1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * wm831x-spi.c -- SPI access for Wolfson WM831x PMICs
5 * Copyright 2009,2010 Wolfson Microelectronics PLC.
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
14 #include <linux/spi/spi.h>
15 #include <linux/regmap.h>
16 #include <linux/err.h>
18 #include <linux/mfd/wm831x/core.h>
20 static int wm831x_spi_probe(struct spi_device
*spi
)
22 struct wm831x_pdata
*pdata
= dev_get_platdata(&spi
->dev
);
23 struct wm831x
*wm831x
;
24 enum wm831x_parent type
;
27 type
= (uintptr_t)spi_get_device_match_data(spi
);
29 dev_err(&spi
->dev
, "Failed to match device\n");
33 wm831x
= devm_kzalloc(&spi
->dev
, sizeof(struct wm831x
), GFP_KERNEL
);
37 spi
->mode
= SPI_MODE_0
;
39 spi_set_drvdata(spi
, wm831x
);
40 wm831x
->dev
= &spi
->dev
;
43 wm831x
->regmap
= devm_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 memcpy(&wm831x
->pdata
, pdata
, sizeof(*pdata
));
54 return wm831x_device_init(wm831x
, spi
->irq
);
57 static int wm831x_spi_suspend(struct device
*dev
)
59 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
61 return wm831x_device_suspend(wm831x
);
64 static int wm831x_spi_poweroff(struct device
*dev
)
66 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
68 wm831x_device_shutdown(wm831x
);
73 static const struct dev_pm_ops wm831x_spi_pm
= {
74 .freeze
= wm831x_spi_suspend
,
75 .suspend
= wm831x_spi_suspend
,
76 .poweroff
= wm831x_spi_poweroff
,
79 static const struct spi_device_id wm831x_spi_ids
[] = {
90 static struct spi_driver wm831x_spi_driver
= {
94 .of_match_table
= of_match_ptr(wm831x_of_match
),
95 .suppress_bind_attrs
= true,
97 .id_table
= wm831x_spi_ids
,
98 .probe
= wm831x_spi_probe
,
101 static int __init
wm831x_spi_init(void)
105 ret
= spi_register_driver(&wm831x_spi_driver
);
107 pr_err("Failed to register WM831x SPI driver: %d\n", ret
);
111 subsys_initcall(wm831x_spi_init
);