mfd: cs47l15: Fix an update made to patch file
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / drivers / mfd / wm831x-spi.c
CommitLineData
2aa13b9e
MB
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>
f6dd8449
CK
17#include <linux/of.h>
18#include <linux/of_device.h>
87d1906d 19#include <linux/pm.h>
2aa13b9e 20#include <linux/spi/spi.h>
1df5981b
MB
21#include <linux/regmap.h>
22#include <linux/err.h>
2aa13b9e
MB
23
24#include <linux/mfd/wm831x/core.h>
25
f791be49 26static int wm831x_spi_probe(struct spi_device *spi)
2aa13b9e 27{
f6dd8449 28 struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
5570c2f7 29 const struct spi_device_id *id = spi_get_device_id(spi);
f6dd8449 30 const struct of_device_id *of_id;
2aa13b9e
MB
31 struct wm831x *wm831x;
32 enum wm831x_parent type;
1df5981b 33 int ret;
2aa13b9e 34
f6dd8449
CK
35 if (spi->dev.of_node) {
36 of_id = of_match_device(wm831x_of_match, &spi->dev);
7b55033f
GS
37 if (!of_id) {
38 dev_err(&spi->dev, "Failed to match device\n");
39 return -ENODEV;
40 }
f6dd8449
CK
41 type = (enum wm831x_parent)of_id->data;
42 } else {
43 type = (enum wm831x_parent)id->driver_data;
44 }
2aa13b9e 45
d48cbb74 46 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
2aa13b9e
MB
47 if (wm831x == NULL)
48 return -ENOMEM;
49
2aa13b9e
MB
50 spi->mode = SPI_MODE_0;
51
0c0d2ab0 52 spi_set_drvdata(spi, wm831x);
2aa13b9e 53 wm831x->dev = &spi->dev;
f6dd8449 54 wm831x->type = type;
1df5981b 55
130a7032 56 wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
1df5981b
MB
57 if (IS_ERR(wm831x->regmap)) {
58 ret = PTR_ERR(wm831x->regmap);
59 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
60 ret);
1df5981b
MB
61 return ret;
62 }
2aa13b9e 63
f6dd8449
CK
64 if (pdata)
65 memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
66
67 return wm831x_device_init(wm831x, spi->irq);
2aa13b9e
MB
68}
69
4740f73f 70static int wm831x_spi_remove(struct spi_device *spi)
2aa13b9e 71{
0c0d2ab0 72 struct wm831x *wm831x = spi_get_drvdata(spi);
2aa13b9e
MB
73
74 wm831x_device_exit(wm831x);
75
76 return 0;
77}
78
87d1906d 79static int wm831x_spi_suspend(struct device *dev)
2aa13b9e 80{
87d1906d 81 struct wm831x *wm831x = dev_get_drvdata(dev);
2aa13b9e
MB
82
83 return wm831x_device_suspend(wm831x);
84}
85
b9736a16 86static int wm831x_spi_poweroff(struct device *dev)
523d9cfb 87{
b9736a16 88 struct wm831x *wm831x = dev_get_drvdata(dev);
523d9cfb
MB
89
90 wm831x_device_shutdown(wm831x);
b9736a16
MB
91
92 return 0;
523d9cfb
MB
93}
94
87d1906d
MB
95static const struct dev_pm_ops wm831x_spi_pm = {
96 .freeze = wm831x_spi_suspend,
97 .suspend = wm831x_spi_suspend,
b9736a16 98 .poweroff = wm831x_spi_poweroff,
87d1906d
MB
99};
100
5570c2f7
MB
101static const struct spi_device_id wm831x_spi_ids[] = {
102 { "wm8310", WM8310 },
103 { "wm8311", WM8311 },
104 { "wm8312", WM8312 },
105 { "wm8320", WM8320 },
106 { "wm8321", WM8321 },
107 { "wm8325", WM8325 },
108 { "wm8326", WM8326 },
109 { },
2aa13b9e 110};
fe2afaa5 111MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
2aa13b9e 112
5570c2f7 113static struct spi_driver wm831x_spi_driver = {
2aa13b9e 114 .driver = {
5570c2f7 115 .name = "wm831x",
87d1906d 116 .pm = &wm831x_spi_pm,
f6dd8449 117 .of_match_table = of_match_ptr(wm831x_of_match),
412dc11d 118 },
5570c2f7 119 .id_table = wm831x_spi_ids,
412dc11d 120 .probe = wm831x_spi_probe,
84449216 121 .remove = wm831x_spi_remove,
412dc11d
MB
122};
123
2aa13b9e
MB
124static int __init wm831x_spi_init(void)
125{
126 int ret;
127
5570c2f7 128 ret = spi_register_driver(&wm831x_spi_driver);
412dc11d 129 if (ret != 0)
5570c2f7 130 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
412dc11d 131
2aa13b9e
MB
132 return 0;
133}
134subsys_initcall(wm831x_spi_init);
135
136static void __exit wm831x_spi_exit(void)
137{
5570c2f7 138 spi_unregister_driver(&wm831x_spi_driver);
2aa13b9e
MB
139}
140module_exit(wm831x_spi_exit);
141
142MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
143MODULE_LICENSE("GPL");
144MODULE_AUTHOR("Mark Brown");