diff options
author | Matt Porter <mporter@linaro.org> | 2014-04-23 19:21:31 -0400 |
---|---|---|
committer | Lee Jones <lee.jones@linaro.org> | 2014-05-21 05:40:08 -0400 |
commit | 9e1e726311830bc5b8b568d5178f6a52c357fb6e (patch) | |
tree | 5f408ef46701a01408da711aea838a96d5155086 /drivers/mfd/bcm590xx.c | |
parent | bb7f32fe966aa009ef6757aa08067cca3b2ac913 (diff) |
mfd: bcm590xx: Add support for secondary I2C slave address
BCM590xx utilizes a secondary I2C slave address to access additional
register space. Add support for the secondary address space by
instantiating a dummy I2C device with the appropriate secondary
I2C slave address. Also expose a secondary regmap register space so
that MFD drivers can access this secondary i2c slave address space.
Signed-off-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/bcm590xx.c')
-rw-r--r-- | drivers/mfd/bcm590xx.c | 60 |
1 files changed, 46 insertions, 14 deletions
diff --git a/drivers/mfd/bcm590xx.c b/drivers/mfd/bcm590xx.c index e9a33c79431b..43cba1a1973c 100644 --- a/drivers/mfd/bcm590xx.c +++ b/drivers/mfd/bcm590xx.c | |||
@@ -28,39 +28,71 @@ static const struct mfd_cell bcm590xx_devs[] = { | |||
28 | }, | 28 | }, |
29 | }; | 29 | }; |
30 | 30 | ||
31 | static const struct regmap_config bcm590xx_regmap_config = { | 31 | static const struct regmap_config bcm590xx_regmap_config_pri = { |
32 | .reg_bits = 8, | 32 | .reg_bits = 8, |
33 | .val_bits = 8, | 33 | .val_bits = 8, |
34 | .max_register = BCM590XX_MAX_REGISTER, | 34 | .max_register = BCM590XX_MAX_REGISTER_PRI, |
35 | .cache_type = REGCACHE_RBTREE, | 35 | .cache_type = REGCACHE_RBTREE, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | static int bcm590xx_i2c_probe(struct i2c_client *i2c, | 38 | static const struct regmap_config bcm590xx_regmap_config_sec = { |
39 | .reg_bits = 8, | ||
40 | .val_bits = 8, | ||
41 | .max_register = BCM590XX_MAX_REGISTER_SEC, | ||
42 | .cache_type = REGCACHE_RBTREE, | ||
43 | }; | ||
44 | |||
45 | static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri, | ||
39 | const struct i2c_device_id *id) | 46 | const struct i2c_device_id *id) |
40 | { | 47 | { |
41 | struct bcm590xx *bcm590xx; | 48 | struct bcm590xx *bcm590xx; |
42 | int ret; | 49 | int ret; |
43 | 50 | ||
44 | bcm590xx = devm_kzalloc(&i2c->dev, sizeof(*bcm590xx), GFP_KERNEL); | 51 | bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL); |
45 | if (!bcm590xx) | 52 | if (!bcm590xx) |
46 | return -ENOMEM; | 53 | return -ENOMEM; |
47 | 54 | ||
48 | i2c_set_clientdata(i2c, bcm590xx); | 55 | i2c_set_clientdata(i2c_pri, bcm590xx); |
49 | bcm590xx->dev = &i2c->dev; | 56 | bcm590xx->dev = &i2c_pri->dev; |
50 | bcm590xx->i2c_client = i2c; | 57 | bcm590xx->i2c_pri = i2c_pri; |
51 | 58 | ||
52 | bcm590xx->regmap = devm_regmap_init_i2c(i2c, &bcm590xx_regmap_config); | 59 | bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri, |
53 | if (IS_ERR(bcm590xx->regmap)) { | 60 | &bcm590xx_regmap_config_pri); |
54 | ret = PTR_ERR(bcm590xx->regmap); | 61 | if (IS_ERR(bcm590xx->regmap_pri)) { |
55 | dev_err(&i2c->dev, "regmap initialization failed: %d\n", ret); | 62 | ret = PTR_ERR(bcm590xx->regmap_pri); |
63 | dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret); | ||
56 | return ret; | 64 | return ret; |
57 | } | 65 | } |
58 | 66 | ||
59 | ret = mfd_add_devices(&i2c->dev, -1, bcm590xx_devs, | 67 | /* Secondary I2C slave address is the base address with A(2) asserted */ |
68 | bcm590xx->i2c_sec = i2c_new_dummy(i2c_pri->adapter, | ||
69 | i2c_pri->addr | BIT(2)); | ||
70 | if (IS_ERR_OR_NULL(bcm590xx->i2c_sec)) { | ||
71 | dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n"); | ||
72 | return -ENODEV; | ||
73 | } | ||
74 | i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx); | ||
75 | |||
76 | bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec, | ||
77 | &bcm590xx_regmap_config_sec); | ||
78 | if (IS_ERR(bcm590xx->regmap_sec)) { | ||
79 | ret = PTR_ERR(bcm590xx->regmap_sec); | ||
80 | dev_err(&bcm590xx->i2c_sec->dev, | ||
81 | "secondary regmap init failed: %d\n", ret); | ||
82 | goto err; | ||
83 | } | ||
84 | |||
85 | ret = mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs, | ||
60 | ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL); | 86 | ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL); |
61 | if (ret < 0) | 87 | if (ret < 0) { |
62 | dev_err(&i2c->dev, "failed to add sub-devices: %d\n", ret); | 88 | dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret); |
89 | goto err; | ||
90 | } | ||
91 | |||
92 | return 0; | ||
63 | 93 | ||
94 | err: | ||
95 | i2c_unregister_device(bcm590xx->i2c_sec); | ||
64 | return ret; | 96 | return ret; |
65 | } | 97 | } |
66 | 98 | ||