ab8500-ext.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. *
  4. * License Terms: GNU General Public License v2
  5. *
  6. * Authors: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
  7. *
  8. * This file is based on drivers/regulator/ab8500.c
  9. *
  10. * AB8500 external regulators
  11. *
  12. * ab8500-ext supports the following regulators:
  13. * - VextSupply3
  14. */
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/err.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/regulator/driver.h>
  22. #include <linux/regulator/machine.h>
  23. #include <linux/regulator/of_regulator.h>
  24. #include <linux/mfd/abx500.h>
  25. #include <linux/mfd/abx500/ab8500.h>
  26. #include <linux/regulator/ab8500.h>
  27. static struct regulator_consumer_supply ab8500_vaux1_consumers[] = {
  28. /* Main display, u8500 R3 uib */
  29. REGULATOR_SUPPLY("vddi", "mcde_disp_sony_acx424akp.0"),
  30. /* Main display, u8500 uib and ST uib */
  31. REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.0"),
  32. /* Secondary display, ST uib */
  33. REGULATOR_SUPPLY("vdd1", "samsung_s6d16d0.1"),
  34. /* SFH7741 proximity sensor */
  35. REGULATOR_SUPPLY("vcc", "gpio-keys.0"),
  36. /* BH1780GLS ambient light sensor */
  37. REGULATOR_SUPPLY("vcc", "2-0029"),
  38. /* lsm303dlh accelerometer */
  39. REGULATOR_SUPPLY("vdd", "2-0018"),
  40. /* lsm303dlhc accelerometer */
  41. REGULATOR_SUPPLY("vdd", "2-0019"),
  42. /* lsm303dlh magnetometer */
  43. REGULATOR_SUPPLY("vdd", "2-001e"),
  44. /* Rohm BU21013 Touchscreen devices */
  45. REGULATOR_SUPPLY("avdd", "3-005c"),
  46. REGULATOR_SUPPLY("avdd", "3-005d"),
  47. /* Synaptics RMI4 Touchscreen device */
  48. REGULATOR_SUPPLY("vdd", "3-004b"),
  49. /* L3G4200D Gyroscope device */
  50. REGULATOR_SUPPLY("vdd", "2-0068"),
  51. /* Ambient light sensor device */
  52. REGULATOR_SUPPLY("vdd", "3-0029"),
  53. /* Pressure sensor device */
  54. REGULATOR_SUPPLY("vdd", "2-005c"),
  55. /* Cypress TrueTouch Touchscreen device */
  56. REGULATOR_SUPPLY("vcpin", "spi8.0"),
  57. /* Camera device */
  58. REGULATOR_SUPPLY("vaux12v5", "mmio_camera"),
  59. };
  60. static struct regulator_consumer_supply ab8500_vaux2_consumers[] = {
  61. /* On-board eMMC power */
  62. REGULATOR_SUPPLY("vmmc", "sdi4"),
  63. /* AB8500 audio codec */
  64. REGULATOR_SUPPLY("vcc-N2158", "ab8500-codec.0"),
  65. /* AB8500 accessory detect 1 */
  66. REGULATOR_SUPPLY("vcc-N2158", "ab8500-acc-det.0"),
  67. /* AB8500 Tv-out device */
  68. REGULATOR_SUPPLY("vcc-N2158", "mcde_tv_ab8500.4"),
  69. /* AV8100 HDMI device */
  70. REGULATOR_SUPPLY("vcc-N2158", "av8100_hdmi.3"),
  71. };
  72. static struct regulator_consumer_supply ab8500_vaux3_consumers[] = {
  73. REGULATOR_SUPPLY("v-SD-STM", "stm"),
  74. /* External MMC slot power */
  75. REGULATOR_SUPPLY("vmmc", "sdi0"),
  76. };
  77. static struct regulator_consumer_supply ab8500_vtvout_consumers[] = {
  78. /* TV-out DENC supply */
  79. REGULATOR_SUPPLY("vtvout", "ab8500-denc.0"),
  80. /* Internal general-purpose ADC */
  81. REGULATOR_SUPPLY("vddadc", "ab8500-gpadc.0"),
  82. /* ADC for charger */
  83. REGULATOR_SUPPLY("vddadc", "ab8500-charger.0"),
  84. /* AB8500 Tv-out device */
  85. REGULATOR_SUPPLY("vtvout", "mcde_tv_ab8500.4"),
  86. };
  87. static struct regulator_consumer_supply ab8500_vaud_consumers[] = {
  88. /* AB8500 audio-codec main supply */
  89. REGULATOR_SUPPLY("vaud", "ab8500-codec.0"),
  90. };
  91. static struct regulator_consumer_supply ab8500_vamic1_consumers[] = {
  92. /* AB8500 audio-codec Mic1 supply */
  93. REGULATOR_SUPPLY("vamic1", "ab8500-codec.0"),
  94. };
  95. static struct regulator_consumer_supply ab8500_vamic2_consumers[] = {
  96. /* AB8500 audio-codec Mic2 supply */
  97. REGULATOR_SUPPLY("vamic2", "ab8500-codec.0"),
  98. };
  99. static struct regulator_consumer_supply ab8500_vdmic_consumers[] = {
  100. /* AB8500 audio-codec DMic supply */
  101. REGULATOR_SUPPLY("vdmic", "ab8500-codec.0"),
  102. };
  103. static struct regulator_consumer_supply ab8500_vintcore_consumers[] = {
  104. /* SoC core supply, no device */
  105. REGULATOR_SUPPLY("v-intcore", NULL),
  106. /* USB Transceiver */
  107. REGULATOR_SUPPLY("vddulpivio18", "ab8500-usb.0"),
  108. /* Handled by abx500 clk driver */
  109. REGULATOR_SUPPLY("v-intcore", "abx500-clk.0"),
  110. };
  111. static struct regulator_consumer_supply ab8500_vana_consumers[] = {
  112. /* DB8500 DSI */
  113. REGULATOR_SUPPLY("vdddsi1v2", "mcde"),
  114. REGULATOR_SUPPLY("vdddsi1v2", "b2r2_core"),
  115. REGULATOR_SUPPLY("vdddsi1v2", "b2r2_1_core"),
  116. REGULATOR_SUPPLY("vdddsi1v2", "dsilink.0"),
  117. REGULATOR_SUPPLY("vdddsi1v2", "dsilink.1"),
  118. REGULATOR_SUPPLY("vdddsi1v2", "dsilink.2"),
  119. /* DB8500 CSI */
  120. REGULATOR_SUPPLY("vddcsi1v2", "mmio_camera"),
  121. };
  122. /* ab8500 regulator register initialization */
  123. static struct ab8500_regulator_reg_init ab8500_reg_init[] = {
  124. /*
  125. * VanaRequestCtrl = HP/LP depending on VxRequest
  126. * VextSupply1RequestCtrl = HP/LP depending on VxRequest
  127. */
  128. INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL2, 0xf0, 0x00),
  129. /*
  130. * VextSupply2RequestCtrl = HP/LP depending on VxRequest
  131. * VextSupply3RequestCtrl = HP/LP depending on VxRequest
  132. * Vaux1RequestCtrl = HP/LP depending on VxRequest
  133. * Vaux2RequestCtrl = HP/LP depending on VxRequest
  134. */
  135. INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL3, 0xff, 0x00),
  136. /*
  137. * Vaux3RequestCtrl = HP/LP depending on VxRequest
  138. * SwHPReq = Control through SWValid disabled
  139. */
  140. INIT_REGULATOR_REGISTER(AB8500_REGUREQUESTCTRL4, 0x07, 0x00),
  141. /*
  142. * VanaSysClkReq1HPValid = disabled
  143. * Vaux1SysClkReq1HPValid = disabled
  144. * Vaux2SysClkReq1HPValid = disabled
  145. * Vaux3SysClkReq1HPValid = disabled
  146. */
  147. INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID1, 0xe8, 0x00),
  148. /*
  149. * VextSupply1SysClkReq1HPValid = disabled
  150. * VextSupply2SysClkReq1HPValid = disabled
  151. * VextSupply3SysClkReq1HPValid = SysClkReq1 controlled
  152. */
  153. INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQ1HPVALID2, 0x70, 0x40),
  154. /*
  155. * VanaHwHPReq1Valid = disabled
  156. * Vaux1HwHPreq1Valid = disabled
  157. * Vaux2HwHPReq1Valid = disabled
  158. * Vaux3HwHPReqValid = disabled
  159. */
  160. INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID1, 0xe8, 0x00),
  161. /*
  162. * VextSupply1HwHPReq1Valid = disabled
  163. * VextSupply2HwHPReq1Valid = disabled
  164. * VextSupply3HwHPReq1Valid = disabled
  165. */
  166. INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ1VALID2, 0x07, 0x00),
  167. /*
  168. * VanaHwHPReq2Valid = disabled
  169. * Vaux1HwHPReq2Valid = disabled
  170. * Vaux2HwHPReq2Valid = disabled
  171. * Vaux3HwHPReq2Valid = disabled
  172. */
  173. INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID1, 0xe8, 0x00),
  174. /*
  175. * VextSupply1HwHPReq2Valid = disabled
  176. * VextSupply2HwHPReq2Valid = disabled
  177. * VextSupply3HwHPReq2Valid = HWReq2 controlled
  178. */
  179. INIT_REGULATOR_REGISTER(AB8500_REGUHWHPREQ2VALID2, 0x07, 0x04),
  180. /*
  181. * VanaSwHPReqValid = disabled
  182. * Vaux1SwHPReqValid = disabled
  183. */
  184. INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID1, 0xa0, 0x00),
  185. /*
  186. * Vaux2SwHPReqValid = disabled
  187. * Vaux3SwHPReqValid = disabled
  188. * VextSupply1SwHPReqValid = disabled
  189. * VextSupply2SwHPReqValid = disabled
  190. * VextSupply3SwHPReqValid = disabled
  191. */
  192. INIT_REGULATOR_REGISTER(AB8500_REGUSWHPREQVALID2, 0x1f, 0x00),
  193. /*
  194. * SysClkReq2Valid1 = SysClkReq2 controlled
  195. * SysClkReq3Valid1 = disabled
  196. * SysClkReq4Valid1 = SysClkReq4 controlled
  197. * SysClkReq5Valid1 = disabled
  198. * SysClkReq6Valid1 = SysClkReq6 controlled
  199. * SysClkReq7Valid1 = disabled
  200. * SysClkReq8Valid1 = disabled
  201. */
  202. INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID1, 0xfe, 0x2a),
  203. /*
  204. * SysClkReq2Valid2 = disabled
  205. * SysClkReq3Valid2 = disabled
  206. * SysClkReq4Valid2 = disabled
  207. * SysClkReq5Valid2 = disabled
  208. * SysClkReq6Valid2 = SysClkReq6 controlled
  209. * SysClkReq7Valid2 = disabled
  210. * SysClkReq8Valid2 = disabled
  211. */
  212. INIT_REGULATOR_REGISTER(AB8500_REGUSYSCLKREQVALID2, 0xfe, 0x20),
  213. /*
  214. * VTVoutEna = disabled
  215. * Vintcore12Ena = disabled
  216. * Vintcore12Sel = 1.25 V
  217. * Vintcore12LP = inactive (HP)
  218. * VTVoutLP = inactive (HP)
  219. */
  220. INIT_REGULATOR_REGISTER(AB8500_REGUMISC1, 0xfe, 0x10),
  221. /*
  222. * VaudioEna = disabled
  223. * VdmicEna = disabled
  224. * Vamic1Ena = disabled
  225. * Vamic2Ena = disabled
  226. */
  227. INIT_REGULATOR_REGISTER(AB8500_VAUDIOSUPPLY, 0x1e, 0x00),
  228. /*
  229. * Vamic1_dzout = high-Z when Vamic1 is disabled
  230. * Vamic2_dzout = high-Z when Vamic2 is disabled
  231. */
  232. INIT_REGULATOR_REGISTER(AB8500_REGUCTRL1VAMIC, 0x03, 0x00),
  233. /*
  234. * VPll = Hw controlled (NOTE! PRCMU bits)
  235. * VanaRegu = force off
  236. */
  237. INIT_REGULATOR_REGISTER(AB8500_VPLLVANAREGU, 0x0f, 0x02),
  238. /*
  239. * VrefDDREna = disabled
  240. * VrefDDRSleepMode = inactive (no pulldown)
  241. */
  242. INIT_REGULATOR_REGISTER(AB8500_VREFDDR, 0x03, 0x00),
  243. /*
  244. * VextSupply1Regu = force LP
  245. * VextSupply2Regu = force OFF
  246. * VextSupply3Regu = force HP (-> STBB2=LP and TPS=LP)
  247. * ExtSupply2Bypass = ExtSupply12LPn ball is 0 when Ena is 0
  248. * ExtSupply3Bypass = ExtSupply3LPn ball is 0 when Ena is 0
  249. */
  250. INIT_REGULATOR_REGISTER(AB8500_EXTSUPPLYREGU, 0xff, 0x13),
  251. /*
  252. * Vaux1Regu = force HP
  253. * Vaux2Regu = force off
  254. */
  255. INIT_REGULATOR_REGISTER(AB8500_VAUX12REGU, 0x0f, 0x01),
  256. /*
  257. * Vaux3Regu = force off
  258. */
  259. INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3REGU, 0x03, 0x00),
  260. /*
  261. * Vaux1Sel = 2.8 V
  262. */
  263. INIT_REGULATOR_REGISTER(AB8500_VAUX1SEL, 0x0f, 0x0C),
  264. /*
  265. * Vaux2Sel = 2.9 V
  266. */
  267. INIT_REGULATOR_REGISTER(AB8500_VAUX2SEL, 0x0f, 0x0d),
  268. /*
  269. * Vaux3Sel = 2.91 V
  270. */
  271. INIT_REGULATOR_REGISTER(AB8500_VRF1VAUX3SEL, 0x07, 0x07),
  272. /*
  273. * VextSupply12LP = disabled (no LP)
  274. */
  275. INIT_REGULATOR_REGISTER(AB8500_REGUCTRL2SPARE, 0x01, 0x00),
  276. /*
  277. * Vaux1Disch = short discharge time
  278. * Vaux2Disch = short discharge time
  279. * Vaux3Disch = short discharge time
  280. * Vintcore12Disch = short discharge time
  281. * VTVoutDisch = short discharge time
  282. * VaudioDisch = short discharge time
  283. */
  284. INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH, 0xfc, 0x00),
  285. /*
  286. * VanaDisch = short discharge time
  287. * VdmicPullDownEna = pulldown disabled when Vdmic is disabled
  288. * VdmicDisch = short discharge time
  289. */
  290. INIT_REGULATOR_REGISTER(AB8500_REGUCTRLDISCH2, 0x16, 0x00),
  291. };
  292. /* AB8500 regulators */
  293. static struct regulator_init_data ab8500_regulators[AB8500_NUM_REGULATORS] = {
  294. /* supplies to the display/camera */
  295. [AB8500_LDO_AUX1] = {
  296. .supply_regulator = "ab8500-ext-supply3",
  297. .constraints = {
  298. .name = "V-DISPLAY",
  299. .min_uV = 2800000,
  300. .max_uV = 3300000,
  301. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  302. REGULATOR_CHANGE_STATUS,
  303. .boot_on = 1, /* display is on at boot */
  304. },
  305. .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux1_consumers),
  306. .consumer_supplies = ab8500_vaux1_consumers,
  307. },
  308. /* supplies to the on-board eMMC */
  309. [AB8500_LDO_AUX2] = {
  310. .supply_regulator = "ab8500-ext-supply3",
  311. .constraints = {
  312. .name = "V-eMMC1",
  313. .min_uV = 1100000,
  314. .max_uV = 3300000,
  315. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  316. REGULATOR_CHANGE_STATUS |
  317. REGULATOR_CHANGE_MODE,
  318. .valid_modes_mask = REGULATOR_MODE_NORMAL |
  319. REGULATOR_MODE_IDLE,
  320. },
  321. .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux2_consumers),
  322. .consumer_supplies = ab8500_vaux2_consumers,
  323. },
  324. /* supply for VAUX3, supplies to SDcard slots */
  325. [AB8500_LDO_AUX3] = {
  326. .supply_regulator = "ab8500-ext-supply3",
  327. .constraints = {
  328. .name = "V-MMC-SD",
  329. .min_uV = 1100000,
  330. .max_uV = 3300000,
  331. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  332. REGULATOR_CHANGE_STATUS |
  333. REGULATOR_CHANGE_MODE,
  334. .valid_modes_mask = REGULATOR_MODE_NORMAL |
  335. REGULATOR_MODE_IDLE,
  336. },
  337. .num_consumer_supplies = ARRAY_SIZE(ab8500_vaux3_consumers),
  338. .consumer_supplies = ab8500_vaux3_consumers,
  339. },
  340. /* supply for tvout, gpadc, TVOUT LDO */
  341. [AB8500_LDO_TVOUT] = {
  342. .constraints = {
  343. .name = "V-TVOUT",
  344. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  345. },
  346. .num_consumer_supplies = ARRAY_SIZE(ab8500_vtvout_consumers),
  347. .consumer_supplies = ab8500_vtvout_consumers,
  348. },
  349. /* supply for ab8500-vaudio, VAUDIO LDO */
  350. [AB8500_LDO_AUDIO] = {
  351. .constraints = {
  352. .name = "V-AUD",
  353. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  354. },
  355. .num_consumer_supplies = ARRAY_SIZE(ab8500_vaud_consumers),
  356. .consumer_supplies = ab8500_vaud_consumers,
  357. },
  358. /* supply for v-anamic1 VAMic1-LDO */
  359. [AB8500_LDO_ANAMIC1] = {
  360. .constraints = {
  361. .name = "V-AMIC1",
  362. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  363. },
  364. .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic1_consumers),
  365. .consumer_supplies = ab8500_vamic1_consumers,
  366. },
  367. /* supply for v-amic2, VAMIC2 LDO, reuse constants for AMIC1 */
  368. [AB8500_LDO_ANAMIC2] = {
  369. .constraints = {
  370. .name = "V-AMIC2",
  371. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  372. },
  373. .num_consumer_supplies = ARRAY_SIZE(ab8500_vamic2_consumers),
  374. .consumer_supplies = ab8500_vamic2_consumers,
  375. },
  376. /* supply for v-dmic, VDMIC LDO */
  377. [AB8500_LDO_DMIC] = {
  378. .constraints = {
  379. .name = "V-DMIC",
  380. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  381. },
  382. .num_consumer_supplies = ARRAY_SIZE(ab8500_vdmic_consumers),
  383. .consumer_supplies = ab8500_vdmic_consumers,
  384. },
  385. /* supply for v-intcore12, VINTCORE12 LDO */
  386. [AB8500_LDO_INTCORE] = {
  387. .constraints = {
  388. .name = "V-INTCORE",
  389. .min_uV = 1250000,
  390. .max_uV = 1350000,
  391. .input_uV = 1800000,
  392. .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE |
  393. REGULATOR_CHANGE_STATUS |
  394. REGULATOR_CHANGE_MODE |
  395. REGULATOR_CHANGE_DRMS,
  396. .valid_modes_mask = REGULATOR_MODE_NORMAL |
  397. REGULATOR_MODE_IDLE,
  398. },
  399. .num_consumer_supplies = ARRAY_SIZE(ab8500_vintcore_consumers),
  400. .consumer_supplies = ab8500_vintcore_consumers,
  401. },
  402. /* supply for U8500 CSI-DSI, VANA LDO */
  403. [AB8500_LDO_ANA] = {
  404. .constraints = {
  405. .name = "V-CSI-DSI",
  406. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  407. },
  408. .num_consumer_supplies = ARRAY_SIZE(ab8500_vana_consumers),
  409. .consumer_supplies = ab8500_vana_consumers,
  410. },
  411. };
  412. /* supply for VextSupply3 */
  413. static struct regulator_consumer_supply ab8500_ext_supply3_consumers[] = {
  414. /* SIM supply for 3 V SIM cards */
  415. REGULATOR_SUPPLY("vinvsim", "sim-detect.0"),
  416. };
  417. /*
  418. * AB8500 external regulators
  419. */
  420. static struct regulator_init_data ab8500_ext_regulators[] = {
  421. /* fixed Vbat supplies VSMPS1_EXT_1V8 */
  422. [AB8500_EXT_SUPPLY1] = {
  423. .constraints = {
  424. .name = "ab8500-ext-supply1",
  425. .min_uV = 1800000,
  426. .max_uV = 1800000,
  427. .initial_mode = REGULATOR_MODE_IDLE,
  428. .boot_on = 1,
  429. .always_on = 1,
  430. },
  431. },
  432. /* fixed Vbat supplies VSMPS2_EXT_1V36 and VSMPS5_EXT_1V15 */
  433. [AB8500_EXT_SUPPLY2] = {
  434. .constraints = {
  435. .name = "ab8500-ext-supply2",
  436. .min_uV = 1360000,
  437. .max_uV = 1360000,
  438. },
  439. },
  440. /* fixed Vbat supplies VSMPS3_EXT_3V4 and VSMPS4_EXT_3V4 */
  441. [AB8500_EXT_SUPPLY3] = {
  442. .constraints = {
  443. .name = "ab8500-ext-supply3",
  444. .min_uV = 3400000,
  445. .max_uV = 3400000,
  446. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  447. .boot_on = 1,
  448. },
  449. .num_consumer_supplies =
  450. ARRAY_SIZE(ab8500_ext_supply3_consumers),
  451. .consumer_supplies = ab8500_ext_supply3_consumers,
  452. },
  453. };
  454. static struct ab8500_regulator_platform_data ab8500_regulator_plat_data = {
  455. .reg_init = ab8500_reg_init,
  456. .num_reg_init = ARRAY_SIZE(ab8500_reg_init),
  457. .regulator = ab8500_regulators,
  458. .num_regulator = ARRAY_SIZE(ab8500_regulators),
  459. .ext_regulator = ab8500_ext_regulators,
  460. .num_ext_regulator = ARRAY_SIZE(ab8500_ext_regulators),
  461. };
  462. /**
  463. * struct ab8500_ext_regulator_info - ab8500 regulator information
  464. * @dev: device pointer
  465. * @desc: regulator description
  466. * @rdev: regulator device
  467. * @cfg: regulator configuration (extension of regulator FW configuration)
  468. * @update_bank: bank to control on/off
  469. * @update_reg: register to control on/off
  470. * @update_mask: mask to enable/disable and set mode of regulator
  471. * @update_val: bits holding the regulator current mode
  472. * @update_val_hp: bits to set EN pin active (LPn pin deactive)
  473. * normally this means high power mode
  474. * @update_val_lp: bits to set EN pin active and LPn pin active
  475. * normally this means low power mode
  476. * @update_val_hw: bits to set regulator pins in HW control
  477. * SysClkReq pins and logic will choose mode
  478. */
  479. struct ab8500_ext_regulator_info {
  480. struct device *dev;
  481. struct regulator_desc desc;
  482. struct regulator_dev *rdev;
  483. struct ab8500_ext_regulator_cfg *cfg;
  484. u8 update_bank;
  485. u8 update_reg;
  486. u8 update_mask;
  487. u8 update_val;
  488. u8 update_val_hp;
  489. u8 update_val_lp;
  490. u8 update_val_hw;
  491. };
  492. static int ab8500_ext_regulator_enable(struct regulator_dev *rdev)
  493. {
  494. int ret;
  495. struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
  496. u8 regval;
  497. if (info == NULL) {
  498. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  499. return -EINVAL;
  500. }
  501. /*
  502. * To satisfy both HW high power request and SW request, the regulator
  503. * must be on in high power.
  504. */
  505. if (info->cfg && info->cfg->hwreq)
  506. regval = info->update_val_hp;
  507. else
  508. regval = info->update_val;
  509. ret = abx500_mask_and_set_register_interruptible(info->dev,
  510. info->update_bank, info->update_reg,
  511. info->update_mask, regval);
  512. if (ret < 0) {
  513. dev_err(rdev_get_dev(info->rdev),
  514. "couldn't set enable bits for regulator\n");
  515. return ret;
  516. }
  517. dev_dbg(rdev_get_dev(rdev),
  518. "%s-enable (bank, reg, mask, value): 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
  519. info->desc.name, info->update_bank, info->update_reg,
  520. info->update_mask, regval);
  521. return 0;
  522. }
  523. static int ab8500_ext_regulator_disable(struct regulator_dev *rdev)
  524. {
  525. int ret;
  526. struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
  527. u8 regval;
  528. if (info == NULL) {
  529. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  530. return -EINVAL;
  531. }
  532. /*
  533. * Set the regulator in HW request mode if configured
  534. */
  535. if (info->cfg && info->cfg->hwreq)
  536. regval = info->update_val_hw;
  537. else
  538. regval = 0;
  539. ret = abx500_mask_and_set_register_interruptible(info->dev,
  540. info->update_bank, info->update_reg,
  541. info->update_mask, regval);
  542. if (ret < 0) {
  543. dev_err(rdev_get_dev(info->rdev),
  544. "couldn't set disable bits for regulator\n");
  545. return ret;
  546. }
  547. dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):"
  548. " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
  549. info->desc.name, info->update_bank, info->update_reg,
  550. info->update_mask, regval);
  551. return 0;
  552. }
  553. static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev)
  554. {
  555. int ret;
  556. struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
  557. u8 regval;
  558. if (info == NULL) {
  559. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  560. return -EINVAL;
  561. }
  562. ret = abx500_get_register_interruptible(info->dev,
  563. info->update_bank, info->update_reg, &regval);
  564. if (ret < 0) {
  565. dev_err(rdev_get_dev(rdev),
  566. "couldn't read 0x%x register\n", info->update_reg);
  567. return ret;
  568. }
  569. dev_dbg(rdev_get_dev(rdev), "%s-is_enabled (bank, reg, mask, value):"
  570. " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
  571. info->desc.name, info->update_bank, info->update_reg,
  572. info->update_mask, regval);
  573. if (((regval & info->update_mask) == info->update_val_lp) ||
  574. ((regval & info->update_mask) == info->update_val_hp))
  575. return 1;
  576. else
  577. return 0;
  578. }
  579. static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev,
  580. unsigned int mode)
  581. {
  582. int ret = 0;
  583. struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
  584. u8 regval;
  585. if (info == NULL) {
  586. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  587. return -EINVAL;
  588. }
  589. switch (mode) {
  590. case REGULATOR_MODE_NORMAL:
  591. regval = info->update_val_hp;
  592. break;
  593. case REGULATOR_MODE_IDLE:
  594. regval = info->update_val_lp;
  595. break;
  596. default:
  597. return -EINVAL;
  598. }
  599. /* If regulator is enabled and info->cfg->hwreq is set, the regulator
  600. must be on in high power, so we don't need to write the register with
  601. the same value.
  602. */
  603. if (ab8500_ext_regulator_is_enabled(rdev) &&
  604. !(info->cfg && info->cfg->hwreq)) {
  605. ret = abx500_mask_and_set_register_interruptible(info->dev,
  606. info->update_bank, info->update_reg,
  607. info->update_mask, regval);
  608. if (ret < 0) {
  609. dev_err(rdev_get_dev(rdev),
  610. "Could not set regulator mode.\n");
  611. return ret;
  612. }
  613. dev_dbg(rdev_get_dev(rdev),
  614. "%s-set_mode (bank, reg, mask, value): "
  615. "0x%x, 0x%x, 0x%x, 0x%x\n",
  616. info->desc.name, info->update_bank, info->update_reg,
  617. info->update_mask, regval);
  618. }
  619. info->update_val = regval;
  620. return 0;
  621. }
  622. static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev)
  623. {
  624. struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev);
  625. int ret;
  626. if (info == NULL) {
  627. dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
  628. return -EINVAL;
  629. }
  630. if (info->update_val == info->update_val_hp)
  631. ret = REGULATOR_MODE_NORMAL;
  632. else if (info->update_val == info->update_val_lp)
  633. ret = REGULATOR_MODE_IDLE;
  634. else
  635. ret = -EINVAL;
  636. return ret;
  637. }
  638. static int ab8500_ext_set_voltage(struct regulator_dev *rdev, int min_uV,
  639. int max_uV, unsigned *selector)
  640. {
  641. struct regulation_constraints *regu_constraints = rdev->constraints;
  642. if (!regu_constraints) {
  643. dev_err(rdev_get_dev(rdev), "No regulator constraints\n");
  644. return -EINVAL;
  645. }
  646. if (regu_constraints->min_uV == min_uV &&
  647. regu_constraints->max_uV == max_uV)
  648. return 0;
  649. dev_err(rdev_get_dev(rdev),
  650. "Requested min %duV max %duV != constrained min %duV max %duV\n",
  651. min_uV, max_uV,
  652. regu_constraints->min_uV, regu_constraints->max_uV);
  653. return -EINVAL;
  654. }
  655. static int ab8500_ext_list_voltage(struct regulator_dev *rdev,
  656. unsigned selector)
  657. {
  658. struct regulation_constraints *regu_constraints = rdev->constraints;
  659. if (regu_constraints == NULL) {
  660. dev_err(rdev_get_dev(rdev), "regulator constraints null pointer\n");
  661. return -EINVAL;
  662. }
  663. /* return the uV for the fixed regulators */
  664. if (regu_constraints->min_uV && regu_constraints->max_uV) {
  665. if (regu_constraints->min_uV == regu_constraints->max_uV)
  666. return regu_constraints->min_uV;
  667. }
  668. return -EINVAL;
  669. }
  670. static struct regulator_ops ab8500_ext_regulator_ops = {
  671. .enable = ab8500_ext_regulator_enable,
  672. .disable = ab8500_ext_regulator_disable,
  673. .is_enabled = ab8500_ext_regulator_is_enabled,
  674. .set_mode = ab8500_ext_regulator_set_mode,
  675. .get_mode = ab8500_ext_regulator_get_mode,
  676. .set_voltage = ab8500_ext_set_voltage,
  677. .list_voltage = ab8500_ext_list_voltage,
  678. };
  679. static struct ab8500_ext_regulator_info
  680. ab8500_ext_regulator_info[AB8500_NUM_EXT_REGULATORS] = {
  681. [AB8500_EXT_SUPPLY1] = {
  682. .desc = {
  683. .name = "VEXTSUPPLY1",
  684. .ops = &ab8500_ext_regulator_ops,
  685. .type = REGULATOR_VOLTAGE,
  686. .id = AB8500_EXT_SUPPLY1,
  687. .owner = THIS_MODULE,
  688. .n_voltages = 1,
  689. },
  690. .update_bank = 0x04,
  691. .update_reg = 0x08,
  692. .update_mask = 0x03,
  693. .update_val = 0x01,
  694. .update_val_hp = 0x01,
  695. .update_val_lp = 0x03,
  696. .update_val_hw = 0x02,
  697. },
  698. [AB8500_EXT_SUPPLY2] = {
  699. .desc = {
  700. .name = "VEXTSUPPLY2",
  701. .ops = &ab8500_ext_regulator_ops,
  702. .type = REGULATOR_VOLTAGE,
  703. .id = AB8500_EXT_SUPPLY2,
  704. .owner = THIS_MODULE,
  705. .n_voltages = 1,
  706. },
  707. .update_bank = 0x04,
  708. .update_reg = 0x08,
  709. .update_mask = 0x0c,
  710. .update_val = 0x04,
  711. .update_val_hp = 0x04,
  712. .update_val_lp = 0x0c,
  713. .update_val_hw = 0x08,
  714. },
  715. [AB8500_EXT_SUPPLY3] = {
  716. .desc = {
  717. .name = "VEXTSUPPLY3",
  718. .ops = &ab8500_ext_regulator_ops,
  719. .type = REGULATOR_VOLTAGE,
  720. .id = AB8500_EXT_SUPPLY3,
  721. .owner = THIS_MODULE,
  722. .n_voltages = 1,
  723. },
  724. .update_bank = 0x04,
  725. .update_reg = 0x08,
  726. .update_mask = 0x30,
  727. .update_val = 0x10,
  728. .update_val_hp = 0x10,
  729. .update_val_lp = 0x30,
  730. .update_val_hw = 0x20,
  731. },
  732. };
  733. static struct of_regulator_match ab8500_ext_regulator_match[] = {
  734. { .name = "ab8500_ext1", .driver_data = (void *) AB8500_EXT_SUPPLY1, },
  735. { .name = "ab8500_ext2", .driver_data = (void *) AB8500_EXT_SUPPLY2, },
  736. { .name = "ab8500_ext3", .driver_data = (void *) AB8500_EXT_SUPPLY3, },
  737. };
  738. static int ab8500_ext_regulator_probe(struct platform_device *pdev)
  739. {
  740. struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
  741. struct ab8500_regulator_platform_data *pdata = &ab8500_regulator_plat_data;
  742. struct device_node *np = pdev->dev.of_node;
  743. struct regulator_config config = { };
  744. int i, err;
  745. if (np) {
  746. err = of_regulator_match(&pdev->dev, np,
  747. ab8500_ext_regulator_match,
  748. ARRAY_SIZE(ab8500_ext_regulator_match));
  749. if (err < 0) {
  750. dev_err(&pdev->dev,
  751. "Error parsing regulator init data: %d\n", err);
  752. return err;
  753. }
  754. }
  755. if (!ab8500) {
  756. dev_err(&pdev->dev, "null mfd parent\n");
  757. return -EINVAL;
  758. }
  759. /* make sure the platform data has the correct size */
  760. if (pdata->num_ext_regulator != ARRAY_SIZE(ab8500_ext_regulator_info)) {
  761. dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
  762. return -EINVAL;
  763. }
  764. /* check for AB8500 2.x */
  765. if (is_ab8500_2p0_or_earlier(ab8500)) {
  766. struct ab8500_ext_regulator_info *info;
  767. /* VextSupply3LPn is inverted on AB8500 2.x */
  768. info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3];
  769. info->update_val = 0x30;
  770. info->update_val_hp = 0x30;
  771. info->update_val_lp = 0x10;
  772. }
  773. /* register all regulators */
  774. for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) {
  775. struct ab8500_ext_regulator_info *info = NULL;
  776. /* assign per-regulator data */
  777. info = &ab8500_ext_regulator_info[i];
  778. info->dev = &pdev->dev;
  779. info->cfg = (struct ab8500_ext_regulator_cfg *)
  780. pdata->ext_regulator[i].driver_data;
  781. config.dev = &pdev->dev;
  782. config.driver_data = info;
  783. config.of_node = ab8500_ext_regulator_match[i].of_node;
  784. config.init_data = (np) ?
  785. ab8500_ext_regulator_match[i].init_data :
  786. &pdata->ext_regulator[i];
  787. /* register regulator with framework */
  788. info->rdev = devm_regulator_register(&pdev->dev, &info->desc,
  789. &config);
  790. if (IS_ERR(info->rdev)) {
  791. err = PTR_ERR(info->rdev);
  792. dev_err(&pdev->dev, "failed to register regulator %s\n",
  793. info->desc.name);
  794. return err;
  795. }
  796. dev_dbg(rdev_get_dev(info->rdev),
  797. "%s-probed\n", info->desc.name);
  798. }
  799. return 0;
  800. }
  801. static struct platform_driver ab8500_ext_regulator_driver = {
  802. .probe = ab8500_ext_regulator_probe,
  803. .driver = {
  804. .name = "ab8500-ext-regulator",
  805. },
  806. };
  807. static int __init ab8500_ext_regulator_init(void)
  808. {
  809. int ret;
  810. ret = platform_driver_register(&ab8500_ext_regulator_driver);
  811. if (ret)
  812. pr_err("Failed to register ab8500 ext regulator: %d\n", ret);
  813. return ret;
  814. }
  815. subsys_initcall(ab8500_ext_regulator_init);
  816. static void __exit ab8500_ext_regulator_exit(void)
  817. {
  818. platform_driver_unregister(&ab8500_ext_regulator_driver);
  819. }
  820. module_exit(ab8500_ext_regulator_exit);
  821. MODULE_LICENSE("GPL v2");
  822. MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
  823. MODULE_DESCRIPTION("AB8500 external regulator driver");
  824. MODULE_ALIAS("platform:ab8500-ext-regulator");