max77686-regulator.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /*
  2. * max77686.c - Regulator driver for the Maxim 77686
  3. *
  4. * Copyright (C) 2012 Samsung Electronics
  5. * Chiwoong Byun <woong.byun@samsung.com>
  6. * Jonghwa Lee <jonghwa3.lee@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. * This driver is based on max8997.c
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/bug.h>
  26. #include <linux/err.h>
  27. #include <linux/gpio.h>
  28. #include <linux/of_gpio.h>
  29. #include <linux/slab.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. #define MAX77686_LDO_MINUV 800000
  37. #define MAX77686_LDO_UVSTEP 50000
  38. #define MAX77686_LDO_LOW_MINUV 800000
  39. #define MAX77686_LDO_LOW_UVSTEP 25000
  40. #define MAX77686_BUCK_MINUV 750000
  41. #define MAX77686_BUCK_UVSTEP 50000
  42. #define MAX77686_BUCK_ENABLE_TIME 40 /* us */
  43. #define MAX77686_DVS_ENABLE_TIME 22 /* us */
  44. #define MAX77686_RAMP_DELAY 100000 /* uV/us */
  45. #define MAX77686_DVS_RAMP_DELAY 27500 /* uV/us */
  46. #define MAX77686_DVS_MINUV 600000
  47. #define MAX77686_DVS_UVSTEP 12500
  48. /*
  49. * Value for configuring buck[89] and LDO{20,21,22} as GPIO control.
  50. * It is the same as 'off' for other regulators.
  51. */
  52. #define MAX77686_GPIO_CONTROL 0x0
  53. /*
  54. * Values used for configuring LDOs and bucks.
  55. * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
  56. */
  57. #define MAX77686_LDO_LOWPOWER 0x1
  58. /*
  59. * On/off controlled by PWRREQ:
  60. * - LDO2, 6-8, 10-12, 14-16
  61. * - buck[1234]
  62. */
  63. #define MAX77686_OFF_PWRREQ 0x1
  64. /* Low power mode controlled by PWRREQ: All LDOs */
  65. #define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
  66. /* Forcing low power mode: buck[234] */
  67. #define MAX77686_BUCK_LOWPOWER 0x2
  68. #define MAX77686_NORMAL 0x3
  69. #define MAX77686_OPMODE_SHIFT 6
  70. #define MAX77686_OPMODE_BUCK234_SHIFT 4
  71. #define MAX77686_OPMODE_MASK 0x3
  72. #define MAX77686_VSEL_MASK 0x3F
  73. #define MAX77686_DVS_VSEL_MASK 0xFF
  74. #define MAX77686_RAMP_RATE_MASK 0xC0
  75. #define MAX77686_REGULATORS MAX77686_REG_MAX
  76. #define MAX77686_LDOS 26
  77. enum max77686_ramp_rate {
  78. RAMP_RATE_13P75MV,
  79. RAMP_RATE_27P5MV,
  80. RAMP_RATE_55MV,
  81. RAMP_RATE_NO_CTRL, /* 100mV/us */
  82. };
  83. struct max77686_data {
  84. DECLARE_BITMAP(gpio_enabled, MAX77686_REGULATORS);
  85. /* Array indexed by regulator id */
  86. unsigned int opmode[MAX77686_REGULATORS];
  87. };
  88. static unsigned int max77686_get_opmode_shift(int id)
  89. {
  90. switch (id) {
  91. case MAX77686_BUCK1:
  92. case MAX77686_BUCK5 ... MAX77686_BUCK9:
  93. return 0;
  94. case MAX77686_BUCK2 ... MAX77686_BUCK4:
  95. return MAX77686_OPMODE_BUCK234_SHIFT;
  96. default:
  97. /* all LDOs */
  98. return MAX77686_OPMODE_SHIFT;
  99. }
  100. }
  101. /*
  102. * When regulator is configured for GPIO control then it
  103. * replaces "normal" mode. Any change from low power mode to normal
  104. * should actually change to GPIO control.
  105. * Map normal mode to proper value for such regulators.
  106. */
  107. static unsigned int max77686_map_normal_mode(struct max77686_data *max77686,
  108. int id)
  109. {
  110. switch (id) {
  111. case MAX77686_BUCK8:
  112. case MAX77686_BUCK9:
  113. case MAX77686_LDO20 ... MAX77686_LDO22:
  114. if (test_bit(id, max77686->gpio_enabled))
  115. return MAX77686_GPIO_CONTROL;
  116. }
  117. return MAX77686_NORMAL;
  118. }
  119. /* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
  120. static int max77686_set_suspend_disable(struct regulator_dev *rdev)
  121. {
  122. unsigned int val, shift;
  123. struct max77686_data *max77686 = rdev_get_drvdata(rdev);
  124. int ret, id = rdev_get_id(rdev);
  125. shift = max77686_get_opmode_shift(id);
  126. val = MAX77686_OFF_PWRREQ;
  127. ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  128. rdev->desc->enable_mask, val << shift);
  129. if (ret)
  130. return ret;
  131. max77686->opmode[id] = val;
  132. return 0;
  133. }
  134. /* Some LDOs supports [LPM/Normal]ON mode during suspend state */
  135. static int max77686_set_suspend_mode(struct regulator_dev *rdev,
  136. unsigned int mode)
  137. {
  138. struct max77686_data *max77686 = rdev_get_drvdata(rdev);
  139. unsigned int val;
  140. int ret, id = rdev_get_id(rdev);
  141. /* BUCK[5-9] doesn't support this feature */
  142. if (id >= MAX77686_BUCK5)
  143. return 0;
  144. switch (mode) {
  145. case REGULATOR_MODE_IDLE: /* ON in LP Mode */
  146. val = MAX77686_LDO_LOWPOWER_PWRREQ;
  147. break;
  148. case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
  149. val = max77686_map_normal_mode(max77686, id);
  150. break;
  151. default:
  152. pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
  153. rdev->desc->name, mode);
  154. return -EINVAL;
  155. }
  156. ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  157. rdev->desc->enable_mask,
  158. val << MAX77686_OPMODE_SHIFT);
  159. if (ret)
  160. return ret;
  161. max77686->opmode[id] = val;
  162. return 0;
  163. }
  164. /* Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state */
  165. static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
  166. unsigned int mode)
  167. {
  168. unsigned int val;
  169. struct max77686_data *max77686 = rdev_get_drvdata(rdev);
  170. int ret, id = rdev_get_id(rdev);
  171. switch (mode) {
  172. case REGULATOR_MODE_STANDBY: /* switch off */
  173. val = MAX77686_OFF_PWRREQ;
  174. break;
  175. case REGULATOR_MODE_IDLE: /* ON in LP Mode */
  176. val = MAX77686_LDO_LOWPOWER_PWRREQ;
  177. break;
  178. case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
  179. val = max77686_map_normal_mode(max77686, id);
  180. break;
  181. default:
  182. pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
  183. rdev->desc->name, mode);
  184. return -EINVAL;
  185. }
  186. ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  187. rdev->desc->enable_mask,
  188. val << MAX77686_OPMODE_SHIFT);
  189. if (ret)
  190. return ret;
  191. max77686->opmode[id] = val;
  192. return 0;
  193. }
  194. static int max77686_enable(struct regulator_dev *rdev)
  195. {
  196. struct max77686_data *max77686 = rdev_get_drvdata(rdev);
  197. unsigned int shift;
  198. int id = rdev_get_id(rdev);
  199. shift = max77686_get_opmode_shift(id);
  200. if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
  201. max77686->opmode[id] = max77686_map_normal_mode(max77686, id);
  202. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  203. rdev->desc->enable_mask,
  204. max77686->opmode[id] << shift);
  205. }
  206. static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
  207. {
  208. unsigned int ramp_value = RAMP_RATE_NO_CTRL;
  209. switch (ramp_delay) {
  210. case 1 ... 13750:
  211. ramp_value = RAMP_RATE_13P75MV;
  212. break;
  213. case 13751 ... 27500:
  214. ramp_value = RAMP_RATE_27P5MV;
  215. break;
  216. case 27501 ... 55000:
  217. ramp_value = RAMP_RATE_55MV;
  218. break;
  219. case 55001 ... 100000:
  220. break;
  221. default:
  222. pr_warn("%s: ramp_delay: %d not supported, setting 100000\n",
  223. rdev->desc->name, ramp_delay);
  224. }
  225. return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
  226. MAX77686_RAMP_RATE_MASK, ramp_value << 6);
  227. }
  228. static int max77686_of_parse_cb(struct device_node *np,
  229. const struct regulator_desc *desc,
  230. struct regulator_config *config)
  231. {
  232. struct max77686_data *max77686 = config->driver_data;
  233. switch (desc->id) {
  234. case MAX77686_BUCK8:
  235. case MAX77686_BUCK9:
  236. case MAX77686_LDO20 ... MAX77686_LDO22:
  237. config->ena_gpio = of_get_named_gpio(np,
  238. "maxim,ena-gpios", 0);
  239. config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
  240. config->ena_gpio_initialized = true;
  241. break;
  242. default:
  243. return 0;
  244. }
  245. if (gpio_is_valid(config->ena_gpio)) {
  246. set_bit(desc->id, max77686->gpio_enabled);
  247. return regmap_update_bits(config->regmap, desc->enable_reg,
  248. desc->enable_mask,
  249. MAX77686_GPIO_CONTROL);
  250. }
  251. return 0;
  252. }
  253. static const struct regulator_ops max77686_ops = {
  254. .list_voltage = regulator_list_voltage_linear,
  255. .map_voltage = regulator_map_voltage_linear,
  256. .is_enabled = regulator_is_enabled_regmap,
  257. .enable = max77686_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_mode = max77686_set_suspend_mode,
  263. };
  264. static const struct regulator_ops max77686_ldo_ops = {
  265. .list_voltage = regulator_list_voltage_linear,
  266. .map_voltage = regulator_map_voltage_linear,
  267. .is_enabled = regulator_is_enabled_regmap,
  268. .enable = max77686_enable,
  269. .disable = regulator_disable_regmap,
  270. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  271. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  272. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  273. .set_suspend_mode = max77686_ldo_set_suspend_mode,
  274. .set_suspend_disable = max77686_set_suspend_disable,
  275. };
  276. static const struct regulator_ops max77686_buck1_ops = {
  277. .list_voltage = regulator_list_voltage_linear,
  278. .map_voltage = regulator_map_voltage_linear,
  279. .is_enabled = regulator_is_enabled_regmap,
  280. .enable = max77686_enable,
  281. .disable = regulator_disable_regmap,
  282. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  283. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  284. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  285. .set_suspend_disable = max77686_set_suspend_disable,
  286. };
  287. static const struct regulator_ops max77686_buck_dvs_ops = {
  288. .list_voltage = regulator_list_voltage_linear,
  289. .map_voltage = regulator_map_voltage_linear,
  290. .is_enabled = regulator_is_enabled_regmap,
  291. .enable = max77686_enable,
  292. .disable = regulator_disable_regmap,
  293. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  294. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  295. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  296. .set_ramp_delay = max77686_set_ramp_delay,
  297. .set_suspend_disable = max77686_set_suspend_disable,
  298. };
  299. #define regulator_desc_ldo(num) { \
  300. .name = "LDO"#num, \
  301. .of_match = of_match_ptr("LDO"#num), \
  302. .regulators_node = of_match_ptr("voltage-regulators"), \
  303. .of_parse_cb = max77686_of_parse_cb, \
  304. .id = MAX77686_LDO##num, \
  305. .ops = &max77686_ops, \
  306. .type = REGULATOR_VOLTAGE, \
  307. .owner = THIS_MODULE, \
  308. .min_uV = MAX77686_LDO_MINUV, \
  309. .uV_step = MAX77686_LDO_UVSTEP, \
  310. .ramp_delay = MAX77686_RAMP_DELAY, \
  311. .n_voltages = MAX77686_VSEL_MASK + 1, \
  312. .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  313. .vsel_mask = MAX77686_VSEL_MASK, \
  314. .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  315. .enable_mask = MAX77686_OPMODE_MASK \
  316. << MAX77686_OPMODE_SHIFT, \
  317. }
  318. #define regulator_desc_lpm_ldo(num) { \
  319. .name = "LDO"#num, \
  320. .of_match = of_match_ptr("LDO"#num), \
  321. .regulators_node = of_match_ptr("voltage-regulators"), \
  322. .id = MAX77686_LDO##num, \
  323. .ops = &max77686_ldo_ops, \
  324. .type = REGULATOR_VOLTAGE, \
  325. .owner = THIS_MODULE, \
  326. .min_uV = MAX77686_LDO_MINUV, \
  327. .uV_step = MAX77686_LDO_UVSTEP, \
  328. .ramp_delay = MAX77686_RAMP_DELAY, \
  329. .n_voltages = MAX77686_VSEL_MASK + 1, \
  330. .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  331. .vsel_mask = MAX77686_VSEL_MASK, \
  332. .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  333. .enable_mask = MAX77686_OPMODE_MASK \
  334. << MAX77686_OPMODE_SHIFT, \
  335. }
  336. #define regulator_desc_ldo_low(num) { \
  337. .name = "LDO"#num, \
  338. .of_match = of_match_ptr("LDO"#num), \
  339. .regulators_node = of_match_ptr("voltage-regulators"), \
  340. .id = MAX77686_LDO##num, \
  341. .ops = &max77686_ldo_ops, \
  342. .type = REGULATOR_VOLTAGE, \
  343. .owner = THIS_MODULE, \
  344. .min_uV = MAX77686_LDO_LOW_MINUV, \
  345. .uV_step = MAX77686_LDO_LOW_UVSTEP, \
  346. .ramp_delay = MAX77686_RAMP_DELAY, \
  347. .n_voltages = MAX77686_VSEL_MASK + 1, \
  348. .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  349. .vsel_mask = MAX77686_VSEL_MASK, \
  350. .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  351. .enable_mask = MAX77686_OPMODE_MASK \
  352. << MAX77686_OPMODE_SHIFT, \
  353. }
  354. #define regulator_desc_ldo1_low(num) { \
  355. .name = "LDO"#num, \
  356. .of_match = of_match_ptr("LDO"#num), \
  357. .regulators_node = of_match_ptr("voltage-regulators"), \
  358. .id = MAX77686_LDO##num, \
  359. .ops = &max77686_ops, \
  360. .type = REGULATOR_VOLTAGE, \
  361. .owner = THIS_MODULE, \
  362. .min_uV = MAX77686_LDO_LOW_MINUV, \
  363. .uV_step = MAX77686_LDO_LOW_UVSTEP, \
  364. .ramp_delay = MAX77686_RAMP_DELAY, \
  365. .n_voltages = MAX77686_VSEL_MASK + 1, \
  366. .vsel_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  367. .vsel_mask = MAX77686_VSEL_MASK, \
  368. .enable_reg = MAX77686_REG_LDO1CTRL1 + num - 1, \
  369. .enable_mask = MAX77686_OPMODE_MASK \
  370. << MAX77686_OPMODE_SHIFT, \
  371. }
  372. #define regulator_desc_buck(num) { \
  373. .name = "BUCK"#num, \
  374. .of_match = of_match_ptr("BUCK"#num), \
  375. .regulators_node = of_match_ptr("voltage-regulators"), \
  376. .of_parse_cb = max77686_of_parse_cb, \
  377. .id = MAX77686_BUCK##num, \
  378. .ops = &max77686_ops, \
  379. .type = REGULATOR_VOLTAGE, \
  380. .owner = THIS_MODULE, \
  381. .min_uV = MAX77686_BUCK_MINUV, \
  382. .uV_step = MAX77686_BUCK_UVSTEP, \
  383. .ramp_delay = MAX77686_RAMP_DELAY, \
  384. .enable_time = MAX77686_BUCK_ENABLE_TIME, \
  385. .n_voltages = MAX77686_VSEL_MASK + 1, \
  386. .vsel_reg = MAX77686_REG_BUCK5OUT + (num - 5) * 2, \
  387. .vsel_mask = MAX77686_VSEL_MASK, \
  388. .enable_reg = MAX77686_REG_BUCK5CTRL + (num - 5) * 2, \
  389. .enable_mask = MAX77686_OPMODE_MASK, \
  390. }
  391. #define regulator_desc_buck1(num) { \
  392. .name = "BUCK"#num, \
  393. .of_match = of_match_ptr("BUCK"#num), \
  394. .regulators_node = of_match_ptr("voltage-regulators"), \
  395. .id = MAX77686_BUCK##num, \
  396. .ops = &max77686_buck1_ops, \
  397. .type = REGULATOR_VOLTAGE, \
  398. .owner = THIS_MODULE, \
  399. .min_uV = MAX77686_BUCK_MINUV, \
  400. .uV_step = MAX77686_BUCK_UVSTEP, \
  401. .ramp_delay = MAX77686_RAMP_DELAY, \
  402. .enable_time = MAX77686_BUCK_ENABLE_TIME, \
  403. .n_voltages = MAX77686_VSEL_MASK + 1, \
  404. .vsel_reg = MAX77686_REG_BUCK1OUT, \
  405. .vsel_mask = MAX77686_VSEL_MASK, \
  406. .enable_reg = MAX77686_REG_BUCK1CTRL, \
  407. .enable_mask = MAX77686_OPMODE_MASK, \
  408. }
  409. #define regulator_desc_buck_dvs(num) { \
  410. .name = "BUCK"#num, \
  411. .of_match = of_match_ptr("BUCK"#num), \
  412. .regulators_node = of_match_ptr("voltage-regulators"), \
  413. .id = MAX77686_BUCK##num, \
  414. .ops = &max77686_buck_dvs_ops, \
  415. .type = REGULATOR_VOLTAGE, \
  416. .owner = THIS_MODULE, \
  417. .min_uV = MAX77686_DVS_MINUV, \
  418. .uV_step = MAX77686_DVS_UVSTEP, \
  419. .ramp_delay = MAX77686_DVS_RAMP_DELAY, \
  420. .enable_time = MAX77686_DVS_ENABLE_TIME, \
  421. .n_voltages = MAX77686_DVS_VSEL_MASK + 1, \
  422. .vsel_reg = MAX77686_REG_BUCK2DVS1 + (num - 2) * 10, \
  423. .vsel_mask = MAX77686_DVS_VSEL_MASK, \
  424. .enable_reg = MAX77686_REG_BUCK2CTRL1 + (num - 2) * 10, \
  425. .enable_mask = MAX77686_OPMODE_MASK \
  426. << MAX77686_OPMODE_BUCK234_SHIFT, \
  427. }
  428. static const struct regulator_desc regulators[] = {
  429. regulator_desc_ldo1_low(1),
  430. regulator_desc_ldo_low(2),
  431. regulator_desc_ldo(3),
  432. regulator_desc_ldo(4),
  433. regulator_desc_ldo(5),
  434. regulator_desc_ldo_low(6),
  435. regulator_desc_ldo_low(7),
  436. regulator_desc_ldo_low(8),
  437. regulator_desc_ldo(9),
  438. regulator_desc_lpm_ldo(10),
  439. regulator_desc_lpm_ldo(11),
  440. regulator_desc_lpm_ldo(12),
  441. regulator_desc_ldo(13),
  442. regulator_desc_lpm_ldo(14),
  443. regulator_desc_ldo_low(15),
  444. regulator_desc_lpm_ldo(16),
  445. regulator_desc_ldo(17),
  446. regulator_desc_ldo(18),
  447. regulator_desc_ldo(19),
  448. regulator_desc_ldo(20),
  449. regulator_desc_ldo(21),
  450. regulator_desc_ldo(22),
  451. regulator_desc_ldo(23),
  452. regulator_desc_ldo(24),
  453. regulator_desc_ldo(25),
  454. regulator_desc_ldo(26),
  455. regulator_desc_buck1(1),
  456. regulator_desc_buck_dvs(2),
  457. regulator_desc_buck_dvs(3),
  458. regulator_desc_buck_dvs(4),
  459. regulator_desc_buck(5),
  460. regulator_desc_buck(6),
  461. regulator_desc_buck(7),
  462. regulator_desc_buck(8),
  463. regulator_desc_buck(9),
  464. };
  465. static int max77686_pmic_probe(struct platform_device *pdev)
  466. {
  467. struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
  468. struct max77686_data *max77686;
  469. int i;
  470. struct regulator_config config = { };
  471. dev_dbg(&pdev->dev, "%s\n", __func__);
  472. max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
  473. GFP_KERNEL);
  474. if (!max77686)
  475. return -ENOMEM;
  476. config.dev = iodev->dev;
  477. config.regmap = iodev->regmap;
  478. config.driver_data = max77686;
  479. platform_set_drvdata(pdev, max77686);
  480. for (i = 0; i < MAX77686_REGULATORS; i++) {
  481. struct regulator_dev *rdev;
  482. int id = regulators[i].id;
  483. max77686->opmode[id] = MAX77686_NORMAL;
  484. rdev = devm_regulator_register(&pdev->dev,
  485. &regulators[i], &config);
  486. if (IS_ERR(rdev)) {
  487. int ret = PTR_ERR(rdev);
  488. dev_err(&pdev->dev,
  489. "regulator init failed for %d: %d\n", i, ret);
  490. return ret;
  491. }
  492. }
  493. return 0;
  494. }
  495. static const struct platform_device_id max77686_pmic_id[] = {
  496. {"max77686-pmic", 0},
  497. { },
  498. };
  499. MODULE_DEVICE_TABLE(platform, max77686_pmic_id);
  500. static struct platform_driver max77686_pmic_driver = {
  501. .driver = {
  502. .name = "max77686-pmic",
  503. },
  504. .probe = max77686_pmic_probe,
  505. .id_table = max77686_pmic_id,
  506. };
  507. module_platform_driver(max77686_pmic_driver);
  508. MODULE_DESCRIPTION("MAXIM 77686 Regulator Driver");
  509. MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
  510. MODULE_LICENSE("GPL");