Commit | Line | Data |
---|---|---|
2874c5fd | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
037b60f2 MP |
2 | /* |
3 | * Broadcom BCM590xx PMU | |
4 | * | |
5 | * Copyright 2014 Linaro Limited | |
6 | * Author: Matt Porter <mporter@linaro.org> | |
037b60f2 MP |
7 | */ |
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> | |
17 | #include <linux/of_device.h> | |
18 | #include <linux/regmap.h> | |
19 | #include <linux/slab.h> | |
20 | ||
21 | static const struct mfd_cell bcm590xx_devs[] = { | |
22 | { | |
23 | .name = "bcm590xx-vregs", | |
24 | }, | |
25 | }; | |
26 | ||
9e1e7263 | 27 | static const struct regmap_config bcm590xx_regmap_config_pri = { |
037b60f2 MP |
28 | .reg_bits = 8, |
29 | .val_bits = 8, | |
9e1e7263 | 30 | .max_register = BCM590XX_MAX_REGISTER_PRI, |
037b60f2 MP |
31 | .cache_type = REGCACHE_RBTREE, |
32 | }; | |
33 | ||
9e1e7263 MP |
34 | static const struct regmap_config bcm590xx_regmap_config_sec = { |
35 | .reg_bits = 8, | |
36 | .val_bits = 8, | |
37 | .max_register = BCM590XX_MAX_REGISTER_SEC, | |
38 | .cache_type = REGCACHE_RBTREE, | |
39 | }; | |
40 | ||
ace24876 | 41 | static int bcm590xx_i2c_probe(struct i2c_client *i2c_pri) |
037b60f2 MP |
42 | { |
43 | struct bcm590xx *bcm590xx; | |
44 | int ret; | |
45 | ||
9e1e7263 | 46 | bcm590xx = devm_kzalloc(&i2c_pri->dev, sizeof(*bcm590xx), GFP_KERNEL); |
037b60f2 MP |
47 | if (!bcm590xx) |
48 | return -ENOMEM; | |
49 | ||
9e1e7263 MP |
50 | i2c_set_clientdata(i2c_pri, bcm590xx); |
51 | bcm590xx->dev = &i2c_pri->dev; | |
52 | bcm590xx->i2c_pri = i2c_pri; | |
037b60f2 | 53 | |
9e1e7263 MP |
54 | bcm590xx->regmap_pri = devm_regmap_init_i2c(i2c_pri, |
55 | &bcm590xx_regmap_config_pri); | |
56 | if (IS_ERR(bcm590xx->regmap_pri)) { | |
57 | ret = PTR_ERR(bcm590xx->regmap_pri); | |
58 | dev_err(&i2c_pri->dev, "primary regmap init failed: %d\n", ret); | |
037b60f2 MP |
59 | return ret; |
60 | } | |
61 | ||
9e1e7263 | 62 | /* Secondary I2C slave address is the base address with A(2) asserted */ |
98f0c05f | 63 | bcm590xx->i2c_sec = i2c_new_dummy_device(i2c_pri->adapter, |
9e1e7263 | 64 | i2c_pri->addr | BIT(2)); |
98f0c05f | 65 | if (IS_ERR(bcm590xx->i2c_sec)) { |
9e1e7263 | 66 | dev_err(&i2c_pri->dev, "failed to add secondary I2C device\n"); |
98f0c05f | 67 | return PTR_ERR(bcm590xx->i2c_sec); |
9e1e7263 MP |
68 | } |
69 | i2c_set_clientdata(bcm590xx->i2c_sec, bcm590xx); | |
70 | ||
71 | bcm590xx->regmap_sec = devm_regmap_init_i2c(bcm590xx->i2c_sec, | |
72 | &bcm590xx_regmap_config_sec); | |
73 | if (IS_ERR(bcm590xx->regmap_sec)) { | |
74 | ret = PTR_ERR(bcm590xx->regmap_sec); | |
75 | dev_err(&bcm590xx->i2c_sec->dev, | |
76 | "secondary regmap init failed: %d\n", ret); | |
77 | goto err; | |
78 | } | |
79 | ||
9148f2c0 LD |
80 | ret = devm_mfd_add_devices(&i2c_pri->dev, -1, bcm590xx_devs, |
81 | ARRAY_SIZE(bcm590xx_devs), NULL, 0, NULL); | |
9e1e7263 MP |
82 | if (ret < 0) { |
83 | dev_err(&i2c_pri->dev, "failed to add sub-devices: %d\n", ret); | |
84 | goto err; | |
85 | } | |
86 | ||
87 | return 0; | |
037b60f2 | 88 | |
9e1e7263 MP |
89 | err: |
90 | i2c_unregister_device(bcm590xx->i2c_sec); | |
037b60f2 MP |
91 | return ret; |
92 | } | |
93 | ||
94 | static const struct of_device_id bcm590xx_of_match[] = { | |
95 | { .compatible = "brcm,bcm59056" }, | |
96 | { } | |
97 | }; | |
3827c510 | 98 | MODULE_DEVICE_TABLE(of, bcm590xx_of_match); |
037b60f2 MP |
99 | |
100 | static const struct i2c_device_id bcm590xx_i2c_id[] = { | |
101 | { "bcm59056" }, | |
102 | { } | |
103 | }; | |
104 | MODULE_DEVICE_TABLE(i2c, bcm590xx_i2c_id); | |
105 | ||
106 | static struct i2c_driver bcm590xx_i2c_driver = { | |
107 | .driver = { | |
108 | .name = "bcm590xx", | |
b0ad7ebe | 109 | .of_match_table = bcm590xx_of_match, |
037b60f2 | 110 | }, |
ace24876 | 111 | .probe_new = bcm590xx_i2c_probe, |
037b60f2 MP |
112 | .id_table = bcm590xx_i2c_id, |
113 | }; | |
114 | module_i2c_driver(bcm590xx_i2c_driver); | |
115 | ||
116 | MODULE_AUTHOR("Matt Porter <mporter@linaro.org>"); | |
117 | MODULE_DESCRIPTION("BCM590xx multi-function driver"); | |
118 | MODULE_LICENSE("GPL v2"); |