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>
19 #include <linux/regmap.h>
20 #include <linux/err.h>
22 #include <linux/mfd/wm831x/core.h>
24 static int __devinit
wm831x_spi_probe(struct spi_device
*spi
)
26 const struct spi_device_id
*id
= spi_get_device_id(spi
);
27 struct wm831x
*wm831x
;
28 enum wm831x_parent type
;
31 type
= (enum wm831x_parent
)id
->driver_data
;
33 wm831x
= kzalloc(sizeof(struct wm831x
), GFP_KERNEL
);
37 spi
->bits_per_word
= 16;
38 spi
->mode
= SPI_MODE_0
;
40 dev_set_drvdata(&spi
->dev
, wm831x
);
41 wm831x
->dev
= &spi
->dev
;
43 wm831x
->regmap
= regmap_init_spi(spi
, &wm831x_regmap_config
);
44 if (IS_ERR(wm831x
->regmap
)) {
45 ret
= PTR_ERR(wm831x
->regmap
);
46 dev_err(wm831x
->dev
, "Failed to allocate register map: %d\n",
52 return wm831x_device_init(wm831x
, type
, spi
->irq
);
55 static int __devexit
wm831x_spi_remove(struct spi_device
*spi
)
57 struct wm831x
*wm831x
= dev_get_drvdata(&spi
->dev
);
59 wm831x_device_exit(wm831x
);
64 static int wm831x_spi_suspend(struct device
*dev
)
66 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
68 return wm831x_device_suspend(wm831x
);
71 static void wm831x_spi_shutdown(struct spi_device
*spi
)
73 struct wm831x
*wm831x
= dev_get_drvdata(&spi
->dev
);
75 wm831x_device_shutdown(wm831x
);
78 static const struct dev_pm_ops wm831x_spi_pm
= {
79 .freeze
= wm831x_spi_suspend
,
80 .suspend
= wm831x_spi_suspend
,
83 static const struct spi_device_id wm831x_spi_ids
[] = {
93 MODULE_DEVICE_TABLE(spi
, wm831x_spi_id
);
95 static struct spi_driver wm831x_spi_driver
= {
100 .pm
= &wm831x_spi_pm
,
102 .id_table
= wm831x_spi_ids
,
103 .probe
= wm831x_spi_probe
,
104 .remove
= __devexit_p(wm831x_spi_remove
),
105 .shutdown
= wm831x_spi_shutdown
,
108 static int __init
wm831x_spi_init(void)
112 ret
= spi_register_driver(&wm831x_spi_driver
);
114 pr_err("Failed to register WM831x SPI driver: %d\n", ret
);
118 subsys_initcall(wm831x_spi_init
);
120 static void __exit
wm831x_spi_exit(void)
122 spi_unregister_driver(&wm831x_spi_driver
);
124 module_exit(wm831x_spi_exit
);
126 MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
127 MODULE_LICENSE("GPL");
128 MODULE_AUTHOR("Mark Brown");