Blame view
drivers/mfd/arizona-i2c.c
2.79 KB
c6f756223
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/* * Arizona-i2c.c -- Arizona I2C bus interface * * Copyright 2012 Wolfson Microelectronics plc * * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/err.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> |
3d6d1d1cd
|
20 |
#include <linux/of.h> |
c6f756223
|
21 22 23 24 |
#include <linux/mfd/arizona/core.h> #include "arizona.h" |
f791be492
|
25 |
static int arizona_i2c_probe(struct i2c_client *i2c, |
942786e6e
|
26 |
const struct i2c_device_id *id) |
c6f756223
|
27 28 |
{ struct arizona *arizona; |
b61c1ec05
|
29 |
const struct regmap_config *regmap_config = NULL; |
942786e6e
|
30 31 |
unsigned long type; int ret; |
c6f756223
|
32 |
|
d781009ca
|
33 34 35 36 37 38 |
if (i2c->dev.of_node) type = arizona_of_get_type(&i2c->dev); else type = id->driver_data; switch (type) { |
c6f756223
|
39 |
case WM5102: |
b61c1ec05
|
40 41 |
if (IS_ENABLED(CONFIG_MFD_WM5102)) regmap_config = &wm5102_i2c_regmap; |
c6f756223
|
42 |
break; |
e102befe7
|
43 |
case WM5110: |
e5d4ef0d7
|
44 |
case WM8280: |
b61c1ec05
|
45 46 |
if (IS_ENABLED(CONFIG_MFD_WM5110)) regmap_config = &wm5110_i2c_regmap; |
e102befe7
|
47 |
break; |
dc7d48635
|
48 |
case WM8997: |
b61c1ec05
|
49 50 |
if (IS_ENABLED(CONFIG_MFD_WM8997)) regmap_config = &wm8997_i2c_regmap; |
dc7d48635
|
51 |
break; |
6887b042c
|
52 53 |
case WM8998: case WM1814: |
b61c1ec05
|
54 55 |
if (IS_ENABLED(CONFIG_MFD_WM8998)) regmap_config = &wm8998_i2c_regmap; |
6887b042c
|
56 |
break; |
c6f756223
|
57 |
default: |
2e44e28ad
|
58 59 |
dev_err(&i2c->dev, "Unknown device type %ld ", type); |
c6f756223
|
60 61 |
return -EINVAL; } |
b61c1ec05
|
62 63 64 65 66 67 |
if (!regmap_config) { dev_err(&i2c->dev, "No kernel support for device type %ld ", type); return -EINVAL; } |
c6f756223
|
68 69 70 71 72 73 74 75 76 77 78 79 |
arizona = devm_kzalloc(&i2c->dev, sizeof(*arizona), GFP_KERNEL); if (arizona == NULL) return -ENOMEM; arizona->regmap = devm_regmap_init_i2c(i2c, regmap_config); if (IS_ERR(arizona->regmap)) { ret = PTR_ERR(arizona->regmap); dev_err(&i2c->dev, "Failed to allocate register map: %d ", ret); return ret; } |
2e44e28ad
|
80 |
arizona->type = type; |
c6f756223
|
81 82 83 84 85 |
arizona->dev = &i2c->dev; arizona->irq = i2c->irq; return arizona_dev_init(arizona); } |
4740f73fe
|
86 |
static int arizona_i2c_remove(struct i2c_client *i2c) |
c6f756223
|
87 88 |
{ struct arizona *arizona = dev_get_drvdata(&i2c->dev); |
9f6e872a7
|
89 |
|
c6f756223
|
90 |
arizona_dev_exit(arizona); |
9f6e872a7
|
91 |
|
c6f756223
|
92 93 94 95 96 |
return 0; } static const struct i2c_device_id arizona_i2c_id[] = { { "wm5102", WM5102 }, |
e102befe7
|
97 |
{ "wm5110", WM5110 }, |
e5d4ef0d7
|
98 |
{ "wm8280", WM8280 }, |
dc7d48635
|
99 |
{ "wm8997", WM8997 }, |
6887b042c
|
100 101 |
{ "wm8998", WM8998 }, { "wm1814", WM1814 }, |
c6f756223
|
102 103 104 105 106 107 108 |
{ } }; MODULE_DEVICE_TABLE(i2c, arizona_i2c_id); static struct i2c_driver arizona_i2c_driver = { .driver = { .name = "arizona", |
c6f756223
|
109 |
.pm = &arizona_pm_ops, |
d781009ca
|
110 |
.of_match_table = of_match_ptr(arizona_of_match), |
c6f756223
|
111 112 |
}, .probe = arizona_i2c_probe, |
84449216b
|
113 |
.remove = arizona_i2c_remove, |
c6f756223
|
114 115 116 117 118 119 120 121 |
.id_table = arizona_i2c_id, }; module_i2c_driver(arizona_i2c_driver); MODULE_DESCRIPTION("Arizona I2C bus interface"); MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); MODULE_LICENSE("GPL"); |