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");
36 /* Returns the number of padding bytes for alignment. */
37 #define PAD_POW2(x, pow) ((((x)&((pow)-1))==0) ? 0 : (((pow)-((x)&((pow)-1)))))
40 module_param(spi_loop
, bool, S_IRUGO
);
41 MODULE_PARM_DESC(spi_loop
, "SPI running in loopback mode.");
43 /* SPI frame alignment. */
44 module_param(spi_frm_align
, int, S_IRUGO
);
45 MODULE_PARM_DESC(spi_frm_align
, "SPI frame alignment.");
48 * SPI padding options.
49 * Warning: must be a base of 2 (& operation used) and can not be zero !
51 module_param(spi_up_head_align
, int, S_IRUGO
);
52 MODULE_PARM_DESC(spi_up_head_align
, "SPI uplink head alignment.");
54 module_param(spi_up_tail_align
, int, S_IRUGO
);
55 MODULE_PARM_DESC(spi_up_tail_align
, "SPI uplink tail alignment.");
57 module_param(spi_down_head_align
, int, S_IRUGO
);
58 MODULE_PARM_DESC(spi_down_head_align
, "SPI downlink head alignment.");
60 module_param(spi_down_tail_align
, int, S_IRUGO
);
61 MODULE_PARM_DESC(spi_down_tail_align
, "SPI downlink tail alignment.");
64 #define BYTE_HEX_FMT "%02X"
66 #define BYTE_HEX_FMT "%02hhX"
69 #define SPI_MAX_PAYLOAD_SIZE 4096
71 * Threshold values for the SPI packet queue. Flowcontrol will be asserted
72 * when the number of packets exceeds HIGH_WATER_MARK. It will not be
73 * deasserted before the number of packets drops below LOW_WATER_MARK.
75 #define LOW_WATER_MARK 100
76 #define HIGH_WATER_MARK (LOW_WATER_MARK*5)
81 * We sometimes use UML for debugging, but it cannot handle
82 * dma_alloc_coherent so we have to wrap it.
84 static inline void *dma_alloc(dma_addr_t
*daddr
)
86 return kmalloc(SPI_DMA_BUF_LEN
, GFP_KERNEL
);
89 static inline void dma_free(void *cpu_addr
, dma_addr_t handle
)
96 static inline void *dma_alloc(dma_addr_t
*daddr
)
98 return dma_alloc_coherent(NULL
, SPI_DMA_BUF_LEN
, daddr
,
102 static inline void dma_free(void *cpu_addr
, dma_addr_t handle
)
104 dma_free_coherent(NULL
, SPI_DMA_BUF_LEN
, cpu_addr
, handle
);
106 #endif /* CONFIG_UML */
108 #ifdef CONFIG_DEBUG_FS
110 #define DEBUGFS_BUF_SIZE 4096
112 static struct dentry
*dbgfs_root
;
114 static inline void driver_debugfs_create(void)
116 dbgfs_root
= debugfs_create_dir(cfspi_spi_driver
.driver
.name
, NULL
);
119 static inline void driver_debugfs_remove(void)
121 debugfs_remove(dbgfs_root
);
124 static inline void dev_debugfs_rem(struct cfspi
*cfspi
)
126 debugfs_remove(cfspi
->dbgfs_frame
);
127 debugfs_remove(cfspi
->dbgfs_state
);
128 debugfs_remove(cfspi
->dbgfs_dir
);
131 static int dbgfs_open(struct inode
*inode
, struct file
*file
)
133 file
->private_data
= inode
->i_private
;
137 static ssize_t
dbgfs_state(struct file
*file
, char __user
*user_buf
,
138 size_t count
, loff_t
*ppos
)
143 struct cfspi
*cfspi
= file
->private_data
;
145 buf
= kzalloc(DEBUGFS_BUF_SIZE
, GFP_KERNEL
);
149 /* Print out debug information. */
150 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
151 "CAIF SPI debug information:\n");
153 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
), FLAVOR
);
155 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
156 "STATE: %d\n", cfspi
->dbg_state
);
157 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
158 "Previous CMD: 0x%x\n", cfspi
->pcmd
);
159 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
160 "Current CMD: 0x%x\n", cfspi
->cmd
);
161 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
162 "Previous TX len: %d\n", cfspi
->tx_ppck_len
);
163 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
164 "Previous RX len: %d\n", cfspi
->rx_ppck_len
);
165 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
166 "Current TX len: %d\n", cfspi
->tx_cpck_len
);
167 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
168 "Current RX len: %d\n", cfspi
->rx_cpck_len
);
169 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
170 "Next TX len: %d\n", cfspi
->tx_npck_len
);
171 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
172 "Next RX len: %d\n", cfspi
->rx_npck_len
);
174 if (len
> DEBUGFS_BUF_SIZE
)
175 len
= DEBUGFS_BUF_SIZE
;
177 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
183 static ssize_t
print_frame(char *buf
, size_t size
, char *frm
,
184 size_t count
, size_t cut
)
188 for (i
= 0; i
< count
; i
++) {
189 len
+= snprintf((buf
+ len
), (size
- len
),
190 "[0x" BYTE_HEX_FMT
"]",
192 if ((i
== cut
) && (count
> (cut
* 2))) {
195 len
+= snprintf((buf
+ len
), (size
- len
),
196 "--- %u bytes skipped ---\n",
197 (int)(count
- (cut
* 2)));
200 if ((!(i
% 10)) && i
) {
201 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
205 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
), "\n");
209 static ssize_t
dbgfs_frame(struct file
*file
, char __user
*user_buf
,
210 size_t count
, loff_t
*ppos
)
217 cfspi
= file
->private_data
;
218 buf
= kzalloc(DEBUGFS_BUF_SIZE
, GFP_KERNEL
);
222 /* Print out debug information. */
223 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
226 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
227 "Tx data (Len: %d):\n", cfspi
->tx_cpck_len
);
229 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
231 (cfspi
->tx_cpck_len
+ SPI_CMD_SZ
), 100);
233 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
234 "Rx data (Len: %d):\n", cfspi
->rx_cpck_len
);
236 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
238 (cfspi
->rx_cpck_len
+ SPI_CMD_SZ
), 100);
240 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
246 static const struct file_operations dbgfs_state_fops
= {
252 static const struct file_operations dbgfs_frame_fops
= {
258 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
260 cfspi
->dbgfs_dir
= debugfs_create_dir(cfspi
->pdev
->name
, dbgfs_root
);
261 cfspi
->dbgfs_state
= debugfs_create_file("state", S_IRUGO
,
262 cfspi
->dbgfs_dir
, cfspi
,
264 cfspi
->dbgfs_frame
= debugfs_create_file("frame", S_IRUGO
,
265 cfspi
->dbgfs_dir
, cfspi
,
269 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
271 cfspi
->dbg_state
= state
;
275 static inline void driver_debugfs_create(void)
279 static inline void driver_debugfs_remove(void)
283 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
287 static inline void dev_debugfs_rem(struct cfspi
*cfspi
)
291 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
294 #endif /* CONFIG_DEBUG_FS */
296 static LIST_HEAD(cfspi_list
);
297 static spinlock_t cfspi_list_lock
;
299 /* SPI uplink head alignment. */
300 static ssize_t
show_up_head_align(struct device_driver
*driver
, char *buf
)
302 return sprintf(buf
, "%d\n", spi_up_head_align
);
305 static DRIVER_ATTR(up_head_align
, S_IRUSR
, show_up_head_align
, NULL
);
307 /* SPI uplink tail alignment. */
308 static ssize_t
show_up_tail_align(struct device_driver
*driver
, char *buf
)
310 return sprintf(buf
, "%d\n", spi_up_tail_align
);
313 static DRIVER_ATTR(up_tail_align
, S_IRUSR
, show_up_tail_align
, NULL
);
315 /* SPI downlink head alignment. */
316 static ssize_t
show_down_head_align(struct device_driver
*driver
, char *buf
)
318 return sprintf(buf
, "%d\n", spi_down_head_align
);
321 static DRIVER_ATTR(down_head_align
, S_IRUSR
, show_down_head_align
, NULL
);
323 /* SPI downlink tail alignment. */
324 static ssize_t
show_down_tail_align(struct device_driver
*driver
, char *buf
)
326 return sprintf(buf
, "%d\n", spi_down_tail_align
);
329 static DRIVER_ATTR(down_tail_align
, S_IRUSR
, show_down_tail_align
, NULL
);
331 /* SPI frame alignment. */
332 static ssize_t
show_frame_align(struct device_driver
*driver
, char *buf
)
334 return sprintf(buf
, "%d\n", spi_frm_align
);
337 static DRIVER_ATTR(frame_align
, S_IRUSR
, show_frame_align
, NULL
);
339 int cfspi_xmitfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
344 if (cfspi
->slave
&& !cfspi
->slave_talked
)
345 cfspi
->slave_talked
= true;
349 struct caif_payload_info
*info
;
353 skb
= skb_dequeue(&cfspi
->chead
);
358 * Calculate length of frame including SPI padding.
359 * The payload position is found in the control buffer.
361 info
= (struct caif_payload_info
*)&skb
->cb
;
364 * Compute head offset i.e. number of bytes to add to
365 * get the start of the payload aligned.
367 if (spi_up_head_align
> 1) {
368 spad
= 1 + PAD_POW2((info
->hdr_len
+ 1), spi_up_head_align
);
369 *dst
= (u8
)(spad
- 1);
373 /* Copy in CAIF frame. */
374 skb_copy_bits(skb
, 0, dst
, skb
->len
);
376 cfspi
->ndev
->stats
.tx_packets
++;
377 cfspi
->ndev
->stats
.tx_bytes
+= skb
->len
;
380 * Compute tail offset i.e. number of bytes to add to
381 * get the complete CAIF frame aligned.
383 epad
= PAD_POW2((skb
->len
+ spad
), spi_up_tail_align
);
388 } while ((dst
- buf
) < len
);
393 int cfspi_xmitlen(struct cfspi
*cfspi
)
395 struct sk_buff
*skb
= NULL
;
400 * Decommit previously committed frames.
401 * skb_queue_splice_tail(&cfspi->chead,&cfspi->qhead)
403 while (skb_peek(&cfspi
->chead
)) {
404 skb
= skb_dequeue_tail(&cfspi
->chead
);
405 skb_queue_head(&cfspi
->qhead
, skb
);
409 struct caif_payload_info
*info
= NULL
;
413 skb
= skb_dequeue(&cfspi
->qhead
);
418 * Calculate length of frame including SPI padding.
419 * The payload position is found in the control buffer.
421 info
= (struct caif_payload_info
*)&skb
->cb
;
424 * Compute head offset i.e. number of bytes to add to
425 * get the start of the payload aligned.
427 if (spi_up_head_align
> 1)
428 spad
= 1 + PAD_POW2((info
->hdr_len
+ 1), spi_up_head_align
);
431 * Compute tail offset i.e. number of bytes to add to
432 * get the complete CAIF frame aligned.
434 epad
= PAD_POW2((skb
->len
+ spad
), spi_up_tail_align
);
436 if ((skb
->len
+ spad
+ epad
+ frm_len
) <= CAIF_MAX_SPI_FRAME
) {
437 skb_queue_tail(&cfspi
->chead
, skb
);
439 frm_len
+= skb
->len
+ spad
+ epad
;
441 /* Put back packet. */
442 skb_queue_head(&cfspi
->qhead
, skb
);
445 } while (pkts
<= CAIF_MAX_SPI_PKTS
);
448 * Send flow on if previously sent flow off
449 * and now go below the low water mark
451 if (cfspi
->flow_off_sent
&& cfspi
->qhead
.qlen
< cfspi
->qd_low_mark
&&
452 cfspi
->cfdev
.flowctrl
) {
453 cfspi
->flow_off_sent
= 0;
454 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 1);
460 static void cfspi_ss_cb(bool assert, struct cfspi_ifc
*ifc
)
462 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
465 * The slave device is the master on the link. Interrupts before the
466 * slave has transmitted are considered spurious.
468 if (cfspi
->slave
&& !cfspi
->slave_talked
) {
469 printk(KERN_WARNING
"CFSPI: Spurious SS interrupt.\n");
474 spin_lock(&cfspi
->lock
);
476 set_bit(SPI_SS_ON
, &cfspi
->state
);
477 set_bit(SPI_XFER
, &cfspi
->state
);
479 set_bit(SPI_SS_OFF
, &cfspi
->state
);
482 spin_unlock(&cfspi
->lock
);
484 /* Wake up the xfer thread. */
486 wake_up_interruptible(&cfspi
->wait
);
489 static void cfspi_xfer_done_cb(struct cfspi_ifc
*ifc
)
491 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
493 /* Transfer done, complete work queue */
494 complete(&cfspi
->comp
);
497 static int cfspi_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
499 struct cfspi
*cfspi
= NULL
;
504 cfspi
= netdev_priv(dev
);
506 skb_queue_tail(&cfspi
->qhead
, skb
);
508 spin_lock_irqsave(&cfspi
->lock
, flags
);
509 if (!test_and_set_bit(SPI_XFER
, &cfspi
->state
)) {
510 /* Wake up xfer thread. */
511 wake_up_interruptible(&cfspi
->wait
);
513 spin_unlock_irqrestore(&cfspi
->lock
, flags
);
515 /* Send flow off if number of bytes is above high water mark */
516 if (!cfspi
->flow_off_sent
&&
517 cfspi
->qhead
.qlen
> cfspi
->qd_high_mark
&&
518 cfspi
->cfdev
.flowctrl
) {
519 cfspi
->flow_off_sent
= 1;
520 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 0);
526 int cfspi_rxfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
530 caif_assert(buf
!= NULL
);
534 struct sk_buff
*skb
= NULL
;
541 * Compute head offset i.e. number of bytes added to
542 * get the start of the payload aligned.
544 if (spi_down_head_align
> 1) {
549 /* Read length of CAIF frame (little endian). */
551 pkt_len
|= ((*(src
+1)) << 8) & 0xFF00;
552 pkt_len
+= 2; /* Add FCS fields. */
554 /* Get a suitable caif packet and copy in data. */
556 skb
= netdev_alloc_skb(cfspi
->ndev
, pkt_len
+ 1);
557 caif_assert(skb
!= NULL
);
559 dst
= skb_put(skb
, pkt_len
);
560 memcpy(dst
, src
, pkt_len
);
563 skb
->protocol
= htons(ETH_P_CAIF
);
564 skb_reset_mac_header(skb
);
565 skb
->dev
= cfspi
->ndev
;
568 * Push received packet up the stack.
571 res
= netif_rx_ni(skb
);
573 res
= cfspi_xmit(skb
, cfspi
->ndev
);
576 cfspi
->ndev
->stats
.rx_packets
++;
577 cfspi
->ndev
->stats
.rx_bytes
+= pkt_len
;
579 cfspi
->ndev
->stats
.rx_dropped
++;
582 * Compute tail offset i.e. number of bytes added to
583 * get the complete CAIF frame aligned.
585 epad
= PAD_POW2((pkt_len
+ spad
), spi_down_tail_align
);
587 } while ((src
- buf
) < len
);
592 static int cfspi_open(struct net_device
*dev
)
594 netif_wake_queue(dev
);
598 static int cfspi_close(struct net_device
*dev
)
600 netif_stop_queue(dev
);
603 static const struct net_device_ops cfspi_ops
= {
604 .ndo_open
= cfspi_open
,
605 .ndo_stop
= cfspi_close
,
606 .ndo_start_xmit
= cfspi_xmit
609 static void cfspi_setup(struct net_device
*dev
)
611 struct cfspi
*cfspi
= netdev_priv(dev
);
613 dev
->netdev_ops
= &cfspi_ops
;
614 dev
->type
= ARPHRD_CAIF
;
615 dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
616 dev
->tx_queue_len
= 0;
617 dev
->mtu
= SPI_MAX_PAYLOAD_SIZE
;
618 dev
->destructor
= free_netdev
;
619 skb_queue_head_init(&cfspi
->qhead
);
620 skb_queue_head_init(&cfspi
->chead
);
621 cfspi
->cfdev
.link_select
= CAIF_LINK_HIGH_BANDW
;
622 cfspi
->cfdev
.use_frag
= false;
623 cfspi
->cfdev
.use_stx
= false;
624 cfspi
->cfdev
.use_fcs
= false;
628 int cfspi_spi_probe(struct platform_device
*pdev
)
630 struct cfspi
*cfspi
= NULL
;
631 struct net_device
*ndev
;
632 struct cfspi_dev
*dev
;
634 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
636 ndev
= alloc_netdev(sizeof(struct cfspi
),
637 "cfspi%d", cfspi_setup
);
641 cfspi
= netdev_priv(ndev
);
642 netif_stop_queue(ndev
);
647 cfspi
->flow_off_sent
= 0;
648 cfspi
->qd_low_mark
= LOW_WATER_MARK
;
649 cfspi
->qd_high_mark
= HIGH_WATER_MARK
;
651 /* Set slave info. */
652 if (!strncmp(cfspi_spi_driver
.driver
.name
, "cfspi_sspi", 10)) {
654 cfspi
->slave_talked
= false;
656 cfspi
->slave
= false;
657 cfspi
->slave_talked
= false;
660 /* Assign the SPI device. */
662 /* Assign the device ifc to this SPI interface. */
663 dev
->ifc
= &cfspi
->ifc
;
665 /* Allocate DMA buffers. */
666 cfspi
->xfer
.va_tx
= dma_alloc(&cfspi
->xfer
.pa_tx
);
667 if (!cfspi
->xfer
.va_tx
) {
669 "CFSPI: failed to allocate dma TX buffer.\n");
671 goto err_dma_alloc_tx
;
674 cfspi
->xfer
.va_rx
= dma_alloc(&cfspi
->xfer
.pa_rx
);
676 if (!cfspi
->xfer
.va_rx
) {
678 "CFSPI: failed to allocate dma TX buffer.\n");
680 goto err_dma_alloc_rx
;
683 /* Initialize the work queue. */
684 INIT_WORK(&cfspi
->work
, cfspi_xfer
);
686 /* Initialize spin locks. */
687 spin_lock_init(&cfspi
->lock
);
689 /* Initialize flow control state. */
690 cfspi
->flow_stop
= false;
692 /* Initialize wait queue. */
693 init_waitqueue_head(&cfspi
->wait
);
695 /* Create work thread. */
696 cfspi
->wq
= create_singlethread_workqueue(dev
->name
);
698 printk(KERN_WARNING
"CFSPI: failed to create work queue.\n");
703 /* Initialize work queue. */
704 init_completion(&cfspi
->comp
);
706 /* Create debugfs entries. */
707 dev_debugfs_add(cfspi
);
709 /* Set up the ifc. */
710 cfspi
->ifc
.ss_cb
= cfspi_ss_cb
;
711 cfspi
->ifc
.xfer_done_cb
= cfspi_xfer_done_cb
;
712 cfspi
->ifc
.priv
= cfspi
;
714 /* Add CAIF SPI device to list. */
715 spin_lock(&cfspi_list_lock
);
716 list_add_tail(&cfspi
->list
, &cfspi_list
);
717 spin_unlock(&cfspi_list_lock
);
719 /* Schedule the work queue. */
720 queue_work(cfspi
->wq
, &cfspi
->work
);
722 /* Register network device. */
723 res
= register_netdev(ndev
);
725 printk(KERN_ERR
"CFSPI: Reg. error: %d.\n", res
);
731 dev_debugfs_rem(cfspi
);
732 set_bit(SPI_TERMINATE
, &cfspi
->state
);
733 wake_up_interruptible(&cfspi
->wait
);
734 destroy_workqueue(cfspi
->wq
);
736 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
738 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
745 int cfspi_spi_remove(struct platform_device
*pdev
)
747 struct list_head
*list_node
;
749 struct cfspi
*cfspi
= NULL
;
750 struct cfspi_dev
*dev
;
752 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
753 spin_lock(&cfspi_list_lock
);
754 list_for_each_safe(list_node
, n
, &cfspi_list
) {
755 cfspi
= list_entry(list_node
, struct cfspi
, list
);
756 /* Find the corresponding device. */
757 if (cfspi
->dev
== dev
) {
758 /* Remove from list. */
760 /* Free DMA buffers. */
761 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
762 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
763 set_bit(SPI_TERMINATE
, &cfspi
->state
);
764 wake_up_interruptible(&cfspi
->wait
);
765 destroy_workqueue(cfspi
->wq
);
766 /* Destroy debugfs directory and files. */
767 dev_debugfs_rem(cfspi
);
768 unregister_netdev(cfspi
->ndev
);
769 spin_unlock(&cfspi_list_lock
);
773 spin_unlock(&cfspi_list_lock
);
777 static void __exit
cfspi_exit_module(void)
779 struct list_head
*list_node
;
781 struct cfspi
*cfspi
= NULL
;
783 list_for_each_safe(list_node
, n
, &cfspi_list
) {
784 cfspi
= list_entry(list_node
, struct cfspi
, list
);
785 platform_device_unregister(cfspi
->pdev
);
788 /* Destroy sysfs files. */
789 driver_remove_file(&cfspi_spi_driver
.driver
,
790 &driver_attr_up_head_align
);
791 driver_remove_file(&cfspi_spi_driver
.driver
,
792 &driver_attr_up_tail_align
);
793 driver_remove_file(&cfspi_spi_driver
.driver
,
794 &driver_attr_down_head_align
);
795 driver_remove_file(&cfspi_spi_driver
.driver
,
796 &driver_attr_down_tail_align
);
797 driver_remove_file(&cfspi_spi_driver
.driver
, &driver_attr_frame_align
);
798 /* Unregister platform driver. */
799 platform_driver_unregister(&cfspi_spi_driver
);
800 /* Destroy debugfs root directory. */
801 driver_debugfs_remove();
804 static int __init
cfspi_init_module(void)
808 /* Initialize spin lock. */
809 spin_lock_init(&cfspi_list_lock
);
811 /* Register platform driver. */
812 result
= platform_driver_register(&cfspi_spi_driver
);
814 printk(KERN_ERR
"Could not register platform SPI driver.\n");
815 goto err_dev_register
;
818 /* Create sysfs files. */
820 driver_create_file(&cfspi_spi_driver
.driver
,
821 &driver_attr_up_head_align
);
823 printk(KERN_ERR
"Sysfs creation failed 1.\n");
824 goto err_create_up_head_align
;
828 driver_create_file(&cfspi_spi_driver
.driver
,
829 &driver_attr_up_tail_align
);
831 printk(KERN_ERR
"Sysfs creation failed 2.\n");
832 goto err_create_up_tail_align
;
836 driver_create_file(&cfspi_spi_driver
.driver
,
837 &driver_attr_down_head_align
);
839 printk(KERN_ERR
"Sysfs creation failed 3.\n");
840 goto err_create_down_head_align
;
844 driver_create_file(&cfspi_spi_driver
.driver
,
845 &driver_attr_down_tail_align
);
847 printk(KERN_ERR
"Sysfs creation failed 4.\n");
848 goto err_create_down_tail_align
;
852 driver_create_file(&cfspi_spi_driver
.driver
,
853 &driver_attr_frame_align
);
855 printk(KERN_ERR
"Sysfs creation failed 5.\n");
856 goto err_create_frame_align
;
858 driver_debugfs_create();
861 err_create_frame_align
:
862 driver_remove_file(&cfspi_spi_driver
.driver
,
863 &driver_attr_down_tail_align
);
864 err_create_down_tail_align
:
865 driver_remove_file(&cfspi_spi_driver
.driver
,
866 &driver_attr_down_head_align
);
867 err_create_down_head_align
:
868 driver_remove_file(&cfspi_spi_driver
.driver
,
869 &driver_attr_up_tail_align
);
870 err_create_up_tail_align
:
871 driver_remove_file(&cfspi_spi_driver
.driver
,
872 &driver_attr_up_head_align
);
873 err_create_up_head_align
:
878 module_init(cfspi_init_module
);
879 module_exit(cfspi_exit_module
);