blob: 2633e147b76c2da975225a98577be8e85cb97d92 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Mark Browna15123c2012-06-19 16:36:18 +01002/*
3 * arizona-spi.c -- Arizona SPI bus interface
4 *
5 * Copyright 2012 Wolfson Microelectronics plc
6 *
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
Mark Browna15123c2012-06-19 16:36:18 +01008 */
9
10#include <linux/err.h>
11#include <linux/module.h>
12#include <linux/pm_runtime.h>
13#include <linux/regmap.h>
14#include <linux/regulator/consumer.h>
15#include <linux/slab.h>
16#include <linux/spi/spi.h>
Sachin Kamat3d6d1d12013-10-16 14:26:56 +053017#include <linux/of.h>
Mark Browna15123c2012-06-19 16:36:18 +010018
19#include <linux/mfd/arizona/core.h>
20
21#include "arizona.h"
22
Bill Pembertonf791be42012-11-19 13:23:04 -050023static int arizona_spi_probe(struct spi_device *spi)
Mark Browna15123c2012-06-19 16:36:18 +010024{
25 const struct spi_device_id *id = spi_get_device_id(spi);
26 struct arizona *arizona;
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010027 const struct regmap_config *regmap_config = NULL;
Lee Jones942786e2014-07-02 14:28:46 +010028 unsigned long type;
29 int ret;
Mark Browna15123c2012-06-19 16:36:18 +010030
Mark Brownd7810092013-03-25 00:11:27 +000031 if (spi->dev.of_node)
32 type = arizona_of_get_type(&spi->dev);
33 else
34 type = id->driver_data;
35
36 switch (type) {
Mark Browna15123c2012-06-19 16:36:18 +010037 case WM5102:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010038 if (IS_ENABLED(CONFIG_MFD_WM5102))
39 regmap_config = &wm5102_spi_regmap;
Mark Browna15123c2012-06-19 16:36:18 +010040 break;
Mark Browne102bef2012-07-10 12:37:58 +010041 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +000042 case WM8280:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010043 if (IS_ENABLED(CONFIG_MFD_WM5110))
44 regmap_config = &wm5110_spi_regmap;
Mark Browne102bef2012-07-10 12:37:58 +010045 break;
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +000046 case WM1831:
47 case CS47L24:
48 if (IS_ENABLED(CONFIG_MFD_CS47L24))
49 regmap_config = &cs47l24_spi_regmap;
50 break;
Mark Browna15123c2012-06-19 16:36:18 +010051 default:
Richard Fitzgerald2e44e282015-10-02 13:29:15 +010052 dev_err(&spi->dev, "Unknown device type %ld\n", type);
Mark Browna15123c2012-06-19 16:36:18 +010053 return -EINVAL;
54 }
55
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010056 if (!regmap_config) {
57 dev_err(&spi->dev,
58 "No kernel support for device type %ld\n", type);
Mark Browna15123c2012-06-19 16:36:18 +010059 return -EINVAL;
60 }
61
62 arizona = devm_kzalloc(&spi->dev, sizeof(*arizona), GFP_KERNEL);
63 if (arizona == NULL)
64 return -ENOMEM;
65
66 arizona->regmap = devm_regmap_init_spi(spi, regmap_config);
67 if (IS_ERR(arizona->regmap)) {
68 ret = PTR_ERR(arizona->regmap);
69 dev_err(&spi->dev, "Failed to allocate register map: %d\n",
70 ret);
71 return ret;
72 }
73
Richard Fitzgerald2e44e282015-10-02 13:29:15 +010074 arizona->type = type;
Mark Browna15123c2012-06-19 16:36:18 +010075 arizona->dev = &spi->dev;
76 arizona->irq = spi->irq;
77
78 return arizona_dev_init(arizona);
79}
80
Bill Pemberton4740f732012-11-19 13:26:01 -050081static int arizona_spi_remove(struct spi_device *spi)
Mark Browna15123c2012-06-19 16:36:18 +010082{
Jingoo Hane9642d52013-04-06 15:44:30 +090083 struct arizona *arizona = spi_get_drvdata(spi);
Will Sheppard6f467e52014-10-15 09:38:47 +010084
Mark Browna15123c2012-06-19 16:36:18 +010085 arizona_dev_exit(arizona);
Will Sheppard6f467e52014-10-15 09:38:47 +010086
Mark Browna15123c2012-06-19 16:36:18 +010087 return 0;
88}
89
90static const struct spi_device_id arizona_spi_ids[] = {
91 { "wm5102", WM5102 },
Mark Browne102bef2012-07-10 12:37:58 +010092 { "wm5110", WM5110 },
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +000093 { "wm8280", WM8280 },
Richard Fitzgeraldea1f3332015-11-03 15:08:32 +000094 { "wm1831", WM1831 },
95 { "cs47l24", CS47L24 },
Mark Browna15123c2012-06-19 16:36:18 +010096 { },
97};
98MODULE_DEVICE_TABLE(spi, arizona_spi_ids);
99
100static struct spi_driver arizona_spi_driver = {
101 .driver = {
102 .name = "arizona",
Mark Browna15123c2012-06-19 16:36:18 +0100103 .pm = &arizona_pm_ops,
Mark Brownd7810092013-03-25 00:11:27 +0000104 .of_match_table = of_match_ptr(arizona_of_match),
Mark Browna15123c2012-06-19 16:36:18 +0100105 },
106 .probe = arizona_spi_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500107 .remove = arizona_spi_remove,
Mark Browna15123c2012-06-19 16:36:18 +0100108 .id_table = arizona_spi_ids,
109};
110
111module_spi_driver(arizona_spi_driver);
112
113MODULE_DESCRIPTION("Arizona SPI bus interface");
114MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
115MODULE_LICENSE("GPL");