diff options
Diffstat (limited to 'drivers/base/regmap/regmap-spi.c')
-rw-r--r-- | drivers/base/regmap/regmap-spi.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index ffa46a92ad33..4c506bd940f3 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c | |||
@@ -15,6 +15,21 @@ | |||
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/module.h> | 16 | #include <linux/module.h> |
17 | 17 | ||
18 | #include "internal.h" | ||
19 | |||
20 | struct regmap_async_spi { | ||
21 | struct regmap_async core; | ||
22 | struct spi_message m; | ||
23 | struct spi_transfer t[2]; | ||
24 | }; | ||
25 | |||
26 | static void regmap_spi_complete(void *data) | ||
27 | { | ||
28 | struct regmap_async_spi *async = data; | ||
29 | |||
30 | regmap_async_complete_cb(&async->core, async->m.status); | ||
31 | } | ||
32 | |||
18 | static int regmap_spi_write(void *context, const void *data, size_t count) | 33 | static int regmap_spi_write(void *context, const void *data, size_t count) |
19 | { | 34 | { |
20 | struct device *dev = context; | 35 | struct device *dev = context; |
@@ -40,6 +55,43 @@ static int regmap_spi_gather_write(void *context, | |||
40 | return spi_sync(spi, &m); | 55 | return spi_sync(spi, &m); |
41 | } | 56 | } |
42 | 57 | ||
58 | static int regmap_spi_async_write(void *context, | ||
59 | const void *reg, size_t reg_len, | ||
60 | const void *val, size_t val_len, | ||
61 | struct regmap_async *a) | ||
62 | { | ||
63 | struct regmap_async_spi *async = container_of(a, | ||
64 | struct regmap_async_spi, | ||
65 | core); | ||
66 | struct device *dev = context; | ||
67 | struct spi_device *spi = to_spi_device(dev); | ||
68 | |||
69 | async->t[0].tx_buf = reg; | ||
70 | async->t[0].len = reg_len; | ||
71 | async->t[1].tx_buf = val; | ||
72 | async->t[1].len = val_len; | ||
73 | |||
74 | spi_message_init(&async->m); | ||
75 | spi_message_add_tail(&async->t[0], &async->m); | ||
76 | spi_message_add_tail(&async->t[1], &async->m); | ||
77 | |||
78 | async->m.complete = regmap_spi_complete; | ||
79 | async->m.context = async; | ||
80 | |||
81 | return spi_async(spi, &async->m); | ||
82 | } | ||
83 | |||
84 | static struct regmap_async *regmap_spi_async_alloc(void) | ||
85 | { | ||
86 | struct regmap_async_spi *async_spi; | ||
87 | |||
88 | async_spi = kzalloc(sizeof(*async_spi), GFP_KERNEL); | ||
89 | if (!async_spi) | ||
90 | return NULL; | ||
91 | |||
92 | return &async_spi->core; | ||
93 | } | ||
94 | |||
43 | static int regmap_spi_read(void *context, | 95 | static int regmap_spi_read(void *context, |
44 | const void *reg, size_t reg_size, | 96 | const void *reg, size_t reg_size, |
45 | void *val, size_t val_size) | 97 | void *val, size_t val_size) |
@@ -53,6 +105,8 @@ static int regmap_spi_read(void *context, | |||
53 | static struct regmap_bus regmap_spi = { | 105 | static struct regmap_bus regmap_spi = { |
54 | .write = regmap_spi_write, | 106 | .write = regmap_spi_write, |
55 | .gather_write = regmap_spi_gather_write, | 107 | .gather_write = regmap_spi_gather_write, |
108 | .async_write = regmap_spi_async_write, | ||
109 | .async_alloc = regmap_spi_async_alloc, | ||
56 | .read = regmap_spi_read, | 110 | .read = regmap_spi_read, |
57 | .read_flag_mask = 0x80, | 111 | .read_flag_mask = 0x80, |
58 | }; | 112 | }; |