db8500-prcmu.c 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217
  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/of.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/mfd/core.h>
  32. #include <linux/mfd/dbx500-prcmu.h>
  33. #include <linux/mfd/abx500/ab8500.h>
  34. #include <linux/regulator/db8500-prcmu.h>
  35. #include <linux/regulator/machine.h>
  36. #include <linux/cpufreq.h>
  37. #include <linux/platform_data/ux500_wdt.h>
  38. #include <linux/platform_data/db8500_thermal.h>
  39. #include "dbx500-prcmu-regs.h"
  40. /* Index of different voltages to be used when accessing AVSData */
  41. #define PRCM_AVS_BASE 0x2FC
  42. #define PRCM_AVS_VBB_RET (PRCM_AVS_BASE + 0x0)
  43. #define PRCM_AVS_VBB_MAX_OPP (PRCM_AVS_BASE + 0x1)
  44. #define PRCM_AVS_VBB_100_OPP (PRCM_AVS_BASE + 0x2)
  45. #define PRCM_AVS_VBB_50_OPP (PRCM_AVS_BASE + 0x3)
  46. #define PRCM_AVS_VARM_MAX_OPP (PRCM_AVS_BASE + 0x4)
  47. #define PRCM_AVS_VARM_100_OPP (PRCM_AVS_BASE + 0x5)
  48. #define PRCM_AVS_VARM_50_OPP (PRCM_AVS_BASE + 0x6)
  49. #define PRCM_AVS_VARM_RET (PRCM_AVS_BASE + 0x7)
  50. #define PRCM_AVS_VAPE_100_OPP (PRCM_AVS_BASE + 0x8)
  51. #define PRCM_AVS_VAPE_50_OPP (PRCM_AVS_BASE + 0x9)
  52. #define PRCM_AVS_VMOD_100_OPP (PRCM_AVS_BASE + 0xA)
  53. #define PRCM_AVS_VMOD_50_OPP (PRCM_AVS_BASE + 0xB)
  54. #define PRCM_AVS_VSAFE (PRCM_AVS_BASE + 0xC)
  55. #define PRCM_AVS_VOLTAGE 0
  56. #define PRCM_AVS_VOLTAGE_MASK 0x3f
  57. #define PRCM_AVS_ISSLOWSTARTUP 6
  58. #define PRCM_AVS_ISSLOWSTARTUP_MASK (1 << PRCM_AVS_ISSLOWSTARTUP)
  59. #define PRCM_AVS_ISMODEENABLE 7
  60. #define PRCM_AVS_ISMODEENABLE_MASK (1 << PRCM_AVS_ISMODEENABLE)
  61. #define PRCM_BOOT_STATUS 0xFFF
  62. #define PRCM_ROMCODE_A2P 0xFFE
  63. #define PRCM_ROMCODE_P2A 0xFFD
  64. #define PRCM_XP70_CUR_PWR_STATE 0xFFC /* 4 BYTES */
  65. #define PRCM_SW_RST_REASON 0xFF8 /* 2 bytes */
  66. #define _PRCM_MBOX_HEADER 0xFE8 /* 16 bytes */
  67. #define PRCM_MBOX_HEADER_REQ_MB0 (_PRCM_MBOX_HEADER + 0x0)
  68. #define PRCM_MBOX_HEADER_REQ_MB1 (_PRCM_MBOX_HEADER + 0x1)
  69. #define PRCM_MBOX_HEADER_REQ_MB2 (_PRCM_MBOX_HEADER + 0x2)
  70. #define PRCM_MBOX_HEADER_REQ_MB3 (_PRCM_MBOX_HEADER + 0x3)
  71. #define PRCM_MBOX_HEADER_REQ_MB4 (_PRCM_MBOX_HEADER + 0x4)
  72. #define PRCM_MBOX_HEADER_REQ_MB5 (_PRCM_MBOX_HEADER + 0x5)
  73. #define PRCM_MBOX_HEADER_ACK_MB0 (_PRCM_MBOX_HEADER + 0x8)
  74. /* Req Mailboxes */
  75. #define PRCM_REQ_MB0 0xFDC /* 12 bytes */
  76. #define PRCM_REQ_MB1 0xFD0 /* 12 bytes */
  77. #define PRCM_REQ_MB2 0xFC0 /* 16 bytes */
  78. #define PRCM_REQ_MB3 0xE4C /* 372 bytes */
  79. #define PRCM_REQ_MB4 0xE48 /* 4 bytes */
  80. #define PRCM_REQ_MB5 0xE44 /* 4 bytes */
  81. /* Ack Mailboxes */
  82. #define PRCM_ACK_MB0 0xE08 /* 52 bytes */
  83. #define PRCM_ACK_MB1 0xE04 /* 4 bytes */
  84. #define PRCM_ACK_MB2 0xE00 /* 4 bytes */
  85. #define PRCM_ACK_MB3 0xDFC /* 4 bytes */
  86. #define PRCM_ACK_MB4 0xDF8 /* 4 bytes */
  87. #define PRCM_ACK_MB5 0xDF4 /* 4 bytes */
  88. /* Mailbox 0 headers */
  89. #define MB0H_POWER_STATE_TRANS 0
  90. #define MB0H_CONFIG_WAKEUPS_EXE 1
  91. #define MB0H_READ_WAKEUP_ACK 3
  92. #define MB0H_CONFIG_WAKEUPS_SLEEP 4
  93. #define MB0H_WAKEUP_EXE 2
  94. #define MB0H_WAKEUP_SLEEP 5
  95. /* Mailbox 0 REQs */
  96. #define PRCM_REQ_MB0_AP_POWER_STATE (PRCM_REQ_MB0 + 0x0)
  97. #define PRCM_REQ_MB0_AP_PLL_STATE (PRCM_REQ_MB0 + 0x1)
  98. #define PRCM_REQ_MB0_ULP_CLOCK_STATE (PRCM_REQ_MB0 + 0x2)
  99. #define PRCM_REQ_MB0_DO_NOT_WFI (PRCM_REQ_MB0 + 0x3)
  100. #define PRCM_REQ_MB0_WAKEUP_8500 (PRCM_REQ_MB0 + 0x4)
  101. #define PRCM_REQ_MB0_WAKEUP_4500 (PRCM_REQ_MB0 + 0x8)
  102. /* Mailbox 0 ACKs */
  103. #define PRCM_ACK_MB0_AP_PWRSTTR_STATUS (PRCM_ACK_MB0 + 0x0)
  104. #define PRCM_ACK_MB0_READ_POINTER (PRCM_ACK_MB0 + 0x1)
  105. #define PRCM_ACK_MB0_WAKEUP_0_8500 (PRCM_ACK_MB0 + 0x4)
  106. #define PRCM_ACK_MB0_WAKEUP_0_4500 (PRCM_ACK_MB0 + 0x8)
  107. #define PRCM_ACK_MB0_WAKEUP_1_8500 (PRCM_ACK_MB0 + 0x1C)
  108. #define PRCM_ACK_MB0_WAKEUP_1_4500 (PRCM_ACK_MB0 + 0x20)
  109. #define PRCM_ACK_MB0_EVENT_4500_NUMBERS 20
  110. /* Mailbox 1 headers */
  111. #define MB1H_ARM_APE_OPP 0x0
  112. #define MB1H_RESET_MODEM 0x2
  113. #define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
  114. #define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
  115. #define MB1H_RELEASE_USB_WAKEUP 0x5
  116. #define MB1H_PLL_ON_OFF 0x6
  117. /* Mailbox 1 Requests */
  118. #define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
  119. #define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
  120. #define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
  121. #define PLL_SOC0_OFF 0x1
  122. #define PLL_SOC0_ON 0x2
  123. #define PLL_SOC1_OFF 0x4
  124. #define PLL_SOC1_ON 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. #define MB4H_A9WDOG_CONF 0x16
  166. #define MB4H_A9WDOG_EN 0x17
  167. #define MB4H_A9WDOG_DIS 0x18
  168. #define MB4H_A9WDOG_LOAD 0x19
  169. #define MB4H_A9WDOG_KICK 0x20
  170. /* Mailbox 4 Requests */
  171. #define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
  172. #define PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE (PRCM_REQ_MB4 + 0x1)
  173. #define PRCM_REQ_MB4_ESRAM0_ST (PRCM_REQ_MB4 + 0x3)
  174. #define PRCM_REQ_MB4_HOTDOG_THRESHOLD (PRCM_REQ_MB4 + 0x0)
  175. #define PRCM_REQ_MB4_HOTMON_LOW (PRCM_REQ_MB4 + 0x0)
  176. #define PRCM_REQ_MB4_HOTMON_HIGH (PRCM_REQ_MB4 + 0x1)
  177. #define PRCM_REQ_MB4_HOTMON_CONFIG (PRCM_REQ_MB4 + 0x2)
  178. #define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
  179. #define HOTMON_CONFIG_LOW BIT(0)
  180. #define HOTMON_CONFIG_HIGH BIT(1)
  181. #define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
  182. #define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
  183. #define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
  184. #define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
  185. #define A9WDOG_AUTO_OFF_EN BIT(7)
  186. #define A9WDOG_AUTO_OFF_DIS 0
  187. #define A9WDOG_ID_MASK 0xf
  188. /* Mailbox 5 Requests */
  189. #define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
  190. #define PRCM_REQ_MB5_I2C_HW_BITS (PRCM_REQ_MB5 + 0x1)
  191. #define PRCM_REQ_MB5_I2C_REG (PRCM_REQ_MB5 + 0x2)
  192. #define PRCM_REQ_MB5_I2C_VAL (PRCM_REQ_MB5 + 0x3)
  193. #define PRCMU_I2C_WRITE(slave) (((slave) << 1) | BIT(6))
  194. #define PRCMU_I2C_READ(slave) (((slave) << 1) | BIT(0) | BIT(6))
  195. #define PRCMU_I2C_STOP_EN BIT(3)
  196. /* Mailbox 5 ACKs */
  197. #define PRCM_ACK_MB5_I2C_STATUS (PRCM_ACK_MB5 + 0x1)
  198. #define PRCM_ACK_MB5_I2C_VAL (PRCM_ACK_MB5 + 0x3)
  199. #define I2C_WR_OK 0x1
  200. #define I2C_RD_OK 0x2
  201. #define NUM_MB 8
  202. #define MBOX_BIT BIT
  203. #define ALL_MBOX_BITS (MBOX_BIT(NUM_MB) - 1)
  204. /*
  205. * Wakeups/IRQs
  206. */
  207. #define WAKEUP_BIT_RTC BIT(0)
  208. #define WAKEUP_BIT_RTT0 BIT(1)
  209. #define WAKEUP_BIT_RTT1 BIT(2)
  210. #define WAKEUP_BIT_HSI0 BIT(3)
  211. #define WAKEUP_BIT_HSI1 BIT(4)
  212. #define WAKEUP_BIT_CA_WAKE BIT(5)
  213. #define WAKEUP_BIT_USB BIT(6)
  214. #define WAKEUP_BIT_ABB BIT(7)
  215. #define WAKEUP_BIT_ABB_FIFO BIT(8)
  216. #define WAKEUP_BIT_SYSCLK_OK BIT(9)
  217. #define WAKEUP_BIT_CA_SLEEP BIT(10)
  218. #define WAKEUP_BIT_AC_WAKE_ACK BIT(11)
  219. #define WAKEUP_BIT_SIDE_TONE_OK BIT(12)
  220. #define WAKEUP_BIT_ANC_OK BIT(13)
  221. #define WAKEUP_BIT_SW_ERROR BIT(14)
  222. #define WAKEUP_BIT_AC_SLEEP_ACK BIT(15)
  223. #define WAKEUP_BIT_ARM BIT(17)
  224. #define WAKEUP_BIT_HOTMON_LOW BIT(18)
  225. #define WAKEUP_BIT_HOTMON_HIGH BIT(19)
  226. #define WAKEUP_BIT_MODEM_SW_RESET_REQ BIT(20)
  227. #define WAKEUP_BIT_GPIO0 BIT(23)
  228. #define WAKEUP_BIT_GPIO1 BIT(24)
  229. #define WAKEUP_BIT_GPIO2 BIT(25)
  230. #define WAKEUP_BIT_GPIO3 BIT(26)
  231. #define WAKEUP_BIT_GPIO4 BIT(27)
  232. #define WAKEUP_BIT_GPIO5 BIT(28)
  233. #define WAKEUP_BIT_GPIO6 BIT(29)
  234. #define WAKEUP_BIT_GPIO7 BIT(30)
  235. #define WAKEUP_BIT_GPIO8 BIT(31)
  236. static struct {
  237. bool valid;
  238. struct prcmu_fw_version version;
  239. } fw_info;
  240. static struct irq_domain *db8500_irq_domain;
  241. /*
  242. * This vector maps irq numbers to the bits in the bit field used in
  243. * communication with the PRCMU firmware.
  244. *
  245. * The reason for having this is to keep the irq numbers contiguous even though
  246. * the bits in the bit field are not. (The bits also have a tendency to move
  247. * around, to further complicate matters.)
  248. */
  249. #define IRQ_INDEX(_name) ((IRQ_PRCMU_##_name))
  250. #define IRQ_ENTRY(_name)[IRQ_INDEX(_name)] = (WAKEUP_BIT_##_name)
  251. #define IRQ_PRCMU_RTC 0
  252. #define IRQ_PRCMU_RTT0 1
  253. #define IRQ_PRCMU_RTT1 2
  254. #define IRQ_PRCMU_HSI0 3
  255. #define IRQ_PRCMU_HSI1 4
  256. #define IRQ_PRCMU_CA_WAKE 5
  257. #define IRQ_PRCMU_USB 6
  258. #define IRQ_PRCMU_ABB 7
  259. #define IRQ_PRCMU_ABB_FIFO 8
  260. #define IRQ_PRCMU_ARM 9
  261. #define IRQ_PRCMU_MODEM_SW_RESET_REQ 10
  262. #define IRQ_PRCMU_GPIO0 11
  263. #define IRQ_PRCMU_GPIO1 12
  264. #define IRQ_PRCMU_GPIO2 13
  265. #define IRQ_PRCMU_GPIO3 14
  266. #define IRQ_PRCMU_GPIO4 15
  267. #define IRQ_PRCMU_GPIO5 16
  268. #define IRQ_PRCMU_GPIO6 17
  269. #define IRQ_PRCMU_GPIO7 18
  270. #define IRQ_PRCMU_GPIO8 19
  271. #define IRQ_PRCMU_CA_SLEEP 20
  272. #define IRQ_PRCMU_HOTMON_LOW 21
  273. #define IRQ_PRCMU_HOTMON_HIGH 22
  274. #define NUM_PRCMU_WAKEUPS 23
  275. static u32 prcmu_irq_bit[NUM_PRCMU_WAKEUPS] = {
  276. IRQ_ENTRY(RTC),
  277. IRQ_ENTRY(RTT0),
  278. IRQ_ENTRY(RTT1),
  279. IRQ_ENTRY(HSI0),
  280. IRQ_ENTRY(HSI1),
  281. IRQ_ENTRY(CA_WAKE),
  282. IRQ_ENTRY(USB),
  283. IRQ_ENTRY(ABB),
  284. IRQ_ENTRY(ABB_FIFO),
  285. IRQ_ENTRY(CA_SLEEP),
  286. IRQ_ENTRY(ARM),
  287. IRQ_ENTRY(HOTMON_LOW),
  288. IRQ_ENTRY(HOTMON_HIGH),
  289. IRQ_ENTRY(MODEM_SW_RESET_REQ),
  290. IRQ_ENTRY(GPIO0),
  291. IRQ_ENTRY(GPIO1),
  292. IRQ_ENTRY(GPIO2),
  293. IRQ_ENTRY(GPIO3),
  294. IRQ_ENTRY(GPIO4),
  295. IRQ_ENTRY(GPIO5),
  296. IRQ_ENTRY(GPIO6),
  297. IRQ_ENTRY(GPIO7),
  298. IRQ_ENTRY(GPIO8)
  299. };
  300. #define VALID_WAKEUPS (BIT(NUM_PRCMU_WAKEUP_INDICES) - 1)
  301. #define WAKEUP_ENTRY(_name)[PRCMU_WAKEUP_INDEX_##_name] = (WAKEUP_BIT_##_name)
  302. static u32 prcmu_wakeup_bit[NUM_PRCMU_WAKEUP_INDICES] = {
  303. WAKEUP_ENTRY(RTC),
  304. WAKEUP_ENTRY(RTT0),
  305. WAKEUP_ENTRY(RTT1),
  306. WAKEUP_ENTRY(HSI0),
  307. WAKEUP_ENTRY(HSI1),
  308. WAKEUP_ENTRY(USB),
  309. WAKEUP_ENTRY(ABB),
  310. WAKEUP_ENTRY(ABB_FIFO),
  311. WAKEUP_ENTRY(ARM)
  312. };
  313. /*
  314. * mb0_transfer - state needed for mailbox 0 communication.
  315. * @lock: The transaction lock.
  316. * @dbb_events_lock: A lock used to handle concurrent access to (parts of)
  317. * the request data.
  318. * @mask_work: Work structure used for (un)masking wakeup interrupts.
  319. * @req: Request data that need to persist between requests.
  320. */
  321. static struct {
  322. spinlock_t lock;
  323. spinlock_t dbb_irqs_lock;
  324. struct work_struct mask_work;
  325. struct mutex ac_wake_lock;
  326. struct completion ac_wake_work;
  327. struct {
  328. u32 dbb_irqs;
  329. u32 dbb_wakeups;
  330. u32 abb_events;
  331. } req;
  332. } mb0_transfer;
  333. /*
  334. * mb1_transfer - state needed for mailbox 1 communication.
  335. * @lock: The transaction lock.
  336. * @work: The transaction completion structure.
  337. * @ape_opp: The current APE OPP.
  338. * @ack: Reply ("acknowledge") data.
  339. */
  340. static struct {
  341. struct mutex lock;
  342. struct completion work;
  343. u8 ape_opp;
  344. struct {
  345. u8 header;
  346. u8 arm_opp;
  347. u8 ape_opp;
  348. u8 ape_voltage_status;
  349. } ack;
  350. } mb1_transfer;
  351. /*
  352. * mb2_transfer - state needed for mailbox 2 communication.
  353. * @lock: The transaction lock.
  354. * @work: The transaction completion structure.
  355. * @auto_pm_lock: The autonomous power management configuration lock.
  356. * @auto_pm_enabled: A flag indicating whether autonomous PM is enabled.
  357. * @req: Request data that need to persist between requests.
  358. * @ack: Reply ("acknowledge") data.
  359. */
  360. static struct {
  361. struct mutex lock;
  362. struct completion work;
  363. spinlock_t auto_pm_lock;
  364. bool auto_pm_enabled;
  365. struct {
  366. u8 status;
  367. } ack;
  368. } mb2_transfer;
  369. /*
  370. * mb3_transfer - state needed for mailbox 3 communication.
  371. * @lock: The request lock.
  372. * @sysclk_lock: A lock used to handle concurrent sysclk requests.
  373. * @sysclk_work: Work structure used for sysclk requests.
  374. */
  375. static struct {
  376. spinlock_t lock;
  377. struct mutex sysclk_lock;
  378. struct completion sysclk_work;
  379. } mb3_transfer;
  380. /*
  381. * mb4_transfer - state needed for mailbox 4 communication.
  382. * @lock: The transaction lock.
  383. * @work: The transaction completion structure.
  384. */
  385. static struct {
  386. struct mutex lock;
  387. struct completion work;
  388. } mb4_transfer;
  389. /*
  390. * mb5_transfer - state needed for mailbox 5 communication.
  391. * @lock: The transaction lock.
  392. * @work: The transaction completion structure.
  393. * @ack: Reply ("acknowledge") data.
  394. */
  395. static struct {
  396. struct mutex lock;
  397. struct completion work;
  398. struct {
  399. u8 status;
  400. u8 value;
  401. } ack;
  402. } mb5_transfer;
  403. static atomic_t ac_wake_req_state = ATOMIC_INIT(0);
  404. /* Spinlocks */
  405. static DEFINE_SPINLOCK(prcmu_lock);
  406. static DEFINE_SPINLOCK(clkout_lock);
  407. /* Global var to runtime determine TCDM base for v2 or v1 */
  408. static __iomem void *tcdm_base;
  409. static __iomem void *prcmu_base;
  410. struct clk_mgt {
  411. u32 offset;
  412. u32 pllsw;
  413. int branch;
  414. bool clk38div;
  415. };
  416. enum {
  417. PLL_RAW,
  418. PLL_FIX,
  419. PLL_DIV
  420. };
  421. static DEFINE_SPINLOCK(clk_mgt_lock);
  422. #define CLK_MGT_ENTRY(_name, _branch, _clk38div)[PRCMU_##_name] = \
  423. { (PRCM_##_name##_MGT), 0 , _branch, _clk38div}
  424. static struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
  425. CLK_MGT_ENTRY(SGACLK, PLL_DIV, false),
  426. CLK_MGT_ENTRY(UARTCLK, PLL_FIX, true),
  427. CLK_MGT_ENTRY(MSP02CLK, PLL_FIX, true),
  428. CLK_MGT_ENTRY(MSP1CLK, PLL_FIX, true),
  429. CLK_MGT_ENTRY(I2CCLK, PLL_FIX, true),
  430. CLK_MGT_ENTRY(SDMMCCLK, PLL_DIV, true),
  431. CLK_MGT_ENTRY(SLIMCLK, PLL_FIX, true),
  432. CLK_MGT_ENTRY(PER1CLK, PLL_DIV, true),
  433. CLK_MGT_ENTRY(PER2CLK, PLL_DIV, true),
  434. CLK_MGT_ENTRY(PER3CLK, PLL_DIV, true),
  435. CLK_MGT_ENTRY(PER5CLK, PLL_DIV, true),
  436. CLK_MGT_ENTRY(PER6CLK, PLL_DIV, true),
  437. CLK_MGT_ENTRY(PER7CLK, PLL_DIV, true),
  438. CLK_MGT_ENTRY(LCDCLK, PLL_FIX, true),
  439. CLK_MGT_ENTRY(BMLCLK, PLL_DIV, true),
  440. CLK_MGT_ENTRY(HSITXCLK, PLL_DIV, true),
  441. CLK_MGT_ENTRY(HSIRXCLK, PLL_DIV, true),
  442. CLK_MGT_ENTRY(HDMICLK, PLL_FIX, false),
  443. CLK_MGT_ENTRY(APEATCLK, PLL_DIV, true),
  444. CLK_MGT_ENTRY(APETRACECLK, PLL_DIV, true),
  445. CLK_MGT_ENTRY(MCDECLK, PLL_DIV, true),
  446. CLK_MGT_ENTRY(IPI2CCLK, PLL_FIX, true),
  447. CLK_MGT_ENTRY(DSIALTCLK, PLL_FIX, false),
  448. CLK_MGT_ENTRY(DMACLK, PLL_DIV, true),
  449. CLK_MGT_ENTRY(B2R2CLK, PLL_DIV, true),
  450. CLK_MGT_ENTRY(TVCLK, PLL_FIX, true),
  451. CLK_MGT_ENTRY(SSPCLK, PLL_FIX, true),
  452. CLK_MGT_ENTRY(RNGCLK, PLL_FIX, true),
  453. CLK_MGT_ENTRY(UICCCLK, PLL_FIX, false),
  454. };
  455. struct dsiclk {
  456. u32 divsel_mask;
  457. u32 divsel_shift;
  458. u32 divsel;
  459. };
  460. static struct dsiclk dsiclk[2] = {
  461. {
  462. .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_MASK,
  463. .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI0_PLLOUT_DIVSEL_SHIFT,
  464. .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
  465. },
  466. {
  467. .divsel_mask = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_MASK,
  468. .divsel_shift = PRCM_DSI_PLLOUT_SEL_DSI1_PLLOUT_DIVSEL_SHIFT,
  469. .divsel = PRCM_DSI_PLLOUT_SEL_PHI,
  470. }
  471. };
  472. struct dsiescclk {
  473. u32 en;
  474. u32 div_mask;
  475. u32 div_shift;
  476. };
  477. static struct dsiescclk dsiescclk[3] = {
  478. {
  479. .en = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_EN,
  480. .div_mask = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_MASK,
  481. .div_shift = PRCM_DSITVCLK_DIV_DSI0_ESC_CLK_DIV_SHIFT,
  482. },
  483. {
  484. .en = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_EN,
  485. .div_mask = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_MASK,
  486. .div_shift = PRCM_DSITVCLK_DIV_DSI1_ESC_CLK_DIV_SHIFT,
  487. },
  488. {
  489. .en = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_EN,
  490. .div_mask = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_MASK,
  491. .div_shift = PRCM_DSITVCLK_DIV_DSI2_ESC_CLK_DIV_SHIFT,
  492. }
  493. };
  494. /*
  495. * Used by MCDE to setup all necessary PRCMU registers
  496. */
  497. #define PRCMU_RESET_DSIPLL 0x00004000
  498. #define PRCMU_UNCLAMP_DSIPLL 0x00400800
  499. #define PRCMU_CLK_PLL_DIV_SHIFT 0
  500. #define PRCMU_CLK_PLL_SW_SHIFT 5
  501. #define PRCMU_CLK_38 (1 << 9)
  502. #define PRCMU_CLK_38_SRC (1 << 10)
  503. #define PRCMU_CLK_38_DIV (1 << 11)
  504. /* PLLDIV=12, PLLSW=4 (PLLDDR) */
  505. #define PRCMU_DSI_CLOCK_SETTING 0x0000008C
  506. /* DPI 50000000 Hz */
  507. #define PRCMU_DPI_CLOCK_SETTING ((1 << PRCMU_CLK_PLL_SW_SHIFT) | \
  508. (16 << PRCMU_CLK_PLL_DIV_SHIFT))
  509. #define PRCMU_DSI_LP_CLOCK_SETTING 0x00000E00
  510. /* D=101, N=1, R=4, SELDIV2=0 */
  511. #define PRCMU_PLLDSI_FREQ_SETTING 0x00040165
  512. #define PRCMU_ENABLE_PLLDSI 0x00000001
  513. #define PRCMU_DISABLE_PLLDSI 0x00000000
  514. #define PRCMU_RELEASE_RESET_DSS 0x0000400C
  515. #define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000202
  516. /* ESC clk, div0=1, div1=1, div2=3 */
  517. #define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x07030101
  518. #define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00030101
  519. #define PRCMU_DSI_RESET_SW 0x00000007
  520. #define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
  521. int db8500_prcmu_enable_dsipll(void)
  522. {
  523. int i;
  524. /* Clear DSIPLL_RESETN */
  525. writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR);
  526. /* Unclamp DSIPLL in/out */
  527. writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR);
  528. /* Set DSI PLL FREQ */
  529. writel(PRCMU_PLLDSI_FREQ_SETTING, PRCM_PLLDSI_FREQ);
  530. writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL);
  531. /* Enable Escape clocks */
  532. writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
  533. /* Start DSI PLL */
  534. writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
  535. /* Reset DSI PLL */
  536. writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET);
  537. for (i = 0; i < 10; i++) {
  538. if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED)
  539. == PRCMU_PLLDSI_LOCKP_LOCKED)
  540. break;
  541. udelay(100);
  542. }
  543. /* Set DSIPLL_RESETN */
  544. writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET);
  545. return 0;
  546. }
  547. int db8500_prcmu_disable_dsipll(void)
  548. {
  549. /* Disable dsi pll */
  550. writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
  551. /* Disable escapeclock */
  552. writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
  553. return 0;
  554. }
  555. int db8500_prcmu_set_display_clocks(void)
  556. {
  557. unsigned long flags;
  558. spin_lock_irqsave(&clk_mgt_lock, flags);
  559. /* Grab the HW semaphore. */
  560. while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  561. cpu_relax();
  562. writel(PRCMU_DSI_CLOCK_SETTING, prcmu_base + PRCM_HDMICLK_MGT);
  563. writel(PRCMU_DSI_LP_CLOCK_SETTING, prcmu_base + PRCM_TVCLK_MGT);
  564. writel(PRCMU_DPI_CLOCK_SETTING, prcmu_base + PRCM_LCDCLK_MGT);
  565. /* Release the HW semaphore. */
  566. writel(0, PRCM_SEM);
  567. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  568. return 0;
  569. }
  570. u32 db8500_prcmu_read(unsigned int reg)
  571. {
  572. return readl(prcmu_base + reg);
  573. }
  574. void db8500_prcmu_write(unsigned int reg, u32 value)
  575. {
  576. unsigned long flags;
  577. spin_lock_irqsave(&prcmu_lock, flags);
  578. writel(value, (prcmu_base + reg));
  579. spin_unlock_irqrestore(&prcmu_lock, flags);
  580. }
  581. void db8500_prcmu_write_masked(unsigned int reg, u32 mask, u32 value)
  582. {
  583. u32 val;
  584. unsigned long flags;
  585. spin_lock_irqsave(&prcmu_lock, flags);
  586. val = readl(prcmu_base + reg);
  587. val = ((val & ~mask) | (value & mask));
  588. writel(val, (prcmu_base + reg));
  589. spin_unlock_irqrestore(&prcmu_lock, flags);
  590. }
  591. struct prcmu_fw_version *prcmu_get_fw_version(void)
  592. {
  593. return fw_info.valid ? &fw_info.version : NULL;
  594. }
  595. bool prcmu_has_arm_maxopp(void)
  596. {
  597. return (readb(tcdm_base + PRCM_AVS_VARM_MAX_OPP) &
  598. PRCM_AVS_ISMODEENABLE_MASK) == PRCM_AVS_ISMODEENABLE_MASK;
  599. }
  600. /**
  601. * prcmu_set_rc_a2p - This function is used to run few power state sequences
  602. * @val: Value to be set, i.e. transition requested
  603. * Returns: 0 on success, -EINVAL on invalid argument
  604. *
  605. * This function is used to run the following power state sequences -
  606. * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
  607. */
  608. int prcmu_set_rc_a2p(enum romcode_write val)
  609. {
  610. if (val < RDY_2_DS || val > RDY_2_XP70_RST)
  611. return -EINVAL;
  612. writeb(val, (tcdm_base + PRCM_ROMCODE_A2P));
  613. return 0;
  614. }
  615. /**
  616. * prcmu_get_rc_p2a - This function is used to get power state sequences
  617. * Returns: the power transition that has last happened
  618. *
  619. * This function can return the following transitions-
  620. * any state to ApReset, ApDeepSleep to ApExecute, ApExecute to ApDeepSleep
  621. */
  622. enum romcode_read prcmu_get_rc_p2a(void)
  623. {
  624. return readb(tcdm_base + PRCM_ROMCODE_P2A);
  625. }
  626. /**
  627. * prcmu_get_current_mode - Return the current XP70 power mode
  628. * Returns: Returns the current AP(ARM) power mode: init,
  629. * apBoot, apExecute, apDeepSleep, apSleep, apIdle, apReset
  630. */
  631. enum ap_pwrst prcmu_get_xp70_current_state(void)
  632. {
  633. return readb(tcdm_base + PRCM_XP70_CUR_PWR_STATE);
  634. }
  635. /**
  636. * prcmu_config_clkout - Configure one of the programmable clock outputs.
  637. * @clkout: The CLKOUT number (0 or 1).
  638. * @source: The clock to be used (one of the PRCMU_CLKSRC_*).
  639. * @div: The divider to be applied.
  640. *
  641. * Configures one of the programmable clock outputs (CLKOUTs).
  642. * @div should be in the range [1,63] to request a configuration, or 0 to
  643. * inform that the configuration is no longer requested.
  644. */
  645. int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
  646. {
  647. static int requests[2];
  648. int r = 0;
  649. unsigned long flags;
  650. u32 val;
  651. u32 bits;
  652. u32 mask;
  653. u32 div_mask;
  654. BUG_ON(clkout > 1);
  655. BUG_ON(div > 63);
  656. BUG_ON((clkout == 0) && (source > PRCMU_CLKSRC_CLK009));
  657. if (!div && !requests[clkout])
  658. return -EINVAL;
  659. if (clkout == 0) {
  660. div_mask = PRCM_CLKOCR_CLKODIV0_MASK;
  661. mask = (PRCM_CLKOCR_CLKODIV0_MASK | PRCM_CLKOCR_CLKOSEL0_MASK);
  662. bits = ((source << PRCM_CLKOCR_CLKOSEL0_SHIFT) |
  663. (div << PRCM_CLKOCR_CLKODIV0_SHIFT));
  664. } else {
  665. div_mask = PRCM_CLKOCR_CLKODIV1_MASK;
  666. mask = (PRCM_CLKOCR_CLKODIV1_MASK | PRCM_CLKOCR_CLKOSEL1_MASK |
  667. PRCM_CLKOCR_CLK1TYPE);
  668. bits = ((source << PRCM_CLKOCR_CLKOSEL1_SHIFT) |
  669. (div << PRCM_CLKOCR_CLKODIV1_SHIFT));
  670. }
  671. bits &= mask;
  672. spin_lock_irqsave(&clkout_lock, flags);
  673. val = readl(PRCM_CLKOCR);
  674. if (val & div_mask) {
  675. if (div) {
  676. if ((val & mask) != bits) {
  677. r = -EBUSY;
  678. goto unlock_and_return;
  679. }
  680. } else {
  681. if ((val & mask & ~div_mask) != bits) {
  682. r = -EINVAL;
  683. goto unlock_and_return;
  684. }
  685. }
  686. }
  687. writel((bits | (val & ~mask)), PRCM_CLKOCR);
  688. requests[clkout] += (div ? 1 : -1);
  689. unlock_and_return:
  690. spin_unlock_irqrestore(&clkout_lock, flags);
  691. return r;
  692. }
  693. int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
  694. {
  695. unsigned long flags;
  696. BUG_ON((state < PRCMU_AP_SLEEP) || (PRCMU_AP_DEEP_IDLE < state));
  697. spin_lock_irqsave(&mb0_transfer.lock, flags);
  698. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  699. cpu_relax();
  700. writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  701. writeb(state, (tcdm_base + PRCM_REQ_MB0_AP_POWER_STATE));
  702. writeb((keep_ap_pll ? 1 : 0), (tcdm_base + PRCM_REQ_MB0_AP_PLL_STATE));
  703. writeb((keep_ulp_clk ? 1 : 0),
  704. (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
  705. writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
  706. writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
  707. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  708. return 0;
  709. }
  710. u8 db8500_prcmu_get_power_state_result(void)
  711. {
  712. return readb(tcdm_base + PRCM_ACK_MB0_AP_PWRSTTR_STATUS);
  713. }
  714. /* This function should only be called while mb0_transfer.lock is held. */
  715. static void config_wakeups(void)
  716. {
  717. const u8 header[2] = {
  718. MB0H_CONFIG_WAKEUPS_EXE,
  719. MB0H_CONFIG_WAKEUPS_SLEEP
  720. };
  721. static u32 last_dbb_events;
  722. static u32 last_abb_events;
  723. u32 dbb_events;
  724. u32 abb_events;
  725. unsigned int i;
  726. dbb_events = mb0_transfer.req.dbb_irqs | mb0_transfer.req.dbb_wakeups;
  727. dbb_events |= (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK);
  728. abb_events = mb0_transfer.req.abb_events;
  729. if ((dbb_events == last_dbb_events) && (abb_events == last_abb_events))
  730. return;
  731. for (i = 0; i < 2; i++) {
  732. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  733. cpu_relax();
  734. writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
  735. writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
  736. writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  737. writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
  738. }
  739. last_dbb_events = dbb_events;
  740. last_abb_events = abb_events;
  741. }
  742. void db8500_prcmu_enable_wakeups(u32 wakeups)
  743. {
  744. unsigned long flags;
  745. u32 bits;
  746. int i;
  747. BUG_ON(wakeups != (wakeups & VALID_WAKEUPS));
  748. for (i = 0, bits = 0; i < NUM_PRCMU_WAKEUP_INDICES; i++) {
  749. if (wakeups & BIT(i))
  750. bits |= prcmu_wakeup_bit[i];
  751. }
  752. spin_lock_irqsave(&mb0_transfer.lock, flags);
  753. mb0_transfer.req.dbb_wakeups = bits;
  754. config_wakeups();
  755. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  756. }
  757. void db8500_prcmu_config_abb_event_readout(u32 abb_events)
  758. {
  759. unsigned long flags;
  760. spin_lock_irqsave(&mb0_transfer.lock, flags);
  761. mb0_transfer.req.abb_events = abb_events;
  762. config_wakeups();
  763. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  764. }
  765. void db8500_prcmu_get_abb_event_buffer(void __iomem **buf)
  766. {
  767. if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
  768. *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
  769. else
  770. *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_0_4500);
  771. }
  772. /**
  773. * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP
  774. * @opp: The new ARM operating point to which transition is to be made
  775. * Returns: 0 on success, non-zero on failure
  776. *
  777. * This function sets the the operating point of the ARM.
  778. */
  779. int db8500_prcmu_set_arm_opp(u8 opp)
  780. {
  781. int r;
  782. if (opp < ARM_NO_CHANGE || opp > ARM_EXTCLK)
  783. return -EINVAL;
  784. r = 0;
  785. mutex_lock(&mb1_transfer.lock);
  786. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  787. cpu_relax();
  788. writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  789. writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
  790. writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
  791. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  792. wait_for_completion(&mb1_transfer.work);
  793. if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
  794. (mb1_transfer.ack.arm_opp != opp))
  795. r = -EIO;
  796. mutex_unlock(&mb1_transfer.lock);
  797. return r;
  798. }
  799. /**
  800. * db8500_prcmu_get_arm_opp - get the current ARM OPP
  801. *
  802. * Returns: the current ARM OPP
  803. */
  804. int db8500_prcmu_get_arm_opp(void)
  805. {
  806. return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
  807. }
  808. /**
  809. * db8500_prcmu_get_ddr_opp - get the current DDR OPP
  810. *
  811. * Returns: the current DDR OPP
  812. */
  813. int db8500_prcmu_get_ddr_opp(void)
  814. {
  815. return readb(PRCM_DDR_SUBSYS_APE_MINBW);
  816. }
  817. /* Divide the frequency of certain clocks by 2 for APE_50_PARTLY_25_OPP. */
  818. static void request_even_slower_clocks(bool enable)
  819. {
  820. u32 clock_reg[] = {
  821. PRCM_ACLK_MGT,
  822. PRCM_DMACLK_MGT
  823. };
  824. unsigned long flags;
  825. unsigned int i;
  826. spin_lock_irqsave(&clk_mgt_lock, flags);
  827. /* Grab the HW semaphore. */
  828. while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  829. cpu_relax();
  830. for (i = 0; i < ARRAY_SIZE(clock_reg); i++) {
  831. u32 val;
  832. u32 div;
  833. val = readl(prcmu_base + clock_reg[i]);
  834. div = (val & PRCM_CLK_MGT_CLKPLLDIV_MASK);
  835. if (enable) {
  836. if ((div <= 1) || (div > 15)) {
  837. pr_err("prcmu: Bad clock divider %d in %s\n",
  838. div, __func__);
  839. goto unlock_and_return;
  840. }
  841. div <<= 1;
  842. } else {
  843. if (div <= 2)
  844. goto unlock_and_return;
  845. div >>= 1;
  846. }
  847. val = ((val & ~PRCM_CLK_MGT_CLKPLLDIV_MASK) |
  848. (div & PRCM_CLK_MGT_CLKPLLDIV_MASK));
  849. writel(val, prcmu_base + clock_reg[i]);
  850. }
  851. unlock_and_return:
  852. /* Release the HW semaphore. */
  853. writel(0, PRCM_SEM);
  854. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  855. }
  856. /**
  857. * db8500_set_ape_opp - set the appropriate APE OPP
  858. * @opp: The new APE operating point to which transition is to be made
  859. * Returns: 0 on success, non-zero on failure
  860. *
  861. * This function sets the operating point of the APE.
  862. */
  863. int db8500_prcmu_set_ape_opp(u8 opp)
  864. {
  865. int r = 0;
  866. if (opp == mb1_transfer.ape_opp)
  867. return 0;
  868. mutex_lock(&mb1_transfer.lock);
  869. if (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)
  870. request_even_slower_clocks(false);
  871. if ((opp != APE_100_OPP) && (mb1_transfer.ape_opp != APE_100_OPP))
  872. goto skip_message;
  873. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  874. cpu_relax();
  875. writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  876. writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
  877. writeb(((opp == APE_50_PARTLY_25_OPP) ? APE_50_OPP : opp),
  878. (tcdm_base + PRCM_REQ_MB1_APE_OPP));
  879. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  880. wait_for_completion(&mb1_transfer.work);
  881. if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
  882. (mb1_transfer.ack.ape_opp != opp))
  883. r = -EIO;
  884. skip_message:
  885. if ((!r && (opp == APE_50_PARTLY_25_OPP)) ||
  886. (r && (mb1_transfer.ape_opp == APE_50_PARTLY_25_OPP)))
  887. request_even_slower_clocks(true);
  888. if (!r)
  889. mb1_transfer.ape_opp = opp;
  890. mutex_unlock(&mb1_transfer.lock);
  891. return r;
  892. }
  893. /**
  894. * db8500_prcmu_get_ape_opp - get the current APE OPP
  895. *
  896. * Returns: the current APE OPP
  897. */
  898. int db8500_prcmu_get_ape_opp(void)
  899. {
  900. return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_APE_OPP);
  901. }
  902. /**
  903. * db8500_prcmu_request_ape_opp_100_voltage - Request APE OPP 100% voltage
  904. * @enable: true to request the higher voltage, false to drop a request.
  905. *
  906. * Calls to this function to enable and disable requests must be balanced.
  907. */
  908. int db8500_prcmu_request_ape_opp_100_voltage(bool enable)
  909. {
  910. int r = 0;
  911. u8 header;
  912. static unsigned int requests;
  913. mutex_lock(&mb1_transfer.lock);
  914. if (enable) {
  915. if (0 != requests++)
  916. goto unlock_and_return;
  917. header = MB1H_REQUEST_APE_OPP_100_VOLT;
  918. } else {
  919. if (requests == 0) {
  920. r = -EIO;
  921. goto unlock_and_return;
  922. } else if (1 != requests--) {
  923. goto unlock_and_return;
  924. }
  925. header = MB1H_RELEASE_APE_OPP_100_VOLT;
  926. }
  927. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  928. cpu_relax();
  929. writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  930. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  931. wait_for_completion(&mb1_transfer.work);
  932. if ((mb1_transfer.ack.header != header) ||
  933. ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
  934. r = -EIO;
  935. unlock_and_return:
  936. mutex_unlock(&mb1_transfer.lock);
  937. return r;
  938. }
  939. /**
  940. * prcmu_release_usb_wakeup_state - release the state required by a USB wakeup
  941. *
  942. * This function releases the power state requirements of a USB wakeup.
  943. */
  944. int prcmu_release_usb_wakeup_state(void)
  945. {
  946. int r = 0;
  947. mutex_lock(&mb1_transfer.lock);
  948. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  949. cpu_relax();
  950. writeb(MB1H_RELEASE_USB_WAKEUP,
  951. (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  952. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  953. wait_for_completion(&mb1_transfer.work);
  954. if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
  955. ((mb1_transfer.ack.ape_voltage_status & BIT(0)) != 0))
  956. r = -EIO;
  957. mutex_unlock(&mb1_transfer.lock);
  958. return r;
  959. }
  960. static int request_pll(u8 clock, bool enable)
  961. {
  962. int r = 0;
  963. if (clock == PRCMU_PLLSOC0)
  964. clock = (enable ? PLL_SOC0_ON : PLL_SOC0_OFF);
  965. else if (clock == PRCMU_PLLSOC1)
  966. clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF);
  967. else
  968. return -EINVAL;
  969. mutex_lock(&mb1_transfer.lock);
  970. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  971. cpu_relax();
  972. writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  973. writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF));
  974. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  975. wait_for_completion(&mb1_transfer.work);
  976. if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF)
  977. r = -EIO;
  978. mutex_unlock(&mb1_transfer.lock);
  979. return r;
  980. }
  981. /**
  982. * db8500_prcmu_set_epod - set the state of a EPOD (power domain)
  983. * @epod_id: The EPOD to set
  984. * @epod_state: The new EPOD state
  985. *
  986. * This function sets the state of a EPOD (power domain). It may not be called
  987. * from interrupt context.
  988. */
  989. int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state)
  990. {
  991. int r = 0;
  992. bool ram_retention = false;
  993. int i;
  994. /* check argument */
  995. BUG_ON(epod_id >= NUM_EPOD_ID);
  996. /* set flag if retention is possible */
  997. switch (epod_id) {
  998. case EPOD_ID_SVAMMDSP:
  999. case EPOD_ID_SIAMMDSP:
  1000. case EPOD_ID_ESRAM12:
  1001. case EPOD_ID_ESRAM34:
  1002. ram_retention = true;
  1003. break;
  1004. }
  1005. /* check argument */
  1006. BUG_ON(epod_state > EPOD_STATE_ON);
  1007. BUG_ON(epod_state == EPOD_STATE_RAMRET && !ram_retention);
  1008. /* get lock */
  1009. mutex_lock(&mb2_transfer.lock);
  1010. /* wait for mailbox */
  1011. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
  1012. cpu_relax();
  1013. /* fill in mailbox */
  1014. for (i = 0; i < NUM_EPOD_ID; i++)
  1015. writeb(EPOD_STATE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB2 + i));
  1016. writeb(epod_state, (tcdm_base + PRCM_REQ_MB2 + epod_id));
  1017. writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
  1018. writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET);
  1019. /*
  1020. * The current firmware version does not handle errors correctly,
  1021. * and we cannot recover if there is an error.
  1022. * This is expected to change when the firmware is updated.
  1023. */
  1024. if (!wait_for_completion_timeout(&mb2_transfer.work,
  1025. msecs_to_jiffies(20000))) {
  1026. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1027. __func__);
  1028. r = -EIO;
  1029. goto unlock_and_return;
  1030. }
  1031. if (mb2_transfer.ack.status != HWACC_PWR_ST_OK)
  1032. r = -EIO;
  1033. unlock_and_return:
  1034. mutex_unlock(&mb2_transfer.lock);
  1035. return r;
  1036. }
  1037. /**
  1038. * prcmu_configure_auto_pm - Configure autonomous power management.
  1039. * @sleep: Configuration for ApSleep.
  1040. * @idle: Configuration for ApIdle.
  1041. */
  1042. void prcmu_configure_auto_pm(struct prcmu_auto_pm_config *sleep,
  1043. struct prcmu_auto_pm_config *idle)
  1044. {
  1045. u32 sleep_cfg;
  1046. u32 idle_cfg;
  1047. unsigned long flags;
  1048. BUG_ON((sleep == NULL) || (idle == NULL));
  1049. sleep_cfg = (sleep->sva_auto_pm_enable & 0xF);
  1050. sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_auto_pm_enable & 0xF));
  1051. sleep_cfg = ((sleep_cfg << 8) | (sleep->sva_power_on & 0xFF));
  1052. sleep_cfg = ((sleep_cfg << 8) | (sleep->sia_power_on & 0xFF));
  1053. sleep_cfg = ((sleep_cfg << 4) | (sleep->sva_policy & 0xF));
  1054. sleep_cfg = ((sleep_cfg << 4) | (sleep->sia_policy & 0xF));
  1055. idle_cfg = (idle->sva_auto_pm_enable & 0xF);
  1056. idle_cfg = ((idle_cfg << 4) | (idle->sia_auto_pm_enable & 0xF));
  1057. idle_cfg = ((idle_cfg << 8) | (idle->sva_power_on & 0xFF));
  1058. idle_cfg = ((idle_cfg << 8) | (idle->sia_power_on & 0xFF));
  1059. idle_cfg = ((idle_cfg << 4) | (idle->sva_policy & 0xF));
  1060. idle_cfg = ((idle_cfg << 4) | (idle->sia_policy & 0xF));
  1061. spin_lock_irqsave(&mb2_transfer.auto_pm_lock, flags);
  1062. /*
  1063. * The autonomous power management configuration is done through
  1064. * fields in mailbox 2, but these fields are only used as shared
  1065. * variables - i.e. there is no need to send a message.
  1066. */
  1067. writel(sleep_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_SLEEP));
  1068. writel(idle_cfg, (tcdm_base + PRCM_REQ_MB2_AUTO_PM_IDLE));
  1069. mb2_transfer.auto_pm_enabled =
  1070. ((sleep->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  1071. (sleep->sia_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  1072. (idle->sva_auto_pm_enable == PRCMU_AUTO_PM_ON) ||
  1073. (idle->sia_auto_pm_enable == PRCMU_AUTO_PM_ON));
  1074. spin_unlock_irqrestore(&mb2_transfer.auto_pm_lock, flags);
  1075. }
  1076. EXPORT_SYMBOL(prcmu_configure_auto_pm);
  1077. bool prcmu_is_auto_pm_enabled(void)
  1078. {
  1079. return mb2_transfer.auto_pm_enabled;
  1080. }
  1081. static int request_sysclk(bool enable)
  1082. {
  1083. int r;
  1084. unsigned long flags;
  1085. r = 0;
  1086. mutex_lock(&mb3_transfer.sysclk_lock);
  1087. spin_lock_irqsave(&mb3_transfer.lock, flags);
  1088. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
  1089. cpu_relax();
  1090. writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
  1091. writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
  1092. writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET);
  1093. spin_unlock_irqrestore(&mb3_transfer.lock, flags);
  1094. /*
  1095. * The firmware only sends an ACK if we want to enable the
  1096. * SysClk, and it succeeds.
  1097. */
  1098. if (enable && !wait_for_completion_timeout(&mb3_transfer.sysclk_work,
  1099. msecs_to_jiffies(20000))) {
  1100. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1101. __func__);
  1102. r = -EIO;
  1103. }
  1104. mutex_unlock(&mb3_transfer.sysclk_lock);
  1105. return r;
  1106. }
  1107. static int request_timclk(bool enable)
  1108. {
  1109. u32 val = (PRCM_TCR_DOZE_MODE | PRCM_TCR_TENSEL_MASK);
  1110. if (!enable)
  1111. val |= PRCM_TCR_STOP_TIMERS;
  1112. writel(val, PRCM_TCR);
  1113. return 0;
  1114. }
  1115. static int request_clock(u8 clock, bool enable)
  1116. {
  1117. u32 val;
  1118. unsigned long flags;
  1119. spin_lock_irqsave(&clk_mgt_lock, flags);
  1120. /* Grab the HW semaphore. */
  1121. while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  1122. cpu_relax();
  1123. val = readl(prcmu_base + clk_mgt[clock].offset);
  1124. if (enable) {
  1125. val |= (PRCM_CLK_MGT_CLKEN | clk_mgt[clock].pllsw);
  1126. } else {
  1127. clk_mgt[clock].pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
  1128. val &= ~(PRCM_CLK_MGT_CLKEN | PRCM_CLK_MGT_CLKPLLSW_MASK);
  1129. }
  1130. writel(val, prcmu_base + clk_mgt[clock].offset);
  1131. /* Release the HW semaphore. */
  1132. writel(0, PRCM_SEM);
  1133. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  1134. return 0;
  1135. }
  1136. static int request_sga_clock(u8 clock, bool enable)
  1137. {
  1138. u32 val;
  1139. int ret;
  1140. if (enable) {
  1141. val = readl(PRCM_CGATING_BYPASS);
  1142. writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
  1143. }
  1144. ret = request_clock(clock, enable);
  1145. if (!ret && !enable) {
  1146. val = readl(PRCM_CGATING_BYPASS);
  1147. writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
  1148. }
  1149. return ret;
  1150. }
  1151. static inline bool plldsi_locked(void)
  1152. {
  1153. return (readl(PRCM_PLLDSI_LOCKP) &
  1154. (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
  1155. PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3)) ==
  1156. (PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP10 |
  1157. PRCM_PLLDSI_LOCKP_PRCM_PLLDSI_LOCKP3);
  1158. }
  1159. static int request_plldsi(bool enable)
  1160. {
  1161. int r = 0;
  1162. u32 val;
  1163. writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
  1164. PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI), (enable ?
  1165. PRCM_MMIP_LS_CLAMP_CLR : PRCM_MMIP_LS_CLAMP_SET));
  1166. val = readl(PRCM_PLLDSI_ENABLE);
  1167. if (enable)
  1168. val |= PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
  1169. else
  1170. val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
  1171. writel(val, PRCM_PLLDSI_ENABLE);
  1172. if (enable) {
  1173. unsigned int i;
  1174. bool locked = plldsi_locked();
  1175. for (i = 10; !locked && (i > 0); --i) {
  1176. udelay(100);
  1177. locked = plldsi_locked();
  1178. }
  1179. if (locked) {
  1180. writel(PRCM_APE_RESETN_DSIPLL_RESETN,
  1181. PRCM_APE_RESETN_SET);
  1182. } else {
  1183. writel((PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMP |
  1184. PRCM_MMIP_LS_CLAMP_DSIPLL_CLAMPI),
  1185. PRCM_MMIP_LS_CLAMP_SET);
  1186. val &= ~PRCM_PLLDSI_ENABLE_PRCM_PLLDSI_ENABLE;
  1187. writel(val, PRCM_PLLDSI_ENABLE);
  1188. r = -EAGAIN;
  1189. }
  1190. } else {
  1191. writel(PRCM_APE_RESETN_DSIPLL_RESETN, PRCM_APE_RESETN_CLR);
  1192. }
  1193. return r;
  1194. }
  1195. static int request_dsiclk(u8 n, bool enable)
  1196. {
  1197. u32 val;
  1198. val = readl(PRCM_DSI_PLLOUT_SEL);
  1199. val &= ~dsiclk[n].divsel_mask;
  1200. val |= ((enable ? dsiclk[n].divsel : PRCM_DSI_PLLOUT_SEL_OFF) <<
  1201. dsiclk[n].divsel_shift);
  1202. writel(val, PRCM_DSI_PLLOUT_SEL);
  1203. return 0;
  1204. }
  1205. static int request_dsiescclk(u8 n, bool enable)
  1206. {
  1207. u32 val;
  1208. val = readl(PRCM_DSITVCLK_DIV);
  1209. enable ? (val |= dsiescclk[n].en) : (val &= ~dsiescclk[n].en);
  1210. writel(val, PRCM_DSITVCLK_DIV);
  1211. return 0;
  1212. }
  1213. /**
  1214. * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled.
  1215. * @clock: The clock for which the request is made.
  1216. * @enable: Whether the clock should be enabled (true) or disabled (false).
  1217. *
  1218. * This function should only be used by the clock implementation.
  1219. * Do not use it from any other place!
  1220. */
  1221. int db8500_prcmu_request_clock(u8 clock, bool enable)
  1222. {
  1223. if (clock == PRCMU_SGACLK)
  1224. return request_sga_clock(clock, enable);
  1225. else if (clock < PRCMU_NUM_REG_CLOCKS)
  1226. return request_clock(clock, enable);
  1227. else if (clock == PRCMU_TIMCLK)
  1228. return request_timclk(enable);
  1229. else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
  1230. return request_dsiclk((clock - PRCMU_DSI0CLK), enable);
  1231. else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
  1232. return request_dsiescclk((clock - PRCMU_DSI0ESCCLK), enable);
  1233. else if (clock == PRCMU_PLLDSI)
  1234. return request_plldsi(enable);
  1235. else if (clock == PRCMU_SYSCLK)
  1236. return request_sysclk(enable);
  1237. else if ((clock == PRCMU_PLLSOC0) || (clock == PRCMU_PLLSOC1))
  1238. return request_pll(clock, enable);
  1239. else
  1240. return -EINVAL;
  1241. }
  1242. static unsigned long pll_rate(void __iomem *reg, unsigned long src_rate,
  1243. int branch)
  1244. {
  1245. u64 rate;
  1246. u32 val;
  1247. u32 d;
  1248. u32 div = 1;
  1249. val = readl(reg);
  1250. rate = src_rate;
  1251. rate *= ((val & PRCM_PLL_FREQ_D_MASK) >> PRCM_PLL_FREQ_D_SHIFT);
  1252. d = ((val & PRCM_PLL_FREQ_N_MASK) >> PRCM_PLL_FREQ_N_SHIFT);
  1253. if (d > 1)
  1254. div *= d;
  1255. d = ((val & PRCM_PLL_FREQ_R_MASK) >> PRCM_PLL_FREQ_R_SHIFT);
  1256. if (d > 1)
  1257. div *= d;
  1258. if (val & PRCM_PLL_FREQ_SELDIV2)
  1259. div *= 2;
  1260. if ((branch == PLL_FIX) || ((branch == PLL_DIV) &&
  1261. (val & PRCM_PLL_FREQ_DIV2EN) &&
  1262. ((reg == PRCM_PLLSOC0_FREQ) ||
  1263. (reg == PRCM_PLLARM_FREQ) ||
  1264. (reg == PRCM_PLLDDR_FREQ))))
  1265. div *= 2;
  1266. (void)do_div(rate, div);
  1267. return (unsigned long)rate;
  1268. }
  1269. #define ROOT_CLOCK_RATE 38400000
  1270. static unsigned long clock_rate(u8 clock)
  1271. {
  1272. u32 val;
  1273. u32 pllsw;
  1274. unsigned long rate = ROOT_CLOCK_RATE;
  1275. val = readl(prcmu_base + clk_mgt[clock].offset);
  1276. if (val & PRCM_CLK_MGT_CLK38) {
  1277. if (clk_mgt[clock].clk38div && (val & PRCM_CLK_MGT_CLK38DIV))
  1278. rate /= 2;
  1279. return rate;
  1280. }
  1281. val |= clk_mgt[clock].pllsw;
  1282. pllsw = (val & PRCM_CLK_MGT_CLKPLLSW_MASK);
  1283. if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC0)
  1284. rate = pll_rate(PRCM_PLLSOC0_FREQ, rate, clk_mgt[clock].branch);
  1285. else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_SOC1)
  1286. rate = pll_rate(PRCM_PLLSOC1_FREQ, rate, clk_mgt[clock].branch);
  1287. else if (pllsw == PRCM_CLK_MGT_CLKPLLSW_DDR)
  1288. rate = pll_rate(PRCM_PLLDDR_FREQ, rate, clk_mgt[clock].branch);
  1289. else
  1290. return 0;
  1291. if ((clock == PRCMU_SGACLK) &&
  1292. (val & PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN)) {
  1293. u64 r = (rate * 10);
  1294. (void)do_div(r, 25);
  1295. return (unsigned long)r;
  1296. }
  1297. val &= PRCM_CLK_MGT_CLKPLLDIV_MASK;
  1298. if (val)
  1299. return rate / val;
  1300. else
  1301. return 0;
  1302. }
  1303. static unsigned long armss_rate(void)
  1304. {
  1305. u32 r;
  1306. unsigned long rate;
  1307. r = readl(PRCM_ARM_CHGCLKREQ);
  1308. if (r & PRCM_ARM_CHGCLKREQ_PRCM_ARM_CHGCLKREQ) {
  1309. /* External ARMCLKFIX clock */
  1310. rate = pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_FIX);
  1311. /* Check PRCM_ARM_CHGCLKREQ divider */
  1312. if (!(r & PRCM_ARM_CHGCLKREQ_PRCM_ARM_DIVSEL))
  1313. rate /= 2;
  1314. /* Check PRCM_ARMCLKFIX_MGT divider */
  1315. r = readl(PRCM_ARMCLKFIX_MGT);
  1316. r &= PRCM_CLK_MGT_CLKPLLDIV_MASK;
  1317. rate /= r;
  1318. } else {/* ARM PLL */
  1319. rate = pll_rate(PRCM_PLLARM_FREQ, ROOT_CLOCK_RATE, PLL_DIV);
  1320. }
  1321. return rate;
  1322. }
  1323. static unsigned long dsiclk_rate(u8 n)
  1324. {
  1325. u32 divsel;
  1326. u32 div = 1;
  1327. divsel = readl(PRCM_DSI_PLLOUT_SEL);
  1328. divsel = ((divsel & dsiclk[n].divsel_mask) >> dsiclk[n].divsel_shift);
  1329. if (divsel == PRCM_DSI_PLLOUT_SEL_OFF)
  1330. divsel = dsiclk[n].divsel;
  1331. else
  1332. dsiclk[n].divsel = divsel;
  1333. switch (divsel) {
  1334. case PRCM_DSI_PLLOUT_SEL_PHI_4:
  1335. div *= 2;
  1336. case PRCM_DSI_PLLOUT_SEL_PHI_2:
  1337. div *= 2;
  1338. case PRCM_DSI_PLLOUT_SEL_PHI:
  1339. return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
  1340. PLL_RAW) / div;
  1341. default:
  1342. return 0;
  1343. }
  1344. }
  1345. static unsigned long dsiescclk_rate(u8 n)
  1346. {
  1347. u32 div;
  1348. div = readl(PRCM_DSITVCLK_DIV);
  1349. div = ((div & dsiescclk[n].div_mask) >> (dsiescclk[n].div_shift));
  1350. return clock_rate(PRCMU_TVCLK) / max((u32)1, div);
  1351. }
  1352. unsigned long prcmu_clock_rate(u8 clock)
  1353. {
  1354. if (clock < PRCMU_NUM_REG_CLOCKS)
  1355. return clock_rate(clock);
  1356. else if (clock == PRCMU_TIMCLK)
  1357. return ROOT_CLOCK_RATE / 16;
  1358. else if (clock == PRCMU_SYSCLK)
  1359. return ROOT_CLOCK_RATE;
  1360. else if (clock == PRCMU_PLLSOC0)
  1361. return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
  1362. else if (clock == PRCMU_PLLSOC1)
  1363. return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
  1364. else if (clock == PRCMU_ARMSS)
  1365. return armss_rate();
  1366. else if (clock == PRCMU_PLLDDR)
  1367. return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, PLL_RAW);
  1368. else if (clock == PRCMU_PLLDSI)
  1369. return pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
  1370. PLL_RAW);
  1371. else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
  1372. return dsiclk_rate(clock - PRCMU_DSI0CLK);
  1373. else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
  1374. return dsiescclk_rate(clock - PRCMU_DSI0ESCCLK);
  1375. else
  1376. return 0;
  1377. }
  1378. static unsigned long clock_source_rate(u32 clk_mgt_val, int branch)
  1379. {
  1380. if (clk_mgt_val & PRCM_CLK_MGT_CLK38)
  1381. return ROOT_CLOCK_RATE;
  1382. clk_mgt_val &= PRCM_CLK_MGT_CLKPLLSW_MASK;
  1383. if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC0)
  1384. return pll_rate(PRCM_PLLSOC0_FREQ, ROOT_CLOCK_RATE, branch);
  1385. else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_SOC1)
  1386. return pll_rate(PRCM_PLLSOC1_FREQ, ROOT_CLOCK_RATE, branch);
  1387. else if (clk_mgt_val == PRCM_CLK_MGT_CLKPLLSW_DDR)
  1388. return pll_rate(PRCM_PLLDDR_FREQ, ROOT_CLOCK_RATE, branch);
  1389. else
  1390. return 0;
  1391. }
  1392. static u32 clock_divider(unsigned long src_rate, unsigned long rate)
  1393. {
  1394. u32 div;
  1395. div = (src_rate / rate);
  1396. if (div == 0)
  1397. return 1;
  1398. if (rate < (src_rate / div))
  1399. div++;
  1400. return div;
  1401. }
  1402. static long round_clock_rate(u8 clock, unsigned long rate)
  1403. {
  1404. u32 val;
  1405. u32 div;
  1406. unsigned long src_rate;
  1407. long rounded_rate;
  1408. val = readl(prcmu_base + clk_mgt[clock].offset);
  1409. src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
  1410. clk_mgt[clock].branch);
  1411. div = clock_divider(src_rate, rate);
  1412. if (val & PRCM_CLK_MGT_CLK38) {
  1413. if (clk_mgt[clock].clk38div) {
  1414. if (div > 2)
  1415. div = 2;
  1416. } else {
  1417. div = 1;
  1418. }
  1419. } else if ((clock == PRCMU_SGACLK) && (div == 3)) {
  1420. u64 r = (src_rate * 10);
  1421. (void)do_div(r, 25);
  1422. if (r <= rate)
  1423. return (unsigned long)r;
  1424. }
  1425. rounded_rate = (src_rate / min(div, (u32)31));
  1426. return rounded_rate;
  1427. }
  1428. /* CPU FREQ table, may be changed due to if MAX_OPP is supported. */
  1429. static struct cpufreq_frequency_table db8500_cpufreq_table[] = {
  1430. { .frequency = 200000, .driver_data = ARM_EXTCLK,},
  1431. { .frequency = 400000, .driver_data = ARM_50_OPP,},
  1432. { .frequency = 800000, .driver_data = ARM_100_OPP,},
  1433. { .frequency = CPUFREQ_TABLE_END,}, /* To be used for MAX_OPP. */
  1434. { .frequency = CPUFREQ_TABLE_END,},
  1435. };
  1436. static long round_armss_rate(unsigned long rate)
  1437. {
  1438. struct cpufreq_frequency_table *pos;
  1439. long freq = 0;
  1440. /* cpufreq table frequencies is in KHz. */
  1441. rate = rate / 1000;
  1442. /* Find the corresponding arm opp from the cpufreq table. */
  1443. cpufreq_for_each_entry(pos, db8500_cpufreq_table) {
  1444. freq = pos->frequency;
  1445. if (freq == rate)
  1446. break;
  1447. }
  1448. /* Return the last valid value, even if a match was not found. */
  1449. return freq * 1000;
  1450. }
  1451. #define MIN_PLL_VCO_RATE 600000000ULL
  1452. #define MAX_PLL_VCO_RATE 1680640000ULL
  1453. static long round_plldsi_rate(unsigned long rate)
  1454. {
  1455. long rounded_rate = 0;
  1456. unsigned long src_rate;
  1457. unsigned long rem;
  1458. u32 r;
  1459. src_rate = clock_rate(PRCMU_HDMICLK);
  1460. rem = rate;
  1461. for (r = 7; (rem > 0) && (r > 0); r--) {
  1462. u64 d;
  1463. d = (r * rate);
  1464. (void)do_div(d, src_rate);
  1465. if (d < 6)
  1466. d = 6;
  1467. else if (d > 255)
  1468. d = 255;
  1469. d *= src_rate;
  1470. if (((2 * d) < (r * MIN_PLL_VCO_RATE)) ||
  1471. ((r * MAX_PLL_VCO_RATE) < (2 * d)))
  1472. continue;
  1473. (void)do_div(d, r);
  1474. if (rate < d) {
  1475. if (rounded_rate == 0)
  1476. rounded_rate = (long)d;
  1477. break;
  1478. }
  1479. if ((rate - d) < rem) {
  1480. rem = (rate - d);
  1481. rounded_rate = (long)d;
  1482. }
  1483. }
  1484. return rounded_rate;
  1485. }
  1486. static long round_dsiclk_rate(unsigned long rate)
  1487. {
  1488. u32 div;
  1489. unsigned long src_rate;
  1490. long rounded_rate;
  1491. src_rate = pll_rate(PRCM_PLLDSI_FREQ, clock_rate(PRCMU_HDMICLK),
  1492. PLL_RAW);
  1493. div = clock_divider(src_rate, rate);
  1494. rounded_rate = (src_rate / ((div > 2) ? 4 : div));
  1495. return rounded_rate;
  1496. }
  1497. static long round_dsiescclk_rate(unsigned long rate)
  1498. {
  1499. u32 div;
  1500. unsigned long src_rate;
  1501. long rounded_rate;
  1502. src_rate = clock_rate(PRCMU_TVCLK);
  1503. div = clock_divider(src_rate, rate);
  1504. rounded_rate = (src_rate / min(div, (u32)255));
  1505. return rounded_rate;
  1506. }
  1507. long prcmu_round_clock_rate(u8 clock, unsigned long rate)
  1508. {
  1509. if (clock < PRCMU_NUM_REG_CLOCKS)
  1510. return round_clock_rate(clock, rate);
  1511. else if (clock == PRCMU_ARMSS)
  1512. return round_armss_rate(rate);
  1513. else if (clock == PRCMU_PLLDSI)
  1514. return round_plldsi_rate(rate);
  1515. else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
  1516. return round_dsiclk_rate(rate);
  1517. else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
  1518. return round_dsiescclk_rate(rate);
  1519. else
  1520. return (long)prcmu_clock_rate(clock);
  1521. }
  1522. static void set_clock_rate(u8 clock, unsigned long rate)
  1523. {
  1524. u32 val;
  1525. u32 div;
  1526. unsigned long src_rate;
  1527. unsigned long flags;
  1528. spin_lock_irqsave(&clk_mgt_lock, flags);
  1529. /* Grab the HW semaphore. */
  1530. while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
  1531. cpu_relax();
  1532. val = readl(prcmu_base + clk_mgt[clock].offset);
  1533. src_rate = clock_source_rate((val | clk_mgt[clock].pllsw),
  1534. clk_mgt[clock].branch);
  1535. div = clock_divider(src_rate, rate);
  1536. if (val & PRCM_CLK_MGT_CLK38) {
  1537. if (clk_mgt[clock].clk38div) {
  1538. if (div > 1)
  1539. val |= PRCM_CLK_MGT_CLK38DIV;
  1540. else
  1541. val &= ~PRCM_CLK_MGT_CLK38DIV;
  1542. }
  1543. } else if (clock == PRCMU_SGACLK) {
  1544. val &= ~(PRCM_CLK_MGT_CLKPLLDIV_MASK |
  1545. PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN);
  1546. if (div == 3) {
  1547. u64 r = (src_rate * 10);
  1548. (void)do_div(r, 25);
  1549. if (r <= rate) {
  1550. val |= PRCM_SGACLK_MGT_SGACLKDIV_BY_2_5_EN;
  1551. div = 0;
  1552. }
  1553. }
  1554. val |= min(div, (u32)31);
  1555. } else {
  1556. val &= ~PRCM_CLK_MGT_CLKPLLDIV_MASK;
  1557. val |= min(div, (u32)31);
  1558. }
  1559. writel(val, prcmu_base + clk_mgt[clock].offset);
  1560. /* Release the HW semaphore. */
  1561. writel(0, PRCM_SEM);
  1562. spin_unlock_irqrestore(&clk_mgt_lock, flags);
  1563. }
  1564. static int set_armss_rate(unsigned long rate)
  1565. {
  1566. struct cpufreq_frequency_table *pos;
  1567. /* cpufreq table frequencies is in KHz. */
  1568. rate = rate / 1000;
  1569. /* Find the corresponding arm opp from the cpufreq table. */
  1570. cpufreq_for_each_entry(pos, db8500_cpufreq_table)
  1571. if (pos->frequency == rate)
  1572. break;
  1573. if (pos->frequency != rate)
  1574. return -EINVAL;
  1575. /* Set the new arm opp. */
  1576. return db8500_prcmu_set_arm_opp(pos->driver_data);
  1577. }
  1578. static int set_plldsi_rate(unsigned long rate)
  1579. {
  1580. unsigned long src_rate;
  1581. unsigned long rem;
  1582. u32 pll_freq = 0;
  1583. u32 r;
  1584. src_rate = clock_rate(PRCMU_HDMICLK);
  1585. rem = rate;
  1586. for (r = 7; (rem > 0) && (r > 0); r--) {
  1587. u64 d;
  1588. u64 hwrate;
  1589. d = (r * rate);
  1590. (void)do_div(d, src_rate);
  1591. if (d < 6)
  1592. d = 6;
  1593. else if (d > 255)
  1594. d = 255;
  1595. hwrate = (d * src_rate);
  1596. if (((2 * hwrate) < (r * MIN_PLL_VCO_RATE)) ||
  1597. ((r * MAX_PLL_VCO_RATE) < (2 * hwrate)))
  1598. continue;
  1599. (void)do_div(hwrate, r);
  1600. if (rate < hwrate) {
  1601. if (pll_freq == 0)
  1602. pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
  1603. (r << PRCM_PLL_FREQ_R_SHIFT));
  1604. break;
  1605. }
  1606. if ((rate - hwrate) < rem) {
  1607. rem = (rate - hwrate);
  1608. pll_freq = (((u32)d << PRCM_PLL_FREQ_D_SHIFT) |
  1609. (r << PRCM_PLL_FREQ_R_SHIFT));
  1610. }
  1611. }
  1612. if (pll_freq == 0)
  1613. return -EINVAL;
  1614. pll_freq |= (1 << PRCM_PLL_FREQ_N_SHIFT);
  1615. writel(pll_freq, PRCM_PLLDSI_FREQ);
  1616. return 0;
  1617. }
  1618. static void set_dsiclk_rate(u8 n, unsigned long rate)
  1619. {
  1620. u32 val;
  1621. u32 div;
  1622. div = clock_divider(pll_rate(PRCM_PLLDSI_FREQ,
  1623. clock_rate(PRCMU_HDMICLK), PLL_RAW), rate);
  1624. dsiclk[n].divsel = (div == 1) ? PRCM_DSI_PLLOUT_SEL_PHI :
  1625. (div == 2) ? PRCM_DSI_PLLOUT_SEL_PHI_2 :
  1626. /* else */ PRCM_DSI_PLLOUT_SEL_PHI_4;
  1627. val = readl(PRCM_DSI_PLLOUT_SEL);
  1628. val &= ~dsiclk[n].divsel_mask;
  1629. val |= (dsiclk[n].divsel << dsiclk[n].divsel_shift);
  1630. writel(val, PRCM_DSI_PLLOUT_SEL);
  1631. }
  1632. static void set_dsiescclk_rate(u8 n, unsigned long rate)
  1633. {
  1634. u32 val;
  1635. u32 div;
  1636. div = clock_divider(clock_rate(PRCMU_TVCLK), rate);
  1637. val = readl(PRCM_DSITVCLK_DIV);
  1638. val &= ~dsiescclk[n].div_mask;
  1639. val |= (min(div, (u32)255) << dsiescclk[n].div_shift);
  1640. writel(val, PRCM_DSITVCLK_DIV);
  1641. }
  1642. int prcmu_set_clock_rate(u8 clock, unsigned long rate)
  1643. {
  1644. if (clock < PRCMU_NUM_REG_CLOCKS)
  1645. set_clock_rate(clock, rate);
  1646. else if (clock == PRCMU_ARMSS)
  1647. return set_armss_rate(rate);
  1648. else if (clock == PRCMU_PLLDSI)
  1649. return set_plldsi_rate(rate);
  1650. else if ((clock == PRCMU_DSI0CLK) || (clock == PRCMU_DSI1CLK))
  1651. set_dsiclk_rate((clock - PRCMU_DSI0CLK), rate);
  1652. else if ((PRCMU_DSI0ESCCLK <= clock) && (clock <= PRCMU_DSI2ESCCLK))
  1653. set_dsiescclk_rate((clock - PRCMU_DSI0ESCCLK), rate);
  1654. return 0;
  1655. }
  1656. int db8500_prcmu_config_esram0_deep_sleep(u8 state)
  1657. {
  1658. if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
  1659. (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
  1660. return -EINVAL;
  1661. mutex_lock(&mb4_transfer.lock);
  1662. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1663. cpu_relax();
  1664. writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1665. writeb(((DDR_PWR_STATE_OFFHIGHLAT << 4) | DDR_PWR_STATE_ON),
  1666. (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE));
  1667. writeb(DDR_PWR_STATE_ON,
  1668. (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
  1669. writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
  1670. writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
  1671. wait_for_completion(&mb4_transfer.work);
  1672. mutex_unlock(&mb4_transfer.lock);
  1673. return 0;
  1674. }
  1675. int db8500_prcmu_config_hotdog(u8 threshold)
  1676. {
  1677. mutex_lock(&mb4_transfer.lock);
  1678. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1679. cpu_relax();
  1680. writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
  1681. writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1682. writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
  1683. wait_for_completion(&mb4_transfer.work);
  1684. mutex_unlock(&mb4_transfer.lock);
  1685. return 0;
  1686. }
  1687. int db8500_prcmu_config_hotmon(u8 low, u8 high)
  1688. {
  1689. mutex_lock(&mb4_transfer.lock);
  1690. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1691. cpu_relax();
  1692. writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
  1693. writeb(high, (tcdm_base + PRCM_REQ_MB4_HOTMON_HIGH));
  1694. writeb((HOTMON_CONFIG_LOW | HOTMON_CONFIG_HIGH),
  1695. (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
  1696. writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1697. writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
  1698. wait_for_completion(&mb4_transfer.work);
  1699. mutex_unlock(&mb4_transfer.lock);
  1700. return 0;
  1701. }
  1702. EXPORT_SYMBOL_GPL(db8500_prcmu_config_hotmon);
  1703. static int config_hot_period(u16 val)
  1704. {
  1705. mutex_lock(&mb4_transfer.lock);
  1706. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1707. cpu_relax();
  1708. writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
  1709. writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1710. writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
  1711. wait_for_completion(&mb4_transfer.work);
  1712. mutex_unlock(&mb4_transfer.lock);
  1713. return 0;
  1714. }
  1715. int db8500_prcmu_start_temp_sense(u16 cycles32k)
  1716. {
  1717. if (cycles32k == 0xFFFF)
  1718. return -EINVAL;
  1719. return config_hot_period(cycles32k);
  1720. }
  1721. EXPORT_SYMBOL_GPL(db8500_prcmu_start_temp_sense);
  1722. int db8500_prcmu_stop_temp_sense(void)
  1723. {
  1724. return config_hot_period(0xFFFF);
  1725. }
  1726. EXPORT_SYMBOL_GPL(db8500_prcmu_stop_temp_sense);
  1727. static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3)
  1728. {
  1729. mutex_lock(&mb4_transfer.lock);
  1730. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
  1731. cpu_relax();
  1732. writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0));
  1733. writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1));
  1734. writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2));
  1735. writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3));
  1736. writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
  1737. writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
  1738. wait_for_completion(&mb4_transfer.work);
  1739. mutex_unlock(&mb4_transfer.lock);
  1740. return 0;
  1741. }
  1742. int db8500_prcmu_config_a9wdog(u8 num, bool sleep_auto_off)
  1743. {
  1744. BUG_ON(num == 0 || num > 0xf);
  1745. return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0,
  1746. sleep_auto_off ? A9WDOG_AUTO_OFF_EN :
  1747. A9WDOG_AUTO_OFF_DIS);
  1748. }
  1749. EXPORT_SYMBOL(db8500_prcmu_config_a9wdog);
  1750. int db8500_prcmu_enable_a9wdog(u8 id)
  1751. {
  1752. return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0);
  1753. }
  1754. EXPORT_SYMBOL(db8500_prcmu_enable_a9wdog);
  1755. int db8500_prcmu_disable_a9wdog(u8 id)
  1756. {
  1757. return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0);
  1758. }
  1759. EXPORT_SYMBOL(db8500_prcmu_disable_a9wdog);
  1760. int db8500_prcmu_kick_a9wdog(u8 id)
  1761. {
  1762. return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0);
  1763. }
  1764. EXPORT_SYMBOL(db8500_prcmu_kick_a9wdog);
  1765. /*
  1766. * timeout is 28 bit, in ms.
  1767. */
  1768. int db8500_prcmu_load_a9wdog(u8 id, u32 timeout)
  1769. {
  1770. return prcmu_a9wdog(MB4H_A9WDOG_LOAD,
  1771. (id & A9WDOG_ID_MASK) |
  1772. /*
  1773. * Put the lowest 28 bits of timeout at
  1774. * offset 4. Four first bits are used for id.
  1775. */
  1776. (u8)((timeout << 4) & 0xf0),
  1777. (u8)((timeout >> 4) & 0xff),
  1778. (u8)((timeout >> 12) & 0xff),
  1779. (u8)((timeout >> 20) & 0xff));
  1780. }
  1781. EXPORT_SYMBOL(db8500_prcmu_load_a9wdog);
  1782. /**
  1783. * prcmu_abb_read() - Read register value(s) from the ABB.
  1784. * @slave: The I2C slave address.
  1785. * @reg: The (start) register address.
  1786. * @value: The read out value(s).
  1787. * @size: The number of registers to read.
  1788. *
  1789. * Reads register value(s) from the ABB.
  1790. * @size has to be 1 for the current firmware version.
  1791. */
  1792. int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
  1793. {
  1794. int r;
  1795. if (size != 1)
  1796. return -EINVAL;
  1797. mutex_lock(&mb5_transfer.lock);
  1798. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
  1799. cpu_relax();
  1800. writeb(0, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
  1801. writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
  1802. writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
  1803. writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
  1804. writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
  1805. writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
  1806. if (!wait_for_completion_timeout(&mb5_transfer.work,
  1807. msecs_to_jiffies(20000))) {
  1808. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1809. __func__);
  1810. r = -EIO;
  1811. } else {
  1812. r = ((mb5_transfer.ack.status == I2C_RD_OK) ? 0 : -EIO);
  1813. }
  1814. if (!r)
  1815. *value = mb5_transfer.ack.value;
  1816. mutex_unlock(&mb5_transfer.lock);
  1817. return r;
  1818. }
  1819. /**
  1820. * prcmu_abb_write_masked() - Write masked register value(s) to the ABB.
  1821. * @slave: The I2C slave address.
  1822. * @reg: The (start) register address.
  1823. * @value: The value(s) to write.
  1824. * @mask: The mask(s) to use.
  1825. * @size: The number of registers to write.
  1826. *
  1827. * Writes masked register value(s) to the ABB.
  1828. * For each @value, only the bits set to 1 in the corresponding @mask
  1829. * will be written. The other bits are not changed.
  1830. * @size has to be 1 for the current firmware version.
  1831. */
  1832. int prcmu_abb_write_masked(u8 slave, u8 reg, u8 *value, u8 *mask, u8 size)
  1833. {
  1834. int r;
  1835. if (size != 1)
  1836. return -EINVAL;
  1837. mutex_lock(&mb5_transfer.lock);
  1838. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
  1839. cpu_relax();
  1840. writeb(~*mask, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB5));
  1841. writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
  1842. writeb(PRCMU_I2C_STOP_EN, (tcdm_base + PRCM_REQ_MB5_I2C_HW_BITS));
  1843. writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
  1844. writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
  1845. writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
  1846. if (!wait_for_completion_timeout(&mb5_transfer.work,
  1847. msecs_to_jiffies(20000))) {
  1848. pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n",
  1849. __func__);
  1850. r = -EIO;
  1851. } else {
  1852. r = ((mb5_transfer.ack.status == I2C_WR_OK) ? 0 : -EIO);
  1853. }
  1854. mutex_unlock(&mb5_transfer.lock);
  1855. return r;
  1856. }
  1857. /**
  1858. * prcmu_abb_write() - Write register value(s) to the ABB.
  1859. * @slave: The I2C slave address.
  1860. * @reg: The (start) register address.
  1861. * @value: The value(s) to write.
  1862. * @size: The number of registers to write.
  1863. *
  1864. * Writes register value(s) to the ABB.
  1865. * @size has to be 1 for the current firmware version.
  1866. */
  1867. int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
  1868. {
  1869. u8 mask = ~0;
  1870. return prcmu_abb_write_masked(slave, reg, value, &mask, size);
  1871. }
  1872. /**
  1873. * prcmu_ac_wake_req - should be called whenever ARM wants to wakeup Modem
  1874. */
  1875. int prcmu_ac_wake_req(void)
  1876. {
  1877. u32 val;
  1878. int ret = 0;
  1879. mutex_lock(&mb0_transfer.ac_wake_lock);
  1880. val = readl(PRCM_HOSTACCESS_REQ);
  1881. if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
  1882. goto unlock_and_return;
  1883. atomic_set(&ac_wake_req_state, 1);
  1884. /*
  1885. * Force Modem Wake-up before hostaccess_req ping-pong.
  1886. * It prevents Modem to enter in Sleep while acking the hostaccess
  1887. * request. The 31us delay has been calculated by HWI.
  1888. */
  1889. val |= PRCM_HOSTACCESS_REQ_WAKE_REQ;
  1890. writel(val, PRCM_HOSTACCESS_REQ);
  1891. udelay(31);
  1892. val |= PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ;
  1893. writel(val, PRCM_HOSTACCESS_REQ);
  1894. if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
  1895. msecs_to_jiffies(5000))) {
  1896. pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
  1897. __func__);
  1898. ret = -EFAULT;
  1899. }
  1900. unlock_and_return:
  1901. mutex_unlock(&mb0_transfer.ac_wake_lock);
  1902. return ret;
  1903. }
  1904. /**
  1905. * prcmu_ac_sleep_req - called when ARM no longer needs to talk to modem
  1906. */
  1907. void prcmu_ac_sleep_req(void)
  1908. {
  1909. u32 val;
  1910. mutex_lock(&mb0_transfer.ac_wake_lock);
  1911. val = readl(PRCM_HOSTACCESS_REQ);
  1912. if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
  1913. goto unlock_and_return;
  1914. writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
  1915. PRCM_HOSTACCESS_REQ);
  1916. if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
  1917. msecs_to_jiffies(5000))) {
  1918. pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
  1919. __func__);
  1920. }
  1921. atomic_set(&ac_wake_req_state, 0);
  1922. unlock_and_return:
  1923. mutex_unlock(&mb0_transfer.ac_wake_lock);
  1924. }
  1925. bool db8500_prcmu_is_ac_wake_requested(void)
  1926. {
  1927. return (atomic_read(&ac_wake_req_state) != 0);
  1928. }
  1929. /**
  1930. * db8500_prcmu_system_reset - System reset
  1931. *
  1932. * Saves the reset reason code and then sets the APE_SOFTRST register which
  1933. * fires interrupt to fw
  1934. */
  1935. void db8500_prcmu_system_reset(u16 reset_code)
  1936. {
  1937. writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
  1938. writel(1, PRCM_APE_SOFTRST);
  1939. }
  1940. /**
  1941. * db8500_prcmu_get_reset_code - Retrieve SW reset reason code
  1942. *
  1943. * Retrieves the reset reason code stored by prcmu_system_reset() before
  1944. * last restart.
  1945. */
  1946. u16 db8500_prcmu_get_reset_code(void)
  1947. {
  1948. return readw(tcdm_base + PRCM_SW_RST_REASON);
  1949. }
  1950. /**
  1951. * db8500_prcmu_reset_modem - ask the PRCMU to reset modem
  1952. */
  1953. void db8500_prcmu_modem_reset(void)
  1954. {
  1955. mutex_lock(&mb1_transfer.lock);
  1956. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
  1957. cpu_relax();
  1958. writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
  1959. writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
  1960. wait_for_completion(&mb1_transfer.work);
  1961. /*
  1962. * No need to check return from PRCMU as modem should go in reset state
  1963. * This state is already managed by upper layer
  1964. */
  1965. mutex_unlock(&mb1_transfer.lock);
  1966. }
  1967. static void ack_dbb_wakeup(void)
  1968. {
  1969. unsigned long flags;
  1970. spin_lock_irqsave(&mb0_transfer.lock, flags);
  1971. while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
  1972. cpu_relax();
  1973. writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
  1974. writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
  1975. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  1976. }
  1977. static inline void print_unknown_header_warning(u8 n, u8 header)
  1978. {
  1979. pr_warning("prcmu: Unknown message header (%d) in mailbox %d.\n",
  1980. header, n);
  1981. }
  1982. static bool read_mailbox_0(void)
  1983. {
  1984. bool r;
  1985. u32 ev;
  1986. unsigned int n;
  1987. u8 header;
  1988. header = readb(tcdm_base + PRCM_MBOX_HEADER_ACK_MB0);
  1989. switch (header) {
  1990. case MB0H_WAKEUP_EXE:
  1991. case MB0H_WAKEUP_SLEEP:
  1992. if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
  1993. ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_1_8500);
  1994. else
  1995. ev = readl(tcdm_base + PRCM_ACK_MB0_WAKEUP_0_8500);
  1996. if (ev & (WAKEUP_BIT_AC_WAKE_ACK | WAKEUP_BIT_AC_SLEEP_ACK))
  1997. complete(&mb0_transfer.ac_wake_work);
  1998. if (ev & WAKEUP_BIT_SYSCLK_OK)
  1999. complete(&mb3_transfer.sysclk_work);
  2000. ev &= mb0_transfer.req.dbb_irqs;
  2001. for (n = 0; n < NUM_PRCMU_WAKEUPS; n++) {
  2002. if (ev & prcmu_irq_bit[n])
  2003. generic_handle_irq(irq_find_mapping(db8500_irq_domain, n));
  2004. }
  2005. r = true;
  2006. break;
  2007. default:
  2008. print_unknown_header_warning(0, header);
  2009. r = false;
  2010. break;
  2011. }
  2012. writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
  2013. return r;
  2014. }
  2015. static bool read_mailbox_1(void)
  2016. {
  2017. mb1_transfer.ack.header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB1);
  2018. mb1_transfer.ack.arm_opp = readb(tcdm_base +
  2019. PRCM_ACK_MB1_CURRENT_ARM_OPP);
  2020. mb1_transfer.ack.ape_opp = readb(tcdm_base +
  2021. PRCM_ACK_MB1_CURRENT_APE_OPP);
  2022. mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
  2023. PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
  2024. writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
  2025. complete(&mb1_transfer.work);
  2026. return false;
  2027. }
  2028. static bool read_mailbox_2(void)
  2029. {
  2030. mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
  2031. writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
  2032. complete(&mb2_transfer.work);
  2033. return false;
  2034. }
  2035. static bool read_mailbox_3(void)
  2036. {
  2037. writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
  2038. return false;
  2039. }
  2040. static bool read_mailbox_4(void)
  2041. {
  2042. u8 header;
  2043. bool do_complete = true;
  2044. header = readb(tcdm_base + PRCM_MBOX_HEADER_REQ_MB4);
  2045. switch (header) {
  2046. case MB4H_MEM_ST:
  2047. case MB4H_HOTDOG:
  2048. case MB4H_HOTMON:
  2049. case MB4H_HOT_PERIOD:
  2050. case MB4H_A9WDOG_CONF:
  2051. case MB4H_A9WDOG_EN:
  2052. case MB4H_A9WDOG_DIS:
  2053. case MB4H_A9WDOG_LOAD:
  2054. case MB4H_A9WDOG_KICK:
  2055. break;
  2056. default:
  2057. print_unknown_header_warning(4, header);
  2058. do_complete = false;
  2059. break;
  2060. }
  2061. writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
  2062. if (do_complete)
  2063. complete(&mb4_transfer.work);
  2064. return false;
  2065. }
  2066. static bool read_mailbox_5(void)
  2067. {
  2068. mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
  2069. mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
  2070. writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
  2071. complete(&mb5_transfer.work);
  2072. return false;
  2073. }
  2074. static bool read_mailbox_6(void)
  2075. {
  2076. writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
  2077. return false;
  2078. }
  2079. static bool read_mailbox_7(void)
  2080. {
  2081. writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
  2082. return false;
  2083. }
  2084. static bool (* const read_mailbox[NUM_MB])(void) = {
  2085. read_mailbox_0,
  2086. read_mailbox_1,
  2087. read_mailbox_2,
  2088. read_mailbox_3,
  2089. read_mailbox_4,
  2090. read_mailbox_5,
  2091. read_mailbox_6,
  2092. read_mailbox_7
  2093. };
  2094. static irqreturn_t prcmu_irq_handler(int irq, void *data)
  2095. {
  2096. u32 bits;
  2097. u8 n;
  2098. irqreturn_t r;
  2099. bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
  2100. if (unlikely(!bits))
  2101. return IRQ_NONE;
  2102. r = IRQ_HANDLED;
  2103. for (n = 0; bits; n++) {
  2104. if (bits & MBOX_BIT(n)) {
  2105. bits -= MBOX_BIT(n);
  2106. if (read_mailbox[n]())
  2107. r = IRQ_WAKE_THREAD;
  2108. }
  2109. }
  2110. return r;
  2111. }
  2112. static irqreturn_t prcmu_irq_thread_fn(int irq, void *data)
  2113. {
  2114. ack_dbb_wakeup();
  2115. return IRQ_HANDLED;
  2116. }
  2117. static void prcmu_mask_work(struct work_struct *work)
  2118. {
  2119. unsigned long flags;
  2120. spin_lock_irqsave(&mb0_transfer.lock, flags);
  2121. config_wakeups();
  2122. spin_unlock_irqrestore(&mb0_transfer.lock, flags);
  2123. }
  2124. static void prcmu_irq_mask(struct irq_data *d)
  2125. {
  2126. unsigned long flags;
  2127. spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
  2128. mb0_transfer.req.dbb_irqs &= ~prcmu_irq_bit[d->hwirq];
  2129. spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
  2130. if (d->irq != IRQ_PRCMU_CA_SLEEP)
  2131. schedule_work(&mb0_transfer.mask_work);
  2132. }
  2133. static void prcmu_irq_unmask(struct irq_data *d)
  2134. {
  2135. unsigned long flags;
  2136. spin_lock_irqsave(&mb0_transfer.dbb_irqs_lock, flags);
  2137. mb0_transfer.req.dbb_irqs |= prcmu_irq_bit[d->hwirq];
  2138. spin_unlock_irqrestore(&mb0_transfer.dbb_irqs_lock, flags);
  2139. if (d->irq != IRQ_PRCMU_CA_SLEEP)
  2140. schedule_work(&mb0_transfer.mask_work);
  2141. }
  2142. static void noop(struct irq_data *d)
  2143. {
  2144. }
  2145. static struct irq_chip prcmu_irq_chip = {
  2146. .name = "prcmu",
  2147. .irq_disable = prcmu_irq_mask,
  2148. .irq_ack = noop,
  2149. .irq_mask = prcmu_irq_mask,
  2150. .irq_unmask = prcmu_irq_unmask,
  2151. };
  2152. static __init char *fw_project_name(u32 project)
  2153. {
  2154. switch (project) {
  2155. case PRCMU_FW_PROJECT_U8500:
  2156. return "U8500";
  2157. case PRCMU_FW_PROJECT_U8400:
  2158. return "U8400";
  2159. case PRCMU_FW_PROJECT_U9500:
  2160. return "U9500";
  2161. case PRCMU_FW_PROJECT_U8500_MBB:
  2162. return "U8500 MBB";
  2163. case PRCMU_FW_PROJECT_U8500_C1:
  2164. return "U8500 C1";
  2165. case PRCMU_FW_PROJECT_U8500_C2:
  2166. return "U8500 C2";
  2167. case PRCMU_FW_PROJECT_U8500_C3:
  2168. return "U8500 C3";
  2169. case PRCMU_FW_PROJECT_U8500_C4:
  2170. return "U8500 C4";
  2171. case PRCMU_FW_PROJECT_U9500_MBL:
  2172. return "U9500 MBL";
  2173. case PRCMU_FW_PROJECT_U8500_MBL:
  2174. return "U8500 MBL";
  2175. case PRCMU_FW_PROJECT_U8500_MBL2:
  2176. return "U8500 MBL2";
  2177. case PRCMU_FW_PROJECT_U8520:
  2178. return "U8520 MBL";
  2179. case PRCMU_FW_PROJECT_U8420:
  2180. return "U8420";
  2181. case PRCMU_FW_PROJECT_U9540:
  2182. return "U9540";
  2183. case PRCMU_FW_PROJECT_A9420:
  2184. return "A9420";
  2185. case PRCMU_FW_PROJECT_L8540:
  2186. return "L8540";
  2187. case PRCMU_FW_PROJECT_L8580:
  2188. return "L8580";
  2189. default:
  2190. return "Unknown";
  2191. }
  2192. }
  2193. static int db8500_irq_map(struct irq_domain *d, unsigned int virq,
  2194. irq_hw_number_t hwirq)
  2195. {
  2196. irq_set_chip_and_handler(virq, &prcmu_irq_chip,
  2197. handle_simple_irq);
  2198. return 0;
  2199. }
  2200. static const struct irq_domain_ops db8500_irq_ops = {
  2201. .map = db8500_irq_map,
  2202. .xlate = irq_domain_xlate_twocell,
  2203. };
  2204. static int db8500_irq_init(struct device_node *np)
  2205. {
  2206. int i;
  2207. db8500_irq_domain = irq_domain_add_simple(
  2208. np, NUM_PRCMU_WAKEUPS, 0,
  2209. &db8500_irq_ops, NULL);
  2210. if (!db8500_irq_domain) {
  2211. pr_err("Failed to create irqdomain\n");
  2212. return -ENOSYS;
  2213. }
  2214. /* All wakeups will be used, so create mappings for all */
  2215. for (i = 0; i < NUM_PRCMU_WAKEUPS; i++)
  2216. irq_create_mapping(db8500_irq_domain, i);
  2217. return 0;
  2218. }
  2219. static void dbx500_fw_version_init(struct platform_device *pdev,
  2220. u32 version_offset)
  2221. {
  2222. struct resource *res;
  2223. void __iomem *tcpm_base;
  2224. u32 version;
  2225. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  2226. "prcmu-tcpm");
  2227. if (!res) {
  2228. dev_err(&pdev->dev,
  2229. "Error: no prcmu tcpm memory region provided\n");
  2230. return;
  2231. }
  2232. tcpm_base = ioremap(res->start, resource_size(res));
  2233. if (!tcpm_base) {
  2234. dev_err(&pdev->dev, "no prcmu tcpm mem region provided\n");
  2235. return;
  2236. }
  2237. version = readl(tcpm_base + version_offset);
  2238. fw_info.version.project = (version & 0xFF);
  2239. fw_info.version.api_version = (version >> 8) & 0xFF;
  2240. fw_info.version.func_version = (version >> 16) & 0xFF;
  2241. fw_info.version.errata = (version >> 24) & 0xFF;
  2242. strncpy(fw_info.version.project_name,
  2243. fw_project_name(fw_info.version.project),
  2244. PRCMU_FW_PROJECT_NAME_LEN);
  2245. fw_info.valid = true;
  2246. pr_info("PRCMU firmware: %s(%d), version %d.%d.%d\n",
  2247. fw_info.version.project_name,
  2248. fw_info.version.project,
  2249. fw_info.version.api_version,
  2250. fw_info.version.func_version,
  2251. fw_info.version.errata);
  2252. iounmap(tcpm_base);
  2253. }
  2254. void __init db8500_prcmu_early_init(u32 phy_base, u32 size)
  2255. {
  2256. /*
  2257. * This is a temporary remap to bring up the clocks. It is
  2258. * subsequently replaces with a real remap. After the merge of
  2259. * the mailbox subsystem all of this early code goes away, and the
  2260. * clock driver can probe independently. An early initcall will
  2261. * still be needed, but it can be diverted into drivers/clk/ux500.
  2262. */
  2263. prcmu_base = ioremap(phy_base, size);
  2264. if (!prcmu_base)
  2265. pr_err("%s: ioremap() of prcmu registers failed!\n", __func__);
  2266. spin_lock_init(&mb0_transfer.lock);
  2267. spin_lock_init(&mb0_transfer.dbb_irqs_lock);
  2268. mutex_init(&mb0_transfer.ac_wake_lock);
  2269. init_completion(&mb0_transfer.ac_wake_work);
  2270. mutex_init(&mb1_transfer.lock);
  2271. init_completion(&mb1_transfer.work);
  2272. mb1_transfer.ape_opp = APE_NO_CHANGE;
  2273. mutex_init(&mb2_transfer.lock);
  2274. init_completion(&mb2_transfer.work);
  2275. spin_lock_init(&mb2_transfer.auto_pm_lock);
  2276. spin_lock_init(&mb3_transfer.lock);
  2277. mutex_init(&mb3_transfer.sysclk_lock);
  2278. init_completion(&mb3_transfer.sysclk_work);
  2279. mutex_init(&mb4_transfer.lock);
  2280. init_completion(&mb4_transfer.work);
  2281. mutex_init(&mb5_transfer.lock);
  2282. init_completion(&mb5_transfer.work);
  2283. INIT_WORK(&mb0_transfer.mask_work, prcmu_mask_work);
  2284. }
  2285. static void __init init_prcm_registers(void)
  2286. {
  2287. u32 val;
  2288. val = readl(PRCM_A9PL_FORCE_CLKEN);
  2289. val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN |
  2290. PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN);
  2291. writel(val, (PRCM_A9PL_FORCE_CLKEN));
  2292. }
  2293. /*
  2294. * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
  2295. */
  2296. static struct regulator_consumer_supply db8500_vape_consumers[] = {
  2297. REGULATOR_SUPPLY("v-ape", NULL),
  2298. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.0"),
  2299. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.1"),
  2300. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.2"),
  2301. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.3"),
  2302. REGULATOR_SUPPLY("v-i2c", "nmk-i2c.4"),
  2303. /* "v-mmc" changed to "vcore" in the mainline kernel */
  2304. REGULATOR_SUPPLY("vcore", "sdi0"),
  2305. REGULATOR_SUPPLY("vcore", "sdi1"),
  2306. REGULATOR_SUPPLY("vcore", "sdi2"),
  2307. REGULATOR_SUPPLY("vcore", "sdi3"),
  2308. REGULATOR_SUPPLY("vcore", "sdi4"),
  2309. REGULATOR_SUPPLY("v-dma", "dma40.0"),
  2310. REGULATOR_SUPPLY("v-ape", "ab8500-usb.0"),
  2311. /* "v-uart" changed to "vcore" in the mainline kernel */
  2312. REGULATOR_SUPPLY("vcore", "uart0"),
  2313. REGULATOR_SUPPLY("vcore", "uart1"),
  2314. REGULATOR_SUPPLY("vcore", "uart2"),
  2315. REGULATOR_SUPPLY("v-ape", "nmk-ske-keypad.0"),
  2316. REGULATOR_SUPPLY("v-hsi", "ste_hsi.0"),
  2317. REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
  2318. };
  2319. static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
  2320. REGULATOR_SUPPLY("musb_1v8", "ab8500-usb.0"),
  2321. /* AV8100 regulator */
  2322. REGULATOR_SUPPLY("hdmi_1v8", "0-0070"),
  2323. };
  2324. static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
  2325. REGULATOR_SUPPLY("vsupply", "b2r2_bus"),
  2326. REGULATOR_SUPPLY("vsupply", "mcde"),
  2327. };
  2328. /* SVA MMDSP regulator switch */
  2329. static struct regulator_consumer_supply db8500_svammdsp_consumers[] = {
  2330. REGULATOR_SUPPLY("sva-mmdsp", "cm_control"),
  2331. };
  2332. /* SVA pipe regulator switch */
  2333. static struct regulator_consumer_supply db8500_svapipe_consumers[] = {
  2334. REGULATOR_SUPPLY("sva-pipe", "cm_control"),
  2335. };
  2336. /* SIA MMDSP regulator switch */
  2337. static struct regulator_consumer_supply db8500_siammdsp_consumers[] = {
  2338. REGULATOR_SUPPLY("sia-mmdsp", "cm_control"),
  2339. };
  2340. /* SIA pipe regulator switch */
  2341. static struct regulator_consumer_supply db8500_siapipe_consumers[] = {
  2342. REGULATOR_SUPPLY("sia-pipe", "cm_control"),
  2343. };
  2344. static struct regulator_consumer_supply db8500_sga_consumers[] = {
  2345. REGULATOR_SUPPLY("v-mali", NULL),
  2346. };
  2347. /* ESRAM1 and 2 regulator switch */
  2348. static struct regulator_consumer_supply db8500_esram12_consumers[] = {
  2349. REGULATOR_SUPPLY("esram12", "cm_control"),
  2350. };
  2351. /* ESRAM3 and 4 regulator switch */
  2352. static struct regulator_consumer_supply db8500_esram34_consumers[] = {
  2353. REGULATOR_SUPPLY("v-esram34", "mcde"),
  2354. REGULATOR_SUPPLY("esram34", "cm_control"),
  2355. REGULATOR_SUPPLY("lcla_esram", "dma40.0"),
  2356. };
  2357. static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
  2358. [DB8500_REGULATOR_VAPE] = {
  2359. .constraints = {
  2360. .name = "db8500-vape",
  2361. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2362. .always_on = true,
  2363. },
  2364. .consumer_supplies = db8500_vape_consumers,
  2365. .num_consumer_supplies = ARRAY_SIZE(db8500_vape_consumers),
  2366. },
  2367. [DB8500_REGULATOR_VARM] = {
  2368. .constraints = {
  2369. .name = "db8500-varm",
  2370. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2371. },
  2372. },
  2373. [DB8500_REGULATOR_VMODEM] = {
  2374. .constraints = {
  2375. .name = "db8500-vmodem",
  2376. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2377. },
  2378. },
  2379. [DB8500_REGULATOR_VPLL] = {
  2380. .constraints = {
  2381. .name = "db8500-vpll",
  2382. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2383. },
  2384. },
  2385. [DB8500_REGULATOR_VSMPS1] = {
  2386. .constraints = {
  2387. .name = "db8500-vsmps1",
  2388. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2389. },
  2390. },
  2391. [DB8500_REGULATOR_VSMPS2] = {
  2392. .constraints = {
  2393. .name = "db8500-vsmps2",
  2394. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2395. },
  2396. .consumer_supplies = db8500_vsmps2_consumers,
  2397. .num_consumer_supplies = ARRAY_SIZE(db8500_vsmps2_consumers),
  2398. },
  2399. [DB8500_REGULATOR_VSMPS3] = {
  2400. .constraints = {
  2401. .name = "db8500-vsmps3",
  2402. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2403. },
  2404. },
  2405. [DB8500_REGULATOR_VRF1] = {
  2406. .constraints = {
  2407. .name = "db8500-vrf1",
  2408. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2409. },
  2410. },
  2411. [DB8500_REGULATOR_SWITCH_SVAMMDSP] = {
  2412. /* dependency to u8500-vape is handled outside regulator framework */
  2413. .constraints = {
  2414. .name = "db8500-sva-mmdsp",
  2415. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2416. },
  2417. .consumer_supplies = db8500_svammdsp_consumers,
  2418. .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers),
  2419. },
  2420. [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
  2421. .constraints = {
  2422. /* "ret" means "retention" */
  2423. .name = "db8500-sva-mmdsp-ret",
  2424. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2425. },
  2426. },
  2427. [DB8500_REGULATOR_SWITCH_SVAPIPE] = {
  2428. /* dependency to u8500-vape is handled outside regulator framework */
  2429. .constraints = {
  2430. .name = "db8500-sva-pipe",
  2431. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2432. },
  2433. .consumer_supplies = db8500_svapipe_consumers,
  2434. .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers),
  2435. },
  2436. [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
  2437. /* dependency to u8500-vape is handled outside regulator framework */
  2438. .constraints = {
  2439. .name = "db8500-sia-mmdsp",
  2440. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2441. },
  2442. .consumer_supplies = db8500_siammdsp_consumers,
  2443. .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers),
  2444. },
  2445. [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
  2446. .constraints = {
  2447. .name = "db8500-sia-mmdsp-ret",
  2448. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2449. },
  2450. },
  2451. [DB8500_REGULATOR_SWITCH_SIAPIPE] = {
  2452. /* dependency to u8500-vape is handled outside regulator framework */
  2453. .constraints = {
  2454. .name = "db8500-sia-pipe",
  2455. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2456. },
  2457. .consumer_supplies = db8500_siapipe_consumers,
  2458. .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers),
  2459. },
  2460. [DB8500_REGULATOR_SWITCH_SGA] = {
  2461. .supply_regulator = "db8500-vape",
  2462. .constraints = {
  2463. .name = "db8500-sga",
  2464. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2465. },
  2466. .consumer_supplies = db8500_sga_consumers,
  2467. .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers),
  2468. },
  2469. [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
  2470. .supply_regulator = "db8500-vape",
  2471. .constraints = {
  2472. .name = "db8500-b2r2-mcde",
  2473. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2474. },
  2475. .consumer_supplies = db8500_b2r2_mcde_consumers,
  2476. .num_consumer_supplies = ARRAY_SIZE(db8500_b2r2_mcde_consumers),
  2477. },
  2478. [DB8500_REGULATOR_SWITCH_ESRAM12] = {
  2479. /*
  2480. * esram12 is set in retention and supplied by Vsafe when Vape is off,
  2481. * no need to hold Vape
  2482. */
  2483. .constraints = {
  2484. .name = "db8500-esram12",
  2485. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2486. },
  2487. .consumer_supplies = db8500_esram12_consumers,
  2488. .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers),
  2489. },
  2490. [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
  2491. .constraints = {
  2492. .name = "db8500-esram12-ret",
  2493. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2494. },
  2495. },
  2496. [DB8500_REGULATOR_SWITCH_ESRAM34] = {
  2497. /*
  2498. * esram34 is set in retention and supplied by Vsafe when Vape is off,
  2499. * no need to hold Vape
  2500. */
  2501. .constraints = {
  2502. .name = "db8500-esram34",
  2503. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2504. },
  2505. .consumer_supplies = db8500_esram34_consumers,
  2506. .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers),
  2507. },
  2508. [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
  2509. .constraints = {
  2510. .name = "db8500-esram34-ret",
  2511. .valid_ops_mask = REGULATOR_CHANGE_STATUS,
  2512. },
  2513. },
  2514. };
  2515. static struct ux500_wdt_data db8500_wdt_pdata = {
  2516. .timeout = 600, /* 10 minutes */
  2517. .has_28_bits_resolution = true,
  2518. };
  2519. /*
  2520. * Thermal Sensor
  2521. */
  2522. static struct resource db8500_thsens_resources[] = {
  2523. {
  2524. .name = "IRQ_HOTMON_LOW",
  2525. .start = IRQ_PRCMU_HOTMON_LOW,
  2526. .end = IRQ_PRCMU_HOTMON_LOW,
  2527. .flags = IORESOURCE_IRQ,
  2528. },
  2529. {
  2530. .name = "IRQ_HOTMON_HIGH",
  2531. .start = IRQ_PRCMU_HOTMON_HIGH,
  2532. .end = IRQ_PRCMU_HOTMON_HIGH,
  2533. .flags = IORESOURCE_IRQ,
  2534. },
  2535. };
  2536. static struct db8500_thsens_platform_data db8500_thsens_data = {
  2537. .trip_points[0] = {
  2538. .temp = 70000,
  2539. .type = THERMAL_TRIP_ACTIVE,
  2540. .cdev_name = {
  2541. [0] = "thermal-cpufreq-0",
  2542. },
  2543. },
  2544. .trip_points[1] = {
  2545. .temp = 75000,
  2546. .type = THERMAL_TRIP_ACTIVE,
  2547. .cdev_name = {
  2548. [0] = "thermal-cpufreq-0",
  2549. },
  2550. },
  2551. .trip_points[2] = {
  2552. .temp = 80000,
  2553. .type = THERMAL_TRIP_ACTIVE,
  2554. .cdev_name = {
  2555. [0] = "thermal-cpufreq-0",
  2556. },
  2557. },
  2558. .trip_points[3] = {
  2559. .temp = 85000,
  2560. .type = THERMAL_TRIP_CRITICAL,
  2561. },
  2562. .num_trips = 4,
  2563. };
  2564. static const struct mfd_cell common_prcmu_devs[] = {
  2565. {
  2566. .name = "ux500_wdt",
  2567. .platform_data = &db8500_wdt_pdata,
  2568. .pdata_size = sizeof(db8500_wdt_pdata),
  2569. .id = -1,
  2570. },
  2571. };
  2572. static const struct mfd_cell db8500_prcmu_devs[] = {
  2573. {
  2574. .name = "db8500-prcmu-regulators",
  2575. .of_compatible = "stericsson,db8500-prcmu-regulator",
  2576. .platform_data = &db8500_regulators,
  2577. .pdata_size = sizeof(db8500_regulators),
  2578. },
  2579. {
  2580. .name = "cpufreq-ux500",
  2581. .of_compatible = "stericsson,cpufreq-ux500",
  2582. .platform_data = &db8500_cpufreq_table,
  2583. .pdata_size = sizeof(db8500_cpufreq_table),
  2584. },
  2585. {
  2586. .name = "cpuidle-dbx500",
  2587. .of_compatible = "stericsson,cpuidle-dbx500",
  2588. },
  2589. {
  2590. .name = "db8500-thermal",
  2591. .num_resources = ARRAY_SIZE(db8500_thsens_resources),
  2592. .resources = db8500_thsens_resources,
  2593. .platform_data = &db8500_thsens_data,
  2594. .pdata_size = sizeof(db8500_thsens_data),
  2595. },
  2596. };
  2597. static void db8500_prcmu_update_cpufreq(void)
  2598. {
  2599. if (prcmu_has_arm_maxopp()) {
  2600. db8500_cpufreq_table[3].frequency = 1000000;
  2601. db8500_cpufreq_table[3].driver_data = ARM_MAX_OPP;
  2602. }
  2603. }
  2604. static int db8500_prcmu_register_ab8500(struct device *parent)
  2605. {
  2606. struct device_node *np;
  2607. struct resource ab8500_resource;
  2608. const struct mfd_cell ab8500_cell = {
  2609. .name = "ab8500-core",
  2610. .of_compatible = "stericsson,ab8500",
  2611. .id = AB8500_VERSION_AB8500,
  2612. .resources = &ab8500_resource,
  2613. .num_resources = 1,
  2614. };
  2615. if (!parent->of_node)
  2616. return -ENODEV;
  2617. /* Look up the device node, sneak the IRQ out of it */
  2618. for_each_child_of_node(parent->of_node, np) {
  2619. if (of_device_is_compatible(np, ab8500_cell.of_compatible))
  2620. break;
  2621. }
  2622. if (!np) {
  2623. dev_info(parent, "could not find AB8500 node in the device tree\n");
  2624. return -ENODEV;
  2625. }
  2626. of_irq_to_resource_table(np, &ab8500_resource, 1);
  2627. return mfd_add_devices(parent, 0, &ab8500_cell, 1, NULL, 0, NULL);
  2628. }
  2629. /**
  2630. * prcmu_fw_init - arch init call for the Linux PRCMU fw init logic
  2631. *
  2632. */
  2633. static int db8500_prcmu_probe(struct platform_device *pdev)
  2634. {
  2635. struct device_node *np = pdev->dev.of_node;
  2636. int irq = 0, err = 0;
  2637. struct resource *res;
  2638. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu");
  2639. if (!res) {
  2640. dev_err(&pdev->dev, "no prcmu memory region provided\n");
  2641. return -EINVAL;
  2642. }
  2643. prcmu_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
  2644. if (!prcmu_base) {
  2645. dev_err(&pdev->dev,
  2646. "failed to ioremap prcmu register memory\n");
  2647. return -ENOMEM;
  2648. }
  2649. init_prcm_registers();
  2650. dbx500_fw_version_init(pdev, DB8500_PRCMU_FW_VERSION_OFFSET);
  2651. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu-tcdm");
  2652. if (!res) {
  2653. dev_err(&pdev->dev, "no prcmu tcdm region provided\n");
  2654. return -EINVAL;
  2655. }
  2656. tcdm_base = devm_ioremap(&pdev->dev, res->start,
  2657. resource_size(res));
  2658. if (!tcdm_base) {
  2659. dev_err(&pdev->dev,
  2660. "failed to ioremap prcmu-tcdm register memory\n");
  2661. return -ENOMEM;
  2662. }
  2663. /* Clean up the mailbox interrupts after pre-kernel code. */
  2664. writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
  2665. irq = platform_get_irq(pdev, 0);
  2666. if (irq <= 0) {
  2667. dev_err(&pdev->dev, "no prcmu irq provided\n");
  2668. return irq;
  2669. }
  2670. err = request_threaded_irq(irq, prcmu_irq_handler,
  2671. prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
  2672. if (err < 0) {
  2673. pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
  2674. return err;
  2675. }
  2676. db8500_irq_init(np);
  2677. prcmu_config_esram0_deep_sleep(ESRAM0_DEEP_SLEEP_STATE_RET);
  2678. db8500_prcmu_update_cpufreq();
  2679. err = mfd_add_devices(&pdev->dev, 0, common_prcmu_devs,
  2680. ARRAY_SIZE(common_prcmu_devs), NULL, 0, db8500_irq_domain);
  2681. if (err) {
  2682. pr_err("prcmu: Failed to add subdevices\n");
  2683. return err;
  2684. }
  2685. /* TODO: Remove restriction when clk definitions are available. */
  2686. if (!of_machine_is_compatible("st-ericsson,u8540")) {
  2687. err = mfd_add_devices(&pdev->dev, 0, db8500_prcmu_devs,
  2688. ARRAY_SIZE(db8500_prcmu_devs), NULL, 0,
  2689. db8500_irq_domain);
  2690. if (err) {
  2691. mfd_remove_devices(&pdev->dev);
  2692. pr_err("prcmu: Failed to add subdevices\n");
  2693. return err;
  2694. }
  2695. }
  2696. err = db8500_prcmu_register_ab8500(&pdev->dev);
  2697. if (err) {
  2698. mfd_remove_devices(&pdev->dev);
  2699. pr_err("prcmu: Failed to add ab8500 subdevice\n");
  2700. return err;
  2701. }
  2702. pr_info("DB8500 PRCMU initialized\n");
  2703. return err;
  2704. }
  2705. static const struct of_device_id db8500_prcmu_match[] = {
  2706. { .compatible = "stericsson,db8500-prcmu"},
  2707. { },
  2708. };
  2709. static struct platform_driver db8500_prcmu_driver = {
  2710. .driver = {
  2711. .name = "db8500-prcmu",
  2712. .of_match_table = db8500_prcmu_match,
  2713. },
  2714. .probe = db8500_prcmu_probe,
  2715. };
  2716. static int __init db8500_prcmu_init(void)
  2717. {
  2718. return platform_driver_register(&db8500_prcmu_driver);
  2719. }
  2720. core_initcall(db8500_prcmu_init);
  2721. MODULE_AUTHOR("Mattias Nilsson <mattias.i.nilsson@stericsson.com>");
  2722. MODULE_DESCRIPTION("DB8500 PRCM Unit driver");
  2723. MODULE_LICENSE("GPL v2");