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