Fabio Estevam | c07bbfe | 2018-05-23 16:17:35 -0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved. |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 4 | |
| 5 | #include <linux/slab.h> |
| 6 | #include <linux/device.h> |
| 7 | #include <linux/module.h> |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 8 | #include <linux/mfd/syscon.h> |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 9 | #include <linux/err.h> |
| 10 | #include <linux/io.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/of.h> |
| 13 | #include <linux/of_address.h> |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 14 | #include <linux/regmap.h> |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 15 | #include <linux/regulator/driver.h> |
| 16 | #include <linux/regulator/of_regulator.h> |
Sascha Hauer | 0d19208 | 2015-10-13 12:45:30 +0200 | [diff] [blame] | 17 | #include <linux/regulator/machine.h> |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 18 | |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 19 | #define LDO_RAMP_UP_UNIT_IN_CYCLES 64 /* 64 cycles per step */ |
| 20 | #define LDO_RAMP_UP_FREQ_IN_MHZ 24 /* cycle based on 24M OSC */ |
| 21 | |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 22 | #define LDO_POWER_GATE 0x00 |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 23 | #define LDO_FET_FULL_ON 0x1f |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 24 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 25 | struct anatop_regulator { |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 26 | u32 delay_reg; |
| 27 | int delay_bit_shift; |
| 28 | int delay_bit_width; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 29 | struct regulator_desc rdesc; |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 30 | bool bypass; |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 31 | int sel; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 32 | }; |
| 33 | |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 34 | static int anatop_regmap_set_voltage_time_sel(struct regulator_dev *reg, |
| 35 | unsigned int old_sel, |
| 36 | unsigned int new_sel) |
| 37 | { |
| 38 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
| 39 | u32 val; |
| 40 | int ret = 0; |
| 41 | |
| 42 | /* check whether need to care about LDO ramp up speed */ |
| 43 | if (anatop_reg->delay_bit_width && new_sel > old_sel) { |
| 44 | /* |
| 45 | * the delay for LDO ramp up time is |
| 46 | * based on the register setting, we need |
| 47 | * to calculate how many steps LDO need to |
| 48 | * ramp up, and how much delay needed. (us) |
| 49 | */ |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 50 | regmap_read(reg->regmap, anatop_reg->delay_reg, &val); |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 51 | val = (val >> anatop_reg->delay_bit_shift) & |
| 52 | ((1 << anatop_reg->delay_bit_width) - 1); |
Shawn Guo | ff1ce05 | 2013-02-04 10:21:32 +0800 | [diff] [blame] | 53 | ret = (new_sel - old_sel) * (LDO_RAMP_UP_UNIT_IN_CYCLES << |
| 54 | val) / LDO_RAMP_UP_FREQ_IN_MHZ + 1; |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return ret; |
| 58 | } |
| 59 | |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 60 | static int anatop_regmap_enable(struct regulator_dev *reg) |
| 61 | { |
| 62 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 63 | int sel; |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 64 | |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 65 | sel = anatop_reg->bypass ? LDO_FET_FULL_ON : anatop_reg->sel; |
| 66 | return regulator_set_voltage_sel_regmap(reg, sel); |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static int anatop_regmap_disable(struct regulator_dev *reg) |
| 70 | { |
| 71 | return regulator_set_voltage_sel_regmap(reg, LDO_POWER_GATE); |
| 72 | } |
| 73 | |
| 74 | static int anatop_regmap_is_enabled(struct regulator_dev *reg) |
| 75 | { |
| 76 | return regulator_get_voltage_sel_regmap(reg) != LDO_POWER_GATE; |
| 77 | } |
| 78 | |
| 79 | static int anatop_regmap_core_set_voltage_sel(struct regulator_dev *reg, |
| 80 | unsigned selector) |
| 81 | { |
| 82 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
| 83 | int ret; |
| 84 | |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 85 | if (anatop_reg->bypass || !anatop_regmap_is_enabled(reg)) { |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 86 | anatop_reg->sel = selector; |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | ret = regulator_set_voltage_sel_regmap(reg, selector); |
| 91 | if (!ret) |
| 92 | anatop_reg->sel = selector; |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | static int anatop_regmap_core_get_voltage_sel(struct regulator_dev *reg) |
| 97 | { |
| 98 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
| 99 | |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 100 | if (anatop_reg->bypass || !anatop_regmap_is_enabled(reg)) |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 101 | return anatop_reg->sel; |
| 102 | |
| 103 | return regulator_get_voltage_sel_regmap(reg); |
| 104 | } |
| 105 | |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 106 | static int anatop_regmap_get_bypass(struct regulator_dev *reg, bool *enable) |
| 107 | { |
| 108 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
| 109 | int sel; |
| 110 | |
| 111 | sel = regulator_get_voltage_sel_regmap(reg); |
| 112 | if (sel == LDO_FET_FULL_ON) |
| 113 | WARN_ON(!anatop_reg->bypass); |
| 114 | else if (sel != LDO_POWER_GATE) |
| 115 | WARN_ON(anatop_reg->bypass); |
| 116 | |
| 117 | *enable = anatop_reg->bypass; |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static int anatop_regmap_set_bypass(struct regulator_dev *reg, bool enable) |
| 122 | { |
| 123 | struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg); |
| 124 | int sel; |
| 125 | |
| 126 | if (enable == anatop_reg->bypass) |
| 127 | return 0; |
| 128 | |
| 129 | sel = enable ? LDO_FET_FULL_ON : anatop_reg->sel; |
| 130 | anatop_reg->bypass = enable; |
| 131 | |
| 132 | return regulator_set_voltage_sel_regmap(reg, sel); |
| 133 | } |
| 134 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 135 | static struct regulator_ops anatop_rops = { |
Axel Lin | 114c574 | 2014-02-22 12:53:18 +0800 | [diff] [blame] | 136 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 137 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Axel Lin | d01c3a1e | 2012-06-03 23:02:34 +0800 | [diff] [blame] | 138 | .list_voltage = regulator_list_voltage_linear, |
| 139 | .map_voltage = regulator_map_voltage_linear, |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 140 | }; |
| 141 | |
Rikard Falkeborn | cae62a9 | 2020-06-18 00:32:43 +0200 | [diff] [blame] | 142 | static const struct regulator_ops anatop_core_rops = { |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 143 | .enable = anatop_regmap_enable, |
| 144 | .disable = anatop_regmap_disable, |
| 145 | .is_enabled = anatop_regmap_is_enabled, |
| 146 | .set_voltage_sel = anatop_regmap_core_set_voltage_sel, |
| 147 | .set_voltage_time_sel = anatop_regmap_set_voltage_time_sel, |
| 148 | .get_voltage_sel = anatop_regmap_core_get_voltage_sel, |
| 149 | .list_voltage = regulator_list_voltage_linear, |
| 150 | .map_voltage = regulator_map_voltage_linear, |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 151 | .get_bypass = anatop_regmap_get_bypass, |
| 152 | .set_bypass = anatop_regmap_set_bypass, |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 153 | }; |
| 154 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 155 | static int anatop_regulator_probe(struct platform_device *pdev) |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 156 | { |
| 157 | struct device *dev = &pdev->dev; |
| 158 | struct device_node *np = dev->of_node; |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 159 | struct device_node *anatop_np; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 160 | struct regulator_desc *rdesc; |
| 161 | struct regulator_dev *rdev; |
| 162 | struct anatop_regulator *sreg; |
| 163 | struct regulator_init_data *initdata; |
Axel Lin | d914d81 | 2012-04-10 22:45:01 +0800 | [diff] [blame] | 164 | struct regulator_config config = { }; |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 165 | struct regmap *regmap; |
| 166 | u32 control_reg; |
| 167 | u32 vol_bit_shift; |
| 168 | u32 vol_bit_width; |
| 169 | u32 min_bit_val; |
| 170 | u32 min_voltage; |
| 171 | u32 max_voltage; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 172 | int ret = 0; |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 173 | u32 val; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 174 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 175 | sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); |
| 176 | if (!sreg) |
| 177 | return -ENOMEM; |
Dong Aisheng | 5062e04 | 2017-04-12 09:58:44 +0800 | [diff] [blame] | 178 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 179 | rdesc = &sreg->rdesc; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 180 | rdesc->type = REGULATOR_VOLTAGE; |
| 181 | rdesc->owner = THIS_MODULE; |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 182 | |
Dong Aisheng | aeb1404 | 2017-04-12 09:58:45 +0800 | [diff] [blame] | 183 | of_property_read_string(np, "regulator-name", &rdesc->name); |
Dong Aisheng | 4af5924 | 2017-04-14 22:32:43 +0800 | [diff] [blame] | 184 | if (!rdesc->name) { |
| 185 | dev_err(dev, "failed to get a regulator-name\n"); |
| 186 | return -EINVAL; |
| 187 | } |
Dong Aisheng | aeb1404 | 2017-04-12 09:58:45 +0800 | [diff] [blame] | 188 | |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 189 | initdata = of_get_regulator_init_data(dev, np, rdesc); |
Dong Aisheng | 7f51cf2 | 2017-04-12 09:58:42 +0800 | [diff] [blame] | 190 | if (!initdata) |
| 191 | return -ENOMEM; |
| 192 | |
Sascha Hauer | 0d19208 | 2015-10-13 12:45:30 +0200 | [diff] [blame] | 193 | initdata->supply_regulator = "vin"; |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 194 | |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 195 | anatop_np = of_get_parent(np); |
| 196 | if (!anatop_np) |
| 197 | return -ENODEV; |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 198 | regmap = syscon_node_to_regmap(anatop_np); |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 199 | of_node_put(anatop_np); |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 200 | if (IS_ERR(regmap)) |
| 201 | return PTR_ERR(regmap); |
Dong Aisheng | baa6415 | 2012-09-05 10:57:15 +0800 | [diff] [blame] | 202 | |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 203 | ret = of_property_read_u32(np, "anatop-reg-offset", &control_reg); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 204 | if (ret) { |
Ying-Chun Liu (PaulLiu) | 2f2cc27 | 2012-03-27 15:54:01 +0800 | [diff] [blame] | 205 | dev_err(dev, "no anatop-reg-offset property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 206 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 207 | } |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 208 | ret = of_property_read_u32(np, "anatop-vol-bit-width", &vol_bit_width); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 209 | if (ret) { |
| 210 | dev_err(dev, "no anatop-vol-bit-width property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 211 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 212 | } |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 213 | ret = of_property_read_u32(np, "anatop-vol-bit-shift", &vol_bit_shift); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 214 | if (ret) { |
| 215 | dev_err(dev, "no anatop-vol-bit-shift property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 216 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 217 | } |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 218 | ret = of_property_read_u32(np, "anatop-min-bit-val", &min_bit_val); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 219 | if (ret) { |
| 220 | dev_err(dev, "no anatop-min-bit-val property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 221 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 222 | } |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 223 | ret = of_property_read_u32(np, "anatop-min-voltage", &min_voltage); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 224 | if (ret) { |
| 225 | dev_err(dev, "no anatop-min-voltage property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 226 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 227 | } |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 228 | ret = of_property_read_u32(np, "anatop-max-voltage", &max_voltage); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 229 | if (ret) { |
| 230 | dev_err(dev, "no anatop-max-voltage property set\n"); |
Fabio Estevam | f2b269b | 2014-01-06 10:13:15 -0200 | [diff] [blame] | 231 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 232 | } |
| 233 | |
Anson Huang | 9ee417c | 2013-01-31 11:23:53 -0500 | [diff] [blame] | 234 | /* read LDO ramp up setting, only for core reg */ |
| 235 | of_property_read_u32(np, "anatop-delay-reg-offset", |
| 236 | &sreg->delay_reg); |
| 237 | of_property_read_u32(np, "anatop-delay-bit-width", |
| 238 | &sreg->delay_bit_width); |
| 239 | of_property_read_u32(np, "anatop-delay-bit-shift", |
| 240 | &sreg->delay_bit_shift); |
| 241 | |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 242 | rdesc->n_voltages = (max_voltage - min_voltage) / 25000 + 1 |
| 243 | + min_bit_val; |
| 244 | rdesc->min_uV = min_voltage; |
Axel Lin | 0713e6a | 2012-05-14 11:06:44 +0800 | [diff] [blame] | 245 | rdesc->uV_step = 25000; |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 246 | rdesc->linear_min_sel = min_bit_val; |
| 247 | rdesc->vsel_reg = control_reg; |
| 248 | rdesc->vsel_mask = ((1 << vol_bit_width) - 1) << vol_bit_shift; |
Sascha Hauer | 0d19208 | 2015-10-13 12:45:30 +0200 | [diff] [blame] | 249 | rdesc->min_dropout_uV = 125000; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 250 | |
Axel Lin | d914d81 | 2012-04-10 22:45:01 +0800 | [diff] [blame] | 251 | config.dev = &pdev->dev; |
| 252 | config.init_data = initdata; |
| 253 | config.driver_data = sreg; |
| 254 | config.of_node = pdev->dev.of_node; |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 255 | config.regmap = regmap; |
Axel Lin | d914d81 | 2012-04-10 22:45:01 +0800 | [diff] [blame] | 256 | |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 257 | /* Only core regulators have the ramp up delay configuration. */ |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 258 | if (control_reg && sreg->delay_bit_width) { |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 259 | rdesc->ops = &anatop_core_rops; |
| 260 | |
| 261 | ret = regmap_read(config.regmap, rdesc->vsel_reg, &val); |
| 262 | if (ret) { |
| 263 | dev_err(dev, "failed to read initial state\n"); |
| 264 | return ret; |
| 265 | } |
| 266 | |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 267 | sreg->sel = (val & rdesc->vsel_mask) >> vol_bit_shift; |
Philipp Zabel | d38018f | 2014-02-11 14:43:45 +0100 | [diff] [blame] | 268 | if (sreg->sel == LDO_FET_FULL_ON) { |
| 269 | sreg->sel = 0; |
| 270 | sreg->bypass = true; |
| 271 | } |
Markus Pargmann | fe08be3 | 2014-10-06 21:33:36 +0200 | [diff] [blame] | 272 | |
| 273 | /* |
| 274 | * In case vddpu was disabled by the bootloader, we need to set |
| 275 | * a sane default until imx6-cpufreq was probed and changes the |
| 276 | * voltage to the correct value. In this case we set 1.25V. |
| 277 | */ |
Dong Aisheng | aeb1404 | 2017-04-12 09:58:45 +0800 | [diff] [blame] | 278 | if (!sreg->sel && !strcmp(rdesc->name, "vddpu")) |
Markus Pargmann | fe08be3 | 2014-10-06 21:33:36 +0200 | [diff] [blame] | 279 | sreg->sel = 22; |
Markus Pargmann | da0607c | 2014-10-06 21:33:37 +0200 | [diff] [blame] | 280 | |
Dong Aisheng | 9bf9445 | 2017-04-12 09:58:47 +0800 | [diff] [blame] | 281 | /* set the default voltage of the pcie phy to be 1.100v */ |
Dong Aisheng | 4af5924 | 2017-04-14 22:32:43 +0800 | [diff] [blame] | 282 | if (!sreg->sel && !strcmp(rdesc->name, "vddpcie")) |
Dong Aisheng | 9bf9445 | 2017-04-12 09:58:47 +0800 | [diff] [blame] | 283 | sreg->sel = 0x10; |
| 284 | |
Mika Båtsman | 8a092e6 | 2016-06-17 13:31:37 +0300 | [diff] [blame] | 285 | if (!sreg->bypass && !sreg->sel) { |
Markus Pargmann | da0607c | 2014-10-06 21:33:37 +0200 | [diff] [blame] | 286 | dev_err(&pdev->dev, "Failed to read a valid default voltage selector.\n"); |
| 287 | return -EINVAL; |
| 288 | } |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 289 | } else { |
Andrey Smirnov | ca7734a | 2017-01-10 08:30:14 -0800 | [diff] [blame] | 290 | u32 enable_bit; |
| 291 | |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 292 | rdesc->ops = &anatop_rops; |
Andrey Smirnov | ca7734a | 2017-01-10 08:30:14 -0800 | [diff] [blame] | 293 | |
| 294 | if (!of_property_read_u32(np, "anatop-enable-bit", |
| 295 | &enable_bit)) { |
| 296 | anatop_rops.enable = regulator_enable_regmap; |
| 297 | anatop_rops.disable = regulator_disable_regmap; |
| 298 | anatop_rops.is_enabled = regulator_is_enabled_regmap; |
| 299 | |
Axel Lin | f34a269 | 2019-04-10 00:10:39 +0800 | [diff] [blame] | 300 | rdesc->enable_reg = control_reg; |
Andrey Smirnov | ca7734a | 2017-01-10 08:30:14 -0800 | [diff] [blame] | 301 | rdesc->enable_mask = BIT(enable_bit); |
| 302 | } |
Philipp Zabel | 605ebd3 | 2014-02-11 14:43:44 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 305 | /* register regulator */ |
Sachin Kamat | be1221e | 2013-09-04 12:00:57 +0530 | [diff] [blame] | 306 | rdev = devm_regulator_register(dev, rdesc, &config); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 307 | if (IS_ERR(rdev)) { |
Anson Huang | 788bfc6 | 2020-03-03 21:44:12 +0800 | [diff] [blame] | 308 | ret = PTR_ERR(rdev); |
| 309 | if (ret == -EPROBE_DEFER) |
| 310 | dev_dbg(dev, "failed to register %s, deferring...\n", |
| 311 | rdesc->name); |
| 312 | else |
| 313 | dev_err(dev, "failed to register %s\n", rdesc->name); |
| 314 | return ret; |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | platform_set_drvdata(pdev, rdev); |
| 318 | |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 319 | return 0; |
| 320 | } |
| 321 | |
Jingoo Han | a799baa | 2014-05-07 16:55:10 +0900 | [diff] [blame] | 322 | static const struct of_device_id of_anatop_regulator_match_tbl[] = { |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 323 | { .compatible = "fsl,anatop-regulator", }, |
| 324 | { /* end */ } |
| 325 | }; |
Luis de Bethencourt | d702ffd | 2015-09-18 19:09:07 +0200 | [diff] [blame] | 326 | MODULE_DEVICE_TABLE(of, of_anatop_regulator_match_tbl); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 327 | |
Shawn Guo | c0d78c2 | 2012-04-02 14:57:01 +0800 | [diff] [blame] | 328 | static struct platform_driver anatop_regulator_driver = { |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 329 | .driver = { |
| 330 | .name = "anatop_regulator", |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 331 | .of_match_table = of_anatop_regulator_match_tbl, |
| 332 | }, |
| 333 | .probe = anatop_regulator_probe, |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | static int __init anatop_regulator_init(void) |
| 337 | { |
Shawn Guo | c0d78c2 | 2012-04-02 14:57:01 +0800 | [diff] [blame] | 338 | return platform_driver_register(&anatop_regulator_driver); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 339 | } |
| 340 | postcore_initcall(anatop_regulator_init); |
| 341 | |
| 342 | static void __exit anatop_regulator_exit(void) |
| 343 | { |
Shawn Guo | c0d78c2 | 2012-04-02 14:57:01 +0800 | [diff] [blame] | 344 | platform_driver_unregister(&anatop_regulator_driver); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 345 | } |
| 346 | module_exit(anatop_regulator_exit); |
| 347 | |
Jingoo Han | 34f7568 | 2013-10-14 17:45:51 +0900 | [diff] [blame] | 348 | MODULE_AUTHOR("Nancy Chen <Nancy.Chen@freescale.com>"); |
| 349 | MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>"); |
Ying-Chun Liu (PaulLiu) | e3e5aff | 2012-03-14 10:29:12 +0800 | [diff] [blame] | 350 | MODULE_DESCRIPTION("ANATOP Regulator driver"); |
| 351 | MODULE_LICENSE("GPL v2"); |
Fabio Estevam | 89705b9 | 2013-12-31 10:56:00 -0200 | [diff] [blame] | 352 | MODULE_ALIAS("platform:anatop_regulator"); |