io-domain.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Rockchip IO Voltage Domain driver
  4. *
  5. * Copyright 2014 MundoReader S.L.
  6. * Copyright 2014 Google, Inc.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/module.h>
  10. #include <linux/err.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #include <linux/regulator/consumer.h>
  16. #define MAX_SUPPLIES 16
  17. /*
  18. * The max voltage for 1.8V and 3.3V come from the Rockchip datasheet under
  19. * "Recommended Operating Conditions" for "Digital GPIO". When the typical
  20. * is 3.3V the max is 3.6V. When the typical is 1.8V the max is 1.98V.
  21. *
  22. * They are used like this:
  23. * - If the voltage on a rail is above the "1.8" voltage (1.98V) we'll tell the
  24. * SoC we're at 3.3.
  25. * - If the voltage on a rail is above the "3.3" voltage (3.6V) we'll consider
  26. * that to be an error.
  27. */
  28. #define MAX_VOLTAGE_1_8 1980000
  29. #define MAX_VOLTAGE_3_3 3600000
  30. #define PX30_IO_VSEL 0x180
  31. #define PX30_IO_VSEL_VCCIO6_SRC BIT(0)
  32. #define PX30_IO_VSEL_VCCIO6_SUPPLY_NUM 1
  33. #define RK3288_SOC_CON2 0x24c
  34. #define RK3288_SOC_CON2_FLASH0 BIT(7)
  35. #define RK3288_SOC_FLASH_SUPPLY_NUM 2
  36. #define RK3328_SOC_CON4 0x410
  37. #define RK3328_SOC_CON4_VCCIO2 BIT(7)
  38. #define RK3328_SOC_VCCIO2_SUPPLY_NUM 1
  39. #define RK3368_SOC_CON15 0x43c
  40. #define RK3368_SOC_CON15_FLASH0 BIT(14)
  41. #define RK3368_SOC_FLASH_SUPPLY_NUM 2
  42. #define RK3399_PMUGRF_CON0 0x180
  43. #define RK3399_PMUGRF_CON0_VSEL BIT(8)
  44. #define RK3399_PMUGRF_VSEL_SUPPLY_NUM 9
  45. #define RK3568_PMU_GRF_IO_VSEL0 (0x0140)
  46. #define RK3568_PMU_GRF_IO_VSEL1 (0x0144)
  47. #define RK3568_PMU_GRF_IO_VSEL2 (0x0148)
  48. struct rockchip_iodomain;
  49. struct rockchip_iodomain_supply {
  50. struct rockchip_iodomain *iod;
  51. struct regulator *reg;
  52. struct notifier_block nb;
  53. int idx;
  54. };
  55. struct rockchip_iodomain_soc_data {
  56. int grf_offset;
  57. const char *supply_names[MAX_SUPPLIES];
  58. void (*init)(struct rockchip_iodomain *iod);
  59. int (*write)(struct rockchip_iodomain_supply *supply, int uV);
  60. };
  61. struct rockchip_iodomain {
  62. struct device *dev;
  63. struct regmap *grf;
  64. const struct rockchip_iodomain_soc_data *soc_data;
  65. struct rockchip_iodomain_supply supplies[MAX_SUPPLIES];
  66. int (*write)(struct rockchip_iodomain_supply *supply, int uV);
  67. };
  68. static int rk3568_iodomain_write(struct rockchip_iodomain_supply *supply, int uV)
  69. {
  70. struct rockchip_iodomain *iod = supply->iod;
  71. u32 is_3v3 = uV > MAX_VOLTAGE_1_8;
  72. u32 val0, val1;
  73. int b;
  74. switch (supply->idx) {
  75. case 0: /* pmuio1 */
  76. break;
  77. case 1: /* pmuio2 */
  78. b = supply->idx;
  79. val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
  80. b = supply->idx + 4;
  81. val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
  82. regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL2, val0);
  83. regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL2, val1);
  84. break;
  85. case 3: /* vccio2 */
  86. break;
  87. case 2: /* vccio1 */
  88. case 4: /* vccio3 */
  89. case 5: /* vccio4 */
  90. case 6: /* vccio5 */
  91. case 7: /* vccio6 */
  92. case 8: /* vccio7 */
  93. b = supply->idx - 1;
  94. val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
  95. val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
  96. regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL0, val0);
  97. regmap_write(iod->grf, RK3568_PMU_GRF_IO_VSEL1, val1);
  98. break;
  99. default:
  100. return -EINVAL;
  101. }
  102. return 0;
  103. }
  104. static int rockchip_iodomain_write(struct rockchip_iodomain_supply *supply,
  105. int uV)
  106. {
  107. struct rockchip_iodomain *iod = supply->iod;
  108. u32 val;
  109. int ret;
  110. /* set value bit */
  111. val = (uV > MAX_VOLTAGE_1_8) ? 0 : 1;
  112. val <<= supply->idx;
  113. /* apply hiword-mask */
  114. val |= (BIT(supply->idx) << 16);
  115. ret = regmap_write(iod->grf, iod->soc_data->grf_offset, val);
  116. if (ret)
  117. dev_err(iod->dev, "Couldn't write to GRF\n");
  118. return ret;
  119. }
  120. static int rockchip_iodomain_notify(struct notifier_block *nb,
  121. unsigned long event,
  122. void *data)
  123. {
  124. struct rockchip_iodomain_supply *supply =
  125. container_of(nb, struct rockchip_iodomain_supply, nb);
  126. int uV;
  127. int ret;
  128. /*
  129. * According to Rockchip it's important to keep the SoC IO domain
  130. * higher than (or equal to) the external voltage. That means we need
  131. * to change it before external voltage changes happen in the case
  132. * of an increase.
  133. *
  134. * Note that in the "pre" change we pick the max possible voltage that
  135. * the regulator might end up at (the client requests a range and we
  136. * don't know for certain the exact voltage). Right now we rely on the
  137. * slop in MAX_VOLTAGE_1_8 and MAX_VOLTAGE_3_3 to save us if clients
  138. * request something like a max of 3.6V when they really want 3.3V.
  139. * We could attempt to come up with better rules if this fails.
  140. */
  141. if (event & REGULATOR_EVENT_PRE_VOLTAGE_CHANGE) {
  142. struct pre_voltage_change_data *pvc_data = data;
  143. uV = max_t(unsigned long, pvc_data->old_uV, pvc_data->max_uV);
  144. } else if (event & (REGULATOR_EVENT_VOLTAGE_CHANGE |
  145. REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE)) {
  146. uV = (unsigned long)data;
  147. } else {
  148. return NOTIFY_OK;
  149. }
  150. dev_dbg(supply->iod->dev, "Setting to %d\n", uV);
  151. if (uV > MAX_VOLTAGE_3_3) {
  152. dev_err(supply->iod->dev, "Voltage too high: %d\n", uV);
  153. if (event == REGULATOR_EVENT_PRE_VOLTAGE_CHANGE)
  154. return NOTIFY_BAD;
  155. }
  156. ret = supply->iod->write(supply, uV);
  157. if (ret && event == REGULATOR_EVENT_PRE_VOLTAGE_CHANGE)
  158. return NOTIFY_BAD;
  159. dev_dbg(supply->iod->dev, "Setting to %d done\n", uV);
  160. return NOTIFY_OK;
  161. }
  162. static void px30_iodomain_init(struct rockchip_iodomain *iod)
  163. {
  164. int ret;
  165. u32 val;
  166. /* if no VCCIO6 supply we should leave things alone */
  167. if (!iod->supplies[PX30_IO_VSEL_VCCIO6_SUPPLY_NUM].reg)
  168. return;
  169. /*
  170. * set vccio6 iodomain to also use this framework
  171. * instead of a special gpio.
  172. */
  173. val = PX30_IO_VSEL_VCCIO6_SRC | (PX30_IO_VSEL_VCCIO6_SRC << 16);
  174. ret = regmap_write(iod->grf, PX30_IO_VSEL, val);
  175. if (ret < 0)
  176. dev_warn(iod->dev, "couldn't update vccio6 ctrl\n");
  177. }
  178. static void rk3288_iodomain_init(struct rockchip_iodomain *iod)
  179. {
  180. int ret;
  181. u32 val;
  182. /* if no flash supply we should leave things alone */
  183. if (!iod->supplies[RK3288_SOC_FLASH_SUPPLY_NUM].reg)
  184. return;
  185. /*
  186. * set flash0 iodomain to also use this framework
  187. * instead of a special gpio.
  188. */
  189. val = RK3288_SOC_CON2_FLASH0 | (RK3288_SOC_CON2_FLASH0 << 16);
  190. ret = regmap_write(iod->grf, RK3288_SOC_CON2, val);
  191. if (ret < 0)
  192. dev_warn(iod->dev, "couldn't update flash0 ctrl\n");
  193. }
  194. static void rk3328_iodomain_init(struct rockchip_iodomain *iod)
  195. {
  196. int ret;
  197. u32 val;
  198. /* if no vccio2 supply we should leave things alone */
  199. if (!iod->supplies[RK3328_SOC_VCCIO2_SUPPLY_NUM].reg)
  200. return;
  201. /*
  202. * set vccio2 iodomain to also use this framework
  203. * instead of a special gpio.
  204. */
  205. val = RK3328_SOC_CON4_VCCIO2 | (RK3328_SOC_CON4_VCCIO2 << 16);
  206. ret = regmap_write(iod->grf, RK3328_SOC_CON4, val);
  207. if (ret < 0)
  208. dev_warn(iod->dev, "couldn't update vccio2 vsel ctrl\n");
  209. }
  210. static void rk3368_iodomain_init(struct rockchip_iodomain *iod)
  211. {
  212. int ret;
  213. u32 val;
  214. /* if no flash supply we should leave things alone */
  215. if (!iod->supplies[RK3368_SOC_FLASH_SUPPLY_NUM].reg)
  216. return;
  217. /*
  218. * set flash0 iodomain to also use this framework
  219. * instead of a special gpio.
  220. */
  221. val = RK3368_SOC_CON15_FLASH0 | (RK3368_SOC_CON15_FLASH0 << 16);
  222. ret = regmap_write(iod->grf, RK3368_SOC_CON15, val);
  223. if (ret < 0)
  224. dev_warn(iod->dev, "couldn't update flash0 ctrl\n");
  225. }
  226. static void rk3399_pmu_iodomain_init(struct rockchip_iodomain *iod)
  227. {
  228. int ret;
  229. u32 val;
  230. /* if no pmu io supply we should leave things alone */
  231. if (!iod->supplies[RK3399_PMUGRF_VSEL_SUPPLY_NUM].reg)
  232. return;
  233. /*
  234. * set pmu io iodomain to also use this framework
  235. * instead of a special gpio.
  236. */
  237. val = RK3399_PMUGRF_CON0_VSEL | (RK3399_PMUGRF_CON0_VSEL << 16);
  238. ret = regmap_write(iod->grf, RK3399_PMUGRF_CON0, val);
  239. if (ret < 0)
  240. dev_warn(iod->dev, "couldn't update pmu io iodomain ctrl\n");
  241. }
  242. static const struct rockchip_iodomain_soc_data soc_data_px30 = {
  243. .grf_offset = 0x180,
  244. .supply_names = {
  245. NULL,
  246. "vccio6",
  247. "vccio1",
  248. "vccio2",
  249. "vccio3",
  250. "vccio4",
  251. "vccio5",
  252. "vccio-oscgpi",
  253. },
  254. .init = px30_iodomain_init,
  255. };
  256. static const struct rockchip_iodomain_soc_data soc_data_px30_pmu = {
  257. .grf_offset = 0x100,
  258. .supply_names = {
  259. NULL,
  260. NULL,
  261. NULL,
  262. NULL,
  263. NULL,
  264. NULL,
  265. NULL,
  266. NULL,
  267. NULL,
  268. NULL,
  269. NULL,
  270. NULL,
  271. NULL,
  272. NULL,
  273. "pmuio1",
  274. "pmuio2",
  275. },
  276. };
  277. /*
  278. * On the rk3188 the io-domains are handled by a shared register with the
  279. * lower 8 bits being still being continuing drive-strength settings.
  280. */
  281. static const struct rockchip_iodomain_soc_data soc_data_rk3188 = {
  282. .grf_offset = 0x104,
  283. .supply_names = {
  284. NULL,
  285. NULL,
  286. NULL,
  287. NULL,
  288. NULL,
  289. NULL,
  290. NULL,
  291. NULL,
  292. "ap0",
  293. "ap1",
  294. "cif",
  295. "flash",
  296. "vccio0",
  297. "vccio1",
  298. "lcdc0",
  299. "lcdc1",
  300. },
  301. };
  302. static const struct rockchip_iodomain_soc_data soc_data_rk3228 = {
  303. .grf_offset = 0x418,
  304. .supply_names = {
  305. "vccio1",
  306. "vccio2",
  307. "vccio3",
  308. "vccio4",
  309. },
  310. };
  311. static const struct rockchip_iodomain_soc_data soc_data_rk3288 = {
  312. .grf_offset = 0x380,
  313. .supply_names = {
  314. "lcdc", /* LCDC_VDD */
  315. "dvp", /* DVPIO_VDD */
  316. "flash0", /* FLASH0_VDD (emmc) */
  317. "flash1", /* FLASH1_VDD (sdio1) */
  318. "wifi", /* APIO3_VDD (sdio0) */
  319. "bb", /* APIO5_VDD */
  320. "audio", /* APIO4_VDD */
  321. "sdcard", /* SDMMC0_VDD (sdmmc) */
  322. "gpio30", /* APIO1_VDD */
  323. "gpio1830", /* APIO2_VDD */
  324. },
  325. .init = rk3288_iodomain_init,
  326. };
  327. static const struct rockchip_iodomain_soc_data soc_data_rk3328 = {
  328. .grf_offset = 0x410,
  329. .supply_names = {
  330. "vccio1",
  331. "vccio2",
  332. "vccio3",
  333. "vccio4",
  334. "vccio5",
  335. "vccio6",
  336. "pmuio",
  337. },
  338. .init = rk3328_iodomain_init,
  339. };
  340. static const struct rockchip_iodomain_soc_data soc_data_rk3368 = {
  341. .grf_offset = 0x900,
  342. .supply_names = {
  343. NULL, /* reserved */
  344. "dvp", /* DVPIO_VDD */
  345. "flash0", /* FLASH0_VDD (emmc) */
  346. "wifi", /* APIO2_VDD (sdio0) */
  347. NULL,
  348. "audio", /* APIO3_VDD */
  349. "sdcard", /* SDMMC0_VDD (sdmmc) */
  350. "gpio30", /* APIO1_VDD */
  351. "gpio1830", /* APIO4_VDD (gpujtag) */
  352. },
  353. .init = rk3368_iodomain_init,
  354. };
  355. static const struct rockchip_iodomain_soc_data soc_data_rk3368_pmu = {
  356. .grf_offset = 0x100,
  357. .supply_names = {
  358. NULL,
  359. NULL,
  360. NULL,
  361. NULL,
  362. "pmu", /*PMU IO domain*/
  363. "vop", /*LCDC IO domain*/
  364. },
  365. };
  366. static const struct rockchip_iodomain_soc_data soc_data_rk3399 = {
  367. .grf_offset = 0xe640,
  368. .supply_names = {
  369. "bt656", /* APIO2_VDD */
  370. "audio", /* APIO5_VDD */
  371. "sdmmc", /* SDMMC0_VDD */
  372. "gpio1830", /* APIO4_VDD */
  373. },
  374. };
  375. static const struct rockchip_iodomain_soc_data soc_data_rk3399_pmu = {
  376. .grf_offset = 0x180,
  377. .supply_names = {
  378. NULL,
  379. NULL,
  380. NULL,
  381. NULL,
  382. NULL,
  383. NULL,
  384. NULL,
  385. NULL,
  386. NULL,
  387. "pmu1830", /* PMUIO2_VDD */
  388. },
  389. .init = rk3399_pmu_iodomain_init,
  390. };
  391. static const struct rockchip_iodomain_soc_data soc_data_rk3568_pmu = {
  392. .grf_offset = 0x140,
  393. .supply_names = {
  394. "pmuio1",
  395. "pmuio2",
  396. "vccio1",
  397. "vccio2",
  398. "vccio3",
  399. "vccio4",
  400. "vccio5",
  401. "vccio6",
  402. "vccio7",
  403. },
  404. .write = rk3568_iodomain_write,
  405. };
  406. static const struct rockchip_iodomain_soc_data soc_data_rv1108 = {
  407. .grf_offset = 0x404,
  408. .supply_names = {
  409. NULL,
  410. NULL,
  411. NULL,
  412. NULL,
  413. NULL,
  414. NULL,
  415. NULL,
  416. NULL,
  417. NULL,
  418. NULL,
  419. NULL,
  420. "vccio1",
  421. "vccio2",
  422. "vccio3",
  423. "vccio5",
  424. "vccio6",
  425. },
  426. };
  427. static const struct rockchip_iodomain_soc_data soc_data_rv1108_pmu = {
  428. .grf_offset = 0x104,
  429. .supply_names = {
  430. "pmu",
  431. },
  432. };
  433. static const struct rockchip_iodomain_soc_data soc_data_rv1126_pmu = {
  434. .grf_offset = 0x140,
  435. .supply_names = {
  436. NULL,
  437. "vccio1",
  438. "vccio2",
  439. "vccio3",
  440. "vccio4",
  441. "vccio5",
  442. "vccio6",
  443. "vccio7",
  444. "pmuio0",
  445. "pmuio1",
  446. },
  447. };
  448. static const struct of_device_id rockchip_iodomain_match[] = {
  449. {
  450. .compatible = "rockchip,px30-io-voltage-domain",
  451. .data = (void *)&soc_data_px30
  452. },
  453. {
  454. .compatible = "rockchip,px30-pmu-io-voltage-domain",
  455. .data = (void *)&soc_data_px30_pmu
  456. },
  457. {
  458. .compatible = "rockchip,rk3188-io-voltage-domain",
  459. .data = &soc_data_rk3188
  460. },
  461. {
  462. .compatible = "rockchip,rk3228-io-voltage-domain",
  463. .data = &soc_data_rk3228
  464. },
  465. {
  466. .compatible = "rockchip,rk3288-io-voltage-domain",
  467. .data = &soc_data_rk3288
  468. },
  469. {
  470. .compatible = "rockchip,rk3328-io-voltage-domain",
  471. .data = &soc_data_rk3328
  472. },
  473. {
  474. .compatible = "rockchip,rk3368-io-voltage-domain",
  475. .data = &soc_data_rk3368
  476. },
  477. {
  478. .compatible = "rockchip,rk3368-pmu-io-voltage-domain",
  479. .data = &soc_data_rk3368_pmu
  480. },
  481. {
  482. .compatible = "rockchip,rk3399-io-voltage-domain",
  483. .data = &soc_data_rk3399
  484. },
  485. {
  486. .compatible = "rockchip,rk3399-pmu-io-voltage-domain",
  487. .data = &soc_data_rk3399_pmu
  488. },
  489. {
  490. .compatible = "rockchip,rk3568-pmu-io-voltage-domain",
  491. .data = &soc_data_rk3568_pmu
  492. },
  493. {
  494. .compatible = "rockchip,rv1108-io-voltage-domain",
  495. .data = &soc_data_rv1108
  496. },
  497. {
  498. .compatible = "rockchip,rv1108-pmu-io-voltage-domain",
  499. .data = &soc_data_rv1108_pmu
  500. },
  501. {
  502. .compatible = "rockchip,rv1126-pmu-io-voltage-domain",
  503. .data = &soc_data_rv1126_pmu
  504. },
  505. { /* sentinel */ },
  506. };
  507. MODULE_DEVICE_TABLE(of, rockchip_iodomain_match);
  508. static int rockchip_iodomain_probe(struct platform_device *pdev)
  509. {
  510. struct device_node *np = pdev->dev.of_node;
  511. const struct of_device_id *match;
  512. struct rockchip_iodomain *iod;
  513. struct device *parent;
  514. int i, ret = 0;
  515. if (!np)
  516. return -ENODEV;
  517. iod = devm_kzalloc(&pdev->dev, sizeof(*iod), GFP_KERNEL);
  518. if (!iod)
  519. return -ENOMEM;
  520. iod->dev = &pdev->dev;
  521. platform_set_drvdata(pdev, iod);
  522. match = of_match_node(rockchip_iodomain_match, np);
  523. iod->soc_data = match->data;
  524. if (iod->soc_data->write)
  525. iod->write = iod->soc_data->write;
  526. else
  527. iod->write = rockchip_iodomain_write;
  528. parent = pdev->dev.parent;
  529. if (parent && parent->of_node) {
  530. iod->grf = syscon_node_to_regmap(parent->of_node);
  531. } else {
  532. dev_dbg(&pdev->dev, "falling back to old binding\n");
  533. iod->grf = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
  534. }
  535. if (IS_ERR(iod->grf)) {
  536. dev_err(&pdev->dev, "couldn't find grf regmap\n");
  537. return PTR_ERR(iod->grf);
  538. }
  539. for (i = 0; i < MAX_SUPPLIES; i++) {
  540. const char *supply_name = iod->soc_data->supply_names[i];
  541. struct rockchip_iodomain_supply *supply = &iod->supplies[i];
  542. struct regulator *reg;
  543. int uV;
  544. if (!supply_name)
  545. continue;
  546. reg = devm_regulator_get_optional(iod->dev, supply_name);
  547. if (IS_ERR(reg)) {
  548. ret = PTR_ERR(reg);
  549. /* If a supply wasn't specified, that's OK */
  550. if (ret == -ENODEV)
  551. continue;
  552. else if (ret != -EPROBE_DEFER)
  553. dev_err(iod->dev, "couldn't get regulator %s\n",
  554. supply_name);
  555. goto unreg_notify;
  556. }
  557. /* set initial correct value */
  558. uV = regulator_get_voltage(reg);
  559. /* must be a regulator we can get the voltage of */
  560. if (uV < 0) {
  561. dev_err(iod->dev, "Can't determine voltage: %s\n",
  562. supply_name);
  563. ret = uV;
  564. goto unreg_notify;
  565. }
  566. if (uV > MAX_VOLTAGE_3_3) {
  567. dev_crit(iod->dev,
  568. "%d uV is too high. May damage SoC!\n",
  569. uV);
  570. ret = -EINVAL;
  571. goto unreg_notify;
  572. }
  573. /* setup our supply */
  574. supply->idx = i;
  575. supply->iod = iod;
  576. supply->reg = reg;
  577. supply->nb.notifier_call = rockchip_iodomain_notify;
  578. ret = iod->write(supply, uV);
  579. if (ret) {
  580. supply->reg = NULL;
  581. goto unreg_notify;
  582. }
  583. /* register regulator notifier */
  584. ret = regulator_register_notifier(reg, &supply->nb);
  585. if (ret) {
  586. dev_err(&pdev->dev,
  587. "regulator notifier request failed\n");
  588. supply->reg = NULL;
  589. goto unreg_notify;
  590. }
  591. }
  592. if (iod->soc_data->init)
  593. iod->soc_data->init(iod);
  594. return 0;
  595. unreg_notify:
  596. for (i = MAX_SUPPLIES - 1; i >= 0; i--) {
  597. struct rockchip_iodomain_supply *io_supply = &iod->supplies[i];
  598. if (io_supply->reg)
  599. regulator_unregister_notifier(io_supply->reg,
  600. &io_supply->nb);
  601. }
  602. return ret;
  603. }
  604. static int rockchip_iodomain_remove(struct platform_device *pdev)
  605. {
  606. struct rockchip_iodomain *iod = platform_get_drvdata(pdev);
  607. int i;
  608. for (i = MAX_SUPPLIES - 1; i >= 0; i--) {
  609. struct rockchip_iodomain_supply *io_supply = &iod->supplies[i];
  610. if (io_supply->reg)
  611. regulator_unregister_notifier(io_supply->reg,
  612. &io_supply->nb);
  613. }
  614. return 0;
  615. }
  616. static struct platform_driver rockchip_iodomain_driver = {
  617. .probe = rockchip_iodomain_probe,
  618. .remove = rockchip_iodomain_remove,
  619. .driver = {
  620. .name = "rockchip-iodomain",
  621. .of_match_table = rockchip_iodomain_match,
  622. },
  623. };
  624. module_platform_driver(rockchip_iodomain_driver);
  625. MODULE_DESCRIPTION("Rockchip IO-domain driver");
  626. MODULE_AUTHOR("Heiko Stuebner <[email protected]>");
  627. MODULE_AUTHOR("Doug Anderson <[email protected]>");
  628. MODULE_LICENSE("GPL v2");