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
28 struct wcxb_spi_transfer {
29 const void *tx_buf;
30 void *rx_buf;
31 u32 len:16;
32 u16 delay_usecs;
33 struct list_head node;
34 };
35
36 struct wcxb_spi_message {
37 struct list_head transfers;
38 struct list_head node;
39 struct wcxb_spi_device *spi;
40 void (*complete)(void *arg);
41 void *arg;
42 int status;
43 };
44
45 struct wcxb_spi_master;
46
47 struct wcxb_spi_device {
48 struct wcxb_spi_master *master;
49 u16 chip_select;
50 };
51
52 extern struct wcxb_spi_master *wcxb_spi_master_create(struct device *parent,
53 void __iomem *base, bool auto_cs);
54 extern void wcxb_spi_master_destroy(struct wcxb_spi_master *master);
55 extern int wcxb_spi_sync(struct wcxb_spi_device *spi,
56 struct wcxb_spi_message *message);
57 extern int wcxb_spi_async(struct wcxb_spi_device *spi,
58 struct wcxb_spi_message *message);
59 extern void wcxb_spi_handle_interrupt(struct wcxb_spi_master *master);
60
61 static inline struct wcxb_spi_device *
62 wcxb_spi_device_create(struct wcxb_spi_master *master, u16 chip_select)
63 {
64 struct wcxb_spi_device *spi = kzalloc(sizeof(*spi), GFP_KERNEL);
65 if (!spi)
66 return NULL;
67 spi->master = master;
68 spi->chip_select = chip_select;
69 return spi;
70 }
71
72 static inline void wcxb_spi_device_destroy(struct wcxb_spi_device *spi)
73 {
74 kfree(spi);
75 }
76
77 static inline void wcxb_spi_message_init(struct wcxb_spi_message *m)
78 {
79 memset(m, 0, sizeof(*m));
80 INIT_LIST_HEAD(&m->transfers);
81 }
82
83 static inline void wcxb_spi_message_add_tail(struct wcxb_spi_transfer *t,
84 struct wcxb_spi_message *m)
85 {
86 list_add_tail(&t->node, &m->transfers);
87 }
88
89 static inline int
90 wcxb_spi_write(struct wcxb_spi_device *spi, const void *buffer, size_t len)
91 {
92 struct wcxb_spi_transfer t = {
93 .tx_buf = buffer,
94 .len = len,
95 };
96 struct wcxb_spi_message m;
97 wcxb_spi_message_init(&m);
98 wcxb_spi_message_add_tail(&t, &m);
99 return wcxb_spi_sync(spi, &m);
100 }
101
102 static inline int
103 wcxb_spi_read(struct wcxb_spi_device *spi, void *buffer, size_t len)
104 {
105 struct wcxb_spi_transfer t = {
106 .rx_buf = buffer,
107 .len = len,
108 };
109 struct wcxb_spi_message m;
110 wcxb_spi_message_init(&m);
111 wcxb_spi_message_add_tail(&t, &m);
112 return wcxb_spi_sync(spi, &m);
113 }
114
115 #endif