Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * isl9305 - Intersil ISL9305 DCDC regulator
0004  *
0005  * Copyright 2014 Linaro Ltd
0006  *
0007  * Author: Mark Brown <broonie@kernel.org>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/err.h>
0012 #include <linux/i2c.h>
0013 #include <linux/of.h>
0014 #include <linux/platform_data/isl9305.h>
0015 #include <linux/regmap.h>
0016 #include <linux/regulator/driver.h>
0017 #include <linux/regulator/of_regulator.h>
0018 #include <linux/slab.h>
0019 
0020 /*
0021  * Registers
0022  */
0023 #define ISL9305_DCD1OUT          0x0
0024 #define ISL9305_DCD2OUT          0x1
0025 #define ISL9305_LDO1OUT          0x2
0026 #define ISL9305_LDO2OUT          0x3
0027 #define ISL9305_DCD_PARAMETER    0x4
0028 #define ISL9305_SYSTEM_PARAMETER 0x5
0029 #define ISL9305_DCD_SRCTL        0x6
0030 
0031 #define ISL9305_MAX_REG ISL9305_DCD_SRCTL
0032 
0033 /*
0034  * DCD_PARAMETER
0035  */
0036 #define ISL9305_DCD_PHASE   0x40
0037 #define ISL9305_DCD2_ULTRA  0x20
0038 #define ISL9305_DCD1_ULTRA  0x10
0039 #define ISL9305_DCD2_BLD    0x08
0040 #define ISL9305_DCD1_BLD    0x04
0041 #define ISL9305_DCD2_MODE   0x02
0042 #define ISL9305_DCD1_MODE   0x01
0043 
0044 /*
0045  * SYSTEM_PARAMETER
0046  */
0047 #define ISL9305_I2C_EN      0x40
0048 #define ISL9305_DCDPOR_MASK 0x30
0049 #define ISL9305_LDO2_EN     0x08
0050 #define ISL9305_LDO1_EN     0x04
0051 #define ISL9305_DCD2_EN     0x02
0052 #define ISL9305_DCD1_EN     0x01
0053 
0054 /*
0055  * DCD_SRCTL
0056  */
0057 #define ISL9305_DCD2SR_MASK 0xc0
0058 #define ISL9305_DCD1SR_MASK 0x07
0059 
0060 static const struct regulator_ops isl9305_ops = {
0061     .enable = regulator_enable_regmap,
0062     .disable = regulator_disable_regmap,
0063     .is_enabled = regulator_is_enabled_regmap,
0064     .list_voltage = regulator_list_voltage_linear,
0065     .get_voltage_sel = regulator_get_voltage_sel_regmap,
0066     .set_voltage_sel = regulator_set_voltage_sel_regmap,
0067 };
0068 
0069 static const struct regulator_desc isl9305_regulators[] = {
0070     [ISL9305_DCD1] = {
0071         .name =     "DCD1",
0072         .of_match = of_match_ptr("dcd1"),
0073         .regulators_node = of_match_ptr("regulators"),
0074         .n_voltages =   0x70,
0075         .min_uV =   825000,
0076         .uV_step =  25000,
0077         .vsel_reg = ISL9305_DCD1OUT,
0078         .vsel_mask =    0x7f,
0079         .enable_reg =   ISL9305_SYSTEM_PARAMETER,
0080         .enable_mask =  ISL9305_DCD1_EN,
0081         .supply_name =  "VINDCD1",
0082         .ops =      &isl9305_ops,
0083         .owner =    THIS_MODULE,
0084     },
0085     [ISL9305_DCD2] = {
0086         .name =     "DCD2",
0087         .of_match = of_match_ptr("dcd2"),
0088         .regulators_node = of_match_ptr("regulators"),
0089         .n_voltages =   0x70,
0090         .min_uV =   825000,
0091         .uV_step =  25000,
0092         .vsel_reg = ISL9305_DCD2OUT,
0093         .vsel_mask =    0x7f,
0094         .enable_reg =   ISL9305_SYSTEM_PARAMETER,
0095         .enable_mask =  ISL9305_DCD2_EN,
0096         .supply_name =  "VINDCD2",
0097         .ops =      &isl9305_ops,
0098         .owner =    THIS_MODULE,
0099     },
0100     [ISL9305_LDO1] = {
0101         .name =     "LDO1",
0102         .of_match = of_match_ptr("ldo1"),
0103         .regulators_node = of_match_ptr("regulators"),
0104         .n_voltages =   0x37,
0105         .min_uV =   900000,
0106         .uV_step =  50000,
0107         .vsel_reg = ISL9305_LDO1OUT,
0108         .vsel_mask =    0x3f,
0109         .enable_reg =   ISL9305_SYSTEM_PARAMETER,
0110         .enable_mask =  ISL9305_LDO1_EN,
0111         .supply_name =  "VINLDO1",
0112         .ops =      &isl9305_ops,
0113         .owner =    THIS_MODULE,
0114     },
0115     [ISL9305_LDO2] = {
0116         .name =     "LDO2",
0117         .of_match = of_match_ptr("ldo2"),
0118         .regulators_node = of_match_ptr("regulators"),
0119         .n_voltages =   0x37,
0120         .min_uV =   900000,
0121         .uV_step =  50000,
0122         .vsel_reg = ISL9305_LDO2OUT,
0123         .vsel_mask =    0x3f,
0124         .enable_reg =   ISL9305_SYSTEM_PARAMETER,
0125         .enable_mask =  ISL9305_LDO2_EN,
0126         .supply_name =  "VINLDO2",
0127         .ops =      &isl9305_ops,
0128         .owner =    THIS_MODULE,
0129     },
0130 };
0131 
0132 static const struct regmap_config isl9305_regmap = {
0133     .reg_bits = 8,
0134     .val_bits = 8,
0135 
0136     .max_register = ISL9305_MAX_REG,
0137     .cache_type = REGCACHE_RBTREE,
0138 };
0139 
0140 static int isl9305_i2c_probe(struct i2c_client *i2c)
0141 {
0142     struct regulator_config config = { };
0143     struct isl9305_pdata *pdata = i2c->dev.platform_data;
0144     struct regulator_dev *rdev;
0145     struct regmap *regmap;
0146     int i, ret;
0147 
0148     regmap = devm_regmap_init_i2c(i2c, &isl9305_regmap);
0149     if (IS_ERR(regmap)) {
0150         ret = PTR_ERR(regmap);
0151         dev_err(&i2c->dev, "Failed to create regmap: %d\n", ret);
0152         return ret;
0153     }
0154 
0155     config.dev = &i2c->dev;
0156 
0157     for (i = 0; i < ARRAY_SIZE(isl9305_regulators); i++) {
0158         if (pdata)
0159             config.init_data = pdata->init_data[i];
0160         else
0161             config.init_data = NULL;
0162 
0163         rdev = devm_regulator_register(&i2c->dev,
0164                            &isl9305_regulators[i],
0165                            &config);
0166         if (IS_ERR(rdev)) {
0167             ret = PTR_ERR(rdev);
0168             dev_err(&i2c->dev, "Failed to register %s: %d\n",
0169                 isl9305_regulators[i].name, ret);
0170             return ret;
0171         }
0172     }
0173 
0174     return 0;
0175 }
0176 
0177 #ifdef CONFIG_OF
0178 static const struct of_device_id isl9305_dt_ids[] = {
0179     { .compatible = "isl,isl9305" }, /* for backward compat., don't use */
0180     { .compatible = "isil,isl9305" },
0181     { .compatible = "isl,isl9305h" }, /* for backward compat., don't use */
0182     { .compatible = "isil,isl9305h" },
0183     {},
0184 };
0185 MODULE_DEVICE_TABLE(of, isl9305_dt_ids);
0186 #endif
0187 
0188 static const struct i2c_device_id isl9305_i2c_id[] = {
0189     { "isl9305", },
0190     { "isl9305h", },
0191     { }
0192 };
0193 MODULE_DEVICE_TABLE(i2c, isl9305_i2c_id);
0194 
0195 static struct i2c_driver isl9305_regulator_driver = {
0196     .driver = {
0197         .name = "isl9305",
0198         .of_match_table = of_match_ptr(isl9305_dt_ids),
0199     },
0200     .probe_new = isl9305_i2c_probe,
0201     .id_table = isl9305_i2c_id,
0202 };
0203 
0204 module_i2c_driver(isl9305_regulator_driver);
0205 
0206 MODULE_AUTHOR("Mark Brown");
0207 MODULE_DESCRIPTION("Intersil ISL9305 DCDC regulator");
0208 MODULE_LICENSE("GPL");