15 #include <linux/module.h>
32 #define DA9052_BUCK_PERI_3uV_STEP 100000
33 #define DA9052_BUCK_PERI_REG_MAP_UPTO_3uV 24
34 #define DA9052_CONST_3uV 3000000
36 #define DA9052_MIN_UA 0
37 #define DA9052_MAX_UA 3
38 #define DA9052_CURRENT_RANGE 4
41 #define DA9052_BUCK_ILIM_MASK_EVEN 0x0c
42 #define DA9052_BUCK_ILIM_MASK_ODD 0xc0
45 #define DA9052_ID_BUCK1 0
46 #define DA9052_ID_BUCK2 1
47 #define DA9052_ID_BUCK3 2
48 #define DA9052_ID_BUCK4 3
49 #define DA9052_ID_LDO1 4
50 #define DA9052_ID_LDO2 5
51 #define DA9052_ID_LDO3 6
52 #define DA9052_ID_LDO4 7
53 #define DA9052_ID_LDO5 8
54 #define DA9052_ID_LDO6 9
55 #define DA9052_ID_LDO7 10
56 #define DA9052_ID_LDO8 11
57 #define DA9052_ID_LDO9 12
58 #define DA9052_ID_LDO10 13
60 static const u32 da9052_current_limits[3][4] = {
61 {700000, 800000, 1000000, 1200000},
62 {1600000, 2000000, 2400000, 3000000},
63 {800000, 1000000, 1200000, 1500000},
83 int min_uV,
int max_uV)
85 if (min_uV > info->
max_uV || max_uV < info->min_uV)
112 else if (offset == 0)
115 return da9052_current_limits[row][
ret];
118 static int da9052_dcdc_set_current_limit(
struct regulator_dev *rdev,
int min_uA,
129 else if (offset == 0)
137 if (da9052_current_limits[row][i] <= max_uA) {
147 return da9052_reg_update(regulator->
da9052,
152 return da9052_reg_update(regulator->
da9052,
176 if (volt_uV > info->
max_uV)
190 ret = verify_range(info, min_uV, max_uV);
194 if (min_uV < info->min_uV)
206 ret = da9052_list_voltage(rdev, sel);
213 static int da9052_regulator_set_voltage_sel(
struct regulator_dev *rdev,
214 unsigned int selector)
221 ret = da9052_reg_update(regulator->
da9052, rdev->
desc->vsel_reg,
222 rdev->
desc->vsel_mask, selector);
244 .get_current_limit = da9052_dcdc_get_current_limit,
245 .set_current_limit = da9052_dcdc_set_current_limit,
247 .list_voltage = da9052_list_voltage,
248 .map_voltage = da9052_map_voltage,
250 .set_voltage_sel = da9052_regulator_set_voltage_sel,
257 .list_voltage = da9052_list_voltage,
258 .map_voltage = da9052_map_voltage,
260 .set_voltage_sel = da9052_regulator_set_voltage_sel,
266 #define DA9052_LDO(_id, step, min, max, sbits, ebits, abits) \
270 .ops = &da9052_ldo_ops,\
271 .type = REGULATOR_VOLTAGE,\
272 .id = DA9052_ID_##_id,\
273 .n_voltages = (max - min) / step + 1, \
274 .owner = THIS_MODULE,\
275 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
276 .vsel_mask = (1 << (sbits)) - 1,\
277 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
278 .enable_mask = 1 << (ebits),\
280 .min_uV = (min) * 1000,\
281 .max_uV = (max) * 1000,\
282 .step_uV = (step) * 1000,\
283 .activate_bit = (abits),\
286 #define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \
290 .ops = &da9052_dcdc_ops,\
291 .type = REGULATOR_VOLTAGE,\
292 .id = DA9052_ID_##_id,\
293 .n_voltages = (max - min) / step + 1, \
294 .owner = THIS_MODULE,\
295 .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
296 .vsel_mask = (1 << (sbits)) - 1,\
297 .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
298 .enable_mask = 1 << (ebits),\
300 .min_uV = (min) * 1000,\
301 .max_uV = (max) * 1000,\
302 .step_uV = (step) * 1000,\
303 .activate_bit = (abits),\
323 static struct da9052_regulator_info da9053_regulator_info[] = {
340 static inline struct da9052_regulator_info *find_regulator_info(
u8 chip_id,
343 struct da9052_regulator_info *
info;
348 for (i = 0; i <
ARRAY_SIZE(da9052_regulator_info); i++) {
349 info = &da9052_regulator_info[
i];
357 for (i = 0; i <
ARRAY_SIZE(da9053_regulator_info); i++) {
358 info = &da9053_regulator_info[
i];
381 pdata = da9052->
dev->platform_data;
382 regulator->
da9052 = da9052;
384 regulator->
info = find_regulator_info(regulator->
da9052->chip_id,
387 dev_err(&pdev->
dev,
"invalid regulator ID specified\n");
409 if (!of_node_cmp(np->
name,
410 regulator->
info->reg_desc.name)) {
422 if (IS_ERR(regulator->
rdev)) {
423 dev_err(&pdev->
dev,
"failed to register regulator %s\n",
424 regulator->
info->reg_desc.name);
425 return PTR_ERR(regulator->
rdev);
428 platform_set_drvdata(pdev, regulator);
442 .probe = da9052_regulator_probe,
445 .name =
"da9052-regulator",
450 static int __init da9052_regulator_init(
void)
456 static void __exit da9052_regulator_exit(
void)