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 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
174 static ssize_t
print_frame(char *buf
, size_t size
, char *frm
,
175 size_t count
, size_t cut
)
179 for (i
= 0; i
< count
; i
++) {
180 len
+= snprintf((buf
+ len
), (size
- len
),
181 "[0x" BYTE_HEX_FMT
"]",
183 if ((i
== cut
) && (count
> (cut
* 2))) {
186 len
+= snprintf((buf
+ len
), (size
- len
),
187 "--- %u bytes skipped ---\n",
188 (int)(count
- (cut
* 2)));
191 if ((!(i
% 10)) && i
) {
192 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
196 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
), "\n");
200 static ssize_t
dbgfs_frame(struct file
*file
, char __user
*user_buf
,
201 size_t count
, loff_t
*ppos
)
208 cfspi
= file
->private_data
;
209 buf
= kzalloc(DEBUGFS_BUF_SIZE
, GFP_KERNEL
);
213 /* Print out debug information. */
214 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
217 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
218 "Tx data (Len: %d):\n", cfspi
->tx_cpck_len
);
220 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
222 (cfspi
->tx_cpck_len
+ SPI_CMD_SZ
), 100);
224 len
+= snprintf((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
225 "Rx data (Len: %d):\n", cfspi
->rx_cpck_len
);
227 len
+= print_frame((buf
+ len
), (DEBUGFS_BUF_SIZE
- len
),
229 (cfspi
->rx_cpck_len
+ SPI_CMD_SZ
), 100);
231 size
= simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
237 static const struct file_operations dbgfs_state_fops
= {
243 static const struct file_operations dbgfs_frame_fops
= {
249 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
251 cfspi
->dbgfs_dir
= debugfs_create_dir(cfspi
->pdev
->name
, dbgfs_root
);
252 cfspi
->dbgfs_state
= debugfs_create_file("state", S_IRUGO
,
253 cfspi
->dbgfs_dir
, cfspi
,
255 cfspi
->dbgfs_frame
= debugfs_create_file("frame", S_IRUGO
,
256 cfspi
->dbgfs_dir
, cfspi
,
260 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
262 cfspi
->dbg_state
= state
;
266 static inline void driver_debugfs_create(void)
270 static inline void driver_debugfs_remove(void)
274 static inline void dev_debugfs_add(struct cfspi
*cfspi
)
278 static inline void dev_debugfs_rem(struct cfspi
*cfspi
)
282 inline void cfspi_dbg_state(struct cfspi
*cfspi
, int state
)
285 #endif /* CONFIG_DEBUG_FS */
287 static LIST_HEAD(cfspi_list
);
288 static spinlock_t cfspi_list_lock
;
290 /* SPI uplink head alignment. */
291 static ssize_t
show_up_head_align(struct device_driver
*driver
, char *buf
)
293 return sprintf(buf
, "%d\n", spi_up_head_align
);
296 static DRIVER_ATTR(up_head_align
, S_IRUSR
, show_up_head_align
, NULL
);
298 /* SPI uplink tail alignment. */
299 static ssize_t
show_up_tail_align(struct device_driver
*driver
, char *buf
)
301 return sprintf(buf
, "%d\n", spi_up_tail_align
);
304 static DRIVER_ATTR(up_tail_align
, S_IRUSR
, show_up_tail_align
, NULL
);
306 /* SPI downlink head alignment. */
307 static ssize_t
show_down_head_align(struct device_driver
*driver
, char *buf
)
309 return sprintf(buf
, "%d\n", spi_down_head_align
);
312 static DRIVER_ATTR(down_head_align
, S_IRUSR
, show_down_head_align
, NULL
);
314 /* SPI downlink tail alignment. */
315 static ssize_t
show_down_tail_align(struct device_driver
*driver
, char *buf
)
317 return sprintf(buf
, "%d\n", spi_down_tail_align
);
320 static DRIVER_ATTR(down_tail_align
, S_IRUSR
, show_down_tail_align
, NULL
);
322 /* SPI frame alignment. */
323 static ssize_t
show_frame_align(struct device_driver
*driver
, char *buf
)
325 return sprintf(buf
, "%d\n", spi_frm_align
);
328 static DRIVER_ATTR(frame_align
, S_IRUSR
, show_frame_align
, NULL
);
330 int cfspi_xmitfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
337 struct caif_payload_info
*info
;
341 skb
= skb_dequeue(&cfspi
->chead
);
346 * Calculate length of frame including SPI padding.
347 * The payload position is found in the control buffer.
349 info
= (struct caif_payload_info
*)&skb
->cb
;
352 * Compute head offset i.e. number of bytes to add to
353 * get the start of the payload aligned.
355 if (spi_up_head_align
) {
356 spad
= 1 + ((info
->hdr_len
+ 1) & spi_up_head_align
);
357 *dst
= (u8
)(spad
- 1);
361 /* Copy in CAIF frame. */
362 skb_copy_bits(skb
, 0, dst
, skb
->len
);
364 cfspi
->ndev
->stats
.tx_packets
++;
365 cfspi
->ndev
->stats
.tx_bytes
+= skb
->len
;
368 * Compute tail offset i.e. number of bytes to add to
369 * get the complete CAIF frame aligned.
371 epad
= (skb
->len
+ spad
) & spi_up_tail_align
;
376 } while ((dst
- buf
) < len
);
381 int cfspi_xmitlen(struct cfspi
*cfspi
)
383 struct sk_buff
*skb
= NULL
;
388 * Decommit previously commited frames.
389 * skb_queue_splice_tail(&cfspi->chead,&cfspi->qhead)
391 while (skb_peek(&cfspi
->chead
)) {
392 skb
= skb_dequeue_tail(&cfspi
->chead
);
393 skb_queue_head(&cfspi
->qhead
, skb
);
397 struct caif_payload_info
*info
= NULL
;
401 skb
= skb_dequeue(&cfspi
->qhead
);
406 * Calculate length of frame including SPI padding.
407 * The payload position is found in the control buffer.
409 info
= (struct caif_payload_info
*)&skb
->cb
;
412 * Compute head offset i.e. number of bytes to add to
413 * get the start of the payload aligned.
415 if (spi_up_head_align
)
416 spad
= 1 + ((info
->hdr_len
+ 1) & spi_up_head_align
);
419 * Compute tail offset i.e. number of bytes to add to
420 * get the complete CAIF frame aligned.
422 epad
= (skb
->len
+ spad
) & spi_up_tail_align
;
424 if ((skb
->len
+ spad
+ epad
+ frm_len
) <= CAIF_MAX_SPI_FRAME
) {
425 skb_queue_tail(&cfspi
->chead
, skb
);
427 frm_len
+= skb
->len
+ spad
+ epad
;
429 /* Put back packet. */
430 skb_queue_head(&cfspi
->qhead
, skb
);
432 } while (pkts
<= CAIF_MAX_SPI_PKTS
);
435 * Send flow on if previously sent flow off
436 * and now go below the low water mark
438 if (cfspi
->flow_off_sent
&& cfspi
->qhead
.qlen
< cfspi
->qd_low_mark
&&
439 cfspi
->cfdev
.flowctrl
) {
440 cfspi
->flow_off_sent
= 0;
441 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 1);
447 static void cfspi_ss_cb(bool assert, struct cfspi_ifc
*ifc
)
449 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
452 spin_lock(&cfspi
->lock
);
454 set_bit(SPI_SS_ON
, &cfspi
->state
);
455 set_bit(SPI_XFER
, &cfspi
->state
);
457 set_bit(SPI_SS_OFF
, &cfspi
->state
);
460 spin_unlock(&cfspi
->lock
);
462 /* Wake up the xfer thread. */
463 wake_up_interruptible(&cfspi
->wait
);
466 static void cfspi_xfer_done_cb(struct cfspi_ifc
*ifc
)
468 struct cfspi
*cfspi
= (struct cfspi
*)ifc
->priv
;
470 /* Transfer done, complete work queue */
471 complete(&cfspi
->comp
);
474 static int cfspi_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
476 struct cfspi
*cfspi
= NULL
;
481 cfspi
= netdev_priv(dev
);
483 skb_queue_tail(&cfspi
->qhead
, skb
);
485 spin_lock_irqsave(&cfspi
->lock
, flags
);
486 if (!test_and_set_bit(SPI_XFER
, &cfspi
->state
)) {
487 /* Wake up xfer thread. */
488 wake_up_interruptible(&cfspi
->wait
);
490 spin_unlock_irqrestore(&cfspi
->lock
, flags
);
492 /* Send flow off if number of bytes is above high water mark */
493 if (!cfspi
->flow_off_sent
&&
494 cfspi
->qhead
.qlen
> cfspi
->qd_high_mark
&&
495 cfspi
->cfdev
.flowctrl
) {
496 cfspi
->flow_off_sent
= 1;
497 cfspi
->cfdev
.flowctrl(cfspi
->ndev
, 0);
503 int cfspi_rxfrm(struct cfspi
*cfspi
, u8
*buf
, size_t len
)
507 caif_assert(buf
!= NULL
);
511 struct sk_buff
*skb
= NULL
;
518 * Compute head offset i.e. number of bytes added to
519 * get the start of the payload aligned.
521 if (spi_down_head_align
) {
526 /* Read length of CAIF frame (little endian). */
528 pkt_len
|= ((*(src
+1)) << 8) & 0xFF00;
529 pkt_len
+= 2; /* Add FCS fields. */
531 /* Get a suitable caif packet and copy in data. */
533 skb
= netdev_alloc_skb(cfspi
->ndev
, pkt_len
+ 1);
534 caif_assert(skb
!= NULL
);
536 dst
= skb_put(skb
, pkt_len
);
537 memcpy(dst
, src
, pkt_len
);
540 skb
->protocol
= htons(ETH_P_CAIF
);
541 skb_reset_mac_header(skb
);
542 skb
->dev
= cfspi
->ndev
;
545 * Push received packet up the stack.
548 res
= netif_rx_ni(skb
);
550 res
= cfspi_xmit(skb
, cfspi
->ndev
);
553 cfspi
->ndev
->stats
.rx_packets
++;
554 cfspi
->ndev
->stats
.rx_bytes
+= pkt_len
;
556 cfspi
->ndev
->stats
.rx_dropped
++;
559 * Compute tail offset i.e. number of bytes added to
560 * get the complete CAIF frame aligned.
562 epad
= (pkt_len
+ spad
) & spi_down_tail_align
;
564 } while ((src
- buf
) < len
);
569 static int cfspi_open(struct net_device
*dev
)
571 netif_wake_queue(dev
);
575 static int cfspi_close(struct net_device
*dev
)
577 netif_stop_queue(dev
);
580 static const struct net_device_ops cfspi_ops
= {
581 .ndo_open
= cfspi_open
,
582 .ndo_stop
= cfspi_close
,
583 .ndo_start_xmit
= cfspi_xmit
586 static void cfspi_setup(struct net_device
*dev
)
588 struct cfspi
*cfspi
= netdev_priv(dev
);
590 dev
->netdev_ops
= &cfspi_ops
;
591 dev
->type
= ARPHRD_CAIF
;
592 dev
->flags
= IFF_NOARP
| IFF_POINTOPOINT
;
593 dev
->tx_queue_len
= 0;
594 dev
->mtu
= SPI_MAX_PAYLOAD_SIZE
;
595 dev
->destructor
= free_netdev
;
596 skb_queue_head_init(&cfspi
->qhead
);
597 skb_queue_head_init(&cfspi
->chead
);
598 cfspi
->cfdev
.link_select
= CAIF_LINK_HIGH_BANDW
;
599 cfspi
->cfdev
.use_frag
= false;
600 cfspi
->cfdev
.use_stx
= false;
601 cfspi
->cfdev
.use_fcs
= false;
605 int cfspi_spi_probe(struct platform_device
*pdev
)
607 struct cfspi
*cfspi
= NULL
;
608 struct net_device
*ndev
;
609 struct cfspi_dev
*dev
;
611 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
613 ndev
= alloc_netdev(sizeof(struct cfspi
),
614 "cfspi%d", cfspi_setup
);
618 cfspi
= netdev_priv(ndev
);
619 netif_stop_queue(ndev
);
624 cfspi
->flow_off_sent
= 0;
625 cfspi
->qd_low_mark
= LOW_WATER_MARK
;
626 cfspi
->qd_high_mark
= HIGH_WATER_MARK
;
628 /* Assign the SPI device. */
630 /* Assign the device ifc to this SPI interface. */
631 dev
->ifc
= &cfspi
->ifc
;
633 /* Allocate DMA buffers. */
634 cfspi
->xfer
.va_tx
= dma_alloc(&cfspi
->xfer
.pa_tx
);
635 if (!cfspi
->xfer
.va_tx
) {
637 "CFSPI: failed to allocate dma TX buffer.\n");
639 goto err_dma_alloc_tx
;
642 cfspi
->xfer
.va_rx
= dma_alloc(&cfspi
->xfer
.pa_rx
);
644 if (!cfspi
->xfer
.va_rx
) {
646 "CFSPI: failed to allocate dma TX buffer.\n");
648 goto err_dma_alloc_rx
;
651 /* Initialize the work queue. */
652 INIT_WORK(&cfspi
->work
, cfspi_xfer
);
654 /* Initialize spin locks. */
655 spin_lock_init(&cfspi
->lock
);
657 /* Initialize flow control state. */
658 cfspi
->flow_stop
= false;
660 /* Initialize wait queue. */
661 init_waitqueue_head(&cfspi
->wait
);
663 /* Create work thread. */
664 cfspi
->wq
= create_singlethread_workqueue(dev
->name
);
666 printk(KERN_WARNING
"CFSPI: failed to create work queue.\n");
671 /* Initialize work queue. */
672 init_completion(&cfspi
->comp
);
674 /* Create debugfs entries. */
675 dev_debugfs_add(cfspi
);
677 /* Set up the ifc. */
678 cfspi
->ifc
.ss_cb
= cfspi_ss_cb
;
679 cfspi
->ifc
.xfer_done_cb
= cfspi_xfer_done_cb
;
680 cfspi
->ifc
.priv
= cfspi
;
682 /* Add CAIF SPI device to list. */
683 spin_lock(&cfspi_list_lock
);
684 list_add_tail(&cfspi
->list
, &cfspi_list
);
685 spin_unlock(&cfspi_list_lock
);
687 /* Schedule the work queue. */
688 queue_work(cfspi
->wq
, &cfspi
->work
);
690 /* Register network device. */
691 res
= register_netdev(ndev
);
693 printk(KERN_ERR
"CFSPI: Reg. error: %d.\n", res
);
699 dev_debugfs_rem(cfspi
);
700 set_bit(SPI_TERMINATE
, &cfspi
->state
);
701 wake_up_interruptible(&cfspi
->wait
);
702 destroy_workqueue(cfspi
->wq
);
704 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
706 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
713 int cfspi_spi_remove(struct platform_device
*pdev
)
715 struct list_head
*list_node
;
717 struct cfspi
*cfspi
= NULL
;
718 struct cfspi_dev
*dev
;
720 dev
= (struct cfspi_dev
*)pdev
->dev
.platform_data
;
721 spin_lock(&cfspi_list_lock
);
722 list_for_each_safe(list_node
, n
, &cfspi_list
) {
723 cfspi
= list_entry(list_node
, struct cfspi
, list
);
724 /* Find the corresponding device. */
725 if (cfspi
->dev
== dev
) {
726 /* Remove from list. */
728 /* Free DMA buffers. */
729 dma_free(cfspi
->xfer
.va_rx
, cfspi
->xfer
.pa_rx
);
730 dma_free(cfspi
->xfer
.va_tx
, cfspi
->xfer
.pa_tx
);
731 set_bit(SPI_TERMINATE
, &cfspi
->state
);
732 wake_up_interruptible(&cfspi
->wait
);
733 destroy_workqueue(cfspi
->wq
);
734 /* Destroy debugfs directory and files. */
735 dev_debugfs_rem(cfspi
);
736 unregister_netdev(cfspi
->ndev
);
737 spin_unlock(&cfspi_list_lock
);
741 spin_unlock(&cfspi_list_lock
);
745 static void __exit
cfspi_exit_module(void)
747 struct list_head
*list_node
;
749 struct cfspi
*cfspi
= NULL
;
751 list_for_each_safe(list_node
, n
, &cfspi_list
) {
752 cfspi
= list_entry(list_node
, struct cfspi
, list
);
753 platform_device_unregister(cfspi
->pdev
);
756 /* Destroy sysfs files. */
757 driver_remove_file(&cfspi_spi_driver
.driver
,
758 &driver_attr_up_head_align
);
759 driver_remove_file(&cfspi_spi_driver
.driver
,
760 &driver_attr_up_tail_align
);
761 driver_remove_file(&cfspi_spi_driver
.driver
,
762 &driver_attr_down_head_align
);
763 driver_remove_file(&cfspi_spi_driver
.driver
,
764 &driver_attr_down_tail_align
);
765 driver_remove_file(&cfspi_spi_driver
.driver
, &driver_attr_frame_align
);
766 /* Unregister platform driver. */
767 platform_driver_unregister(&cfspi_spi_driver
);
768 /* Destroy debugfs root directory. */
769 driver_debugfs_remove();
772 static int __init
cfspi_init_module(void)
776 /* Initialize spin lock. */
777 spin_lock_init(&cfspi_list_lock
);
779 /* Register platform driver. */
780 result
= platform_driver_register(&cfspi_spi_driver
);
782 printk(KERN_ERR
"Could not register platform SPI driver.\n");
783 goto err_dev_register
;
786 /* Create sysfs files. */
788 driver_create_file(&cfspi_spi_driver
.driver
,
789 &driver_attr_up_head_align
);
791 printk(KERN_ERR
"Sysfs creation failed 1.\n");
792 goto err_create_up_head_align
;
796 driver_create_file(&cfspi_spi_driver
.driver
,
797 &driver_attr_up_tail_align
);
799 printk(KERN_ERR
"Sysfs creation failed 2.\n");
800 goto err_create_up_tail_align
;
804 driver_create_file(&cfspi_spi_driver
.driver
,
805 &driver_attr_down_head_align
);
807 printk(KERN_ERR
"Sysfs creation failed 3.\n");
808 goto err_create_down_head_align
;
812 driver_create_file(&cfspi_spi_driver
.driver
,
813 &driver_attr_down_tail_align
);
815 printk(KERN_ERR
"Sysfs creation failed 4.\n");
816 goto err_create_down_tail_align
;
820 driver_create_file(&cfspi_spi_driver
.driver
,
821 &driver_attr_frame_align
);
823 printk(KERN_ERR
"Sysfs creation failed 5.\n");
824 goto err_create_frame_align
;
826 driver_debugfs_create();
829 err_create_frame_align
:
830 driver_remove_file(&cfspi_spi_driver
.driver
,
831 &driver_attr_down_tail_align
);
832 err_create_down_tail_align
:
833 driver_remove_file(&cfspi_spi_driver
.driver
,
834 &driver_attr_down_head_align
);
835 err_create_down_head_align
:
836 driver_remove_file(&cfspi_spi_driver
.driver
,
837 &driver_attr_up_tail_align
);
838 err_create_up_tail_align
:
839 driver_remove_file(&cfspi_spi_driver
.driver
,
840 &driver_attr_up_head_align
);
841 err_create_up_head_align
:
846 module_init(cfspi_init_module
);
847 module_exit(cfspi_exit_module
);