pv88080-regulator.c 16 KB

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