1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * isl9305 - Intersil ISL9305 DCDC regulator
5 * Copyright 2014 Linaro Ltd
7 * Author: Mark Brown <broonie@kernel.org>
10 #include <linux/module.h>
11 #include <linux/err.h>
12 #include <linux/i2c.h>
14 #include <linux/platform_data/isl9305.h>
15 #include <linux/regmap.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/regulator/of_regulator.h>
18 #include <linux/slab.h>
23 #define ISL9305_DCD1OUT 0x0
24 #define ISL9305_DCD2OUT 0x1
25 #define ISL9305_LDO1OUT 0x2
26 #define ISL9305_LDO2OUT 0x3
27 #define ISL9305_DCD_PARAMETER 0x4
28 #define ISL9305_SYSTEM_PARAMETER 0x5
29 #define ISL9305_DCD_SRCTL 0x6
31 #define ISL9305_MAX_REG ISL9305_DCD_SRCTL
36 #define ISL9305_DCD_PHASE 0x40
37 #define ISL9305_DCD2_ULTRA 0x20
38 #define ISL9305_DCD1_ULTRA 0x10
39 #define ISL9305_DCD2_BLD 0x08
40 #define ISL9305_DCD1_BLD 0x04
41 #define ISL9305_DCD2_MODE 0x02
42 #define ISL9305_DCD1_MODE 0x01
47 #define ISL9305_I2C_EN 0x40
48 #define ISL9305_DCDPOR_MASK 0x30
49 #define ISL9305_LDO2_EN 0x08
50 #define ISL9305_LDO1_EN 0x04
51 #define ISL9305_DCD2_EN 0x02
52 #define ISL9305_DCD1_EN 0x01
57 #define ISL9305_DCD2SR_MASK 0xc0
58 #define ISL9305_DCD1SR_MASK 0x07
60 static const struct regulator_ops isl9305_ops
= {
61 .enable
= regulator_enable_regmap
,
62 .disable
= regulator_disable_regmap
,
63 .is_enabled
= regulator_is_enabled_regmap
,
64 .list_voltage
= regulator_list_voltage_linear
,
65 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
66 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
69 static const struct regulator_desc isl9305_regulators
[] = {
72 .of_match
= of_match_ptr("dcd1"),
73 .regulators_node
= of_match_ptr("regulators"),
77 .vsel_reg
= ISL9305_DCD1OUT
,
79 .enable_reg
= ISL9305_SYSTEM_PARAMETER
,
80 .enable_mask
= ISL9305_DCD1_EN
,
81 .supply_name
= "VINDCD1",
87 .of_match
= of_match_ptr("dcd2"),
88 .regulators_node
= of_match_ptr("regulators"),
92 .vsel_reg
= ISL9305_DCD2OUT
,
94 .enable_reg
= ISL9305_SYSTEM_PARAMETER
,
95 .enable_mask
= ISL9305_DCD2_EN
,
96 .supply_name
= "VINDCD2",
102 .of_match
= of_match_ptr("ldo1"),
103 .regulators_node
= of_match_ptr("regulators"),
107 .vsel_reg
= ISL9305_LDO1OUT
,
109 .enable_reg
= ISL9305_SYSTEM_PARAMETER
,
110 .enable_mask
= ISL9305_LDO1_EN
,
111 .supply_name
= "VINLDO1",
113 .owner
= THIS_MODULE
,
117 .of_match
= of_match_ptr("ldo2"),
118 .regulators_node
= of_match_ptr("regulators"),
122 .vsel_reg
= ISL9305_LDO2OUT
,
124 .enable_reg
= ISL9305_SYSTEM_PARAMETER
,
125 .enable_mask
= ISL9305_LDO2_EN
,
126 .supply_name
= "VINLDO2",
128 .owner
= THIS_MODULE
,
132 static const struct regmap_config isl9305_regmap
= {
136 .max_register
= ISL9305_MAX_REG
,
137 .cache_type
= REGCACHE_MAPLE
,
140 static int isl9305_i2c_probe(struct i2c_client
*i2c
)
142 struct regulator_config config
= { };
143 struct isl9305_pdata
*pdata
= i2c
->dev
.platform_data
;
144 struct regulator_dev
*rdev
;
145 struct regmap
*regmap
;
148 regmap
= devm_regmap_init_i2c(i2c
, &isl9305_regmap
);
149 if (IS_ERR(regmap
)) {
150 ret
= PTR_ERR(regmap
);
151 dev_err(&i2c
->dev
, "Failed to create regmap: %d\n", ret
);
155 config
.dev
= &i2c
->dev
;
157 for (i
= 0; i
< ARRAY_SIZE(isl9305_regulators
); i
++) {
159 config
.init_data
= pdata
->init_data
[i
];
161 config
.init_data
= NULL
;
163 rdev
= devm_regulator_register(&i2c
->dev
,
164 &isl9305_regulators
[i
],
168 dev_err(&i2c
->dev
, "Failed to register %s: %d\n",
169 isl9305_regulators
[i
].name
, ret
);
178 static const struct of_device_id isl9305_dt_ids
[] = {
179 { .compatible
= "isl,isl9305" }, /* for backward compat., don't use */
180 { .compatible
= "isil,isl9305" },
181 { .compatible
= "isl,isl9305h" }, /* for backward compat., don't use */
182 { .compatible
= "isil,isl9305h" },
185 MODULE_DEVICE_TABLE(of
, isl9305_dt_ids
);
188 static const struct i2c_device_id isl9305_i2c_id
[] = {
193 MODULE_DEVICE_TABLE(i2c
, isl9305_i2c_id
);
195 static struct i2c_driver isl9305_regulator_driver
= {
198 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
199 .of_match_table
= of_match_ptr(isl9305_dt_ids
),
201 .probe
= isl9305_i2c_probe
,
202 .id_table
= isl9305_i2c_id
,
205 module_i2c_driver(isl9305_regulator_driver
);
207 MODULE_AUTHOR("Mark Brown");
208 MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
209 MODULE_LICENSE("GPL");