axp20x-regulator.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. /*
  2. * AXP20x regulators driver.
  3. *
  4. * Copyright (C) 2013 Carlo Caione <carlo@caione.org>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file "COPYING" in the main directory of this
  8. * archive for more details.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/bitops.h>
  16. #include <linux/delay.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/mfd/axp20x.h>
  20. #include <linux/module.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/regmap.h>
  25. #include <linux/regulator/driver.h>
  26. #include <linux/regulator/machine.h>
  27. #include <linux/regulator/of_regulator.h>
  28. #define AXP20X_GPIO0_FUNC_MASK GENMASK(3, 0)
  29. #define AXP20X_GPIO1_FUNC_MASK GENMASK(3, 0)
  30. #define AXP20X_IO_ENABLED 0x03
  31. #define AXP20X_IO_DISABLED 0x07
  32. #define AXP20X_WORKMODE_DCDC2_MASK BIT_MASK(2)
  33. #define AXP20X_WORKMODE_DCDC3_MASK BIT_MASK(1)
  34. #define AXP20X_FREQ_DCDC_MASK GENMASK(3, 0)
  35. #define AXP20X_VBUS_IPSOUT_MGMT_MASK BIT_MASK(2)
  36. #define AXP20X_DCDC2_V_OUT_MASK GENMASK(5, 0)
  37. #define AXP20X_DCDC3_V_OUT_MASK GENMASK(7, 0)
  38. #define AXP20X_LDO2_V_OUT_MASK GENMASK(7, 4)
  39. #define AXP20X_LDO3_V_OUT_MASK GENMASK(6, 0)
  40. #define AXP20X_LDO4_V_OUT_MASK GENMASK(3, 0)
  41. #define AXP20X_LDO5_V_OUT_MASK GENMASK(7, 4)
  42. #define AXP20X_PWR_OUT_EXTEN_MASK BIT_MASK(0)
  43. #define AXP20X_PWR_OUT_DCDC3_MASK BIT_MASK(1)
  44. #define AXP20X_PWR_OUT_LDO2_MASK BIT_MASK(2)
  45. #define AXP20X_PWR_OUT_LDO4_MASK BIT_MASK(3)
  46. #define AXP20X_PWR_OUT_DCDC2_MASK BIT_MASK(4)
  47. #define AXP20X_PWR_OUT_LDO3_MASK BIT_MASK(6)
  48. #define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK BIT_MASK(0)
  49. #define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE(x) \
  50. ((x) << 0)
  51. #define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK BIT_MASK(1)
  52. #define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(x) \
  53. ((x) << 1)
  54. #define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK BIT_MASK(2)
  55. #define AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN BIT(2)
  56. #define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK BIT_MASK(3)
  57. #define AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN BIT(3)
  58. #define AXP20X_LDO4_V_OUT_1250mV_START 0x0
  59. #define AXP20X_LDO4_V_OUT_1250mV_STEPS 0
  60. #define AXP20X_LDO4_V_OUT_1250mV_END \
  61. (AXP20X_LDO4_V_OUT_1250mV_START + AXP20X_LDO4_V_OUT_1250mV_STEPS)
  62. #define AXP20X_LDO4_V_OUT_1300mV_START 0x1
  63. #define AXP20X_LDO4_V_OUT_1300mV_STEPS 7
  64. #define AXP20X_LDO4_V_OUT_1300mV_END \
  65. (AXP20X_LDO4_V_OUT_1300mV_START + AXP20X_LDO4_V_OUT_1300mV_STEPS)
  66. #define AXP20X_LDO4_V_OUT_2500mV_START 0x9
  67. #define AXP20X_LDO4_V_OUT_2500mV_STEPS 0
  68. #define AXP20X_LDO4_V_OUT_2500mV_END \
  69. (AXP20X_LDO4_V_OUT_2500mV_START + AXP20X_LDO4_V_OUT_2500mV_STEPS)
  70. #define AXP20X_LDO4_V_OUT_2700mV_START 0xa
  71. #define AXP20X_LDO4_V_OUT_2700mV_STEPS 1
  72. #define AXP20X_LDO4_V_OUT_2700mV_END \
  73. (AXP20X_LDO4_V_OUT_2700mV_START + AXP20X_LDO4_V_OUT_2700mV_STEPS)
  74. #define AXP20X_LDO4_V_OUT_3000mV_START 0xc
  75. #define AXP20X_LDO4_V_OUT_3000mV_STEPS 3
  76. #define AXP20X_LDO4_V_OUT_3000mV_END \
  77. (AXP20X_LDO4_V_OUT_3000mV_START + AXP20X_LDO4_V_OUT_3000mV_STEPS)
  78. #define AXP20X_LDO4_V_OUT_NUM_VOLTAGES 16
  79. #define AXP22X_IO_ENABLED 0x03
  80. #define AXP22X_IO_DISABLED 0x04
  81. #define AXP22X_WORKMODE_DCDCX_MASK(x) BIT_MASK(x)
  82. #define AXP22X_MISC_N_VBUSEN_FUNC BIT(4)
  83. #define AXP22X_DCDC1_V_OUT_MASK GENMASK(4, 0)
  84. #define AXP22X_DCDC2_V_OUT_MASK GENMASK(5, 0)
  85. #define AXP22X_DCDC3_V_OUT_MASK GENMASK(5, 0)
  86. #define AXP22X_DCDC4_V_OUT_MASK GENMASK(5, 0)
  87. #define AXP22X_DCDC5_V_OUT_MASK GENMASK(4, 0)
  88. #define AXP22X_DC5LDO_V_OUT_MASK GENMASK(2, 0)
  89. #define AXP22X_ALDO1_V_OUT_MASK GENMASK(4, 0)
  90. #define AXP22X_ALDO2_V_OUT_MASK GENMASK(4, 0)
  91. #define AXP22X_ALDO3_V_OUT_MASK GENMASK(4, 0)
  92. #define AXP22X_DLDO1_V_OUT_MASK GENMASK(4, 0)
  93. #define AXP22X_DLDO2_V_OUT_MASK GENMASK(4, 0)
  94. #define AXP22X_DLDO3_V_OUT_MASK GENMASK(4, 0)
  95. #define AXP22X_DLDO4_V_OUT_MASK GENMASK(4, 0)
  96. #define AXP22X_ELDO1_V_OUT_MASK GENMASK(4, 0)
  97. #define AXP22X_ELDO2_V_OUT_MASK GENMASK(4, 0)
  98. #define AXP22X_ELDO3_V_OUT_MASK GENMASK(4, 0)
  99. #define AXP22X_LDO_IO0_V_OUT_MASK GENMASK(4, 0)
  100. #define AXP22X_LDO_IO1_V_OUT_MASK GENMASK(4, 0)
  101. #define AXP22X_PWR_OUT_DC5LDO_MASK BIT_MASK(0)
  102. #define AXP22X_PWR_OUT_DCDC1_MASK BIT_MASK(1)
  103. #define AXP22X_PWR_OUT_DCDC2_MASK BIT_MASK(2)
  104. #define AXP22X_PWR_OUT_DCDC3_MASK BIT_MASK(3)
  105. #define AXP22X_PWR_OUT_DCDC4_MASK BIT_MASK(4)
  106. #define AXP22X_PWR_OUT_DCDC5_MASK BIT_MASK(5)
  107. #define AXP22X_PWR_OUT_ALDO1_MASK BIT_MASK(6)
  108. #define AXP22X_PWR_OUT_ALDO2_MASK BIT_MASK(7)
  109. #define AXP22X_PWR_OUT_SW_MASK BIT_MASK(6)
  110. #define AXP22X_PWR_OUT_DC1SW_MASK BIT_MASK(7)
  111. #define AXP22X_PWR_OUT_ELDO1_MASK BIT_MASK(0)
  112. #define AXP22X_PWR_OUT_ELDO2_MASK BIT_MASK(1)
  113. #define AXP22X_PWR_OUT_ELDO3_MASK BIT_MASK(2)
  114. #define AXP22X_PWR_OUT_DLDO1_MASK BIT_MASK(3)
  115. #define AXP22X_PWR_OUT_DLDO2_MASK BIT_MASK(4)
  116. #define AXP22X_PWR_OUT_DLDO3_MASK BIT_MASK(5)
  117. #define AXP22X_PWR_OUT_DLDO4_MASK BIT_MASK(6)
  118. #define AXP22X_PWR_OUT_ALDO3_MASK BIT_MASK(7)
  119. #define AXP803_PWR_OUT_DCDC1_MASK BIT_MASK(0)
  120. #define AXP803_PWR_OUT_DCDC2_MASK BIT_MASK(1)
  121. #define AXP803_PWR_OUT_DCDC3_MASK BIT_MASK(2)
  122. #define AXP803_PWR_OUT_DCDC4_MASK BIT_MASK(3)
  123. #define AXP803_PWR_OUT_DCDC5_MASK BIT_MASK(4)
  124. #define AXP803_PWR_OUT_DCDC6_MASK BIT_MASK(5)
  125. #define AXP803_PWR_OUT_FLDO1_MASK BIT_MASK(2)
  126. #define AXP803_PWR_OUT_FLDO2_MASK BIT_MASK(3)
  127. #define AXP803_DCDC1_V_OUT_MASK GENMASK(4, 0)
  128. #define AXP803_DCDC2_V_OUT_MASK GENMASK(6, 0)
  129. #define AXP803_DCDC3_V_OUT_MASK GENMASK(6, 0)
  130. #define AXP803_DCDC4_V_OUT_MASK GENMASK(6, 0)
  131. #define AXP803_DCDC5_V_OUT_MASK GENMASK(6, 0)
  132. #define AXP803_DCDC6_V_OUT_MASK GENMASK(6, 0)
  133. #define AXP803_FLDO1_V_OUT_MASK GENMASK(3, 0)
  134. #define AXP803_FLDO2_V_OUT_MASK GENMASK(3, 0)
  135. #define AXP803_DCDC23_POLYPHASE_DUAL BIT(6)
  136. #define AXP803_DCDC56_POLYPHASE_DUAL BIT(5)
  137. #define AXP803_DCDC234_500mV_START 0x00
  138. #define AXP803_DCDC234_500mV_STEPS 70
  139. #define AXP803_DCDC234_500mV_END \
  140. (AXP803_DCDC234_500mV_START + AXP803_DCDC234_500mV_STEPS)
  141. #define AXP803_DCDC234_1220mV_START 0x47
  142. #define AXP803_DCDC234_1220mV_STEPS 4
  143. #define AXP803_DCDC234_1220mV_END \
  144. (AXP803_DCDC234_1220mV_START + AXP803_DCDC234_1220mV_STEPS)
  145. #define AXP803_DCDC234_NUM_VOLTAGES 76
  146. #define AXP803_DCDC5_800mV_START 0x00
  147. #define AXP803_DCDC5_800mV_STEPS 32
  148. #define AXP803_DCDC5_800mV_END \
  149. (AXP803_DCDC5_800mV_START + AXP803_DCDC5_800mV_STEPS)
  150. #define AXP803_DCDC5_1140mV_START 0x21
  151. #define AXP803_DCDC5_1140mV_STEPS 35
  152. #define AXP803_DCDC5_1140mV_END \
  153. (AXP803_DCDC5_1140mV_START + AXP803_DCDC5_1140mV_STEPS)
  154. #define AXP803_DCDC5_NUM_VOLTAGES 69
  155. #define AXP803_DCDC6_600mV_START 0x00
  156. #define AXP803_DCDC6_600mV_STEPS 50
  157. #define AXP803_DCDC6_600mV_END \
  158. (AXP803_DCDC6_600mV_START + AXP803_DCDC6_600mV_STEPS)
  159. #define AXP803_DCDC6_1120mV_START 0x33
  160. #define AXP803_DCDC6_1120mV_STEPS 20
  161. #define AXP803_DCDC6_1120mV_END \
  162. (AXP803_DCDC6_1120mV_START + AXP803_DCDC6_1120mV_STEPS)
  163. #define AXP803_DCDC6_NUM_VOLTAGES 72
  164. #define AXP803_DLDO2_700mV_START 0x00
  165. #define AXP803_DLDO2_700mV_STEPS 26
  166. #define AXP803_DLDO2_700mV_END \
  167. (AXP803_DLDO2_700mV_START + AXP803_DLDO2_700mV_STEPS)
  168. #define AXP803_DLDO2_3400mV_START 0x1b
  169. #define AXP803_DLDO2_3400mV_STEPS 4
  170. #define AXP803_DLDO2_3400mV_END \
  171. (AXP803_DLDO2_3400mV_START + AXP803_DLDO2_3400mV_STEPS)
  172. #define AXP803_DLDO2_NUM_VOLTAGES 32
  173. #define AXP806_DCDCA_V_CTRL_MASK GENMASK(6, 0)
  174. #define AXP806_DCDCB_V_CTRL_MASK GENMASK(4, 0)
  175. #define AXP806_DCDCC_V_CTRL_MASK GENMASK(6, 0)
  176. #define AXP806_DCDCD_V_CTRL_MASK GENMASK(5, 0)
  177. #define AXP806_DCDCE_V_CTRL_MASK GENMASK(4, 0)
  178. #define AXP806_ALDO1_V_CTRL_MASK GENMASK(4, 0)
  179. #define AXP806_ALDO2_V_CTRL_MASK GENMASK(4, 0)
  180. #define AXP806_ALDO3_V_CTRL_MASK GENMASK(4, 0)
  181. #define AXP806_BLDO1_V_CTRL_MASK GENMASK(3, 0)
  182. #define AXP806_BLDO2_V_CTRL_MASK GENMASK(3, 0)
  183. #define AXP806_BLDO3_V_CTRL_MASK GENMASK(3, 0)
  184. #define AXP806_BLDO4_V_CTRL_MASK GENMASK(3, 0)
  185. #define AXP806_CLDO1_V_CTRL_MASK GENMASK(4, 0)
  186. #define AXP806_CLDO2_V_CTRL_MASK GENMASK(4, 0)
  187. #define AXP806_CLDO3_V_CTRL_MASK GENMASK(4, 0)
  188. #define AXP806_PWR_OUT_DCDCA_MASK BIT_MASK(0)
  189. #define AXP806_PWR_OUT_DCDCB_MASK BIT_MASK(1)
  190. #define AXP806_PWR_OUT_DCDCC_MASK BIT_MASK(2)
  191. #define AXP806_PWR_OUT_DCDCD_MASK BIT_MASK(3)
  192. #define AXP806_PWR_OUT_DCDCE_MASK BIT_MASK(4)
  193. #define AXP806_PWR_OUT_ALDO1_MASK BIT_MASK(5)
  194. #define AXP806_PWR_OUT_ALDO2_MASK BIT_MASK(6)
  195. #define AXP806_PWR_OUT_ALDO3_MASK BIT_MASK(7)
  196. #define AXP806_PWR_OUT_BLDO1_MASK BIT_MASK(0)
  197. #define AXP806_PWR_OUT_BLDO2_MASK BIT_MASK(1)
  198. #define AXP806_PWR_OUT_BLDO3_MASK BIT_MASK(2)
  199. #define AXP806_PWR_OUT_BLDO4_MASK BIT_MASK(3)
  200. #define AXP806_PWR_OUT_CLDO1_MASK BIT_MASK(4)
  201. #define AXP806_PWR_OUT_CLDO2_MASK BIT_MASK(5)
  202. #define AXP806_PWR_OUT_CLDO3_MASK BIT_MASK(6)
  203. #define AXP806_PWR_OUT_SW_MASK BIT_MASK(7)
  204. #define AXP806_DCDCAB_POLYPHASE_DUAL 0x40
  205. #define AXP806_DCDCABC_POLYPHASE_TRI 0x80
  206. #define AXP806_DCDCABC_POLYPHASE_MASK GENMASK(7, 6)
  207. #define AXP806_DCDCDE_POLYPHASE_DUAL BIT(5)
  208. #define AXP806_DCDCA_600mV_START 0x00
  209. #define AXP806_DCDCA_600mV_STEPS 50
  210. #define AXP806_DCDCA_600mV_END \
  211. (AXP806_DCDCA_600mV_START + AXP806_DCDCA_600mV_STEPS)
  212. #define AXP806_DCDCA_1120mV_START 0x33
  213. #define AXP806_DCDCA_1120mV_STEPS 20
  214. #define AXP806_DCDCA_1120mV_END \
  215. (AXP806_DCDCA_1120mV_START + AXP806_DCDCA_1120mV_STEPS)
  216. #define AXP806_DCDCA_NUM_VOLTAGES 72
  217. #define AXP806_DCDCD_600mV_START 0x00
  218. #define AXP806_DCDCD_600mV_STEPS 45
  219. #define AXP806_DCDCD_600mV_END \
  220. (AXP806_DCDCD_600mV_START + AXP806_DCDCD_600mV_STEPS)
  221. #define AXP806_DCDCD_1600mV_START 0x2e
  222. #define AXP806_DCDCD_1600mV_STEPS 17
  223. #define AXP806_DCDCD_1600mV_END \
  224. (AXP806_DCDCD_1600mV_START + AXP806_DCDCD_1600mV_STEPS)
  225. #define AXP806_DCDCD_NUM_VOLTAGES 64
  226. #define AXP809_DCDC4_600mV_START 0x00
  227. #define AXP809_DCDC4_600mV_STEPS 47
  228. #define AXP809_DCDC4_600mV_END \
  229. (AXP809_DCDC4_600mV_START + AXP809_DCDC4_600mV_STEPS)
  230. #define AXP809_DCDC4_1800mV_START 0x30
  231. #define AXP809_DCDC4_1800mV_STEPS 8
  232. #define AXP809_DCDC4_1800mV_END \
  233. (AXP809_DCDC4_1800mV_START + AXP809_DCDC4_1800mV_STEPS)
  234. #define AXP809_DCDC4_NUM_VOLTAGES 57
  235. #define AXP813_DCDC7_V_OUT_MASK GENMASK(6, 0)
  236. #define AXP813_PWR_OUT_DCDC7_MASK BIT_MASK(6)
  237. #define AXP_DESC_IO(_family, _id, _match, _supply, _min, _max, _step, _vreg, \
  238. _vmask, _ereg, _emask, _enable_val, _disable_val) \
  239. [_family##_##_id] = { \
  240. .name = (_match), \
  241. .supply_name = (_supply), \
  242. .of_match = of_match_ptr(_match), \
  243. .regulators_node = of_match_ptr("regulators"), \
  244. .type = REGULATOR_VOLTAGE, \
  245. .id = _family##_##_id, \
  246. .n_voltages = (((_max) - (_min)) / (_step) + 1), \
  247. .owner = THIS_MODULE, \
  248. .min_uV = (_min) * 1000, \
  249. .uV_step = (_step) * 1000, \
  250. .vsel_reg = (_vreg), \
  251. .vsel_mask = (_vmask), \
  252. .enable_reg = (_ereg), \
  253. .enable_mask = (_emask), \
  254. .enable_val = (_enable_val), \
  255. .disable_val = (_disable_val), \
  256. .ops = &axp20x_ops, \
  257. }
  258. #define AXP_DESC(_family, _id, _match, _supply, _min, _max, _step, _vreg, \
  259. _vmask, _ereg, _emask) \
  260. [_family##_##_id] = { \
  261. .name = (_match), \
  262. .supply_name = (_supply), \
  263. .of_match = of_match_ptr(_match), \
  264. .regulators_node = of_match_ptr("regulators"), \
  265. .type = REGULATOR_VOLTAGE, \
  266. .id = _family##_##_id, \
  267. .n_voltages = (((_max) - (_min)) / (_step) + 1), \
  268. .owner = THIS_MODULE, \
  269. .min_uV = (_min) * 1000, \
  270. .uV_step = (_step) * 1000, \
  271. .vsel_reg = (_vreg), \
  272. .vsel_mask = (_vmask), \
  273. .enable_reg = (_ereg), \
  274. .enable_mask = (_emask), \
  275. .ops = &axp20x_ops, \
  276. }
  277. #define AXP_DESC_SW(_family, _id, _match, _supply, _ereg, _emask) \
  278. [_family##_##_id] = { \
  279. .name = (_match), \
  280. .supply_name = (_supply), \
  281. .of_match = of_match_ptr(_match), \
  282. .regulators_node = of_match_ptr("regulators"), \
  283. .type = REGULATOR_VOLTAGE, \
  284. .id = _family##_##_id, \
  285. .owner = THIS_MODULE, \
  286. .enable_reg = (_ereg), \
  287. .enable_mask = (_emask), \
  288. .ops = &axp20x_ops_sw, \
  289. }
  290. #define AXP_DESC_FIXED(_family, _id, _match, _supply, _volt) \
  291. [_family##_##_id] = { \
  292. .name = (_match), \
  293. .supply_name = (_supply), \
  294. .of_match = of_match_ptr(_match), \
  295. .regulators_node = of_match_ptr("regulators"), \
  296. .type = REGULATOR_VOLTAGE, \
  297. .id = _family##_##_id, \
  298. .n_voltages = 1, \
  299. .owner = THIS_MODULE, \
  300. .min_uV = (_volt) * 1000, \
  301. .ops = &axp20x_ops_fixed \
  302. }
  303. #define AXP_DESC_RANGES(_family, _id, _match, _supply, _ranges, _n_voltages, \
  304. _vreg, _vmask, _ereg, _emask) \
  305. [_family##_##_id] = { \
  306. .name = (_match), \
  307. .supply_name = (_supply), \
  308. .of_match = of_match_ptr(_match), \
  309. .regulators_node = of_match_ptr("regulators"), \
  310. .type = REGULATOR_VOLTAGE, \
  311. .id = _family##_##_id, \
  312. .n_voltages = (_n_voltages), \
  313. .owner = THIS_MODULE, \
  314. .vsel_reg = (_vreg), \
  315. .vsel_mask = (_vmask), \
  316. .enable_reg = (_ereg), \
  317. .enable_mask = (_emask), \
  318. .linear_ranges = (_ranges), \
  319. .n_linear_ranges = ARRAY_SIZE(_ranges), \
  320. .ops = &axp20x_ops_range, \
  321. }
  322. static const int axp209_dcdc2_ldo3_slew_rates[] = {
  323. 1600,
  324. 800,
  325. };
  326. static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp)
  327. {
  328. struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
  329. int id = rdev_get_id(rdev);
  330. u8 reg, mask, enable, cfg = 0xff;
  331. const int *slew_rates;
  332. int rate_count = 0;
  333. switch (axp20x->variant) {
  334. case AXP209_ID:
  335. if (id == AXP20X_DCDC2) {
  336. slew_rates = axp209_dcdc2_ldo3_slew_rates;
  337. rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
  338. reg = AXP20X_DCDC2_LDO3_V_RAMP;
  339. mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK |
  340. AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK;
  341. enable = (ramp > 0) ?
  342. AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN :
  343. !AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN;
  344. break;
  345. }
  346. if (id == AXP20X_LDO3) {
  347. slew_rates = axp209_dcdc2_ldo3_slew_rates;
  348. rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates);
  349. reg = AXP20X_DCDC2_LDO3_V_RAMP;
  350. mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK |
  351. AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK;
  352. enable = (ramp > 0) ?
  353. AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN :
  354. !AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN;
  355. break;
  356. }
  357. if (rate_count > 0)
  358. break;
  359. /* fall through */
  360. default:
  361. /* Not supported for this regulator */
  362. return -ENOTSUPP;
  363. }
  364. if (ramp == 0) {
  365. cfg = enable;
  366. } else {
  367. int i;
  368. for (i = 0; i < rate_count; i++) {
  369. if (ramp > slew_rates[i])
  370. break;
  371. if (id == AXP20X_DCDC2)
  372. cfg = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE(i);
  373. else
  374. cfg = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(i);
  375. }
  376. if (cfg == 0xff) {
  377. dev_err(axp20x->dev, "unsupported ramp value %d", ramp);
  378. return -EINVAL;
  379. }
  380. cfg |= enable;
  381. }
  382. return regmap_update_bits(axp20x->regmap, reg, mask, cfg);
  383. }
  384. static int axp20x_regulator_enable_regmap(struct regulator_dev *rdev)
  385. {
  386. struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
  387. int id = rdev_get_id(rdev);
  388. switch (axp20x->variant) {
  389. case AXP209_ID:
  390. if ((id == AXP20X_LDO3) &&
  391. rdev->constraints && rdev->constraints->soft_start) {
  392. int v_out;
  393. int ret;
  394. /*
  395. * On some boards, the LDO3 can be overloaded when
  396. * turning on, causing the entire PMIC to shutdown
  397. * without warning. Turning it on at the minimal voltage
  398. * and then setting the voltage to the requested value
  399. * works reliably.
  400. */
  401. if (regulator_is_enabled_regmap(rdev))
  402. break;
  403. v_out = regulator_get_voltage_sel_regmap(rdev);
  404. if (v_out < 0)
  405. return v_out;
  406. if (v_out == 0)
  407. break;
  408. ret = regulator_set_voltage_sel_regmap(rdev, 0x00);
  409. /*
  410. * A small pause is needed between
  411. * setting the voltage and enabling the LDO to give the
  412. * internal state machine time to process the request.
  413. */
  414. usleep_range(1000, 5000);
  415. ret |= regulator_enable_regmap(rdev);
  416. ret |= regulator_set_voltage_sel_regmap(rdev, v_out);
  417. return ret;
  418. }
  419. break;
  420. default:
  421. /* No quirks */
  422. break;
  423. }
  424. return regulator_enable_regmap(rdev);
  425. };
  426. static const struct regulator_ops axp20x_ops_fixed = {
  427. .list_voltage = regulator_list_voltage_linear,
  428. };
  429. static const struct regulator_ops axp20x_ops_range = {
  430. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  431. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  432. .list_voltage = regulator_list_voltage_linear_range,
  433. .enable = regulator_enable_regmap,
  434. .disable = regulator_disable_regmap,
  435. .is_enabled = regulator_is_enabled_regmap,
  436. };
  437. static const struct regulator_ops axp20x_ops = {
  438. .set_voltage_sel = regulator_set_voltage_sel_regmap,
  439. .get_voltage_sel = regulator_get_voltage_sel_regmap,
  440. .list_voltage = regulator_list_voltage_linear,
  441. .enable = axp20x_regulator_enable_regmap,
  442. .disable = regulator_disable_regmap,
  443. .is_enabled = regulator_is_enabled_regmap,
  444. .set_ramp_delay = axp20x_set_ramp_delay,
  445. };
  446. static const struct regulator_ops axp20x_ops_sw = {
  447. .enable = regulator_enable_regmap,
  448. .disable = regulator_disable_regmap,
  449. .is_enabled = regulator_is_enabled_regmap,
  450. };
  451. static const struct regulator_linear_range axp20x_ldo4_ranges[] = {
  452. REGULATOR_LINEAR_RANGE(1250000,
  453. AXP20X_LDO4_V_OUT_1250mV_START,
  454. AXP20X_LDO4_V_OUT_1250mV_END,
  455. 0),
  456. REGULATOR_LINEAR_RANGE(1300000,
  457. AXP20X_LDO4_V_OUT_1300mV_START,
  458. AXP20X_LDO4_V_OUT_1300mV_END,
  459. 100000),
  460. REGULATOR_LINEAR_RANGE(2500000,
  461. AXP20X_LDO4_V_OUT_2500mV_START,
  462. AXP20X_LDO4_V_OUT_2500mV_END,
  463. 0),
  464. REGULATOR_LINEAR_RANGE(2700000,
  465. AXP20X_LDO4_V_OUT_2700mV_START,
  466. AXP20X_LDO4_V_OUT_2700mV_END,
  467. 100000),
  468. REGULATOR_LINEAR_RANGE(3000000,
  469. AXP20X_LDO4_V_OUT_3000mV_START,
  470. AXP20X_LDO4_V_OUT_3000mV_END,
  471. 100000),
  472. };
  473. static const struct regulator_desc axp20x_regulators[] = {
  474. AXP_DESC(AXP20X, DCDC2, "dcdc2", "vin2", 700, 2275, 25,
  475. AXP20X_DCDC2_V_OUT, AXP20X_DCDC2_V_OUT_MASK,
  476. AXP20X_PWR_OUT_CTRL, AXP20X_PWR_OUT_DCDC2_MASK),
  477. AXP_DESC(AXP20X, DCDC3, "dcdc3", "vin3", 700, 3500, 25,
  478. AXP20X_DCDC3_V_OUT, AXP20X_DCDC3_V_OUT_MASK,
  479. AXP20X_PWR_OUT_CTRL, AXP20X_PWR_OUT_DCDC3_MASK),
  480. AXP_DESC_FIXED(AXP20X, LDO1, "ldo1", "acin", 1300),
  481. AXP_DESC(AXP20X, LDO2, "ldo2", "ldo24in", 1800, 3300, 100,
  482. AXP20X_LDO24_V_OUT, AXP20X_LDO2_V_OUT_MASK,
  483. AXP20X_PWR_OUT_CTRL, AXP20X_PWR_OUT_LDO2_MASK),
  484. AXP_DESC(AXP20X, LDO3, "ldo3", "ldo3in", 700, 3500, 25,
  485. AXP20X_LDO3_V_OUT, AXP20X_LDO3_V_OUT_MASK,
  486. AXP20X_PWR_OUT_CTRL, AXP20X_PWR_OUT_LDO3_MASK),
  487. AXP_DESC_RANGES(AXP20X, LDO4, "ldo4", "ldo24in",
  488. axp20x_ldo4_ranges, AXP20X_LDO4_V_OUT_NUM_VOLTAGES,
  489. AXP20X_LDO24_V_OUT, AXP20X_LDO4_V_OUT_MASK,
  490. AXP20X_PWR_OUT_CTRL, AXP20X_PWR_OUT_LDO4_MASK),
  491. AXP_DESC_IO(AXP20X, LDO5, "ldo5", "ldo5in", 1800, 3300, 100,
  492. AXP20X_LDO5_V_OUT, AXP20X_LDO5_V_OUT_MASK,
  493. AXP20X_GPIO0_CTRL, AXP20X_GPIO0_FUNC_MASK,
  494. AXP20X_IO_ENABLED, AXP20X_IO_DISABLED),
  495. };
  496. static const struct regulator_desc axp22x_regulators[] = {
  497. AXP_DESC(AXP22X, DCDC1, "dcdc1", "vin1", 1600, 3400, 100,
  498. AXP22X_DCDC1_V_OUT, AXP22X_DCDC1_V_OUT_MASK,
  499. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC1_MASK),
  500. AXP_DESC(AXP22X, DCDC2, "dcdc2", "vin2", 600, 1540, 20,
  501. AXP22X_DCDC2_V_OUT, AXP22X_DCDC2_V_OUT_MASK,
  502. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC2_MASK),
  503. AXP_DESC(AXP22X, DCDC3, "dcdc3", "vin3", 600, 1860, 20,
  504. AXP22X_DCDC3_V_OUT, AXP22X_DCDC3_V_OUT_MASK,
  505. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC3_MASK),
  506. AXP_DESC(AXP22X, DCDC4, "dcdc4", "vin4", 600, 1540, 20,
  507. AXP22X_DCDC4_V_OUT, AXP22X_DCDC4_V_OUT_MASK,
  508. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC4_MASK),
  509. AXP_DESC(AXP22X, DCDC5, "dcdc5", "vin5", 1000, 2550, 50,
  510. AXP22X_DCDC5_V_OUT, AXP22X_DCDC5_V_OUT_MASK,
  511. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC5_MASK),
  512. /* secondary switchable output of DCDC1 */
  513. AXP_DESC_SW(AXP22X, DC1SW, "dc1sw", NULL,
  514. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DC1SW_MASK),
  515. /* LDO regulator internally chained to DCDC5 */
  516. AXP_DESC(AXP22X, DC5LDO, "dc5ldo", NULL, 700, 1400, 100,
  517. AXP22X_DC5LDO_V_OUT, AXP22X_DC5LDO_V_OUT_MASK,
  518. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DC5LDO_MASK),
  519. AXP_DESC(AXP22X, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  520. AXP22X_ALDO1_V_OUT, AXP22X_ALDO1_V_OUT_MASK,
  521. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_ALDO1_MASK),
  522. AXP_DESC(AXP22X, ALDO2, "aldo2", "aldoin", 700, 3300, 100,
  523. AXP22X_ALDO2_V_OUT, AXP22X_ALDO2_V_OUT_MASK,
  524. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_ALDO2_MASK),
  525. AXP_DESC(AXP22X, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  526. AXP22X_ALDO3_V_OUT, AXP22X_ALDO3_V_OUT_MASK,
  527. AXP22X_PWR_OUT_CTRL3, AXP22X_PWR_OUT_ALDO3_MASK),
  528. AXP_DESC(AXP22X, DLDO1, "dldo1", "dldoin", 700, 3300, 100,
  529. AXP22X_DLDO1_V_OUT, AXP22X_DLDO1_V_OUT_MASK,
  530. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO1_MASK),
  531. AXP_DESC(AXP22X, DLDO2, "dldo2", "dldoin", 700, 3300, 100,
  532. AXP22X_DLDO2_V_OUT, AXP22X_DLDO2_V_OUT_MASK,
  533. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO2_MASK),
  534. AXP_DESC(AXP22X, DLDO3, "dldo3", "dldoin", 700, 3300, 100,
  535. AXP22X_DLDO3_V_OUT, AXP22X_DLDO3_V_OUT_MASK,
  536. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO3_MASK),
  537. AXP_DESC(AXP22X, DLDO4, "dldo4", "dldoin", 700, 3300, 100,
  538. AXP22X_DLDO4_V_OUT, AXP22X_DLDO4_V_OUT_MASK,
  539. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO4_MASK),
  540. AXP_DESC(AXP22X, ELDO1, "eldo1", "eldoin", 700, 3300, 100,
  541. AXP22X_ELDO1_V_OUT, AXP22X_ELDO1_V_OUT_MASK,
  542. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO1_MASK),
  543. AXP_DESC(AXP22X, ELDO2, "eldo2", "eldoin", 700, 3300, 100,
  544. AXP22X_ELDO2_V_OUT, AXP22X_ELDO2_V_OUT_MASK,
  545. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO2_MASK),
  546. AXP_DESC(AXP22X, ELDO3, "eldo3", "eldoin", 700, 3300, 100,
  547. AXP22X_ELDO3_V_OUT, AXP22X_ELDO3_V_OUT_MASK,
  548. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO3_MASK),
  549. /* Note the datasheet only guarantees reliable operation up to
  550. * 3.3V, this needs to be enforced via dts provided constraints */
  551. AXP_DESC_IO(AXP22X, LDO_IO0, "ldo_io0", "ips", 700, 3800, 100,
  552. AXP22X_LDO_IO0_V_OUT, AXP22X_LDO_IO0_V_OUT_MASK,
  553. AXP20X_GPIO0_CTRL, AXP20X_GPIO0_FUNC_MASK,
  554. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  555. /* Note the datasheet only guarantees reliable operation up to
  556. * 3.3V, this needs to be enforced via dts provided constraints */
  557. AXP_DESC_IO(AXP22X, LDO_IO1, "ldo_io1", "ips", 700, 3800, 100,
  558. AXP22X_LDO_IO1_V_OUT, AXP22X_LDO_IO1_V_OUT_MASK,
  559. AXP20X_GPIO1_CTRL, AXP20X_GPIO1_FUNC_MASK,
  560. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  561. AXP_DESC_FIXED(AXP22X, RTC_LDO, "rtc_ldo", "ips", 3000),
  562. };
  563. static const struct regulator_desc axp22x_drivevbus_regulator = {
  564. .name = "drivevbus",
  565. .supply_name = "drivevbus",
  566. .of_match = of_match_ptr("drivevbus"),
  567. .regulators_node = of_match_ptr("regulators"),
  568. .type = REGULATOR_VOLTAGE,
  569. .owner = THIS_MODULE,
  570. .enable_reg = AXP20X_VBUS_IPSOUT_MGMT,
  571. .enable_mask = AXP20X_VBUS_IPSOUT_MGMT_MASK,
  572. .ops = &axp20x_ops_sw,
  573. };
  574. /* DCDC ranges shared with AXP813 */
  575. static const struct regulator_linear_range axp803_dcdc234_ranges[] = {
  576. REGULATOR_LINEAR_RANGE(500000,
  577. AXP803_DCDC234_500mV_START,
  578. AXP803_DCDC234_500mV_END,
  579. 10000),
  580. REGULATOR_LINEAR_RANGE(1220000,
  581. AXP803_DCDC234_1220mV_START,
  582. AXP803_DCDC234_1220mV_END,
  583. 20000),
  584. };
  585. static const struct regulator_linear_range axp803_dcdc5_ranges[] = {
  586. REGULATOR_LINEAR_RANGE(800000,
  587. AXP803_DCDC5_800mV_START,
  588. AXP803_DCDC5_800mV_END,
  589. 10000),
  590. REGULATOR_LINEAR_RANGE(1140000,
  591. AXP803_DCDC5_1140mV_START,
  592. AXP803_DCDC5_1140mV_END,
  593. 20000),
  594. };
  595. static const struct regulator_linear_range axp803_dcdc6_ranges[] = {
  596. REGULATOR_LINEAR_RANGE(600000,
  597. AXP803_DCDC6_600mV_START,
  598. AXP803_DCDC6_600mV_END,
  599. 10000),
  600. REGULATOR_LINEAR_RANGE(1120000,
  601. AXP803_DCDC6_1120mV_START,
  602. AXP803_DCDC6_1120mV_END,
  603. 20000),
  604. };
  605. /* AXP806's CLDO2 and AXP809's DLDO1 share the same range */
  606. static const struct regulator_linear_range axp803_dldo2_ranges[] = {
  607. REGULATOR_LINEAR_RANGE(700000,
  608. AXP803_DLDO2_700mV_START,
  609. AXP803_DLDO2_700mV_END,
  610. 100000),
  611. REGULATOR_LINEAR_RANGE(3400000,
  612. AXP803_DLDO2_3400mV_START,
  613. AXP803_DLDO2_3400mV_END,
  614. 200000),
  615. };
  616. static const struct regulator_desc axp803_regulators[] = {
  617. AXP_DESC(AXP803, DCDC1, "dcdc1", "vin1", 1600, 3400, 100,
  618. AXP803_DCDC1_V_OUT, AXP803_DCDC1_V_OUT_MASK,
  619. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC1_MASK),
  620. AXP_DESC_RANGES(AXP803, DCDC2, "dcdc2", "vin2",
  621. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  622. AXP803_DCDC2_V_OUT, AXP803_DCDC2_V_OUT_MASK,
  623. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC2_MASK),
  624. AXP_DESC_RANGES(AXP803, DCDC3, "dcdc3", "vin3",
  625. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  626. AXP803_DCDC3_V_OUT, AXP803_DCDC3_V_OUT_MASK,
  627. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC3_MASK),
  628. AXP_DESC_RANGES(AXP803, DCDC4, "dcdc4", "vin4",
  629. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  630. AXP803_DCDC4_V_OUT, AXP803_DCDC4_V_OUT_MASK,
  631. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC4_MASK),
  632. AXP_DESC_RANGES(AXP803, DCDC5, "dcdc5", "vin5",
  633. axp803_dcdc5_ranges, AXP803_DCDC5_NUM_VOLTAGES,
  634. AXP803_DCDC5_V_OUT, AXP803_DCDC5_V_OUT_MASK,
  635. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC5_MASK),
  636. AXP_DESC_RANGES(AXP803, DCDC6, "dcdc6", "vin6",
  637. axp803_dcdc6_ranges, AXP803_DCDC6_NUM_VOLTAGES,
  638. AXP803_DCDC6_V_OUT, AXP803_DCDC6_V_OUT_MASK,
  639. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC6_MASK),
  640. /* secondary switchable output of DCDC1 */
  641. AXP_DESC_SW(AXP803, DC1SW, "dc1sw", NULL,
  642. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DC1SW_MASK),
  643. AXP_DESC(AXP803, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  644. AXP22X_ALDO1_V_OUT, AXP22X_ALDO1_V_OUT_MASK,
  645. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO1_MASK),
  646. AXP_DESC(AXP803, ALDO2, "aldo2", "aldoin", 700, 3300, 100,
  647. AXP22X_ALDO2_V_OUT, AXP22X_ALDO2_V_OUT_MASK,
  648. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO2_MASK),
  649. AXP_DESC(AXP803, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  650. AXP22X_ALDO3_V_OUT, AXP22X_ALDO3_V_OUT_MASK,
  651. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO3_MASK),
  652. AXP_DESC(AXP803, DLDO1, "dldo1", "dldoin", 700, 3300, 100,
  653. AXP22X_DLDO1_V_OUT, AXP22X_DLDO1_V_OUT_MASK,
  654. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO1_MASK),
  655. AXP_DESC_RANGES(AXP803, DLDO2, "dldo2", "dldoin",
  656. axp803_dldo2_ranges, AXP803_DLDO2_NUM_VOLTAGES,
  657. AXP22X_DLDO2_V_OUT, AXP22X_DLDO2_V_OUT_MASK,
  658. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO2_MASK),
  659. AXP_DESC(AXP803, DLDO3, "dldo3", "dldoin", 700, 3300, 100,
  660. AXP22X_DLDO3_V_OUT, AXP22X_DLDO3_V_OUT_MASK,
  661. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO3_MASK),
  662. AXP_DESC(AXP803, DLDO4, "dldo4", "dldoin", 700, 3300, 100,
  663. AXP22X_DLDO4_V_OUT, AXP22X_DLDO4_V_OUT_MASK,
  664. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO4_MASK),
  665. AXP_DESC(AXP803, ELDO1, "eldo1", "eldoin", 700, 1900, 50,
  666. AXP22X_ELDO1_V_OUT, AXP22X_ELDO1_V_OUT_MASK,
  667. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO1_MASK),
  668. AXP_DESC(AXP803, ELDO2, "eldo2", "eldoin", 700, 1900, 50,
  669. AXP22X_ELDO2_V_OUT, AXP22X_ELDO2_V_OUT_MASK,
  670. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO2_MASK),
  671. AXP_DESC(AXP803, ELDO3, "eldo3", "eldoin", 700, 1900, 50,
  672. AXP22X_ELDO3_V_OUT, AXP22X_ELDO3_V_OUT_MASK,
  673. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO3_MASK),
  674. AXP_DESC(AXP803, FLDO1, "fldo1", "fldoin", 700, 1450, 50,
  675. AXP803_FLDO1_V_OUT, AXP803_FLDO1_V_OUT_MASK,
  676. AXP22X_PWR_OUT_CTRL3, AXP803_PWR_OUT_FLDO1_MASK),
  677. AXP_DESC(AXP803, FLDO2, "fldo2", "fldoin", 700, 1450, 50,
  678. AXP803_FLDO2_V_OUT, AXP803_FLDO2_V_OUT_MASK,
  679. AXP22X_PWR_OUT_CTRL3, AXP803_PWR_OUT_FLDO2_MASK),
  680. AXP_DESC_IO(AXP803, LDO_IO0, "ldo-io0", "ips", 700, 3300, 100,
  681. AXP22X_LDO_IO0_V_OUT, AXP22X_LDO_IO0_V_OUT_MASK,
  682. AXP20X_GPIO0_CTRL, AXP20X_GPIO0_FUNC_MASK,
  683. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  684. AXP_DESC_IO(AXP803, LDO_IO1, "ldo-io1", "ips", 700, 3300, 100,
  685. AXP22X_LDO_IO1_V_OUT, AXP22X_LDO_IO1_V_OUT_MASK,
  686. AXP20X_GPIO1_CTRL, AXP20X_GPIO1_FUNC_MASK,
  687. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  688. AXP_DESC_FIXED(AXP803, RTC_LDO, "rtc-ldo", "ips", 3000),
  689. };
  690. static const struct regulator_linear_range axp806_dcdca_ranges[] = {
  691. REGULATOR_LINEAR_RANGE(600000,
  692. AXP806_DCDCA_600mV_START,
  693. AXP806_DCDCA_600mV_END,
  694. 10000),
  695. REGULATOR_LINEAR_RANGE(1120000,
  696. AXP806_DCDCA_1120mV_START,
  697. AXP806_DCDCA_1120mV_END,
  698. 20000),
  699. };
  700. static const struct regulator_linear_range axp806_dcdcd_ranges[] = {
  701. REGULATOR_LINEAR_RANGE(600000,
  702. AXP806_DCDCD_600mV_START,
  703. AXP806_DCDCD_600mV_END,
  704. 20000),
  705. REGULATOR_LINEAR_RANGE(1600000,
  706. AXP806_DCDCD_1600mV_START,
  707. AXP806_DCDCD_1600mV_END,
  708. 100000),
  709. };
  710. static const struct regulator_desc axp806_regulators[] = {
  711. AXP_DESC_RANGES(AXP806, DCDCA, "dcdca", "vina",
  712. axp806_dcdca_ranges, AXP806_DCDCA_NUM_VOLTAGES,
  713. AXP806_DCDCA_V_CTRL, AXP806_DCDCA_V_CTRL_MASK,
  714. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_DCDCA_MASK),
  715. AXP_DESC(AXP806, DCDCB, "dcdcb", "vinb", 1000, 2550, 50,
  716. AXP806_DCDCB_V_CTRL, AXP806_DCDCB_V_CTRL_MASK,
  717. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_DCDCB_MASK),
  718. AXP_DESC_RANGES(AXP806, DCDCC, "dcdcc", "vinc",
  719. axp806_dcdca_ranges, AXP806_DCDCA_NUM_VOLTAGES,
  720. AXP806_DCDCC_V_CTRL, AXP806_DCDCC_V_CTRL_MASK,
  721. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_DCDCC_MASK),
  722. AXP_DESC_RANGES(AXP806, DCDCD, "dcdcd", "vind",
  723. axp806_dcdcd_ranges, AXP806_DCDCD_NUM_VOLTAGES,
  724. AXP806_DCDCD_V_CTRL, AXP806_DCDCD_V_CTRL_MASK,
  725. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_DCDCD_MASK),
  726. AXP_DESC(AXP806, DCDCE, "dcdce", "vine", 1100, 3400, 100,
  727. AXP806_DCDCE_V_CTRL, AXP806_DCDCE_V_CTRL_MASK,
  728. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_DCDCE_MASK),
  729. AXP_DESC(AXP806, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  730. AXP806_ALDO1_V_CTRL, AXP806_ALDO1_V_CTRL_MASK,
  731. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_ALDO1_MASK),
  732. AXP_DESC(AXP806, ALDO2, "aldo2", "aldoin", 700, 3400, 100,
  733. AXP806_ALDO2_V_CTRL, AXP806_ALDO2_V_CTRL_MASK,
  734. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_ALDO2_MASK),
  735. AXP_DESC(AXP806, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  736. AXP806_ALDO3_V_CTRL, AXP806_ALDO3_V_CTRL_MASK,
  737. AXP806_PWR_OUT_CTRL1, AXP806_PWR_OUT_ALDO3_MASK),
  738. AXP_DESC(AXP806, BLDO1, "bldo1", "bldoin", 700, 1900, 100,
  739. AXP806_BLDO1_V_CTRL, AXP806_BLDO1_V_CTRL_MASK,
  740. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_BLDO1_MASK),
  741. AXP_DESC(AXP806, BLDO2, "bldo2", "bldoin", 700, 1900, 100,
  742. AXP806_BLDO2_V_CTRL, AXP806_BLDO2_V_CTRL_MASK,
  743. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_BLDO2_MASK),
  744. AXP_DESC(AXP806, BLDO3, "bldo3", "bldoin", 700, 1900, 100,
  745. AXP806_BLDO3_V_CTRL, AXP806_BLDO3_V_CTRL_MASK,
  746. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_BLDO3_MASK),
  747. AXP_DESC(AXP806, BLDO4, "bldo4", "bldoin", 700, 1900, 100,
  748. AXP806_BLDO4_V_CTRL, AXP806_BLDO4_V_CTRL_MASK,
  749. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_BLDO4_MASK),
  750. AXP_DESC(AXP806, CLDO1, "cldo1", "cldoin", 700, 3300, 100,
  751. AXP806_CLDO1_V_CTRL, AXP806_CLDO1_V_CTRL_MASK,
  752. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_CLDO1_MASK),
  753. AXP_DESC_RANGES(AXP806, CLDO2, "cldo2", "cldoin",
  754. axp803_dldo2_ranges, AXP803_DLDO2_NUM_VOLTAGES,
  755. AXP806_CLDO2_V_CTRL, AXP806_CLDO2_V_CTRL_MASK,
  756. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_CLDO2_MASK),
  757. AXP_DESC(AXP806, CLDO3, "cldo3", "cldoin", 700, 3300, 100,
  758. AXP806_CLDO3_V_CTRL, AXP806_CLDO3_V_CTRL_MASK,
  759. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_CLDO3_MASK),
  760. AXP_DESC_SW(AXP806, SW, "sw", "swin",
  761. AXP806_PWR_OUT_CTRL2, AXP806_PWR_OUT_SW_MASK),
  762. };
  763. static const struct regulator_linear_range axp809_dcdc4_ranges[] = {
  764. REGULATOR_LINEAR_RANGE(600000,
  765. AXP809_DCDC4_600mV_START,
  766. AXP809_DCDC4_600mV_END,
  767. 20000),
  768. REGULATOR_LINEAR_RANGE(1800000,
  769. AXP809_DCDC4_1800mV_START,
  770. AXP809_DCDC4_1800mV_END,
  771. 100000),
  772. };
  773. static const struct regulator_desc axp809_regulators[] = {
  774. AXP_DESC(AXP809, DCDC1, "dcdc1", "vin1", 1600, 3400, 100,
  775. AXP22X_DCDC1_V_OUT, AXP22X_DCDC1_V_OUT_MASK,
  776. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC1_MASK),
  777. AXP_DESC(AXP809, DCDC2, "dcdc2", "vin2", 600, 1540, 20,
  778. AXP22X_DCDC2_V_OUT, AXP22X_DCDC2_V_OUT_MASK,
  779. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC2_MASK),
  780. AXP_DESC(AXP809, DCDC3, "dcdc3", "vin3", 600, 1860, 20,
  781. AXP22X_DCDC3_V_OUT, AXP22X_DCDC3_V_OUT_MASK,
  782. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC3_MASK),
  783. AXP_DESC_RANGES(AXP809, DCDC4, "dcdc4", "vin4",
  784. axp809_dcdc4_ranges, AXP809_DCDC4_NUM_VOLTAGES,
  785. AXP22X_DCDC4_V_OUT, AXP22X_DCDC4_V_OUT_MASK,
  786. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC4_MASK),
  787. AXP_DESC(AXP809, DCDC5, "dcdc5", "vin5", 1000, 2550, 50,
  788. AXP22X_DCDC5_V_OUT, AXP22X_DCDC5_V_OUT_MASK,
  789. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DCDC5_MASK),
  790. /* secondary switchable output of DCDC1 */
  791. AXP_DESC_SW(AXP809, DC1SW, "dc1sw", NULL,
  792. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DC1SW_MASK),
  793. /* LDO regulator internally chained to DCDC5 */
  794. AXP_DESC(AXP809, DC5LDO, "dc5ldo", NULL, 700, 1400, 100,
  795. AXP22X_DC5LDO_V_OUT, AXP22X_DC5LDO_V_OUT_MASK,
  796. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_DC5LDO_MASK),
  797. AXP_DESC(AXP809, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  798. AXP22X_ALDO1_V_OUT, AXP22X_ALDO1_V_OUT_MASK,
  799. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_ALDO1_MASK),
  800. AXP_DESC(AXP809, ALDO2, "aldo2", "aldoin", 700, 3300, 100,
  801. AXP22X_ALDO2_V_OUT, AXP22X_ALDO2_V_OUT_MASK,
  802. AXP22X_PWR_OUT_CTRL1, AXP22X_PWR_OUT_ALDO2_MASK),
  803. AXP_DESC(AXP809, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  804. AXP22X_ALDO3_V_OUT, AXP22X_ALDO3_V_OUT_MASK,
  805. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ALDO3_MASK),
  806. AXP_DESC_RANGES(AXP809, DLDO1, "dldo1", "dldoin",
  807. axp803_dldo2_ranges, AXP803_DLDO2_NUM_VOLTAGES,
  808. AXP22X_DLDO1_V_OUT, AXP22X_DLDO1_V_OUT_MASK,
  809. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO1_MASK),
  810. AXP_DESC(AXP809, DLDO2, "dldo2", "dldoin", 700, 3300, 100,
  811. AXP22X_DLDO2_V_OUT, AXP22X_DLDO2_V_OUT_MASK,
  812. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO2_MASK),
  813. AXP_DESC(AXP809, ELDO1, "eldo1", "eldoin", 700, 3300, 100,
  814. AXP22X_ELDO1_V_OUT, AXP22X_ELDO1_V_OUT_MASK,
  815. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO1_MASK),
  816. AXP_DESC(AXP809, ELDO2, "eldo2", "eldoin", 700, 3300, 100,
  817. AXP22X_ELDO2_V_OUT, AXP22X_ELDO2_V_OUT_MASK,
  818. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO2_MASK),
  819. AXP_DESC(AXP809, ELDO3, "eldo3", "eldoin", 700, 3300, 100,
  820. AXP22X_ELDO3_V_OUT, AXP22X_ELDO3_V_OUT_MASK,
  821. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO3_MASK),
  822. /*
  823. * Note the datasheet only guarantees reliable operation up to
  824. * 3.3V, this needs to be enforced via dts provided constraints
  825. */
  826. AXP_DESC_IO(AXP809, LDO_IO0, "ldo_io0", "ips", 700, 3800, 100,
  827. AXP22X_LDO_IO0_V_OUT, AXP22X_LDO_IO0_V_OUT_MASK,
  828. AXP20X_GPIO0_CTRL, AXP20X_GPIO0_FUNC_MASK,
  829. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  830. /*
  831. * Note the datasheet only guarantees reliable operation up to
  832. * 3.3V, this needs to be enforced via dts provided constraints
  833. */
  834. AXP_DESC_IO(AXP809, LDO_IO1, "ldo_io1", "ips", 700, 3800, 100,
  835. AXP22X_LDO_IO1_V_OUT, AXP22X_LDO_IO1_V_OUT_MASK,
  836. AXP20X_GPIO1_CTRL, AXP20X_GPIO1_FUNC_MASK,
  837. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  838. AXP_DESC_FIXED(AXP809, RTC_LDO, "rtc_ldo", "ips", 1800),
  839. AXP_DESC_SW(AXP809, SW, "sw", "swin",
  840. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_SW_MASK),
  841. };
  842. static const struct regulator_desc axp813_regulators[] = {
  843. AXP_DESC(AXP813, DCDC1, "dcdc1", "vin1", 1600, 3400, 100,
  844. AXP803_DCDC1_V_OUT, AXP803_DCDC1_V_OUT_MASK,
  845. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC1_MASK),
  846. AXP_DESC_RANGES(AXP813, DCDC2, "dcdc2", "vin2",
  847. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  848. AXP803_DCDC2_V_OUT, AXP803_DCDC2_V_OUT_MASK,
  849. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC2_MASK),
  850. AXP_DESC_RANGES(AXP813, DCDC3, "dcdc3", "vin3",
  851. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  852. AXP803_DCDC3_V_OUT, AXP803_DCDC3_V_OUT_MASK,
  853. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC3_MASK),
  854. AXP_DESC_RANGES(AXP813, DCDC4, "dcdc4", "vin4",
  855. axp803_dcdc234_ranges, AXP803_DCDC234_NUM_VOLTAGES,
  856. AXP803_DCDC4_V_OUT, AXP803_DCDC4_V_OUT_MASK,
  857. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC4_MASK),
  858. AXP_DESC_RANGES(AXP813, DCDC5, "dcdc5", "vin5",
  859. axp803_dcdc5_ranges, AXP803_DCDC5_NUM_VOLTAGES,
  860. AXP803_DCDC5_V_OUT, AXP803_DCDC5_V_OUT_MASK,
  861. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC5_MASK),
  862. AXP_DESC_RANGES(AXP813, DCDC6, "dcdc6", "vin6",
  863. axp803_dcdc6_ranges, AXP803_DCDC6_NUM_VOLTAGES,
  864. AXP803_DCDC6_V_OUT, AXP803_DCDC6_V_OUT_MASK,
  865. AXP22X_PWR_OUT_CTRL1, AXP803_PWR_OUT_DCDC6_MASK),
  866. AXP_DESC_RANGES(AXP813, DCDC7, "dcdc7", "vin7",
  867. axp803_dcdc6_ranges, AXP803_DCDC6_NUM_VOLTAGES,
  868. AXP813_DCDC7_V_OUT, AXP813_DCDC7_V_OUT_MASK,
  869. AXP22X_PWR_OUT_CTRL1, AXP813_PWR_OUT_DCDC7_MASK),
  870. AXP_DESC(AXP813, ALDO1, "aldo1", "aldoin", 700, 3300, 100,
  871. AXP22X_ALDO1_V_OUT, AXP22X_ALDO1_V_OUT_MASK,
  872. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO1_MASK),
  873. AXP_DESC(AXP813, ALDO2, "aldo2", "aldoin", 700, 3300, 100,
  874. AXP22X_ALDO2_V_OUT, AXP22X_ALDO2_V_OUT_MASK,
  875. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO2_MASK),
  876. AXP_DESC(AXP813, ALDO3, "aldo3", "aldoin", 700, 3300, 100,
  877. AXP22X_ALDO3_V_OUT, AXP22X_ALDO3_V_OUT_MASK,
  878. AXP22X_PWR_OUT_CTRL3, AXP806_PWR_OUT_ALDO3_MASK),
  879. AXP_DESC(AXP813, DLDO1, "dldo1", "dldoin", 700, 3300, 100,
  880. AXP22X_DLDO1_V_OUT, AXP22X_DLDO1_V_OUT_MASK,
  881. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO1_MASK),
  882. AXP_DESC_RANGES(AXP813, DLDO2, "dldo2", "dldoin",
  883. axp803_dldo2_ranges, AXP803_DLDO2_NUM_VOLTAGES,
  884. AXP22X_DLDO2_V_OUT, AXP22X_DLDO2_V_OUT_MASK,
  885. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO2_MASK),
  886. AXP_DESC(AXP813, DLDO3, "dldo3", "dldoin", 700, 3300, 100,
  887. AXP22X_DLDO3_V_OUT, AXP22X_DLDO3_V_OUT_MASK,
  888. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO3_MASK),
  889. AXP_DESC(AXP813, DLDO4, "dldo4", "dldoin", 700, 3300, 100,
  890. AXP22X_DLDO4_V_OUT, AXP22X_DLDO4_V_OUT_MASK,
  891. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DLDO4_MASK),
  892. AXP_DESC(AXP813, ELDO1, "eldo1", "eldoin", 700, 1900, 50,
  893. AXP22X_ELDO1_V_OUT, AXP22X_ELDO1_V_OUT_MASK,
  894. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO1_MASK),
  895. AXP_DESC(AXP813, ELDO2, "eldo2", "eldoin", 700, 1900, 50,
  896. AXP22X_ELDO2_V_OUT, AXP22X_ELDO2_V_OUT_MASK,
  897. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO2_MASK),
  898. AXP_DESC(AXP813, ELDO3, "eldo3", "eldoin", 700, 1900, 50,
  899. AXP22X_ELDO3_V_OUT, AXP22X_ELDO3_V_OUT_MASK,
  900. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_ELDO3_MASK),
  901. /* to do / check ... */
  902. AXP_DESC(AXP813, FLDO1, "fldo1", "fldoin", 700, 1450, 50,
  903. AXP803_FLDO1_V_OUT, AXP803_FLDO1_V_OUT_MASK,
  904. AXP22X_PWR_OUT_CTRL3, AXP803_PWR_OUT_FLDO1_MASK),
  905. AXP_DESC(AXP813, FLDO2, "fldo2", "fldoin", 700, 1450, 50,
  906. AXP803_FLDO2_V_OUT, AXP803_FLDO2_V_OUT_MASK,
  907. AXP22X_PWR_OUT_CTRL3, AXP803_PWR_OUT_FLDO2_MASK),
  908. /*
  909. * TODO: FLDO3 = {DCDC5, FLDOIN} / 2
  910. *
  911. * This means FLDO3 effectively switches supplies at runtime,
  912. * something the regulator subsystem does not support.
  913. */
  914. AXP_DESC_FIXED(AXP813, RTC_LDO, "rtc-ldo", "ips", 1800),
  915. AXP_DESC_IO(AXP813, LDO_IO0, "ldo-io0", "ips", 700, 3300, 100,
  916. AXP22X_LDO_IO0_V_OUT, AXP22X_LDO_IO0_V_OUT_MASK,
  917. AXP20X_GPIO0_CTRL, AXP20X_GPIO0_FUNC_MASK,
  918. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  919. AXP_DESC_IO(AXP813, LDO_IO1, "ldo-io1", "ips", 700, 3300, 100,
  920. AXP22X_LDO_IO1_V_OUT, AXP22X_LDO_IO1_V_OUT_MASK,
  921. AXP20X_GPIO1_CTRL, AXP20X_GPIO1_FUNC_MASK,
  922. AXP22X_IO_ENABLED, AXP22X_IO_DISABLED),
  923. AXP_DESC_SW(AXP813, SW, "sw", "swin",
  924. AXP22X_PWR_OUT_CTRL2, AXP22X_PWR_OUT_DC1SW_MASK),
  925. };
  926. static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq)
  927. {
  928. struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
  929. unsigned int reg = AXP20X_DCDC_FREQ;
  930. u32 min, max, def, step;
  931. switch (axp20x->variant) {
  932. case AXP202_ID:
  933. case AXP209_ID:
  934. min = 750;
  935. max = 1875;
  936. def = 1500;
  937. step = 75;
  938. break;
  939. case AXP803_ID:
  940. case AXP813_ID:
  941. /*
  942. * AXP803/AXP813 DCDC work frequency setting has the same
  943. * range and step as AXP22X, but at a different register.
  944. * (See include/linux/mfd/axp20x.h)
  945. */
  946. reg = AXP803_DCDC_FREQ_CTRL;
  947. /* Fall through - to the check below.*/
  948. case AXP806_ID:
  949. /*
  950. * AXP806 also have DCDC work frequency setting register at a
  951. * different position.
  952. */
  953. if (axp20x->variant == AXP806_ID)
  954. reg = AXP806_DCDC_FREQ_CTRL;
  955. /* Fall through */
  956. case AXP221_ID:
  957. case AXP223_ID:
  958. case AXP809_ID:
  959. min = 1800;
  960. max = 4050;
  961. def = 3000;
  962. step = 150;
  963. break;
  964. default:
  965. dev_err(&pdev->dev,
  966. "Setting DCDC frequency for unsupported AXP variant\n");
  967. return -EINVAL;
  968. }
  969. if (dcdcfreq == 0)
  970. dcdcfreq = def;
  971. if (dcdcfreq < min) {
  972. dcdcfreq = min;
  973. dev_warn(&pdev->dev, "DCDC frequency too low. Set to %ukHz\n",
  974. min);
  975. }
  976. if (dcdcfreq > max) {
  977. dcdcfreq = max;
  978. dev_warn(&pdev->dev, "DCDC frequency too high. Set to %ukHz\n",
  979. max);
  980. }
  981. dcdcfreq = (dcdcfreq - min) / step;
  982. return regmap_update_bits(axp20x->regmap, reg,
  983. AXP20X_FREQ_DCDC_MASK, dcdcfreq);
  984. }
  985. static int axp20x_regulator_parse_dt(struct platform_device *pdev)
  986. {
  987. struct device_node *np, *regulators;
  988. int ret = 0;
  989. u32 dcdcfreq = 0;
  990. np = of_node_get(pdev->dev.parent->of_node);
  991. if (!np)
  992. return 0;
  993. regulators = of_get_child_by_name(np, "regulators");
  994. if (!regulators) {
  995. dev_warn(&pdev->dev, "regulators node not found\n");
  996. } else {
  997. of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
  998. ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
  999. if (ret < 0) {
  1000. dev_err(&pdev->dev, "Error setting dcdc frequency: %d\n", ret);
  1001. }
  1002. of_node_put(regulators);
  1003. }
  1004. of_node_put(np);
  1005. return ret;
  1006. }
  1007. static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 workmode)
  1008. {
  1009. struct axp20x_dev *axp20x = rdev_get_drvdata(rdev);
  1010. unsigned int reg = AXP20X_DCDC_MODE;
  1011. unsigned int mask;
  1012. switch (axp20x->variant) {
  1013. case AXP202_ID:
  1014. case AXP209_ID:
  1015. if ((id != AXP20X_DCDC2) && (id != AXP20X_DCDC3))
  1016. return -EINVAL;
  1017. mask = AXP20X_WORKMODE_DCDC2_MASK;
  1018. if (id == AXP20X_DCDC3)
  1019. mask = AXP20X_WORKMODE_DCDC3_MASK;
  1020. workmode <<= ffs(mask) - 1;
  1021. break;
  1022. case AXP806_ID:
  1023. /*
  1024. * AXP806 DCDC regulator IDs have the same range as AXP22X.
  1025. * (See include/linux/mfd/axp20x.h)
  1026. */
  1027. reg = AXP806_DCDC_MODE_CTRL2;
  1028. /* Fall through - to the check below. */
  1029. case AXP221_ID:
  1030. case AXP223_ID:
  1031. case AXP809_ID:
  1032. if (id < AXP22X_DCDC1 || id > AXP22X_DCDC5)
  1033. return -EINVAL;
  1034. mask = AXP22X_WORKMODE_DCDCX_MASK(id - AXP22X_DCDC1);
  1035. workmode <<= id - AXP22X_DCDC1;
  1036. break;
  1037. case AXP803_ID:
  1038. if (id < AXP803_DCDC1 || id > AXP803_DCDC6)
  1039. return -EINVAL;
  1040. mask = AXP22X_WORKMODE_DCDCX_MASK(id - AXP803_DCDC1);
  1041. workmode <<= id - AXP803_DCDC1;
  1042. break;
  1043. case AXP813_ID:
  1044. if (id < AXP813_DCDC1 || id > AXP813_DCDC7)
  1045. return -EINVAL;
  1046. mask = AXP22X_WORKMODE_DCDCX_MASK(id - AXP813_DCDC1);
  1047. workmode <<= id - AXP813_DCDC1;
  1048. break;
  1049. default:
  1050. /* should not happen */
  1051. WARN_ON(1);
  1052. return -EINVAL;
  1053. }
  1054. return regmap_update_bits(rdev->regmap, reg, mask, workmode);
  1055. }
  1056. /*
  1057. * This function checks whether a regulator is part of a poly-phase
  1058. * output setup based on the registers settings. Returns true if it is.
  1059. */
  1060. static bool axp20x_is_polyphase_slave(struct axp20x_dev *axp20x, int id)
  1061. {
  1062. u32 reg = 0;
  1063. /*
  1064. * Currently in our supported AXP variants, only AXP803, AXP806,
  1065. * and AXP813 have polyphase regulators.
  1066. */
  1067. switch (axp20x->variant) {
  1068. case AXP803_ID:
  1069. case AXP813_ID:
  1070. regmap_read(axp20x->regmap, AXP803_POLYPHASE_CTRL, &reg);
  1071. switch (id) {
  1072. case AXP803_DCDC3:
  1073. return !!(reg & AXP803_DCDC23_POLYPHASE_DUAL);
  1074. case AXP803_DCDC6:
  1075. return !!(reg & AXP803_DCDC56_POLYPHASE_DUAL);
  1076. }
  1077. break;
  1078. case AXP806_ID:
  1079. regmap_read(axp20x->regmap, AXP806_DCDC_MODE_CTRL2, &reg);
  1080. switch (id) {
  1081. case AXP806_DCDCB:
  1082. return (((reg & AXP806_DCDCABC_POLYPHASE_MASK) ==
  1083. AXP806_DCDCAB_POLYPHASE_DUAL) ||
  1084. ((reg & AXP806_DCDCABC_POLYPHASE_MASK) ==
  1085. AXP806_DCDCABC_POLYPHASE_TRI));
  1086. case AXP806_DCDCC:
  1087. return ((reg & AXP806_DCDCABC_POLYPHASE_MASK) ==
  1088. AXP806_DCDCABC_POLYPHASE_TRI);
  1089. case AXP806_DCDCE:
  1090. return !!(reg & AXP806_DCDCDE_POLYPHASE_DUAL);
  1091. }
  1092. break;
  1093. default:
  1094. return false;
  1095. }
  1096. return false;
  1097. }
  1098. static int axp20x_regulator_probe(struct platform_device *pdev)
  1099. {
  1100. struct regulator_dev *rdev;
  1101. struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
  1102. const struct regulator_desc *regulators;
  1103. struct regulator_config config = {
  1104. .dev = pdev->dev.parent,
  1105. .regmap = axp20x->regmap,
  1106. .driver_data = axp20x,
  1107. };
  1108. int ret, i, nregulators;
  1109. u32 workmode;
  1110. const char *dcdc1_name = axp22x_regulators[AXP22X_DCDC1].name;
  1111. const char *dcdc5_name = axp22x_regulators[AXP22X_DCDC5].name;
  1112. bool drivevbus = false;
  1113. switch (axp20x->variant) {
  1114. case AXP202_ID:
  1115. case AXP209_ID:
  1116. regulators = axp20x_regulators;
  1117. nregulators = AXP20X_REG_ID_MAX;
  1118. break;
  1119. case AXP221_ID:
  1120. case AXP223_ID:
  1121. regulators = axp22x_regulators;
  1122. nregulators = AXP22X_REG_ID_MAX;
  1123. drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
  1124. "x-powers,drive-vbus-en");
  1125. break;
  1126. case AXP803_ID:
  1127. regulators = axp803_regulators;
  1128. nregulators = AXP803_REG_ID_MAX;
  1129. drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
  1130. "x-powers,drive-vbus-en");
  1131. break;
  1132. case AXP806_ID:
  1133. regulators = axp806_regulators;
  1134. nregulators = AXP806_REG_ID_MAX;
  1135. break;
  1136. case AXP809_ID:
  1137. regulators = axp809_regulators;
  1138. nregulators = AXP809_REG_ID_MAX;
  1139. break;
  1140. case AXP813_ID:
  1141. regulators = axp813_regulators;
  1142. nregulators = AXP813_REG_ID_MAX;
  1143. drivevbus = of_property_read_bool(pdev->dev.parent->of_node,
  1144. "x-powers,drive-vbus-en");
  1145. break;
  1146. default:
  1147. dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
  1148. axp20x->variant);
  1149. return -EINVAL;
  1150. }
  1151. /* This only sets the dcdc freq. Ignore any errors */
  1152. axp20x_regulator_parse_dt(pdev);
  1153. for (i = 0; i < nregulators; i++) {
  1154. const struct regulator_desc *desc = &regulators[i];
  1155. struct regulator_desc *new_desc;
  1156. /*
  1157. * If this regulator is a slave in a poly-phase setup,
  1158. * skip it, as its controls are bound to the master
  1159. * regulator and won't work.
  1160. */
  1161. if (axp20x_is_polyphase_slave(axp20x, i))
  1162. continue;
  1163. /* Support for AXP813's FLDO3 is not implemented */
  1164. if (axp20x->variant == AXP813_ID && i == AXP813_FLDO3)
  1165. continue;
  1166. /*
  1167. * Regulators DC1SW and DC5LDO are connected internally,
  1168. * so we have to handle their supply names separately.
  1169. *
  1170. * We always register the regulators in proper sequence,
  1171. * so the supply names are correctly read. See the last
  1172. * part of this loop to see where we save the DT defined
  1173. * name.
  1174. */
  1175. if ((regulators == axp22x_regulators && i == AXP22X_DC1SW) ||
  1176. (regulators == axp803_regulators && i == AXP803_DC1SW) ||
  1177. (regulators == axp809_regulators && i == AXP809_DC1SW)) {
  1178. new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
  1179. GFP_KERNEL);
  1180. if (!new_desc)
  1181. return -ENOMEM;
  1182. *new_desc = regulators[i];
  1183. new_desc->supply_name = dcdc1_name;
  1184. desc = new_desc;
  1185. }
  1186. if ((regulators == axp22x_regulators && i == AXP22X_DC5LDO) ||
  1187. (regulators == axp809_regulators && i == AXP809_DC5LDO)) {
  1188. new_desc = devm_kzalloc(&pdev->dev, sizeof(*desc),
  1189. GFP_KERNEL);
  1190. if (!new_desc)
  1191. return -ENOMEM;
  1192. *new_desc = regulators[i];
  1193. new_desc->supply_name = dcdc5_name;
  1194. desc = new_desc;
  1195. }
  1196. rdev = devm_regulator_register(&pdev->dev, desc, &config);
  1197. if (IS_ERR(rdev)) {
  1198. dev_err(&pdev->dev, "Failed to register %s\n",
  1199. regulators[i].name);
  1200. return PTR_ERR(rdev);
  1201. }
  1202. ret = of_property_read_u32(rdev->dev.of_node,
  1203. "x-powers,dcdc-workmode",
  1204. &workmode);
  1205. if (!ret) {
  1206. if (axp20x_set_dcdc_workmode(rdev, i, workmode))
  1207. dev_err(&pdev->dev, "Failed to set workmode on %s\n",
  1208. rdev->desc->name);
  1209. }
  1210. /*
  1211. * Save AXP22X DCDC1 / DCDC5 regulator names for later.
  1212. */
  1213. if ((regulators == axp22x_regulators && i == AXP22X_DCDC1) ||
  1214. (regulators == axp809_regulators && i == AXP809_DCDC1))
  1215. of_property_read_string(rdev->dev.of_node,
  1216. "regulator-name",
  1217. &dcdc1_name);
  1218. if ((regulators == axp22x_regulators && i == AXP22X_DCDC5) ||
  1219. (regulators == axp809_regulators && i == AXP809_DCDC5))
  1220. of_property_read_string(rdev->dev.of_node,
  1221. "regulator-name",
  1222. &dcdc5_name);
  1223. }
  1224. if (drivevbus) {
  1225. /* Change N_VBUSEN sense pin to DRIVEVBUS output pin */
  1226. regmap_update_bits(axp20x->regmap, AXP20X_OVER_TMP,
  1227. AXP22X_MISC_N_VBUSEN_FUNC, 0);
  1228. rdev = devm_regulator_register(&pdev->dev,
  1229. &axp22x_drivevbus_regulator,
  1230. &config);
  1231. if (IS_ERR(rdev)) {
  1232. dev_err(&pdev->dev, "Failed to register drivevbus\n");
  1233. return PTR_ERR(rdev);
  1234. }
  1235. }
  1236. return 0;
  1237. }
  1238. static struct platform_driver axp20x_regulator_driver = {
  1239. .probe = axp20x_regulator_probe,
  1240. .driver = {
  1241. .name = "axp20x-regulator",
  1242. },
  1243. };
  1244. module_platform_driver(axp20x_regulator_driver);
  1245. MODULE_LICENSE("GPL v2");
  1246. MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
  1247. MODULE_DESCRIPTION("Regulator Driver for AXP20X PMIC");
  1248. MODULE_ALIAS("platform:axp20x-regulator");