max77802-regulator.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * max77802.c - Regulator driver for the Maxim 77802
  3. *
  4. * Copyright (C) 2013-2014 Google, Inc
  5. * Simon Glass <sjg@chromium.org>
  6. *
  7. * Copyright (C) 2012 Samsung Electronics
  8. * Chiwoong Byun <woong.byun@samsung.com>
  9. * Jonghwa Lee <jonghwa3.lee@samsung.com>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * This driver is based on max8997.c
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/bug.h>
  25. #include <linux/err.h>
  26. #include <linux/gpio.h>
  27. #include <linux/slab.h>
  28. #include <linux/gpio/consumer.h>
  29. #include <linux/module.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/regulator/driver.h>
  32. #include <linux/regulator/machine.h>
  33. #include <linux/regulator/of_regulator.h>
  34. #include <linux/mfd/max77686.h>
  35. #include <linux/mfd/max77686-private.h>
  36. #include <dt-bindings/regulator/maxim,max77802.h>
  37. /* Default ramp delay in case it is not manually set */
  38. #define MAX77802_RAMP_DELAY 100000 /* uV/us */
  39. #define MAX77802_OPMODE_SHIFT_LDO 6
  40. #define MAX77802_OPMODE_BUCK234_SHIFT 4
  41. #define MAX77802_OPMODE_MASK 0x3
  42. #define MAX77802_VSEL_MASK 0x3F
  43. #define MAX77802_DVS_VSEL_MASK 0xFF
  44. #define MAX77802_RAMP_RATE_MASK_2BIT 0xC0
  45. #define MAX77802_RAMP_RATE_SHIFT_2BIT 6
  46. #define MAX77802_RAMP_RATE_MASK_4BIT 0xF0
  47. #define MAX77802_RAMP_RATE_SHIFT_4BIT 4
  48. #define MAX77802_STATUS_OFF 0x0
  49. #define MAX77802_OFF_PWRREQ 0x1
  50. #define MAX77802_LP_PWRREQ 0x2
  51. /* MAX77802 has two register formats: 2-bit and 4-bit */
  52. static const unsigned int ramp_table_77802_2bit[] = {
  53. 12500,
  54. 25000,
  55. 50000,
  56. 100000,
  57. };
  58. static unsigned int ramp_table_77802_4bit[] = {
  59. 1000, 2000, 3030, 4000,
  60. 5000, 5880, 7140, 8330,
  61. 9090, 10000, 11110, 12500,
  62. 16670, 25000, 50000, 100000,
  63. };
  64. struct max77802_regulator_prv {
  65. /* Array indexed by regulator id */
  66. unsigned int opmode[MAX77802_REG_MAX];
  67. };
  68. static inline unsigned int max77802_map_mode(unsigned int mode)
  69. {
  70. return mode == MAX77802_OPMODE_NORMAL ?
  71. REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
  72. }
  73. static int max77802_get_opmode_shift(int id)
  74. {
  75. if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
  76. id <= MAX77802_BUCK10))
  77. return 0;
  78. if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4)
  79. return MAX77802_OPMODE_BUCK234_SHIFT;
  80. if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35)
  81. return MAX77802_OPMODE_SHIFT_LDO;
  82. return -EINVAL;
  83. }
  84. /**
  85. * max77802_set_suspend_disable - Disable the regulator during system suspend
  86. * @rdev: regulator to mark as disabled
  87. *
  88. * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ.
  89. * Configure the regulator so the PMIC will turn it OFF during system suspend.
  90. */
  91. static int max77802_set_suspend_disable(struct regulator_dev *rdev)
  92. {
  93. unsigned int val = MAX77802_OFF_PWRREQ;
  94. struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
  95. int id = rdev_get_id(rdev);
  96. int shift = max77802_get_opmode_shift(id);
  97. max77802->opmode[id] = val;
  98. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  99. rdev->desc->enable_mask, val << shift);
  100. }
  101. /*
  102. * Some LDOs support Low Power Mode while the system is running.
  103. *
  104. * LDOs 1, 3, 20, 21.
  105. */
  106. static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
  107. {
  108. struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
  109. int id = rdev_get_id(rdev);
  110. unsigned int val;
  111. int shift = max77802_get_opmode_shift(id);
  112. switch (mode) {
  113. case REGULATOR_MODE_STANDBY:
  114. val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */
  115. break;
  116. case REGULATOR_MODE_NORMAL:
  117. val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */
  118. break;
  119. default:
  120. dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
  121. rdev->desc->name, mode);
  122. return -EINVAL;
  123. }
  124. max77802->opmode[id] = val;
  125. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  126. rdev->desc->enable_mask, val << shift);
  127. }
  128. static unsigned max77802_get_mode(struct regulator_dev *rdev)
  129. {
  130. struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
  131. int id = rdev_get_id(rdev);
  132. return max77802_map_mode(max77802->opmode[id]);
  133. }
  134. /**
  135. * max77802_set_suspend_mode - set regulator opmode when the system is suspended
  136. * @rdev: regulator to change mode
  137. * @mode: operating mode to be set
  138. *
  139. * Will set the operating mode for the regulators during system suspend.
  140. * This function is valid for the three different enable control logics:
  141. *
  142. * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35)
  143. * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21)
  144. * Enable Control Logic3 by PWRREQ (LDO 3)
  145. *
  146. * If setting the regulator mode fails, the function only warns but does
  147. * not return an error code to avoid the regulator core to stop setting
  148. * the operating mode for the remaining regulators.
  149. */
  150. static int max77802_set_suspend_mode(struct regulator_dev *rdev,
  151. unsigned int mode)
  152. {
  153. struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
  154. int id = rdev_get_id(rdev);
  155. unsigned int val;
  156. int shift = max77802_get_opmode_shift(id);
  157. /*
  158. * If the regulator has been disabled for suspend
  159. * then is invalid to try setting a suspend mode.
  160. */
  161. if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
  162. dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
  163. rdev->desc->name, mode);
  164. return 0;
  165. }
  166. switch (mode) {
  167. case REGULATOR_MODE_STANDBY:
  168. /*
  169. * If the regulator opmode is normal then enable
  170. * ON in Low Power Mode by PWRREQ. If the mode is
  171. * already Low Power then no action is required.
  172. */
  173. if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
  174. val = MAX77802_LP_PWRREQ;
  175. else
  176. return 0;
  177. break;
  178. case REGULATOR_MODE_NORMAL:
  179. /*
  180. * If the regulator operating mode is Low Power then
  181. * normal is not a valid opmode in suspend. If the
  182. * mode is already normal then no action is required.
  183. */
  184. if (max77802->opmode[id] == MAX77802_OPMODE_LP)
  185. dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
  186. rdev->desc->name, mode);
  187. return 0;
  188. default:
  189. dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
  190. rdev->desc->name, mode);
  191. return -EINVAL;
  192. }
  193. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  194. rdev->desc->enable_mask, val << shift);
  195. }
  196. static int max77802_enable(struct regulator_dev *rdev)
  197. {
  198. struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
  199. int id = rdev_get_id(rdev);
  200. int shift = max77802_get_opmode_shift(id);
  201. if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
  202. max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
  203. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  204. rdev->desc->enable_mask,
  205. max77802->opmode[id] << shift);
  206. }
  207. static int max77802_find_ramp_value(struct regulator_dev *rdev,
  208. const unsigned int limits[], int size,
  209. unsigned int ramp_delay)
  210. {
  211. int i;
  212. for (i = 0; i < size; i++) {
  213. if (ramp_delay <= limits[i])
  214. return i;
  215. }
  216. /* Use maximum value for no ramp control */
  217. dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n",
  218. rdev->desc->name, ramp_delay);
  219. return size - 1;
  220. }
  221. /* Used for BUCKs 2-4 */
  222. static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev,
  223. int ramp_delay)
  224. {
  225. int id = rdev_get_id(rdev);
  226. unsigned int ramp_value;
  227. if (id > MAX77802_BUCK4) {
  228. dev_warn(&rdev->dev,
  229. "%s: regulator: ramp delay not supported\n",
  230. rdev->desc->name);
  231. return -EINVAL;
  232. }
  233. ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit,
  234. ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay);
  235. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  236. MAX77802_RAMP_RATE_MASK_2BIT,
  237. ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT);
  238. }
  239. /* For BUCK1, 6 */
  240. static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev,
  241. int ramp_delay)
  242. {
  243. unsigned int ramp_value;
  244. ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit,
  245. ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay);
  246. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  247. MAX77802_RAMP_RATE_MASK_4BIT,
  248. ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT);
  249. }
  250. /*
  251. * LDOs 2, 4-19, 22-35
  252. */
  253. static struct regulator_ops max77802_ldo_ops_logic1 = {
  254. .list_voltage = regulator_list_voltage_linear,
  255. .map_voltage = regulator_map_voltage_linear,
  256. .is_enabled = regulator_is_enabled_regmap,
  257. .enable = max77802_enable,
  258. .disable = regulator_disable_regmap,
  259. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  260. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  261. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  262. .set_suspend_disable = max77802_set_suspend_disable,
  263. .set_suspend_mode = max77802_set_suspend_mode,
  264. };
  265. /*
  266. * LDOs 1, 20, 21, 3
  267. */
  268. static struct regulator_ops max77802_ldo_ops_logic2 = {
  269. .list_voltage = regulator_list_voltage_linear,
  270. .map_voltage = regulator_map_voltage_linear,
  271. .is_enabled = regulator_is_enabled_regmap,
  272. .enable = max77802_enable,
  273. .disable = regulator_disable_regmap,
  274. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  275. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  276. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  277. .set_mode = max77802_set_mode,
  278. .get_mode = max77802_get_mode,
  279. .set_suspend_mode = max77802_set_suspend_mode,
  280. };
  281. /* BUCKS 1, 6 */
  282. static struct regulator_ops max77802_buck_16_dvs_ops = {
  283. .list_voltage = regulator_list_voltage_linear,
  284. .map_voltage = regulator_map_voltage_linear,
  285. .is_enabled = regulator_is_enabled_regmap,
  286. .enable = max77802_enable,
  287. .disable = regulator_disable_regmap,
  288. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  289. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  290. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  291. .set_ramp_delay = max77802_set_ramp_delay_4bit,
  292. .set_suspend_disable = max77802_set_suspend_disable,
  293. };
  294. /* BUCKs 2-4 */
  295. static struct regulator_ops max77802_buck_234_ops = {
  296. .list_voltage = regulator_list_voltage_linear,
  297. .map_voltage = regulator_map_voltage_linear,
  298. .is_enabled = regulator_is_enabled_regmap,
  299. .enable = max77802_enable,
  300. .disable = regulator_disable_regmap,
  301. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  302. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  303. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  304. .set_ramp_delay = max77802_set_ramp_delay_2bit,
  305. .set_suspend_disable = max77802_set_suspend_disable,
  306. .set_suspend_mode = max77802_set_suspend_mode,
  307. };
  308. /* BUCKs 5, 7-10 */
  309. static struct regulator_ops max77802_buck_dvs_ops = {
  310. .list_voltage = regulator_list_voltage_linear,
  311. .map_voltage = regulator_map_voltage_linear,
  312. .is_enabled = regulator_is_enabled_regmap,
  313. .enable = max77802_enable,
  314. .disable = regulator_disable_regmap,
  315. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  316. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  317. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  318. .set_ramp_delay = max77802_set_ramp_delay_2bit,
  319. .set_suspend_disable = max77802_set_suspend_disable,
  320. };
  321. /* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */
  322. #define regulator_77802_desc_p_ldo(num, supply, log) { \
  323. .name = "LDO"#num, \
  324. .of_match = of_match_ptr("LDO"#num), \
  325. .regulators_node = of_match_ptr("regulators"), \
  326. .id = MAX77802_LDO##num, \
  327. .supply_name = "inl"#supply, \
  328. .ops = &max77802_ldo_ops_logic##log, \
  329. .type = REGULATOR_VOLTAGE, \
  330. .owner = THIS_MODULE, \
  331. .min_uV = 800000, \
  332. .uV_step = 50000, \
  333. .ramp_delay = MAX77802_RAMP_DELAY, \
  334. .n_voltages = 1 << 6, \
  335. .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
  336. .vsel_mask = MAX77802_VSEL_MASK, \
  337. .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
  338. .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
  339. .of_map_mode = max77802_map_mode, \
  340. }
  341. /* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */
  342. #define regulator_77802_desc_n_ldo(num, supply, log) { \
  343. .name = "LDO"#num, \
  344. .of_match = of_match_ptr("LDO"#num), \
  345. .regulators_node = of_match_ptr("regulators"), \
  346. .id = MAX77802_LDO##num, \
  347. .supply_name = "inl"#supply, \
  348. .ops = &max77802_ldo_ops_logic##log, \
  349. .type = REGULATOR_VOLTAGE, \
  350. .owner = THIS_MODULE, \
  351. .min_uV = 800000, \
  352. .uV_step = 25000, \
  353. .ramp_delay = MAX77802_RAMP_DELAY, \
  354. .n_voltages = 1 << 6, \
  355. .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
  356. .vsel_mask = MAX77802_VSEL_MASK, \
  357. .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
  358. .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
  359. .of_map_mode = max77802_map_mode, \
  360. }
  361. /* BUCKs 1, 6 */
  362. #define regulator_77802_desc_16_buck(num) { \
  363. .name = "BUCK"#num, \
  364. .of_match = of_match_ptr("BUCK"#num), \
  365. .regulators_node = of_match_ptr("regulators"), \
  366. .id = MAX77802_BUCK##num, \
  367. .supply_name = "inb"#num, \
  368. .ops = &max77802_buck_16_dvs_ops, \
  369. .type = REGULATOR_VOLTAGE, \
  370. .owner = THIS_MODULE, \
  371. .min_uV = 612500, \
  372. .uV_step = 6250, \
  373. .ramp_delay = MAX77802_RAMP_DELAY, \
  374. .n_voltages = 1 << 8, \
  375. .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \
  376. .vsel_mask = MAX77802_DVS_VSEL_MASK, \
  377. .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \
  378. .enable_mask = MAX77802_OPMODE_MASK, \
  379. .of_map_mode = max77802_map_mode, \
  380. }
  381. /* BUCKS 2-4 */
  382. #define regulator_77802_desc_234_buck(num) { \
  383. .name = "BUCK"#num, \
  384. .of_match = of_match_ptr("BUCK"#num), \
  385. .regulators_node = of_match_ptr("regulators"), \
  386. .id = MAX77802_BUCK##num, \
  387. .supply_name = "inb"#num, \
  388. .ops = &max77802_buck_234_ops, \
  389. .type = REGULATOR_VOLTAGE, \
  390. .owner = THIS_MODULE, \
  391. .min_uV = 600000, \
  392. .uV_step = 6250, \
  393. .ramp_delay = MAX77802_RAMP_DELAY, \
  394. .n_voltages = 0x91, \
  395. .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \
  396. .vsel_mask = MAX77802_DVS_VSEL_MASK, \
  397. .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \
  398. .enable_mask = MAX77802_OPMODE_MASK << \
  399. MAX77802_OPMODE_BUCK234_SHIFT, \
  400. .of_map_mode = max77802_map_mode, \
  401. }
  402. /* BUCK 5 */
  403. #define regulator_77802_desc_buck5(num) { \
  404. .name = "BUCK"#num, \
  405. .of_match = of_match_ptr("BUCK"#num), \
  406. .regulators_node = of_match_ptr("regulators"), \
  407. .id = MAX77802_BUCK##num, \
  408. .supply_name = "inb"#num, \
  409. .ops = &max77802_buck_dvs_ops, \
  410. .type = REGULATOR_VOLTAGE, \
  411. .owner = THIS_MODULE, \
  412. .min_uV = 750000, \
  413. .uV_step = 50000, \
  414. .ramp_delay = MAX77802_RAMP_DELAY, \
  415. .n_voltages = 1 << 6, \
  416. .vsel_reg = MAX77802_REG_BUCK5OUT, \
  417. .vsel_mask = MAX77802_VSEL_MASK, \
  418. .enable_reg = MAX77802_REG_BUCK5CTRL, \
  419. .enable_mask = MAX77802_OPMODE_MASK, \
  420. .of_map_mode = max77802_map_mode, \
  421. }
  422. /* BUCKs 7-10 */
  423. #define regulator_77802_desc_buck7_10(num) { \
  424. .name = "BUCK"#num, \
  425. .of_match = of_match_ptr("BUCK"#num), \
  426. .regulators_node = of_match_ptr("regulators"), \
  427. .id = MAX77802_BUCK##num, \
  428. .supply_name = "inb"#num, \
  429. .ops = &max77802_buck_dvs_ops, \
  430. .type = REGULATOR_VOLTAGE, \
  431. .owner = THIS_MODULE, \
  432. .min_uV = 750000, \
  433. .uV_step = 50000, \
  434. .ramp_delay = MAX77802_RAMP_DELAY, \
  435. .n_voltages = 1 << 6, \
  436. .vsel_reg = MAX77802_REG_BUCK7OUT + (num - 7) * 3, \
  437. .vsel_mask = MAX77802_VSEL_MASK, \
  438. .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \
  439. .enable_mask = MAX77802_OPMODE_MASK, \
  440. .of_map_mode = max77802_map_mode, \
  441. }
  442. static const struct regulator_desc regulators[] = {
  443. regulator_77802_desc_16_buck(1),
  444. regulator_77802_desc_234_buck(2),
  445. regulator_77802_desc_234_buck(3),
  446. regulator_77802_desc_234_buck(4),
  447. regulator_77802_desc_buck5(5),
  448. regulator_77802_desc_16_buck(6),
  449. regulator_77802_desc_buck7_10(7),
  450. regulator_77802_desc_buck7_10(8),
  451. regulator_77802_desc_buck7_10(9),
  452. regulator_77802_desc_buck7_10(10),
  453. regulator_77802_desc_n_ldo(1, 10, 2),
  454. regulator_77802_desc_n_ldo(2, 10, 1),
  455. regulator_77802_desc_p_ldo(3, 3, 2),
  456. regulator_77802_desc_p_ldo(4, 6, 1),
  457. regulator_77802_desc_p_ldo(5, 3, 1),
  458. regulator_77802_desc_p_ldo(6, 3, 1),
  459. regulator_77802_desc_p_ldo(7, 3, 1),
  460. regulator_77802_desc_n_ldo(8, 1, 1),
  461. regulator_77802_desc_p_ldo(9, 5, 1),
  462. regulator_77802_desc_p_ldo(10, 4, 1),
  463. regulator_77802_desc_p_ldo(11, 4, 1),
  464. regulator_77802_desc_p_ldo(12, 9, 1),
  465. regulator_77802_desc_p_ldo(13, 4, 1),
  466. regulator_77802_desc_p_ldo(14, 4, 1),
  467. regulator_77802_desc_n_ldo(15, 1, 1),
  468. regulator_77802_desc_n_ldo(17, 2, 1),
  469. regulator_77802_desc_p_ldo(18, 7, 1),
  470. regulator_77802_desc_p_ldo(19, 5, 1),
  471. regulator_77802_desc_p_ldo(20, 7, 2),
  472. regulator_77802_desc_p_ldo(21, 6, 2),
  473. regulator_77802_desc_p_ldo(23, 9, 1),
  474. regulator_77802_desc_p_ldo(24, 6, 1),
  475. regulator_77802_desc_p_ldo(25, 9, 1),
  476. regulator_77802_desc_p_ldo(26, 9, 1),
  477. regulator_77802_desc_n_ldo(27, 2, 1),
  478. regulator_77802_desc_p_ldo(28, 7, 1),
  479. regulator_77802_desc_p_ldo(29, 7, 1),
  480. regulator_77802_desc_n_ldo(30, 2, 1),
  481. regulator_77802_desc_p_ldo(32, 9, 1),
  482. regulator_77802_desc_p_ldo(33, 6, 1),
  483. regulator_77802_desc_p_ldo(34, 9, 1),
  484. regulator_77802_desc_n_ldo(35, 2, 1),
  485. };
  486. static int max77802_pmic_probe(struct platform_device *pdev)
  487. {
  488. struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
  489. struct max77802_regulator_prv *max77802;
  490. int i, val;
  491. struct regulator_config config = { };
  492. max77802 = devm_kzalloc(&pdev->dev,
  493. sizeof(struct max77802_regulator_prv),
  494. GFP_KERNEL);
  495. if (!max77802)
  496. return -ENOMEM;
  497. config.dev = iodev->dev;
  498. config.regmap = iodev->regmap;
  499. config.driver_data = max77802;
  500. platform_set_drvdata(pdev, max77802);
  501. for (i = 0; i < MAX77802_REG_MAX; i++) {
  502. struct regulator_dev *rdev;
  503. int id = regulators[i].id;
  504. int shift = max77802_get_opmode_shift(id);
  505. int ret;
  506. ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val);
  507. if (ret < 0) {
  508. dev_warn(&pdev->dev,
  509. "cannot read current mode for %d\n", i);
  510. val = MAX77802_OPMODE_NORMAL;
  511. } else {
  512. val = val >> shift & MAX77802_OPMODE_MASK;
  513. }
  514. /*
  515. * If the regulator is disabled and the system warm rebooted,
  516. * the hardware reports OFF as the regulator operating mode.
  517. * Default to operating mode NORMAL in that case.
  518. */
  519. if (val == MAX77802_STATUS_OFF)
  520. max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
  521. else
  522. max77802->opmode[id] = val;
  523. rdev = devm_regulator_register(&pdev->dev,
  524. &regulators[i], &config);
  525. if (IS_ERR(rdev)) {
  526. ret = PTR_ERR(rdev);
  527. dev_err(&pdev->dev,
  528. "regulator init failed for %d: %d\n", i, ret);
  529. return ret;
  530. }
  531. }
  532. return 0;
  533. }
  534. static const struct platform_device_id max77802_pmic_id[] = {
  535. {"max77802-pmic", 0},
  536. { },
  537. };
  538. MODULE_DEVICE_TABLE(platform, max77802_pmic_id);
  539. static struct platform_driver max77802_pmic_driver = {
  540. .driver = {
  541. .name = "max77802-pmic",
  542. },
  543. .probe = max77802_pmic_probe,
  544. .id_table = max77802_pmic_id,
  545. };
  546. module_platform_driver(max77802_pmic_driver);
  547. MODULE_DESCRIPTION("MAXIM 77802 Regulator Driver");
  548. MODULE_AUTHOR("Simon Glass <sjg@chromium.org>");
  549. MODULE_LICENSE("GPL");