ab8500-ext.c 26 KB

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