aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/wm831x-spi.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2011-06-10 14:28:10 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-08-22 07:23:22 -0400
commit1df5981b82d9eabdd6e66d1d9514164c02329345 (patch)
treec5fc2653d70a884d42957b2c7bc0c8cd49d8b895 /drivers/mfd/wm831x-spi.c
parentbd20eb541ebbb17a5e047cd20e74b9ccf19a4123 (diff)
mfd: Convert WM831x to use regmap API
Factor out the register read/write code to use the register map API. We still need some wm831x specific code and locking in place to check that the user key is handled correctly but only on the write side, reads are not affected by the key. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/wm831x-spi.c')
-rw-r--r--drivers/mfd/wm831x-spi.c60
1 files changed, 12 insertions, 48 deletions
diff --git a/drivers/mfd/wm831x-spi.c b/drivers/mfd/wm831x-spi.c
index eed8e4f7a5a1..dbe11472afce 100644
--- a/drivers/mfd/wm831x-spi.c
+++ b/drivers/mfd/wm831x-spi.c
@@ -16,58 +16,16 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/pm.h> 17#include <linux/pm.h>
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/regmap.h>
20#include <linux/err.h>
19 21
20#include <linux/mfd/wm831x/core.h> 22#include <linux/mfd/wm831x/core.h>
21 23
22static int wm831x_spi_read_device(struct wm831x *wm831x, unsigned short reg,
23 int bytes, void *dest)
24{
25 u16 tx_val;
26 u16 *d = dest;
27 int r, ret;
28
29 /* Go register at a time */
30 for (r = reg; r < reg + (bytes / 2); r++) {
31 tx_val = r | 0x8000;
32
33 ret = spi_write_then_read(wm831x->control_data,
34 (u8 *)&tx_val, 2, (u8 *)d, 2);
35 if (ret != 0)
36 return ret;
37
38 *d = be16_to_cpu(*d);
39
40 d++;
41 }
42
43 return 0;
44}
45
46static int wm831x_spi_write_device(struct wm831x *wm831x, unsigned short reg,
47 int bytes, void *src)
48{
49 struct spi_device *spi = wm831x->control_data;
50 u16 *s = src;
51 u16 data[2];
52 int ret, r;
53
54 /* Go register at a time */
55 for (r = reg; r < reg + (bytes / 2); r++) {
56 data[0] = r;
57 data[1] = *s++;
58
59 ret = spi_write(spi, (char *)&data, sizeof(data));
60 if (ret != 0)
61 return ret;
62 }
63
64 return 0;
65}
66
67static int __devinit wm831x_spi_probe(struct spi_device *spi) 24static int __devinit wm831x_spi_probe(struct spi_device *spi)
68{ 25{
69 struct wm831x *wm831x; 26 struct wm831x *wm831x;
70 enum wm831x_parent type; 27 enum wm831x_parent type;
28 int ret;
71 29
72 /* Currently SPI support for ID tables is unmerged, we're faking it */ 30 /* Currently SPI support for ID tables is unmerged, we're faking it */
73 if (strcmp(spi->modalias, "wm8310") == 0) 31 if (strcmp(spi->modalias, "wm8310") == 0)
@@ -98,9 +56,15 @@ static int __devinit wm831x_spi_probe(struct spi_device *spi)
98 56
99 dev_set_drvdata(&spi->dev, wm831x); 57 dev_set_drvdata(&spi->dev, wm831x);
100 wm831x->dev = &spi->dev; 58 wm831x->dev = &spi->dev;
101 wm831x->control_data = spi; 59
102 wm831x->read_dev = wm831x_spi_read_device; 60 wm831x->regmap = regmap_init_spi(wm831x->dev, &wm831x_regmap_config);
103 wm831x->write_dev = wm831x_spi_write_device; 61 if (IS_ERR(wm831x->regmap)) {
62 ret = PTR_ERR(wm831x->regmap);
63 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
64 ret);
65 kfree(wm831x);
66 return ret;
67 }
104 68
105 return wm831x_device_init(wm831x, type, spi->irq); 69 return wm831x_device_init(wm831x, type, spi->irq);
106} 70}