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/init.h>
18 #include <linux/of_device.h>
20 #include <linux/spi/spi.h>
21 #include <linux/regmap.h>
22 #include <linux/err.h>
24 #include <linux/mfd/wm831x/core.h>
26 static int wm831x_spi_probe(struct spi_device
*spi
)
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
;
35 if (spi
->dev
.of_node
) {
36 of_id
= of_match_device(wm831x_of_match
, &spi
->dev
);
38 dev_err(&spi
->dev
, "Failed to match device\n");
41 type
= (enum wm831x_parent
)of_id
->data
;
43 type
= (enum wm831x_parent
)id
->driver_data
;
46 wm831x
= devm_kzalloc(&spi
->dev
, sizeof(struct wm831x
), GFP_KERNEL
);
50 spi
->mode
= SPI_MODE_0
;
52 spi_set_drvdata(spi
, wm831x
);
53 wm831x
->dev
= &spi
->dev
;
56 wm831x
->regmap
= devm_regmap_init_spi(spi
, &wm831x_regmap_config
);
57 if (IS_ERR(wm831x
->regmap
)) {
58 ret
= PTR_ERR(wm831x
->regmap
);
59 dev_err(wm831x
->dev
, "Failed to allocate register map: %d\n",
65 memcpy(&wm831x
->pdata
, pdata
, sizeof(*pdata
));
67 return wm831x_device_init(wm831x
, spi
->irq
);
70 static int wm831x_spi_suspend(struct device
*dev
)
72 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
74 return wm831x_device_suspend(wm831x
);
77 static int wm831x_spi_poweroff(struct device
*dev
)
79 struct wm831x
*wm831x
= dev_get_drvdata(dev
);
81 wm831x_device_shutdown(wm831x
);
86 static const struct dev_pm_ops wm831x_spi_pm
= {
87 .freeze
= wm831x_spi_suspend
,
88 .suspend
= wm831x_spi_suspend
,
89 .poweroff
= wm831x_spi_poweroff
,
92 static const struct spi_device_id wm831x_spi_ids
[] = {
103 static struct spi_driver wm831x_spi_driver
= {
106 .pm
= &wm831x_spi_pm
,
107 .of_match_table
= of_match_ptr(wm831x_of_match
),
108 .suppress_bind_attrs
= true,
110 .id_table
= wm831x_spi_ids
,
111 .probe
= wm831x_spi_probe
,
114 static int __init
wm831x_spi_init(void)
118 ret
= spi_register_driver(&wm831x_spi_driver
);
120 pr_err("Failed to register WM831x SPI driver: %d\n", ret
);
124 subsys_initcall(wm831x_spi_init
);