Debian Codegraph @

drivers/dahdi/wcxb_spi.h

raw symbols SCIP
1 /*
2 * wcxb SPI library
3 *
4 * Copyright (C) 2013 Digium, Inc.
5 *
6 * All rights reserved.
7 *
8 */
9
10 /*
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
16 *
17 * This program is free software, distributed under the terms of
18 * the GNU General Public License Version 2 as published by the
19 * Free Software Foundation. See the LICENSE file included with
20 * this program for more details.
21 */
22
23 #ifndef __WCXB_SPI_H
24 #define __WCXB_SPI_H
25
26 #include <linux/spi/spi.h>
27 #include <stdbool.h>
28
29 struct wcxb_spi_transfer {
30 const void *tx_buf;
31 void *rx_buf;
32 u32 len:16;
33 u16 delay_usecs;
34 struct list_head node;
35 };
36
37 struct wcxb_spi_message {
38 struct list_head transfers;
39 struct list_head node;
40 struct wcxb_spi_device *spi;
41 void (*complete)(void *arg);
42 void *arg;
43 int status;
44 };
45
46 struct wcxb_spi_master;
47
48 struct wcxb_spi_device {
49 struct wcxb_spi_master *master;
50 u16 chip_select;
51 };
52
53 extern struct wcxb_spi_master *wcxb_spi_master_create(struct device *parent,
54 void __iomem *base, bool auto_cs);
55 extern void wcxb_spi_master_destroy(struct wcxb_spi_master *master);
56 extern int wcxb_spi_sync(struct wcxb_spi_device *spi,
57 struct wcxb_spi_message *message);
58 extern int wcxb_spi_async(struct wcxb_spi_device *spi,
59 struct wcxb_spi_message *message);
60 extern void wcxb_spi_handle_interrupt(struct wcxb_spi_master *master);
61
62 static inline struct wcxb_spi_device *
63 wcxb_spi_device_create(struct wcxb_spi_master *master, u16 chip_select)
64 {
65 struct wcxb_spi_device *spi = kzalloc(sizeof(*spi), GFP_KERNEL);
66 if (!spi)
67 return NULL;
68 spi->master = master;
69 spi->chip_select = chip_select;
70 return spi;
71 }
72
73 static inline void wcxb_spi_device_destroy(struct wcxb_spi_device *spi)
74 {
75 kfree(spi);
76 }
77
78 static inline void wcxb_spi_message_init(struct wcxb_spi_message *m)
79 {
80 memset(m, 0, sizeof(*m));
81 INIT_LIST_HEAD(&m->transfers);
82 }
83
84 static inline void wcxb_spi_message_add_tail(struct wcxb_spi_transfer *t,
85 struct wcxb_spi_message *m)
86 {
87 list_add_tail(&t->node, &m->transfers);
88 }
89
90 static inline int
91 wcxb_spi_write(struct wcxb_spi_device *spi, const void *buffer, size_t len)
92 {
93 struct wcxb_spi_transfer t = {
94 .tx_buf = buffer,
95 .len = len,
96 };
97 struct wcxb_spi_message m;
98 wcxb_spi_message_init(&m);
99 wcxb_spi_message_add_tail(&t, &m);
100 return wcxb_spi_sync(spi, &m);
101 }
102
103 static inline int
104 wcxb_spi_read(struct wcxb_spi_device *spi, void *buffer, size_t len)
105 {
106 struct wcxb_spi_transfer t = {
107 .rx_buf = buffer,
108 .len = len,
109 };
110 struct wcxb_spi_message m;
111 wcxb_spi_message_init(&m);
112 wcxb_spi_message_add_tail(&t, &m);
113 return wcxb_spi_sync(spi, &m);
114 }
115
116 #endif