tps65910-regulator.c 32 KB

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