Fabio Estevam | 809858c | 2018-05-23 16:17:34 -0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // Copyright (C) 2011-2013 Freescale Semiconductor, Inc. All Rights Reserved. |
| 4 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 5 | #include <linux/kernel.h> |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/err.h> |
| 9 | #include <linux/of.h> |
| 10 | #include <linux/of_device.h> |
| 11 | #include <linux/regulator/of_regulator.h> |
| 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/regulator/driver.h> |
| 14 | #include <linux/regulator/machine.h> |
| 15 | #include <linux/regulator/pfuze100.h> |
| 16 | #include <linux/i2c.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/regmap.h> |
| 19 | |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 20 | #define PFUZE_FLAG_DISABLE_SW BIT(1) |
| 21 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 22 | #define PFUZE_NUMREGS 128 |
| 23 | #define PFUZE100_VOL_OFFSET 0 |
| 24 | #define PFUZE100_STANDBY_OFFSET 1 |
| 25 | #define PFUZE100_MODE_OFFSET 3 |
| 26 | #define PFUZE100_CONF_OFFSET 4 |
| 27 | |
| 28 | #define PFUZE100_DEVICEID 0x0 |
| 29 | #define PFUZE100_REVID 0x3 |
Axel Lin | a1b6fa8 | 2013-12-09 15:24:19 +0800 | [diff] [blame] | 30 | #define PFUZE100_FABID 0x4 |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 31 | |
George McCollister | c6182ac | 2017-03-09 08:14:43 -0600 | [diff] [blame] | 32 | #define PFUZE100_COINVOL 0x1a |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 33 | #define PFUZE100_SW1ABVOL 0x20 |
| 34 | #define PFUZE100_SW1CVOL 0x2e |
| 35 | #define PFUZE100_SW2VOL 0x35 |
| 36 | #define PFUZE100_SW3AVOL 0x3c |
| 37 | #define PFUZE100_SW3BVOL 0x43 |
| 38 | #define PFUZE100_SW4VOL 0x4a |
| 39 | #define PFUZE100_SWBSTCON1 0x66 |
| 40 | #define PFUZE100_VREFDDRCON 0x6a |
| 41 | #define PFUZE100_VSNVSVOL 0x6b |
| 42 | #define PFUZE100_VGEN1VOL 0x6c |
| 43 | #define PFUZE100_VGEN2VOL 0x6d |
| 44 | #define PFUZE100_VGEN3VOL 0x6e |
| 45 | #define PFUZE100_VGEN4VOL 0x6f |
| 46 | #define PFUZE100_VGEN5VOL 0x70 |
| 47 | #define PFUZE100_VGEN6VOL 0x71 |
| 48 | |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 49 | enum chips { PFUZE100, PFUZE200, PFUZE3000 = 3, PFUZE3001 = 0x31, }; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 50 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 51 | struct pfuze_regulator { |
| 52 | struct regulator_desc desc; |
| 53 | unsigned char stby_reg; |
| 54 | unsigned char stby_mask; |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 55 | bool sw_reg; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct pfuze_chip { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 59 | int chip_id; |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 60 | int flags; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 61 | struct regmap *regmap; |
| 62 | struct device *dev; |
| 63 | struct pfuze_regulator regulator_descs[PFUZE100_MAX_REGULATOR]; |
| 64 | struct regulator_dev *regulators[PFUZE100_MAX_REGULATOR]; |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 65 | struct pfuze_regulator *pfuze_regulators; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static const int pfuze100_swbst[] = { |
| 69 | 5000000, 5050000, 5100000, 5150000, |
| 70 | }; |
| 71 | |
| 72 | static const int pfuze100_vsnvs[] = { |
| 73 | 1000000, 1100000, 1200000, 1300000, 1500000, 1800000, 3000000, |
| 74 | }; |
| 75 | |
George McCollister | c6182ac | 2017-03-09 08:14:43 -0600 | [diff] [blame] | 76 | static const int pfuze100_coin[] = { |
| 77 | 2500000, 2700000, 2800000, 2900000, 3000000, 3100000, 3200000, 3300000, |
| 78 | }; |
| 79 | |
Anson Huang | 1dced99 | 2018-03-18 11:23:21 +0800 | [diff] [blame] | 80 | static const int pfuze3000_sw1a[] = { |
| 81 | 700000, 725000, 750000, 775000, 800000, 825000, 850000, 875000, |
| 82 | 900000, 925000, 950000, 975000, 1000000, 1025000, 1050000, 1075000, |
| 83 | 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, |
| 84 | 1300000, 1325000, 1350000, 1375000, 1400000, 1425000, 1800000, 3300000, |
| 85 | }; |
| 86 | |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 87 | static const int pfuze3000_sw2lo[] = { |
| 88 | 1500000, 1550000, 1600000, 1650000, 1700000, 1750000, 1800000, 1850000, |
| 89 | }; |
| 90 | |
| 91 | static const int pfuze3000_sw2hi[] = { |
| 92 | 2500000, 2800000, 2850000, 3000000, 3100000, 3150000, 3200000, 3300000, |
| 93 | }; |
| 94 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 95 | static const struct i2c_device_id pfuze_device_id[] = { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 96 | {.name = "pfuze100", .driver_data = PFUZE100}, |
| 97 | {.name = "pfuze200", .driver_data = PFUZE200}, |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 98 | {.name = "pfuze3000", .driver_data = PFUZE3000}, |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 99 | {.name = "pfuze3001", .driver_data = PFUZE3001}, |
Axel Lin | e6c4c33 | 2014-03-04 18:20:14 +0800 | [diff] [blame] | 100 | { } |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 101 | }; |
| 102 | MODULE_DEVICE_TABLE(i2c, pfuze_device_id); |
| 103 | |
| 104 | static const struct of_device_id pfuze_dt_ids[] = { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 105 | { .compatible = "fsl,pfuze100", .data = (void *)PFUZE100}, |
| 106 | { .compatible = "fsl,pfuze200", .data = (void *)PFUZE200}, |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 107 | { .compatible = "fsl,pfuze3000", .data = (void *)PFUZE3000}, |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 108 | { .compatible = "fsl,pfuze3001", .data = (void *)PFUZE3001}, |
Axel Lin | e6c4c33 | 2014-03-04 18:20:14 +0800 | [diff] [blame] | 109 | { } |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 110 | }; |
| 111 | MODULE_DEVICE_TABLE(of, pfuze_dt_ids); |
| 112 | |
| 113 | static int pfuze100_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 114 | { |
| 115 | struct pfuze_chip *pfuze100 = rdev_get_drvdata(rdev); |
Thiago Farina | d55efa4 | 2014-01-26 21:57:12 -0200 | [diff] [blame] | 116 | int id = rdev_get_id(rdev); |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 117 | bool reg_has_ramp_delay; |
Axel Lin | e565666 | 2013-07-30 22:47:44 +0800 | [diff] [blame] | 118 | unsigned int ramp_bits; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 119 | int ret; |
| 120 | |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 121 | switch (pfuze100->chip_id) { |
| 122 | case PFUZE3001: |
| 123 | /* no dynamic voltage scaling for PF3001 */ |
| 124 | reg_has_ramp_delay = false; |
| 125 | break; |
| 126 | case PFUZE3000: |
| 127 | reg_has_ramp_delay = (id < PFUZE3000_SWBST); |
| 128 | break; |
| 129 | case PFUZE200: |
| 130 | reg_has_ramp_delay = (id < PFUZE200_SWBST); |
| 131 | break; |
| 132 | case PFUZE100: |
| 133 | default: |
| 134 | reg_has_ramp_delay = (id < PFUZE100_SWBST); |
| 135 | break; |
| 136 | } |
| 137 | |
| 138 | if (reg_has_ramp_delay) { |
Axel Lin | e565666 | 2013-07-30 22:47:44 +0800 | [diff] [blame] | 139 | ramp_delay = 12500 / ramp_delay; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 140 | ramp_bits = (ramp_delay >> 1) - (ramp_delay >> 3); |
Axel Lin | e565666 | 2013-07-30 22:47:44 +0800 | [diff] [blame] | 141 | ret = regmap_update_bits(pfuze100->regmap, |
| 142 | rdev->desc->vsel_reg + 4, |
| 143 | 0xc0, ramp_bits << 6); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 144 | if (ret < 0) |
| 145 | dev_err(pfuze100->dev, "ramp failed, err %d\n", ret); |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 146 | } else { |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 147 | ret = -EACCES; |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 148 | } |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 149 | |
| 150 | return ret; |
| 151 | } |
| 152 | |
Bhumika Goyal | e505385 | 2017-01-28 20:38:57 +0530 | [diff] [blame] | 153 | static const struct regulator_ops pfuze100_ldo_regulator_ops = { |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 154 | .enable = regulator_enable_regmap, |
| 155 | .disable = regulator_disable_regmap, |
| 156 | .is_enabled = regulator_is_enabled_regmap, |
| 157 | .list_voltage = regulator_list_voltage_linear, |
| 158 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 159 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 160 | }; |
| 161 | |
Bhumika Goyal | e505385 | 2017-01-28 20:38:57 +0530 | [diff] [blame] | 162 | static const struct regulator_ops pfuze100_fixed_regulator_ops = { |
Axel Lin | ab3ca77 | 2014-05-26 17:56:13 +0800 | [diff] [blame] | 163 | .enable = regulator_enable_regmap, |
| 164 | .disable = regulator_disable_regmap, |
| 165 | .is_enabled = regulator_is_enabled_regmap, |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 166 | .list_voltage = regulator_list_voltage_linear, |
| 167 | }; |
| 168 | |
Bhumika Goyal | e505385 | 2017-01-28 20:38:57 +0530 | [diff] [blame] | 169 | static const struct regulator_ops pfuze100_sw_regulator_ops = { |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 170 | .list_voltage = regulator_list_voltage_linear, |
| 171 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 172 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 173 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 174 | .set_ramp_delay = pfuze100_set_ramp_delay, |
| 175 | }; |
| 176 | |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 177 | static const struct regulator_ops pfuze100_sw_disable_regulator_ops = { |
| 178 | .enable = regulator_enable_regmap, |
| 179 | .disable = regulator_disable_regmap, |
| 180 | .is_enabled = regulator_is_enabled_regmap, |
| 181 | .list_voltage = regulator_list_voltage_linear, |
| 182 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 183 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 184 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 185 | .set_ramp_delay = pfuze100_set_ramp_delay, |
| 186 | }; |
| 187 | |
Bhumika Goyal | e505385 | 2017-01-28 20:38:57 +0530 | [diff] [blame] | 188 | static const struct regulator_ops pfuze100_swb_regulator_ops = { |
Sean Cross | a6dcf97 | 2014-05-26 16:45:40 +0800 | [diff] [blame] | 189 | .enable = regulator_enable_regmap, |
| 190 | .disable = regulator_disable_regmap, |
Anson Huang | 0b01fd3 | 2018-05-17 15:27:22 +0800 | [diff] [blame] | 191 | .is_enabled = regulator_is_enabled_regmap, |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 192 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | 2e04cc4 | 2013-07-29 15:38:58 +0800 | [diff] [blame] | 193 | .map_voltage = regulator_map_voltage_ascend, |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 194 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 195 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 196 | |
| 197 | }; |
| 198 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 199 | #define PFUZE100_FIXED_REG(_chip, _name, base, voltage) \ |
| 200 | [_chip ## _ ## _name] = { \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 201 | .desc = { \ |
| 202 | .name = #_name, \ |
| 203 | .n_voltages = 1, \ |
| 204 | .ops = &pfuze100_fixed_regulator_ops, \ |
| 205 | .type = REGULATOR_VOLTAGE, \ |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 206 | .id = _chip ## _ ## _name, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 207 | .owner = THIS_MODULE, \ |
| 208 | .min_uV = (voltage), \ |
| 209 | .enable_reg = (base), \ |
| 210 | .enable_mask = 0x10, \ |
| 211 | }, \ |
| 212 | } |
| 213 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 214 | #define PFUZE100_SW_REG(_chip, _name, base, min, max, step) \ |
| 215 | [_chip ## _ ## _name] = { \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 216 | .desc = { \ |
| 217 | .name = #_name,\ |
| 218 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 219 | .ops = &pfuze100_sw_regulator_ops, \ |
| 220 | .type = REGULATOR_VOLTAGE, \ |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 221 | .id = _chip ## _ ## _name, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 222 | .owner = THIS_MODULE, \ |
| 223 | .min_uV = (min), \ |
| 224 | .uV_step = (step), \ |
| 225 | .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \ |
| 226 | .vsel_mask = 0x3f, \ |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 227 | .enable_reg = (base) + PFUZE100_MODE_OFFSET, \ |
| 228 | .enable_mask = 0xf, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 229 | }, \ |
| 230 | .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \ |
| 231 | .stby_mask = 0x3f, \ |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 232 | .sw_reg = true, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 233 | } |
| 234 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 235 | #define PFUZE100_SWB_REG(_chip, _name, base, mask, voltages) \ |
| 236 | [_chip ## _ ## _name] = { \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 237 | .desc = { \ |
| 238 | .name = #_name, \ |
| 239 | .n_voltages = ARRAY_SIZE(voltages), \ |
| 240 | .ops = &pfuze100_swb_regulator_ops, \ |
| 241 | .type = REGULATOR_VOLTAGE, \ |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 242 | .id = _chip ## _ ## _name, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 243 | .owner = THIS_MODULE, \ |
| 244 | .volt_table = voltages, \ |
| 245 | .vsel_reg = (base), \ |
| 246 | .vsel_mask = (mask), \ |
Sean Cross | a6dcf97 | 2014-05-26 16:45:40 +0800 | [diff] [blame] | 247 | .enable_reg = (base), \ |
| 248 | .enable_mask = 0x48, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 249 | }, \ |
| 250 | } |
| 251 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 252 | #define PFUZE100_VGEN_REG(_chip, _name, base, min, max, step) \ |
| 253 | [_chip ## _ ## _name] = { \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 254 | .desc = { \ |
| 255 | .name = #_name, \ |
| 256 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 257 | .ops = &pfuze100_ldo_regulator_ops, \ |
| 258 | .type = REGULATOR_VOLTAGE, \ |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 259 | .id = _chip ## _ ## _name, \ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 260 | .owner = THIS_MODULE, \ |
| 261 | .min_uV = (min), \ |
| 262 | .uV_step = (step), \ |
| 263 | .vsel_reg = (base), \ |
| 264 | .vsel_mask = 0xf, \ |
| 265 | .enable_reg = (base), \ |
| 266 | .enable_mask = 0x10, \ |
| 267 | }, \ |
| 268 | .stby_reg = (base), \ |
| 269 | .stby_mask = 0x20, \ |
| 270 | } |
| 271 | |
George McCollister | c6182ac | 2017-03-09 08:14:43 -0600 | [diff] [blame] | 272 | #define PFUZE100_COIN_REG(_chip, _name, base, mask, voltages) \ |
| 273 | [_chip ## _ ## _name] = { \ |
| 274 | .desc = { \ |
| 275 | .name = #_name, \ |
| 276 | .n_voltages = ARRAY_SIZE(voltages), \ |
| 277 | .ops = &pfuze100_swb_regulator_ops, \ |
| 278 | .type = REGULATOR_VOLTAGE, \ |
| 279 | .id = _chip ## _ ## _name, \ |
| 280 | .owner = THIS_MODULE, \ |
| 281 | .volt_table = voltages, \ |
| 282 | .vsel_reg = (base), \ |
| 283 | .vsel_mask = (mask), \ |
| 284 | .enable_reg = (base), \ |
| 285 | .enable_mask = 0x8, \ |
| 286 | }, \ |
| 287 | } |
| 288 | |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 289 | #define PFUZE3000_VCC_REG(_chip, _name, base, min, max, step) { \ |
| 290 | .desc = { \ |
| 291 | .name = #_name, \ |
| 292 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 293 | .ops = &pfuze100_ldo_regulator_ops, \ |
| 294 | .type = REGULATOR_VOLTAGE, \ |
| 295 | .id = _chip ## _ ## _name, \ |
| 296 | .owner = THIS_MODULE, \ |
| 297 | .min_uV = (min), \ |
| 298 | .uV_step = (step), \ |
| 299 | .vsel_reg = (base), \ |
| 300 | .vsel_mask = 0x3, \ |
| 301 | .enable_reg = (base), \ |
| 302 | .enable_mask = 0x10, \ |
| 303 | }, \ |
| 304 | .stby_reg = (base), \ |
| 305 | .stby_mask = 0x20, \ |
| 306 | } |
| 307 | |
| 308 | |
| 309 | #define PFUZE3000_SW2_REG(_chip, _name, base, min, max, step) { \ |
| 310 | .desc = { \ |
| 311 | .name = #_name,\ |
| 312 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 313 | .ops = &pfuze100_sw_regulator_ops, \ |
| 314 | .type = REGULATOR_VOLTAGE, \ |
| 315 | .id = _chip ## _ ## _name, \ |
| 316 | .owner = THIS_MODULE, \ |
| 317 | .min_uV = (min), \ |
| 318 | .uV_step = (step), \ |
| 319 | .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \ |
| 320 | .vsel_mask = 0x7, \ |
| 321 | }, \ |
| 322 | .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \ |
| 323 | .stby_mask = 0x7, \ |
| 324 | } |
| 325 | |
| 326 | #define PFUZE3000_SW3_REG(_chip, _name, base, min, max, step) { \ |
| 327 | .desc = { \ |
| 328 | .name = #_name,\ |
| 329 | .n_voltages = ((max) - (min)) / (step) + 1, \ |
| 330 | .ops = &pfuze100_sw_regulator_ops, \ |
| 331 | .type = REGULATOR_VOLTAGE, \ |
| 332 | .id = _chip ## _ ## _name, \ |
| 333 | .owner = THIS_MODULE, \ |
| 334 | .min_uV = (min), \ |
| 335 | .uV_step = (step), \ |
| 336 | .vsel_reg = (base) + PFUZE100_VOL_OFFSET, \ |
| 337 | .vsel_mask = 0xf, \ |
| 338 | }, \ |
| 339 | .stby_reg = (base) + PFUZE100_STANDBY_OFFSET, \ |
| 340 | .stby_mask = 0xf, \ |
| 341 | } |
| 342 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 343 | /* PFUZE100 */ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 344 | static struct pfuze_regulator pfuze100_regulators[] = { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 345 | PFUZE100_SW_REG(PFUZE100, SW1AB, PFUZE100_SW1ABVOL, 300000, 1875000, 25000), |
| 346 | PFUZE100_SW_REG(PFUZE100, SW1C, PFUZE100_SW1CVOL, 300000, 1875000, 25000), |
| 347 | PFUZE100_SW_REG(PFUZE100, SW2, PFUZE100_SW2VOL, 400000, 1975000, 25000), |
| 348 | PFUZE100_SW_REG(PFUZE100, SW3A, PFUZE100_SW3AVOL, 400000, 1975000, 25000), |
| 349 | PFUZE100_SW_REG(PFUZE100, SW3B, PFUZE100_SW3BVOL, 400000, 1975000, 25000), |
| 350 | PFUZE100_SW_REG(PFUZE100, SW4, PFUZE100_SW4VOL, 400000, 1975000, 25000), |
| 351 | PFUZE100_SWB_REG(PFUZE100, SWBST, PFUZE100_SWBSTCON1, 0x3 , pfuze100_swbst), |
| 352 | PFUZE100_SWB_REG(PFUZE100, VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs), |
| 353 | PFUZE100_FIXED_REG(PFUZE100, VREFDDR, PFUZE100_VREFDDRCON, 750000), |
| 354 | PFUZE100_VGEN_REG(PFUZE100, VGEN1, PFUZE100_VGEN1VOL, 800000, 1550000, 50000), |
| 355 | PFUZE100_VGEN_REG(PFUZE100, VGEN2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000), |
| 356 | PFUZE100_VGEN_REG(PFUZE100, VGEN3, PFUZE100_VGEN3VOL, 1800000, 3300000, 100000), |
| 357 | PFUZE100_VGEN_REG(PFUZE100, VGEN4, PFUZE100_VGEN4VOL, 1800000, 3300000, 100000), |
| 358 | PFUZE100_VGEN_REG(PFUZE100, VGEN5, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000), |
| 359 | PFUZE100_VGEN_REG(PFUZE100, VGEN6, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000), |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 360 | }; |
| 361 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 362 | static struct pfuze_regulator pfuze200_regulators[] = { |
| 363 | PFUZE100_SW_REG(PFUZE200, SW1AB, PFUZE100_SW1ABVOL, 300000, 1875000, 25000), |
| 364 | PFUZE100_SW_REG(PFUZE200, SW2, PFUZE100_SW2VOL, 400000, 1975000, 25000), |
| 365 | PFUZE100_SW_REG(PFUZE200, SW3A, PFUZE100_SW3AVOL, 400000, 1975000, 25000), |
| 366 | PFUZE100_SW_REG(PFUZE200, SW3B, PFUZE100_SW3BVOL, 400000, 1975000, 25000), |
| 367 | PFUZE100_SWB_REG(PFUZE200, SWBST, PFUZE100_SWBSTCON1, 0x3 , pfuze100_swbst), |
| 368 | PFUZE100_SWB_REG(PFUZE200, VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs), |
| 369 | PFUZE100_FIXED_REG(PFUZE200, VREFDDR, PFUZE100_VREFDDRCON, 750000), |
| 370 | PFUZE100_VGEN_REG(PFUZE200, VGEN1, PFUZE100_VGEN1VOL, 800000, 1550000, 50000), |
| 371 | PFUZE100_VGEN_REG(PFUZE200, VGEN2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000), |
| 372 | PFUZE100_VGEN_REG(PFUZE200, VGEN3, PFUZE100_VGEN3VOL, 1800000, 3300000, 100000), |
| 373 | PFUZE100_VGEN_REG(PFUZE200, VGEN4, PFUZE100_VGEN4VOL, 1800000, 3300000, 100000), |
| 374 | PFUZE100_VGEN_REG(PFUZE200, VGEN5, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000), |
| 375 | PFUZE100_VGEN_REG(PFUZE200, VGEN6, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000), |
George McCollister | c6182ac | 2017-03-09 08:14:43 -0600 | [diff] [blame] | 376 | PFUZE100_COIN_REG(PFUZE200, COIN, PFUZE100_COINVOL, 0x7, pfuze100_coin), |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 377 | }; |
| 378 | |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 379 | static struct pfuze_regulator pfuze3000_regulators[] = { |
Anson Huang | 1dced99 | 2018-03-18 11:23:21 +0800 | [diff] [blame] | 380 | PFUZE100_SWB_REG(PFUZE3000, SW1A, PFUZE100_SW1ABVOL, 0x1f, pfuze3000_sw1a), |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 381 | PFUZE100_SW_REG(PFUZE3000, SW1B, PFUZE100_SW1CVOL, 700000, 1475000, 25000), |
| 382 | PFUZE100_SWB_REG(PFUZE3000, SW2, PFUZE100_SW2VOL, 0x7, pfuze3000_sw2lo), |
| 383 | PFUZE3000_SW3_REG(PFUZE3000, SW3, PFUZE100_SW3AVOL, 900000, 1650000, 50000), |
| 384 | PFUZE100_SWB_REG(PFUZE3000, SWBST, PFUZE100_SWBSTCON1, 0x3, pfuze100_swbst), |
| 385 | PFUZE100_SWB_REG(PFUZE3000, VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs), |
| 386 | PFUZE100_FIXED_REG(PFUZE3000, VREFDDR, PFUZE100_VREFDDRCON, 750000), |
| 387 | PFUZE100_VGEN_REG(PFUZE3000, VLDO1, PFUZE100_VGEN1VOL, 1800000, 3300000, 100000), |
| 388 | PFUZE100_VGEN_REG(PFUZE3000, VLDO2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000), |
| 389 | PFUZE3000_VCC_REG(PFUZE3000, VCCSD, PFUZE100_VGEN3VOL, 2850000, 3300000, 150000), |
| 390 | PFUZE3000_VCC_REG(PFUZE3000, V33, PFUZE100_VGEN4VOL, 2850000, 3300000, 150000), |
| 391 | PFUZE100_VGEN_REG(PFUZE3000, VLDO3, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000), |
| 392 | PFUZE100_VGEN_REG(PFUZE3000, VLDO4, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000), |
| 393 | }; |
| 394 | |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 395 | static struct pfuze_regulator pfuze3001_regulators[] = { |
| 396 | PFUZE100_SWB_REG(PFUZE3001, SW1, PFUZE100_SW1ABVOL, 0x1f, pfuze3000_sw1a), |
| 397 | PFUZE100_SWB_REG(PFUZE3001, SW2, PFUZE100_SW2VOL, 0x7, pfuze3000_sw2lo), |
| 398 | PFUZE3000_SW3_REG(PFUZE3001, SW3, PFUZE100_SW3AVOL, 900000, 1650000, 50000), |
| 399 | PFUZE100_SWB_REG(PFUZE3001, VSNVS, PFUZE100_VSNVSVOL, 0x7, pfuze100_vsnvs), |
| 400 | PFUZE100_VGEN_REG(PFUZE3001, VLDO1, PFUZE100_VGEN1VOL, 1800000, 3300000, 100000), |
| 401 | PFUZE100_VGEN_REG(PFUZE3001, VLDO2, PFUZE100_VGEN2VOL, 800000, 1550000, 50000), |
| 402 | PFUZE3000_VCC_REG(PFUZE3001, VCCSD, PFUZE100_VGEN3VOL, 2850000, 3300000, 150000), |
| 403 | PFUZE3000_VCC_REG(PFUZE3001, V33, PFUZE100_VGEN4VOL, 2850000, 3300000, 150000), |
| 404 | PFUZE100_VGEN_REG(PFUZE3001, VLDO3, PFUZE100_VGEN5VOL, 1800000, 3300000, 100000), |
| 405 | PFUZE100_VGEN_REG(PFUZE3001, VLDO4, PFUZE100_VGEN6VOL, 1800000, 3300000, 100000), |
| 406 | }; |
| 407 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 408 | #ifdef CONFIG_OF |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 409 | /* PFUZE100 */ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 410 | static struct of_regulator_match pfuze100_matches[] = { |
| 411 | { .name = "sw1ab", }, |
| 412 | { .name = "sw1c", }, |
| 413 | { .name = "sw2", }, |
| 414 | { .name = "sw3a", }, |
| 415 | { .name = "sw3b", }, |
| 416 | { .name = "sw4", }, |
| 417 | { .name = "swbst", }, |
| 418 | { .name = "vsnvs", }, |
| 419 | { .name = "vrefddr", }, |
| 420 | { .name = "vgen1", }, |
| 421 | { .name = "vgen2", }, |
| 422 | { .name = "vgen3", }, |
| 423 | { .name = "vgen4", }, |
| 424 | { .name = "vgen5", }, |
| 425 | { .name = "vgen6", }, |
| 426 | }; |
| 427 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 428 | /* PFUZE200 */ |
| 429 | static struct of_regulator_match pfuze200_matches[] = { |
| 430 | |
| 431 | { .name = "sw1ab", }, |
| 432 | { .name = "sw2", }, |
| 433 | { .name = "sw3a", }, |
| 434 | { .name = "sw3b", }, |
| 435 | { .name = "swbst", }, |
| 436 | { .name = "vsnvs", }, |
| 437 | { .name = "vrefddr", }, |
| 438 | { .name = "vgen1", }, |
| 439 | { .name = "vgen2", }, |
| 440 | { .name = "vgen3", }, |
| 441 | { .name = "vgen4", }, |
| 442 | { .name = "vgen5", }, |
| 443 | { .name = "vgen6", }, |
George McCollister | c6182ac | 2017-03-09 08:14:43 -0600 | [diff] [blame] | 444 | { .name = "coin", }, |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 445 | }; |
| 446 | |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 447 | /* PFUZE3000 */ |
| 448 | static struct of_regulator_match pfuze3000_matches[] = { |
| 449 | |
| 450 | { .name = "sw1a", }, |
| 451 | { .name = "sw1b", }, |
| 452 | { .name = "sw2", }, |
| 453 | { .name = "sw3", }, |
| 454 | { .name = "swbst", }, |
| 455 | { .name = "vsnvs", }, |
| 456 | { .name = "vrefddr", }, |
| 457 | { .name = "vldo1", }, |
| 458 | { .name = "vldo2", }, |
| 459 | { .name = "vccsd", }, |
| 460 | { .name = "v33", }, |
| 461 | { .name = "vldo3", }, |
| 462 | { .name = "vldo4", }, |
| 463 | }; |
| 464 | |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 465 | /* PFUZE3001 */ |
| 466 | static struct of_regulator_match pfuze3001_matches[] = { |
| 467 | |
| 468 | { .name = "sw1", }, |
| 469 | { .name = "sw2", }, |
| 470 | { .name = "sw3", }, |
| 471 | { .name = "vsnvs", }, |
| 472 | { .name = "vldo1", }, |
| 473 | { .name = "vldo2", }, |
| 474 | { .name = "vccsd", }, |
| 475 | { .name = "v33", }, |
| 476 | { .name = "vldo3", }, |
| 477 | { .name = "vldo4", }, |
| 478 | }; |
| 479 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 480 | static struct of_regulator_match *pfuze_matches; |
| 481 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 482 | static int pfuze_parse_regulators_dt(struct pfuze_chip *chip) |
| 483 | { |
| 484 | struct device *dev = chip->dev; |
| 485 | struct device_node *np, *parent; |
| 486 | int ret; |
| 487 | |
Fabio Estevam | 3e01c75 | 2014-02-18 23:46:14 -0300 | [diff] [blame] | 488 | np = of_node_get(dev->of_node); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 489 | if (!np) |
Fabio Estevam | 6428789 | 2014-02-20 13:47:02 -0300 | [diff] [blame] | 490 | return -EINVAL; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 491 | |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 492 | if (of_property_read_bool(np, "fsl,pfuze-support-disable-sw")) |
| 493 | chip->flags |= PFUZE_FLAG_DISABLE_SW; |
| 494 | |
Sachin Kamat | d7857c4 | 2014-02-14 17:20:00 +0530 | [diff] [blame] | 495 | parent = of_get_child_by_name(np, "regulators"); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 496 | if (!parent) { |
| 497 | dev_err(dev, "regulators node not found\n"); |
| 498 | return -EINVAL; |
| 499 | } |
| 500 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 501 | switch (chip->chip_id) { |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 502 | case PFUZE3001: |
| 503 | pfuze_matches = pfuze3001_matches; |
| 504 | ret = of_regulator_match(dev, parent, pfuze3001_matches, |
| 505 | ARRAY_SIZE(pfuze3001_matches)); |
| 506 | break; |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 507 | case PFUZE3000: |
| 508 | pfuze_matches = pfuze3000_matches; |
| 509 | ret = of_regulator_match(dev, parent, pfuze3000_matches, |
| 510 | ARRAY_SIZE(pfuze3000_matches)); |
| 511 | break; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 512 | case PFUZE200: |
| 513 | pfuze_matches = pfuze200_matches; |
| 514 | ret = of_regulator_match(dev, parent, pfuze200_matches, |
| 515 | ARRAY_SIZE(pfuze200_matches)); |
| 516 | break; |
| 517 | |
| 518 | case PFUZE100: |
| 519 | default: |
| 520 | pfuze_matches = pfuze100_matches; |
| 521 | ret = of_regulator_match(dev, parent, pfuze100_matches, |
| 522 | ARRAY_SIZE(pfuze100_matches)); |
| 523 | break; |
| 524 | } |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 525 | |
| 526 | of_node_put(parent); |
| 527 | if (ret < 0) { |
| 528 | dev_err(dev, "Error parsing regulator init data: %d\n", |
| 529 | ret); |
| 530 | return ret; |
| 531 | } |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static inline struct regulator_init_data *match_init_data(int index) |
| 537 | { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 538 | return pfuze_matches[index].init_data; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static inline struct device_node *match_of_node(int index) |
| 542 | { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 543 | return pfuze_matches[index].of_node; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 544 | } |
| 545 | #else |
| 546 | static int pfuze_parse_regulators_dt(struct pfuze_chip *chip) |
| 547 | { |
Robin Gong | 205c97b | 2013-07-26 10:27:18 +0800 | [diff] [blame] | 548 | return 0; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static inline struct regulator_init_data *match_init_data(int index) |
| 552 | { |
| 553 | return NULL; |
| 554 | } |
| 555 | |
| 556 | static inline struct device_node *match_of_node(int index) |
| 557 | { |
| 558 | return NULL; |
| 559 | } |
| 560 | #endif |
| 561 | |
| 562 | static int pfuze_identify(struct pfuze_chip *pfuze_chip) |
| 563 | { |
| 564 | unsigned int value; |
| 565 | int ret; |
| 566 | |
| 567 | ret = regmap_read(pfuze_chip->regmap, PFUZE100_DEVICEID, &value); |
| 568 | if (ret) |
| 569 | return ret; |
| 570 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 571 | if (((value & 0x0f) == 0x8) && (pfuze_chip->chip_id == PFUZE100)) { |
| 572 | /* |
| 573 | * Freescale misprogrammed 1-3% of parts prior to week 8 of 2013 |
| 574 | * as ID=8 in PFUZE100 |
| 575 | */ |
Fabio Estevam | 62b3891 | 2014-01-15 00:52:45 -0200 | [diff] [blame] | 576 | dev_info(pfuze_chip->dev, "Assuming misprogrammed ID=0x8"); |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 577 | } else if ((value & 0x0f) != pfuze_chip->chip_id && |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 578 | (value & 0xf0) >> 4 != pfuze_chip->chip_id && |
| 579 | (value != pfuze_chip->chip_id)) { |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 580 | /* device id NOT match with your setting */ |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 581 | dev_warn(pfuze_chip->dev, "Illegal ID: %x\n", value); |
| 582 | return -ENODEV; |
| 583 | } |
| 584 | |
| 585 | ret = regmap_read(pfuze_chip->regmap, PFUZE100_REVID, &value); |
| 586 | if (ret) |
| 587 | return ret; |
| 588 | dev_info(pfuze_chip->dev, |
Fabio Estevam | f269438 | 2014-01-20 18:53:56 -0200 | [diff] [blame] | 589 | "Full layer: %x, Metal layer: %x\n", |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 590 | (value & 0xf0) >> 4, value & 0x0f); |
| 591 | |
| 592 | ret = regmap_read(pfuze_chip->regmap, PFUZE100_FABID, &value); |
| 593 | if (ret) |
| 594 | return ret; |
| 595 | dev_info(pfuze_chip->dev, "FAB: %x, FIN: %x\n", |
| 596 | (value & 0xc) >> 2, value & 0x3); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | static const struct regmap_config pfuze_regmap_config = { |
| 602 | .reg_bits = 8, |
| 603 | .val_bits = 8, |
Axel Lin | 6b8430c | 2013-08-01 19:59:56 +0800 | [diff] [blame] | 604 | .max_register = PFUZE_NUMREGS - 1, |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 605 | .cache_type = REGCACHE_RBTREE, |
| 606 | }; |
| 607 | |
| 608 | static int pfuze100_regulator_probe(struct i2c_client *client, |
| 609 | const struct i2c_device_id *id) |
| 610 | { |
| 611 | struct pfuze_chip *pfuze_chip; |
| 612 | struct pfuze_regulator_platform_data *pdata = |
| 613 | dev_get_platdata(&client->dev); |
| 614 | struct regulator_config config = { }; |
| 615 | int i, ret; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 616 | const struct of_device_id *match; |
| 617 | u32 regulator_num; |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 618 | u32 sw_check_start, sw_check_end, sw_hi = 0x40; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 619 | |
| 620 | pfuze_chip = devm_kzalloc(&client->dev, sizeof(*pfuze_chip), |
| 621 | GFP_KERNEL); |
| 622 | if (!pfuze_chip) |
| 623 | return -ENOMEM; |
| 624 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 625 | if (client->dev.of_node) { |
| 626 | match = of_match_device(of_match_ptr(pfuze_dt_ids), |
| 627 | &client->dev); |
| 628 | if (!match) { |
| 629 | dev_err(&client->dev, "Error: No device match found\n"); |
| 630 | return -ENODEV; |
| 631 | } |
| 632 | pfuze_chip->chip_id = (int)(long)match->data; |
| 633 | } else if (id) { |
| 634 | pfuze_chip->chip_id = id->driver_data; |
| 635 | } else { |
| 636 | dev_err(&client->dev, "No dts match or id table match found\n"); |
| 637 | return -ENODEV; |
| 638 | } |
| 639 | |
Axel Lin | 8c86ab2 | 2013-07-29 12:09:12 +0800 | [diff] [blame] | 640 | i2c_set_clientdata(client, pfuze_chip); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 641 | pfuze_chip->dev = &client->dev; |
| 642 | |
| 643 | pfuze_chip->regmap = devm_regmap_init_i2c(client, &pfuze_regmap_config); |
| 644 | if (IS_ERR(pfuze_chip->regmap)) { |
| 645 | ret = PTR_ERR(pfuze_chip->regmap); |
| 646 | dev_err(&client->dev, |
| 647 | "regmap allocation failed with err %d\n", ret); |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | ret = pfuze_identify(pfuze_chip); |
| 652 | if (ret) { |
| 653 | dev_err(&client->dev, "unrecognized pfuze chip ID!\n"); |
| 654 | return ret; |
| 655 | } |
| 656 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 657 | /* use the right regulators after identify the right device */ |
| 658 | switch (pfuze_chip->chip_id) { |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 659 | case PFUZE3001: |
| 660 | pfuze_chip->pfuze_regulators = pfuze3001_regulators; |
| 661 | regulator_num = ARRAY_SIZE(pfuze3001_regulators); |
| 662 | sw_check_start = PFUZE3001_SW2; |
| 663 | sw_check_end = PFUZE3001_SW2; |
| 664 | sw_hi = 1 << 3; |
| 665 | break; |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 666 | case PFUZE3000: |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 667 | pfuze_chip->pfuze_regulators = pfuze3000_regulators; |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 668 | regulator_num = ARRAY_SIZE(pfuze3000_regulators); |
| 669 | sw_check_start = PFUZE3000_SW2; |
| 670 | sw_check_end = PFUZE3000_SW2; |
| 671 | sw_hi = 1 << 3; |
| 672 | break; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 673 | case PFUZE200: |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 674 | pfuze_chip->pfuze_regulators = pfuze200_regulators; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 675 | regulator_num = ARRAY_SIZE(pfuze200_regulators); |
| 676 | sw_check_start = PFUZE200_SW2; |
| 677 | sw_check_end = PFUZE200_SW3B; |
| 678 | break; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 679 | case PFUZE100: |
| 680 | default: |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 681 | pfuze_chip->pfuze_regulators = pfuze100_regulators; |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 682 | regulator_num = ARRAY_SIZE(pfuze100_regulators); |
| 683 | sw_check_start = PFUZE100_SW2; |
| 684 | sw_check_end = PFUZE100_SW4; |
| 685 | break; |
| 686 | } |
| 687 | dev_info(&client->dev, "pfuze%s found.\n", |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 688 | (pfuze_chip->chip_id == PFUZE100) ? "100" : |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 689 | (((pfuze_chip->chip_id == PFUZE200) ? "200" : |
| 690 | ((pfuze_chip->chip_id == PFUZE3000) ? "3000" : "3001")))); |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 691 | |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 692 | memcpy(pfuze_chip->regulator_descs, pfuze_chip->pfuze_regulators, |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 693 | sizeof(pfuze_chip->regulator_descs)); |
| 694 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 695 | ret = pfuze_parse_regulators_dt(pfuze_chip); |
| 696 | if (ret) |
| 697 | return ret; |
| 698 | |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 699 | for (i = 0; i < regulator_num; i++) { |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 700 | struct regulator_init_data *init_data; |
Axel Lin | d949323 | 2013-07-30 10:46:28 +0800 | [diff] [blame] | 701 | struct regulator_desc *desc; |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 702 | int val; |
| 703 | |
Axel Lin | d949323 | 2013-07-30 10:46:28 +0800 | [diff] [blame] | 704 | desc = &pfuze_chip->regulator_descs[i].desc; |
| 705 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 706 | if (pdata) |
| 707 | init_data = pdata->init_data[i]; |
| 708 | else |
| 709 | init_data = match_init_data(i); |
| 710 | |
| 711 | /* SW2~SW4 high bit check and modify the voltage value table */ |
Robin Gong | f251848 | 2014-03-04 17:40:36 +0800 | [diff] [blame] | 712 | if (i >= sw_check_start && i <= sw_check_end) { |
Axel Lin | d949323 | 2013-07-30 10:46:28 +0800 | [diff] [blame] | 713 | regmap_read(pfuze_chip->regmap, desc->vsel_reg, &val); |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 714 | if (val & sw_hi) { |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 715 | if (pfuze_chip->chip_id == PFUZE3000 || |
| 716 | pfuze_chip->chip_id == PFUZE3001) { |
Robin Gong | e5a7a72 | 2015-01-09 09:57:33 +0800 | [diff] [blame] | 717 | desc->volt_table = pfuze3000_sw2hi; |
| 718 | desc->n_voltages = ARRAY_SIZE(pfuze3000_sw2hi); |
| 719 | } else { |
| 720 | desc->min_uV = 800000; |
| 721 | desc->uV_step = 50000; |
| 722 | desc->n_voltages = 51; |
| 723 | } |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | |
Marco Felsch | 9d2fd4f | 2018-07-23 09:47:47 +0200 | [diff] [blame] | 727 | /* |
| 728 | * Allow SW regulators to turn off. Checking it trough a flag is |
| 729 | * a workaround to keep the backward compatibility with existing |
| 730 | * old dtb's which may relay on the fact that we didn't disable |
| 731 | * the switched regulator till yet. |
| 732 | */ |
| 733 | if (pfuze_chip->flags & PFUZE_FLAG_DISABLE_SW) { |
| 734 | if (pfuze_chip->regulator_descs[i].sw_reg) { |
| 735 | desc->ops = &pfuze100_sw_disable_regulator_ops; |
| 736 | desc->enable_val = 0x8; |
| 737 | desc->disable_val = 0x0; |
| 738 | desc->enable_time = 500; |
| 739 | } |
| 740 | } |
| 741 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 742 | config.dev = &client->dev; |
| 743 | config.init_data = init_data; |
| 744 | config.driver_data = pfuze_chip; |
| 745 | config.of_node = match_of_node(i); |
| 746 | |
Jingoo Han | f5247b4 | 2013-12-06 16:11:58 +0900 | [diff] [blame] | 747 | pfuze_chip->regulators[i] = |
| 748 | devm_regulator_register(&client->dev, desc, &config); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 749 | if (IS_ERR(pfuze_chip->regulators[i])) { |
| 750 | dev_err(&client->dev, "register regulator%s failed\n", |
Fabio Estevam | 1242565 | 2016-06-05 19:17:38 -0300 | [diff] [blame] | 751 | pfuze_chip->pfuze_regulators[i].desc.name); |
Jingoo Han | f5247b4 | 2013-12-06 16:11:58 +0900 | [diff] [blame] | 752 | return PTR_ERR(pfuze_chip->regulators[i]); |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 759 | static struct i2c_driver pfuze_driver = { |
| 760 | .id_table = pfuze_device_id, |
| 761 | .driver = { |
| 762 | .name = "pfuze100-regulator", |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 763 | .of_match_table = pfuze_dt_ids, |
| 764 | }, |
| 765 | .probe = pfuze100_regulator_probe, |
Robin Gong | 3784b6d | 2013-07-25 11:33:18 +0800 | [diff] [blame] | 766 | }; |
| 767 | module_i2c_driver(pfuze_driver); |
| 768 | |
| 769 | MODULE_AUTHOR("Robin Gong <b38343@freescale.com>"); |
Stefan Wahren | 297101a | 2018-06-15 13:44:53 +0200 | [diff] [blame] | 770 | MODULE_DESCRIPTION("Regulator Driver for Freescale PFUZE100/200/3000/3001 PMIC"); |
Robin Gong | 12d20fc2 | 2013-07-29 11:40:11 +0800 | [diff] [blame] | 771 | MODULE_LICENSE("GPL v2"); |