2 * Copyright (C) ST-Ericsson AB 2010
3 * Contact: Sjur Brendeland / sjur.brandeland@stericsson.com
4 * Author: Daniel Martensson / Daniel.Martensson@stericsson.com
5 * License terms: GNU General Public License (GPL) version 2.
8 #include <linux/version.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/device.h>
12 #include <linux/platform_device.h>
13 #include <linux/string.h>
14 #include <linux/workqueue.h>
15 #include <linux/completion.h>
16 #include <linux/list.h>
17 #include <linux/interrupt.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/delay.h>
20 #include <linux/sched.h>
21 #include <linux/debugfs.h>
22 #include <linux/if_arp.h>
23 #include <net/caif/caif_layer.h>
24 #include <net/caif/caif_spi.h>
26 #ifndef CONFIG_CAIF_SPI_SYNC
27 #define FLAVOR "Flavour: Vanilla.\n"
29 #define FLAVOR "Flavour: Master CMD&LEN at start.\n"
30 #endif /* CONFIG_CAIF_SPI_SYNC */
32 MODULE_LICENSE("GPL");
33 MODULE_AUTHOR("Daniel Martensson<daniel.martensson@stericsson.com>");
34 MODULE_DESCRIPTION("CAIF SPI driver");
37 module_param(spi_loop
, bool, S_IRUGO
);
38 MODULE_PARM_DESC(spi_loop
, "SPI running in loopback mode.");
40 /* SPI frame alignment. */
41 module_param(spi_frm_align
, int, S_IRUGO
);
42 MODULE_PARM_DESC(spi_frm_align
, "SPI frame alignment.");
44 /* SPI padding options. */
45 module_param(spi_up_head_align
, int, S_IRUGO
);
46 MODULE_PARM_DESC(spi_up_head_align
, "SPI uplink head alignment.");
48 module_param(spi_up_tail_align
, int, S_IRUGO
);
49 MODULE_PARM_DESC(spi_up_tail_align
, "SPI uplink tail alignment.");
51 module_param(spi_down_head_align
, int, S_IRUGO
);
52 MODULE_PARM_DESC(spi_down_head_align
, "SPI downlink head alignment.");
54 module_param(spi_down_tail_align
, int, S_IRUGO
);
55 MODULE_PARM_DESC(spi_down_tail_align
, "SPI downlink tail alignment.");
58 #define BYTE_HEX_FMT "%02X"
60 #define BYTE_HEX_FMT "%02hhX"
63 #define SPI_MAX_PAYLOAD_SIZE 4096
65 * Threshold values for the SPI packet queue. Flowcontrol will be asserted
66 * when the number of packets exceeds HIGH_WATER_MARK. It will not be
67 * deasserted before the number of packets drops below LOW_WATER_MARK.
69 #define LOW_WATER_MARK 100
70 #define HIGH_WATER_MARK (LOW_WATER_MARK*5)
75 * We sometimes use UML for debugging, but it cannot handle
76 * dma_alloc_coherent so we have to wrap it.
78 static inline void *dma_alloc(dma_addr_t
*daddr
)
80 return kmalloc(SPI_DMA_BUF_LEN
, GFP_KERNEL
);
83 static inline void dma_free(void *cpu_addr
, dma_addr_t handle
)
90 static inline void *dma_alloc(dma_addr_t
*daddr
)
92 return dma_alloc_coherent(NULL
, SPI_DMA_BUF_LEN
, daddr
,
96 static inline void dma_free(void *cpu_addr
, dma_addr_t handle
)
98 dma_free_coherent(NULL
, SPI_DMA_BUF_LEN
, cpu_addr
, handle
);
100 #endif /* CONFIG_UML */
102 #ifdef CONFIG_DEBUG_FS
104 #define DEBUGFS_BUF_SIZE 4096
106 static struct dentry
*dbgfs_root
;
108 static inline void driver_debugfs_create(void)
110 dbgfs_root
= debugfs_create_dir(cfspi_spi_driver
.driver
.name
, NULL
);
113 static inline void driver_debugfs_remove(void)
115 debugfs_remove(dbgfs_root
);
118 static inline void dev_debugfs_rem(struct cfspi
*cfspi
)
120 debugfs_remove(cfspi
->dbgfs_frame
);
121 debugfs_remove(cfspi
->dbgfs_state
);
122 debugfs_remove(cfspi
->dbgfs_dir
);
125 static int dbgfs_open(struct inode
*inode
, struct file
*file
)
127 file
->private_data
= inode
->i_private
;
131 static ssize_t
dbgfs_state(struct file
*file
, char __user
*user_buf
,
132 size_t count
, loff_t
*ppos
)
137 struct cfspi
*cfspi
= file
->private_data
;
139 buf
= kzalloc(DEBUGFS_BUF_SIZE
, GFP_KERNEL
);
143 /* Print out debug information. */
144 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
145 "CAIF SPI debug information:\n");
147 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
), FLAVOR
);
149 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
150 "STATE: %d\n", cfspi
->dbg_state
);
151 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
152 "Previous CMD: 0x%x\n", cfspi
->pcmd
);
153 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
154 "Current CMD: 0x%x\n", cfspi
->cmd
);
155 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
156 "Previous TX len: %d\n", cfspi
->tx_ppck_len
);
157 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
158 "Previous RX len: %d\n", cfspi
->rx_ppck_len
);
159 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
160 "Current TX len: %d\n", cfspi
->tx_cpck_len
);
161 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
162 "Current RX len: %d\n", cfspi
->rx_cpck_len
);
163 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
164 "Next TX len: %d\n", cfspi
->tx_npck_len
);
165 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
166 "Next RX len: %d\n", cfspi
->rx_npck_len
);
168 if (len
> DEBUGFS_BUF_SIZE
)
169 len
= DEBUGFS_BUF_SIZE
;
171 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
177 static ssize_t
print_frame(char *buf
, size_t size
, char *frm
,
178 size_t count
, size_t cut
)
182 for (i
= 0; i
< count
; i
++) {
183 len
+= snprintf((buf
+ len
), (size
- len
),
184 "[0x" BYTE_HEX_FMT
"]",
186 if ((i
== cut
) && (count
> (cut
* 2))) {
189 len
+= snprintf((buf
+ len
), (size
- len
),
190 "--- %u bytes skipped ---\n",
191 (int)(count
- (cut
* 2)));
194 if ((!(i
% 10)) && i
) {
195 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
199 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
), "\n");
203 static ssize_t
dbgfs_frame(struct file
*file
, char __user
*user_buf
,
204 size_t count
, loff_t
*ppos
)
211 cfspi
= file
->private_data
;
212 buf
= kzalloc(DEBUGFS_BUF_SIZE
, GFP_KERNEL
);
216 /* Print out debug information. */
217 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
220 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
221 "Tx data (Len: %d):\n", cfspi
->tx_cpck_len
);
223 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
225 (cfspi
->tx_cpck_len
+ SPI_CMD_SZ
), 100);
227 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
228 "Rx data (Len: %d):\n", cfspi
->rx_cpck_len
);
230 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
232 (cfspi
->rx_cpck_len
+ SPI_CMD_SZ
), 100);
234 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
240 static const struct file_operations dbgfs_state_fops
= {
246 static const struct file_operations dbgfs_frame_fops
= {
252 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
254 cfspi
->dbgfs_dir
= debugfs_create_dir(cfspi
->pdev
->name
, dbgfs_root
);
255 cfspi
->dbgfs_state
= debugfs_create_file("state", S_IRUGO
,
256 cfspi
->dbgfs_dir
, cfspi
,
258 cfspi
->dbgfs_frame
= debugfs_create_file("frame", S_IRUGO
,
259 cfspi
->dbgfs_dir
, cfspi
,
263 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
265 cfspi
->dbg_state
= state
;
269 static inline void driver_debugfs_create(void)
273 static inline void driver_debugfs_remove(void)
277 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
281 static inline void dev_debugfs_rem(struct cfspi
*cfspi
)
285 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
288 #endif /* CONFIG_DEBUG_FS */
290 static LIST_HEAD(cfspi_list
);
291 static spinlock_t cfspi_list_lock
;
293 /* SPI uplink head alignment. */
294 static ssize_t
show_up_head_align(struct device_driver
*driver
, char *buf
)
296 return sprintf(buf
, "%d\n", spi_up_head_align
);
299 static DRIVER_ATTR(up_head_align
, S_IRUSR
, show_up_head_align
, NULL
);
301 /* SPI uplink tail alignment. */
302 static ssize_t
show_up_tail_align(struct device_driver
*driver
, char *buf
)
304 return sprintf(buf
, "%d\n", spi_up_tail_align
);
307 static DRIVER_ATTR(up_tail_align
, S_IRUSR
, show_up_tail_align
, NULL
);
309 /* SPI downlink head alignment. */
310 static ssize_t
show_down_head_align(struct device_driver
*driver
, char *buf
)
312 return sprintf(buf
, "%d\n", spi_down_head_align
);
315 static DRIVER_ATTR(down_head_align
, S_IRUSR
, show_down_head_align
, NULL
);
317 /* SPI downlink tail alignment. */
318 static ssize_t
show_down_tail_align(struct device_driver
*driver
, char *buf
)
320 return sprintf(buf
, "%d\n", spi_down_tail_align
);
323 static DRIVER_ATTR(down_tail_align
, S_IRUSR
, show_down_tail_align
, NULL
);
325 /* SPI frame alignment. */
326 static ssize_t
show_frame_align(struct device_driver
*driver
, char *buf
)
328 return sprintf(buf
, "%d\n", spi_frm_align
);
331 static DRIVER_ATTR(frame_align
, S_IRUSR
, show_frame_align
, NULL
);
333 int cfspi_xmitfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
340 struct caif_payload_info
*info
;
344 skb
= skb_dequeue(&cfspi
->chead
);
349 * Calculate length of frame including SPI padding.
350 * The payload position is found in the control buffer.
352 info
= (struct caif_payload_info
*)&skb
->cb
;
355 * Compute head offset i.e. number of bytes to add to
356 * get the start of the payload aligned.
358 if (spi_up_head_align
) {
359 spad
= 1 + ((info
->hdr_len
+ 1) & spi_up_head_align
);
360 *dst
= (u8
)(spad
- 1);
364 /* Copy in CAIF frame. */
365 skb_copy_bits(skb
, 0, dst
, skb
->len
);
367 cfspi
->ndev
->stats
.tx_packets
++;
368 cfspi
->ndev
->stats
.tx_bytes
+= skb
->len
;
371 * Compute tail offset i.e. number of bytes to add to
372 * get the complete CAIF frame aligned.
374 epad
= (skb
->len
+ spad
) & spi_up_tail_align
;
379 } while ((dst
- buf
) < len
);
384 int cfspi_xmitlen(struct cfspi
*cfspi
)
386 struct sk_buff
*skb
= NULL
;
391 * Decommit previously commited frames.
392 * skb_queue_splice_tail(&cfspi->chead,&cfspi->qhead)
394 while (skb_peek(&cfspi
->chead
)) {
395 skb
= skb_dequeue_tail(&cfspi
->chead
);
396 skb_queue_head(&cfspi
->qhead
, skb
);
400 struct caif_payload_info
*info
= NULL
;
404 skb
= skb_dequeue(&cfspi
->qhead
);
409 * Calculate length of frame including SPI padding.
410 * The payload position is found in the control buffer.
412 info
= (struct caif_payload_info
*)&skb
->cb
;
415 * Compute head offset i.e. number of bytes to add to
416 * get the start of the payload aligned.
418 if (spi_up_head_align
)
419 spad
= 1 + ((info
->hdr_len
+ 1) & spi_up_head_align
);
422 * Compute tail offset i.e. number of bytes to add to
423 * get the complete CAIF frame aligned.
425 epad
= (skb
->len
+ spad
) & spi_up_tail_align
;
427 if ((skb
->len
+ spad
+ epad
+ frm_len
) <= CAIF_MAX_SPI_FRAME
) {
428 skb_queue_tail(&cfspi
->chead
, skb
);
430 frm_len
+= skb
->len
+ spad
+ epad
;
432 /* Put back packet. */
433 skb_queue_head(&cfspi
->qhead
, skb
);
435 } while (pkts
<= CAIF_MAX_SPI_PKTS
);
438 * Send flow on if previously sent flow off
439 * and now go below the low water mark
441 if (cfspi
->flow_off_sent
&& cfspi
->qhead
.qlen
< cfspi
->qd_low_mark
&&
442 cfspi
->cfdev
.flowctrl
) {
443 cfspi
->flow_off_sent
= 0;
444 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 1);
450 static void cfspi_ss_cb(bool assert, struct cfspi_ifc
*ifc
)
452 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
455 spin_lock(&cfspi
->lock
);
457 set_bit(SPI_SS_ON
, &cfspi
->state
);
458 set_bit(SPI_XFER
, &cfspi
->state
);
460 set_bit(SPI_SS_OFF
, &cfspi
->state
);
463 spin_unlock(&cfspi
->lock
);
465 /* Wake up the xfer thread. */
466 wake_up_interruptible(&cfspi
->wait
);
469 static void cfspi_xfer_done_cb(struct cfspi_ifc
*ifc
)
471 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
473 /* Transfer done, complete work queue */
474 complete(&cfspi
->comp
);
477 static int cfspi_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
479 struct cfspi
*cfspi
= NULL
;
484 cfspi
= netdev_priv(dev
);
486 skb_queue_tail(&cfspi
->qhead
, skb
);
488 spin_lock_irqsave(&cfspi
->lock
, flags
);
489 if (!test_and_set_bit(SPI_XFER
, &cfspi
->state
)) {
490 /* Wake up xfer thread. */
491 wake_up_interruptible(&cfspi
->wait
);
493 spin_unlock_irqrestore(&cfspi
->lock
, flags
);
495 /* Send flow off if number of bytes is above high water mark */
496 if (!cfspi
->flow_off_sent
&&
497 cfspi
->qhead
.qlen
> cfspi
->qd_high_mark
&&
498 cfspi
->cfdev
.flowctrl
) {
499 cfspi
->flow_off_sent
= 1;
500 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 0);
506 int cfspi_rxfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
510 caif_assert(buf
!= NULL
);
514 struct sk_buff
*skb
= NULL
;
521 * Compute head offset i.e. number of bytes added to
522 * get the start of the payload aligned.
524 if (spi_down_head_align
) {
529 /* Read length of CAIF frame (little endian). */
531 pkt_len
|= ((*(src
+1)) << 8) & 0xFF00;
532 pkt_len
+= 2; /* Add FCS fields. */
534 /* Get a suitable caif packet and copy in data. */
536 skb
= netdev_alloc_skb(cfspi
->ndev
, pkt_len
+ 1);
537 caif_assert(skb
!= NULL
);
539 dst
= skb_put(skb
, pkt_len
);
540 memcpy(dst
, src
, pkt_len
);
543 skb
->protocol
= htons(ETH_P_CAIF
);
544 skb_reset_mac_header(skb
);
545 skb
->dev
= cfspi
->ndev
;
548 * Push received packet up the stack.
551 res
= netif_rx_ni(skb
);
553 res
= cfspi_xmit(skb
, cfspi
->ndev
);
556 cfspi
->ndev
->stats
.rx_packets
++;
557 cfspi
->ndev
->stats
.rx_bytes
+= pkt_len
;
559 cfspi
->ndev
->stats
.rx_dropped
++;
562 * Compute tail offset i.e. number of bytes added to
563 * get the complete CAIF frame aligned.
565 epad
= (pkt_len
+ spad
) & spi_down_tail_align
;
567 } while ((src
- buf
) < len
);
572 static int cfspi_open(struct net_device
*dev
)
574 netif_wake_queue(dev
);
578 static int cfspi_close(struct net_device
*dev
)
580 netif_stop_queue(dev
);
583 static const struct net_device_ops cfspi_ops
= {
584 .ndo_open
= cfspi_open
,
585 .ndo_stop
= cfspi_close
,
586 .ndo_start_xmit
= cfspi_xmit
589 static void cfspi_setup(struct net_device
*dev
)
591 struct cfspi
*cfspi
= netdev_priv(dev
);
593 dev
->netdev_ops
= &cfspi_ops
;
594 dev
->type
= ARPHRD_CAIF
;
595 dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
596 dev
->tx_queue_len
= 0;
597 dev
->mtu
= SPI_MAX_PAYLOAD_SIZE
;
598 dev
->destructor
= free_netdev
;
599 skb_queue_head_init(&cfspi
->qhead
);
600 skb_queue_head_init(&cfspi
->chead
);
601 cfspi
->cfdev
.link_select
= CAIF_LINK_HIGH_BANDW
;
602 cfspi
->cfdev
.use_frag
= false;
603 cfspi
->cfdev
.use_stx
= false;
604 cfspi
->cfdev
.use_fcs
= false;
608 int cfspi_spi_probe(struct platform_device
*pdev
)
610 struct cfspi
*cfspi
= NULL
;
611 struct net_device
*ndev
;
612 struct cfspi_dev
*dev
;
614 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
616 ndev
= alloc_netdev(sizeof(struct cfspi
),
617 "cfspi%d", cfspi_setup
);
621 cfspi
= netdev_priv(ndev
);
622 netif_stop_queue(ndev
);
627 cfspi
->flow_off_sent
= 0;
628 cfspi
->qd_low_mark
= LOW_WATER_MARK
;
629 cfspi
->qd_high_mark
= HIGH_WATER_MARK
;
631 /* Assign the SPI device. */
633 /* Assign the device ifc to this SPI interface. */
634 dev
->ifc
= &cfspi
->ifc
;
636 /* Allocate DMA buffers. */
637 cfspi
->xfer
.va_tx
= dma_alloc(&cfspi
->xfer
.pa_tx
);
638 if (!cfspi
->xfer
.va_tx
) {
640 "CFSPI: failed to allocate dma TX buffer.\n");
642 goto err_dma_alloc_tx
;
645 cfspi
->xfer
.va_rx
= dma_alloc(&cfspi
->xfer
.pa_rx
);
647 if (!cfspi
->xfer
.va_rx
) {
649 "CFSPI: failed to allocate dma TX buffer.\n");
651 goto err_dma_alloc_rx
;
654 /* Initialize the work queue. */
655 INIT_WORK(&cfspi
->work
, cfspi_xfer
);
657 /* Initialize spin locks. */
658 spin_lock_init(&cfspi
->lock
);
660 /* Initialize flow control state. */
661 cfspi
->flow_stop
= false;
663 /* Initialize wait queue. */
664 init_waitqueue_head(&cfspi
->wait
);
666 /* Create work thread. */
667 cfspi
->wq
= create_singlethread_workqueue(dev
->name
);
669 printk(KERN_WARNING
"CFSPI: failed to create work queue.\n");
674 /* Initialize work queue. */
675 init_completion(&cfspi
->comp
);
677 /* Create debugfs entries. */
678 dev_debugfs_add(cfspi
);
680 /* Set up the ifc. */
681 cfspi
->ifc
.ss_cb
= cfspi_ss_cb
;
682 cfspi
->ifc
.xfer_done_cb
= cfspi_xfer_done_cb
;
683 cfspi
->ifc
.priv
= cfspi
;
685 /* Add CAIF SPI device to list. */
686 spin_lock(&cfspi_list_lock
);
687 list_add_tail(&cfspi
->list
, &cfspi_list
);
688 spin_unlock(&cfspi_list_lock
);
690 /* Schedule the work queue. */
691 queue_work(cfspi
->wq
, &cfspi
->work
);
693 /* Register network device. */
694 res
= register_netdev(ndev
);
696 printk(KERN_ERR
"CFSPI: Reg. error: %d.\n", res
);
702 dev_debugfs_rem(cfspi
);
703 set_bit(SPI_TERMINATE
, &cfspi
->state
);
704 wake_up_interruptible(&cfspi
->wait
);
705 destroy_workqueue(cfspi
->wq
);
707 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
709 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
716 int cfspi_spi_remove(struct platform_device
*pdev
)
718 struct list_head
*list_node
;
720 struct cfspi
*cfspi
= NULL
;
721 struct cfspi_dev
*dev
;
723 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
724 spin_lock(&cfspi_list_lock
);
725 list_for_each_safe(list_node
, n
, &cfspi_list
) {
726 cfspi
= list_entry(list_node
, struct cfspi
, list
);
727 /* Find the corresponding device. */
728 if (cfspi
->dev
== dev
) {
729 /* Remove from list. */
731 /* Free DMA buffers. */
732 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
733 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
734 set_bit(SPI_TERMINATE
, &cfspi
->state
);
735 wake_up_interruptible(&cfspi
->wait
);
736 destroy_workqueue(cfspi
->wq
);
737 /* Destroy debugfs directory and files. */
738 dev_debugfs_rem(cfspi
);
739 unregister_netdev(cfspi
->ndev
);
740 spin_unlock(&cfspi_list_lock
);
744 spin_unlock(&cfspi_list_lock
);
748 static void __exit
cfspi_exit_module(void)
750 struct list_head
*list_node
;
752 struct cfspi
*cfspi
= NULL
;
754 list_for_each_safe(list_node
, n
, &cfspi_list
) {
755 cfspi
= list_entry(list_node
, struct cfspi
, list
);
756 platform_device_unregister(cfspi
->pdev
);
759 /* Destroy sysfs files. */
760 driver_remove_file(&cfspi_spi_driver
.driver
,
761 &driver_attr_up_head_align
);
762 driver_remove_file(&cfspi_spi_driver
.driver
,
763 &driver_attr_up_tail_align
);
764 driver_remove_file(&cfspi_spi_driver
.driver
,
765 &driver_attr_down_head_align
);
766 driver_remove_file(&cfspi_spi_driver
.driver
,
767 &driver_attr_down_tail_align
);
768 driver_remove_file(&cfspi_spi_driver
.driver
, &driver_attr_frame_align
);
769 /* Unregister platform driver. */
770 platform_driver_unregister(&cfspi_spi_driver
);
771 /* Destroy debugfs root directory. */
772 driver_debugfs_remove();
775 static int __init
cfspi_init_module(void)
779 /* Initialize spin lock. */
780 spin_lock_init(&cfspi_list_lock
);
782 /* Register platform driver. */
783 result
= platform_driver_register(&cfspi_spi_driver
);
785 printk(KERN_ERR
"Could not register platform SPI driver.\n");
786 goto err_dev_register
;
789 /* Create sysfs files. */
791 driver_create_file(&cfspi_spi_driver
.driver
,
792 &driver_attr_up_head_align
);
794 printk(KERN_ERR
"Sysfs creation failed 1.\n");
795 goto err_create_up_head_align
;
799 driver_create_file(&cfspi_spi_driver
.driver
,
800 &driver_attr_up_tail_align
);
802 printk(KERN_ERR
"Sysfs creation failed 2.\n");
803 goto err_create_up_tail_align
;
807 driver_create_file(&cfspi_spi_driver
.driver
,
808 &driver_attr_down_head_align
);
810 printk(KERN_ERR
"Sysfs creation failed 3.\n");
811 goto err_create_down_head_align
;
815 driver_create_file(&cfspi_spi_driver
.driver
,
816 &driver_attr_down_tail_align
);
818 printk(KERN_ERR
"Sysfs creation failed 4.\n");
819 goto err_create_down_tail_align
;
823 driver_create_file(&cfspi_spi_driver
.driver
,
824 &driver_attr_frame_align
);
826 printk(KERN_ERR
"Sysfs creation failed 5.\n");
827 goto err_create_frame_align
;
829 driver_debugfs_create();
832 err_create_frame_align
:
833 driver_remove_file(&cfspi_spi_driver
.driver
,
834 &driver_attr_down_tail_align
);
835 err_create_down_tail_align
:
836 driver_remove_file(&cfspi_spi_driver
.driver
,
837 &driver_attr_down_head_align
);
838 err_create_down_head_align
:
839 driver_remove_file(&cfspi_spi_driver
.driver
,
840 &driver_attr_up_tail_align
);
841 err_create_up_tail_align
:
842 driver_remove_file(&cfspi_spi_driver
.driver
,
843 &driver_attr_up_head_align
);
844 err_create_up_head_align
:
849 module_init(cfspi_init_module
);
850 module_exit(cfspi_exit_module
);