pv88080-regulator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * pv88080-regulator.c - Regulator device driver for PV88080
  3. * Copyright (C) 2016 Powerventure Semiconductor Ltd.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/err.h>
  16. #include <linux/i2c.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/init.h>
  20. #include <linux/slab.h>
  21. #include <linux/regulator/driver.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/regmap.h>
  24. #include <linux/irq.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/regulator/of_regulator.h>
  27. #include "pv88080-regulator.h"
  28. #define PV88080_MAX_REGULATORS 4
  29. /* PV88080 REGULATOR IDs */
  30. enum {
  31. /* BUCKs */
  32. PV88080_ID_BUCK1,
  33. PV88080_ID_BUCK2,
  34. PV88080_ID_BUCK3,
  35. PV88080_ID_HVBUCK,
  36. };
  37. enum pv88080_types {
  38. TYPE_PV88080_AA,
  39. TYPE_PV88080_BA,
  40. };
  41. struct pv88080_regulator {
  42. struct regulator_desc desc;
  43. /* Current limiting */
  44. unsigned int n_current_limits;
  45. const int *current_limits;
  46. unsigned int limit_mask;
  47. unsigned int mode_reg;
  48. unsigned int limit_reg;
  49. unsigned int conf2;
  50. unsigned int conf5;
  51. };
  52. struct pv88080 {
  53. struct device *dev;
  54. struct regmap *regmap;
  55. struct regulator_dev *rdev[PV88080_MAX_REGULATORS];
  56. unsigned long type;
  57. const struct pv88080_compatible_regmap *regmap_config;
  58. };
  59. struct pv88080_buck_voltage {
  60. int min_uV;
  61. int max_uV;
  62. int uV_step;
  63. };
  64. struct pv88080_buck_regmap {
  65. /* REGS */
  66. int buck_enable_reg;
  67. int buck_vsel_reg;
  68. int buck_mode_reg;
  69. int buck_limit_reg;
  70. int buck_vdac_range_reg;
  71. int buck_vrange_gain_reg;
  72. /* MASKS */
  73. int buck_enable_mask;
  74. int buck_vsel_mask;
  75. int buck_limit_mask;
  76. };
  77. struct pv88080_compatible_regmap {
  78. /* BUCK1, 2, 3 */
  79. struct pv88080_buck_regmap buck_regmap[PV88080_MAX_REGULATORS-1];
  80. /* HVBUCK */
  81. int hvbuck_enable_reg;
  82. int hvbuck_vsel_reg;
  83. int hvbuck_enable_mask;
  84. int hvbuck_vsel_mask;
  85. };
  86. static const struct regmap_config pv88080_regmap_config = {
  87. .reg_bits = 8,
  88. .val_bits = 8,
  89. };
  90. /* Current limits array (in uA) for BUCK1, BUCK2, BUCK3.
  91. * Entry indexes corresponds to register values.
  92. */
  93. static const int pv88080_buck1_limits[] = {
  94. 3230000, 5130000, 6960000, 8790000
  95. };
  96. static const int pv88080_buck23_limits[] = {
  97. 1496000, 2393000, 3291000, 4189000
  98. };
  99. static const struct pv88080_buck_voltage pv88080_buck_vol[2] = {
  100. {
  101. .min_uV = 600000,
  102. .max_uV = 1393750,
  103. .uV_step = 6250,
  104. },
  105. {
  106. .min_uV = 1400000,
  107. .max_uV = 2193750,
  108. .uV_step = 6250,
  109. },
  110. };
  111. static const struct pv88080_compatible_regmap pv88080_aa_regs = {
  112. /* BUCK1 */
  113. .buck_regmap[0] = {
  114. .buck_enable_reg = PV88080AA_REG_BUCK1_CONF0,
  115. .buck_vsel_reg = PV88080AA_REG_BUCK1_CONF0,
  116. .buck_mode_reg = PV88080AA_REG_BUCK1_CONF1,
  117. .buck_limit_reg = PV88080AA_REG_BUCK1_CONF1,
  118. .buck_vdac_range_reg = PV88080AA_REG_BUCK1_CONF2,
  119. .buck_vrange_gain_reg = PV88080AA_REG_BUCK1_CONF5,
  120. .buck_enable_mask = PV88080_BUCK1_EN,
  121. .buck_vsel_mask = PV88080_VBUCK1_MASK,
  122. .buck_limit_mask = PV88080_BUCK1_ILIM_MASK,
  123. },
  124. /* BUCK2 */
  125. .buck_regmap[1] = {
  126. .buck_enable_reg = PV88080AA_REG_BUCK2_CONF0,
  127. .buck_vsel_reg = PV88080AA_REG_BUCK2_CONF0,
  128. .buck_mode_reg = PV88080AA_REG_BUCK2_CONF1,
  129. .buck_limit_reg = PV88080AA_REG_BUCK2_CONF1,
  130. .buck_vdac_range_reg = PV88080AA_REG_BUCK2_CONF2,
  131. .buck_vrange_gain_reg = PV88080AA_REG_BUCK2_CONF5,
  132. .buck_enable_mask = PV88080_BUCK2_EN,
  133. .buck_vsel_mask = PV88080_VBUCK2_MASK,
  134. .buck_limit_mask = PV88080_BUCK2_ILIM_MASK,
  135. },
  136. /* BUCK3 */
  137. .buck_regmap[2] = {
  138. .buck_enable_reg = PV88080AA_REG_BUCK3_CONF0,
  139. .buck_vsel_reg = PV88080AA_REG_BUCK3_CONF0,
  140. .buck_mode_reg = PV88080AA_REG_BUCK3_CONF1,
  141. .buck_limit_reg = PV88080AA_REG_BUCK3_CONF1,
  142. .buck_vdac_range_reg = PV88080AA_REG_BUCK3_CONF2,
  143. .buck_vrange_gain_reg = PV88080AA_REG_BUCK3_CONF5,
  144. .buck_enable_mask = PV88080_BUCK3_EN,
  145. .buck_vsel_mask = PV88080_VBUCK3_MASK,
  146. .buck_limit_mask = PV88080_BUCK3_ILIM_MASK,
  147. },
  148. /* HVBUCK */
  149. .hvbuck_enable_reg = PV88080AA_REG_HVBUCK_CONF2,
  150. .hvbuck_vsel_reg = PV88080AA_REG_HVBUCK_CONF1,
  151. .hvbuck_enable_mask = PV88080_HVBUCK_EN,
  152. .hvbuck_vsel_mask = PV88080_VHVBUCK_MASK,
  153. };
  154. static const struct pv88080_compatible_regmap pv88080_ba_regs = {
  155. /* BUCK1 */
  156. .buck_regmap[0] = {
  157. .buck_enable_reg = PV88080BA_REG_BUCK1_CONF0,
  158. .buck_vsel_reg = PV88080BA_REG_BUCK1_CONF0,
  159. .buck_mode_reg = PV88080BA_REG_BUCK1_CONF1,
  160. .buck_limit_reg = PV88080BA_REG_BUCK1_CONF1,
  161. .buck_vdac_range_reg = PV88080BA_REG_BUCK1_CONF2,
  162. .buck_vrange_gain_reg = PV88080BA_REG_BUCK1_CONF5,
  163. .buck_enable_mask = PV88080_BUCK1_EN,
  164. .buck_vsel_mask = PV88080_VBUCK1_MASK,
  165. .buck_limit_mask = PV88080_BUCK1_ILIM_MASK,
  166. },
  167. /* BUCK2 */
  168. .buck_regmap[1] = {
  169. .buck_enable_reg = PV88080BA_REG_BUCK2_CONF0,
  170. .buck_vsel_reg = PV88080BA_REG_BUCK2_CONF0,
  171. .buck_mode_reg = PV88080BA_REG_BUCK2_CONF1,
  172. .buck_limit_reg = PV88080BA_REG_BUCK2_CONF1,
  173. .buck_vdac_range_reg = PV88080BA_REG_BUCK2_CONF2,
  174. .buck_vrange_gain_reg = PV88080BA_REG_BUCK2_CONF5,
  175. .buck_enable_mask = PV88080_BUCK2_EN,
  176. .buck_vsel_mask = PV88080_VBUCK2_MASK,
  177. .buck_limit_mask = PV88080_BUCK2_ILIM_MASK,
  178. },
  179. /* BUCK3 */
  180. .buck_regmap[2] = {
  181. .buck_enable_reg = PV88080BA_REG_BUCK3_CONF0,
  182. .buck_vsel_reg = PV88080BA_REG_BUCK3_CONF0,
  183. .buck_mode_reg = PV88080BA_REG_BUCK3_CONF1,
  184. .buck_limit_reg = PV88080BA_REG_BUCK3_CONF1,
  185. .buck_vdac_range_reg = PV88080BA_REG_BUCK3_CONF2,
  186. .buck_vrange_gain_reg = PV88080BA_REG_BUCK3_CONF5,
  187. .buck_enable_mask = PV88080_BUCK3_EN,
  188. .buck_vsel_mask = PV88080_VBUCK3_MASK,
  189. .buck_limit_mask = PV88080_BUCK3_ILIM_MASK,
  190. },
  191. /* HVBUCK */
  192. .hvbuck_enable_reg = PV88080BA_REG_HVBUCK_CONF2,
  193. .hvbuck_vsel_reg = PV88080BA_REG_HVBUCK_CONF1,
  194. .hvbuck_enable_mask = PV88080_HVBUCK_EN,
  195. .hvbuck_vsel_mask = PV88080_VHVBUCK_MASK,
  196. };
  197. #ifdef CONFIG_OF
  198. static const struct of_device_id pv88080_dt_ids[] = {
  199. { .compatible = "pvs,pv88080", .data = (void *)TYPE_PV88080_AA },
  200. { .compatible = "pvs,pv88080-aa", .data = (void *)TYPE_PV88080_AA },
  201. { .compatible = "pvs,pv88080-ba", .data = (void *)TYPE_PV88080_BA },
  202. {},
  203. };
  204. MODULE_DEVICE_TABLE(of, pv88080_dt_ids);
  205. #endif
  206. static unsigned int pv88080_buck_get_mode(struct regulator_dev *rdev)
  207. {
  208. struct pv88080_regulator *info = rdev_get_drvdata(rdev);
  209. unsigned int data;
  210. int ret, mode = 0;
  211. ret = regmap_read(rdev->regmap, info->mode_reg, &data);
  212. if (ret < 0)
  213. return ret;
  214. switch (data & PV88080_BUCK1_MODE_MASK) {
  215. case PV88080_BUCK_MODE_SYNC:
  216. mode = REGULATOR_MODE_FAST;
  217. break;
  218. case PV88080_BUCK_MODE_AUTO:
  219. mode = REGULATOR_MODE_NORMAL;
  220. break;
  221. case PV88080_BUCK_MODE_SLEEP:
  222. mode = REGULATOR_MODE_STANDBY;
  223. break;
  224. default:
  225. return -EINVAL;
  226. }
  227. return mode;
  228. }
  229. static int pv88080_buck_set_mode(struct regulator_dev *rdev,
  230. unsigned int mode)
  231. {
  232. struct pv88080_regulator *info = rdev_get_drvdata(rdev);
  233. int val = 0;
  234. switch (mode) {
  235. case REGULATOR_MODE_FAST:
  236. val = PV88080_BUCK_MODE_SYNC;
  237. break;
  238. case REGULATOR_MODE_NORMAL:
  239. val = PV88080_BUCK_MODE_AUTO;
  240. break;
  241. case REGULATOR_MODE_STANDBY:
  242. val = PV88080_BUCK_MODE_SLEEP;
  243. break;
  244. default:
  245. return -EINVAL;
  246. }
  247. return regmap_update_bits(rdev->regmap, info->mode_reg,
  248. PV88080_BUCK1_MODE_MASK, val);
  249. }
  250. static int pv88080_set_current_limit(struct regulator_dev *rdev, int min,
  251. int max)
  252. {
  253. struct pv88080_regulator *info = rdev_get_drvdata(rdev);
  254. int i;
  255. /* search for closest to maximum */
  256. for (i = info->n_current_limits; i >= 0; i--) {
  257. if (min <= info->current_limits[i]
  258. && max >= info->current_limits[i]) {
  259. return regmap_update_bits(rdev->regmap,
  260. info->limit_reg,
  261. info->limit_mask,
  262. i << PV88080_BUCK1_ILIM_SHIFT);
  263. }
  264. }
  265. return -EINVAL;
  266. }
  267. static int pv88080_get_current_limit(struct regulator_dev *rdev)
  268. {
  269. struct pv88080_regulator *info = rdev_get_drvdata(rdev);
  270. unsigned int data;
  271. int ret;
  272. ret = regmap_read(rdev->regmap, info->limit_reg, &data);
  273. if (ret < 0)
  274. return ret;
  275. data = (data & info->limit_mask) >> PV88080_BUCK1_ILIM_SHIFT;
  276. return info->current_limits[data];
  277. }
  278. static struct regulator_ops pv88080_buck_ops = {
  279. .get_mode = pv88080_buck_get_mode,
  280. .set_mode = pv88080_buck_set_mode,
  281. .enable = regulator_enable_regmap,
  282. .disable = regulator_disable_regmap,
  283. .is_enabled = regulator_is_enabled_regmap,
  284. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  285. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  286. .list_voltage = regulator_list_voltage_linear,
  287. .set_current_limit = pv88080_set_current_limit,
  288. .get_current_limit = pv88080_get_current_limit,
  289. };
  290. static struct regulator_ops pv88080_hvbuck_ops = {
  291. .enable = regulator_enable_regmap,
  292. .disable = regulator_disable_regmap,
  293. .is_enabled = regulator_is_enabled_regmap,
  294. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  295. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  296. .list_voltage = regulator_list_voltage_linear,
  297. };
  298. #define PV88080_BUCK(chip, regl_name, min, step, max, limits_array) \
  299. {\
  300. .desc = {\
  301. .id = chip##_ID_##regl_name,\
  302. .name = __stringify(chip##_##regl_name),\
  303. .of_match = of_match_ptr(#regl_name),\
  304. .regulators_node = of_match_ptr("regulators"),\
  305. .type = REGULATOR_VOLTAGE,\
  306. .owner = THIS_MODULE,\
  307. .ops = &pv88080_buck_ops,\
  308. .min_uV = min, \
  309. .uV_step = step, \
  310. .n_voltages = ((max) - (min))/(step) + 1, \
  311. },\
  312. .current_limits = limits_array, \
  313. .n_current_limits = ARRAY_SIZE(limits_array), \
  314. }
  315. #define PV88080_HVBUCK(chip, regl_name, min, step, max) \
  316. {\
  317. .desc = {\
  318. .id = chip##_ID_##regl_name,\
  319. .name = __stringify(chip##_##regl_name),\
  320. .of_match = of_match_ptr(#regl_name),\
  321. .regulators_node = of_match_ptr("regulators"),\
  322. .type = REGULATOR_VOLTAGE,\
  323. .owner = THIS_MODULE,\
  324. .ops = &pv88080_hvbuck_ops,\
  325. .min_uV = min, \
  326. .uV_step = step, \
  327. .n_voltages = ((max) - (min))/(step) + 1, \
  328. },\
  329. }
  330. static struct pv88080_regulator pv88080_regulator_info[] = {
  331. PV88080_BUCK(PV88080, BUCK1, 600000, 6250, 1393750,
  332. pv88080_buck1_limits),
  333. PV88080_BUCK(PV88080, BUCK2, 600000, 6250, 1393750,
  334. pv88080_buck23_limits),
  335. PV88080_BUCK(PV88080, BUCK3, 600000, 6250, 1393750,
  336. pv88080_buck23_limits),
  337. PV88080_HVBUCK(PV88080, HVBUCK, 0, 5000, 1275000),
  338. };
  339. static irqreturn_t pv88080_irq_handler(int irq, void *data)
  340. {
  341. struct pv88080 *chip = data;
  342. int i, reg_val, err, ret = IRQ_NONE;
  343. err = regmap_read(chip->regmap, PV88080_REG_EVENT_A, &reg_val);
  344. if (err < 0)
  345. goto error_i2c;
  346. if (reg_val & PV88080_E_VDD_FLT) {
  347. for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
  348. if (chip->rdev[i] != NULL) {
  349. regulator_notifier_call_chain(chip->rdev[i],
  350. REGULATOR_EVENT_UNDER_VOLTAGE,
  351. NULL);
  352. }
  353. }
  354. err = regmap_write(chip->regmap, PV88080_REG_EVENT_A,
  355. PV88080_E_VDD_FLT);
  356. if (err < 0)
  357. goto error_i2c;
  358. ret = IRQ_HANDLED;
  359. }
  360. if (reg_val & PV88080_E_OVER_TEMP) {
  361. for (i = 0; i < PV88080_MAX_REGULATORS; i++) {
  362. if (chip->rdev[i] != NULL) {
  363. regulator_notifier_call_chain(chip->rdev[i],
  364. REGULATOR_EVENT_OVER_TEMP,
  365. NULL);
  366. }
  367. }
  368. err = regmap_write(chip->regmap, PV88080_REG_EVENT_A,
  369. PV88080_E_OVER_TEMP);
  370. if (err < 0)
  371. goto error_i2c;
  372. ret = IRQ_HANDLED;
  373. }
  374. return ret;
  375. error_i2c:
  376. dev_err(chip->dev, "I2C error : %d\n", err);
  377. return IRQ_NONE;
  378. }
  379. /*
  380. * I2C driver interface functions
  381. */
  382. static int pv88080_i2c_probe(struct i2c_client *i2c,
  383. const struct i2c_device_id *id)
  384. {
  385. struct regulator_init_data *init_data = dev_get_platdata(&i2c->dev);
  386. struct pv88080 *chip;
  387. const struct pv88080_compatible_regmap *regmap_config;
  388. const struct of_device_id *match;
  389. struct regulator_config config = { };
  390. int i, error, ret;
  391. unsigned int conf2, conf5;
  392. chip = devm_kzalloc(&i2c->dev, sizeof(struct pv88080), GFP_KERNEL);
  393. if (!chip)
  394. return -ENOMEM;
  395. chip->dev = &i2c->dev;
  396. chip->regmap = devm_regmap_init_i2c(i2c, &pv88080_regmap_config);
  397. if (IS_ERR(chip->regmap)) {
  398. error = PTR_ERR(chip->regmap);
  399. dev_err(chip->dev, "Failed to allocate register map: %d\n",
  400. error);
  401. return error;
  402. }
  403. if (i2c->dev.of_node) {
  404. match = of_match_node(pv88080_dt_ids, i2c->dev.of_node);
  405. if (!match) {
  406. dev_err(chip->dev, "Failed to get of_match_node\n");
  407. return -EINVAL;
  408. }
  409. chip->type = (unsigned long)match->data;
  410. } else {
  411. chip->type = id->driver_data;
  412. }
  413. i2c_set_clientdata(i2c, chip);
  414. if (i2c->irq != 0) {
  415. ret = regmap_write(chip->regmap, PV88080_REG_MASK_A, 0xFF);
  416. if (ret < 0) {
  417. dev_err(chip->dev,
  418. "Failed to mask A reg: %d\n", ret);
  419. return ret;
  420. }
  421. ret = regmap_write(chip->regmap, PV88080_REG_MASK_B, 0xFF);
  422. if (ret < 0) {
  423. dev_err(chip->dev,
  424. "Failed to mask B reg: %d\n", ret);
  425. return ret;
  426. }
  427. ret = regmap_write(chip->regmap, PV88080_REG_MASK_C, 0xFF);
  428. if (ret < 0) {
  429. dev_err(chip->dev,
  430. "Failed to mask C reg: %d\n", ret);
  431. return ret;
  432. }
  433. ret = devm_request_threaded_irq(&i2c->dev, i2c->irq, NULL,
  434. pv88080_irq_handler,
  435. IRQF_TRIGGER_LOW|IRQF_ONESHOT,
  436. "pv88080", chip);
  437. if (ret != 0) {
  438. dev_err(chip->dev, "Failed to request IRQ: %d\n",
  439. i2c->irq);
  440. return ret;
  441. }
  442. ret = regmap_update_bits(chip->regmap, PV88080_REG_MASK_A,
  443. PV88080_M_VDD_FLT | PV88080_M_OVER_TEMP, 0);
  444. if (ret < 0) {
  445. dev_err(chip->dev,
  446. "Failed to update mask reg: %d\n", ret);
  447. return ret;
  448. }
  449. } else {
  450. dev_warn(chip->dev, "No IRQ configured\n");
  451. }
  452. switch (chip->type) {
  453. case TYPE_PV88080_AA:
  454. chip->regmap_config = &pv88080_aa_regs;
  455. break;
  456. case TYPE_PV88080_BA:
  457. chip->regmap_config = &pv88080_ba_regs;
  458. break;
  459. }
  460. regmap_config = chip->regmap_config;
  461. config.dev = chip->dev;
  462. config.regmap = chip->regmap;
  463. /* Registeration for BUCK1, 2, 3 */
  464. for (i = 0; i < PV88080_MAX_REGULATORS-1; i++) {
  465. if (init_data)
  466. config.init_data = &init_data[i];
  467. pv88080_regulator_info[i].limit_reg
  468. = regmap_config->buck_regmap[i].buck_limit_reg;
  469. pv88080_regulator_info[i].limit_mask
  470. = regmap_config->buck_regmap[i].buck_limit_mask;
  471. pv88080_regulator_info[i].mode_reg
  472. = regmap_config->buck_regmap[i].buck_mode_reg;
  473. pv88080_regulator_info[i].conf2
  474. = regmap_config->buck_regmap[i].buck_vdac_range_reg;
  475. pv88080_regulator_info[i].conf5
  476. = regmap_config->buck_regmap[i].buck_vrange_gain_reg;
  477. pv88080_regulator_info[i].desc.enable_reg
  478. = regmap_config->buck_regmap[i].buck_enable_reg;
  479. pv88080_regulator_info[i].desc.enable_mask
  480. = regmap_config->buck_regmap[i].buck_enable_mask;
  481. pv88080_regulator_info[i].desc.vsel_reg
  482. = regmap_config->buck_regmap[i].buck_vsel_reg;
  483. pv88080_regulator_info[i].desc.vsel_mask
  484. = regmap_config->buck_regmap[i].buck_vsel_mask;
  485. ret = regmap_read(chip->regmap,
  486. pv88080_regulator_info[i].conf2, &conf2);
  487. if (ret < 0)
  488. return ret;
  489. conf2 = ((conf2 >> PV88080_BUCK_VDAC_RANGE_SHIFT) &
  490. PV88080_BUCK_VDAC_RANGE_MASK);
  491. ret = regmap_read(chip->regmap,
  492. pv88080_regulator_info[i].conf5, &conf5);
  493. if (ret < 0)
  494. return ret;
  495. conf5 = ((conf5 >> PV88080_BUCK_VRANGE_GAIN_SHIFT) &
  496. PV88080_BUCK_VRANGE_GAIN_MASK);
  497. pv88080_regulator_info[i].desc.min_uV =
  498. pv88080_buck_vol[conf2].min_uV * (conf5+1);
  499. pv88080_regulator_info[i].desc.uV_step =
  500. pv88080_buck_vol[conf2].uV_step * (conf5+1);
  501. pv88080_regulator_info[i].desc.n_voltages =
  502. ((pv88080_buck_vol[conf2].max_uV * (conf5+1))
  503. - (pv88080_regulator_info[i].desc.min_uV))
  504. /(pv88080_regulator_info[i].desc.uV_step) + 1;
  505. config.driver_data = (void *)&pv88080_regulator_info[i];
  506. chip->rdev[i] = devm_regulator_register(chip->dev,
  507. &pv88080_regulator_info[i].desc, &config);
  508. if (IS_ERR(chip->rdev[i])) {
  509. dev_err(chip->dev,
  510. "Failed to register PV88080 regulator\n");
  511. return PTR_ERR(chip->rdev[i]);
  512. }
  513. }
  514. pv88080_regulator_info[PV88080_ID_HVBUCK].desc.enable_reg
  515. = regmap_config->hvbuck_enable_reg;
  516. pv88080_regulator_info[PV88080_ID_HVBUCK].desc.enable_mask
  517. = regmap_config->hvbuck_enable_mask;
  518. pv88080_regulator_info[PV88080_ID_HVBUCK].desc.vsel_reg
  519. = regmap_config->hvbuck_vsel_reg;
  520. pv88080_regulator_info[PV88080_ID_HVBUCK].desc.vsel_mask
  521. = regmap_config->hvbuck_vsel_mask;
  522. /* Registeration for HVBUCK */
  523. if (init_data)
  524. config.init_data = &init_data[PV88080_ID_HVBUCK];
  525. config.driver_data = (void *)&pv88080_regulator_info[PV88080_ID_HVBUCK];
  526. chip->rdev[PV88080_ID_HVBUCK] = devm_regulator_register(chip->dev,
  527. &pv88080_regulator_info[PV88080_ID_HVBUCK].desc, &config);
  528. if (IS_ERR(chip->rdev[PV88080_ID_HVBUCK])) {
  529. dev_err(chip->dev, "Failed to register PV88080 regulator\n");
  530. return PTR_ERR(chip->rdev[PV88080_ID_HVBUCK]);
  531. }
  532. return 0;
  533. }
  534. static const struct i2c_device_id pv88080_i2c_id[] = {
  535. { "pv88080", TYPE_PV88080_AA },
  536. { "pv88080-aa", TYPE_PV88080_AA },
  537. { "pv88080-ba", TYPE_PV88080_BA },
  538. {},
  539. };
  540. MODULE_DEVICE_TABLE(i2c, pv88080_i2c_id);
  541. static struct i2c_driver pv88080_regulator_driver = {
  542. .driver = {
  543. .name = "pv88080",
  544. .of_match_table = of_match_ptr(pv88080_dt_ids),
  545. },
  546. .probe = pv88080_i2c_probe,
  547. .id_table = pv88080_i2c_id,
  548. };
  549. module_i2c_driver(pv88080_regulator_driver);
  550. MODULE_AUTHOR("James Ban <[email protected]>");
  551. MODULE_DESCRIPTION("Regulator device driver for Powerventure PV88080");
  552. MODULE_LICENSE("GPL");