tps65910-regulator.c 30 KB

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