blob: 5fe12961cfe54dd46ffb97bb8e57a489736579b5 [file] [log] [blame]
Mark Brownc6f75622012-06-19 16:35:49 +01001/*
2 * Arizona-i2c.c -- Arizona I2C bus interface
3 *
4 * Copyright 2012 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
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/err.h>
14#include <linux/i2c.h>
15#include <linux/module.h>
16#include <linux/pm_runtime.h>
17#include <linux/regmap.h>
18#include <linux/regulator/consumer.h>
19#include <linux/slab.h>
Sachin Kamat3d6d1d12013-10-16 14:26:56 +053020#include <linux/of.h>
Mark Brownc6f75622012-06-19 16:35:49 +010021
22#include <linux/mfd/arizona/core.h>
23
24#include "arizona.h"
25
Bill Pembertonf791be42012-11-19 13:23:04 -050026static int arizona_i2c_probe(struct i2c_client *i2c,
Lee Jones942786e2014-07-02 14:28:46 +010027 const struct i2c_device_id *id)
Mark Brownc6f75622012-06-19 16:35:49 +010028{
29 struct arizona *arizona;
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010030 const struct regmap_config *regmap_config = NULL;
Lee Jones942786e2014-07-02 14:28:46 +010031 unsigned long type;
32 int ret;
Mark Brownc6f75622012-06-19 16:35:49 +010033
Mark Brownd7810092013-03-25 00:11:27 +000034 if (i2c->dev.of_node)
35 type = arizona_of_get_type(&i2c->dev);
36 else
37 type = id->driver_data;
38
39 switch (type) {
Mark Brownc6f75622012-06-19 16:35:49 +010040 case WM5102:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010041 if (IS_ENABLED(CONFIG_MFD_WM5102))
42 regmap_config = &wm5102_i2c_regmap;
Mark Brownc6f75622012-06-19 16:35:49 +010043 break;
Mark Browne102bef2012-07-10 12:37:58 +010044 case WM5110:
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +000045 case WM8280:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010046 if (IS_ENABLED(CONFIG_MFD_WM5110))
47 regmap_config = &wm5110_i2c_regmap;
Mark Browne102bef2012-07-10 12:37:58 +010048 break;
Charles Keepaxdc7d4862013-06-13 09:43:29 +010049 case WM8997:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010050 if (IS_ENABLED(CONFIG_MFD_WM8997))
51 regmap_config = &wm8997_i2c_regmap;
Charles Keepaxdc7d4862013-06-13 09:43:29 +010052 break;
Richard Fitzgerald6887b042015-07-03 16:16:35 +010053 case WM8998:
54 case WM1814:
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010055 if (IS_ENABLED(CONFIG_MFD_WM8998))
56 regmap_config = &wm8998_i2c_regmap;
Richard Fitzgerald6887b042015-07-03 16:16:35 +010057 break;
Mark Brownc6f75622012-06-19 16:35:49 +010058 default:
Richard Fitzgerald2e44e282015-10-02 13:29:15 +010059 dev_err(&i2c->dev, "Unknown device type %ld\n", type);
Mark Brownc6f75622012-06-19 16:35:49 +010060 return -EINVAL;
61 }
62
Richard Fitzgeraldb61c1ec2015-10-02 13:29:14 +010063 if (!regmap_config) {
64 dev_err(&i2c->dev,
65 "No kernel support for device type %ld\n", type);
66 return -EINVAL;
67 }
68
Mark Brownc6f75622012-06-19 16:35:49 +010069 arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL);
70 if (arizona == NULL)
71 return -ENOMEM;
72
73 arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config);
74 if (IS_ERR(arizona->regmap)) {
75 ret = PTR_ERR(arizona->regmap);
76 dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
77 ret);
78 return ret;
79 }
80
Richard Fitzgerald2e44e282015-10-02 13:29:15 +010081 arizona->type = type;
Mark Brownc6f75622012-06-19 16:35:49 +010082 arizona->dev = &i2c->dev;
83 arizona->irq = i2c->irq;
84
85 return arizona_dev_init(arizona);
86}
87
Bill Pemberton4740f732012-11-19 13:26:01 -050088static int arizona_i2c_remove(struct i2c_client *i2c)
Mark Brownc6f75622012-06-19 16:35:49 +010089{
90 struct arizona *arizona = dev_get_drvdata(&i2c->dev);
Lee Jones9f6e8722015-10-28 13:54:07 +000091
Mark Brownc6f75622012-06-19 16:35:49 +010092 arizona_dev_exit(arizona);
Lee Jones9f6e8722015-10-28 13:54:07 +000093
Mark Brownc6f75622012-06-19 16:35:49 +010094 return 0;
95}
96
97static const struct i2c_device_id arizona_i2c_id[] = {
98 { "wm5102", WM5102 },
Mark Browne102bef2012-07-10 12:37:58 +010099 { "wm5110", WM5110 },
Richard Fitzgeralde5d4ef02015-01-17 15:21:22 +0000100 { "wm8280", WM8280 },
Charles Keepaxdc7d4862013-06-13 09:43:29 +0100101 { "wm8997", WM8997 },
Richard Fitzgerald6887b042015-07-03 16:16:35 +0100102 { "wm8998", WM8998 },
103 { "wm1814", WM1814 },
Mark Brownc6f75622012-06-19 16:35:49 +0100104 { }
105};
106MODULE_DEVICE_TABLE(i2c, arizona_i2c_id);
107
108static struct i2c_driver arizona_i2c_driver = {
109 .driver = {
110 .name = "arizona",
Mark Brownc6f75622012-06-19 16:35:49 +0100111 .pm = &arizona_pm_ops,
Mark Brownd7810092013-03-25 00:11:27 +0000112 .of_match_table = of_match_ptr(arizona_of_match),
Mark Brownc6f75622012-06-19 16:35:49 +0100113 },
114 .probe = arizona_i2c_probe,
Bill Pemberton84449212012-11-19 13:20:24 -0500115 .remove = arizona_i2c_remove,
Mark Brownc6f75622012-06-19 16:35:49 +0100116 .id_table = arizona_i2c_id,
117};
118
119module_i2c_driver(arizona_i2c_driver);
120
121MODULE_DESCRIPTION("Arizona I2C bus interface");
122MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
123MODULE_LICENSE("GPL");