2 * Copyright (C) ST-Ericsson AB 2010
3 * Author: Daniel Martensson
4 * License terms: GNU General Public License (GPL) version 2.
7 #include <linux/init.h>
8 #include <linux/module.h>
9 #include <linux/device.h>
10 #include <linux/platform_device.h>
11 #include <linux/string.h>
12 #include <linux/workqueue.h>
13 #include <linux/completion.h>
14 #include <linux/list.h>
15 #include <linux/interrupt.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/delay.h>
18 #include <linux/sched.h>
19 #include <linux/debugfs.h>
20 #include <linux/if_arp.h>
21 #include <net/caif/caif_layer.h>
22 #include <net/caif/caif_spi.h>
24 #ifndef CONFIG_CAIF_SPI_SYNC
25 #define FLAVOR "Flavour: Vanilla.\n"
27 #define FLAVOR "Flavour: Master CMD&LEN at start.\n"
28 #endif /* CONFIG_CAIF_SPI_SYNC */
30 MODULE_LICENSE("GPL");
31 MODULE_AUTHOR("Daniel Martensson");
32 MODULE_DESCRIPTION("CAIF SPI driver");
34 /* Returns the number of padding bytes for alignment. */
35 #define PAD_POW2(x, pow) ((((x)&((pow)-1))==0) ? 0 : (((pow)-((x)&((pow)-1)))))
38 module_param(spi_loop
, bool, 0444);
39 MODULE_PARM_DESC(spi_loop
, "SPI running in loopback mode.");
41 /* SPI frame alignment. */
42 module_param(spi_frm_align
, int, 0444);
43 MODULE_PARM_DESC(spi_frm_align
, "SPI frame alignment.");
46 * SPI padding options.
47 * Warning: must be a base of 2 (& operation used) and can not be zero !
49 module_param(spi_up_head_align
, int, 0444);
50 MODULE_PARM_DESC(spi_up_head_align
, "SPI uplink head alignment.");
52 module_param(spi_up_tail_align
, int, 0444);
53 MODULE_PARM_DESC(spi_up_tail_align
, "SPI uplink tail alignment.");
55 module_param(spi_down_head_align
, int, 0444);
56 MODULE_PARM_DESC(spi_down_head_align
, "SPI downlink head alignment.");
58 module_param(spi_down_tail_align
, int, 0444);
59 MODULE_PARM_DESC(spi_down_tail_align
, "SPI downlink tail alignment.");
62 #define BYTE_HEX_FMT "%02X"
64 #define BYTE_HEX_FMT "%02hhX"
67 #define SPI_MAX_PAYLOAD_SIZE 4096
69 * Threshold values for the SPI packet queue. Flowcontrol will be asserted
70 * when the number of packets exceeds HIGH_WATER_MARK. It will not be
71 * deasserted before the number of packets drops below LOW_WATER_MARK.
73 #define LOW_WATER_MARK 100
74 #define HIGH_WATER_MARK (LOW_WATER_MARK*5)
76 #ifndef CONFIG_HAS_DMA
79 * We sometimes use UML for debugging, but it cannot handle
80 * dma_alloc_coherent so we have to wrap it.
82 static inline void *dma_alloc(struct cfspi
*cfspi
, dma_addr_t
*daddr
)
84 return kmalloc(SPI_DMA_BUF_LEN
, GFP_KERNEL
);
87 static inline void dma_free(struct cfspi
*cfspi
, void *cpu_addr
,
95 static inline void *dma_alloc(struct cfspi
*cfspi
, dma_addr_t
*daddr
)
97 return dma_alloc_coherent(&cfspi
->pdev
->dev
, SPI_DMA_BUF_LEN
, daddr
,
101 static inline void dma_free(struct cfspi
*cfspi
, void *cpu_addr
,
104 dma_free_coherent(&cfspi
->pdev
->dev
, SPI_DMA_BUF_LEN
, cpu_addr
, handle
);
106 #endif /* CONFIG_HAS_DMA */
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 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 "--- %zu bytes skipped ---\n",
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
),
224 cfspi
->xfer
.va_tx
[0],
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", 0444,
256 cfspi
->dbgfs_dir
, cfspi
,
258 cfspi
->dbgfs_frame
= debugfs_create_file("frame", 0444,
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
up_head_align_show(struct device_driver
*driver
, char *buf
)
296 return sprintf(buf
, "%d\n", spi_up_head_align
);
299 static DRIVER_ATTR_RO(up_head_align
);
301 /* SPI uplink tail alignment. */
302 static ssize_t
up_tail_align_show(struct device_driver
*driver
, char *buf
)
304 return sprintf(buf
, "%d\n", spi_up_tail_align
);
307 static DRIVER_ATTR_RO(up_tail_align
);
309 /* SPI downlink head alignment. */
310 static ssize_t
down_head_align_show(struct device_driver
*driver
, char *buf
)
312 return sprintf(buf
, "%d\n", spi_down_head_align
);
315 static DRIVER_ATTR_RO(down_head_align
);
317 /* SPI downlink tail alignment. */
318 static ssize_t
down_tail_align_show(struct device_driver
*driver
, char *buf
)
320 return sprintf(buf
, "%d\n", spi_down_tail_align
);
323 static DRIVER_ATTR_RO(down_tail_align
);
325 /* SPI frame alignment. */
326 static ssize_t
frame_align_show(struct device_driver
*driver
, char *buf
)
328 return sprintf(buf
, "%d\n", spi_frm_align
);
331 static DRIVER_ATTR_RO(frame_align
);
333 int cfspi_xmitfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
338 if (cfspi
->slave
&& !cfspi
->slave_talked
)
339 cfspi
->slave_talked
= true;
343 struct caif_payload_info
*info
;
347 skb
= skb_dequeue(&cfspi
->chead
);
352 * Calculate length of frame including SPI padding.
353 * The payload position is found in the control buffer.
355 info
= (struct caif_payload_info
*)&skb
->cb
;
358 * Compute head offset i.e. number of bytes to add to
359 * get the start of the payload aligned.
361 if (spi_up_head_align
> 1) {
362 spad
= 1 + PAD_POW2((info
->hdr_len
+ 1), spi_up_head_align
);
363 *dst
= (u8
)(spad
- 1);
367 /* Copy in CAIF frame. */
368 skb_copy_bits(skb
, 0, dst
, skb
->len
);
370 cfspi
->ndev
->stats
.tx_packets
++;
371 cfspi
->ndev
->stats
.tx_bytes
+= skb
->len
;
374 * Compute tail offset i.e. number of bytes to add to
375 * get the complete CAIF frame aligned.
377 epad
= PAD_POW2((skb
->len
+ spad
), spi_up_tail_align
);
382 } while ((dst
- buf
) < len
);
387 int cfspi_xmitlen(struct cfspi
*cfspi
)
389 struct sk_buff
*skb
= NULL
;
394 * Decommit previously committed frames.
395 * skb_queue_splice_tail(&cfspi->chead,&cfspi->qhead)
397 while (skb_peek(&cfspi
->chead
)) {
398 skb
= skb_dequeue_tail(&cfspi
->chead
);
399 skb_queue_head(&cfspi
->qhead
, skb
);
403 struct caif_payload_info
*info
= NULL
;
407 skb
= skb_dequeue(&cfspi
->qhead
);
412 * Calculate length of frame including SPI padding.
413 * The payload position is found in the control buffer.
415 info
= (struct caif_payload_info
*)&skb
->cb
;
418 * Compute head offset i.e. number of bytes to add to
419 * get the start of the payload aligned.
421 if (spi_up_head_align
> 1)
422 spad
= 1 + PAD_POW2((info
->hdr_len
+ 1), spi_up_head_align
);
425 * Compute tail offset i.e. number of bytes to add to
426 * get the complete CAIF frame aligned.
428 epad
= PAD_POW2((skb
->len
+ spad
), spi_up_tail_align
);
430 if ((skb
->len
+ spad
+ epad
+ frm_len
) <= CAIF_MAX_SPI_FRAME
) {
431 skb_queue_tail(&cfspi
->chead
, skb
);
433 frm_len
+= skb
->len
+ spad
+ epad
;
435 /* Put back packet. */
436 skb_queue_head(&cfspi
->qhead
, skb
);
439 } while (pkts
<= CAIF_MAX_SPI_PKTS
);
442 * Send flow on if previously sent flow off
443 * and now go below the low water mark
445 if (cfspi
->flow_off_sent
&& cfspi
->qhead
.qlen
< cfspi
->qd_low_mark
&&
446 cfspi
->cfdev
.flowctrl
) {
447 cfspi
->flow_off_sent
= 0;
448 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 1);
454 static void cfspi_ss_cb(bool assert, struct cfspi_ifc
*ifc
)
456 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
459 * The slave device is the master on the link. Interrupts before the
460 * slave has transmitted are considered spurious.
462 if (cfspi
->slave
&& !cfspi
->slave_talked
) {
463 printk(KERN_WARNING
"CFSPI: Spurious SS interrupt.\n");
468 spin_lock(&cfspi
->lock
);
470 set_bit(SPI_SS_ON
, &cfspi
->state
);
471 set_bit(SPI_XFER
, &cfspi
->state
);
473 set_bit(SPI_SS_OFF
, &cfspi
->state
);
476 spin_unlock(&cfspi
->lock
);
478 /* Wake up the xfer thread. */
480 wake_up_interruptible(&cfspi
->wait
);
483 static void cfspi_xfer_done_cb(struct cfspi_ifc
*ifc
)
485 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
487 /* Transfer done, complete work queue */
488 complete(&cfspi
->comp
);
491 static int cfspi_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
493 struct cfspi
*cfspi
= NULL
;
498 cfspi
= netdev_priv(dev
);
500 skb_queue_tail(&cfspi
->qhead
, skb
);
502 spin_lock_irqsave(&cfspi
->lock
, flags
);
503 if (!test_and_set_bit(SPI_XFER
, &cfspi
->state
)) {
504 /* Wake up xfer thread. */
505 wake_up_interruptible(&cfspi
->wait
);
507 spin_unlock_irqrestore(&cfspi
->lock
, flags
);
509 /* Send flow off if number of bytes is above high water mark */
510 if (!cfspi
->flow_off_sent
&&
511 cfspi
->qhead
.qlen
> cfspi
->qd_high_mark
&&
512 cfspi
->cfdev
.flowctrl
) {
513 cfspi
->flow_off_sent
= 1;
514 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 0);
520 int cfspi_rxfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
524 caif_assert(buf
!= NULL
);
528 struct sk_buff
*skb
= NULL
;
534 * Compute head offset i.e. number of bytes added to
535 * get the start of the payload aligned.
537 if (spi_down_head_align
> 1) {
542 /* Read length of CAIF frame (little endian). */
544 pkt_len
|= ((*(src
+1)) << 8) & 0xFF00;
545 pkt_len
+= 2; /* Add FCS fields. */
547 /* Get a suitable caif packet and copy in data. */
549 skb
= netdev_alloc_skb(cfspi
->ndev
, pkt_len
+ 1);
550 caif_assert(skb
!= NULL
);
552 skb_put_data(skb
, src
, pkt_len
);
555 skb
->protocol
= htons(ETH_P_CAIF
);
556 skb_reset_mac_header(skb
);
559 * Push received packet up the stack.
562 res
= netif_rx_ni(skb
);
564 res
= cfspi_xmit(skb
, cfspi
->ndev
);
567 cfspi
->ndev
->stats
.rx_packets
++;
568 cfspi
->ndev
->stats
.rx_bytes
+= pkt_len
;
570 cfspi
->ndev
->stats
.rx_dropped
++;
573 * Compute tail offset i.e. number of bytes added to
574 * get the complete CAIF frame aligned.
576 epad
= PAD_POW2((pkt_len
+ spad
), spi_down_tail_align
);
578 } while ((src
- buf
) < len
);
583 static int cfspi_open(struct net_device
*dev
)
585 netif_wake_queue(dev
);
589 static int cfspi_close(struct net_device
*dev
)
591 netif_stop_queue(dev
);
595 static int cfspi_init(struct net_device
*dev
)
598 struct cfspi
*cfspi
= netdev_priv(dev
);
601 cfspi
->flow_off_sent
= 0;
602 cfspi
->qd_low_mark
= LOW_WATER_MARK
;
603 cfspi
->qd_high_mark
= HIGH_WATER_MARK
;
605 /* Set slave info. */
606 if (!strncmp(cfspi_spi_driver
.driver
.name
, "cfspi_sspi", 10)) {
608 cfspi
->slave_talked
= false;
610 cfspi
->slave
= false;
611 cfspi
->slave_talked
= false;
614 /* Allocate DMA buffers. */
615 cfspi
->xfer
.va_tx
[0] = dma_alloc(cfspi
, &cfspi
->xfer
.pa_tx
[0]);
616 if (!cfspi
->xfer
.va_tx
[0]) {
618 goto err_dma_alloc_tx_0
;
621 cfspi
->xfer
.va_rx
= dma_alloc(cfspi
, &cfspi
->xfer
.pa_rx
);
623 if (!cfspi
->xfer
.va_rx
) {
625 goto err_dma_alloc_rx
;
628 /* Initialize the work queue. */
629 INIT_WORK(&cfspi
->work
, cfspi_xfer
);
631 /* Initialize spin locks. */
632 spin_lock_init(&cfspi
->lock
);
634 /* Initialize flow control state. */
635 cfspi
->flow_stop
= false;
637 /* Initialize wait queue. */
638 init_waitqueue_head(&cfspi
->wait
);
640 /* Create work thread. */
641 cfspi
->wq
= create_singlethread_workqueue(dev
->name
);
643 printk(KERN_WARNING
"CFSPI: failed to create work queue.\n");
648 /* Initialize work queue. */
649 init_completion(&cfspi
->comp
);
651 /* Create debugfs entries. */
652 dev_debugfs_add(cfspi
);
654 /* Set up the ifc. */
655 cfspi
->ifc
.ss_cb
= cfspi_ss_cb
;
656 cfspi
->ifc
.xfer_done_cb
= cfspi_xfer_done_cb
;
657 cfspi
->ifc
.priv
= cfspi
;
659 /* Add CAIF SPI device to list. */
660 spin_lock(&cfspi_list_lock
);
661 list_add_tail(&cfspi
->list
, &cfspi_list
);
662 spin_unlock(&cfspi_list_lock
);
664 /* Schedule the work queue. */
665 queue_work(cfspi
->wq
, &cfspi
->work
);
670 dma_free(cfspi
, cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
672 dma_free(cfspi
, cfspi
->xfer
.va_tx
[0], cfspi
->xfer
.pa_tx
[0]);
677 static void cfspi_uninit(struct net_device
*dev
)
679 struct cfspi
*cfspi
= netdev_priv(dev
);
681 /* Remove from list. */
682 spin_lock(&cfspi_list_lock
);
683 list_del(&cfspi
->list
);
684 spin_unlock(&cfspi_list_lock
);
687 /* Free DMA buffers. */
688 dma_free(cfspi
, cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
689 dma_free(cfspi
, cfspi
->xfer
.va_tx
[0], cfspi
->xfer
.pa_tx
[0]);
690 set_bit(SPI_TERMINATE
, &cfspi
->state
);
691 wake_up_interruptible(&cfspi
->wait
);
692 destroy_workqueue(cfspi
->wq
);
693 /* Destroy debugfs directory and files. */
694 dev_debugfs_rem(cfspi
);
698 static const struct net_device_ops cfspi_ops
= {
699 .ndo_open
= cfspi_open
,
700 .ndo_stop
= cfspi_close
,
701 .ndo_init
= cfspi_init
,
702 .ndo_uninit
= cfspi_uninit
,
703 .ndo_start_xmit
= cfspi_xmit
706 static void cfspi_setup(struct net_device
*dev
)
708 struct cfspi
*cfspi
= netdev_priv(dev
);
710 dev
->netdev_ops
= &cfspi_ops
;
711 dev
->type
= ARPHRD_CAIF
;
712 dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
713 dev
->priv_flags
|= IFF_NO_QUEUE
;
714 dev
->mtu
= SPI_MAX_PAYLOAD_SIZE
;
715 dev
->needs_free_netdev
= true;
716 skb_queue_head_init(&cfspi
->qhead
);
717 skb_queue_head_init(&cfspi
->chead
);
718 cfspi
->cfdev
.link_select
= CAIF_LINK_HIGH_BANDW
;
719 cfspi
->cfdev
.use_frag
= false;
720 cfspi
->cfdev
.use_stx
= false;
721 cfspi
->cfdev
.use_fcs
= false;
725 int cfspi_spi_probe(struct platform_device
*pdev
)
727 struct cfspi
*cfspi
= NULL
;
728 struct net_device
*ndev
;
729 struct cfspi_dev
*dev
;
731 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
736 ndev
= alloc_netdev(sizeof(struct cfspi
), "cfspi%d",
737 NET_NAME_UNKNOWN
, cfspi_setup
);
741 cfspi
= netdev_priv(ndev
);
742 netif_stop_queue(ndev
);
746 /* Assign the SPI device. */
748 /* Assign the device ifc to this SPI interface. */
749 dev
->ifc
= &cfspi
->ifc
;
751 /* Register network device. */
752 res
= register_netdev(ndev
);
754 printk(KERN_ERR
"CFSPI: Reg. error: %d.\n", res
);
765 int cfspi_spi_remove(struct platform_device
*pdev
)
767 /* Everything is done in cfspi_uninit(). */
771 static void __exit
cfspi_exit_module(void)
773 struct list_head
*list_node
;
775 struct cfspi
*cfspi
= NULL
;
777 list_for_each_safe(list_node
, n
, &cfspi_list
) {
778 cfspi
= list_entry(list_node
, struct cfspi
, list
);
779 unregister_netdev(cfspi
->ndev
);
782 /* Destroy sysfs files. */
783 driver_remove_file(&cfspi_spi_driver
.driver
,
784 &driver_attr_up_head_align
);
785 driver_remove_file(&cfspi_spi_driver
.driver
,
786 &driver_attr_up_tail_align
);
787 driver_remove_file(&cfspi_spi_driver
.driver
,
788 &driver_attr_down_head_align
);
789 driver_remove_file(&cfspi_spi_driver
.driver
,
790 &driver_attr_down_tail_align
);
791 driver_remove_file(&cfspi_spi_driver
.driver
, &driver_attr_frame_align
);
792 /* Unregister platform driver. */
793 platform_driver_unregister(&cfspi_spi_driver
);
794 /* Destroy debugfs root directory. */
795 driver_debugfs_remove();
798 static int __init
cfspi_init_module(void)
802 /* Initialize spin lock. */
803 spin_lock_init(&cfspi_list_lock
);
805 /* Register platform driver. */
806 result
= platform_driver_register(&cfspi_spi_driver
);
808 printk(KERN_ERR
"Could not register platform SPI driver.\n");
809 goto err_dev_register
;
812 /* Create sysfs files. */
814 driver_create_file(&cfspi_spi_driver
.driver
,
815 &driver_attr_up_head_align
);
817 printk(KERN_ERR
"Sysfs creation failed 1.\n");
818 goto err_create_up_head_align
;
822 driver_create_file(&cfspi_spi_driver
.driver
,
823 &driver_attr_up_tail_align
);
825 printk(KERN_ERR
"Sysfs creation failed 2.\n");
826 goto err_create_up_tail_align
;
830 driver_create_file(&cfspi_spi_driver
.driver
,
831 &driver_attr_down_head_align
);
833 printk(KERN_ERR
"Sysfs creation failed 3.\n");
834 goto err_create_down_head_align
;
838 driver_create_file(&cfspi_spi_driver
.driver
,
839 &driver_attr_down_tail_align
);
841 printk(KERN_ERR
"Sysfs creation failed 4.\n");
842 goto err_create_down_tail_align
;
846 driver_create_file(&cfspi_spi_driver
.driver
,
847 &driver_attr_frame_align
);
849 printk(KERN_ERR
"Sysfs creation failed 5.\n");
850 goto err_create_frame_align
;
852 driver_debugfs_create();
855 err_create_frame_align
:
856 driver_remove_file(&cfspi_spi_driver
.driver
,
857 &driver_attr_down_tail_align
);
858 err_create_down_tail_align
:
859 driver_remove_file(&cfspi_spi_driver
.driver
,
860 &driver_attr_down_head_align
);
861 err_create_down_head_align
:
862 driver_remove_file(&cfspi_spi_driver
.driver
,
863 &driver_attr_up_tail_align
);
864 err_create_up_tail_align
:
865 driver_remove_file(&cfspi_spi_driver
.driver
,
866 &driver_attr_up_head_align
);
867 err_create_up_head_align
:
868 platform_driver_unregister(&cfspi_spi_driver
);
873 module_init(cfspi_init_module
);
874 module_exit(cfspi_exit_module
);