tps65910-regulator.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * tps65910.c -- TI tps65910
  4. *
  5. * Copyright 2010 Texas Instruments Inc.
  6. *
  7. * Author: Graeme Gregory <gg@slimlogic.co.uk>
  8. * Author: Jorge Eduardo Candelaria <jedu@slimlogic.co.uk>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/err.h>
  14. #include <linux/of.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regulator/driver.h>
  17. #include <linux/regulator/machine.h>
  18. #include <linux/slab.h>
  19. #include <linux/gpio.h>
  20. #include <linux/mfd/tps65910.h>
  21. #include <linux/regulator/of_regulator.h>
  22. #define TPS65910_SUPPLY_STATE_ENABLED 0x1
  23. #define EXT_SLEEP_CONTROL (TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1 | \
  24. TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2 | \
  25. TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3 | \
  26. TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
  27. /* supported VIO voltages in microvolts */
  28. static const unsigned int VIO_VSEL_table[] = {
  29. 1500000, 1800000, 2500000, 3300000,
  30. };
  31. /* VSEL tables for TPS65910 specific LDOs and dcdc's */
  32. /* supported VRTC voltages in microvolts */
  33. static const unsigned int VRTC_VSEL_table[] = {
  34. 1800000,
  35. };
  36. /* supported VDD3 voltages in microvolts */
  37. static const unsigned int VDD3_VSEL_table[] = {
  38. 5000000,
  39. };
  40. /* supported VDIG1 voltages in microvolts */
  41. static const unsigned int VDIG1_VSEL_table[] = {
  42. 1200000, 1500000, 1800000, 2700000,
  43. };
  44. /* supported VDIG2 voltages in microvolts */
  45. static const unsigned int VDIG2_VSEL_table[] = {
  46. 1000000, 1100000, 1200000, 1800000,
  47. };
  48. /* supported VPLL voltages in microvolts */
  49. static const unsigned int VPLL_VSEL_table[] = {
  50. 1000000, 1100000, 1800000, 2500000,
  51. };
  52. /* supported VDAC voltages in microvolts */
  53. static const unsigned int VDAC_VSEL_table[] = {
  54. 1800000, 2600000, 2800000, 2850000,
  55. };
  56. /* supported VAUX1 voltages in microvolts */
  57. static const unsigned int VAUX1_VSEL_table[] = {
  58. 1800000, 2500000, 2800000, 2850000,
  59. };
  60. /* supported VAUX2 voltages in microvolts */
  61. static const unsigned int VAUX2_VSEL_table[] = {
  62. 1800000, 2800000, 2900000, 3300000,
  63. };
  64. /* supported VAUX33 voltages in microvolts */
  65. static const unsigned int VAUX33_VSEL_table[] = {
  66. 1800000, 2000000, 2800000, 3300000,
  67. };
  68. /* supported VMMC voltages in microvolts */
  69. static const unsigned int VMMC_VSEL_table[] = {
  70. 1800000, 2800000, 3000000, 3300000,
  71. };
  72. /* supported BBCH voltages in microvolts */
  73. static const unsigned int VBB_VSEL_table[] = {
  74. 3000000, 2520000, 3150000, 5000000,
  75. };
  76. struct tps_info {
  77. const char *name;
  78. const char *vin_name;
  79. u8 n_voltages;
  80. const unsigned int *voltage_table;
  81. int enable_time_us;
  82. };
  83. static struct tps_info tps65910_regs[] = {
  84. {
  85. .name = "vrtc",
  86. .vin_name = "vcc7",
  87. .n_voltages = ARRAY_SIZE(VRTC_VSEL_table),
  88. .voltage_table = VRTC_VSEL_table,
  89. .enable_time_us = 2200,
  90. },
  91. {
  92. .name = "vio",
  93. .vin_name = "vccio",
  94. .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
  95. .voltage_table = VIO_VSEL_table,
  96. .enable_time_us = 350,
  97. },
  98. {
  99. .name = "vdd1",
  100. .vin_name = "vcc1",
  101. .enable_time_us = 350,
  102. },
  103. {
  104. .name = "vdd2",
  105. .vin_name = "vcc2",
  106. .enable_time_us = 350,
  107. },
  108. {
  109. .name = "vdd3",
  110. .n_voltages = ARRAY_SIZE(VDD3_VSEL_table),
  111. .voltage_table = VDD3_VSEL_table,
  112. .enable_time_us = 200,
  113. },
  114. {
  115. .name = "vdig1",
  116. .vin_name = "vcc6",
  117. .n_voltages = ARRAY_SIZE(VDIG1_VSEL_table),
  118. .voltage_table = VDIG1_VSEL_table,
  119. .enable_time_us = 100,
  120. },
  121. {
  122. .name = "vdig2",
  123. .vin_name = "vcc6",
  124. .n_voltages = ARRAY_SIZE(VDIG2_VSEL_table),
  125. .voltage_table = VDIG2_VSEL_table,
  126. .enable_time_us = 100,
  127. },
  128. {
  129. .name = "vpll",
  130. .vin_name = "vcc5",
  131. .n_voltages = ARRAY_SIZE(VPLL_VSEL_table),
  132. .voltage_table = VPLL_VSEL_table,
  133. .enable_time_us = 100,
  134. },
  135. {
  136. .name = "vdac",
  137. .vin_name = "vcc5",
  138. .n_voltages = ARRAY_SIZE(VDAC_VSEL_table),
  139. .voltage_table = VDAC_VSEL_table,
  140. .enable_time_us = 100,
  141. },
  142. {
  143. .name = "vaux1",
  144. .vin_name = "vcc4",
  145. .n_voltages = ARRAY_SIZE(VAUX1_VSEL_table),
  146. .voltage_table = VAUX1_VSEL_table,
  147. .enable_time_us = 100,
  148. },
  149. {
  150. .name = "vaux2",
  151. .vin_name = "vcc4",
  152. .n_voltages = ARRAY_SIZE(VAUX2_VSEL_table),
  153. .voltage_table = VAUX2_VSEL_table,
  154. .enable_time_us = 100,
  155. },
  156. {
  157. .name = "vaux33",
  158. .vin_name = "vcc3",
  159. .n_voltages = ARRAY_SIZE(VAUX33_VSEL_table),
  160. .voltage_table = VAUX33_VSEL_table,
  161. .enable_time_us = 100,
  162. },
  163. {
  164. .name = "vmmc",
  165. .vin_name = "vcc3",
  166. .n_voltages = ARRAY_SIZE(VMMC_VSEL_table),
  167. .voltage_table = VMMC_VSEL_table,
  168. .enable_time_us = 100,
  169. },
  170. {
  171. .name = "vbb",
  172. .vin_name = "vcc7",
  173. .n_voltages = ARRAY_SIZE(VBB_VSEL_table),
  174. .voltage_table = VBB_VSEL_table,
  175. },
  176. };
  177. static struct tps_info tps65911_regs[] = {
  178. {
  179. .name = "vrtc",
  180. .vin_name = "vcc7",
  181. .enable_time_us = 2200,
  182. },
  183. {
  184. .name = "vio",
  185. .vin_name = "vccio",
  186. .n_voltages = ARRAY_SIZE(VIO_VSEL_table),
  187. .voltage_table = VIO_VSEL_table,
  188. .enable_time_us = 350,
  189. },
  190. {
  191. .name = "vdd1",
  192. .vin_name = "vcc1",
  193. .n_voltages = 0x4C,
  194. .enable_time_us = 350,
  195. },
  196. {
  197. .name = "vdd2",
  198. .vin_name = "vcc2",
  199. .n_voltages = 0x4C,
  200. .enable_time_us = 350,
  201. },
  202. {
  203. .name = "vddctrl",
  204. .n_voltages = 0x44,
  205. .enable_time_us = 900,
  206. },
  207. {
  208. .name = "ldo1",
  209. .vin_name = "vcc6",
  210. .n_voltages = 0x33,
  211. .enable_time_us = 420,
  212. },
  213. {
  214. .name = "ldo2",
  215. .vin_name = "vcc6",
  216. .n_voltages = 0x33,
  217. .enable_time_us = 420,
  218. },
  219. {
  220. .name = "ldo3",
  221. .vin_name = "vcc5",
  222. .n_voltages = 0x1A,
  223. .enable_time_us = 230,
  224. },
  225. {
  226. .name = "ldo4",
  227. .vin_name = "vcc5",
  228. .n_voltages = 0x33,
  229. .enable_time_us = 230,
  230. },
  231. {
  232. .name = "ldo5",
  233. .vin_name = "vcc4",
  234. .n_voltages = 0x1A,
  235. .enable_time_us = 230,
  236. },
  237. {
  238. .name = "ldo6",
  239. .vin_name = "vcc3",
  240. .n_voltages = 0x1A,
  241. .enable_time_us = 230,
  242. },
  243. {
  244. .name = "ldo7",
  245. .vin_name = "vcc3",
  246. .n_voltages = 0x1A,
  247. .enable_time_us = 230,
  248. },
  249. {
  250. .name = "ldo8",
  251. .vin_name = "vcc3",
  252. .n_voltages = 0x1A,
  253. .enable_time_us = 230,
  254. },
  255. };
  256. #define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
  257. static unsigned int tps65910_ext_sleep_control[] = {
  258. 0,
  259. EXT_CONTROL_REG_BITS(VIO, 1, 0),
  260. EXT_CONTROL_REG_BITS(VDD1, 1, 1),
  261. EXT_CONTROL_REG_BITS(VDD2, 1, 2),
  262. EXT_CONTROL_REG_BITS(VDD3, 1, 3),
  263. EXT_CONTROL_REG_BITS(VDIG1, 0, 1),
  264. EXT_CONTROL_REG_BITS(VDIG2, 0, 2),
  265. EXT_CONTROL_REG_BITS(VPLL, 0, 6),
  266. EXT_CONTROL_REG_BITS(VDAC, 0, 7),
  267. EXT_CONTROL_REG_BITS(VAUX1, 0, 3),
  268. EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
  269. EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
  270. EXT_CONTROL_REG_BITS(VMMC, 0, 0),
  271. };
  272. static unsigned int tps65911_ext_sleep_control[] = {
  273. 0,
  274. EXT_CONTROL_REG_BITS(VIO, 1, 0),
  275. EXT_CONTROL_REG_BITS(VDD1, 1, 1),
  276. EXT_CONTROL_REG_BITS(VDD2, 1, 2),
  277. EXT_CONTROL_REG_BITS(VDDCTRL, 1, 3),
  278. EXT_CONTROL_REG_BITS(LDO1, 0, 1),
  279. EXT_CONTROL_REG_BITS(LDO2, 0, 2),
  280. EXT_CONTROL_REG_BITS(LDO3, 0, 7),
  281. EXT_CONTROL_REG_BITS(LDO4, 0, 6),
  282. EXT_CONTROL_REG_BITS(LDO5, 0, 3),
  283. EXT_CONTROL_REG_BITS(LDO6, 0, 0),
  284. EXT_CONTROL_REG_BITS(LDO7, 0, 5),
  285. EXT_CONTROL_REG_BITS(LDO8, 0, 4),
  286. };
  287. struct tps65910_reg {
  288. struct regulator_desc *desc;
  289. struct tps65910 *mfd;
  290. struct regulator_dev **rdev;
  291. struct tps_info **info;
  292. int num_regulators;
  293. int mode;
  294. int (*get_ctrl_reg)(int);
  295. unsigned int *ext_sleep_control;
  296. unsigned int board_ext_control[TPS65910_NUM_REGS];
  297. };
  298. static int tps65910_get_ctrl_register(int id)
  299. {
  300. switch (id) {
  301. case TPS65910_REG_VRTC:
  302. return TPS65910_VRTC;
  303. case TPS65910_REG_VIO:
  304. return TPS65910_VIO;
  305. case TPS65910_REG_VDD1:
  306. return TPS65910_VDD1;
  307. case TPS65910_REG_VDD2:
  308. return TPS65910_VDD2;
  309. case TPS65910_REG_VDD3:
  310. return TPS65910_VDD3;
  311. case TPS65910_REG_VDIG1:
  312. return TPS65910_VDIG1;
  313. case TPS65910_REG_VDIG2:
  314. return TPS65910_VDIG2;
  315. case TPS65910_REG_VPLL:
  316. return TPS65910_VPLL;
  317. case TPS65910_REG_VDAC:
  318. return TPS65910_VDAC;
  319. case TPS65910_REG_VAUX1:
  320. return TPS65910_VAUX1;
  321. case TPS65910_REG_VAUX2:
  322. return TPS65910_VAUX2;
  323. case TPS65910_REG_VAUX33:
  324. return TPS65910_VAUX33;
  325. case TPS65910_REG_VMMC:
  326. return TPS65910_VMMC;
  327. case TPS65910_REG_VBB:
  328. return TPS65910_BBCH;
  329. default:
  330. return -EINVAL;
  331. }
  332. }
  333. static int tps65911_get_ctrl_register(int id)
  334. {
  335. switch (id) {
  336. case TPS65910_REG_VRTC:
  337. return TPS65910_VRTC;
  338. case TPS65910_REG_VIO:
  339. return TPS65910_VIO;
  340. case TPS65910_REG_VDD1:
  341. return TPS65910_VDD1;
  342. case TPS65910_REG_VDD2:
  343. return TPS65910_VDD2;
  344. case TPS65911_REG_VDDCTRL:
  345. return TPS65911_VDDCTRL;
  346. case TPS65911_REG_LDO1:
  347. return TPS65911_LDO1;
  348. case TPS65911_REG_LDO2:
  349. return TPS65911_LDO2;
  350. case TPS65911_REG_LDO3:
  351. return TPS65911_LDO3;
  352. case TPS65911_REG_LDO4:
  353. return TPS65911_LDO4;
  354. case TPS65911_REG_LDO5:
  355. return TPS65911_LDO5;
  356. case TPS65911_REG_LDO6:
  357. return TPS65911_LDO6;
  358. case TPS65911_REG_LDO7:
  359. return TPS65911_LDO7;
  360. case TPS65911_REG_LDO8:
  361. return TPS65911_LDO8;
  362. default:
  363. return -EINVAL;
  364. }
  365. }
  366. static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode)
  367. {
  368. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  369. struct regmap *regmap = rdev_get_regmap(dev);
  370. int reg, id = rdev_get_id(dev);
  371. reg = pmic->get_ctrl_reg(id);
  372. if (reg < 0)
  373. return reg;
  374. switch (mode) {
  375. case REGULATOR_MODE_NORMAL:
  376. return regmap_update_bits(regmap, reg,
  377. LDO_ST_MODE_BIT | LDO_ST_ON_BIT,
  378. LDO_ST_ON_BIT);
  379. case REGULATOR_MODE_IDLE:
  380. return regmap_set_bits(regmap, reg,
  381. LDO_ST_ON_BIT | LDO_ST_MODE_BIT);
  382. case REGULATOR_MODE_STANDBY:
  383. return regmap_clear_bits(regmap, reg, LDO_ST_ON_BIT);
  384. }
  385. return -EINVAL;
  386. }
  387. static unsigned int tps65910_get_mode(struct regulator_dev *dev)
  388. {
  389. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  390. struct regmap *regmap = rdev_get_regmap(dev);
  391. int ret, reg, value, id = rdev_get_id(dev);
  392. reg = pmic->get_ctrl_reg(id);
  393. if (reg < 0)
  394. return reg;
  395. ret = regmap_read(regmap, reg, &value);
  396. if (ret < 0)
  397. return ret;
  398. if (!(value & LDO_ST_ON_BIT))
  399. return REGULATOR_MODE_STANDBY;
  400. else if (value & LDO_ST_MODE_BIT)
  401. return REGULATOR_MODE_IDLE;
  402. else
  403. return REGULATOR_MODE_NORMAL;
  404. }
  405. static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev)
  406. {
  407. struct regmap *regmap = rdev_get_regmap(dev);
  408. int ret, id = rdev_get_id(dev);
  409. int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0;
  410. switch (id) {
  411. case TPS65910_REG_VDD1:
  412. ret = regmap_read(regmap, TPS65910_VDD1_OP, &opvsel);
  413. if (ret < 0)
  414. return ret;
  415. ret = regmap_read(regmap, TPS65910_VDD1, &mult);
  416. if (ret < 0)
  417. return ret;
  418. mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT;
  419. ret = regmap_read(regmap, TPS65910_VDD1_SR, &srvsel);
  420. if (ret < 0)
  421. return ret;
  422. sr = opvsel & VDD1_OP_CMD_MASK;
  423. opvsel &= VDD1_OP_SEL_MASK;
  424. srvsel &= VDD1_SR_SEL_MASK;
  425. vselmax = 75;
  426. break;
  427. case TPS65910_REG_VDD2:
  428. ret = regmap_read(regmap, TPS65910_VDD2_OP, &opvsel);
  429. if (ret < 0)
  430. return ret;
  431. ret = regmap_read(regmap, TPS65910_VDD2, &mult);
  432. if (ret < 0)
  433. return ret;
  434. mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT;
  435. ret = regmap_read(regmap, TPS65910_VDD2_SR, &srvsel);
  436. if (ret < 0)
  437. return ret;
  438. sr = opvsel & VDD2_OP_CMD_MASK;
  439. opvsel &= VDD2_OP_SEL_MASK;
  440. srvsel &= VDD2_SR_SEL_MASK;
  441. vselmax = 75;
  442. break;
  443. case TPS65911_REG_VDDCTRL:
  444. ret = regmap_read(regmap, TPS65911_VDDCTRL_OP, &opvsel);
  445. if (ret < 0)
  446. return ret;
  447. ret = regmap_read(regmap, TPS65911_VDDCTRL_SR, &srvsel);
  448. if (ret < 0)
  449. return ret;
  450. sr = opvsel & VDDCTRL_OP_CMD_MASK;
  451. opvsel &= VDDCTRL_OP_SEL_MASK;
  452. srvsel &= VDDCTRL_SR_SEL_MASK;
  453. vselmax = 64;
  454. break;
  455. }
  456. /* multiplier 0 == 1 but 2,3 normal */
  457. if (!mult)
  458. mult = 1;
  459. if (sr) {
  460. /* normalise to valid range */
  461. if (srvsel < 3)
  462. srvsel = 3;
  463. if (srvsel > vselmax)
  464. srvsel = vselmax;
  465. return srvsel - 3;
  466. } else {
  467. /* normalise to valid range*/
  468. if (opvsel < 3)
  469. opvsel = 3;
  470. if (opvsel > vselmax)
  471. opvsel = vselmax;
  472. return opvsel - 3;
  473. }
  474. return -EINVAL;
  475. }
  476. static int tps65910_get_voltage_sel(struct regulator_dev *dev)
  477. {
  478. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  479. struct regmap *regmap = rdev_get_regmap(dev);
  480. int ret, reg, value, id = rdev_get_id(dev);
  481. reg = pmic->get_ctrl_reg(id);
  482. if (reg < 0)
  483. return reg;
  484. ret = regmap_read(regmap, reg, &value);
  485. if (ret < 0)
  486. return ret;
  487. switch (id) {
  488. case TPS65910_REG_VIO:
  489. case TPS65910_REG_VDIG1:
  490. case TPS65910_REG_VDIG2:
  491. case TPS65910_REG_VPLL:
  492. case TPS65910_REG_VDAC:
  493. case TPS65910_REG_VAUX1:
  494. case TPS65910_REG_VAUX2:
  495. case TPS65910_REG_VAUX33:
  496. case TPS65910_REG_VMMC:
  497. value &= LDO_SEL_MASK;
  498. value >>= LDO_SEL_SHIFT;
  499. break;
  500. case TPS65910_REG_VBB:
  501. value &= BBCH_BBSEL_MASK;
  502. value >>= BBCH_BBSEL_SHIFT;
  503. break;
  504. default:
  505. return -EINVAL;
  506. }
  507. return value;
  508. }
  509. static int tps65910_get_voltage_vdd3(struct regulator_dev *dev)
  510. {
  511. return dev->desc->volt_table[0];
  512. }
  513. static int tps65911_get_voltage_sel(struct regulator_dev *dev)
  514. {
  515. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  516. struct regmap *regmap = rdev_get_regmap(dev);
  517. int ret, id = rdev_get_id(dev);
  518. unsigned int value, reg;
  519. reg = pmic->get_ctrl_reg(id);
  520. ret = regmap_read(regmap, reg, &value);
  521. if (ret < 0)
  522. return ret;
  523. switch (id) {
  524. case TPS65911_REG_LDO1:
  525. case TPS65911_REG_LDO2:
  526. case TPS65911_REG_LDO4:
  527. value &= LDO1_SEL_MASK;
  528. value >>= LDO_SEL_SHIFT;
  529. break;
  530. case TPS65911_REG_LDO3:
  531. case TPS65911_REG_LDO5:
  532. case TPS65911_REG_LDO6:
  533. case TPS65911_REG_LDO7:
  534. case TPS65911_REG_LDO8:
  535. value &= LDO3_SEL_MASK;
  536. value >>= LDO_SEL_SHIFT;
  537. break;
  538. case TPS65910_REG_VIO:
  539. value &= LDO_SEL_MASK;
  540. value >>= LDO_SEL_SHIFT;
  541. break;
  542. default:
  543. return -EINVAL;
  544. }
  545. return value;
  546. }
  547. static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev,
  548. unsigned selector)
  549. {
  550. struct regmap *regmap = rdev_get_regmap(dev);
  551. int id = rdev_get_id(dev), vsel;
  552. int dcdc_mult = 0;
  553. switch (id) {
  554. case TPS65910_REG_VDD1:
  555. dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
  556. if (dcdc_mult == 1)
  557. dcdc_mult--;
  558. vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
  559. regmap_update_bits(regmap, TPS65910_VDD1, VDD1_VGAIN_SEL_MASK,
  560. dcdc_mult << VDD1_VGAIN_SEL_SHIFT);
  561. regmap_write(regmap, TPS65910_VDD1_OP, vsel);
  562. break;
  563. case TPS65910_REG_VDD2:
  564. dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
  565. if (dcdc_mult == 1)
  566. dcdc_mult--;
  567. vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3;
  568. regmap_update_bits(regmap, TPS65910_VDD2, VDD1_VGAIN_SEL_MASK,
  569. dcdc_mult << VDD2_VGAIN_SEL_SHIFT);
  570. regmap_write(regmap, TPS65910_VDD2_OP, vsel);
  571. break;
  572. case TPS65911_REG_VDDCTRL:
  573. vsel = selector + 3;
  574. regmap_write(regmap, TPS65911_VDDCTRL_OP, vsel);
  575. break;
  576. }
  577. return 0;
  578. }
  579. static int tps65910_set_voltage_sel(struct regulator_dev *dev,
  580. unsigned selector)
  581. {
  582. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  583. struct regmap *regmap = rdev_get_regmap(dev);
  584. int reg, id = rdev_get_id(dev);
  585. reg = pmic->get_ctrl_reg(id);
  586. if (reg < 0)
  587. return reg;
  588. switch (id) {
  589. case TPS65910_REG_VIO:
  590. case TPS65910_REG_VDIG1:
  591. case TPS65910_REG_VDIG2:
  592. case TPS65910_REG_VPLL:
  593. case TPS65910_REG_VDAC:
  594. case TPS65910_REG_VAUX1:
  595. case TPS65910_REG_VAUX2:
  596. case TPS65910_REG_VAUX33:
  597. case TPS65910_REG_VMMC:
  598. return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
  599. selector << LDO_SEL_SHIFT);
  600. case TPS65910_REG_VBB:
  601. return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
  602. selector << BBCH_BBSEL_SHIFT);
  603. }
  604. return -EINVAL;
  605. }
  606. static int tps65911_set_voltage_sel(struct regulator_dev *dev,
  607. unsigned selector)
  608. {
  609. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  610. struct regmap *regmap = rdev_get_regmap(dev);
  611. int reg, id = rdev_get_id(dev);
  612. reg = pmic->get_ctrl_reg(id);
  613. if (reg < 0)
  614. return reg;
  615. switch (id) {
  616. case TPS65911_REG_LDO1:
  617. case TPS65911_REG_LDO2:
  618. case TPS65911_REG_LDO4:
  619. return regmap_update_bits(regmap, reg, LDO1_SEL_MASK,
  620. selector << LDO_SEL_SHIFT);
  621. case TPS65911_REG_LDO3:
  622. case TPS65911_REG_LDO5:
  623. case TPS65911_REG_LDO6:
  624. case TPS65911_REG_LDO7:
  625. case TPS65911_REG_LDO8:
  626. return regmap_update_bits(regmap, reg, LDO3_SEL_MASK,
  627. selector << LDO_SEL_SHIFT);
  628. case TPS65910_REG_VIO:
  629. return regmap_update_bits(regmap, reg, LDO_SEL_MASK,
  630. selector << LDO_SEL_SHIFT);
  631. case TPS65910_REG_VBB:
  632. return regmap_update_bits(regmap, reg, BBCH_BBSEL_MASK,
  633. selector << BBCH_BBSEL_SHIFT);
  634. }
  635. return -EINVAL;
  636. }
  637. static int tps65910_list_voltage_dcdc(struct regulator_dev *dev,
  638. unsigned selector)
  639. {
  640. int volt, mult = 1, id = rdev_get_id(dev);
  641. switch (id) {
  642. case TPS65910_REG_VDD1:
  643. case TPS65910_REG_VDD2:
  644. mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1;
  645. volt = VDD1_2_MIN_VOLT +
  646. (selector % VDD1_2_NUM_VOLT_FINE) * VDD1_2_OFFSET;
  647. break;
  648. case TPS65911_REG_VDDCTRL:
  649. volt = VDDCTRL_MIN_VOLT + (selector * VDDCTRL_OFFSET);
  650. break;
  651. default:
  652. BUG();
  653. return -EINVAL;
  654. }
  655. return volt * 100 * mult;
  656. }
  657. static int tps65911_list_voltage(struct regulator_dev *dev, unsigned selector)
  658. {
  659. struct tps65910_reg *pmic = rdev_get_drvdata(dev);
  660. int step_mv = 0, id = rdev_get_id(dev);
  661. switch (id) {
  662. case TPS65911_REG_LDO1:
  663. case TPS65911_REG_LDO2:
  664. case TPS65911_REG_LDO4:
  665. /* The first 5 values of the selector correspond to 1V */
  666. if (selector < 5)
  667. selector = 0;
  668. else
  669. selector -= 4;
  670. step_mv = 50;
  671. break;
  672. case TPS65911_REG_LDO3:
  673. case TPS65911_REG_LDO5:
  674. case TPS65911_REG_LDO6:
  675. case TPS65911_REG_LDO7:
  676. case TPS65911_REG_LDO8:
  677. /* The first 3 values of the selector correspond to 1V */
  678. if (selector < 3)
  679. selector = 0;
  680. else
  681. selector -= 2;
  682. step_mv = 100;
  683. break;
  684. case TPS65910_REG_VIO:
  685. return pmic->info[id]->voltage_table[selector];
  686. default:
  687. return -EINVAL;
  688. }
  689. return (LDO_MIN_VOLT + selector * step_mv) * 1000;
  690. }
  691. /* Regulator ops (except VRTC) */
  692. static const struct regulator_ops tps65910_ops_dcdc = {
  693. .is_enabled = regulator_is_enabled_regmap,
  694. .enable = regulator_enable_regmap,
  695. .disable = regulator_disable_regmap,
  696. .set_mode = tps65910_set_mode,
  697. .get_mode = tps65910_get_mode,
  698. .get_voltage_sel = tps65910_get_voltage_dcdc_sel,
  699. .set_voltage_sel = tps65910_set_voltage_dcdc_sel,
  700. .set_voltage_time_sel = regulator_set_voltage_time_sel,
  701. .list_voltage = tps65910_list_voltage_dcdc,
  702. .map_voltage = regulator_map_voltage_ascend,
  703. };
  704. static const struct regulator_ops tps65910_ops_vdd3 = {
  705. .is_enabled = regulator_is_enabled_regmap,
  706. .enable = regulator_enable_regmap,
  707. .disable = regulator_disable_regmap,
  708. .set_mode = tps65910_set_mode,
  709. .get_mode = tps65910_get_mode,
  710. .get_voltage = tps65910_get_voltage_vdd3,
  711. .list_voltage = regulator_list_voltage_table,
  712. .map_voltage = regulator_map_voltage_ascend,
  713. };
  714. static const struct regulator_ops tps65910_ops_vbb = {
  715. .is_enabled = regulator_is_enabled_regmap,
  716. .enable = regulator_enable_regmap,
  717. .disable = regulator_disable_regmap,
  718. .set_mode = tps65910_set_mode,
  719. .get_mode = tps65910_get_mode,
  720. .get_voltage_sel = tps65910_get_voltage_sel,
  721. .set_voltage_sel = tps65910_set_voltage_sel,
  722. .list_voltage = regulator_list_voltage_table,
  723. .map_voltage = regulator_map_voltage_iterate,
  724. };
  725. static const struct regulator_ops tps65910_ops = {
  726. .is_enabled = regulator_is_enabled_regmap,
  727. .enable = regulator_enable_regmap,
  728. .disable = regulator_disable_regmap,
  729. .set_mode = tps65910_set_mode,
  730. .get_mode = tps65910_get_mode,
  731. .get_voltage_sel = tps65910_get_voltage_sel,
  732. .set_voltage_sel = tps65910_set_voltage_sel,
  733. .list_voltage = regulator_list_voltage_table,
  734. .map_voltage = regulator_map_voltage_ascend,
  735. };
  736. static const struct regulator_ops tps65911_ops = {
  737. .is_enabled = regulator_is_enabled_regmap,
  738. .enable = regulator_enable_regmap,
  739. .disable = regulator_disable_regmap,
  740. .set_mode = tps65910_set_mode,
  741. .get_mode = tps65910_get_mode,
  742. .get_voltage_sel = tps65911_get_voltage_sel,
  743. .set_voltage_sel = tps65911_set_voltage_sel,
  744. .list_voltage = tps65911_list_voltage,
  745. .map_voltage = regulator_map_voltage_ascend,
  746. };
  747. static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
  748. int id, int ext_sleep_config)
  749. {
  750. struct tps65910 *mfd = pmic->mfd;
  751. u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
  752. u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
  753. int ret;
  754. /*
  755. * Regulator can not be control from multiple external input EN1, EN2
  756. * and EN3 together.
  757. */
  758. if (ext_sleep_config & EXT_SLEEP_CONTROL) {
  759. int en_count;
  760. en_count = ((ext_sleep_config &
  761. TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1) != 0);
  762. en_count += ((ext_sleep_config &
  763. TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2) != 0);
  764. en_count += ((ext_sleep_config &
  765. TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3) != 0);
  766. en_count += ((ext_sleep_config &
  767. TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP) != 0);
  768. if (en_count > 1) {
  769. dev_err(mfd->dev,
  770. "External sleep control flag is not proper\n");
  771. return -EINVAL;
  772. }
  773. }
  774. pmic->board_ext_control[id] = ext_sleep_config;
  775. /* External EN1 control */
  776. if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN1)
  777. ret = regmap_set_bits(mfd->regmap,
  778. TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
  779. else
  780. ret = regmap_clear_bits(mfd->regmap,
  781. TPS65910_EN1_LDO_ASS + regoffs, bit_pos);
  782. if (ret < 0) {
  783. dev_err(mfd->dev,
  784. "Error in configuring external control EN1\n");
  785. return ret;
  786. }
  787. /* External EN2 control */
  788. if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN2)
  789. ret = regmap_set_bits(mfd->regmap,
  790. TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
  791. else
  792. ret = regmap_clear_bits(mfd->regmap,
  793. TPS65910_EN2_LDO_ASS + regoffs, bit_pos);
  794. if (ret < 0) {
  795. dev_err(mfd->dev,
  796. "Error in configuring external control EN2\n");
  797. return ret;
  798. }
  799. /* External EN3 control for TPS65910 LDO only */
  800. if ((tps65910_chip_id(mfd) == TPS65910) &&
  801. (id >= TPS65910_REG_VDIG1)) {
  802. if (ext_sleep_config & TPS65910_SLEEP_CONTROL_EXT_INPUT_EN3)
  803. ret = regmap_set_bits(mfd->regmap,
  804. TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
  805. else
  806. ret = regmap_clear_bits(mfd->regmap,
  807. TPS65910_EN3_LDO_ASS + regoffs, bit_pos);
  808. if (ret < 0) {
  809. dev_err(mfd->dev,
  810. "Error in configuring external control EN3\n");
  811. return ret;
  812. }
  813. }
  814. /* Return if no external control is selected */
  815. if (!(ext_sleep_config & EXT_SLEEP_CONTROL)) {
  816. /* Clear all sleep controls */
  817. ret = regmap_clear_bits(mfd->regmap,
  818. TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
  819. if (!ret)
  820. ret = regmap_clear_bits(mfd->regmap,
  821. TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
  822. if (ret < 0)
  823. dev_err(mfd->dev,
  824. "Error in configuring SLEEP register\n");
  825. return ret;
  826. }
  827. /*
  828. * For regulator that has separate operational and sleep register make
  829. * sure that operational is used and clear sleep register to turn
  830. * regulator off when external control is inactive
  831. */
  832. if ((id == TPS65910_REG_VDD1) ||
  833. (id == TPS65910_REG_VDD2) ||
  834. ((id == TPS65911_REG_VDDCTRL) &&
  835. (tps65910_chip_id(mfd) == TPS65911))) {
  836. int op_reg_add = pmic->get_ctrl_reg(id) + 1;
  837. int sr_reg_add = pmic->get_ctrl_reg(id) + 2;
  838. int opvsel, srvsel;
  839. ret = regmap_read(mfd->regmap, op_reg_add, &opvsel);
  840. if (ret < 0)
  841. return ret;
  842. ret = regmap_read(mfd->regmap, sr_reg_add, &srvsel);
  843. if (ret < 0)
  844. return ret;
  845. if (opvsel & VDD1_OP_CMD_MASK) {
  846. u8 reg_val = srvsel & VDD1_OP_SEL_MASK;
  847. ret = regmap_write(mfd->regmap, op_reg_add, reg_val);
  848. if (ret < 0) {
  849. dev_err(mfd->dev,
  850. "Error in configuring op register\n");
  851. return ret;
  852. }
  853. }
  854. ret = regmap_write(mfd->regmap, sr_reg_add, 0);
  855. if (ret < 0) {
  856. dev_err(mfd->dev, "Error in setting sr register\n");
  857. return ret;
  858. }
  859. }
  860. ret = regmap_clear_bits(mfd->regmap,
  861. TPS65910_SLEEP_KEEP_LDO_ON + regoffs, bit_pos);
  862. if (!ret) {
  863. if (ext_sleep_config & TPS65911_SLEEP_CONTROL_EXT_INPUT_SLEEP)
  864. ret = regmap_set_bits(mfd->regmap,
  865. TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
  866. else
  867. ret = regmap_clear_bits(mfd->regmap,
  868. TPS65910_SLEEP_SET_LDO_OFF + regoffs, bit_pos);
  869. }
  870. if (ret < 0)
  871. dev_err(mfd->dev,
  872. "Error in configuring SLEEP register\n");
  873. return ret;
  874. }
  875. #ifdef CONFIG_OF
  876. static struct of_regulator_match tps65910_matches[] = {
  877. { .name = "vrtc", .driver_data = (void *) &tps65910_regs[0] },
  878. { .name = "vio", .driver_data = (void *) &tps65910_regs[1] },
  879. { .name = "vdd1", .driver_data = (void *) &tps65910_regs[2] },
  880. { .name = "vdd2", .driver_data = (void *) &tps65910_regs[3] },
  881. { .name = "vdd3", .driver_data = (void *) &tps65910_regs[4] },
  882. { .name = "vdig1", .driver_data = (void *) &tps65910_regs[5] },
  883. { .name = "vdig2", .driver_data = (void *) &tps65910_regs[6] },
  884. { .name = "vpll", .driver_data = (void *) &tps65910_regs[7] },
  885. { .name = "vdac", .driver_data = (void *) &tps65910_regs[8] },
  886. { .name = "vaux1", .driver_data = (void *) &tps65910_regs[9] },
  887. { .name = "vaux2", .driver_data = (void *) &tps65910_regs[10] },
  888. { .name = "vaux33", .driver_data = (void *) &tps65910_regs[11] },
  889. { .name = "vmmc", .driver_data = (void *) &tps65910_regs[12] },
  890. { .name = "vbb", .driver_data = (void *) &tps65910_regs[13] },
  891. };
  892. static struct of_regulator_match tps65911_matches[] = {
  893. { .name = "vrtc", .driver_data = (void *) &tps65911_regs[0] },
  894. { .name = "vio", .driver_data = (void *) &tps65911_regs[1] },
  895. { .name = "vdd1", .driver_data = (void *) &tps65911_regs[2] },
  896. { .name = "vdd2", .driver_data = (void *) &tps65911_regs[3] },
  897. { .name = "vddctrl", .driver_data = (void *) &tps65911_regs[4] },
  898. { .name = "ldo1", .driver_data = (void *) &tps65911_regs[5] },
  899. { .name = "ldo2", .driver_data = (void *) &tps65911_regs[6] },
  900. { .name = "ldo3", .driver_data = (void *) &tps65911_regs[7] },
  901. { .name = "ldo4", .driver_data = (void *) &tps65911_regs[8] },
  902. { .name = "ldo5", .driver_data = (void *) &tps65911_regs[9] },
  903. { .name = "ldo6", .driver_data = (void *) &tps65911_regs[10] },
  904. { .name = "ldo7", .driver_data = (void *) &tps65911_regs[11] },
  905. { .name = "ldo8", .driver_data = (void *) &tps65911_regs[12] },
  906. };
  907. static struct tps65910_board *tps65910_parse_dt_reg_data(
  908. struct platform_device *pdev,
  909. struct of_regulator_match **tps65910_reg_matches)
  910. {
  911. struct tps65910_board *pmic_plat_data;
  912. struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
  913. struct device_node *np, *regulators;
  914. struct of_regulator_match *matches;
  915. unsigned int prop;
  916. int idx = 0, ret, count;
  917. pmic_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pmic_plat_data),
  918. GFP_KERNEL);
  919. if (!pmic_plat_data)
  920. return NULL;
  921. np = pdev->dev.parent->of_node;
  922. regulators = of_get_child_by_name(np, "regulators");
  923. if (!regulators) {
  924. dev_err(&pdev->dev, "regulator node not found\n");
  925. return NULL;
  926. }
  927. switch (tps65910_chip_id(tps65910)) {
  928. case TPS65910:
  929. count = ARRAY_SIZE(tps65910_matches);
  930. matches = tps65910_matches;
  931. break;
  932. case TPS65911:
  933. count = ARRAY_SIZE(tps65911_matches);
  934. matches = tps65911_matches;
  935. break;
  936. default:
  937. of_node_put(regulators);
  938. dev_err(&pdev->dev, "Invalid tps chip version\n");
  939. return NULL;
  940. }
  941. ret = of_regulator_match(&pdev->dev, regulators, matches, count);
  942. of_node_put(regulators);
  943. if (ret < 0) {
  944. dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
  945. ret);
  946. return NULL;
  947. }
  948. *tps65910_reg_matches = matches;
  949. for (idx = 0; idx < count; idx++) {
  950. if (!matches[idx].of_node)
  951. continue;
  952. pmic_plat_data->tps65910_pmic_init_data[idx] =
  953. matches[idx].init_data;
  954. ret = of_property_read_u32(matches[idx].of_node,
  955. "ti,regulator-ext-sleep-control", &prop);
  956. if (!ret)
  957. pmic_plat_data->regulator_ext_sleep_control[idx] = prop;
  958. }
  959. return pmic_plat_data;
  960. }
  961. #else
  962. static inline struct tps65910_board *tps65910_parse_dt_reg_data(
  963. struct platform_device *pdev,
  964. struct of_regulator_match **tps65910_reg_matches)
  965. {
  966. *tps65910_reg_matches = NULL;
  967. return NULL;
  968. }
  969. #endif
  970. static int tps65910_probe(struct platform_device *pdev)
  971. {
  972. struct tps65910 *tps65910 = dev_get_drvdata(pdev->dev.parent);
  973. struct regulator_config config = { };
  974. struct tps_info *info;
  975. struct regulator_dev *rdev;
  976. struct tps65910_reg *pmic;
  977. struct tps65910_board *pmic_plat_data;
  978. struct of_regulator_match *tps65910_reg_matches = NULL;
  979. int i, err;
  980. pmic_plat_data = dev_get_platdata(tps65910->dev);
  981. if (!pmic_plat_data && tps65910->dev->of_node)
  982. pmic_plat_data = tps65910_parse_dt_reg_data(pdev,
  983. &tps65910_reg_matches);
  984. if (!pmic_plat_data) {
  985. dev_err(&pdev->dev, "Platform data not found\n");
  986. return -EINVAL;
  987. }
  988. pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
  989. if (!pmic)
  990. return -ENOMEM;
  991. pmic->mfd = tps65910;
  992. platform_set_drvdata(pdev, pmic);
  993. /* Give control of all register to control port */
  994. err = regmap_set_bits(pmic->mfd->regmap, TPS65910_DEVCTRL,
  995. DEVCTRL_SR_CTL_I2C_SEL_MASK);
  996. if (err < 0)
  997. return err;
  998. switch (tps65910_chip_id(tps65910)) {
  999. case TPS65910:
  1000. BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
  1001. pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
  1002. pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
  1003. pmic->ext_sleep_control = tps65910_ext_sleep_control;
  1004. info = tps65910_regs;
  1005. /* Work around silicon erratum SWCZ010: output programmed
  1006. * voltage level can go higher than expected or crash
  1007. * Workaround: use no synchronization of DCDC clocks
  1008. */
  1009. regmap_clear_bits(pmic->mfd->regmap, TPS65910_DCDCCTRL,
  1010. DCDCCTRL_DCDCCKSYNC_MASK);
  1011. break;
  1012. case TPS65911:
  1013. BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
  1014. pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
  1015. pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
  1016. pmic->ext_sleep_control = tps65911_ext_sleep_control;
  1017. info = tps65911_regs;
  1018. break;
  1019. default:
  1020. dev_err(&pdev->dev, "Invalid tps chip version\n");
  1021. return -ENODEV;
  1022. }
  1023. pmic->desc = devm_kcalloc(&pdev->dev,
  1024. pmic->num_regulators,
  1025. sizeof(struct regulator_desc),
  1026. GFP_KERNEL);
  1027. if (!pmic->desc)
  1028. return -ENOMEM;
  1029. pmic->info = devm_kcalloc(&pdev->dev,
  1030. pmic->num_regulators,
  1031. sizeof(struct tps_info *),
  1032. GFP_KERNEL);
  1033. if (!pmic->info)
  1034. return -ENOMEM;
  1035. pmic->rdev = devm_kcalloc(&pdev->dev,
  1036. pmic->num_regulators,
  1037. sizeof(struct regulator_dev *),
  1038. GFP_KERNEL);
  1039. if (!pmic->rdev)
  1040. return -ENOMEM;
  1041. for (i = 0; i < pmic->num_regulators; i++, info++) {
  1042. /* Register the regulators */
  1043. pmic->info[i] = info;
  1044. pmic->desc[i].name = info->name;
  1045. pmic->desc[i].supply_name = info->vin_name;
  1046. pmic->desc[i].id = i;
  1047. pmic->desc[i].n_voltages = info->n_voltages;
  1048. pmic->desc[i].enable_time = info->enable_time_us;
  1049. if (i == TPS65910_REG_VDD1 || i == TPS65910_REG_VDD2) {
  1050. pmic->desc[i].ops = &tps65910_ops_dcdc;
  1051. pmic->desc[i].n_voltages = VDD1_2_NUM_VOLT_FINE *
  1052. VDD1_2_NUM_VOLT_COARSE;
  1053. pmic->desc[i].ramp_delay = 12500;
  1054. } else if (i == TPS65910_REG_VDD3) {
  1055. if (tps65910_chip_id(tps65910) == TPS65910) {
  1056. pmic->desc[i].ops = &tps65910_ops_vdd3;
  1057. pmic->desc[i].volt_table = info->voltage_table;
  1058. } else {
  1059. pmic->desc[i].ops = &tps65910_ops_dcdc;
  1060. pmic->desc[i].ramp_delay = 5000;
  1061. }
  1062. } else if (i == TPS65910_REG_VBB &&
  1063. tps65910_chip_id(tps65910) == TPS65910) {
  1064. pmic->desc[i].ops = &tps65910_ops_vbb;
  1065. pmic->desc[i].volt_table = info->voltage_table;
  1066. } else {
  1067. if (tps65910_chip_id(tps65910) == TPS65910) {
  1068. pmic->desc[i].ops = &tps65910_ops;
  1069. pmic->desc[i].volt_table = info->voltage_table;
  1070. } else {
  1071. pmic->desc[i].ops = &tps65911_ops;
  1072. }
  1073. }
  1074. err = tps65910_set_ext_sleep_config(pmic, i,
  1075. pmic_plat_data->regulator_ext_sleep_control[i]);
  1076. /*
  1077. * Failing on regulator for configuring externally control
  1078. * is not a serious issue, just throw warning.
  1079. */
  1080. if (err < 0)
  1081. dev_warn(tps65910->dev,
  1082. "Failed to initialise ext control config\n");
  1083. pmic->desc[i].type = REGULATOR_VOLTAGE;
  1084. pmic->desc[i].owner = THIS_MODULE;
  1085. pmic->desc[i].enable_reg = pmic->get_ctrl_reg(i);
  1086. pmic->desc[i].enable_mask = TPS65910_SUPPLY_STATE_ENABLED;
  1087. config.dev = tps65910->dev;
  1088. config.init_data = pmic_plat_data->tps65910_pmic_init_data[i];
  1089. config.driver_data = pmic;
  1090. config.regmap = tps65910->regmap;
  1091. if (tps65910_reg_matches)
  1092. config.of_node = tps65910_reg_matches[i].of_node;
  1093. rdev = devm_regulator_register(&pdev->dev, &pmic->desc[i],
  1094. &config);
  1095. if (IS_ERR(rdev))
  1096. return dev_err_probe(tps65910->dev, PTR_ERR(rdev),
  1097. "failed to register %s regulator\n",
  1098. pdev->name);
  1099. /* Save regulator for cleanup */
  1100. pmic->rdev[i] = rdev;
  1101. }
  1102. return 0;
  1103. }
  1104. static void tps65910_shutdown(struct platform_device *pdev)
  1105. {
  1106. struct tps65910_reg *pmic = platform_get_drvdata(pdev);
  1107. int i;
  1108. /*
  1109. * Before bootloader jumps to kernel, it makes sure that required
  1110. * external control signals are in desired state so that given rails
  1111. * can be configure accordingly.
  1112. * If rails are configured to be controlled from external control
  1113. * then before shutting down/rebooting the system, the external
  1114. * control configuration need to be remove from the rails so that
  1115. * its output will be available as per register programming even
  1116. * if external controls are removed. This is require when the POR
  1117. * value of the control signals are not in active state and before
  1118. * bootloader initializes it, the system requires the rail output
  1119. * to be active for booting.
  1120. */
  1121. for (i = 0; i < pmic->num_regulators; i++) {
  1122. int err;
  1123. if (!pmic->rdev[i])
  1124. continue;
  1125. err = tps65910_set_ext_sleep_config(pmic, i, 0);
  1126. if (err < 0)
  1127. dev_err(&pdev->dev,
  1128. "Error in clearing external control\n");
  1129. }
  1130. }
  1131. static struct platform_driver tps65910_driver = {
  1132. .driver = {
  1133. .name = "tps65910-pmic",
  1134. },
  1135. .probe = tps65910_probe,
  1136. .shutdown = tps65910_shutdown,
  1137. };
  1138. static int __init tps65910_init(void)
  1139. {
  1140. return platform_driver_register(&tps65910_driver);
  1141. }
  1142. subsys_initcall(tps65910_init);
  1143. static void __exit tps65910_cleanup(void)
  1144. {
  1145. platform_driver_unregister(&tps65910_driver);
  1146. }
  1147. module_exit(tps65910_cleanup);
  1148. MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>");
  1149. MODULE_DESCRIPTION("TPS65910/TPS65911 voltage regulator driver");
  1150. MODULE_LICENSE("GPL v2");
  1151. MODULE_ALIAS("platform:tps65910-pmic");