net: korina: Fix NAPI versus resources freeing
[GitHub/mt8127/android_kernel_alcatel_ttab.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>
87d1906d 17#include <linux/pm.h>
2aa13b9e 18#include <linux/spi/spi.h>
1df5981b
MB
19#include <linux/regmap.h>
20#include <linux/err.h>
2aa13b9e
MB
21
22#include <linux/mfd/wm831x/core.h>
23
f791be49 24static int wm831x_spi_probe(struct spi_device *spi)
2aa13b9e 25{
5570c2f7 26 const struct spi_device_id *id = spi_get_device_id(spi);
2aa13b9e
MB
27 struct wm831x *wm831x;
28 enum wm831x_parent type;
1df5981b 29 int ret;
2aa13b9e 30
5570c2f7 31 type = (enum wm831x_parent)id->driver_data;
2aa13b9e 32
d48cbb74 33 wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
2aa13b9e
MB
34 if (wm831x == NULL)
35 return -ENOMEM;
36
37 spi->bits_per_word = 16;
38 spi->mode = SPI_MODE_0;
39
0c0d2ab0 40 spi_set_drvdata(spi, wm831x);
2aa13b9e 41 wm831x->dev = &spi->dev;
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
MB
50
51 return wm831x_device_init(wm831x, type, spi->irq);
52}
53
4740f73f 54static int wm831x_spi_remove(struct spi_device *spi)
2aa13b9e 55{
0c0d2ab0 56 struct wm831x *wm831x = spi_get_drvdata(spi);
2aa13b9e
MB
57
58 wm831x_device_exit(wm831x);
59
60 return 0;
61}
62
87d1906d 63static int wm831x_spi_suspend(struct device *dev)
2aa13b9e 64{
87d1906d 65 struct wm831x *wm831x = dev_get_drvdata(dev);
2aa13b9e
MB
66
67 return wm831x_device_suspend(wm831x);
68}
69
523d9cfb
MB
70static void wm831x_spi_shutdown(struct spi_device *spi)
71{
0c0d2ab0 72 struct wm831x *wm831x = spi_get_drvdata(spi);
523d9cfb
MB
73
74 wm831x_device_shutdown(wm831x);
75}
76
87d1906d
MB
77static const struct dev_pm_ops wm831x_spi_pm = {
78 .freeze = wm831x_spi_suspend,
79 .suspend = wm831x_spi_suspend,
80};
81
5570c2f7
MB
82static const struct spi_device_id wm831x_spi_ids[] = {
83 { "wm8310", WM8310 },
84 { "wm8311", WM8311 },
85 { "wm8312", WM8312 },
86 { "wm8320", WM8320 },
87 { "wm8321", WM8321 },
88 { "wm8325", WM8325 },
89 { "wm8326", WM8326 },
90 { },
2aa13b9e 91};
fe2afaa5 92MODULE_DEVICE_TABLE(spi, wm831x_spi_ids);
2aa13b9e 93
5570c2f7 94static struct spi_driver wm831x_spi_driver = {
2aa13b9e 95 .driver = {
5570c2f7 96 .name = "wm831x",
412dc11d 97 .owner = THIS_MODULE,
87d1906d 98 .pm = &wm831x_spi_pm,
412dc11d 99 },
5570c2f7 100 .id_table = wm831x_spi_ids,
412dc11d 101 .probe = wm831x_spi_probe,
84449216 102 .remove = wm831x_spi_remove,
523d9cfb 103 .shutdown = wm831x_spi_shutdown,
412dc11d
MB
104};
105
2aa13b9e
MB
106static int __init wm831x_spi_init(void)
107{
108 int ret;
109
5570c2f7 110 ret = spi_register_driver(&wm831x_spi_driver);
412dc11d 111 if (ret != 0)
5570c2f7 112 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
412dc11d 113
2aa13b9e
MB
114 return 0;
115}
116subsys_initcall(wm831x_spi_init);
117
118static void __exit wm831x_spi_exit(void)
119{
5570c2f7 120 spi_unregister_driver(&wm831x_spi_driver);
2aa13b9e
MB
121}
122module_exit(wm831x_spi_exit);
123
124MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
125MODULE_LICENSE("GPL");
126MODULE_AUTHOR("Mark Brown");