db8500-prcmu.c 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071
  1. /*
  2. * Copyright (C) STMicroelectronics 2009
  3. * Copyright (C) ST-Ericsson SA 2010
  4. *
  5. * License Terms: GNU General Public License v2
  6. * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
  7. * Author: Sundar Iyer <sundar.iyer@stericsson.com>
  8. * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
  9. *
  10. * U8500 PRCM Unit interface driver
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/delay.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/io.h>
  20. #include <linux/slab.h>
  21. #include <linux/mutex.h>
  22. #include <linux/completion.h>
  23. #include <linux/irq.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/bitops.h>
  26. #include <linux/fs.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/uaccess.h>
  29. #include <linux/mfd/core.h>
  30. #include <linux/mfd/db8500-prcmu.h>
  31. #include <linux/regulator/db8500-prcmu.h>
  32. #include <linux/regulator/machine.h>
  33. #include <mach/hardware.h>
  34. #include <mach/irqs.h>
  35. #include <mach/db8500-regs.h>
  36. #include <mach/id.h>
  37. #include "db8500-prcmu-regs.h"
  38. /* Offset for the firmware version within the TCPM */
  39. #define PRCMU_FW_VERSION_OFFSET 0xA4
  40. /* PRCMU project numbers, defined by PRCMU FW */
  41. #define PRCMU_PROJECT_ID_8500V1_0 1
  42. #define PRCMU_PROJECT_ID_8500V2_0 2
  43. #define PRCMU_PROJECT_ID_8400V2_0 3
  44. /* Index of different voltages to be used when accessing AVSData */
  45. #define PRCM_AVS_BASE 0x2FC
  46. #define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
  47. #define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
  48. #define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
  49. #define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
  50. #define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
  51. #define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
  52. #define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
  53. #define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
  54. #define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
  55. #define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
  56. #define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
  57. #define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
  58. #define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
  59. #define PRCM_AVS_VOLTAGE 0
  60. #define PRCM_AVS_VOLTAGE_MASK 0x3f
  61. #define PRCM_AVS_ISSLOWSTARTUP 6
  62. #define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
  63. #define PRCM_AVS_ISMODEENABLE 7
  64. #define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
  65. #define PRCM_BOOT_STATUS 0xFFF
  66. #define PRCM_ROMCODE_A2P 0xFFE
  67. #define PRCM_ROMCODE_P2A 0xFFD
  68. #define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
  69. #define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
  70. #define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
  71. #define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
  72. #define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
  73. #define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
  74. #define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
  75. #define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
  76. #define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
  77. #define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
  78. /* Req Mailboxes */
  79. #define PRCM_REQ_MB0 0xFDC /* 12 bytes */
  80. #define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
  81. #define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
  82. #define PRCM_REQ_MB3 0xE4C /* 372 bytes */
  83. #define PRCM_REQ_MB4 0xE48 /* 4 bytes */
  84. #define PRCM_REQ_MB5 0xE44 /* 4 bytes */
  85. /* Ack Mailboxes */
  86. #define PRCM_ACK_MB0 0xE08 /* 52 bytes */
  87. #define PRCM_ACK_MB1 0xE04 /* 4 bytes */
  88. #define PRCM_ACK_MB2 0xE00 /* 4 bytes */
  89. #define PRCM_ACK_MB3 0xDFC /* 4 bytes */
  90. #define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
  91. #define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
  92. /* Mailbox 0 headers */
  93. #define MB0H_POWER_STATE_TRANS 0
  94. #define MB0H_CONFIG_WAKEUPS_EXE 1
  95. #define MB0H_READ_WAKEUP_ACK 3
  96. #define MB0H_CONFIG_WAKEUPS_SLEEP 4
  97. #define MB0H_WAKEUP_EXE 2
  98. #define MB0H_WAKEUP_SLEEP 5
  99. /* Mailbox 0 REQs */
  100. #define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
  101. #define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
  102. #define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
  103. #define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
  104. #define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
  105. #define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
  106. /* Mailbox 0 ACKs */
  107. #define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
  108. #define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
  109. #define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
  110. #define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
  111. #define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
  112. #define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
  113. #define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
  114. /* Mailbox 1 headers */
  115. #define MB1H_ARM_APE_OPP 0x0
  116. #define MB1H_RESET_MODEM 0x2
  117. #define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
  118. #define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
  119. #define MB1H_RELEASE_USB_WAKEUP 0x5
  120. /* Mailbox 1 Requests */
  121. #define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
  122. #define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
  123. #define PRCM_REQ_MB1_APE_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x4)
  124. #define PRCM_REQ_MB1_ARM_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x8)
  125. /* Mailbox 1 ACKs */
  126. #define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
  127. #define PRCM_ACK_MB1_CURRENT_APE_OPP (PRCM_ACK_MB1 + 0x1)
  128. #define PRCM_ACK_MB1_APE_VOLTAGE_STATUS (PRCM_ACK_MB1 + 0x2)
  129. #define PRCM_ACK_MB1_DVFS_STATUS (PRCM_ACK_MB1 + 0x3)
  130. /* Mailbox 2 headers */
  131. #define MB2H_DPS 0x0
  132. #define MB2H_AUTO_PWR 0x1
  133. /* Mailbox 2 REQs */
  134. #define PRCM_REQ_MB2_SVA_MMDSP (PRCM_REQ_MB2 + 0x0)
  135. #define PRCM_REQ_MB2_SVA_PIPE (PRCM_REQ_MB2 + 0x1)
  136. #define PRCM_REQ_MB2_SIA_MMDSP (PRCM_REQ_MB2 + 0x2)
  137. #define PRCM_REQ_MB2_SIA_PIPE (PRCM_REQ_MB2 + 0x3)
  138. #define PRCM_REQ_MB2_SGA (PRCM_REQ_MB2 + 0x4)
  139. #define PRCM_REQ_MB2_B2R2_MCDE (PRCM_REQ_MB2 + 0x5)
  140. #define PRCM_REQ_MB2_ESRAM12 (PRCM_REQ_MB2 + 0x6)
  141. #define PRCM_REQ_MB2_ESRAM34 (PRCM_REQ_MB2 + 0x7)
  142. #define PRCM_REQ_MB2_AUTO_PM_SLEEP (PRCM_REQ_MB2 + 0x8)
  143. #define PRCM_REQ_MB2_AUTO_PM_IDLE (PRCM_REQ_MB2 + 0xC)
  144. /* Mailbox 2 ACKs */
  145. #define PRCM_ACK_MB2_DPS_STATUS (PRCM_ACK_MB2 + 0x0)
  146. #define HWACC_PWR_ST_OK 0xFE
  147. /* Mailbox 3 headers */
  148. #define MB3H_ANC 0x0
  149. #define MB3H_SIDETONE 0x1
  150. #define MB3H_SYSCLK 0xE
  151. /* Mailbox 3 Requests */
  152. #define PRCM_REQ_MB3_ANC_FIR_COEFF (PRCM_REQ_MB3 + 0x0)
  153. #define PRCM_REQ_MB3_ANC_IIR_COEFF (PRCM_REQ_MB3 + 0x20)
  154. #define PRCM_REQ_MB3_ANC_SHIFTER (PRCM_REQ_MB3 + 0x60)
  155. #define PRCM_REQ_MB3_ANC_WARP (PRCM_REQ_MB3 + 0x64)
  156. #define PRCM_REQ_MB3_SIDETONE_FIR_GAIN (PRCM_REQ_MB3 + 0x68)
  157. #define PRCM_REQ_MB3_SIDETONE_FIR_COEFF (PRCM_REQ_MB3 + 0x6C)
  158. #define PRCM_REQ_MB3_SYSCLK_MGT (PRCM_REQ_MB3 + 0x16C)
  159. /* Mailbox 4 headers */
  160. #define MB4H_DDR_INIT 0x0
  161. #define MB4H_MEM_ST 0x1
  162. #define MB4H_HOTDOG 0x12
  163. #define MB4H_HOTMON 0x13
  164. #define MB4H_HOT_PERIOD 0x14
  165. /* Mailbox 4 Requests */
  166. #define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
  167. #define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
  168. #define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
  169. #define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
  170. #define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
  171. #define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
  172. #define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
  173. #define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
  174. #define HOTMON_CONFIG_LOW BIT(0)
  175. #define HOTMON_CONFIG_HIGH BIT(1)
  176. /* Mailbox 5 Requests */
  177. #define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
  178. #define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
  179. #define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
  180. #define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
  181. #define PRCMU_I2C_WRITE(slave) \
  182. (((slave) << 1) | (cpu_is_u8500v2() ? BIT(6) : 0))
  183. #define PRCMU_I2C_READ(slave) \
  184. (((slave) << 1) | BIT(0) | (cpu_is_u8500v2() ? BIT(6) : 0))
  185. #define PRCMU_I2C_STOP_EN BIT(3)
  186. /* Mailbox 5 ACKs */
  187. #define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
  188. #define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
  189. #define I2C_WR_OK 0x1
  190. #define I2C_RD_OK 0x2
  191. #define NUM_MB 8
  192. #define MBOX_BIT BIT
  193. #define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
  194. /*
  195. * Wakeups/IRQs
  196. */
  197. #define WAKEUP_BIT_RTC BIT(0)
  198. #define WAKEUP_BIT_RTT0 BIT(1)
  199. #define WAKEUP_BIT_RTT1 BIT(2)
  200. #define WAKEUP_BIT_HSI0 BIT(3)
  201. #define WAKEUP_BIT_HSI1 BIT(4)
  202. #define WAKEUP_BIT_CA_WAKE BIT(5)
  203. #define WAKEUP_BIT_USB BIT(6)
  204. #define WAKEUP_BIT_ABB BIT(7)
  205. #define WAKEUP_BIT_ABB_FIFO BIT(8)
  206. #define WAKEUP_BIT_SYSCLK_OK BIT(9)
  207. #define WAKEUP_BIT_CA_SLEEP BIT(10)
  208. #define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
  209. #define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
  210. #define WAKEUP_BIT_ANC_OK BIT(13)
  211. #define WAKEUP_BIT_SW_ERROR BIT(14)
  212. #define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
  213. #define WAKEUP_BIT_ARM BIT(17)
  214. #define WAKEUP_BIT_HOTMON_LOW BIT(18)
  215. #define WAKEUP_BIT_HOTMON_HIGH BIT(19)
  216. #define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
  217. #define WAKEUP_BIT_GPIO0 BIT(23)
  218. #define WAKEUP_BIT_GPIO1 BIT(24)
  219. #define WAKEUP_BIT_GPIO2 BIT(25)
  220. #define WAKEUP_BIT_GPIO3 BIT(26)
  221. #define WAKEUP_BIT_GPIO4 BIT(27)
  222. #define WAKEUP_BIT_GPIO5 BIT(28)
  223. #define WAKEUP_BIT_GPIO6 BIT(29)
  224. #define WAKEUP_BIT_GPIO7 BIT(30)
  225. #define WAKEUP_BIT_GPIO8 BIT(31)
  226. /*
  227. * This vector maps irq numbers to the bits in the bit field used in
  228. * communication with the PRCMU firmware.
  229. *
  230. * The reason for having this is to keep the irq numbers contiguous even though
  231. * the bits in the bit field are not. (The bits also have a tendency to move
  232. * around, to further complicate matters.)
  233. */
  234. #define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name) - IRQ_PRCMU_BASE)
  235. #define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
  236. static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
  237. IRQ_ENTRY(RTC),
  238. IRQ_ENTRY(RTT0),
  239. IRQ_ENTRY(RTT1),
  240. IRQ_ENTRY(HSI0),
  241. IRQ_ENTRY(HSI1),
  242. IRQ_ENTRY(CA_WAKE),
  243. IRQ_ENTRY(USB),
  244. IRQ_ENTRY(ABB),
  245. IRQ_ENTRY(ABB_FIFO),
  246. IRQ_ENTRY(CA_SLEEP),
  247. IRQ_ENTRY(ARM),
  248. IRQ_ENTRY(HOTMON_LOW),
  249. IRQ_ENTRY(HOTMON_HIGH),
  250. IRQ_ENTRY(MODEM_SW_RESET_REQ),
  251. IRQ_ENTRY(GPIO0),
  252. IRQ_ENTRY(GPIO1),
  253. IRQ_ENTRY(GPIO2),
  254. IRQ_ENTRY(GPIO3),
  255. IRQ_ENTRY(GPIO4),
  256. IRQ_ENTRY(GPIO5),
  257. IRQ_ENTRY(GPIO6),
  258. IRQ_ENTRY(GPIO7),
  259. IRQ_ENTRY(GPIO8)
  260. };
  261. #define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
  262. #define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
  263. static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
  264. WAKEUP_ENTRY(RTC),
  265. WAKEUP_ENTRY(RTT0),
  266. WAKEUP_ENTRY(RTT1),
  267. WAKEUP_ENTRY(HSI0),
  268. WAKEUP_ENTRY(HSI1),
  269. WAKEUP_ENTRY(USB),
  270. WAKEUP_ENTRY(ABB),
  271. WAKEUP_ENTRY(ABB_FIFO),
  272. WAKEUP_ENTRY(ARM)
  273. };
  274. /*
  275. * mb0_transfer - state needed for mailbox 0 communication.
  276. * @lock: The transaction lock.
  277. * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
  278. * the request data.
  279. * @mask_work: Work structure used for (un)masking wakeup interrupts.
  280. * @req: Request data that need to persist between requests.
  281. */
  282. static struct {
  283. spinlock_t lock;
  284. spinlock_t dbb_irqs_lock;
  285. struct work_struct mask_work;
  286. struct mutex ac_wake_lock;
  287. struct completion ac_wake_work;
  288. struct {
  289. u32 dbb_irqs;
  290. u32 dbb_wakeups;
  291. u32 abb_events;
  292. } req;
  293. } mb0_transfer;
  294. /*
  295. * mb1_transfer - state needed for mailbox 1 communication.
  296. * @lock: The transaction lock.
  297. * @work: The transaction completion structure.
  298. * @ack: Reply ("acknowledge") data.
  299. */
  300. static struct {
  301. struct mutex lock;
  302. struct completion work;
  303. struct {
  304. u8 header;
  305. u8 arm_opp;
  306. u8 ape_opp;
  307. u8 ape_voltage_status;
  308. } ack;
  309. } mb1_transfer;
  310. /*
  311. * mb2_transfer - state needed for mailbox 2 communication.
  312. * @lock: The transaction lock.
  313. * @work: The transaction completion structure.
  314. * @auto_pm_lock: The autonomous power management configuration lock.
  315. * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
  316. * @req: Request data that need to persist between requests.
  317. * @ack: Reply ("acknowledge") data.
  318. */
  319. static struct {
  320. struct mutex lock;
  321. struct completion work;
  322. spinlock_t auto_pm_lock;
  323. bool auto_pm_enabled;
  324. struct {
  325. u8 status;
  326. } ack;
  327. } mb2_transfer;
  328. /*
  329. * mb3_transfer - state needed for mailbox 3 communication.
  330. * @lock: The request lock.
  331. * @sysclk_lock: A lock used to handle concurrent sysclk requests.
  332. * @sysclk_work: Work structure used for sysclk requests.
  333. */
  334. static struct {
  335. spinlock_t lock;
  336. struct mutex sysclk_lock;
  337. struct completion sysclk_work;
  338. } mb3_transfer;
  339. /*
  340. * mb4_transfer - state needed for mailbox 4 communication.
  341. * @lock: The transaction lock.
  342. * @work: The transaction completion structure.
  343. */
  344. static struct {
  345. struct mutex lock;
  346. struct completion work;
  347. } mb4_transfer;
  348. /*
  349. * mb5_transfer - state needed for mailbox 5 communication.
  350. * @lock: The transaction lock.
  351. * @work: The transaction completion structure.
  352. * @ack: Reply ("acknowledge") data.
  353. */
  354. static struct {
  355. struct mutex lock;
  356. struct completion work;
  357. struct {
  358. u8 status;
  359. u8 value;
  360. } ack;
  361. } mb5_transfer;
  362. static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
  363. /* Spinlocks */
  364. static DEFINE_SPINLOCK(clkout_lock);
  365. static DEFINE_SPINLOCK(gpiocr_lock);
  366. /* Global var to runtime determine TCDM base for v2 or v1 */
  367. static __iomem void *tcdm_base;
  368. struct clk_mgt {
  369. unsigned int offset;
  370. u32 pllsw;
  371. };
  372. static DEFINE_SPINLOCK(clk_mgt_lock);
  373. #define CLK_MGT_ENTRY(_name)[PRCMU_##_name] = { (PRCM_##_name##_MGT), 0 }
  374. struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
  375. CLK_MGT_ENTRY(SGACLK),
  376. CLK_MGT_ENTRY(UARTCLK),
  377. CLK_MGT_ENTRY(MSP02CLK),
  378. CLK_MGT_ENTRY(MSP1CLK),
  379. CLK_MGT_ENTRY(I2CCLK),
  380. CLK_MGT_ENTRY(SDMMCCLK),
  381. CLK_MGT_ENTRY(SLIMCLK),
  382. CLK_MGT_ENTRY(PER1CLK),
  383. CLK_MGT_ENTRY(PER2CLK),
  384. CLK_MGT_ENTRY(PER3CLK),
  385. CLK_MGT_ENTRY(PER5CLK),
  386. CLK_MGT_ENTRY(PER6CLK),
  387. CLK_MGT_ENTRY(PER7CLK),
  388. CLK_MGT_ENTRY(LCDCLK),
  389. CLK_MGT_ENTRY(BMLCLK),
  390. CLK_MGT_ENTRY(HSITXCLK),
  391. CLK_MGT_ENTRY(HSIRXCLK),
  392. CLK_MGT_ENTRY(HDMICLK),
  393. CLK_MGT_ENTRY(APEATCLK),
  394. CLK_MGT_ENTRY(APETRACECLK),
  395. CLK_MGT_ENTRY(MCDECLK),
  396. CLK_MGT_ENTRY(IPI2CCLK),
  397. CLK_MGT_ENTRY(DSIALTCLK),
  398. CLK_MGT_ENTRY(DMACLK),
  399. CLK_MGT_ENTRY(B2R2CLK),
  400. CLK_MGT_ENTRY(TVCLK),
  401. CLK_MGT_ENTRY(SSPCLK),
  402. CLK_MGT_ENTRY(RNGCLK),
  403. CLK_MGT_ENTRY(UICCCLK),
  404. };
  405. /*
  406. * Used by MCDE to setup all necessary PRCMU registers
  407. */
  408. #define PRCMU_RESET_DSIPLL 0x00004000
  409. #define PRCMU_UNCLAMP_DSIPLL 0x00400800
  410. #define PRCMU_CLK_PLL_DIV_SHIFT 0
  411. #define PRCMU_CLK_PLL_SW_SHIFT 5
  412. #define PRCMU_CLK_38 (1 << 9)
  413. #define PRCMU_CLK_38_SRC (1 << 10)
  414. #define PRCMU_CLK_38_DIV (1 << 11)
  415. /* PLLDIV=12, PLLSW=4 (PLLDDR) */
  416. #define PRCMU_DSI_CLOCK_SETTING 0x0000008C
  417. /* PLLDIV=8, PLLSW=4 (PLLDDR) */
  418. #define PRCMU_DSI_CLOCK_SETTING_U8400 0x00000088
  419. /* DPI 50000000 Hz */
  420. #define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
  421. (16 << PRCMU_CLK_PLL_DIV_SHIFT))
  422. #define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
  423. /* D=101, N=1, R=4, SELDIV2=0 */
  424. #define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
  425. /* D=70, N=1, R=3, SELDIV2=0 */
  426. #define PRCMU_PLLDSI_FREQ_SETTING_U8400 0x00030146
  427. #define PRCMU_ENABLE_PLLDSI 0x00000001
  428. #define PRCMU_DISABLE_PLLDSI 0x00000000
  429. #define PRCMU_RELEASE_RESET_DSS 0x0000400C
  430. #define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
  431. /* ESC clk, div0=1, div1=1, div2=3 */
  432. #define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
  433. #define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
  434. #define PRCMU_DSI_RESET_SW 0x00000007
  435. #define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
  436. static struct {
  437. u8 project_number;
  438. u8 api_version;
  439. u8 func_version;
  440. u8 errata;
  441. } prcmu_version;
  442. int prcmu_enable_dsipll(void)
  443. {
  444. int i;
  445. unsigned int plldsifreq;
  446. /* Clear DSIPLL_RESETN */
  447. writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_CLR));
  448. /* Unclamp DSIPLL in/out */
  449. writel(PRCMU_UNCLAMP_DSIPLL, (_PRCMU_BASE + PRCM_MMIP_LS_CLAMP_CLR));
  450. if (prcmu_is_u8400())
  451. plldsifreq = PRCMU_PLLDSI_FREQ_SETTING_U8400;
  452. else
  453. plldsifreq = PRCMU_PLLDSI_FREQ_SETTING;
  454. /* Set DSI PLL FREQ */
  455. writel(plldsifreq, (_PRCMU_BASE + PRCM_PLLDSI_FREQ));
  456. writel(PRCMU_DSI_PLLOUT_SEL_SETTING,
  457. (_PRCMU_BASE + PRCM_DSI_PLLOUT_SEL));
  458. /* Enable Escape clocks */
  459. writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV,
  460. (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
  461. /* Start DSI PLL */
  462. writel(PRCMU_ENABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE));
  463. /* Reset DSI PLL */
  464. writel(PRCMU_DSI_RESET_SW, (_PRCMU_BASE + PRCM_DSI_SW_RESET));
  465. for (i = 0; i < 10; i++) {
  466. if ((readl(_PRCMU_BASE + PRCM_PLLDSI_LOCKP) &
  467. PRCMU_PLLDSI_LOCKP_LOCKED)
  468. == PRCMU_PLLDSI_LOCKP_LOCKED)
  469. break;
  470. udelay(100);
  471. }
  472. /* Set DSIPLL_RESETN */
  473. writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_SET));
  474. return 0;
  475. }
  476. int prcmu_disable_dsipll(void)
  477. {
  478. /* Disable dsi pll */
  479. writel(PRCMU_DISABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE));
  480. /* Disable escapeclock */
  481. writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV,
  482. (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
  483. return 0;
  484. }
  485. int prcmu_set_display_clocks(void)
  486. {
  487. unsigned long flags;
  488. unsigned int dsiclk;
  489. if (prcmu_is_u8400())
  490. dsiclk = PRCMU_DSI_CLOCK_SETTING_U8400;
  491. else
  492. dsiclk = PRCMU_DSI_CLOCK_SETTING;
  493. spin_lock_irqsave(&clk_mgt_lock, flags);
  494. /* Grab the HW semaphore. */
  495. while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  496. cpu_relax();
  497. writel(dsiclk, (_PRCMU_BASE + PRCM_HDMICLK_MGT));
  498. writel(PRCMU_DSI_LP_CLOCK_SETTING, (_PRCMU_BASE + PRCM_TVCLK_MGT));
  499. writel(PRCMU_DPI_CLOCK_SETTING, (_PRCMU_BASE + PRCM_LCDCLK_MGT));
  500. /* Release the HW semaphore. */
  501. writel(0, (_PRCMU_BASE + PRCM_SEM));
  502. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  503. return 0;
  504. }
  505. /**
  506. * prcmu_enable_spi2 - Enables pin muxing for SPI2 on OtherAlternateC1.
  507. */
  508. void prcmu_enable_spi2(void)
  509. {
  510. u32 reg;
  511. unsigned long flags;
  512. spin_lock_irqsave(&gpiocr_lock, flags);
  513. reg = readl(_PRCMU_BASE + PRCM_GPIOCR);
  514. writel(reg | PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR);
  515. spin_unlock_irqrestore(&gpiocr_lock, flags);
  516. }
  517. /**
  518. * prcmu_disable_spi2 - Disables pin muxing for SPI2 on OtherAlternateC1.
  519. */
  520. void prcmu_disable_spi2(void)
  521. {
  522. u32 reg;
  523. unsigned long flags;
  524. spin_lock_irqsave(&gpiocr_lock, flags);
  525. reg = readl(_PRCMU_BASE + PRCM_GPIOCR);
  526. writel(reg & ~PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR);
  527. spin_unlock_irqrestore(&gpiocr_lock, flags);
  528. }
  529. bool prcmu_has_arm_maxopp(void)
  530. {
  531. return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
  532. PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
  533. }
  534. bool prcmu_is_u8400(void)
  535. {
  536. return prcmu_version.project_number == PRCMU_PROJECT_ID_8400V2_0;
  537. }
  538. /**
  539. * prcmu_get_boot_status - PRCMU boot status checking
  540. * Returns: the current PRCMU boot status
  541. */
  542. int prcmu_get_boot_status(void)
  543. {
  544. return readb(tcdm_base + PRCM_BOOT_STATUS);
  545. }
  546. /**
  547. * prcmu_set_rc_a2p - This function is used to run few power state sequences
  548. * @val: Value to be set, i.e. transition requested
  549. * Returns: 0 on success, -EINVAL on invalid argument
  550. *
  551. * This function is used to run the following power state sequences -
  552. * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
  553. */
  554. int prcmu_set_rc_a2p(enum romcode_write val)
  555. {
  556. if (val < RDY_2_DS || val > RDY_2_XP70_RST)
  557. return -EINVAL;
  558. writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
  559. return 0;
  560. }
  561. /**
  562. * prcmu_get_rc_p2a - This function is used to get power state sequences
  563. * Returns: the power transition that has last happened
  564. *
  565. * This function can return the following transitions-
  566. * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
  567. */
  568. enum romcode_read prcmu_get_rc_p2a(void)
  569. {
  570. return readb(tcdm_base + PRCM_ROMCODE_P2A);
  571. }
  572. /**
  573. * prcmu_get_current_mode - Return the current XP70 power mode
  574. * Returns: Returns the current AP(ARM) power mode: init,
  575. * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
  576. */
  577. enum ap_pwrst prcmu_get_xp70_current_state(void)
  578. {
  579. return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
  580. }
  581. /**
  582. * prcmu_config_clkout - Configure one of the programmable clock outputs.
  583. * @clkout: The CLKOUT number (0 or 1).
  584. * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
  585. * @div: The divider to be applied.
  586. *
  587. * Configures one of the programmable clock outputs (CLKOUTs).
  588. * @div should be in the range [1,63] to request a configuration, or 0 to
  589. * inform that the configuration is no longer requested.
  590. */
  591. int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
  592. {
  593. static int requests[2];
  594. int r = 0;
  595. unsigned long flags;
  596. u32 val;
  597. u32 bits;
  598. u32 mask;
  599. u32 div_mask;
  600. BUG_ON(clkout > 1);
  601. BUG_ON(div > 63);
  602. BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
  603. if (!div && !requests[clkout])
  604. return -EINVAL;
  605. switch (clkout) {
  606. case 0:
  607. div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
  608. mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
  609. bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
  610. (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
  611. break;
  612. case 1:
  613. div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
  614. mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
  615. PRCM_CLKOCR_CLK1TYPE);
  616. bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
  617. (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
  618. break;
  619. }
  620. bits &= mask;
  621. spin_lock_irqsave(&clkout_lock, flags);
  622. val = readl(_PRCMU_BASE + PRCM_CLKOCR);
  623. if (val & div_mask) {
  624. if (div) {
  625. if ((val & mask) != bits) {
  626. r = -EBUSY;
  627. goto unlock_and_return;
  628. }
  629. } else {
  630. if ((val & mask & ~div_mask) != bits) {
  631. r = -EINVAL;
  632. goto unlock_and_return;
  633. }
  634. }
  635. }
  636. writel((bits | (val & ~mask)), (_PRCMU_BASE + PRCM_CLKOCR));
  637. requests[clkout] += (div ? 1 : -1);
  638. unlock_and_return:
  639. spin_unlock_irqrestore(&clkout_lock, flags);
  640. return r;
  641. }
  642. int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
  643. {
  644. unsigned long flags;
  645. BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
  646. spin_lock_irqsave(&mb0_transfer.lock, flags);
  647. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  648. cpu_relax();
  649. writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  650. writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
  651. writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
  652. writeb((keep_ulp_clk ? 1 : 0),
  653. (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
  654. writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
  655. writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  656. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  657. return 0;
  658. }
  659. /* This function should only be called while mb0_transfer.lock is held. */
  660. static void config_wakeups(void)
  661. {
  662. const u8 header[2] = {
  663. MB0H_CONFIG_WAKEUPS_EXE,
  664. MB0H_CONFIG_WAKEUPS_SLEEP
  665. };
  666. static u32 last_dbb_events;
  667. static u32 last_abb_events;
  668. u32 dbb_events;
  669. u32 abb_events;
  670. unsigned int i;
  671. dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
  672. dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
  673. abb_events = mb0_transfer.req.abb_events;
  674. if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
  675. return;
  676. for (i = 0; i < 2; i++) {
  677. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  678. cpu_relax();
  679. writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
  680. writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
  681. writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  682. writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  683. }
  684. last_dbb_events = dbb_events;
  685. last_abb_events = abb_events;
  686. }
  687. void prcmu_enable_wakeups(u32 wakeups)
  688. {
  689. unsigned long flags;
  690. u32 bits;
  691. int i;
  692. BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
  693. for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
  694. if (wakeups & BIT(i))
  695. bits |= prcmu_wakeup_bit[i];
  696. }
  697. spin_lock_irqsave(&mb0_transfer.lock, flags);
  698. mb0_transfer.req.dbb_wakeups = bits;
  699. config_wakeups();
  700. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  701. }
  702. void prcmu_config_abb_event_readout(u32 abb_events)
  703. {
  704. unsigned long flags;
  705. spin_lock_irqsave(&mb0_transfer.lock, flags);
  706. mb0_transfer.req.abb_events = abb_events;
  707. config_wakeups();
  708. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  709. }
  710. void prcmu_get_abb_event_buffer(void __iomem **buf)
  711. {
  712. if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
  713. *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
  714. else
  715. *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
  716. }
  717. /**
  718. * prcmu_set_arm_opp - set the appropriate ARM OPP
  719. * @opp: The new ARM operating point to which transition is to be made
  720. * Returns: 0 on success, non-zero on failure
  721. *
  722. * This function sets the the operating point of the ARM.
  723. */
  724. int prcmu_set_arm_opp(u8 opp)
  725. {
  726. int r;
  727. if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
  728. return -EINVAL;
  729. r = 0;
  730. mutex_lock(&mb1_transfer.lock);
  731. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  732. cpu_relax();
  733. writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  734. writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
  735. writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
  736. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  737. wait_for_completion(&mb1_transfer.work);
  738. if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
  739. (mb1_transfer.ack.arm_opp != opp))
  740. r = -EIO;
  741. mutex_unlock(&mb1_transfer.lock);
  742. return r;
  743. }
  744. /**
  745. * prcmu_get_arm_opp - get the current ARM OPP
  746. *
  747. * Returns: the current ARM OPP
  748. */
  749. int prcmu_get_arm_opp(void)
  750. {
  751. return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
  752. }
  753. /**
  754. * prcmu_get_ddr_opp - get the current DDR OPP
  755. *
  756. * Returns: the current DDR OPP
  757. */
  758. int prcmu_get_ddr_opp(void)
  759. {
  760. return readb(_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW);
  761. }
  762. /**
  763. * set_ddr_opp - set the appropriate DDR OPP
  764. * @opp: The new DDR operating point to which transition is to be made
  765. * Returns: 0 on success, non-zero on failure
  766. *
  767. * This function sets the operating point of the DDR.
  768. */
  769. int prcmu_set_ddr_opp(u8 opp)
  770. {
  771. if (opp < DDR_100_OPP || opp > DDR_25_OPP)
  772. return -EINVAL;
  773. /* Changing the DDR OPP can hang the hardware pre-v21 */
  774. if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
  775. writeb(opp, (_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW));
  776. return 0;
  777. }
  778. /**
  779. * set_ape_opp - set the appropriate APE OPP
  780. * @opp: The new APE operating point to which transition is to be made
  781. * Returns: 0 on success, non-zero on failure
  782. *
  783. * This function sets the operating point of the APE.
  784. */
  785. int prcmu_set_ape_opp(u8 opp)
  786. {
  787. int r = 0;
  788. mutex_lock(&mb1_transfer.lock);
  789. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  790. cpu_relax();
  791. writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  792. writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
  793. writeb(opp, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
  794. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  795. wait_for_completion(&mb1_transfer.work);
  796. if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
  797. (mb1_transfer.ack.ape_opp != opp))
  798. r = -EIO;
  799. mutex_unlock(&mb1_transfer.lock);
  800. return r;
  801. }
  802. /**
  803. * prcmu_get_ape_opp - get the current APE OPP
  804. *
  805. * Returns: the current APE OPP
  806. */
  807. int prcmu_get_ape_opp(void)
  808. {
  809. return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
  810. }
  811. /**
  812. * prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
  813. * @enable: true to request the higher voltage, false to drop a request.
  814. *
  815. * Calls to this function to enable and disable requests must be balanced.
  816. */
  817. int prcmu_request_ape_opp_100_voltage(bool enable)
  818. {
  819. int r = 0;
  820. u8 header;
  821. static unsigned int requests;
  822. mutex_lock(&mb1_transfer.lock);
  823. if (enable) {
  824. if (0 != requests++)
  825. goto unlock_and_return;
  826. header = MB1H_REQUEST_APE_OPP_100_VOLT;
  827. } else {
  828. if (requests == 0) {
  829. r = -EIO;
  830. goto unlock_and_return;
  831. } else if (1 != requests--) {
  832. goto unlock_and_return;
  833. }
  834. header = MB1H_RELEASE_APE_OPP_100_VOLT;
  835. }
  836. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  837. cpu_relax();
  838. writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  839. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  840. wait_for_completion(&mb1_transfer.work);
  841. if ((mb1_transfer.ack.header != header) ||
  842. ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
  843. r = -EIO;
  844. unlock_and_return:
  845. mutex_unlock(&mb1_transfer.lock);
  846. return r;
  847. }
  848. /**
  849. * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
  850. *
  851. * This function releases the power state requirements of a USB wakeup.
  852. */
  853. int prcmu_release_usb_wakeup_state(void)
  854. {
  855. int r = 0;
  856. mutex_lock(&mb1_transfer.lock);
  857. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  858. cpu_relax();
  859. writeb(MB1H_RELEASE_USB_WAKEUP,
  860. (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  861. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  862. wait_for_completion(&mb1_transfer.work);
  863. if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
  864. ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
  865. r = -EIO;
  866. mutex_unlock(&mb1_transfer.lock);
  867. return r;
  868. }
  869. /**
  870. * prcmu_set_epod - set the state of a EPOD (power domain)
  871. * @epod_id: The EPOD to set
  872. * @epod_state: The new EPOD state
  873. *
  874. * This function sets the state of a EPOD (power domain). It may not be called
  875. * from interrupt context.
  876. */
  877. int prcmu_set_epod(u16 epod_id, u8 epod_state)
  878. {
  879. int r = 0;
  880. bool ram_retention = false;
  881. int i;
  882. /* check argument */
  883. BUG_ON(epod_id >= NUM_EPOD_ID);
  884. /* set flag if retention is possible */
  885. switch (epod_id) {
  886. case EPOD_ID_SVAMMDSP:
  887. case EPOD_ID_SIAMMDSP:
  888. case EPOD_ID_ESRAM12:
  889. case EPOD_ID_ESRAM34:
  890. ram_retention = true;
  891. break;
  892. }
  893. /* check argument */
  894. BUG_ON(epod_state > EPOD_STATE_ON);
  895. BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
  896. /* get lock */
  897. mutex_lock(&mb2_transfer.lock);
  898. /* wait for mailbox */
  899. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
  900. cpu_relax();
  901. /* fill in mailbox */
  902. for (i = 0; i < NUM_EPOD_ID; i++)
  903. writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
  904. writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
  905. writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
  906. writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  907. /*
  908. * The current firmware version does not handle errors correctly,
  909. * and we cannot recover if there is an error.
  910. * This is expected to change when the firmware is updated.
  911. */
  912. if (!wait_for_completion_timeout(&mb2_transfer.work,
  913. msecs_to_jiffies(20000))) {
  914. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  915. __func__);
  916. r = -EIO;
  917. goto unlock_and_return;
  918. }
  919. if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
  920. r = -EIO;
  921. unlock_and_return:
  922. mutex_unlock(&mb2_transfer.lock);
  923. return r;
  924. }
  925. /**
  926. * prcmu_configure_auto_pm - Configure autonomous power management.
  927. * @sleep: Configuration for ApSleep.
  928. * @idle: Configuration for ApIdle.
  929. */
  930. void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
  931. struct prcmu_auto_pm_config *idle)
  932. {
  933. u32 sleep_cfg;
  934. u32 idle_cfg;
  935. unsigned long flags;
  936. BUG_ON((sleep == NULL) || (idle == NULL));
  937. sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
  938. sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
  939. sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
  940. sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
  941. sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
  942. sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
  943. idle_cfg = (idle->sva_auto_pm_enable & 0xF);
  944. idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
  945. idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
  946. idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
  947. idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
  948. idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
  949. spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
  950. /*
  951. * The autonomous power management configuration is done through
  952. * fields in mailbox 2, but these fields are only used as shared
  953. * variables - i.e. there is no need to send a message.
  954. */
  955. writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
  956. writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
  957. mb2_transfer.auto_pm_enabled =
  958. ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  959. (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  960. (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  961. (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
  962. spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
  963. }
  964. EXPORT_SYMBOL(prcmu_configure_auto_pm);
  965. bool prcmu_is_auto_pm_enabled(void)
  966. {
  967. return mb2_transfer.auto_pm_enabled;
  968. }
  969. static int request_sysclk(bool enable)
  970. {
  971. int r;
  972. unsigned long flags;
  973. r = 0;
  974. mutex_lock(&mb3_transfer.sysclk_lock);
  975. spin_lock_irqsave(&mb3_transfer.lock, flags);
  976. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
  977. cpu_relax();
  978. writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
  979. writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
  980. writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  981. spin_unlock_irqrestore(&mb3_transfer.lock, flags);
  982. /*
  983. * The firmware only sends an ACK if we want to enable the
  984. * SysClk, and it succeeds.
  985. */
  986. if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
  987. msecs_to_jiffies(20000))) {
  988. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  989. __func__);
  990. r = -EIO;
  991. }
  992. mutex_unlock(&mb3_transfer.sysclk_lock);
  993. return r;
  994. }
  995. static int request_timclk(bool enable)
  996. {
  997. u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
  998. if (!enable)
  999. val |= PRCM_TCR_STOP_TIMERS;
  1000. writel(val, (_PRCMU_BASE + PRCM_TCR));
  1001. return 0;
  1002. }
  1003. static int request_reg_clock(u8 clock, bool enable)
  1004. {
  1005. u32 val;
  1006. unsigned long flags;
  1007. spin_lock_irqsave(&clk_mgt_lock, flags);
  1008. /* Grab the HW semaphore. */
  1009. while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  1010. cpu_relax();
  1011. val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
  1012. if (enable) {
  1013. val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
  1014. } else {
  1015. clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
  1016. val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
  1017. }
  1018. writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
  1019. /* Release the HW semaphore. */
  1020. writel(0, (_PRCMU_BASE + PRCM_SEM));
  1021. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  1022. return 0;
  1023. }
  1024. /**
  1025. * prcmu_request_clock() - Request for a clock to be enabled or disabled.
  1026. * @clock: The clock for which the request is made.
  1027. * @enable: Whether the clock should be enabled (true) or disabled (false).
  1028. *
  1029. * This function should only be used by the clock implementation.
  1030. * Do not use it from any other place!
  1031. */
  1032. int prcmu_request_clock(u8 clock, bool enable)
  1033. {
  1034. if (clock < PRCMU_NUM_REG_CLOCKS)
  1035. return request_reg_clock(clock, enable);
  1036. else if (clock == PRCMU_TIMCLK)
  1037. return request_timclk(enable);
  1038. else if (clock == PRCMU_SYSCLK)
  1039. return request_sysclk(enable);
  1040. else
  1041. return -EINVAL;
  1042. }
  1043. int prcmu_config_esram0_deep_sleep(u8 state)
  1044. {
  1045. if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
  1046. (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
  1047. return -EINVAL;
  1048. mutex_lock(&mb4_transfer.lock);
  1049. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1050. cpu_relax();
  1051. writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1052. writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
  1053. (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
  1054. writeb(DDR_PWR_STATE_ON,
  1055. (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
  1056. writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
  1057. writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1058. wait_for_completion(&mb4_transfer.work);
  1059. mutex_unlock(&mb4_transfer.lock);
  1060. return 0;
  1061. }
  1062. int prcmu_config_hotdog(u8 threshold)
  1063. {
  1064. mutex_lock(&mb4_transfer.lock);
  1065. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1066. cpu_relax();
  1067. writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
  1068. writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1069. writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1070. wait_for_completion(&mb4_transfer.work);
  1071. mutex_unlock(&mb4_transfer.lock);
  1072. return 0;
  1073. }
  1074. int prcmu_config_hotmon(u8 low, u8 high)
  1075. {
  1076. mutex_lock(&mb4_transfer.lock);
  1077. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1078. cpu_relax();
  1079. writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
  1080. writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
  1081. writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
  1082. (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
  1083. writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1084. writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1085. wait_for_completion(&mb4_transfer.work);
  1086. mutex_unlock(&mb4_transfer.lock);
  1087. return 0;
  1088. }
  1089. static int config_hot_period(u16 val)
  1090. {
  1091. mutex_lock(&mb4_transfer.lock);
  1092. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1093. cpu_relax();
  1094. writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
  1095. writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1096. writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1097. wait_for_completion(&mb4_transfer.work);
  1098. mutex_unlock(&mb4_transfer.lock);
  1099. return 0;
  1100. }
  1101. int prcmu_start_temp_sense(u16 cycles32k)
  1102. {
  1103. if (cycles32k == 0xFFFF)
  1104. return -EINVAL;
  1105. return config_hot_period(cycles32k);
  1106. }
  1107. int prcmu_stop_temp_sense(void)
  1108. {
  1109. return config_hot_period(0xFFFF);
  1110. }
  1111. /**
  1112. * prcmu_set_clock_divider() - Configure the clock divider.
  1113. * @clock: The clock for which the request is made.
  1114. * @divider: The clock divider. (< 32)
  1115. *
  1116. * This function should only be used by the clock implementation.
  1117. * Do not use it from any other place!
  1118. */
  1119. int prcmu_set_clock_divider(u8 clock, u8 divider)
  1120. {
  1121. u32 val;
  1122. unsigned long flags;
  1123. if ((clock >= PRCMU_NUM_REG_CLOCKS) || (divider < 1) || (31 < divider))
  1124. return -EINVAL;
  1125. spin_lock_irqsave(&clk_mgt_lock, flags);
  1126. /* Grab the HW semaphore. */
  1127. while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  1128. cpu_relax();
  1129. val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
  1130. val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK);
  1131. val |= (u32)divider;
  1132. writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
  1133. /* Release the HW semaphore. */
  1134. writel(0, (_PRCMU_BASE + PRCM_SEM));
  1135. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  1136. return 0;
  1137. }
  1138. /**
  1139. * prcmu_abb_read() - Read register value(s) from the ABB.
  1140. * @slave: The I2C slave address.
  1141. * @reg: The (start) register address.
  1142. * @value: The read out value(s).
  1143. * @size: The number of registers to read.
  1144. *
  1145. * Reads register value(s) from the ABB.
  1146. * @size has to be 1 for the current firmware version.
  1147. */
  1148. int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
  1149. {
  1150. int r;
  1151. if (size != 1)
  1152. return -EINVAL;
  1153. mutex_lock(&mb5_transfer.lock);
  1154. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
  1155. cpu_relax();
  1156. writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
  1157. writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
  1158. writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
  1159. writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
  1160. writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1161. if (!wait_for_completion_timeout(&mb5_transfer.work,
  1162. msecs_to_jiffies(20000))) {
  1163. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1164. __func__);
  1165. r = -EIO;
  1166. } else {
  1167. r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
  1168. }
  1169. if (!r)
  1170. *value = mb5_transfer.ack.value;
  1171. mutex_unlock(&mb5_transfer.lock);
  1172. return r;
  1173. }
  1174. /**
  1175. * prcmu_abb_write() - Write register value(s) to the ABB.
  1176. * @slave: The I2C slave address.
  1177. * @reg: The (start) register address.
  1178. * @value: The value(s) to write.
  1179. * @size: The number of registers to write.
  1180. *
  1181. * Reads register value(s) from the ABB.
  1182. * @size has to be 1 for the current firmware version.
  1183. */
  1184. int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
  1185. {
  1186. int r;
  1187. if (size != 1)
  1188. return -EINVAL;
  1189. mutex_lock(&mb5_transfer.lock);
  1190. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
  1191. cpu_relax();
  1192. writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
  1193. writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
  1194. writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
  1195. writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
  1196. writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1197. if (!wait_for_completion_timeout(&mb5_transfer.work,
  1198. msecs_to_jiffies(20000))) {
  1199. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1200. __func__);
  1201. r = -EIO;
  1202. } else {
  1203. r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
  1204. }
  1205. mutex_unlock(&mb5_transfer.lock);
  1206. return r;
  1207. }
  1208. /**
  1209. * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
  1210. */
  1211. void prcmu_ac_wake_req(void)
  1212. {
  1213. u32 val;
  1214. mutex_lock(&mb0_transfer.ac_wake_lock);
  1215. val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ);
  1216. if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
  1217. goto unlock_and_return;
  1218. atomic_set(&ac_wake_req_state, 1);
  1219. writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
  1220. (_PRCMU_BASE + PRCM_HOSTACCESS_REQ));
  1221. if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
  1222. msecs_to_jiffies(20000))) {
  1223. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1224. __func__);
  1225. }
  1226. unlock_and_return:
  1227. mutex_unlock(&mb0_transfer.ac_wake_lock);
  1228. }
  1229. /**
  1230. * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
  1231. */
  1232. void prcmu_ac_sleep_req()
  1233. {
  1234. u32 val;
  1235. mutex_lock(&mb0_transfer.ac_wake_lock);
  1236. val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ);
  1237. if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
  1238. goto unlock_and_return;
  1239. writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
  1240. (_PRCMU_BASE + PRCM_HOSTACCESS_REQ));
  1241. if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
  1242. msecs_to_jiffies(20000))) {
  1243. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1244. __func__);
  1245. }
  1246. atomic_set(&ac_wake_req_state, 0);
  1247. unlock_and_return:
  1248. mutex_unlock(&mb0_transfer.ac_wake_lock);
  1249. }
  1250. bool prcmu_is_ac_wake_requested(void)
  1251. {
  1252. return (atomic_read(&ac_wake_req_state) != 0);
  1253. }
  1254. /**
  1255. * prcmu_system_reset - System reset
  1256. *
  1257. * Saves the reset reason code and then sets the APE_SOFRST register which
  1258. * fires interrupt to fw
  1259. */
  1260. void prcmu_system_reset(u16 reset_code)
  1261. {
  1262. writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
  1263. writel(1, (_PRCMU_BASE + PRCM_APE_SOFTRST));
  1264. }
  1265. /**
  1266. * prcmu_reset_modem - ask the PRCMU to reset modem
  1267. */
  1268. void prcmu_modem_reset(void)
  1269. {
  1270. mutex_lock(&mb1_transfer.lock);
  1271. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  1272. cpu_relax();
  1273. writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  1274. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1275. wait_for_completion(&mb1_transfer.work);
  1276. /*
  1277. * No need to check return from PRCMU as modem should go in reset state
  1278. * This state is already managed by upper layer
  1279. */
  1280. mutex_unlock(&mb1_transfer.lock);
  1281. }
  1282. static void ack_dbb_wakeup(void)
  1283. {
  1284. unsigned long flags;
  1285. spin_lock_irqsave(&mb0_transfer.lock, flags);
  1286. while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  1287. cpu_relax();
  1288. writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  1289. writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET));
  1290. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  1291. }
  1292. static inline void print_unknown_header_warning(u8 n, u8 header)
  1293. {
  1294. pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
  1295. header, n);
  1296. }
  1297. static bool read_mailbox_0(void)
  1298. {
  1299. bool r;
  1300. u32 ev;
  1301. unsigned int n;
  1302. u8 header;
  1303. header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
  1304. switch (header) {
  1305. case MB0H_WAKEUP_EXE:
  1306. case MB0H_WAKEUP_SLEEP:
  1307. if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
  1308. ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
  1309. else
  1310. ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
  1311. if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
  1312. complete(&mb0_transfer.ac_wake_work);
  1313. if (ev & WAKEUP_BIT_SYSCLK_OK)
  1314. complete(&mb3_transfer.sysclk_work);
  1315. ev &= mb0_transfer.req.dbb_irqs;
  1316. for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
  1317. if (ev & prcmu_irq_bit[n])
  1318. generic_handle_irq(IRQ_PRCMU_BASE + n);
  1319. }
  1320. r = true;
  1321. break;
  1322. default:
  1323. print_unknown_header_warning(0, header);
  1324. r = false;
  1325. break;
  1326. }
  1327. writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1328. return r;
  1329. }
  1330. static bool read_mailbox_1(void)
  1331. {
  1332. mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
  1333. mb1_transfer.ack.arm_opp = readb(tcdm_base +
  1334. PRCM_ACK_MB1_CURRENT_ARM_OPP);
  1335. mb1_transfer.ack.ape_opp = readb(tcdm_base +
  1336. PRCM_ACK_MB1_CURRENT_APE_OPP);
  1337. mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
  1338. PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
  1339. writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1340. complete(&mb1_transfer.work);
  1341. return false;
  1342. }
  1343. static bool read_mailbox_2(void)
  1344. {
  1345. mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
  1346. writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1347. complete(&mb2_transfer.work);
  1348. return false;
  1349. }
  1350. static bool read_mailbox_3(void)
  1351. {
  1352. writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1353. return false;
  1354. }
  1355. static bool read_mailbox_4(void)
  1356. {
  1357. u8 header;
  1358. bool do_complete = true;
  1359. header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
  1360. switch (header) {
  1361. case MB4H_MEM_ST:
  1362. case MB4H_HOTDOG:
  1363. case MB4H_HOTMON:
  1364. case MB4H_HOT_PERIOD:
  1365. break;
  1366. default:
  1367. print_unknown_header_warning(4, header);
  1368. do_complete = false;
  1369. break;
  1370. }
  1371. writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1372. if (do_complete)
  1373. complete(&mb4_transfer.work);
  1374. return false;
  1375. }
  1376. static bool read_mailbox_5(void)
  1377. {
  1378. mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
  1379. mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
  1380. writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1381. complete(&mb5_transfer.work);
  1382. return false;
  1383. }
  1384. static bool read_mailbox_6(void)
  1385. {
  1386. writel(MBOX_BIT(6), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1387. return false;
  1388. }
  1389. static bool read_mailbox_7(void)
  1390. {
  1391. writel(MBOX_BIT(7), (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1392. return false;
  1393. }
  1394. static bool (* const read_mailbox[NUM_MB])(void) = {
  1395. read_mailbox_0,
  1396. read_mailbox_1,
  1397. read_mailbox_2,
  1398. read_mailbox_3,
  1399. read_mailbox_4,
  1400. read_mailbox_5,
  1401. read_mailbox_6,
  1402. read_mailbox_7
  1403. };
  1404. static irqreturn_t prcmu_irq_handler(int irq, void *data)
  1405. {
  1406. u32 bits;
  1407. u8 n;
  1408. irqreturn_t r;
  1409. bits = (readl(_PRCMU_BASE + PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
  1410. if (unlikely(!bits))
  1411. return IRQ_NONE;
  1412. r = IRQ_HANDLED;
  1413. for (n = 0; bits; n++) {
  1414. if (bits & MBOX_BIT(n)) {
  1415. bits -= MBOX_BIT(n);
  1416. if (read_mailbox[n]())
  1417. r = IRQ_WAKE_THREAD;
  1418. }
  1419. }
  1420. return r;
  1421. }
  1422. static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
  1423. {
  1424. ack_dbb_wakeup();
  1425. return IRQ_HANDLED;
  1426. }
  1427. static void prcmu_mask_work(struct work_struct *work)
  1428. {
  1429. unsigned long flags;
  1430. spin_lock_irqsave(&mb0_transfer.lock, flags);
  1431. config_wakeups();
  1432. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  1433. }
  1434. static void prcmu_irq_mask(struct irq_data *d)
  1435. {
  1436. unsigned long flags;
  1437. spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
  1438. mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
  1439. spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
  1440. if (d->irq != IRQ_PRCMU_CA_SLEEP)
  1441. schedule_work(&mb0_transfer.mask_work);
  1442. }
  1443. static void prcmu_irq_unmask(struct irq_data *d)
  1444. {
  1445. unsigned long flags;
  1446. spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
  1447. mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->irq - IRQ_PRCMU_BASE];
  1448. spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
  1449. if (d->irq != IRQ_PRCMU_CA_SLEEP)
  1450. schedule_work(&mb0_transfer.mask_work);
  1451. }
  1452. static void noop(struct irq_data *d)
  1453. {
  1454. }
  1455. static struct irq_chip prcmu_irq_chip = {
  1456. .name = "prcmu",
  1457. .irq_disable = prcmu_irq_mask,
  1458. .irq_ack = noop,
  1459. .irq_mask = prcmu_irq_mask,
  1460. .irq_unmask = prcmu_irq_unmask,
  1461. };
  1462. void __init prcmu_early_init(void)
  1463. {
  1464. unsigned int i;
  1465. if (cpu_is_u8500v1()) {
  1466. tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE_V1);
  1467. } else if (cpu_is_u8500v2()) {
  1468. void *tcpm_base = ioremap_nocache(U8500_PRCMU_TCPM_BASE, SZ_4K);
  1469. if (tcpm_base != NULL) {
  1470. int version;
  1471. version = readl(tcpm_base + PRCMU_FW_VERSION_OFFSET);
  1472. prcmu_version.project_number = version & 0xFF;
  1473. prcmu_version.api_version = (version >> 8) & 0xFF;
  1474. prcmu_version.func_version = (version >> 16) & 0xFF;
  1475. prcmu_version.errata = (version >> 24) & 0xFF;
  1476. pr_info("PRCMU firmware version %d.%d.%d\n",
  1477. (version >> 8) & 0xFF, (version >> 16) & 0xFF,
  1478. (version >> 24) & 0xFF);
  1479. iounmap(tcpm_base);
  1480. }
  1481. tcdm_base = __io_address(U8500_PRCMU_TCDM_BASE);
  1482. } else {
  1483. pr_err("prcmu: Unsupported chip version\n");
  1484. BUG();
  1485. }
  1486. spin_lock_init(&mb0_transfer.lock);
  1487. spin_lock_init(&mb0_transfer.dbb_irqs_lock);
  1488. mutex_init(&mb0_transfer.ac_wake_lock);
  1489. init_completion(&mb0_transfer.ac_wake_work);
  1490. mutex_init(&mb1_transfer.lock);
  1491. init_completion(&mb1_transfer.work);
  1492. mutex_init(&mb2_transfer.lock);
  1493. init_completion(&mb2_transfer.work);
  1494. spin_lock_init(&mb2_transfer.auto_pm_lock);
  1495. spin_lock_init(&mb3_transfer.lock);
  1496. mutex_init(&mb3_transfer.sysclk_lock);
  1497. init_completion(&mb3_transfer.sysclk_work);
  1498. mutex_init(&mb4_transfer.lock);
  1499. init_completion(&mb4_transfer.work);
  1500. mutex_init(&mb5_transfer.lock);
  1501. init_completion(&mb5_transfer.work);
  1502. INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
  1503. /* Initalize irqs. */
  1504. for (i = 0; i < NUM_PRCMU_WAKEUPS; i++) {
  1505. unsigned int irq;
  1506. irq = IRQ_PRCMU_BASE + i;
  1507. irq_set_chip_and_handler(irq, &prcmu_irq_chip,
  1508. handle_simple_irq);
  1509. set_irq_flags(irq, IRQF_VALID);
  1510. }
  1511. }
  1512. /*
  1513. * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
  1514. */
  1515. static struct regulator_consumer_supply db8500_vape_consumers[] = {
  1516. REGULATOR_SUPPLY("v-ape", NULL),
  1517. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"),
  1518. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"),
  1519. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"),
  1520. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"),
  1521. /* "v-mmc" changed to "vcore" in the mainline kernel */
  1522. REGULATOR_SUPPLY("vcore", "sdi0"),
  1523. REGULATOR_SUPPLY("vcore", "sdi1"),
  1524. REGULATOR_SUPPLY("vcore", "sdi2"),
  1525. REGULATOR_SUPPLY("vcore", "sdi3"),
  1526. REGULATOR_SUPPLY("vcore", "sdi4"),
  1527. REGULATOR_SUPPLY("v-dma", "dma40.0"),
  1528. REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"),
  1529. /* "v-uart" changed to "vcore" in the mainline kernel */
  1530. REGULATOR_SUPPLY("vcore", "uart0"),
  1531. REGULATOR_SUPPLY("vcore", "uart1"),
  1532. REGULATOR_SUPPLY("vcore", "uart2"),
  1533. REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
  1534. };
  1535. static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
  1536. /* CG2900 and CW1200 power to off-chip peripherals */
  1537. REGULATOR_SUPPLY("gbf_1v8", "cg2900-uart.0"),
  1538. REGULATOR_SUPPLY("wlan_1v8", "cw1200.0"),
  1539. REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"),
  1540. /* AV8100 regulator */
  1541. REGULATOR_SUPPLY("hdmi_1v8", "0-0070"),
  1542. };
  1543. static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
  1544. REGULATOR_SUPPLY("vsupply", "b2r2.0"),
  1545. REGULATOR_SUPPLY("vsupply", "mcde.0"),
  1546. };
  1547. static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
  1548. [DB8500_REGULATOR_VAPE] = {
  1549. .constraints = {
  1550. .name = "db8500-vape",
  1551. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1552. },
  1553. .consumer_supplies = db8500_vape_consumers,
  1554. .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
  1555. },
  1556. [DB8500_REGULATOR_VARM] = {
  1557. .constraints = {
  1558. .name = "db8500-varm",
  1559. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1560. },
  1561. },
  1562. [DB8500_REGULATOR_VMODEM] = {
  1563. .constraints = {
  1564. .name = "db8500-vmodem",
  1565. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1566. },
  1567. },
  1568. [DB8500_REGULATOR_VPLL] = {
  1569. .constraints = {
  1570. .name = "db8500-vpll",
  1571. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1572. },
  1573. },
  1574. [DB8500_REGULATOR_VSMPS1] = {
  1575. .constraints = {
  1576. .name = "db8500-vsmps1",
  1577. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1578. },
  1579. },
  1580. [DB8500_REGULATOR_VSMPS2] = {
  1581. .constraints = {
  1582. .name = "db8500-vsmps2",
  1583. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1584. },
  1585. .consumer_supplies = db8500_vsmps2_consumers,
  1586. .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers),
  1587. },
  1588. [DB8500_REGULATOR_VSMPS3] = {
  1589. .constraints = {
  1590. .name = "db8500-vsmps3",
  1591. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1592. },
  1593. },
  1594. [DB8500_REGULATOR_VRF1] = {
  1595. .constraints = {
  1596. .name = "db8500-vrf1",
  1597. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1598. },
  1599. },
  1600. [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
  1601. .supply_regulator = "db8500-vape",
  1602. .constraints = {
  1603. .name = "db8500-sva-mmdsp",
  1604. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1605. },
  1606. },
  1607. [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
  1608. .constraints = {
  1609. /* "ret" means "retention" */
  1610. .name = "db8500-sva-mmdsp-ret",
  1611. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1612. },
  1613. },
  1614. [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
  1615. .supply_regulator = "db8500-vape",
  1616. .constraints = {
  1617. .name = "db8500-sva-pipe",
  1618. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1619. },
  1620. },
  1621. [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
  1622. .supply_regulator = "db8500-vape",
  1623. .constraints = {
  1624. .name = "db8500-sia-mmdsp",
  1625. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1626. },
  1627. },
  1628. [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
  1629. .constraints = {
  1630. .name = "db8500-sia-mmdsp-ret",
  1631. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1632. },
  1633. },
  1634. [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
  1635. .supply_regulator = "db8500-vape",
  1636. .constraints = {
  1637. .name = "db8500-sia-pipe",
  1638. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1639. },
  1640. },
  1641. [DB8500_REGULATOR_SWITCH_SGA] = {
  1642. .supply_regulator = "db8500-vape",
  1643. .constraints = {
  1644. .name = "db8500-sga",
  1645. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1646. },
  1647. },
  1648. [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
  1649. .supply_regulator = "db8500-vape",
  1650. .constraints = {
  1651. .name = "db8500-b2r2-mcde",
  1652. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1653. },
  1654. .consumer_supplies = db8500_b2r2_mcde_consumers,
  1655. .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers),
  1656. },
  1657. [DB8500_REGULATOR_SWITCH_ESRAM12] = {
  1658. .supply_regulator = "db8500-vape",
  1659. .constraints = {
  1660. .name = "db8500-esram12",
  1661. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1662. },
  1663. },
  1664. [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
  1665. .constraints = {
  1666. .name = "db8500-esram12-ret",
  1667. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1668. },
  1669. },
  1670. [DB8500_REGULATOR_SWITCH_ESRAM34] = {
  1671. .supply_regulator = "db8500-vape",
  1672. .constraints = {
  1673. .name = "db8500-esram34",
  1674. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1675. },
  1676. },
  1677. [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
  1678. .constraints = {
  1679. .name = "db8500-esram34-ret",
  1680. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  1681. },
  1682. },
  1683. };
  1684. static struct mfd_cell db8500_prcmu_devs[] = {
  1685. {
  1686. .name = "db8500-prcmu-regulators",
  1687. .platform_data = &db8500_regulators,
  1688. .pdata_size = sizeof(db8500_regulators),
  1689. },
  1690. {
  1691. .name = "cpufreq-u8500",
  1692. },
  1693. };
  1694. /**
  1695. * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
  1696. *
  1697. */
  1698. static int __init db8500_prcmu_probe(struct platform_device *pdev)
  1699. {
  1700. int err = 0;
  1701. if (ux500_is_svp())
  1702. return -ENODEV;
  1703. /* Clean up the mailbox interrupts after pre-kernel code. */
  1704. writel(ALL_MBOX_BITS, (_PRCMU_BASE + PRCM_ARM_IT1_CLR));
  1705. err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler,
  1706. prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
  1707. if (err < 0) {
  1708. pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
  1709. err = -EBUSY;
  1710. goto no_irq_return;
  1711. }
  1712. if (cpu_is_u8500v20_or_later())
  1713. prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
  1714. err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
  1715. ARRAY_SIZE(db8500_prcmu_devs), NULL,
  1716. 0);
  1717. if (err)
  1718. pr_err("prcmu: Failed to add subdevices\n");
  1719. else
  1720. pr_info("DB8500 PRCMU initialized\n");
  1721. no_irq_return:
  1722. return err;
  1723. }
  1724. static struct platform_driver db8500_prcmu_driver = {
  1725. .driver = {
  1726. .name = "db8500-prcmu",
  1727. .owner = THIS_MODULE,
  1728. },
  1729. };
  1730. static int __init db8500_prcmu_init(void)
  1731. {
  1732. return platform_driver_probe(&db8500_prcmu_driver, db8500_prcmu_probe);
  1733. }
  1734. arch_initcall(db8500_prcmu_init);
  1735. MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
  1736. MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
  1737. MODULE_LICENSE("GPL v2");