mtk-pmic-wrap.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2014 MediaTek Inc.
  4. * Author: Flora Fu, MediaTek
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/io.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/regmap.h>
  14. #include <linux/reset.h>
  15. #define PWRAP_MT8135_BRIDGE_IORD_ARB_EN 0x4
  16. #define PWRAP_MT8135_BRIDGE_WACS3_EN 0x10
  17. #define PWRAP_MT8135_BRIDGE_INIT_DONE3 0x14
  18. #define PWRAP_MT8135_BRIDGE_WACS4_EN 0x24
  19. #define PWRAP_MT8135_BRIDGE_INIT_DONE4 0x28
  20. #define PWRAP_MT8135_BRIDGE_INT_EN 0x38
  21. #define PWRAP_MT8135_BRIDGE_TIMER_EN 0x48
  22. #define PWRAP_MT8135_BRIDGE_WDT_UNIT 0x50
  23. #define PWRAP_MT8135_BRIDGE_WDT_SRC_EN 0x54
  24. /* macro for wrapper status */
  25. #define PWRAP_GET_WACS_RDATA(x) (((x) >> 0) & 0x0000ffff)
  26. #define PWRAP_GET_WACS_FSM(x) (((x) >> 16) & 0x00000007)
  27. #define PWRAP_GET_WACS_REQ(x) (((x) >> 19) & 0x00000001)
  28. #define PWRAP_STATE_SYNC_IDLE0 (1 << 20)
  29. #define PWRAP_STATE_INIT_DONE0 (1 << 21)
  30. /* macro for WACS FSM */
  31. #define PWRAP_WACS_FSM_IDLE 0x00
  32. #define PWRAP_WACS_FSM_REQ 0x02
  33. #define PWRAP_WACS_FSM_WFDLE 0x04
  34. #define PWRAP_WACS_FSM_WFVLDCLR 0x06
  35. #define PWRAP_WACS_INIT_DONE 0x01
  36. #define PWRAP_WACS_WACS_SYNC_IDLE 0x01
  37. #define PWRAP_WACS_SYNC_BUSY 0x00
  38. /* macro for device wrapper default value */
  39. #define PWRAP_DEW_READ_TEST_VAL 0x5aa5
  40. #define PWRAP_DEW_WRITE_TEST_VAL 0xa55a
  41. /* macro for manual command */
  42. #define PWRAP_MAN_CMD_SPI_WRITE_NEW (1 << 14)
  43. #define PWRAP_MAN_CMD_SPI_WRITE (1 << 13)
  44. #define PWRAP_MAN_CMD_OP_CSH (0x0 << 8)
  45. #define PWRAP_MAN_CMD_OP_CSL (0x1 << 8)
  46. #define PWRAP_MAN_CMD_OP_CK (0x2 << 8)
  47. #define PWRAP_MAN_CMD_OP_OUTS (0x8 << 8)
  48. #define PWRAP_MAN_CMD_OP_OUTD (0x9 << 8)
  49. #define PWRAP_MAN_CMD_OP_OUTQ (0xa << 8)
  50. /* macro for Watch Dog Timer Source */
  51. #define PWRAP_WDT_SRC_EN_STAUPD_TRIG (1 << 25)
  52. #define PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE (1 << 20)
  53. #define PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE (1 << 6)
  54. #define PWRAP_WDT_SRC_MASK_ALL 0xffffffff
  55. #define PWRAP_WDT_SRC_MASK_NO_STAUPD ~(PWRAP_WDT_SRC_EN_STAUPD_TRIG | \
  56. PWRAP_WDT_SRC_EN_HARB_STAUPD_DLE | \
  57. PWRAP_WDT_SRC_EN_HARB_STAUPD_ALE)
  58. /* Group of bits used for shown slave capability */
  59. #define PWRAP_SLV_CAP_SPI BIT(0)
  60. #define PWRAP_SLV_CAP_DUALIO BIT(1)
  61. #define PWRAP_SLV_CAP_SECURITY BIT(2)
  62. #define HAS_CAP(_c, _x) (((_c) & (_x)) == (_x))
  63. /* Group of bits used for shown pwrap capability */
  64. #define PWRAP_CAP_BRIDGE BIT(0)
  65. #define PWRAP_CAP_RESET BIT(1)
  66. #define PWRAP_CAP_DCM BIT(2)
  67. #define PWRAP_CAP_INT1_EN BIT(3)
  68. #define PWRAP_CAP_WDT_SRC1 BIT(4)
  69. /* defines for slave device wrapper registers */
  70. enum dew_regs {
  71. PWRAP_DEW_BASE,
  72. PWRAP_DEW_DIO_EN,
  73. PWRAP_DEW_READ_TEST,
  74. PWRAP_DEW_WRITE_TEST,
  75. PWRAP_DEW_CRC_EN,
  76. PWRAP_DEW_CRC_VAL,
  77. PWRAP_DEW_MON_GRP_SEL,
  78. PWRAP_DEW_CIPHER_KEY_SEL,
  79. PWRAP_DEW_CIPHER_IV_SEL,
  80. PWRAP_DEW_CIPHER_RDY,
  81. PWRAP_DEW_CIPHER_MODE,
  82. PWRAP_DEW_CIPHER_SWRST,
  83. /* MT6323 only regs */
  84. PWRAP_DEW_CIPHER_EN,
  85. PWRAP_DEW_RDDMY_NO,
  86. /* MT6358 only regs */
  87. PWRAP_SMT_CON1,
  88. PWRAP_DRV_CON1,
  89. PWRAP_FILTER_CON0,
  90. PWRAP_GPIO_PULLEN0_CLR,
  91. PWRAP_RG_SPI_CON0,
  92. PWRAP_RG_SPI_RECORD0,
  93. PWRAP_RG_SPI_CON2,
  94. PWRAP_RG_SPI_CON3,
  95. PWRAP_RG_SPI_CON4,
  96. PWRAP_RG_SPI_CON5,
  97. PWRAP_RG_SPI_CON6,
  98. PWRAP_RG_SPI_CON7,
  99. PWRAP_RG_SPI_CON8,
  100. PWRAP_RG_SPI_CON13,
  101. PWRAP_SPISLV_KEY,
  102. /* MT6397 only regs */
  103. PWRAP_DEW_EVENT_OUT_EN,
  104. PWRAP_DEW_EVENT_SRC_EN,
  105. PWRAP_DEW_EVENT_SRC,
  106. PWRAP_DEW_EVENT_FLAG,
  107. PWRAP_DEW_MON_FLAG_SEL,
  108. PWRAP_DEW_EVENT_TEST,
  109. PWRAP_DEW_CIPHER_LOAD,
  110. PWRAP_DEW_CIPHER_START,
  111. };
  112. static const u32 mt6323_regs[] = {
  113. [PWRAP_DEW_BASE] = 0x0000,
  114. [PWRAP_DEW_DIO_EN] = 0x018a,
  115. [PWRAP_DEW_READ_TEST] = 0x018c,
  116. [PWRAP_DEW_WRITE_TEST] = 0x018e,
  117. [PWRAP_DEW_CRC_EN] = 0x0192,
  118. [PWRAP_DEW_CRC_VAL] = 0x0194,
  119. [PWRAP_DEW_MON_GRP_SEL] = 0x0196,
  120. [PWRAP_DEW_CIPHER_KEY_SEL] = 0x0198,
  121. [PWRAP_DEW_CIPHER_IV_SEL] = 0x019a,
  122. [PWRAP_DEW_CIPHER_EN] = 0x019c,
  123. [PWRAP_DEW_CIPHER_RDY] = 0x019e,
  124. [PWRAP_DEW_CIPHER_MODE] = 0x01a0,
  125. [PWRAP_DEW_CIPHER_SWRST] = 0x01a2,
  126. [PWRAP_DEW_RDDMY_NO] = 0x01a4,
  127. };
  128. static const u32 mt6351_regs[] = {
  129. [PWRAP_DEW_DIO_EN] = 0x02F2,
  130. [PWRAP_DEW_READ_TEST] = 0x02F4,
  131. [PWRAP_DEW_WRITE_TEST] = 0x02F6,
  132. [PWRAP_DEW_CRC_EN] = 0x02FA,
  133. [PWRAP_DEW_CRC_VAL] = 0x02FC,
  134. [PWRAP_DEW_CIPHER_KEY_SEL] = 0x0300,
  135. [PWRAP_DEW_CIPHER_IV_SEL] = 0x0302,
  136. [PWRAP_DEW_CIPHER_EN] = 0x0304,
  137. [PWRAP_DEW_CIPHER_RDY] = 0x0306,
  138. [PWRAP_DEW_CIPHER_MODE] = 0x0308,
  139. [PWRAP_DEW_CIPHER_SWRST] = 0x030A,
  140. [PWRAP_DEW_RDDMY_NO] = 0x030C,
  141. };
  142. static const u32 mt6357_regs[] = {
  143. [PWRAP_DEW_DIO_EN] = 0x040A,
  144. [PWRAP_DEW_READ_TEST] = 0x040C,
  145. [PWRAP_DEW_WRITE_TEST] = 0x040E,
  146. [PWRAP_DEW_CRC_EN] = 0x0412,
  147. [PWRAP_DEW_CRC_VAL] = 0x0414,
  148. [PWRAP_DEW_CIPHER_KEY_SEL] = 0x0418,
  149. [PWRAP_DEW_CIPHER_IV_SEL] = 0x041A,
  150. [PWRAP_DEW_CIPHER_EN] = 0x041C,
  151. [PWRAP_DEW_CIPHER_RDY] = 0x041E,
  152. [PWRAP_DEW_CIPHER_MODE] = 0x0420,
  153. [PWRAP_DEW_CIPHER_SWRST] = 0x0422,
  154. [PWRAP_DEW_RDDMY_NO] = 0x0424,
  155. };
  156. static const u32 mt6358_regs[] = {
  157. [PWRAP_SMT_CON1] = 0x0030,
  158. [PWRAP_DRV_CON1] = 0x0038,
  159. [PWRAP_FILTER_CON0] = 0x0040,
  160. [PWRAP_GPIO_PULLEN0_CLR] = 0x0098,
  161. [PWRAP_RG_SPI_CON0] = 0x0408,
  162. [PWRAP_RG_SPI_RECORD0] = 0x040a,
  163. [PWRAP_DEW_DIO_EN] = 0x040c,
  164. [PWRAP_DEW_READ_TEST] = 0x040e,
  165. [PWRAP_DEW_WRITE_TEST] = 0x0410,
  166. [PWRAP_DEW_CRC_EN] = 0x0414,
  167. [PWRAP_DEW_CIPHER_KEY_SEL] = 0x041a,
  168. [PWRAP_DEW_CIPHER_IV_SEL] = 0x041c,
  169. [PWRAP_DEW_CIPHER_EN] = 0x041e,
  170. [PWRAP_DEW_CIPHER_RDY] = 0x0420,
  171. [PWRAP_DEW_CIPHER_MODE] = 0x0422,
  172. [PWRAP_DEW_CIPHER_SWRST] = 0x0424,
  173. [PWRAP_RG_SPI_CON2] = 0x0432,
  174. [PWRAP_RG_SPI_CON3] = 0x0434,
  175. [PWRAP_RG_SPI_CON4] = 0x0436,
  176. [PWRAP_RG_SPI_CON5] = 0x0438,
  177. [PWRAP_RG_SPI_CON6] = 0x043a,
  178. [PWRAP_RG_SPI_CON7] = 0x043c,
  179. [PWRAP_RG_SPI_CON8] = 0x043e,
  180. [PWRAP_RG_SPI_CON13] = 0x0448,
  181. [PWRAP_SPISLV_KEY] = 0x044a,
  182. };
  183. static const u32 mt6397_regs[] = {
  184. [PWRAP_DEW_BASE] = 0xbc00,
  185. [PWRAP_DEW_EVENT_OUT_EN] = 0xbc00,
  186. [PWRAP_DEW_DIO_EN] = 0xbc02,
  187. [PWRAP_DEW_EVENT_SRC_EN] = 0xbc04,
  188. [PWRAP_DEW_EVENT_SRC] = 0xbc06,
  189. [PWRAP_DEW_EVENT_FLAG] = 0xbc08,
  190. [PWRAP_DEW_READ_TEST] = 0xbc0a,
  191. [PWRAP_DEW_WRITE_TEST] = 0xbc0c,
  192. [PWRAP_DEW_CRC_EN] = 0xbc0e,
  193. [PWRAP_DEW_CRC_VAL] = 0xbc10,
  194. [PWRAP_DEW_MON_GRP_SEL] = 0xbc12,
  195. [PWRAP_DEW_MON_FLAG_SEL] = 0xbc14,
  196. [PWRAP_DEW_EVENT_TEST] = 0xbc16,
  197. [PWRAP_DEW_CIPHER_KEY_SEL] = 0xbc18,
  198. [PWRAP_DEW_CIPHER_IV_SEL] = 0xbc1a,
  199. [PWRAP_DEW_CIPHER_LOAD] = 0xbc1c,
  200. [PWRAP_DEW_CIPHER_START] = 0xbc1e,
  201. [PWRAP_DEW_CIPHER_RDY] = 0xbc20,
  202. [PWRAP_DEW_CIPHER_MODE] = 0xbc22,
  203. [PWRAP_DEW_CIPHER_SWRST] = 0xbc24,
  204. };
  205. enum pwrap_regs {
  206. PWRAP_MUX_SEL,
  207. PWRAP_WRAP_EN,
  208. PWRAP_DIO_EN,
  209. PWRAP_SIDLY,
  210. PWRAP_CSHEXT_WRITE,
  211. PWRAP_CSHEXT_READ,
  212. PWRAP_CSLEXT_START,
  213. PWRAP_CSLEXT_END,
  214. PWRAP_STAUPD_PRD,
  215. PWRAP_STAUPD_GRPEN,
  216. PWRAP_STAUPD_MAN_TRIG,
  217. PWRAP_STAUPD_STA,
  218. PWRAP_WRAP_STA,
  219. PWRAP_HARB_INIT,
  220. PWRAP_HARB_HPRIO,
  221. PWRAP_HIPRIO_ARB_EN,
  222. PWRAP_HARB_STA0,
  223. PWRAP_HARB_STA1,
  224. PWRAP_MAN_EN,
  225. PWRAP_MAN_CMD,
  226. PWRAP_MAN_RDATA,
  227. PWRAP_MAN_VLDCLR,
  228. PWRAP_WACS0_EN,
  229. PWRAP_INIT_DONE0,
  230. PWRAP_WACS0_CMD,
  231. PWRAP_WACS0_RDATA,
  232. PWRAP_WACS0_VLDCLR,
  233. PWRAP_WACS1_EN,
  234. PWRAP_INIT_DONE1,
  235. PWRAP_WACS1_CMD,
  236. PWRAP_WACS1_RDATA,
  237. PWRAP_WACS1_VLDCLR,
  238. PWRAP_WACS2_EN,
  239. PWRAP_INIT_DONE2,
  240. PWRAP_WACS2_CMD,
  241. PWRAP_WACS2_RDATA,
  242. PWRAP_WACS2_VLDCLR,
  243. PWRAP_INT_EN,
  244. PWRAP_INT_FLG_RAW,
  245. PWRAP_INT_FLG,
  246. PWRAP_INT_CLR,
  247. PWRAP_SIG_ADR,
  248. PWRAP_SIG_MODE,
  249. PWRAP_SIG_VALUE,
  250. PWRAP_SIG_ERRVAL,
  251. PWRAP_CRC_EN,
  252. PWRAP_TIMER_EN,
  253. PWRAP_TIMER_STA,
  254. PWRAP_WDT_UNIT,
  255. PWRAP_WDT_SRC_EN,
  256. PWRAP_WDT_FLG,
  257. PWRAP_DEBUG_INT_SEL,
  258. PWRAP_CIPHER_KEY_SEL,
  259. PWRAP_CIPHER_IV_SEL,
  260. PWRAP_CIPHER_RDY,
  261. PWRAP_CIPHER_MODE,
  262. PWRAP_CIPHER_SWRST,
  263. PWRAP_DCM_EN,
  264. PWRAP_DCM_DBC_PRD,
  265. PWRAP_EINT_STA0_ADR,
  266. PWRAP_EINT_STA1_ADR,
  267. /* MT2701 only regs */
  268. PWRAP_ADC_CMD_ADDR,
  269. PWRAP_PWRAP_ADC_CMD,
  270. PWRAP_ADC_RDY_ADDR,
  271. PWRAP_ADC_RDATA_ADDR1,
  272. PWRAP_ADC_RDATA_ADDR2,
  273. /* MT7622 only regs */
  274. PWRAP_STA,
  275. PWRAP_CLR,
  276. PWRAP_DVFS_ADR8,
  277. PWRAP_DVFS_WDATA8,
  278. PWRAP_DVFS_ADR9,
  279. PWRAP_DVFS_WDATA9,
  280. PWRAP_DVFS_ADR10,
  281. PWRAP_DVFS_WDATA10,
  282. PWRAP_DVFS_ADR11,
  283. PWRAP_DVFS_WDATA11,
  284. PWRAP_DVFS_ADR12,
  285. PWRAP_DVFS_WDATA12,
  286. PWRAP_DVFS_ADR13,
  287. PWRAP_DVFS_WDATA13,
  288. PWRAP_DVFS_ADR14,
  289. PWRAP_DVFS_WDATA14,
  290. PWRAP_DVFS_ADR15,
  291. PWRAP_DVFS_WDATA15,
  292. PWRAP_EXT_CK,
  293. PWRAP_ADC_RDATA_ADDR,
  294. PWRAP_GPS_STA,
  295. PWRAP_SW_RST,
  296. PWRAP_DVFS_STEP_CTRL0,
  297. PWRAP_DVFS_STEP_CTRL1,
  298. PWRAP_DVFS_STEP_CTRL2,
  299. PWRAP_SPI2_CTRL,
  300. /* MT8135 only regs */
  301. PWRAP_CSHEXT,
  302. PWRAP_EVENT_IN_EN,
  303. PWRAP_EVENT_DST_EN,
  304. PWRAP_RRARB_INIT,
  305. PWRAP_RRARB_EN,
  306. PWRAP_RRARB_STA0,
  307. PWRAP_RRARB_STA1,
  308. PWRAP_EVENT_STA,
  309. PWRAP_EVENT_STACLR,
  310. PWRAP_CIPHER_LOAD,
  311. PWRAP_CIPHER_START,
  312. /* MT8173 only regs */
  313. PWRAP_RDDMY,
  314. PWRAP_SI_CK_CON,
  315. PWRAP_DVFS_ADR0,
  316. PWRAP_DVFS_WDATA0,
  317. PWRAP_DVFS_ADR1,
  318. PWRAP_DVFS_WDATA1,
  319. PWRAP_DVFS_ADR2,
  320. PWRAP_DVFS_WDATA2,
  321. PWRAP_DVFS_ADR3,
  322. PWRAP_DVFS_WDATA3,
  323. PWRAP_DVFS_ADR4,
  324. PWRAP_DVFS_WDATA4,
  325. PWRAP_DVFS_ADR5,
  326. PWRAP_DVFS_WDATA5,
  327. PWRAP_DVFS_ADR6,
  328. PWRAP_DVFS_WDATA6,
  329. PWRAP_DVFS_ADR7,
  330. PWRAP_DVFS_WDATA7,
  331. PWRAP_SPMINF_STA,
  332. PWRAP_CIPHER_EN,
  333. /* MT8183 only regs */
  334. PWRAP_SI_SAMPLE_CTRL,
  335. PWRAP_CSLEXT_WRITE,
  336. PWRAP_CSLEXT_READ,
  337. PWRAP_EXT_CK_WRITE,
  338. PWRAP_STAUPD_CTRL,
  339. PWRAP_WACS_P2P_EN,
  340. PWRAP_INIT_DONE_P2P,
  341. PWRAP_WACS_MD32_EN,
  342. PWRAP_INIT_DONE_MD32,
  343. PWRAP_INT1_EN,
  344. PWRAP_INT1_FLG,
  345. PWRAP_INT1_CLR,
  346. PWRAP_WDT_SRC_EN_1,
  347. PWRAP_INT_GPS_AUXADC_CMD_ADDR,
  348. PWRAP_INT_GPS_AUXADC_CMD,
  349. PWRAP_INT_GPS_AUXADC_RDATA_ADDR,
  350. PWRAP_EXT_GPS_AUXADC_RDATA_ADDR,
  351. PWRAP_GPSINF_0_STA,
  352. PWRAP_GPSINF_1_STA,
  353. /* MT8516 only regs */
  354. PWRAP_OP_TYPE,
  355. PWRAP_MSB_FIRST,
  356. };
  357. static int mt2701_regs[] = {
  358. [PWRAP_MUX_SEL] = 0x0,
  359. [PWRAP_WRAP_EN] = 0x4,
  360. [PWRAP_DIO_EN] = 0x8,
  361. [PWRAP_SIDLY] = 0xc,
  362. [PWRAP_RDDMY] = 0x18,
  363. [PWRAP_SI_CK_CON] = 0x1c,
  364. [PWRAP_CSHEXT_WRITE] = 0x20,
  365. [PWRAP_CSHEXT_READ] = 0x24,
  366. [PWRAP_CSLEXT_START] = 0x28,
  367. [PWRAP_CSLEXT_END] = 0x2c,
  368. [PWRAP_STAUPD_PRD] = 0x30,
  369. [PWRAP_STAUPD_GRPEN] = 0x34,
  370. [PWRAP_STAUPD_MAN_TRIG] = 0x38,
  371. [PWRAP_STAUPD_STA] = 0x3c,
  372. [PWRAP_WRAP_STA] = 0x44,
  373. [PWRAP_HARB_INIT] = 0x48,
  374. [PWRAP_HARB_HPRIO] = 0x4c,
  375. [PWRAP_HIPRIO_ARB_EN] = 0x50,
  376. [PWRAP_HARB_STA0] = 0x54,
  377. [PWRAP_HARB_STA1] = 0x58,
  378. [PWRAP_MAN_EN] = 0x5c,
  379. [PWRAP_MAN_CMD] = 0x60,
  380. [PWRAP_MAN_RDATA] = 0x64,
  381. [PWRAP_MAN_VLDCLR] = 0x68,
  382. [PWRAP_WACS0_EN] = 0x6c,
  383. [PWRAP_INIT_DONE0] = 0x70,
  384. [PWRAP_WACS0_CMD] = 0x74,
  385. [PWRAP_WACS0_RDATA] = 0x78,
  386. [PWRAP_WACS0_VLDCLR] = 0x7c,
  387. [PWRAP_WACS1_EN] = 0x80,
  388. [PWRAP_INIT_DONE1] = 0x84,
  389. [PWRAP_WACS1_CMD] = 0x88,
  390. [PWRAP_WACS1_RDATA] = 0x8c,
  391. [PWRAP_WACS1_VLDCLR] = 0x90,
  392. [PWRAP_WACS2_EN] = 0x94,
  393. [PWRAP_INIT_DONE2] = 0x98,
  394. [PWRAP_WACS2_CMD] = 0x9c,
  395. [PWRAP_WACS2_RDATA] = 0xa0,
  396. [PWRAP_WACS2_VLDCLR] = 0xa4,
  397. [PWRAP_INT_EN] = 0xa8,
  398. [PWRAP_INT_FLG_RAW] = 0xac,
  399. [PWRAP_INT_FLG] = 0xb0,
  400. [PWRAP_INT_CLR] = 0xb4,
  401. [PWRAP_SIG_ADR] = 0xb8,
  402. [PWRAP_SIG_MODE] = 0xbc,
  403. [PWRAP_SIG_VALUE] = 0xc0,
  404. [PWRAP_SIG_ERRVAL] = 0xc4,
  405. [PWRAP_CRC_EN] = 0xc8,
  406. [PWRAP_TIMER_EN] = 0xcc,
  407. [PWRAP_TIMER_STA] = 0xd0,
  408. [PWRAP_WDT_UNIT] = 0xd4,
  409. [PWRAP_WDT_SRC_EN] = 0xd8,
  410. [PWRAP_WDT_FLG] = 0xdc,
  411. [PWRAP_DEBUG_INT_SEL] = 0xe0,
  412. [PWRAP_DVFS_ADR0] = 0xe4,
  413. [PWRAP_DVFS_WDATA0] = 0xe8,
  414. [PWRAP_DVFS_ADR1] = 0xec,
  415. [PWRAP_DVFS_WDATA1] = 0xf0,
  416. [PWRAP_DVFS_ADR2] = 0xf4,
  417. [PWRAP_DVFS_WDATA2] = 0xf8,
  418. [PWRAP_DVFS_ADR3] = 0xfc,
  419. [PWRAP_DVFS_WDATA3] = 0x100,
  420. [PWRAP_DVFS_ADR4] = 0x104,
  421. [PWRAP_DVFS_WDATA4] = 0x108,
  422. [PWRAP_DVFS_ADR5] = 0x10c,
  423. [PWRAP_DVFS_WDATA5] = 0x110,
  424. [PWRAP_DVFS_ADR6] = 0x114,
  425. [PWRAP_DVFS_WDATA6] = 0x118,
  426. [PWRAP_DVFS_ADR7] = 0x11c,
  427. [PWRAP_DVFS_WDATA7] = 0x120,
  428. [PWRAP_CIPHER_KEY_SEL] = 0x124,
  429. [PWRAP_CIPHER_IV_SEL] = 0x128,
  430. [PWRAP_CIPHER_EN] = 0x12c,
  431. [PWRAP_CIPHER_RDY] = 0x130,
  432. [PWRAP_CIPHER_MODE] = 0x134,
  433. [PWRAP_CIPHER_SWRST] = 0x138,
  434. [PWRAP_DCM_EN] = 0x13c,
  435. [PWRAP_DCM_DBC_PRD] = 0x140,
  436. [PWRAP_ADC_CMD_ADDR] = 0x144,
  437. [PWRAP_PWRAP_ADC_CMD] = 0x148,
  438. [PWRAP_ADC_RDY_ADDR] = 0x14c,
  439. [PWRAP_ADC_RDATA_ADDR1] = 0x150,
  440. [PWRAP_ADC_RDATA_ADDR2] = 0x154,
  441. };
  442. static int mt6765_regs[] = {
  443. [PWRAP_MUX_SEL] = 0x0,
  444. [PWRAP_WRAP_EN] = 0x4,
  445. [PWRAP_DIO_EN] = 0x8,
  446. [PWRAP_RDDMY] = 0x20,
  447. [PWRAP_CSHEXT_WRITE] = 0x24,
  448. [PWRAP_CSHEXT_READ] = 0x28,
  449. [PWRAP_CSLEXT_START] = 0x2C,
  450. [PWRAP_CSLEXT_END] = 0x30,
  451. [PWRAP_STAUPD_PRD] = 0x3C,
  452. [PWRAP_HARB_HPRIO] = 0x68,
  453. [PWRAP_HIPRIO_ARB_EN] = 0x6C,
  454. [PWRAP_MAN_EN] = 0x7C,
  455. [PWRAP_MAN_CMD] = 0x80,
  456. [PWRAP_WACS0_EN] = 0x8C,
  457. [PWRAP_WACS1_EN] = 0x94,
  458. [PWRAP_WACS2_EN] = 0x9C,
  459. [PWRAP_INIT_DONE2] = 0xA0,
  460. [PWRAP_WACS2_CMD] = 0xC20,
  461. [PWRAP_WACS2_RDATA] = 0xC24,
  462. [PWRAP_WACS2_VLDCLR] = 0xC28,
  463. [PWRAP_INT_EN] = 0xB4,
  464. [PWRAP_INT_FLG_RAW] = 0xB8,
  465. [PWRAP_INT_FLG] = 0xBC,
  466. [PWRAP_INT_CLR] = 0xC0,
  467. [PWRAP_TIMER_EN] = 0xE8,
  468. [PWRAP_WDT_UNIT] = 0xF0,
  469. [PWRAP_WDT_SRC_EN] = 0xF4,
  470. [PWRAP_DCM_EN] = 0x1DC,
  471. [PWRAP_DCM_DBC_PRD] = 0x1E0,
  472. };
  473. static int mt6797_regs[] = {
  474. [PWRAP_MUX_SEL] = 0x0,
  475. [PWRAP_WRAP_EN] = 0x4,
  476. [PWRAP_DIO_EN] = 0x8,
  477. [PWRAP_SIDLY] = 0xC,
  478. [PWRAP_RDDMY] = 0x10,
  479. [PWRAP_CSHEXT_WRITE] = 0x18,
  480. [PWRAP_CSHEXT_READ] = 0x1C,
  481. [PWRAP_CSLEXT_START] = 0x20,
  482. [PWRAP_CSLEXT_END] = 0x24,
  483. [PWRAP_STAUPD_PRD] = 0x28,
  484. [PWRAP_HARB_HPRIO] = 0x50,
  485. [PWRAP_HIPRIO_ARB_EN] = 0x54,
  486. [PWRAP_MAN_EN] = 0x60,
  487. [PWRAP_MAN_CMD] = 0x64,
  488. [PWRAP_WACS0_EN] = 0x70,
  489. [PWRAP_WACS1_EN] = 0x84,
  490. [PWRAP_WACS2_EN] = 0x98,
  491. [PWRAP_INIT_DONE2] = 0x9C,
  492. [PWRAP_WACS2_CMD] = 0xA0,
  493. [PWRAP_WACS2_RDATA] = 0xA4,
  494. [PWRAP_WACS2_VLDCLR] = 0xA8,
  495. [PWRAP_INT_EN] = 0xC0,
  496. [PWRAP_INT_FLG_RAW] = 0xC4,
  497. [PWRAP_INT_FLG] = 0xC8,
  498. [PWRAP_INT_CLR] = 0xCC,
  499. [PWRAP_TIMER_EN] = 0xF4,
  500. [PWRAP_WDT_UNIT] = 0xFC,
  501. [PWRAP_WDT_SRC_EN] = 0x100,
  502. [PWRAP_DCM_EN] = 0x1CC,
  503. [PWRAP_DCM_DBC_PRD] = 0x1D4,
  504. };
  505. static int mt7622_regs[] = {
  506. [PWRAP_MUX_SEL] = 0x0,
  507. [PWRAP_WRAP_EN] = 0x4,
  508. [PWRAP_DIO_EN] = 0x8,
  509. [PWRAP_SIDLY] = 0xC,
  510. [PWRAP_RDDMY] = 0x10,
  511. [PWRAP_SI_CK_CON] = 0x14,
  512. [PWRAP_CSHEXT_WRITE] = 0x18,
  513. [PWRAP_CSHEXT_READ] = 0x1C,
  514. [PWRAP_CSLEXT_START] = 0x20,
  515. [PWRAP_CSLEXT_END] = 0x24,
  516. [PWRAP_STAUPD_PRD] = 0x28,
  517. [PWRAP_STAUPD_GRPEN] = 0x2C,
  518. [PWRAP_EINT_STA0_ADR] = 0x30,
  519. [PWRAP_EINT_STA1_ADR] = 0x34,
  520. [PWRAP_STA] = 0x38,
  521. [PWRAP_CLR] = 0x3C,
  522. [PWRAP_STAUPD_MAN_TRIG] = 0x40,
  523. [PWRAP_STAUPD_STA] = 0x44,
  524. [PWRAP_WRAP_STA] = 0x48,
  525. [PWRAP_HARB_INIT] = 0x4C,
  526. [PWRAP_HARB_HPRIO] = 0x50,
  527. [PWRAP_HIPRIO_ARB_EN] = 0x54,
  528. [PWRAP_HARB_STA0] = 0x58,
  529. [PWRAP_HARB_STA1] = 0x5C,
  530. [PWRAP_MAN_EN] = 0x60,
  531. [PWRAP_MAN_CMD] = 0x64,
  532. [PWRAP_MAN_RDATA] = 0x68,
  533. [PWRAP_MAN_VLDCLR] = 0x6C,
  534. [PWRAP_WACS0_EN] = 0x70,
  535. [PWRAP_INIT_DONE0] = 0x74,
  536. [PWRAP_WACS0_CMD] = 0x78,
  537. [PWRAP_WACS0_RDATA] = 0x7C,
  538. [PWRAP_WACS0_VLDCLR] = 0x80,
  539. [PWRAP_WACS1_EN] = 0x84,
  540. [PWRAP_INIT_DONE1] = 0x88,
  541. [PWRAP_WACS1_CMD] = 0x8C,
  542. [PWRAP_WACS1_RDATA] = 0x90,
  543. [PWRAP_WACS1_VLDCLR] = 0x94,
  544. [PWRAP_WACS2_EN] = 0x98,
  545. [PWRAP_INIT_DONE2] = 0x9C,
  546. [PWRAP_WACS2_CMD] = 0xA0,
  547. [PWRAP_WACS2_RDATA] = 0xA4,
  548. [PWRAP_WACS2_VLDCLR] = 0xA8,
  549. [PWRAP_INT_EN] = 0xAC,
  550. [PWRAP_INT_FLG_RAW] = 0xB0,
  551. [PWRAP_INT_FLG] = 0xB4,
  552. [PWRAP_INT_CLR] = 0xB8,
  553. [PWRAP_SIG_ADR] = 0xBC,
  554. [PWRAP_SIG_MODE] = 0xC0,
  555. [PWRAP_SIG_VALUE] = 0xC4,
  556. [PWRAP_SIG_ERRVAL] = 0xC8,
  557. [PWRAP_CRC_EN] = 0xCC,
  558. [PWRAP_TIMER_EN] = 0xD0,
  559. [PWRAP_TIMER_STA] = 0xD4,
  560. [PWRAP_WDT_UNIT] = 0xD8,
  561. [PWRAP_WDT_SRC_EN] = 0xDC,
  562. [PWRAP_WDT_FLG] = 0xE0,
  563. [PWRAP_DEBUG_INT_SEL] = 0xE4,
  564. [PWRAP_DVFS_ADR0] = 0xE8,
  565. [PWRAP_DVFS_WDATA0] = 0xEC,
  566. [PWRAP_DVFS_ADR1] = 0xF0,
  567. [PWRAP_DVFS_WDATA1] = 0xF4,
  568. [PWRAP_DVFS_ADR2] = 0xF8,
  569. [PWRAP_DVFS_WDATA2] = 0xFC,
  570. [PWRAP_DVFS_ADR3] = 0x100,
  571. [PWRAP_DVFS_WDATA3] = 0x104,
  572. [PWRAP_DVFS_ADR4] = 0x108,
  573. [PWRAP_DVFS_WDATA4] = 0x10C,
  574. [PWRAP_DVFS_ADR5] = 0x110,
  575. [PWRAP_DVFS_WDATA5] = 0x114,
  576. [PWRAP_DVFS_ADR6] = 0x118,
  577. [PWRAP_DVFS_WDATA6] = 0x11C,
  578. [PWRAP_DVFS_ADR7] = 0x120,
  579. [PWRAP_DVFS_WDATA7] = 0x124,
  580. [PWRAP_DVFS_ADR8] = 0x128,
  581. [PWRAP_DVFS_WDATA8] = 0x12C,
  582. [PWRAP_DVFS_ADR9] = 0x130,
  583. [PWRAP_DVFS_WDATA9] = 0x134,
  584. [PWRAP_DVFS_ADR10] = 0x138,
  585. [PWRAP_DVFS_WDATA10] = 0x13C,
  586. [PWRAP_DVFS_ADR11] = 0x140,
  587. [PWRAP_DVFS_WDATA11] = 0x144,
  588. [PWRAP_DVFS_ADR12] = 0x148,
  589. [PWRAP_DVFS_WDATA12] = 0x14C,
  590. [PWRAP_DVFS_ADR13] = 0x150,
  591. [PWRAP_DVFS_WDATA13] = 0x154,
  592. [PWRAP_DVFS_ADR14] = 0x158,
  593. [PWRAP_DVFS_WDATA14] = 0x15C,
  594. [PWRAP_DVFS_ADR15] = 0x160,
  595. [PWRAP_DVFS_WDATA15] = 0x164,
  596. [PWRAP_SPMINF_STA] = 0x168,
  597. [PWRAP_CIPHER_KEY_SEL] = 0x16C,
  598. [PWRAP_CIPHER_IV_SEL] = 0x170,
  599. [PWRAP_CIPHER_EN] = 0x174,
  600. [PWRAP_CIPHER_RDY] = 0x178,
  601. [PWRAP_CIPHER_MODE] = 0x17C,
  602. [PWRAP_CIPHER_SWRST] = 0x180,
  603. [PWRAP_DCM_EN] = 0x184,
  604. [PWRAP_DCM_DBC_PRD] = 0x188,
  605. [PWRAP_EXT_CK] = 0x18C,
  606. [PWRAP_ADC_CMD_ADDR] = 0x190,
  607. [PWRAP_PWRAP_ADC_CMD] = 0x194,
  608. [PWRAP_ADC_RDATA_ADDR] = 0x198,
  609. [PWRAP_GPS_STA] = 0x19C,
  610. [PWRAP_SW_RST] = 0x1A0,
  611. [PWRAP_DVFS_STEP_CTRL0] = 0x238,
  612. [PWRAP_DVFS_STEP_CTRL1] = 0x23C,
  613. [PWRAP_DVFS_STEP_CTRL2] = 0x240,
  614. [PWRAP_SPI2_CTRL] = 0x244,
  615. };
  616. static int mt8135_regs[] = {
  617. [PWRAP_MUX_SEL] = 0x0,
  618. [PWRAP_WRAP_EN] = 0x4,
  619. [PWRAP_DIO_EN] = 0x8,
  620. [PWRAP_SIDLY] = 0xc,
  621. [PWRAP_CSHEXT] = 0x10,
  622. [PWRAP_CSHEXT_WRITE] = 0x14,
  623. [PWRAP_CSHEXT_READ] = 0x18,
  624. [PWRAP_CSLEXT_START] = 0x1c,
  625. [PWRAP_CSLEXT_END] = 0x20,
  626. [PWRAP_STAUPD_PRD] = 0x24,
  627. [PWRAP_STAUPD_GRPEN] = 0x28,
  628. [PWRAP_STAUPD_MAN_TRIG] = 0x2c,
  629. [PWRAP_STAUPD_STA] = 0x30,
  630. [PWRAP_EVENT_IN_EN] = 0x34,
  631. [PWRAP_EVENT_DST_EN] = 0x38,
  632. [PWRAP_WRAP_STA] = 0x3c,
  633. [PWRAP_RRARB_INIT] = 0x40,
  634. [PWRAP_RRARB_EN] = 0x44,
  635. [PWRAP_RRARB_STA0] = 0x48,
  636. [PWRAP_RRARB_STA1] = 0x4c,
  637. [PWRAP_HARB_INIT] = 0x50,
  638. [PWRAP_HARB_HPRIO] = 0x54,
  639. [PWRAP_HIPRIO_ARB_EN] = 0x58,
  640. [PWRAP_HARB_STA0] = 0x5c,
  641. [PWRAP_HARB_STA1] = 0x60,
  642. [PWRAP_MAN_EN] = 0x64,
  643. [PWRAP_MAN_CMD] = 0x68,
  644. [PWRAP_MAN_RDATA] = 0x6c,
  645. [PWRAP_MAN_VLDCLR] = 0x70,
  646. [PWRAP_WACS0_EN] = 0x74,
  647. [PWRAP_INIT_DONE0] = 0x78,
  648. [PWRAP_WACS0_CMD] = 0x7c,
  649. [PWRAP_WACS0_RDATA] = 0x80,
  650. [PWRAP_WACS0_VLDCLR] = 0x84,
  651. [PWRAP_WACS1_EN] = 0x88,
  652. [PWRAP_INIT_DONE1] = 0x8c,
  653. [PWRAP_WACS1_CMD] = 0x90,
  654. [PWRAP_WACS1_RDATA] = 0x94,
  655. [PWRAP_WACS1_VLDCLR] = 0x98,
  656. [PWRAP_WACS2_EN] = 0x9c,
  657. [PWRAP_INIT_DONE2] = 0xa0,
  658. [PWRAP_WACS2_CMD] = 0xa4,
  659. [PWRAP_WACS2_RDATA] = 0xa8,
  660. [PWRAP_WACS2_VLDCLR] = 0xac,
  661. [PWRAP_INT_EN] = 0xb0,
  662. [PWRAP_INT_FLG_RAW] = 0xb4,
  663. [PWRAP_INT_FLG] = 0xb8,
  664. [PWRAP_INT_CLR] = 0xbc,
  665. [PWRAP_SIG_ADR] = 0xc0,
  666. [PWRAP_SIG_MODE] = 0xc4,
  667. [PWRAP_SIG_VALUE] = 0xc8,
  668. [PWRAP_SIG_ERRVAL] = 0xcc,
  669. [PWRAP_CRC_EN] = 0xd0,
  670. [PWRAP_EVENT_STA] = 0xd4,
  671. [PWRAP_EVENT_STACLR] = 0xd8,
  672. [PWRAP_TIMER_EN] = 0xdc,
  673. [PWRAP_TIMER_STA] = 0xe0,
  674. [PWRAP_WDT_UNIT] = 0xe4,
  675. [PWRAP_WDT_SRC_EN] = 0xe8,
  676. [PWRAP_WDT_FLG] = 0xec,
  677. [PWRAP_DEBUG_INT_SEL] = 0xf0,
  678. [PWRAP_CIPHER_KEY_SEL] = 0x134,
  679. [PWRAP_CIPHER_IV_SEL] = 0x138,
  680. [PWRAP_CIPHER_LOAD] = 0x13c,
  681. [PWRAP_CIPHER_START] = 0x140,
  682. [PWRAP_CIPHER_RDY] = 0x144,
  683. [PWRAP_CIPHER_MODE] = 0x148,
  684. [PWRAP_CIPHER_SWRST] = 0x14c,
  685. [PWRAP_DCM_EN] = 0x15c,
  686. [PWRAP_DCM_DBC_PRD] = 0x160,
  687. };
  688. static int mt8173_regs[] = {
  689. [PWRAP_MUX_SEL] = 0x0,
  690. [PWRAP_WRAP_EN] = 0x4,
  691. [PWRAP_DIO_EN] = 0x8,
  692. [PWRAP_SIDLY] = 0xc,
  693. [PWRAP_RDDMY] = 0x10,
  694. [PWRAP_SI_CK_CON] = 0x14,
  695. [PWRAP_CSHEXT_WRITE] = 0x18,
  696. [PWRAP_CSHEXT_READ] = 0x1c,
  697. [PWRAP_CSLEXT_START] = 0x20,
  698. [PWRAP_CSLEXT_END] = 0x24,
  699. [PWRAP_STAUPD_PRD] = 0x28,
  700. [PWRAP_STAUPD_GRPEN] = 0x2c,
  701. [PWRAP_STAUPD_MAN_TRIG] = 0x40,
  702. [PWRAP_STAUPD_STA] = 0x44,
  703. [PWRAP_WRAP_STA] = 0x48,
  704. [PWRAP_HARB_INIT] = 0x4c,
  705. [PWRAP_HARB_HPRIO] = 0x50,
  706. [PWRAP_HIPRIO_ARB_EN] = 0x54,
  707. [PWRAP_HARB_STA0] = 0x58,
  708. [PWRAP_HARB_STA1] = 0x5c,
  709. [PWRAP_MAN_EN] = 0x60,
  710. [PWRAP_MAN_CMD] = 0x64,
  711. [PWRAP_MAN_RDATA] = 0x68,
  712. [PWRAP_MAN_VLDCLR] = 0x6c,
  713. [PWRAP_WACS0_EN] = 0x70,
  714. [PWRAP_INIT_DONE0] = 0x74,
  715. [PWRAP_WACS0_CMD] = 0x78,
  716. [PWRAP_WACS0_RDATA] = 0x7c,
  717. [PWRAP_WACS0_VLDCLR] = 0x80,
  718. [PWRAP_WACS1_EN] = 0x84,
  719. [PWRAP_INIT_DONE1] = 0x88,
  720. [PWRAP_WACS1_CMD] = 0x8c,
  721. [PWRAP_WACS1_RDATA] = 0x90,
  722. [PWRAP_WACS1_VLDCLR] = 0x94,
  723. [PWRAP_WACS2_EN] = 0x98,
  724. [PWRAP_INIT_DONE2] = 0x9c,
  725. [PWRAP_WACS2_CMD] = 0xa0,
  726. [PWRAP_WACS2_RDATA] = 0xa4,
  727. [PWRAP_WACS2_VLDCLR] = 0xa8,
  728. [PWRAP_INT_EN] = 0xac,
  729. [PWRAP_INT_FLG_RAW] = 0xb0,
  730. [PWRAP_INT_FLG] = 0xb4,
  731. [PWRAP_INT_CLR] = 0xb8,
  732. [PWRAP_SIG_ADR] = 0xbc,
  733. [PWRAP_SIG_MODE] = 0xc0,
  734. [PWRAP_SIG_VALUE] = 0xc4,
  735. [PWRAP_SIG_ERRVAL] = 0xc8,
  736. [PWRAP_CRC_EN] = 0xcc,
  737. [PWRAP_TIMER_EN] = 0xd0,
  738. [PWRAP_TIMER_STA] = 0xd4,
  739. [PWRAP_WDT_UNIT] = 0xd8,
  740. [PWRAP_WDT_SRC_EN] = 0xdc,
  741. [PWRAP_WDT_FLG] = 0xe0,
  742. [PWRAP_DEBUG_INT_SEL] = 0xe4,
  743. [PWRAP_DVFS_ADR0] = 0xe8,
  744. [PWRAP_DVFS_WDATA0] = 0xec,
  745. [PWRAP_DVFS_ADR1] = 0xf0,
  746. [PWRAP_DVFS_WDATA1] = 0xf4,
  747. [PWRAP_DVFS_ADR2] = 0xf8,
  748. [PWRAP_DVFS_WDATA2] = 0xfc,
  749. [PWRAP_DVFS_ADR3] = 0x100,
  750. [PWRAP_DVFS_WDATA3] = 0x104,
  751. [PWRAP_DVFS_ADR4] = 0x108,
  752. [PWRAP_DVFS_WDATA4] = 0x10c,
  753. [PWRAP_DVFS_ADR5] = 0x110,
  754. [PWRAP_DVFS_WDATA5] = 0x114,
  755. [PWRAP_DVFS_ADR6] = 0x118,
  756. [PWRAP_DVFS_WDATA6] = 0x11c,
  757. [PWRAP_DVFS_ADR7] = 0x120,
  758. [PWRAP_DVFS_WDATA7] = 0x124,
  759. [PWRAP_SPMINF_STA] = 0x128,
  760. [PWRAP_CIPHER_KEY_SEL] = 0x12c,
  761. [PWRAP_CIPHER_IV_SEL] = 0x130,
  762. [PWRAP_CIPHER_EN] = 0x134,
  763. [PWRAP_CIPHER_RDY] = 0x138,
  764. [PWRAP_CIPHER_MODE] = 0x13c,
  765. [PWRAP_CIPHER_SWRST] = 0x140,
  766. [PWRAP_DCM_EN] = 0x144,
  767. [PWRAP_DCM_DBC_PRD] = 0x148,
  768. };
  769. static int mt8183_regs[] = {
  770. [PWRAP_MUX_SEL] = 0x0,
  771. [PWRAP_WRAP_EN] = 0x4,
  772. [PWRAP_DIO_EN] = 0x8,
  773. [PWRAP_SI_SAMPLE_CTRL] = 0xC,
  774. [PWRAP_RDDMY] = 0x14,
  775. [PWRAP_CSHEXT_WRITE] = 0x18,
  776. [PWRAP_CSHEXT_READ] = 0x1C,
  777. [PWRAP_CSLEXT_WRITE] = 0x20,
  778. [PWRAP_CSLEXT_READ] = 0x24,
  779. [PWRAP_EXT_CK_WRITE] = 0x28,
  780. [PWRAP_STAUPD_CTRL] = 0x30,
  781. [PWRAP_STAUPD_GRPEN] = 0x34,
  782. [PWRAP_EINT_STA0_ADR] = 0x38,
  783. [PWRAP_HARB_HPRIO] = 0x5C,
  784. [PWRAP_HIPRIO_ARB_EN] = 0x60,
  785. [PWRAP_MAN_EN] = 0x70,
  786. [PWRAP_MAN_CMD] = 0x74,
  787. [PWRAP_WACS0_EN] = 0x80,
  788. [PWRAP_INIT_DONE0] = 0x84,
  789. [PWRAP_WACS1_EN] = 0x88,
  790. [PWRAP_INIT_DONE1] = 0x8C,
  791. [PWRAP_WACS2_EN] = 0x90,
  792. [PWRAP_INIT_DONE2] = 0x94,
  793. [PWRAP_WACS_P2P_EN] = 0xA0,
  794. [PWRAP_INIT_DONE_P2P] = 0xA4,
  795. [PWRAP_WACS_MD32_EN] = 0xA8,
  796. [PWRAP_INIT_DONE_MD32] = 0xAC,
  797. [PWRAP_INT_EN] = 0xB0,
  798. [PWRAP_INT_FLG] = 0xB8,
  799. [PWRAP_INT_CLR] = 0xBC,
  800. [PWRAP_INT1_EN] = 0xC0,
  801. [PWRAP_INT1_FLG] = 0xC8,
  802. [PWRAP_INT1_CLR] = 0xCC,
  803. [PWRAP_SIG_ADR] = 0xD0,
  804. [PWRAP_CRC_EN] = 0xE0,
  805. [PWRAP_TIMER_EN] = 0xE4,
  806. [PWRAP_WDT_UNIT] = 0xEC,
  807. [PWRAP_WDT_SRC_EN] = 0xF0,
  808. [PWRAP_WDT_SRC_EN_1] = 0xF4,
  809. [PWRAP_INT_GPS_AUXADC_CMD_ADDR] = 0x1DC,
  810. [PWRAP_INT_GPS_AUXADC_CMD] = 0x1E0,
  811. [PWRAP_INT_GPS_AUXADC_RDATA_ADDR] = 0x1E4,
  812. [PWRAP_EXT_GPS_AUXADC_RDATA_ADDR] = 0x1E8,
  813. [PWRAP_GPSINF_0_STA] = 0x1EC,
  814. [PWRAP_GPSINF_1_STA] = 0x1F0,
  815. [PWRAP_WACS2_CMD] = 0xC20,
  816. [PWRAP_WACS2_RDATA] = 0xC24,
  817. [PWRAP_WACS2_VLDCLR] = 0xC28,
  818. };
  819. static int mt8516_regs[] = {
  820. [PWRAP_MUX_SEL] = 0x0,
  821. [PWRAP_WRAP_EN] = 0x4,
  822. [PWRAP_DIO_EN] = 0x8,
  823. [PWRAP_SIDLY] = 0xc,
  824. [PWRAP_RDDMY] = 0x10,
  825. [PWRAP_SI_CK_CON] = 0x14,
  826. [PWRAP_CSHEXT_WRITE] = 0x18,
  827. [PWRAP_CSHEXT_READ] = 0x1c,
  828. [PWRAP_CSLEXT_START] = 0x20,
  829. [PWRAP_CSLEXT_END] = 0x24,
  830. [PWRAP_STAUPD_PRD] = 0x28,
  831. [PWRAP_STAUPD_GRPEN] = 0x2c,
  832. [PWRAP_STAUPD_MAN_TRIG] = 0x40,
  833. [PWRAP_STAUPD_STA] = 0x44,
  834. [PWRAP_WRAP_STA] = 0x48,
  835. [PWRAP_HARB_INIT] = 0x4c,
  836. [PWRAP_HARB_HPRIO] = 0x50,
  837. [PWRAP_HIPRIO_ARB_EN] = 0x54,
  838. [PWRAP_HARB_STA0] = 0x58,
  839. [PWRAP_HARB_STA1] = 0x5c,
  840. [PWRAP_MAN_EN] = 0x60,
  841. [PWRAP_MAN_CMD] = 0x64,
  842. [PWRAP_MAN_RDATA] = 0x68,
  843. [PWRAP_MAN_VLDCLR] = 0x6c,
  844. [PWRAP_WACS0_EN] = 0x70,
  845. [PWRAP_INIT_DONE0] = 0x74,
  846. [PWRAP_WACS0_CMD] = 0x78,
  847. [PWRAP_WACS0_RDATA] = 0x7c,
  848. [PWRAP_WACS0_VLDCLR] = 0x80,
  849. [PWRAP_WACS1_EN] = 0x84,
  850. [PWRAP_INIT_DONE1] = 0x88,
  851. [PWRAP_WACS1_CMD] = 0x8c,
  852. [PWRAP_WACS1_RDATA] = 0x90,
  853. [PWRAP_WACS1_VLDCLR] = 0x94,
  854. [PWRAP_WACS2_EN] = 0x98,
  855. [PWRAP_INIT_DONE2] = 0x9c,
  856. [PWRAP_WACS2_CMD] = 0xa0,
  857. [PWRAP_WACS2_RDATA] = 0xa4,
  858. [PWRAP_WACS2_VLDCLR] = 0xa8,
  859. [PWRAP_INT_EN] = 0xac,
  860. [PWRAP_INT_FLG_RAW] = 0xb0,
  861. [PWRAP_INT_FLG] = 0xb4,
  862. [PWRAP_INT_CLR] = 0xb8,
  863. [PWRAP_SIG_ADR] = 0xbc,
  864. [PWRAP_SIG_MODE] = 0xc0,
  865. [PWRAP_SIG_VALUE] = 0xc4,
  866. [PWRAP_SIG_ERRVAL] = 0xc8,
  867. [PWRAP_CRC_EN] = 0xcc,
  868. [PWRAP_TIMER_EN] = 0xd0,
  869. [PWRAP_TIMER_STA] = 0xd4,
  870. [PWRAP_WDT_UNIT] = 0xd8,
  871. [PWRAP_WDT_SRC_EN] = 0xdc,
  872. [PWRAP_WDT_FLG] = 0xe0,
  873. [PWRAP_DEBUG_INT_SEL] = 0xe4,
  874. [PWRAP_DVFS_ADR0] = 0xe8,
  875. [PWRAP_DVFS_WDATA0] = 0xec,
  876. [PWRAP_DVFS_ADR1] = 0xf0,
  877. [PWRAP_DVFS_WDATA1] = 0xf4,
  878. [PWRAP_DVFS_ADR2] = 0xf8,
  879. [PWRAP_DVFS_WDATA2] = 0xfc,
  880. [PWRAP_DVFS_ADR3] = 0x100,
  881. [PWRAP_DVFS_WDATA3] = 0x104,
  882. [PWRAP_DVFS_ADR4] = 0x108,
  883. [PWRAP_DVFS_WDATA4] = 0x10c,
  884. [PWRAP_DVFS_ADR5] = 0x110,
  885. [PWRAP_DVFS_WDATA5] = 0x114,
  886. [PWRAP_DVFS_ADR6] = 0x118,
  887. [PWRAP_DVFS_WDATA6] = 0x11c,
  888. [PWRAP_DVFS_ADR7] = 0x120,
  889. [PWRAP_DVFS_WDATA7] = 0x124,
  890. [PWRAP_SPMINF_STA] = 0x128,
  891. [PWRAP_CIPHER_KEY_SEL] = 0x12c,
  892. [PWRAP_CIPHER_IV_SEL] = 0x130,
  893. [PWRAP_CIPHER_EN] = 0x134,
  894. [PWRAP_CIPHER_RDY] = 0x138,
  895. [PWRAP_CIPHER_MODE] = 0x13c,
  896. [PWRAP_CIPHER_SWRST] = 0x140,
  897. [PWRAP_DCM_EN] = 0x144,
  898. [PWRAP_DCM_DBC_PRD] = 0x148,
  899. [PWRAP_SW_RST] = 0x168,
  900. [PWRAP_OP_TYPE] = 0x16c,
  901. [PWRAP_MSB_FIRST] = 0x170,
  902. };
  903. enum pmic_type {
  904. PMIC_MT6323,
  905. PMIC_MT6351,
  906. PMIC_MT6357,
  907. PMIC_MT6358,
  908. PMIC_MT6380,
  909. PMIC_MT6397,
  910. };
  911. enum pwrap_type {
  912. PWRAP_MT2701,
  913. PWRAP_MT6765,
  914. PWRAP_MT6797,
  915. PWRAP_MT7622,
  916. PWRAP_MT8135,
  917. PWRAP_MT8173,
  918. PWRAP_MT8183,
  919. PWRAP_MT8516,
  920. };
  921. struct pmic_wrapper;
  922. struct pwrap_slv_type {
  923. const u32 *dew_regs;
  924. enum pmic_type type;
  925. const struct regmap_config *regmap;
  926. /* Flags indicating the capability for the target slave */
  927. u32 caps;
  928. /*
  929. * pwrap operations are highly associated with the PMIC types,
  930. * so the pointers added increases flexibility allowing determination
  931. * which type is used by the detection through device tree.
  932. */
  933. int (*pwrap_read)(struct pmic_wrapper *wrp, u32 adr, u32 *rdata);
  934. int (*pwrap_write)(struct pmic_wrapper *wrp, u32 adr, u32 wdata);
  935. };
  936. struct pmic_wrapper {
  937. struct device *dev;
  938. void __iomem *base;
  939. struct regmap *regmap;
  940. const struct pmic_wrapper_type *master;
  941. const struct pwrap_slv_type *slave;
  942. struct clk *clk_spi;
  943. struct clk *clk_wrap;
  944. struct reset_control *rstc;
  945. struct reset_control *rstc_bridge;
  946. void __iomem *bridge_base;
  947. };
  948. struct pmic_wrapper_type {
  949. int *regs;
  950. enum pwrap_type type;
  951. u32 arb_en_all;
  952. u32 int_en_all;
  953. u32 int1_en_all;
  954. u32 spi_w;
  955. u32 wdt_src;
  956. /* Flags indicating the capability for the target pwrap */
  957. u32 caps;
  958. int (*init_reg_clock)(struct pmic_wrapper *wrp);
  959. int (*init_soc_specific)(struct pmic_wrapper *wrp);
  960. };
  961. static u32 pwrap_readl(struct pmic_wrapper *wrp, enum pwrap_regs reg)
  962. {
  963. return readl(wrp->base + wrp->master->regs[reg]);
  964. }
  965. static void pwrap_writel(struct pmic_wrapper *wrp, u32 val, enum pwrap_regs reg)
  966. {
  967. writel(val, wrp->base + wrp->master->regs[reg]);
  968. }
  969. static bool pwrap_is_fsm_idle(struct pmic_wrapper *wrp)
  970. {
  971. u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
  972. return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_IDLE;
  973. }
  974. static bool pwrap_is_fsm_vldclr(struct pmic_wrapper *wrp)
  975. {
  976. u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
  977. return PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_WFVLDCLR;
  978. }
  979. /*
  980. * Timeout issue sometimes caused by the last read command
  981. * failed because pmic wrap could not got the FSM_VLDCLR
  982. * in time after finishing WACS2_CMD. It made state machine
  983. * still on FSM_VLDCLR and timeout next time.
  984. * Check the status of FSM and clear the vldclr to recovery the
  985. * error.
  986. */
  987. static inline void pwrap_leave_fsm_vldclr(struct pmic_wrapper *wrp)
  988. {
  989. if (pwrap_is_fsm_vldclr(wrp))
  990. pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
  991. }
  992. static bool pwrap_is_sync_idle(struct pmic_wrapper *wrp)
  993. {
  994. return pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_SYNC_IDLE0;
  995. }
  996. static bool pwrap_is_fsm_idle_and_sync_idle(struct pmic_wrapper *wrp)
  997. {
  998. u32 val = pwrap_readl(wrp, PWRAP_WACS2_RDATA);
  999. return (PWRAP_GET_WACS_FSM(val) == PWRAP_WACS_FSM_IDLE) &&
  1000. (val & PWRAP_STATE_SYNC_IDLE0);
  1001. }
  1002. static int pwrap_wait_for_state(struct pmic_wrapper *wrp,
  1003. bool (*fp)(struct pmic_wrapper *))
  1004. {
  1005. unsigned long timeout;
  1006. timeout = jiffies + usecs_to_jiffies(10000);
  1007. do {
  1008. if (time_after(jiffies, timeout))
  1009. return fp(wrp) ? 0 : -ETIMEDOUT;
  1010. if (fp(wrp))
  1011. return 0;
  1012. } while (1);
  1013. }
  1014. static int pwrap_read16(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
  1015. {
  1016. int ret;
  1017. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  1018. if (ret) {
  1019. pwrap_leave_fsm_vldclr(wrp);
  1020. return ret;
  1021. }
  1022. pwrap_writel(wrp, (adr >> 1) << 16, PWRAP_WACS2_CMD);
  1023. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_vldclr);
  1024. if (ret)
  1025. return ret;
  1026. *rdata = PWRAP_GET_WACS_RDATA(pwrap_readl(wrp, PWRAP_WACS2_RDATA));
  1027. pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
  1028. return 0;
  1029. }
  1030. static int pwrap_read32(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
  1031. {
  1032. int ret, msb;
  1033. *rdata = 0;
  1034. for (msb = 0; msb < 2; msb++) {
  1035. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  1036. if (ret) {
  1037. pwrap_leave_fsm_vldclr(wrp);
  1038. return ret;
  1039. }
  1040. pwrap_writel(wrp, ((msb << 30) | (adr << 16)),
  1041. PWRAP_WACS2_CMD);
  1042. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_vldclr);
  1043. if (ret)
  1044. return ret;
  1045. *rdata += (PWRAP_GET_WACS_RDATA(pwrap_readl(wrp,
  1046. PWRAP_WACS2_RDATA)) << (16 * msb));
  1047. pwrap_writel(wrp, 1, PWRAP_WACS2_VLDCLR);
  1048. }
  1049. return 0;
  1050. }
  1051. static int pwrap_read(struct pmic_wrapper *wrp, u32 adr, u32 *rdata)
  1052. {
  1053. return wrp->slave->pwrap_read(wrp, adr, rdata);
  1054. }
  1055. static int pwrap_write16(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
  1056. {
  1057. int ret;
  1058. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  1059. if (ret) {
  1060. pwrap_leave_fsm_vldclr(wrp);
  1061. return ret;
  1062. }
  1063. pwrap_writel(wrp, (1 << 31) | ((adr >> 1) << 16) | wdata,
  1064. PWRAP_WACS2_CMD);
  1065. return 0;
  1066. }
  1067. static int pwrap_write32(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
  1068. {
  1069. int ret, msb, rdata;
  1070. for (msb = 0; msb < 2; msb++) {
  1071. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle);
  1072. if (ret) {
  1073. pwrap_leave_fsm_vldclr(wrp);
  1074. return ret;
  1075. }
  1076. pwrap_writel(wrp, (1 << 31) | (msb << 30) | (adr << 16) |
  1077. ((wdata >> (msb * 16)) & 0xffff),
  1078. PWRAP_WACS2_CMD);
  1079. /*
  1080. * The pwrap_read operation is the requirement of hardware used
  1081. * for the synchronization between two successive 16-bit
  1082. * pwrap_writel operations composing one 32-bit bus writing.
  1083. * Otherwise, we'll find the result fails on the lower 16-bit
  1084. * pwrap writing.
  1085. */
  1086. if (!msb)
  1087. pwrap_read(wrp, adr, &rdata);
  1088. }
  1089. return 0;
  1090. }
  1091. static int pwrap_write(struct pmic_wrapper *wrp, u32 adr, u32 wdata)
  1092. {
  1093. return wrp->slave->pwrap_write(wrp, adr, wdata);
  1094. }
  1095. static int pwrap_regmap_read(void *context, u32 adr, u32 *rdata)
  1096. {
  1097. return pwrap_read(context, adr, rdata);
  1098. }
  1099. static int pwrap_regmap_write(void *context, u32 adr, u32 wdata)
  1100. {
  1101. return pwrap_write(context, adr, wdata);
  1102. }
  1103. static int pwrap_reset_spislave(struct pmic_wrapper *wrp)
  1104. {
  1105. int ret, i;
  1106. pwrap_writel(wrp, 0, PWRAP_HIPRIO_ARB_EN);
  1107. pwrap_writel(wrp, 0, PWRAP_WRAP_EN);
  1108. pwrap_writel(wrp, 1, PWRAP_MUX_SEL);
  1109. pwrap_writel(wrp, 1, PWRAP_MAN_EN);
  1110. pwrap_writel(wrp, 0, PWRAP_DIO_EN);
  1111. pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_CSL,
  1112. PWRAP_MAN_CMD);
  1113. pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_OUTS,
  1114. PWRAP_MAN_CMD);
  1115. pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_CSH,
  1116. PWRAP_MAN_CMD);
  1117. for (i = 0; i < 4; i++)
  1118. pwrap_writel(wrp, wrp->master->spi_w | PWRAP_MAN_CMD_OP_OUTS,
  1119. PWRAP_MAN_CMD);
  1120. ret = pwrap_wait_for_state(wrp, pwrap_is_sync_idle);
  1121. if (ret) {
  1122. dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
  1123. return ret;
  1124. }
  1125. pwrap_writel(wrp, 0, PWRAP_MAN_EN);
  1126. pwrap_writel(wrp, 0, PWRAP_MUX_SEL);
  1127. return 0;
  1128. }
  1129. /*
  1130. * pwrap_init_sidly - configure serial input delay
  1131. *
  1132. * This configures the serial input delay. We can configure 0, 2, 4 or 6ns
  1133. * delay. Do a read test with all possible values and chose the best delay.
  1134. */
  1135. static int pwrap_init_sidly(struct pmic_wrapper *wrp)
  1136. {
  1137. u32 rdata;
  1138. u32 i;
  1139. u32 pass = 0;
  1140. signed char dly[16] = {
  1141. -1, 0, 1, 0, 2, -1, 1, 1, 3, -1, -1, -1, 3, -1, 2, 1
  1142. };
  1143. for (i = 0; i < 4; i++) {
  1144. pwrap_writel(wrp, i, PWRAP_SIDLY);
  1145. pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_READ_TEST],
  1146. &rdata);
  1147. if (rdata == PWRAP_DEW_READ_TEST_VAL) {
  1148. dev_dbg(wrp->dev, "[Read Test] pass, SIDLY=%x\n", i);
  1149. pass |= 1 << i;
  1150. }
  1151. }
  1152. if (dly[pass] < 0) {
  1153. dev_err(wrp->dev, "sidly pass range 0x%x not continuous\n",
  1154. pass);
  1155. return -EIO;
  1156. }
  1157. pwrap_writel(wrp, dly[pass], PWRAP_SIDLY);
  1158. return 0;
  1159. }
  1160. static int pwrap_init_dual_io(struct pmic_wrapper *wrp)
  1161. {
  1162. int ret;
  1163. u32 rdata;
  1164. /* Enable dual IO mode */
  1165. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_DIO_EN], 1);
  1166. /* Check IDLE & INIT_DONE in advance */
  1167. ret = pwrap_wait_for_state(wrp,
  1168. pwrap_is_fsm_idle_and_sync_idle);
  1169. if (ret) {
  1170. dev_err(wrp->dev, "%s fail, ret=%d\n", __func__, ret);
  1171. return ret;
  1172. }
  1173. pwrap_writel(wrp, 1, PWRAP_DIO_EN);
  1174. /* Read Test */
  1175. pwrap_read(wrp,
  1176. wrp->slave->dew_regs[PWRAP_DEW_READ_TEST], &rdata);
  1177. if (rdata != PWRAP_DEW_READ_TEST_VAL) {
  1178. dev_err(wrp->dev,
  1179. "Read failed on DIO mode: 0x%04x!=0x%04x\n",
  1180. PWRAP_DEW_READ_TEST_VAL, rdata);
  1181. return -EFAULT;
  1182. }
  1183. return 0;
  1184. }
  1185. /*
  1186. * pwrap_init_chip_select_ext is used to configure CS extension time for each
  1187. * phase during data transactions on the pwrap bus.
  1188. */
  1189. static void pwrap_init_chip_select_ext(struct pmic_wrapper *wrp, u8 hext_write,
  1190. u8 hext_read, u8 lext_start,
  1191. u8 lext_end)
  1192. {
  1193. /*
  1194. * After finishing a write and read transaction, extends CS high time
  1195. * to be at least xT of BUS CLK as hext_write and hext_read specifies
  1196. * respectively.
  1197. */
  1198. pwrap_writel(wrp, hext_write, PWRAP_CSHEXT_WRITE);
  1199. pwrap_writel(wrp, hext_read, PWRAP_CSHEXT_READ);
  1200. /*
  1201. * Extends CS low time after CSL and before CSH command to be at
  1202. * least xT of BUS CLK as lext_start and lext_end specifies
  1203. * respectively.
  1204. */
  1205. pwrap_writel(wrp, lext_start, PWRAP_CSLEXT_START);
  1206. pwrap_writel(wrp, lext_end, PWRAP_CSLEXT_END);
  1207. }
  1208. static int pwrap_common_init_reg_clock(struct pmic_wrapper *wrp)
  1209. {
  1210. switch (wrp->master->type) {
  1211. case PWRAP_MT8173:
  1212. pwrap_init_chip_select_ext(wrp, 0, 4, 2, 2);
  1213. break;
  1214. case PWRAP_MT8135:
  1215. pwrap_writel(wrp, 0x4, PWRAP_CSHEXT);
  1216. pwrap_init_chip_select_ext(wrp, 0, 4, 0, 0);
  1217. break;
  1218. default:
  1219. break;
  1220. }
  1221. return 0;
  1222. }
  1223. static int pwrap_mt2701_init_reg_clock(struct pmic_wrapper *wrp)
  1224. {
  1225. switch (wrp->slave->type) {
  1226. case PMIC_MT6397:
  1227. pwrap_writel(wrp, 0xc, PWRAP_RDDMY);
  1228. pwrap_init_chip_select_ext(wrp, 4, 0, 2, 2);
  1229. break;
  1230. case PMIC_MT6323:
  1231. pwrap_writel(wrp, 0x8, PWRAP_RDDMY);
  1232. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_RDDMY_NO],
  1233. 0x8);
  1234. pwrap_init_chip_select_ext(wrp, 5, 0, 2, 2);
  1235. break;
  1236. default:
  1237. break;
  1238. }
  1239. return 0;
  1240. }
  1241. static bool pwrap_is_cipher_ready(struct pmic_wrapper *wrp)
  1242. {
  1243. return pwrap_readl(wrp, PWRAP_CIPHER_RDY) & 1;
  1244. }
  1245. static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)
  1246. {
  1247. u32 rdata;
  1248. int ret;
  1249. ret = pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_RDY],
  1250. &rdata);
  1251. if (ret)
  1252. return false;
  1253. return rdata == 1;
  1254. }
  1255. static int pwrap_init_cipher(struct pmic_wrapper *wrp)
  1256. {
  1257. int ret;
  1258. u32 rdata = 0;
  1259. pwrap_writel(wrp, 0x1, PWRAP_CIPHER_SWRST);
  1260. pwrap_writel(wrp, 0x0, PWRAP_CIPHER_SWRST);
  1261. pwrap_writel(wrp, 0x1, PWRAP_CIPHER_KEY_SEL);
  1262. pwrap_writel(wrp, 0x2, PWRAP_CIPHER_IV_SEL);
  1263. switch (wrp->master->type) {
  1264. case PWRAP_MT8135:
  1265. pwrap_writel(wrp, 1, PWRAP_CIPHER_LOAD);
  1266. pwrap_writel(wrp, 1, PWRAP_CIPHER_START);
  1267. break;
  1268. case PWRAP_MT2701:
  1269. case PWRAP_MT6765:
  1270. case PWRAP_MT6797:
  1271. case PWRAP_MT8173:
  1272. case PWRAP_MT8516:
  1273. pwrap_writel(wrp, 1, PWRAP_CIPHER_EN);
  1274. break;
  1275. case PWRAP_MT7622:
  1276. pwrap_writel(wrp, 0, PWRAP_CIPHER_EN);
  1277. break;
  1278. case PWRAP_MT8183:
  1279. break;
  1280. }
  1281. /* Config cipher mode @PMIC */
  1282. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_SWRST], 0x1);
  1283. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_SWRST], 0x0);
  1284. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_KEY_SEL], 0x1);
  1285. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_IV_SEL], 0x2);
  1286. switch (wrp->slave->type) {
  1287. case PMIC_MT6397:
  1288. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_LOAD],
  1289. 0x1);
  1290. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_START],
  1291. 0x1);
  1292. break;
  1293. case PMIC_MT6323:
  1294. case PMIC_MT6351:
  1295. case PMIC_MT6357:
  1296. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_EN],
  1297. 0x1);
  1298. break;
  1299. default:
  1300. break;
  1301. }
  1302. /* wait for cipher data ready@AP */
  1303. ret = pwrap_wait_for_state(wrp, pwrap_is_cipher_ready);
  1304. if (ret) {
  1305. dev_err(wrp->dev, "cipher data ready@AP fail, ret=%d\n", ret);
  1306. return ret;
  1307. }
  1308. /* wait for cipher data ready@PMIC */
  1309. ret = pwrap_wait_for_state(wrp, pwrap_is_pmic_cipher_ready);
  1310. if (ret) {
  1311. dev_err(wrp->dev,
  1312. "timeout waiting for cipher data ready@PMIC\n");
  1313. return ret;
  1314. }
  1315. /* wait for cipher mode idle */
  1316. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CIPHER_MODE], 0x1);
  1317. ret = pwrap_wait_for_state(wrp, pwrap_is_fsm_idle_and_sync_idle);
  1318. if (ret) {
  1319. dev_err(wrp->dev, "cipher mode idle fail, ret=%d\n", ret);
  1320. return ret;
  1321. }
  1322. pwrap_writel(wrp, 1, PWRAP_CIPHER_MODE);
  1323. /* Write Test */
  1324. if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST],
  1325. PWRAP_DEW_WRITE_TEST_VAL) ||
  1326. pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST],
  1327. &rdata) ||
  1328. (rdata != PWRAP_DEW_WRITE_TEST_VAL)) {
  1329. dev_err(wrp->dev, "rdata=0x%04X\n", rdata);
  1330. return -EFAULT;
  1331. }
  1332. return 0;
  1333. }
  1334. static int pwrap_init_security(struct pmic_wrapper *wrp)
  1335. {
  1336. int ret;
  1337. /* Enable encryption */
  1338. ret = pwrap_init_cipher(wrp);
  1339. if (ret)
  1340. return ret;
  1341. /* Signature checking - using CRC */
  1342. if (pwrap_write(wrp,
  1343. wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1))
  1344. return -EFAULT;
  1345. pwrap_writel(wrp, 0x1, PWRAP_CRC_EN);
  1346. pwrap_writel(wrp, 0x0, PWRAP_SIG_MODE);
  1347. pwrap_writel(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_VAL],
  1348. PWRAP_SIG_ADR);
  1349. pwrap_writel(wrp,
  1350. wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
  1351. return 0;
  1352. }
  1353. static int pwrap_mt8135_init_soc_specific(struct pmic_wrapper *wrp)
  1354. {
  1355. /* enable pwrap events and pwrap bridge in AP side */
  1356. pwrap_writel(wrp, 0x1, PWRAP_EVENT_IN_EN);
  1357. pwrap_writel(wrp, 0xffff, PWRAP_EVENT_DST_EN);
  1358. writel(0x7f, wrp->bridge_base + PWRAP_MT8135_BRIDGE_IORD_ARB_EN);
  1359. writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS3_EN);
  1360. writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WACS4_EN);
  1361. writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_UNIT);
  1362. writel(0xffff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_WDT_SRC_EN);
  1363. writel(0x1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_TIMER_EN);
  1364. writel(0x7ff, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INT_EN);
  1365. /* enable PMIC event out and sources */
  1366. if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_OUT_EN],
  1367. 0x1) ||
  1368. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_SRC_EN],
  1369. 0xffff)) {
  1370. dev_err(wrp->dev, "enable dewrap fail\n");
  1371. return -EFAULT;
  1372. }
  1373. return 0;
  1374. }
  1375. static int pwrap_mt8173_init_soc_specific(struct pmic_wrapper *wrp)
  1376. {
  1377. /* PMIC_DEWRAP enables */
  1378. if (pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_OUT_EN],
  1379. 0x1) ||
  1380. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_EVENT_SRC_EN],
  1381. 0xffff)) {
  1382. dev_err(wrp->dev, "enable dewrap fail\n");
  1383. return -EFAULT;
  1384. }
  1385. return 0;
  1386. }
  1387. static int pwrap_mt2701_init_soc_specific(struct pmic_wrapper *wrp)
  1388. {
  1389. /* GPS_INTF initialization */
  1390. switch (wrp->slave->type) {
  1391. case PMIC_MT6323:
  1392. pwrap_writel(wrp, 0x076c, PWRAP_ADC_CMD_ADDR);
  1393. pwrap_writel(wrp, 0x8000, PWRAP_PWRAP_ADC_CMD);
  1394. pwrap_writel(wrp, 0x072c, PWRAP_ADC_RDY_ADDR);
  1395. pwrap_writel(wrp, 0x072e, PWRAP_ADC_RDATA_ADDR1);
  1396. pwrap_writel(wrp, 0x0730, PWRAP_ADC_RDATA_ADDR2);
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. return 0;
  1402. }
  1403. static int pwrap_mt7622_init_soc_specific(struct pmic_wrapper *wrp)
  1404. {
  1405. pwrap_writel(wrp, 0, PWRAP_STAUPD_PRD);
  1406. /* enable 2wire SPI master */
  1407. pwrap_writel(wrp, 0x8000000, PWRAP_SPI2_CTRL);
  1408. return 0;
  1409. }
  1410. static int pwrap_mt8183_init_soc_specific(struct pmic_wrapper *wrp)
  1411. {
  1412. pwrap_writel(wrp, 0xf5, PWRAP_STAUPD_GRPEN);
  1413. pwrap_write(wrp, wrp->slave->dew_regs[PWRAP_DEW_CRC_EN], 0x1);
  1414. pwrap_writel(wrp, 1, PWRAP_CRC_EN);
  1415. pwrap_writel(wrp, 0x416, PWRAP_SIG_ADR);
  1416. pwrap_writel(wrp, 0x42e, PWRAP_EINT_STA0_ADR);
  1417. pwrap_writel(wrp, 1, PWRAP_WACS_P2P_EN);
  1418. pwrap_writel(wrp, 1, PWRAP_WACS_MD32_EN);
  1419. pwrap_writel(wrp, 1, PWRAP_INIT_DONE_P2P);
  1420. pwrap_writel(wrp, 1, PWRAP_INIT_DONE_MD32);
  1421. return 0;
  1422. }
  1423. static int pwrap_init(struct pmic_wrapper *wrp)
  1424. {
  1425. int ret;
  1426. if (wrp->rstc)
  1427. reset_control_reset(wrp->rstc);
  1428. if (wrp->rstc_bridge)
  1429. reset_control_reset(wrp->rstc_bridge);
  1430. if (wrp->master->type == PWRAP_MT8173) {
  1431. /* Enable DCM */
  1432. pwrap_writel(wrp, 3, PWRAP_DCM_EN);
  1433. pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
  1434. }
  1435. if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
  1436. /* Reset SPI slave */
  1437. ret = pwrap_reset_spislave(wrp);
  1438. if (ret)
  1439. return ret;
  1440. }
  1441. pwrap_writel(wrp, 1, PWRAP_WRAP_EN);
  1442. pwrap_writel(wrp, wrp->master->arb_en_all, PWRAP_HIPRIO_ARB_EN);
  1443. pwrap_writel(wrp, 1, PWRAP_WACS2_EN);
  1444. ret = wrp->master->init_reg_clock(wrp);
  1445. if (ret)
  1446. return ret;
  1447. if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SPI)) {
  1448. /* Setup serial input delay */
  1449. ret = pwrap_init_sidly(wrp);
  1450. if (ret)
  1451. return ret;
  1452. }
  1453. if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_DUALIO)) {
  1454. /* Enable dual I/O mode */
  1455. ret = pwrap_init_dual_io(wrp);
  1456. if (ret)
  1457. return ret;
  1458. }
  1459. if (HAS_CAP(wrp->slave->caps, PWRAP_SLV_CAP_SECURITY)) {
  1460. /* Enable security on bus */
  1461. ret = pwrap_init_security(wrp);
  1462. if (ret)
  1463. return ret;
  1464. }
  1465. if (wrp->master->type == PWRAP_MT8135)
  1466. pwrap_writel(wrp, 0x7, PWRAP_RRARB_EN);
  1467. pwrap_writel(wrp, 0x1, PWRAP_WACS0_EN);
  1468. pwrap_writel(wrp, 0x1, PWRAP_WACS1_EN);
  1469. pwrap_writel(wrp, 0x1, PWRAP_WACS2_EN);
  1470. pwrap_writel(wrp, 0x5, PWRAP_STAUPD_PRD);
  1471. pwrap_writel(wrp, 0xff, PWRAP_STAUPD_GRPEN);
  1472. if (wrp->master->init_soc_specific) {
  1473. ret = wrp->master->init_soc_specific(wrp);
  1474. if (ret)
  1475. return ret;
  1476. }
  1477. /* Setup the init done registers */
  1478. pwrap_writel(wrp, 1, PWRAP_INIT_DONE2);
  1479. pwrap_writel(wrp, 1, PWRAP_INIT_DONE0);
  1480. pwrap_writel(wrp, 1, PWRAP_INIT_DONE1);
  1481. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_BRIDGE)) {
  1482. writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE3);
  1483. writel(1, wrp->bridge_base + PWRAP_MT8135_BRIDGE_INIT_DONE4);
  1484. }
  1485. return 0;
  1486. }
  1487. static irqreturn_t pwrap_interrupt(int irqno, void *dev_id)
  1488. {
  1489. u32 rdata;
  1490. struct pmic_wrapper *wrp = dev_id;
  1491. rdata = pwrap_readl(wrp, PWRAP_INT_FLG);
  1492. dev_err(wrp->dev, "unexpected interrupt int=0x%x\n", rdata);
  1493. pwrap_writel(wrp, 0xffffffff, PWRAP_INT_CLR);
  1494. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_INT1_EN)) {
  1495. rdata = pwrap_readl(wrp, PWRAP_INT1_FLG);
  1496. dev_err(wrp->dev, "unexpected interrupt int1=0x%x\n", rdata);
  1497. pwrap_writel(wrp, 0xffffffff, PWRAP_INT1_CLR);
  1498. }
  1499. return IRQ_HANDLED;
  1500. }
  1501. static const struct regmap_config pwrap_regmap_config16 = {
  1502. .reg_bits = 16,
  1503. .val_bits = 16,
  1504. .reg_stride = 2,
  1505. .reg_read = pwrap_regmap_read,
  1506. .reg_write = pwrap_regmap_write,
  1507. .max_register = 0xffff,
  1508. };
  1509. static const struct regmap_config pwrap_regmap_config32 = {
  1510. .reg_bits = 32,
  1511. .val_bits = 32,
  1512. .reg_stride = 4,
  1513. .reg_read = pwrap_regmap_read,
  1514. .reg_write = pwrap_regmap_write,
  1515. .max_register = 0xffff,
  1516. };
  1517. static const struct pwrap_slv_type pmic_mt6323 = {
  1518. .dew_regs = mt6323_regs,
  1519. .type = PMIC_MT6323,
  1520. .regmap = &pwrap_regmap_config16,
  1521. .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
  1522. PWRAP_SLV_CAP_SECURITY,
  1523. .pwrap_read = pwrap_read16,
  1524. .pwrap_write = pwrap_write16,
  1525. };
  1526. static const struct pwrap_slv_type pmic_mt6351 = {
  1527. .dew_regs = mt6351_regs,
  1528. .type = PMIC_MT6351,
  1529. .regmap = &pwrap_regmap_config16,
  1530. .caps = 0,
  1531. .pwrap_read = pwrap_read16,
  1532. .pwrap_write = pwrap_write16,
  1533. };
  1534. static const struct pwrap_slv_type pmic_mt6357 = {
  1535. .dew_regs = mt6357_regs,
  1536. .type = PMIC_MT6357,
  1537. .regmap = &pwrap_regmap_config16,
  1538. .caps = 0,
  1539. .pwrap_read = pwrap_read16,
  1540. .pwrap_write = pwrap_write16,
  1541. };
  1542. static const struct pwrap_slv_type pmic_mt6358 = {
  1543. .dew_regs = mt6358_regs,
  1544. .type = PMIC_MT6358,
  1545. .regmap = &pwrap_regmap_config16,
  1546. .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO,
  1547. .pwrap_read = pwrap_read16,
  1548. .pwrap_write = pwrap_write16,
  1549. };
  1550. static const struct pwrap_slv_type pmic_mt6380 = {
  1551. .dew_regs = NULL,
  1552. .type = PMIC_MT6380,
  1553. .regmap = &pwrap_regmap_config32,
  1554. .caps = 0,
  1555. .pwrap_read = pwrap_read32,
  1556. .pwrap_write = pwrap_write32,
  1557. };
  1558. static const struct pwrap_slv_type pmic_mt6397 = {
  1559. .dew_regs = mt6397_regs,
  1560. .type = PMIC_MT6397,
  1561. .regmap = &pwrap_regmap_config16,
  1562. .caps = PWRAP_SLV_CAP_SPI | PWRAP_SLV_CAP_DUALIO |
  1563. PWRAP_SLV_CAP_SECURITY,
  1564. .pwrap_read = pwrap_read16,
  1565. .pwrap_write = pwrap_write16,
  1566. };
  1567. static const struct of_device_id of_slave_match_tbl[] = {
  1568. {
  1569. .compatible = "mediatek,mt6323",
  1570. .data = &pmic_mt6323,
  1571. }, {
  1572. .compatible = "mediatek,mt6351",
  1573. .data = &pmic_mt6351,
  1574. }, {
  1575. .compatible = "mediatek,mt6357",
  1576. .data = &pmic_mt6357,
  1577. }, {
  1578. .compatible = "mediatek,mt6358",
  1579. .data = &pmic_mt6358,
  1580. }, {
  1581. /* The MT6380 PMIC only implements a regulator, so we bind it
  1582. * directly instead of using a MFD.
  1583. */
  1584. .compatible = "mediatek,mt6380-regulator",
  1585. .data = &pmic_mt6380,
  1586. }, {
  1587. .compatible = "mediatek,mt6397",
  1588. .data = &pmic_mt6397,
  1589. }, {
  1590. /* sentinel */
  1591. }
  1592. };
  1593. MODULE_DEVICE_TABLE(of, of_slave_match_tbl);
  1594. static const struct pmic_wrapper_type pwrap_mt2701 = {
  1595. .regs = mt2701_regs,
  1596. .type = PWRAP_MT2701,
  1597. .arb_en_all = 0x3f,
  1598. .int_en_all = ~(u32)(BIT(31) | BIT(2)),
  1599. .int1_en_all = 0,
  1600. .spi_w = PWRAP_MAN_CMD_SPI_WRITE_NEW,
  1601. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1602. .caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1603. .init_reg_clock = pwrap_mt2701_init_reg_clock,
  1604. .init_soc_specific = pwrap_mt2701_init_soc_specific,
  1605. };
  1606. static const struct pmic_wrapper_type pwrap_mt6765 = {
  1607. .regs = mt6765_regs,
  1608. .type = PWRAP_MT6765,
  1609. .arb_en_all = 0x3fd35,
  1610. .int_en_all = 0xffffffff,
  1611. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1612. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1613. .caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1614. .init_reg_clock = pwrap_common_init_reg_clock,
  1615. .init_soc_specific = NULL,
  1616. };
  1617. static const struct pmic_wrapper_type pwrap_mt6797 = {
  1618. .regs = mt6797_regs,
  1619. .type = PWRAP_MT6797,
  1620. .arb_en_all = 0x01fff,
  1621. .int_en_all = 0xffffffc6,
  1622. .int1_en_all = 0,
  1623. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1624. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1625. .caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1626. .init_reg_clock = pwrap_common_init_reg_clock,
  1627. .init_soc_specific = NULL,
  1628. };
  1629. static const struct pmic_wrapper_type pwrap_mt7622 = {
  1630. .regs = mt7622_regs,
  1631. .type = PWRAP_MT7622,
  1632. .arb_en_all = 0xff,
  1633. .int_en_all = ~(u32)BIT(31),
  1634. .int1_en_all = 0,
  1635. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1636. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1637. .caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1638. .init_reg_clock = pwrap_common_init_reg_clock,
  1639. .init_soc_specific = pwrap_mt7622_init_soc_specific,
  1640. };
  1641. static const struct pmic_wrapper_type pwrap_mt8135 = {
  1642. .regs = mt8135_regs,
  1643. .type = PWRAP_MT8135,
  1644. .arb_en_all = 0x1ff,
  1645. .int_en_all = ~(u32)(BIT(31) | BIT(1)),
  1646. .int1_en_all = 0,
  1647. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1648. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1649. .caps = PWRAP_CAP_BRIDGE | PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1650. .init_reg_clock = pwrap_common_init_reg_clock,
  1651. .init_soc_specific = pwrap_mt8135_init_soc_specific,
  1652. };
  1653. static const struct pmic_wrapper_type pwrap_mt8173 = {
  1654. .regs = mt8173_regs,
  1655. .type = PWRAP_MT8173,
  1656. .arb_en_all = 0x3f,
  1657. .int_en_all = ~(u32)(BIT(31) | BIT(1)),
  1658. .int1_en_all = 0,
  1659. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1660. .wdt_src = PWRAP_WDT_SRC_MASK_NO_STAUPD,
  1661. .caps = PWRAP_CAP_RESET | PWRAP_CAP_DCM,
  1662. .init_reg_clock = pwrap_common_init_reg_clock,
  1663. .init_soc_specific = pwrap_mt8173_init_soc_specific,
  1664. };
  1665. static const struct pmic_wrapper_type pwrap_mt8183 = {
  1666. .regs = mt8183_regs,
  1667. .type = PWRAP_MT8183,
  1668. .arb_en_all = 0x3fa75,
  1669. .int_en_all = 0xffffffff,
  1670. .int1_en_all = 0xeef7ffff,
  1671. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1672. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1673. .caps = PWRAP_CAP_INT1_EN | PWRAP_CAP_WDT_SRC1,
  1674. .init_reg_clock = pwrap_common_init_reg_clock,
  1675. .init_soc_specific = pwrap_mt8183_init_soc_specific,
  1676. };
  1677. static struct pmic_wrapper_type pwrap_mt8516 = {
  1678. .regs = mt8516_regs,
  1679. .type = PWRAP_MT8516,
  1680. .arb_en_all = 0xff,
  1681. .int_en_all = ~(u32)(BIT(31) | BIT(2)),
  1682. .spi_w = PWRAP_MAN_CMD_SPI_WRITE,
  1683. .wdt_src = PWRAP_WDT_SRC_MASK_ALL,
  1684. .caps = PWRAP_CAP_DCM,
  1685. .init_reg_clock = pwrap_mt2701_init_reg_clock,
  1686. .init_soc_specific = NULL,
  1687. };
  1688. static const struct of_device_id of_pwrap_match_tbl[] = {
  1689. {
  1690. .compatible = "mediatek,mt2701-pwrap",
  1691. .data = &pwrap_mt2701,
  1692. }, {
  1693. .compatible = "mediatek,mt6765-pwrap",
  1694. .data = &pwrap_mt6765,
  1695. }, {
  1696. .compatible = "mediatek,mt6797-pwrap",
  1697. .data = &pwrap_mt6797,
  1698. }, {
  1699. .compatible = "mediatek,mt7622-pwrap",
  1700. .data = &pwrap_mt7622,
  1701. }, {
  1702. .compatible = "mediatek,mt8135-pwrap",
  1703. .data = &pwrap_mt8135,
  1704. }, {
  1705. .compatible = "mediatek,mt8173-pwrap",
  1706. .data = &pwrap_mt8173,
  1707. }, {
  1708. .compatible = "mediatek,mt8183-pwrap",
  1709. .data = &pwrap_mt8183,
  1710. }, {
  1711. .compatible = "mediatek,mt8516-pwrap",
  1712. .data = &pwrap_mt8516,
  1713. }, {
  1714. /* sentinel */
  1715. }
  1716. };
  1717. MODULE_DEVICE_TABLE(of, of_pwrap_match_tbl);
  1718. static int pwrap_probe(struct platform_device *pdev)
  1719. {
  1720. int ret, irq;
  1721. struct pmic_wrapper *wrp;
  1722. struct device_node *np = pdev->dev.of_node;
  1723. const struct of_device_id *of_slave_id = NULL;
  1724. struct resource *res;
  1725. if (np->child)
  1726. of_slave_id = of_match_node(of_slave_match_tbl, np->child);
  1727. if (!of_slave_id) {
  1728. dev_dbg(&pdev->dev, "slave pmic should be defined in dts\n");
  1729. return -EINVAL;
  1730. }
  1731. wrp = devm_kzalloc(&pdev->dev, sizeof(*wrp), GFP_KERNEL);
  1732. if (!wrp)
  1733. return -ENOMEM;
  1734. platform_set_drvdata(pdev, wrp);
  1735. wrp->master = of_device_get_match_data(&pdev->dev);
  1736. wrp->slave = of_slave_id->data;
  1737. wrp->dev = &pdev->dev;
  1738. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwrap");
  1739. wrp->base = devm_ioremap_resource(wrp->dev, res);
  1740. if (IS_ERR(wrp->base))
  1741. return PTR_ERR(wrp->base);
  1742. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_RESET)) {
  1743. wrp->rstc = devm_reset_control_get(wrp->dev, "pwrap");
  1744. if (IS_ERR(wrp->rstc)) {
  1745. ret = PTR_ERR(wrp->rstc);
  1746. dev_dbg(wrp->dev, "cannot get pwrap reset: %d\n", ret);
  1747. return ret;
  1748. }
  1749. }
  1750. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_BRIDGE)) {
  1751. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  1752. "pwrap-bridge");
  1753. wrp->bridge_base = devm_ioremap_resource(wrp->dev, res);
  1754. if (IS_ERR(wrp->bridge_base))
  1755. return PTR_ERR(wrp->bridge_base);
  1756. wrp->rstc_bridge = devm_reset_control_get(wrp->dev,
  1757. "pwrap-bridge");
  1758. if (IS_ERR(wrp->rstc_bridge)) {
  1759. ret = PTR_ERR(wrp->rstc_bridge);
  1760. dev_dbg(wrp->dev,
  1761. "cannot get pwrap-bridge reset: %d\n", ret);
  1762. return ret;
  1763. }
  1764. }
  1765. wrp->clk_spi = devm_clk_get(wrp->dev, "spi");
  1766. if (IS_ERR(wrp->clk_spi)) {
  1767. dev_dbg(wrp->dev, "failed to get clock: %ld\n",
  1768. PTR_ERR(wrp->clk_spi));
  1769. return PTR_ERR(wrp->clk_spi);
  1770. }
  1771. wrp->clk_wrap = devm_clk_get(wrp->dev, "wrap");
  1772. if (IS_ERR(wrp->clk_wrap)) {
  1773. dev_dbg(wrp->dev, "failed to get clock: %ld\n",
  1774. PTR_ERR(wrp->clk_wrap));
  1775. return PTR_ERR(wrp->clk_wrap);
  1776. }
  1777. ret = clk_prepare_enable(wrp->clk_spi);
  1778. if (ret)
  1779. return ret;
  1780. ret = clk_prepare_enable(wrp->clk_wrap);
  1781. if (ret)
  1782. goto err_out1;
  1783. /* Enable internal dynamic clock */
  1784. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_DCM)) {
  1785. pwrap_writel(wrp, 1, PWRAP_DCM_EN);
  1786. pwrap_writel(wrp, 0, PWRAP_DCM_DBC_PRD);
  1787. }
  1788. /*
  1789. * The PMIC could already be initialized by the bootloader.
  1790. * Skip initialization here in this case.
  1791. */
  1792. if (!pwrap_readl(wrp, PWRAP_INIT_DONE2)) {
  1793. ret = pwrap_init(wrp);
  1794. if (ret) {
  1795. dev_dbg(wrp->dev, "init failed with %d\n", ret);
  1796. goto err_out2;
  1797. }
  1798. }
  1799. if (!(pwrap_readl(wrp, PWRAP_WACS2_RDATA) & PWRAP_STATE_INIT_DONE0)) {
  1800. dev_dbg(wrp->dev, "initialization isn't finished\n");
  1801. ret = -ENODEV;
  1802. goto err_out2;
  1803. }
  1804. /* Initialize watchdog, may not be done by the bootloader */
  1805. pwrap_writel(wrp, 0xf, PWRAP_WDT_UNIT);
  1806. /*
  1807. * Since STAUPD was not used on mt8173 platform,
  1808. * so STAUPD of WDT_SRC which should be turned off
  1809. */
  1810. pwrap_writel(wrp, wrp->master->wdt_src, PWRAP_WDT_SRC_EN);
  1811. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_WDT_SRC1))
  1812. pwrap_writel(wrp, wrp->master->wdt_src, PWRAP_WDT_SRC_EN_1);
  1813. pwrap_writel(wrp, 0x1, PWRAP_TIMER_EN);
  1814. pwrap_writel(wrp, wrp->master->int_en_all, PWRAP_INT_EN);
  1815. /*
  1816. * We add INT1 interrupt to handle starvation and request exception
  1817. * If we support it, we should enable it here.
  1818. */
  1819. if (HAS_CAP(wrp->master->caps, PWRAP_CAP_INT1_EN))
  1820. pwrap_writel(wrp, wrp->master->int1_en_all, PWRAP_INT1_EN);
  1821. irq = platform_get_irq(pdev, 0);
  1822. ret = devm_request_irq(wrp->dev, irq, pwrap_interrupt,
  1823. IRQF_TRIGGER_HIGH,
  1824. "mt-pmic-pwrap", wrp);
  1825. if (ret)
  1826. goto err_out2;
  1827. wrp->regmap = devm_regmap_init(wrp->dev, NULL, wrp, wrp->slave->regmap);
  1828. if (IS_ERR(wrp->regmap)) {
  1829. ret = PTR_ERR(wrp->regmap);
  1830. goto err_out2;
  1831. }
  1832. ret = of_platform_populate(np, NULL, NULL, wrp->dev);
  1833. if (ret) {
  1834. dev_dbg(wrp->dev, "failed to create child devices at %pOF\n",
  1835. np);
  1836. goto err_out2;
  1837. }
  1838. return 0;
  1839. err_out2:
  1840. clk_disable_unprepare(wrp->clk_wrap);
  1841. err_out1:
  1842. clk_disable_unprepare(wrp->clk_spi);
  1843. return ret;
  1844. }
  1845. static struct platform_driver pwrap_drv = {
  1846. .driver = {
  1847. .name = "mt-pmic-pwrap",
  1848. .of_match_table = of_match_ptr(of_pwrap_match_tbl),
  1849. },
  1850. .probe = pwrap_probe,
  1851. };
  1852. module_platform_driver(pwrap_drv);
  1853. MODULE_AUTHOR("Flora Fu, MediaTek");
  1854. MODULE_DESCRIPTION("MediaTek MT8135 PMIC Wrapper Driver");
  1855. MODULE_LICENSE("GPL v2");