]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/mfd/wm831x-spi.c
regmap: Allow drivers to control cache_only flag
[mirror_ubuntu-zesty-kernel.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
2aa13b9e
MB
24static int __devinit wm831x_spi_probe(struct spi_device *spi)
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
MB
32
33 wm831x = kzalloc(sizeof(struct wm831x), GFP_KERNEL);
34 if (wm831x == NULL)
35 return -ENOMEM;
36
37 spi->bits_per_word = 16;
38 spi->mode = SPI_MODE_0;
39
40 dev_set_drvdata(&spi->dev, wm831x);
41 wm831x->dev = &spi->dev;
1df5981b 42
5570c2f7 43 wm831x->regmap = 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);
48 kfree(wm831x);
49 return ret;
50 }
2aa13b9e
MB
51
52 return wm831x_device_init(wm831x, type, spi->irq);
53}
54
55static int __devexit wm831x_spi_remove(struct spi_device *spi)
56{
57 struct wm831x *wm831x = dev_get_drvdata(&spi->dev);
58
59 wm831x_device_exit(wm831x);
60
61 return 0;
62}
63
87d1906d 64static int wm831x_spi_suspend(struct device *dev)
2aa13b9e 65{
87d1906d 66 struct wm831x *wm831x = dev_get_drvdata(dev);
2aa13b9e
MB
67
68 return wm831x_device_suspend(wm831x);
69}
70
87d1906d
MB
71static const struct dev_pm_ops wm831x_spi_pm = {
72 .freeze = wm831x_spi_suspend,
73 .suspend = wm831x_spi_suspend,
74};
75
5570c2f7
MB
76static const struct spi_device_id wm831x_spi_ids[] = {
77 { "wm8310", WM8310 },
78 { "wm8311", WM8311 },
79 { "wm8312", WM8312 },
80 { "wm8320", WM8320 },
81 { "wm8321", WM8321 },
82 { "wm8325", WM8325 },
83 { "wm8326", WM8326 },
84 { },
2aa13b9e 85};
5570c2f7 86MODULE_DEVICE_TABLE(spi, wm831x_spi_id);
2aa13b9e 87
5570c2f7 88static struct spi_driver wm831x_spi_driver = {
2aa13b9e 89 .driver = {
5570c2f7 90 .name = "wm831x",
412dc11d
MB
91 .bus = &spi_bus_type,
92 .owner = THIS_MODULE,
87d1906d 93 .pm = &wm831x_spi_pm,
412dc11d 94 },
5570c2f7 95 .id_table = wm831x_spi_ids,
412dc11d
MB
96 .probe = wm831x_spi_probe,
97 .remove = __devexit_p(wm831x_spi_remove),
412dc11d
MB
98};
99
2aa13b9e
MB
100static int __init wm831x_spi_init(void)
101{
102 int ret;
103
5570c2f7 104 ret = spi_register_driver(&wm831x_spi_driver);
412dc11d 105 if (ret != 0)
5570c2f7 106 pr_err("Failed to register WM831x SPI driver: %d\n", ret);
412dc11d 107
2aa13b9e
MB
108 return 0;
109}
110subsys_initcall(wm831x_spi_init);
111
112static void __exit wm831x_spi_exit(void)
113{
5570c2f7 114 spi_unregister_driver(&wm831x_spi_driver);
2aa13b9e
MB
115}
116module_exit(wm831x_spi_exit);
117
118MODULE_DESCRIPTION("SPI support for WM831x/2x AudioPlus PMICs");
119MODULE_LICENSE("GPL");
120MODULE_AUTHOR("Mark Brown");