bnxt_en: support hwrm_func_drv_unrgtr command
[linux-2.6/btrfs-unstable.git] / drivers / mfd / wm831x-spi.c
blob80482aeb246a4bd77e5828f5720b481005d365f3
1 /*
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/module.h>
17 #include <linux/pm.h>
18 #include <linux/spi/spi.h>
19 #include <linux/regmap.h>
20 #include <linux/err.h>
22 #include <linux/mfd/wm831x/core.h>
24 static int wm831x_spi_probe(struct spi_device *spi)
26 const struct spi_device_id *id = spi_get_device_id(spi);
27 struct wm831x *wm831x;
28 enum wm831x_parent type;
29 int ret;
31 type = (enum wm831x_parent)id->driver_data;
33 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
34 if (wm831x == NULL)
35 return -ENOMEM;
37 spi->mode = SPI_MODE_0;
39 spi_set_drvdata(spi, wm831x);
40 wm831x->dev = &spi->dev;
42 wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
43 if (IS_ERR(wm831x->regmap)) {
44 ret = PTR_ERR(wm831x->regmap);
45 dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
46 ret);
47 return ret;
50 return wm831x_device_init(wm831x, type, spi->irq);
53 static int wm831x_spi_remove(struct spi_device *spi)
55 struct wm831x *wm831x = spi_get_drvdata(spi);
57 wm831x_device_exit(wm831x);
59 return 0;
62 static int wm831x_spi_suspend(struct device *dev)
64 struct wm831x *wm831x = dev_get_drvdata(dev);
66 return wm831x_device_suspend(wm831x);
69 static int wm831x_spi_poweroff(struct device *dev)
71 struct wm831x *wm831x = dev_get_drvdata(dev);
73 wm831x_device_shutdown(wm831x);
75 return 0;
78 static const struct dev_pm_ops wm831x_spi_pm = {
79 .freeze = wm831x_spi_suspend,
80 .suspend = wm831x_spi_suspend,
81 .poweroff = wm831x_spi_poweroff,
84 static const struct spi_device_id wm831x_spi_ids[] = {
85 { "wm8310", WM8310 },
86 { "wm8311", WM8311 },
87 { "wm8312", WM8312 },
88 { "wm8320", WM8320 },
89 { "wm8321", WM8321 },
90 { "wm8325", WM8325 },
91 { "wm8326", WM8326 },
92 { },
94 MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
96 static struct spi_driver wm831x_spi_driver = {
97 .driver = {
98 .name = "wm831x",
99 .pm = &wm831x_spi_pm,
101 .id_table = wm831x_spi_ids,
102 .probe = wm831x_spi_probe,
103 .remove = wm831x_spi_remove,
106 static int __init wm831x_spi_init(void)
108 int ret;
110 ret = spi_register_driver(&wm831x_spi_driver);
111 if (ret != 0)
112 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
114 return 0;
116 subsys_initcall(wm831x_spi_init);
118 static void __exit wm831x_spi_exit(void)
120 spi_unregister_driver(&wm831x_spi_driver);
122 module_exit(wm831x_spi_exit);
124 MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
125 MODULE_LICENSE("GPL");
126 MODULE_AUTHOR("Mark Brown");