]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/mfd/wm831x-spi.c
perf/x86/intel: Constify the 'lbr_desc[]' array and make a function static
[karo-tx-linux.git] / drivers / mfd / wm831x-spi.c
1 /*
2  * wm831x-spi.c  --  SPI access for Wolfson WM831x PMICs
3  *
4  * Copyright 2009,2010 Wolfson Microelectronics PLC.
5  *
6  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7  *
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.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/of.h>
18 #include <linux/of_device.h>
19 #include <linux/pm.h>
20 #include <linux/spi/spi.h>
21 #include <linux/regmap.h>
22 #include <linux/err.h>
23
24 #include <linux/mfd/wm831x/core.h>
25
26 static int wm831x_spi_probe(struct spi_device *spi)
27 {
28         struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
29         const struct spi_device_id *id = spi_get_device_id(spi);
30         const struct of_device_id *of_id;
31         struct wm831x *wm831x;
32         enum wm831x_parent type;
33         int ret;
34
35         if (spi->dev.of_node) {
36                 of_id = of_match_device(wm831x_of_match, &spi->dev);
37                 type = (enum wm831x_parent)of_id->data;
38         } else {
39                 type = (enum wm831x_parent)id->driver_data;
40         }
41
42         wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
43         if (wm831x == NULL)
44                 return -ENOMEM;
45
46         spi->mode = SPI_MODE_0;
47
48         spi_set_drvdata(spi, wm831x);
49         wm831x->dev = &spi->dev;
50         wm831x->type = type;
51
52         wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
53         if (IS_ERR(wm831x->regmap)) {
54                 ret = PTR_ERR(wm831x->regmap);
55                 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
56                         ret);
57                 return ret;
58         }
59
60         if (pdata)
61                 memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
62
63         return wm831x_device_init(wm831x, spi->irq);
64 }
65
66 static int wm831x_spi_remove(struct spi_device *spi)
67 {
68         struct wm831x *wm831x = spi_get_drvdata(spi);
69
70         wm831x_device_exit(wm831x);
71
72         return 0;
73 }
74
75 static int wm831x_spi_suspend(struct device *dev)
76 {
77         struct wm831x *wm831x = dev_get_drvdata(dev);
78
79         return wm831x_device_suspend(wm831x);
80 }
81
82 static int wm831x_spi_poweroff(struct device *dev)
83 {
84         struct wm831x *wm831x = dev_get_drvdata(dev);
85
86         wm831x_device_shutdown(wm831x);
87
88         return 0;
89 }
90
91 static const struct dev_pm_ops wm831x_spi_pm = {
92         .freeze = wm831x_spi_suspend,
93         .suspend = wm831x_spi_suspend,
94         .poweroff = wm831x_spi_poweroff,
95 };
96
97 static const struct spi_device_id wm831x_spi_ids[] = {
98         { "wm8310", WM8310 },
99         { "wm8311", WM8311 },
100         { "wm8312", WM8312 },
101         { "wm8320", WM8320 },
102         { "wm8321", WM8321 },
103         { "wm8325", WM8325 },
104         { "wm8326", WM8326 },
105         { },
106 };
107 MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
108
109 static struct spi_driver wm831x_spi_driver = {
110         .driver = {
111                 .name   = "wm831x",
112                 .pm     = &wm831x_spi_pm,
113                 .of_match_table = of_match_ptr(wm831x_of_match),
114         },
115         .id_table       = wm831x_spi_ids,
116         .probe          = wm831x_spi_probe,
117         .remove         = wm831x_spi_remove,
118 };
119
120 static int __init wm831x_spi_init(void)
121 {
122         int ret;
123
124         ret = spi_register_driver(&wm831x_spi_driver);
125         if (ret != 0)
126                 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
127
128         return 0;
129 }
130 subsys_initcall(wm831x_spi_init);
131
132 static void __exit wm831x_spi_exit(void)
133 {
134         spi_unregister_driver(&wm831x_spi_driver);
135 }
136 module_exit(wm831x_spi_exit);
137
138 MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
139 MODULE_LICENSE("GPL");
140 MODULE_AUTHOR("Mark Brown");