2 * wm831x-spi.c -- SPI access for Wolfson WM831x PMICs
4 * Copyright 2009,2010 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
18 #include <linux/spi/spi.h>
20 #include <linux/mfd/wm831x/core.h>
22 static int wm831x_spi_read_device(struct wm831x
*wm831x
, unsigned short reg
,
23 int bytes
, void *dest
)
29 /* Go register at a time */
30 for (r
= reg
; r
< reg
+ (bytes
/ 2); r
++) {
33 ret
= spi_write_then_read(wm831x
->control_data
,
34 (u8
*)&tx_val
, 2, (u8
*)d
, 2);
46 static int wm831x_spi_write_device(struct wm831x
*wm831x
, unsigned short reg
,
49 struct spi_device
*spi
= wm831x
->control_data
;
54 /* Go register at a time */
55 for (r
= reg
; r
< reg
+ (bytes
/ 2); r
++) {
59 ret
= spi_write(spi
, (char *)&data
, sizeof(data
));
67 static int __devinit
wm831x_spi_probe(struct spi_device
*spi
)
69 struct wm831x
*wm831x
;
70 enum wm831x_parent type
;
72 /* Currently SPI support for ID tables is unmerged, we're faking it */
73 if (strcmp(spi
->modalias
, "wm8310") == 0)
75 else if (strcmp(spi
->modalias
, "wm8311") == 0)
77 else if (strcmp(spi
->modalias
, "wm8312") == 0)
79 else if (strcmp(spi
->modalias
, "wm8320") == 0)
81 else if (strcmp(spi
->modalias
, "wm8321") == 0)
83 else if (strcmp(spi
->modalias
, "wm8325") == 0)
85 else if (strcmp(spi
->modalias
, "wm8326") == 0)
88 dev_err(&spi
->dev
, "Unknown device type\n");
92 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
96 spi
->bits_per_word
= 16;
97 spi
->mode
= SPI_MODE_0
;
99 dev_set_drvdata(&spi
->dev
, wm831x
);
100 wm831x
->dev
= &spi
->dev
;
101 wm831x
->control_data
= spi
;
102 wm831x
->read_dev
= wm831x_spi_read_device
;
103 wm831x
->write_dev
= wm831x_spi_write_device
;
105 return wm831x_device_init(wm831x
, type
, spi
->irq
);
108 static int __devexit
wm831x_spi_remove(struct spi_device
*spi
)
110 struct wm831x
*wm831x
= dev_get_drvdata(&spi
->dev
);
112 wm831x_device_exit(wm831x
);
117 static int wm831x_spi_suspend(struct device
*dev
)
119 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
121 return wm831x_device_suspend(wm831x
);
124 static const struct dev_pm_ops wm831x_spi_pm
= {
125 .freeze
= wm831x_spi_suspend
,
126 .suspend
= wm831x_spi_suspend
,
129 static struct spi_driver wm8310_spi_driver
= {
132 .bus
= &spi_bus_type
,
133 .owner
= THIS_MODULE
,
134 .pm
= &wm831x_spi_pm
,
136 .probe
= wm831x_spi_probe
,
137 .remove
= __devexit_p(wm831x_spi_remove
),
140 static struct spi_driver wm8311_spi_driver
= {
143 .bus
= &spi_bus_type
,
144 .owner
= THIS_MODULE
,
145 .pm
= &wm831x_spi_pm
,
147 .probe
= wm831x_spi_probe
,
148 .remove
= __devexit_p(wm831x_spi_remove
),
151 static struct spi_driver wm8312_spi_driver
= {
154 .bus
= &spi_bus_type
,
155 .owner
= THIS_MODULE
,
156 .pm
= &wm831x_spi_pm
,
158 .probe
= wm831x_spi_probe
,
159 .remove
= __devexit_p(wm831x_spi_remove
),
162 static struct spi_driver wm8320_spi_driver
= {
165 .bus
= &spi_bus_type
,
166 .owner
= THIS_MODULE
,
167 .pm
= &wm831x_spi_pm
,
169 .probe
= wm831x_spi_probe
,
170 .remove
= __devexit_p(wm831x_spi_remove
),
173 static struct spi_driver wm8321_spi_driver
= {
176 .bus
= &spi_bus_type
,
177 .owner
= THIS_MODULE
,
178 .pm
= &wm831x_spi_pm
,
180 .probe
= wm831x_spi_probe
,
181 .remove
= __devexit_p(wm831x_spi_remove
),
184 static struct spi_driver wm8325_spi_driver
= {
187 .bus
= &spi_bus_type
,
188 .owner
= THIS_MODULE
,
189 .pm
= &wm831x_spi_pm
,
191 .probe
= wm831x_spi_probe
,
192 .remove
= __devexit_p(wm831x_spi_remove
),
195 static struct spi_driver wm8326_spi_driver
= {
198 .bus
= &spi_bus_type
,
199 .owner
= THIS_MODULE
,
200 .pm
= &wm831x_spi_pm
,
202 .probe
= wm831x_spi_probe
,
203 .remove
= __devexit_p(wm831x_spi_remove
),
206 static int __init
wm831x_spi_init(void)
210 ret
= spi_register_driver(&wm8310_spi_driver
);
212 pr_err("Failed to register WM8310 SPI driver: %d\n", ret
);
214 ret
= spi_register_driver(&wm8311_spi_driver
);
216 pr_err("Failed to register WM8311 SPI driver: %d\n", ret
);
218 ret
= spi_register_driver(&wm8312_spi_driver
);
220 pr_err("Failed to register WM8312 SPI driver: %d\n", ret
);
222 ret
= spi_register_driver(&wm8320_spi_driver
);
224 pr_err("Failed to register WM8320 SPI driver: %d\n", ret
);
226 ret
= spi_register_driver(&wm8321_spi_driver
);
228 pr_err("Failed to register WM8321 SPI driver: %d\n", ret
);
230 ret
= spi_register_driver(&wm8325_spi_driver
);
232 pr_err("Failed to register WM8325 SPI driver: %d\n", ret
);
234 ret
= spi_register_driver(&wm8326_spi_driver
);
236 pr_err("Failed to register WM8326 SPI driver: %d\n", ret
);
240 subsys_initcall(wm831x_spi_init
);
242 static void __exit
wm831x_spi_exit(void)
244 spi_unregister_driver(&wm8326_spi_driver
);
245 spi_unregister_driver(&wm8325_spi_driver
);
246 spi_unregister_driver(&wm8321_spi_driver
);
247 spi_unregister_driver(&wm8320_spi_driver
);
248 spi_unregister_driver(&wm8312_spi_driver
);
249 spi_unregister_driver(&wm8311_spi_driver
);
250 spi_unregister_driver(&wm8310_spi_driver
);
252 module_exit(wm831x_spi_exit
);
254 MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
255 MODULE_LICENSE("GPL");
256 MODULE_AUTHOR("Mark Brown");