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>
17 #include <linux/spi/spi.h>
19 #include <linux/mfd/wm831x/core.h>
21 static int wm831x_spi_read_device(struct wm831x
*wm831x
, unsigned short reg
,
22 int bytes
, void *dest
)
28 /* Go register at a time */
29 for (r
= reg
; r
< reg
+ (bytes
/ 2); r
++) {
32 ret
= spi_write_then_read(wm831x
->control_data
,
33 (u8
*)&tx_val
, 2, (u8
*)d
, 2);
45 static int wm831x_spi_write_device(struct wm831x
*wm831x
, unsigned short reg
,
48 struct spi_device
*spi
= wm831x
->control_data
;
53 /* Go register at a time */
54 for (r
= reg
; r
< reg
+ (bytes
/ 2); r
++) {
58 ret
= spi_write(spi
, (char *)&data
, sizeof(data
));
66 static int __devinit
wm831x_spi_probe(struct spi_device
*spi
)
68 struct wm831x
*wm831x
;
69 enum wm831x_parent type
;
71 /* Currently SPI support for ID tables is unmerged, we're faking it */
72 if (strcmp(spi
->modalias
, "wm8310") == 0)
74 else if (strcmp(spi
->modalias
, "wm8311") == 0)
76 else if (strcmp(spi
->modalias
, "wm8312") == 0)
78 else if (strcmp(spi
->modalias
, "wm8320") == 0)
80 else if (strcmp(spi
->modalias
, "wm8321") == 0)
82 else if (strcmp(spi
->modalias
, "wm8325") == 0)
85 dev_err(&spi
->dev
, "Unknown device type\n");
89 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
93 spi
->bits_per_word
= 16;
94 spi
->mode
= SPI_MODE_0
;
96 dev_set_drvdata(&spi
->dev
, wm831x
);
97 wm831x
->dev
= &spi
->dev
;
98 wm831x
->control_data
= spi
;
99 wm831x
->read_dev
= wm831x_spi_read_device
;
100 wm831x
->write_dev
= wm831x_spi_write_device
;
102 return wm831x_device_init(wm831x
, type
, spi
->irq
);
105 static int __devexit
wm831x_spi_remove(struct spi_device
*spi
)
107 struct wm831x
*wm831x
= dev_get_drvdata(&spi
->dev
);
109 wm831x_device_exit(wm831x
);
114 static int wm831x_spi_suspend(struct spi_device
*spi
, pm_message_t m
)
116 struct wm831x
*wm831x
= dev_get_drvdata(&spi
->dev
);
118 return wm831x_device_suspend(wm831x
);
121 static struct spi_driver wm8310_spi_driver
= {
124 .bus
= &spi_bus_type
,
125 .owner
= THIS_MODULE
,
127 .probe
= wm831x_spi_probe
,
128 .remove
= __devexit_p(wm831x_spi_remove
),
129 .suspend
= wm831x_spi_suspend
,
132 static struct spi_driver wm8311_spi_driver
= {
135 .bus
= &spi_bus_type
,
136 .owner
= THIS_MODULE
,
138 .probe
= wm831x_spi_probe
,
139 .remove
= __devexit_p(wm831x_spi_remove
),
140 .suspend
= wm831x_spi_suspend
,
143 static struct spi_driver wm8312_spi_driver
= {
146 .bus
= &spi_bus_type
,
147 .owner
= THIS_MODULE
,
149 .probe
= wm831x_spi_probe
,
150 .remove
= __devexit_p(wm831x_spi_remove
),
151 .suspend
= wm831x_spi_suspend
,
154 static struct spi_driver wm8320_spi_driver
= {
157 .bus
= &spi_bus_type
,
158 .owner
= THIS_MODULE
,
160 .probe
= wm831x_spi_probe
,
161 .remove
= __devexit_p(wm831x_spi_remove
),
162 .suspend
= wm831x_spi_suspend
,
165 static struct spi_driver wm8321_spi_driver
= {
168 .bus
= &spi_bus_type
,
169 .owner
= THIS_MODULE
,
171 .probe
= wm831x_spi_probe
,
172 .remove
= __devexit_p(wm831x_spi_remove
),
173 .suspend
= wm831x_spi_suspend
,
176 static struct spi_driver wm8325_spi_driver
= {
179 .bus
= &spi_bus_type
,
180 .owner
= THIS_MODULE
,
182 .probe
= wm831x_spi_probe
,
183 .remove
= __devexit_p(wm831x_spi_remove
),
184 .suspend
= wm831x_spi_suspend
,
187 static int __init
wm831x_spi_init(void)
191 ret
= spi_register_driver(&wm8310_spi_driver
);
193 pr_err("Failed to register WM8310 SPI driver: %d\n", ret
);
195 ret
= spi_register_driver(&wm8311_spi_driver
);
197 pr_err("Failed to register WM8311 SPI driver: %d\n", ret
);
199 ret
= spi_register_driver(&wm8312_spi_driver
);
201 pr_err("Failed to register WM8312 SPI driver: %d\n", ret
);
203 ret
= spi_register_driver(&wm8320_spi_driver
);
205 pr_err("Failed to register WM8320 SPI driver: %d\n", ret
);
207 ret
= spi_register_driver(&wm8321_spi_driver
);
209 pr_err("Failed to register WM8321 SPI driver: %d\n", ret
);
211 ret
= spi_register_driver(&wm8325_spi_driver
);
213 pr_err("Failed to register WM8325 SPI driver: %d\n", ret
);
217 subsys_initcall(wm831x_spi_init
);
219 static void __exit
wm831x_spi_exit(void)
221 spi_unregister_driver(&wm8325_spi_driver
);
222 spi_unregister_driver(&wm8321_spi_driver
);
223 spi_unregister_driver(&wm8320_spi_driver
);
224 spi_unregister_driver(&wm8312_spi_driver
);
225 spi_unregister_driver(&wm8311_spi_driver
);
226 spi_unregister_driver(&wm8310_spi_driver
);
228 module_exit(wm831x_spi_exit
);
230 MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
231 MODULE_LICENSE("GPL");
232 MODULE_AUTHOR("Mark Brown");