.. | .. |
---|
1 | 1 | /* |
---|
2 | 2 | * Driver for TPS65218 Integrated power management chipsets |
---|
3 | 3 | * |
---|
4 | | - * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ |
---|
| 4 | + * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/ |
---|
5 | 5 | * |
---|
6 | 6 | * This program is free software; you can redistribute it and/or |
---|
7 | 7 | * modify it under the terms of the GNU General Public License version 2 as |
---|
.. | .. |
---|
48 | 48 | /** |
---|
49 | 49 | * tps65218_reg_write: Write a single tps65218 register. |
---|
50 | 50 | * |
---|
51 | | - * @tps65218: Device to write to. |
---|
| 51 | + * @tps: Device to write to. |
---|
52 | 52 | * @reg: Register to write to. |
---|
53 | 53 | * @val: Value to write. |
---|
54 | 54 | * @level: Password protected level |
---|
.. | .. |
---|
79 | 79 | /** |
---|
80 | 80 | * tps65218_update_bits: Modify bits w.r.t mask, val and level. |
---|
81 | 81 | * |
---|
82 | | - * @tps65218: Device to write to. |
---|
| 82 | + * @tps: Device to write to. |
---|
83 | 83 | * @reg: Register to read-write to. |
---|
84 | 84 | * @mask: Mask. |
---|
85 | 85 | * @val: Value to write. |
---|
.. | .. |
---|
211 | 211 | }; |
---|
212 | 212 | MODULE_DEVICE_TABLE(of, of_tps65218_match_table); |
---|
213 | 213 | |
---|
| 214 | +static int tps65218_voltage_set_strict(struct tps65218 *tps) |
---|
| 215 | +{ |
---|
| 216 | + u32 strict; |
---|
| 217 | + |
---|
| 218 | + if (of_property_read_u32(tps->dev->of_node, |
---|
| 219 | + "ti,strict-supply-voltage-supervision", |
---|
| 220 | + &strict)) |
---|
| 221 | + return 0; |
---|
| 222 | + |
---|
| 223 | + if (strict != 0 && strict != 1) { |
---|
| 224 | + dev_err(tps->dev, |
---|
| 225 | + "Invalid ti,strict-supply-voltage-supervision value\n"); |
---|
| 226 | + return -EINVAL; |
---|
| 227 | + } |
---|
| 228 | + |
---|
| 229 | + tps65218_update_bits(tps, TPS65218_REG_CONFIG1, |
---|
| 230 | + TPS65218_CONFIG1_STRICT, |
---|
| 231 | + strict ? TPS65218_CONFIG1_STRICT : 0, |
---|
| 232 | + TPS65218_PROTECT_L1); |
---|
| 233 | + return 0; |
---|
| 234 | +} |
---|
| 235 | + |
---|
| 236 | +static int tps65218_voltage_set_uv_hyst(struct tps65218 *tps) |
---|
| 237 | +{ |
---|
| 238 | + u32 hyst; |
---|
| 239 | + |
---|
| 240 | + if (of_property_read_u32(tps->dev->of_node, |
---|
| 241 | + "ti,under-voltage-hyst-microvolt", &hyst)) |
---|
| 242 | + return 0; |
---|
| 243 | + |
---|
| 244 | + if (hyst != 400000 && hyst != 200000) { |
---|
| 245 | + dev_err(tps->dev, |
---|
| 246 | + "Invalid ti,under-voltage-hyst-microvolt value\n"); |
---|
| 247 | + return -EINVAL; |
---|
| 248 | + } |
---|
| 249 | + |
---|
| 250 | + tps65218_update_bits(tps, TPS65218_REG_CONFIG2, |
---|
| 251 | + TPS65218_CONFIG2_UVLOHYS, |
---|
| 252 | + hyst == 400000 ? TPS65218_CONFIG2_UVLOHYS : 0, |
---|
| 253 | + TPS65218_PROTECT_L1); |
---|
| 254 | + return 0; |
---|
| 255 | +} |
---|
| 256 | + |
---|
| 257 | +static int tps65218_voltage_set_uvlo(struct tps65218 *tps) |
---|
| 258 | +{ |
---|
| 259 | + u32 uvlo; |
---|
| 260 | + int uvloval; |
---|
| 261 | + |
---|
| 262 | + if (of_property_read_u32(tps->dev->of_node, |
---|
| 263 | + "ti,under-voltage-limit-microvolt", &uvlo)) |
---|
| 264 | + return 0; |
---|
| 265 | + |
---|
| 266 | + switch (uvlo) { |
---|
| 267 | + case 2750000: |
---|
| 268 | + uvloval = TPS65218_CONFIG1_UVLO_2750000; |
---|
| 269 | + break; |
---|
| 270 | + case 2950000: |
---|
| 271 | + uvloval = TPS65218_CONFIG1_UVLO_2950000; |
---|
| 272 | + break; |
---|
| 273 | + case 3250000: |
---|
| 274 | + uvloval = TPS65218_CONFIG1_UVLO_3250000; |
---|
| 275 | + break; |
---|
| 276 | + case 3350000: |
---|
| 277 | + uvloval = TPS65218_CONFIG1_UVLO_3350000; |
---|
| 278 | + break; |
---|
| 279 | + default: |
---|
| 280 | + dev_err(tps->dev, |
---|
| 281 | + "Invalid ti,under-voltage-limit-microvolt value\n"); |
---|
| 282 | + return -EINVAL; |
---|
| 283 | + } |
---|
| 284 | + |
---|
| 285 | + tps65218_update_bits(tps, TPS65218_REG_CONFIG1, |
---|
| 286 | + TPS65218_CONFIG1_UVLO_MASK, uvloval, |
---|
| 287 | + TPS65218_PROTECT_L1); |
---|
| 288 | + return 0; |
---|
| 289 | +} |
---|
| 290 | + |
---|
214 | 291 | static int tps65218_probe(struct i2c_client *client, |
---|
215 | 292 | const struct i2c_device_id *ids) |
---|
216 | 293 | { |
---|
.. | .. |
---|
249 | 326 | |
---|
250 | 327 | tps->rev = chipid & TPS65218_CHIPID_REV_MASK; |
---|
251 | 328 | |
---|
| 329 | + ret = tps65218_voltage_set_strict(tps); |
---|
| 330 | + if (ret) |
---|
| 331 | + return ret; |
---|
| 332 | + |
---|
| 333 | + ret = tps65218_voltage_set_uvlo(tps); |
---|
| 334 | + if (ret) |
---|
| 335 | + return ret; |
---|
| 336 | + |
---|
| 337 | + ret = tps65218_voltage_set_uv_hyst(tps); |
---|
| 338 | + if (ret) |
---|
| 339 | + return ret; |
---|
| 340 | + |
---|
252 | 341 | ret = mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO, tps65218_cells, |
---|
253 | 342 | ARRAY_SIZE(tps65218_cells), NULL, 0, |
---|
254 | 343 | regmap_irq_get_domain(tps->irq_data)); |
---|