blob: 92eede9a5e61b7cec7d43daf59dd1d8de5876a78 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Matt Porter037b60f22014-03-11 19:33:54 -04002/*
3 * Broadcom BCM590xx PMU
4 *
5 * Copyright 2014 Linaro Limited
6 * Author: Matt Porter <mporter@linaro.org>
Matt Porter037b60f22014-03-11 19:33:54 -04007 */
8
9#include <linux/err.h>
10#include <linux/i2c.h>
11#include <linux/init.h>
12#include <linux/mfd/bcm590xx.h>
13#include <linux/mfd/core.h>
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/of.h>
Matt Porter037b60f22014-03-11 19:33:54 -040017#include <linux/regmap.h>
18#include <linux/slab.h>
19
20static const struct mfd_cell bcm590xx_devs[] = {
21 {
22 .name = "bcm590xx-vregs",
23 },
24};
25
Matt Porter9e1e7262014-04-23 19:21:31 -040026static const struct regmap_config bcm590xx_regmap_config_pri = {
Matt Porter037b60f22014-03-11 19:33:54 -040027 .reg_bits = 8,
28 .val_bits = 8,
Matt Porter9e1e7262014-04-23 19:21:31 -040029 .max_register = BCM590XX_MAX_REGISTER_PRI,
Matt Porter037b60f22014-03-11 19:33:54 -040030 .cache_type = REGCACHE_RBTREE,
31};
32
Matt Porter9e1e7262014-04-23 19:21:31 -040033static const struct regmap_config bcm590xx_regmap_config_sec = {
34 .reg_bits = 8,
35 .val_bits = 8,
36 .max_register = BCM590XX_MAX_REGISTER_SEC,
37 .cache_type = REGCACHE_RBTREE,
38};
39
Uwe Kleine-Königace24872022-11-18 23:42:37 +010040static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri)
Matt Porter037b60f22014-03-11 19:33:54 -040041{
42 struct bcm590xx *bcm590xx;
43 int ret;
44
Matt Porter9e1e7262014-04-23 19:21:31 -040045 bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL);
Matt Porter037b60f22014-03-11 19:33:54 -040046 if (!bcm590xx)
47 return -ENOMEM;
48
Matt Porter9e1e7262014-04-23 19:21:31 -040049 i2c_set_clientdata(i2c_pri, bcm590xx);
50 bcm590xx->dev = &i2c_pri->dev;
51 bcm590xx->i2c_pri = i2c_pri;
Matt Porter037b60f22014-03-11 19:33:54 -040052
Matt Porter9e1e7262014-04-23 19:21:31 -040053 bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri,
54 &bcm590xx_regmap_config_pri);
55 if (IS_ERR(bcm590xx->regmap_pri)) {
56 ret = PTR_ERR(bcm590xx->regmap_pri);
57 dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret);
Matt Porter037b60f22014-03-11 19:33:54 -040058 return ret;
59 }
60
Matt Porter9e1e7262014-04-23 19:21:31 -040061 /* Secondary I2C slave address is the base address with A(2) asserted */
Wolfram Sang98f0c052019-07-22 19:26:11 +020062 bcm590xx->i2c_sec = i2c_new_dummy_device(i2c_pri->adapter,
Matt Porter9e1e7262014-04-23 19:21:31 -040063 i2c_pri->addr | BIT(2));
Wolfram Sang98f0c052019-07-22 19:26:11 +020064 if (IS_ERR(bcm590xx->i2c_sec)) {
Matt Porter9e1e7262014-04-23 19:21:31 -040065 dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n");
Wolfram Sang98f0c052019-07-22 19:26:11 +020066 return PTR_ERR(bcm590xx->i2c_sec);
Matt Porter9e1e7262014-04-23 19:21:31 -040067 }
68 i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx);
Matt Porter037b60f22014-03-11 19:33:54 -040069
Matt Porter9e1e7262014-04-23 19:21:31 -040070 bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec,
71 &bcm590xx_regmap_config_sec);
72 if (IS_ERR(bcm590xx->regmap_sec)) {
73 ret = PTR_ERR(bcm590xx->regmap_sec);
74 dev_err(&bcm590xx->i2c_sec->dev,
75 "secondary regmap init failed: %d\n", ret);
76 goto err;
77 }
78
Laxman Dewangan9148f2c2016-04-08 00:13:00 +053079 ret = devm_mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs,
80 ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL);
Matt Porter9e1e7262014-04-23 19:21:31 -040081 if (ret < 0) {
82 dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret);
83 goto err;
84 }
85
86 return 0;
87
88err:
89 i2c_unregister_device(bcm590xx->i2c_sec);
Matt Porter037b60f22014-03-11 19:33:54 -040090 return ret;
91}
92
93static const struct of_device_id bcm590xx_of_match[] = {
94 { .compatible = "brcm,bcm59056" },
95 { }
96};
Axel Lin3827c512014-03-15 09:24:50 +080097MODULE_DEVICE_TABLE(of, bcm590xx_of_match);
Matt Porter037b60f22014-03-11 19:33:54 -040098
99static const struct i2c_device_id bcm590xx_i2c_id[] = {
100 { "bcm59056" },
101 { }
102};
103MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id);
104
105static struct i2c_driver bcm590xx_i2c_driver = {
106 .driver = {
107 .name = "bcm590xx",
Krzysztof Kozlowskib0ad7eb2020-11-20 17:21:18 +0100108 .of_match_table = bcm590xx_of_match,
Matt Porter037b60f22014-03-11 19:33:54 -0400109 },
Uwe Kleine-König9816d852023-05-15 20:27:52 +0200110 .probe = bcm590xx_i2c_probe,
Matt Porter037b60f22014-03-11 19:33:54 -0400111 .id_table = bcm590xx_i2c_id,
112};
113module_i2c_driver(bcm590xx_i2c_driver);
114
115MODULE_AUTHOR("Matt Porter <mporter@linaro.org>");
116MODULE_DESCRIPTION("BCM590xx multi-function driver");
117MODULE_LICENSE("GPL v2");