Merge tag 'optee-supplicant-fix-for-v6.7' of git://git.linaro.org:/people/jens.wiklan...
[linux-block.git] / drivers / mfd / wm831x-spi.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
2aa13b9e
MB
2/*
3 * wm831x-spi.c -- SPI access for Wolfson WM831x PMICs
4 *
5 * Copyright 2009,2010 Wolfson Microelectronics PLC.
6 *
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
2aa13b9e
MB
8 */
9
10#include <linux/kernel.h>
e85c5f0a 11#include <linux/init.h>
f6dd8449 12#include <linux/of.h>
87d1906d 13#include <linux/pm.h>
2aa13b9e 14#include <linux/spi/spi.h>
1df5981b
MB
15#include <linux/regmap.h>
16#include <linux/err.h>
2aa13b9e
MB
17
18#include <linux/mfd/wm831x/core.h>
19
f791be49 20static int wm831x_spi_probe(struct spi_device *spi)
2aa13b9e 21{
f6dd8449 22 struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
2aa13b9e
MB
23 struct wm831x *wm831x;
24 enum wm831x_parent type;
1df5981b 25 int ret;
2aa13b9e 26
15d71e67
RH
27 type = (uintptr_t)spi_get_device_match_data(spi);
28 if (!type) {
29 dev_err(&spi->dev, "Failed to match device\n");
30 return -ENODEV;
f6dd8449 31 }
2aa13b9e 32
d48cbb74 33 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
2aa13b9e
MB
34 if (wm831x == NULL)
35 return -ENOMEM;
36
2aa13b9e
MB
37 spi->mode = SPI_MODE_0;
38
0c0d2ab0 39 spi_set_drvdata(spi, wm831x);
2aa13b9e 40 wm831x->dev = &spi->dev;
f6dd8449 41 wm831x->type = type;
1df5981b 42
130a7032 43 wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
1df5981b
MB
44 if (IS_ERR(wm831x->regmap)) {
45 ret = PTR_ERR(wm831x->regmap);
46 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
47 ret);
1df5981b
MB
48 return ret;
49 }
2aa13b9e 50
f6dd8449
CK
51 if (pdata)
52 memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
53
54 return wm831x_device_init(wm831x, spi->irq);
2aa13b9e
MB
55}
56
87d1906d 57static int wm831x_spi_suspend(struct device *dev)
2aa13b9e 58{
87d1906d 59 struct wm831x *wm831x = dev_get_drvdata(dev);
2aa13b9e
MB
60
61 return wm831x_device_suspend(wm831x);
62}
63
b9736a16 64static int wm831x_spi_poweroff(struct device *dev)
523d9cfb 65{
b9736a16 66 struct wm831x *wm831x = dev_get_drvdata(dev);
523d9cfb
MB
67
68 wm831x_device_shutdown(wm831x);
b9736a16
MB
69
70 return 0;
523d9cfb
MB
71}
72
87d1906d
MB
73static const struct dev_pm_ops wm831x_spi_pm = {
74 .freeze = wm831x_spi_suspend,
75 .suspend = wm831x_spi_suspend,
b9736a16 76 .poweroff = wm831x_spi_poweroff,
87d1906d
MB
77};
78
5570c2f7
MB
79static const struct spi_device_id wm831x_spi_ids[] = {
80 { "wm8310", WM8310 },
81 { "wm8311", WM8311 },
82 { "wm8312", WM8312 },
83 { "wm8320", WM8320 },
84 { "wm8321", WM8321 },
85 { "wm8325", WM8325 },
86 { "wm8326", WM8326 },
87 { },
2aa13b9e
MB
88};
89
5570c2f7 90static struct spi_driver wm831x_spi_driver = {
2aa13b9e 91 .driver = {
5570c2f7 92 .name = "wm831x",
87d1906d 93 .pm = &wm831x_spi_pm,
f6dd8449 94 .of_match_table = of_match_ptr(wm831x_of_match),
e85c5f0a 95 .suppress_bind_attrs = true,
412dc11d 96 },
5570c2f7 97 .id_table = wm831x_spi_ids,
412dc11d 98 .probe = wm831x_spi_probe,
412dc11d
MB
99};
100
2aa13b9e
MB
101static int __init wm831x_spi_init(void)
102{
103 int ret;
104
5570c2f7 105 ret = spi_register_driver(&wm831x_spi_driver);
412dc11d 106 if (ret != 0)
5570c2f7 107 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
412dc11d 108
2aa13b9e
MB
109 return 0;
110}
111subsys_initcall(wm831x_spi_init);