rpmhpd.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2018, The Linux Foundation. All rights reserved.*/
  3. #include <linux/cleanup.h>
  4. #include <linux/err.h>
  5. #include <linux/init.h>
  6. #include <linux/kernel.h>
  7. #include <linux/module.h>
  8. #include <linux/mutex.h>
  9. #include <linux/pm_domain.h>
  10. #include <linux/slab.h>
  11. #include <linux/of.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/pm_opp.h>
  14. #include <soc/qcom/cmd-db.h>
  15. #include <soc/qcom/rpmh.h>
  16. #include <dt-bindings/power/qcom-rpmpd.h>
  17. #include <dt-bindings/power/qcom,rpmhpd.h>
  18. #define domain_to_rpmhpd(domain) container_of(domain, struct rpmhpd, pd)
  19. #define RPMH_ARC_MAX_LEVELS 32
  20. /**
  21. * struct rpmhpd - top level RPMh power domain resource data structure
  22. * @dev: rpmh power domain controller device
  23. * @pd: generic_pm_domain corresponding to the power domain
  24. * @parent: generic_pm_domain corresponding to the parent's power domain
  25. * @peer: A peer power domain in case Active only Voting is
  26. * supported
  27. * @active_only: True if it represents an Active only peer
  28. * @corner: current corner
  29. * @active_corner: current active corner
  30. * @enable_corner: lowest non-zero corner
  31. * @level: An array of level (vlvl) to corner (hlvl) mappings
  32. * derived from cmd-db
  33. * @level_count: Number of levels supported by the power domain. max
  34. * being 16 (0 - 15)
  35. * @enabled: true if the power domain is enabled
  36. * @res_name: Resource name used for cmd-db lookup
  37. * @addr: Resource address as looped up using resource name from
  38. * cmd-db
  39. * @state_synced: Indicator that sync_state has been invoked for the rpmhpd resource
  40. * @skip_retention_level: Indicate that retention level should not be used for the power domain
  41. */
  42. struct rpmhpd {
  43. struct device *dev;
  44. struct generic_pm_domain pd;
  45. struct generic_pm_domain *parent;
  46. struct rpmhpd *peer;
  47. const bool active_only;
  48. unsigned int corner;
  49. unsigned int active_corner;
  50. unsigned int enable_corner;
  51. u32 level[RPMH_ARC_MAX_LEVELS];
  52. size_t level_count;
  53. bool enabled;
  54. const char *res_name;
  55. u32 addr;
  56. bool state_synced;
  57. bool skip_retention_level;
  58. };
  59. struct rpmhpd_desc {
  60. struct rpmhpd **rpmhpds;
  61. size_t num_pds;
  62. };
  63. static DEFINE_MUTEX(rpmhpd_lock);
  64. /* RPMH powerdomains */
  65. static struct rpmhpd cx_ao;
  66. static struct rpmhpd mx;
  67. static struct rpmhpd mx_ao;
  68. static struct rpmhpd cx = {
  69. .pd = { .name = "cx", },
  70. .peer = &cx_ao,
  71. .res_name = "cx.lvl",
  72. };
  73. static struct rpmhpd cx_ao = {
  74. .pd = { .name = "cx_ao", },
  75. .active_only = true,
  76. .peer = &cx,
  77. .res_name = "cx.lvl",
  78. };
  79. static struct rpmhpd cx_ao_w_mx_parent;
  80. static struct rpmhpd cx_w_mx_parent = {
  81. .pd = { .name = "cx", },
  82. .peer = &cx_ao_w_mx_parent,
  83. .parent = &mx.pd,
  84. .res_name = "cx.lvl",
  85. };
  86. static struct rpmhpd cx_ao_w_mx_parent = {
  87. .pd = { .name = "cx_ao", },
  88. .active_only = true,
  89. .peer = &cx_w_mx_parent,
  90. .parent = &mx_ao.pd,
  91. .res_name = "cx.lvl",
  92. };
  93. static struct rpmhpd ebi = {
  94. .pd = { .name = "ebi", },
  95. .res_name = "ebi.lvl",
  96. };
  97. static struct rpmhpd gfx = {
  98. .pd = { .name = "gfx", },
  99. .res_name = "gfx.lvl",
  100. };
  101. static struct rpmhpd lcx = {
  102. .pd = { .name = "lcx", },
  103. .res_name = "lcx.lvl",
  104. };
  105. static struct rpmhpd lmx = {
  106. .pd = { .name = "lmx", },
  107. .res_name = "lmx.lvl",
  108. };
  109. static struct rpmhpd mmcx_ao;
  110. static struct rpmhpd mmcx = {
  111. .pd = { .name = "mmcx", },
  112. .peer = &mmcx_ao,
  113. .res_name = "mmcx.lvl",
  114. };
  115. static struct rpmhpd mmcx_ao = {
  116. .pd = { .name = "mmcx_ao", },
  117. .active_only = true,
  118. .peer = &mmcx,
  119. .res_name = "mmcx.lvl",
  120. };
  121. static struct rpmhpd mmcx_ao_w_cx_parent;
  122. static struct rpmhpd mmcx_w_cx_parent = {
  123. .pd = { .name = "mmcx", },
  124. .peer = &mmcx_ao_w_cx_parent,
  125. .parent = &cx.pd,
  126. .res_name = "mmcx.lvl",
  127. };
  128. static struct rpmhpd mmcx_ao_w_cx_parent = {
  129. .pd = { .name = "mmcx_ao", },
  130. .active_only = true,
  131. .peer = &mmcx_w_cx_parent,
  132. .parent = &cx_ao.pd,
  133. .res_name = "mmcx.lvl",
  134. };
  135. static struct rpmhpd mss = {
  136. .pd = { .name = "mss", },
  137. .res_name = "mss.lvl",
  138. };
  139. static struct rpmhpd mx_ao;
  140. static struct rpmhpd mx = {
  141. .pd = { .name = "mx", },
  142. .peer = &mx_ao,
  143. .res_name = "mx.lvl",
  144. };
  145. static struct rpmhpd mx_ao = {
  146. .pd = { .name = "mx_ao", },
  147. .active_only = true,
  148. .peer = &mx,
  149. .res_name = "mx.lvl",
  150. };
  151. static struct rpmhpd mxc_ao;
  152. static struct rpmhpd mxc = {
  153. .pd = { .name = "mxc", },
  154. .peer = &mxc_ao,
  155. .res_name = "mxc.lvl",
  156. .skip_retention_level = true,
  157. };
  158. static struct rpmhpd mxc_ao = {
  159. .pd = { .name = "mxc_ao", },
  160. .active_only = true,
  161. .peer = &mxc,
  162. .res_name = "mxc.lvl",
  163. .skip_retention_level = true,
  164. };
  165. static struct rpmhpd nsp = {
  166. .pd = { .name = "nsp", },
  167. .res_name = "nsp.lvl",
  168. };
  169. static struct rpmhpd nsp0 = {
  170. .pd = { .name = "nsp0", },
  171. .res_name = "nsp0.lvl",
  172. };
  173. static struct rpmhpd nsp1 = {
  174. .pd = { .name = "nsp1", },
  175. .res_name = "nsp1.lvl",
  176. };
  177. static struct rpmhpd nsp2 = {
  178. .pd = { .name = "nsp2", },
  179. .res_name = "nsp2.lvl",
  180. };
  181. static struct rpmhpd qphy = {
  182. .pd = { .name = "qphy", },
  183. .res_name = "qphy.lvl",
  184. };
  185. static struct rpmhpd gmxc = {
  186. .pd = { .name = "gmxc", },
  187. .res_name = "gmxc.lvl",
  188. };
  189. /* Milos RPMH powerdomains */
  190. static struct rpmhpd *milos_rpmhpds[] = {
  191. [RPMHPD_CX] = &cx,
  192. [RPMHPD_CX_AO] = &cx_ao,
  193. [RPMHPD_EBI] = &ebi,
  194. [RPMHPD_GFX] = &gfx,
  195. [RPMHPD_LCX] = &lcx,
  196. [RPMHPD_LMX] = &lmx,
  197. [RPMHPD_MSS] = &mss,
  198. [RPMHPD_MX] = &mx,
  199. [RPMHPD_MX_AO] = &mx_ao,
  200. };
  201. static const struct rpmhpd_desc milos_desc = {
  202. .rpmhpds = milos_rpmhpds,
  203. .num_pds = ARRAY_SIZE(milos_rpmhpds),
  204. };
  205. /* SA8540P RPMH powerdomains */
  206. static struct rpmhpd *sa8540p_rpmhpds[] = {
  207. [SC8280XP_CX] = &cx,
  208. [SC8280XP_CX_AO] = &cx_ao,
  209. [SC8280XP_EBI] = &ebi,
  210. [SC8280XP_LCX] = &lcx,
  211. [SC8280XP_LMX] = &lmx,
  212. [SC8280XP_MMCX] = &mmcx,
  213. [SC8280XP_MMCX_AO] = &mmcx_ao,
  214. [SC8280XP_MX] = &mx,
  215. [SC8280XP_MX_AO] = &mx_ao,
  216. [SC8280XP_MXC] = &mxc,
  217. [SC8280XP_MXC_AO] = &mxc_ao,
  218. [SC8280XP_NSP] = &nsp,
  219. };
  220. static const struct rpmhpd_desc sa8540p_desc = {
  221. .rpmhpds = sa8540p_rpmhpds,
  222. .num_pds = ARRAY_SIZE(sa8540p_rpmhpds),
  223. };
  224. /* SA8775P RPMH power domains */
  225. static struct rpmhpd *sa8775p_rpmhpds[] = {
  226. [SA8775P_CX] = &cx,
  227. [SA8775P_CX_AO] = &cx_ao,
  228. [SA8775P_EBI] = &ebi,
  229. [SA8775P_GFX] = &gfx,
  230. [SA8775P_LCX] = &lcx,
  231. [SA8775P_LMX] = &lmx,
  232. [SA8775P_MMCX] = &mmcx,
  233. [SA8775P_MMCX_AO] = &mmcx_ao,
  234. [SA8775P_MXC] = &mxc,
  235. [SA8775P_MXC_AO] = &mxc_ao,
  236. [SA8775P_MX] = &mx,
  237. [SA8775P_MX_AO] = &mx_ao,
  238. [SA8775P_NSP0] = &nsp0,
  239. [SA8775P_NSP1] = &nsp1,
  240. };
  241. static const struct rpmhpd_desc sa8775p_desc = {
  242. .rpmhpds = sa8775p_rpmhpds,
  243. .num_pds = ARRAY_SIZE(sa8775p_rpmhpds),
  244. };
  245. /* SAR2130P RPMH powerdomains */
  246. static struct rpmhpd *sar2130p_rpmhpds[] = {
  247. [RPMHPD_CX] = &cx,
  248. [RPMHPD_CX_AO] = &cx_ao,
  249. [RPMHPD_EBI] = &ebi,
  250. [RPMHPD_GFX] = &gfx,
  251. [RPMHPD_LCX] = &lcx,
  252. [RPMHPD_LMX] = &lmx,
  253. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  254. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  255. [RPMHPD_MSS] = &mss,
  256. [RPMHPD_MX] = &mx,
  257. [RPMHPD_MX_AO] = &mx_ao,
  258. [RPMHPD_MXC] = &mxc,
  259. [RPMHPD_MXC_AO] = &mxc_ao,
  260. [RPMHPD_NSP] = &nsp,
  261. [RPMHPD_QPHY] = &qphy,
  262. };
  263. static const struct rpmhpd_desc sar2130p_desc = {
  264. .rpmhpds = sar2130p_rpmhpds,
  265. .num_pds = ARRAY_SIZE(sar2130p_rpmhpds),
  266. };
  267. /* SDM670 RPMH powerdomains */
  268. static struct rpmhpd *sdm670_rpmhpds[] = {
  269. [SDM670_CX] = &cx_w_mx_parent,
  270. [SDM670_CX_AO] = &cx_ao_w_mx_parent,
  271. [SDM670_GFX] = &gfx,
  272. [SDM670_LCX] = &lcx,
  273. [SDM670_LMX] = &lmx,
  274. [SDM670_MSS] = &mss,
  275. [SDM670_MX] = &mx,
  276. [SDM670_MX_AO] = &mx_ao,
  277. };
  278. static const struct rpmhpd_desc sdm670_desc = {
  279. .rpmhpds = sdm670_rpmhpds,
  280. .num_pds = ARRAY_SIZE(sdm670_rpmhpds),
  281. };
  282. /* SDM845 RPMH powerdomains */
  283. static struct rpmhpd *sdm845_rpmhpds[] = {
  284. [SDM845_CX] = &cx_w_mx_parent,
  285. [SDM845_CX_AO] = &cx_ao_w_mx_parent,
  286. [SDM845_EBI] = &ebi,
  287. [SDM845_GFX] = &gfx,
  288. [SDM845_LCX] = &lcx,
  289. [SDM845_LMX] = &lmx,
  290. [SDM845_MSS] = &mss,
  291. [SDM845_MX] = &mx,
  292. [SDM845_MX_AO] = &mx_ao,
  293. };
  294. static const struct rpmhpd_desc sdm845_desc = {
  295. .rpmhpds = sdm845_rpmhpds,
  296. .num_pds = ARRAY_SIZE(sdm845_rpmhpds),
  297. };
  298. /* SDX55 RPMH powerdomains */
  299. static struct rpmhpd *sdx55_rpmhpds[] = {
  300. [SDX55_CX] = &cx_w_mx_parent,
  301. [SDX55_MSS] = &mss,
  302. [SDX55_MX] = &mx,
  303. };
  304. static const struct rpmhpd_desc sdx55_desc = {
  305. .rpmhpds = sdx55_rpmhpds,
  306. .num_pds = ARRAY_SIZE(sdx55_rpmhpds),
  307. };
  308. /* SDX65 RPMH powerdomains */
  309. static struct rpmhpd *sdx65_rpmhpds[] = {
  310. [SDX65_CX] = &cx_w_mx_parent,
  311. [SDX65_CX_AO] = &cx_ao_w_mx_parent,
  312. [SDX65_MSS] = &mss,
  313. [SDX65_MX] = &mx,
  314. [SDX65_MX_AO] = &mx_ao,
  315. [SDX65_MXC] = &mxc,
  316. };
  317. static const struct rpmhpd_desc sdx65_desc = {
  318. .rpmhpds = sdx65_rpmhpds,
  319. .num_pds = ARRAY_SIZE(sdx65_rpmhpds),
  320. };
  321. /* SDX75 RPMH powerdomains */
  322. static struct rpmhpd *sdx75_rpmhpds[] = {
  323. [RPMHPD_CX] = &cx,
  324. [RPMHPD_CX_AO] = &cx_ao,
  325. [RPMHPD_MSS] = &mss,
  326. [RPMHPD_MX] = &mx,
  327. [RPMHPD_MX_AO] = &mx_ao,
  328. [RPMHPD_MXC] = &mxc,
  329. };
  330. static const struct rpmhpd_desc sdx75_desc = {
  331. .rpmhpds = sdx75_rpmhpds,
  332. .num_pds = ARRAY_SIZE(sdx75_rpmhpds),
  333. };
  334. /* SM4450 RPMH powerdomains */
  335. static struct rpmhpd *sm4450_rpmhpds[] = {
  336. [RPMHPD_CX] = &cx,
  337. [RPMHPD_CX_AO] = &cx_ao,
  338. [RPMHPD_EBI] = &ebi,
  339. [RPMHPD_LMX] = &lmx,
  340. [RPMHPD_MSS] = &mss,
  341. [RPMHPD_MX] = &mx,
  342. };
  343. static const struct rpmhpd_desc sm4450_desc = {
  344. .rpmhpds = sm4450_rpmhpds,
  345. .num_pds = ARRAY_SIZE(sm4450_rpmhpds),
  346. };
  347. /* SM6350 RPMH powerdomains */
  348. static struct rpmhpd *sm6350_rpmhpds[] = {
  349. [SM6350_CX] = &cx_w_mx_parent,
  350. [SM6350_GFX] = &gfx,
  351. [SM6350_LCX] = &lcx,
  352. [SM6350_LMX] = &lmx,
  353. [SM6350_MSS] = &mss,
  354. [SM6350_MX] = &mx,
  355. };
  356. static const struct rpmhpd_desc sm6350_desc = {
  357. .rpmhpds = sm6350_rpmhpds,
  358. .num_pds = ARRAY_SIZE(sm6350_rpmhpds),
  359. };
  360. /* SM7150 RPMH powerdomains */
  361. static struct rpmhpd *sm7150_rpmhpds[] = {
  362. [RPMHPD_CX] = &cx_w_mx_parent,
  363. [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
  364. [RPMHPD_GFX] = &gfx,
  365. [RPMHPD_LCX] = &lcx,
  366. [RPMHPD_LMX] = &lmx,
  367. [RPMHPD_MX] = &mx,
  368. [RPMHPD_MX_AO] = &mx_ao,
  369. [RPMHPD_MSS] = &mss,
  370. };
  371. static const struct rpmhpd_desc sm7150_desc = {
  372. .rpmhpds = sm7150_rpmhpds,
  373. .num_pds = ARRAY_SIZE(sm7150_rpmhpds),
  374. };
  375. /* SM8150 RPMH powerdomains */
  376. static struct rpmhpd *sm8150_rpmhpds[] = {
  377. [SM8150_CX] = &cx_w_mx_parent,
  378. [SM8150_CX_AO] = &cx_ao_w_mx_parent,
  379. [SM8150_EBI] = &ebi,
  380. [SM8150_GFX] = &gfx,
  381. [SM8150_LCX] = &lcx,
  382. [SM8150_LMX] = &lmx,
  383. [SM8150_MMCX] = &mmcx,
  384. [SM8150_MMCX_AO] = &mmcx_ao,
  385. [SM8150_MSS] = &mss,
  386. [SM8150_MX] = &mx,
  387. [SM8150_MX_AO] = &mx_ao,
  388. };
  389. static const struct rpmhpd_desc sm8150_desc = {
  390. .rpmhpds = sm8150_rpmhpds,
  391. .num_pds = ARRAY_SIZE(sm8150_rpmhpds),
  392. };
  393. static struct rpmhpd *sa8155p_rpmhpds[] = {
  394. [SA8155P_CX] = &cx_w_mx_parent,
  395. [SA8155P_CX_AO] = &cx_ao_w_mx_parent,
  396. [SA8155P_EBI] = &ebi,
  397. [SA8155P_GFX] = &gfx,
  398. [SA8155P_MSS] = &mss,
  399. [SA8155P_MX] = &mx,
  400. [SA8155P_MX_AO] = &mx_ao,
  401. };
  402. static const struct rpmhpd_desc sa8155p_desc = {
  403. .rpmhpds = sa8155p_rpmhpds,
  404. .num_pds = ARRAY_SIZE(sa8155p_rpmhpds),
  405. };
  406. /* SM8250 RPMH powerdomains */
  407. static struct rpmhpd *sm8250_rpmhpds[] = {
  408. [RPMHPD_CX] = &cx_w_mx_parent,
  409. [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
  410. [RPMHPD_EBI] = &ebi,
  411. [RPMHPD_GFX] = &gfx,
  412. [RPMHPD_LCX] = &lcx,
  413. [RPMHPD_LMX] = &lmx,
  414. [RPMHPD_MMCX] = &mmcx,
  415. [RPMHPD_MMCX_AO] = &mmcx_ao,
  416. [RPMHPD_MX] = &mx,
  417. [RPMHPD_MX_AO] = &mx_ao,
  418. };
  419. static const struct rpmhpd_desc sm8250_desc = {
  420. .rpmhpds = sm8250_rpmhpds,
  421. .num_pds = ARRAY_SIZE(sm8250_rpmhpds),
  422. };
  423. /* SM8350 Power domains */
  424. static struct rpmhpd *sm8350_rpmhpds[] = {
  425. [RPMHPD_CX] = &cx_w_mx_parent,
  426. [RPMHPD_CX_AO] = &cx_ao_w_mx_parent,
  427. [RPMHPD_EBI] = &ebi,
  428. [RPMHPD_GFX] = &gfx,
  429. [RPMHPD_LCX] = &lcx,
  430. [RPMHPD_LMX] = &lmx,
  431. [RPMHPD_MMCX] = &mmcx,
  432. [RPMHPD_MMCX_AO] = &mmcx_ao,
  433. [RPMHPD_MSS] = &mss,
  434. [RPMHPD_MX] = &mx,
  435. [RPMHPD_MX_AO] = &mx_ao,
  436. [RPMHPD_MXC] = &mxc,
  437. [RPMHPD_MXC_AO] = &mxc_ao,
  438. };
  439. static const struct rpmhpd_desc sm8350_desc = {
  440. .rpmhpds = sm8350_rpmhpds,
  441. .num_pds = ARRAY_SIZE(sm8350_rpmhpds),
  442. };
  443. /* SM8450 RPMH powerdomains */
  444. static struct rpmhpd *sm8450_rpmhpds[] = {
  445. [RPMHPD_CX] = &cx,
  446. [RPMHPD_CX_AO] = &cx_ao,
  447. [RPMHPD_EBI] = &ebi,
  448. [RPMHPD_GFX] = &gfx,
  449. [RPMHPD_LCX] = &lcx,
  450. [RPMHPD_LMX] = &lmx,
  451. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  452. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  453. [RPMHPD_MSS] = &mss,
  454. [RPMHPD_MX] = &mx,
  455. [RPMHPD_MX_AO] = &mx_ao,
  456. [RPMHPD_MXC] = &mxc,
  457. [RPMHPD_MXC_AO] = &mxc_ao,
  458. };
  459. static const struct rpmhpd_desc sm8450_desc = {
  460. .rpmhpds = sm8450_rpmhpds,
  461. .num_pds = ARRAY_SIZE(sm8450_rpmhpds),
  462. };
  463. /* SM8550 RPMH powerdomains */
  464. static struct rpmhpd *sm8550_rpmhpds[] = {
  465. [RPMHPD_CX] = &cx,
  466. [RPMHPD_CX_AO] = &cx_ao,
  467. [RPMHPD_EBI] = &ebi,
  468. [RPMHPD_GFX] = &gfx,
  469. [RPMHPD_LCX] = &lcx,
  470. [RPMHPD_LMX] = &lmx,
  471. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  472. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  473. [RPMHPD_MSS] = &mss,
  474. [RPMHPD_MX] = &mx,
  475. [RPMHPD_MX_AO] = &mx_ao,
  476. [RPMHPD_MXC] = &mxc,
  477. [RPMHPD_MXC_AO] = &mxc_ao,
  478. [RPMHPD_NSP] = &nsp,
  479. };
  480. static const struct rpmhpd_desc sm8550_desc = {
  481. .rpmhpds = sm8550_rpmhpds,
  482. .num_pds = ARRAY_SIZE(sm8550_rpmhpds),
  483. };
  484. /* SM8650 RPMH powerdomains */
  485. static struct rpmhpd *sm8650_rpmhpds[] = {
  486. [RPMHPD_CX] = &cx,
  487. [RPMHPD_CX_AO] = &cx_ao,
  488. [RPMHPD_EBI] = &ebi,
  489. [RPMHPD_GFX] = &gfx,
  490. [RPMHPD_LCX] = &lcx,
  491. [RPMHPD_LMX] = &lmx,
  492. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  493. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  494. [RPMHPD_MSS] = &mss,
  495. [RPMHPD_MX] = &mx,
  496. [RPMHPD_MX_AO] = &mx_ao,
  497. [RPMHPD_MXC] = &mxc,
  498. [RPMHPD_MXC_AO] = &mxc_ao,
  499. [RPMHPD_NSP] = &nsp,
  500. [RPMHPD_NSP2] = &nsp2,
  501. };
  502. static const struct rpmhpd_desc sm8650_desc = {
  503. .rpmhpds = sm8650_rpmhpds,
  504. .num_pds = ARRAY_SIZE(sm8650_rpmhpds),
  505. };
  506. /* SM8750 RPMH powerdomains */
  507. static struct rpmhpd *sm8750_rpmhpds[] = {
  508. [RPMHPD_CX] = &cx,
  509. [RPMHPD_CX_AO] = &cx_ao,
  510. [RPMHPD_EBI] = &ebi,
  511. [RPMHPD_GFX] = &gfx,
  512. [RPMHPD_GMXC] = &gmxc,
  513. [RPMHPD_LCX] = &lcx,
  514. [RPMHPD_LMX] = &lmx,
  515. [RPMHPD_MX] = &mx,
  516. [RPMHPD_MX_AO] = &mx_ao,
  517. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  518. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  519. [RPMHPD_MSS] = &mss,
  520. [RPMHPD_MXC] = &mxc,
  521. [RPMHPD_MXC_AO] = &mxc_ao,
  522. [RPMHPD_NSP] = &nsp,
  523. [RPMHPD_NSP2] = &nsp2,
  524. };
  525. static const struct rpmhpd_desc sm8750_desc = {
  526. .rpmhpds = sm8750_rpmhpds,
  527. .num_pds = ARRAY_SIZE(sm8750_rpmhpds),
  528. };
  529. /* KAANAPALI RPMH powerdomains */
  530. static struct rpmhpd *kaanapali_rpmhpds[] = {
  531. [RPMHPD_CX] = &cx,
  532. [RPMHPD_CX_AO] = &cx_ao,
  533. [RPMHPD_EBI] = &ebi,
  534. [RPMHPD_GFX] = &gfx,
  535. [RPMHPD_GMXC] = &gmxc,
  536. [RPMHPD_LCX] = &lcx,
  537. [RPMHPD_LMX] = &lmx,
  538. [RPMHPD_MX] = &mx,
  539. [RPMHPD_MX_AO] = &mx_ao,
  540. [RPMHPD_MMCX] = &mmcx,
  541. [RPMHPD_MMCX_AO] = &mmcx_ao,
  542. [RPMHPD_MSS] = &mss,
  543. [RPMHPD_MXC] = &mxc,
  544. [RPMHPD_MXC_AO] = &mxc_ao,
  545. [RPMHPD_NSP] = &nsp,
  546. [RPMHPD_NSP2] = &nsp2,
  547. };
  548. static const struct rpmhpd_desc kaanapali_desc = {
  549. .rpmhpds = kaanapali_rpmhpds,
  550. .num_pds = ARRAY_SIZE(kaanapali_rpmhpds),
  551. };
  552. /* QDU1000/QRU1000 RPMH powerdomains */
  553. static struct rpmhpd *qdu1000_rpmhpds[] = {
  554. [QDU1000_CX] = &cx,
  555. [QDU1000_EBI] = &ebi,
  556. [QDU1000_MSS] = &mss,
  557. [QDU1000_MX] = &mx,
  558. };
  559. static const struct rpmhpd_desc qdu1000_desc = {
  560. .rpmhpds = qdu1000_rpmhpds,
  561. .num_pds = ARRAY_SIZE(qdu1000_rpmhpds),
  562. };
  563. /* SC7180 RPMH powerdomains */
  564. static struct rpmhpd *sc7180_rpmhpds[] = {
  565. [SC7180_CX] = &cx_w_mx_parent,
  566. [SC7180_CX_AO] = &cx_ao_w_mx_parent,
  567. [SC7180_GFX] = &gfx,
  568. [SC7180_LCX] = &lcx,
  569. [SC7180_LMX] = &lmx,
  570. [SC7180_MSS] = &mss,
  571. [SC7180_MX] = &mx,
  572. [SC7180_MX_AO] = &mx_ao,
  573. };
  574. static const struct rpmhpd_desc sc7180_desc = {
  575. .rpmhpds = sc7180_rpmhpds,
  576. .num_pds = ARRAY_SIZE(sc7180_rpmhpds),
  577. };
  578. /* SC7280 RPMH powerdomains */
  579. static struct rpmhpd *sc7280_rpmhpds[] = {
  580. [SC7280_CX] = &cx,
  581. [SC7280_CX_AO] = &cx_ao,
  582. [SC7280_EBI] = &ebi,
  583. [SC7280_GFX] = &gfx,
  584. [SC7280_LCX] = &lcx,
  585. [SC7280_LMX] = &lmx,
  586. [SC7280_MSS] = &mss,
  587. [SC7280_MX] = &mx,
  588. [SC7280_MX_AO] = &mx_ao,
  589. };
  590. static const struct rpmhpd_desc sc7280_desc = {
  591. .rpmhpds = sc7280_rpmhpds,
  592. .num_pds = ARRAY_SIZE(sc7280_rpmhpds),
  593. };
  594. /* SC8180x RPMH powerdomains */
  595. static struct rpmhpd *sc8180x_rpmhpds[] = {
  596. [SC8180X_CX] = &cx_w_mx_parent,
  597. [SC8180X_CX_AO] = &cx_ao_w_mx_parent,
  598. [SC8180X_EBI] = &ebi,
  599. [SC8180X_GFX] = &gfx,
  600. [SC8180X_LCX] = &lcx,
  601. [SC8180X_LMX] = &lmx,
  602. [SC8180X_MMCX] = &mmcx,
  603. [SC8180X_MMCX_AO] = &mmcx_ao,
  604. [SC8180X_MSS] = &mss,
  605. [SC8180X_MX] = &mx,
  606. [SC8180X_MX_AO] = &mx_ao,
  607. };
  608. static const struct rpmhpd_desc sc8180x_desc = {
  609. .rpmhpds = sc8180x_rpmhpds,
  610. .num_pds = ARRAY_SIZE(sc8180x_rpmhpds),
  611. };
  612. /* SC8280xp RPMH powerdomains */
  613. static struct rpmhpd *sc8280xp_rpmhpds[] = {
  614. [SC8280XP_CX] = &cx,
  615. [SC8280XP_CX_AO] = &cx_ao,
  616. [SC8280XP_EBI] = &ebi,
  617. [SC8280XP_GFX] = &gfx,
  618. [SC8280XP_LCX] = &lcx,
  619. [SC8280XP_LMX] = &lmx,
  620. [SC8280XP_MMCX] = &mmcx,
  621. [SC8280XP_MMCX_AO] = &mmcx_ao,
  622. [SC8280XP_MX] = &mx,
  623. [SC8280XP_MX_AO] = &mx_ao,
  624. [SC8280XP_MXC] = &mxc,
  625. [SC8280XP_MXC_AO] = &mxc_ao,
  626. [SC8280XP_NSP] = &nsp,
  627. [SC8280XP_QPHY] = &qphy,
  628. };
  629. static const struct rpmhpd_desc sc8280xp_desc = {
  630. .rpmhpds = sc8280xp_rpmhpds,
  631. .num_pds = ARRAY_SIZE(sc8280xp_rpmhpds),
  632. };
  633. /* Glymur RPMH powerdomains */
  634. static struct rpmhpd *glymur_rpmhpds[] = {
  635. [RPMHPD_CX] = &cx,
  636. [RPMHPD_CX_AO] = &cx_ao,
  637. [RPMHPD_EBI] = &ebi,
  638. [RPMHPD_GFX] = &gfx,
  639. [RPMHPD_LCX] = &lcx,
  640. [RPMHPD_LMX] = &lmx,
  641. [RPMHPD_MMCX] = &mmcx,
  642. [RPMHPD_MMCX_AO] = &mmcx_ao,
  643. [RPMHPD_MX] = &mx,
  644. [RPMHPD_MX_AO] = &mx_ao,
  645. [RPMHPD_MXC] = &mxc,
  646. [RPMHPD_MXC_AO] = &mxc_ao,
  647. [RPMHPD_MSS] = &mss,
  648. [RPMHPD_NSP] = &nsp,
  649. [RPMHPD_NSP2] = &nsp2,
  650. [RPMHPD_GMXC] = &gmxc,
  651. };
  652. static const struct rpmhpd_desc glymur_desc = {
  653. .rpmhpds = glymur_rpmhpds,
  654. .num_pds = ARRAY_SIZE(glymur_rpmhpds),
  655. };
  656. /* X1E80100 RPMH powerdomains */
  657. static struct rpmhpd *x1e80100_rpmhpds[] = {
  658. [RPMHPD_CX] = &cx,
  659. [RPMHPD_CX_AO] = &cx_ao,
  660. [RPMHPD_EBI] = &ebi,
  661. [RPMHPD_GFX] = &gfx,
  662. [RPMHPD_LCX] = &lcx,
  663. [RPMHPD_LMX] = &lmx,
  664. [RPMHPD_MMCX] = &mmcx,
  665. [RPMHPD_MMCX_AO] = &mmcx_ao,
  666. [RPMHPD_MX] = &mx,
  667. [RPMHPD_MX_AO] = &mx_ao,
  668. [RPMHPD_NSP] = &nsp,
  669. [RPMHPD_MXC] = &mxc,
  670. [RPMHPD_GMXC] = &gmxc,
  671. };
  672. static const struct rpmhpd_desc x1e80100_desc = {
  673. .rpmhpds = x1e80100_rpmhpds,
  674. .num_pds = ARRAY_SIZE(x1e80100_rpmhpds),
  675. };
  676. /* QCS8300 RPMH power domains */
  677. static struct rpmhpd *qcs8300_rpmhpds[] = {
  678. [RPMHPD_CX] = &cx,
  679. [RPMHPD_CX_AO] = &cx_ao,
  680. [RPMHPD_EBI] = &ebi,
  681. [RPMHPD_GFX] = &gfx,
  682. [RPMHPD_LCX] = &lcx,
  683. [RPMHPD_LMX] = &lmx,
  684. [RPMHPD_MMCX] = &mmcx_w_cx_parent,
  685. [RPMHPD_MMCX_AO] = &mmcx_ao_w_cx_parent,
  686. [RPMHPD_MXC] = &mxc,
  687. [RPMHPD_MXC_AO] = &mxc_ao,
  688. [RPMHPD_MX] = &mx,
  689. [RPMHPD_MX_AO] = &mx_ao,
  690. [RPMHPD_NSP0] = &nsp0,
  691. [RPMHPD_NSP1] = &nsp1,
  692. };
  693. static const struct rpmhpd_desc qcs8300_desc = {
  694. .rpmhpds = qcs8300_rpmhpds,
  695. .num_pds = ARRAY_SIZE(qcs8300_rpmhpds),
  696. };
  697. /* QCS615 RPMH powerdomains */
  698. static struct rpmhpd *qcs615_rpmhpds[] = {
  699. [RPMHPD_CX] = &cx,
  700. [RPMHPD_CX_AO] = &cx_ao,
  701. };
  702. static const struct rpmhpd_desc qcs615_desc = {
  703. .rpmhpds = qcs615_rpmhpds,
  704. .num_pds = ARRAY_SIZE(qcs615_rpmhpds),
  705. };
  706. static const struct of_device_id rpmhpd_match_table[] = {
  707. { .compatible = "qcom,glymur-rpmhpd", .data = &glymur_desc },
  708. { .compatible = "qcom,kaanapali-rpmhpd", .data = &kaanapali_desc },
  709. { .compatible = "qcom,milos-rpmhpd", .data = &milos_desc },
  710. { .compatible = "qcom,qcs615-rpmhpd", .data = &qcs615_desc },
  711. { .compatible = "qcom,qcs8300-rpmhpd", .data = &qcs8300_desc },
  712. { .compatible = "qcom,qdu1000-rpmhpd", .data = &qdu1000_desc },
  713. { .compatible = "qcom,sa8155p-rpmhpd", .data = &sa8155p_desc },
  714. { .compatible = "qcom,sa8540p-rpmhpd", .data = &sa8540p_desc },
  715. { .compatible = "qcom,sa8775p-rpmhpd", .data = &sa8775p_desc },
  716. { .compatible = "qcom,sar2130p-rpmhpd", .data = &sar2130p_desc},
  717. { .compatible = "qcom,sc7180-rpmhpd", .data = &sc7180_desc },
  718. { .compatible = "qcom,sc7280-rpmhpd", .data = &sc7280_desc },
  719. { .compatible = "qcom,sc8180x-rpmhpd", .data = &sc8180x_desc },
  720. { .compatible = "qcom,sc8280xp-rpmhpd", .data = &sc8280xp_desc },
  721. { .compatible = "qcom,sdm670-rpmhpd", .data = &sdm670_desc },
  722. { .compatible = "qcom,sdm845-rpmhpd", .data = &sdm845_desc },
  723. { .compatible = "qcom,sdx55-rpmhpd", .data = &sdx55_desc},
  724. { .compatible = "qcom,sdx65-rpmhpd", .data = &sdx65_desc},
  725. { .compatible = "qcom,sdx75-rpmhpd", .data = &sdx75_desc},
  726. { .compatible = "qcom,sm4450-rpmhpd", .data = &sm4450_desc },
  727. { .compatible = "qcom,sm6350-rpmhpd", .data = &sm6350_desc },
  728. { .compatible = "qcom,sm7150-rpmhpd", .data = &sm7150_desc },
  729. { .compatible = "qcom,sm8150-rpmhpd", .data = &sm8150_desc },
  730. { .compatible = "qcom,sm8250-rpmhpd", .data = &sm8250_desc },
  731. { .compatible = "qcom,sm8350-rpmhpd", .data = &sm8350_desc },
  732. { .compatible = "qcom,sm8450-rpmhpd", .data = &sm8450_desc },
  733. { .compatible = "qcom,sm8550-rpmhpd", .data = &sm8550_desc },
  734. { .compatible = "qcom,sm8650-rpmhpd", .data = &sm8650_desc },
  735. { .compatible = "qcom,sm8750-rpmhpd", .data = &sm8750_desc },
  736. { .compatible = "qcom,x1e80100-rpmhpd", .data = &x1e80100_desc },
  737. { }
  738. };
  739. MODULE_DEVICE_TABLE(of, rpmhpd_match_table);
  740. static int rpmhpd_send_corner(struct rpmhpd *pd, int state,
  741. unsigned int corner, bool sync)
  742. {
  743. struct tcs_cmd cmd = {
  744. .addr = pd->addr,
  745. .data = corner,
  746. };
  747. /*
  748. * Wait for an ack only when we are increasing the
  749. * perf state of the power domain
  750. */
  751. if (sync)
  752. return rpmh_write(pd->dev, state, &cmd, 1);
  753. else
  754. return rpmh_write_async(pd->dev, state, &cmd, 1);
  755. }
  756. static void to_active_sleep(struct rpmhpd *pd, unsigned int corner,
  757. unsigned int *active, unsigned int *sleep)
  758. {
  759. *active = corner;
  760. if (pd->active_only)
  761. *sleep = 0;
  762. else
  763. *sleep = *active;
  764. }
  765. /*
  766. * This function is used to aggregate the votes across the active only
  767. * resources and its peers. The aggregated votes are sent to RPMh as
  768. * ACTIVE_ONLY votes (which take effect immediately), as WAKE_ONLY votes
  769. * (applied by RPMh on system wakeup) and as SLEEP votes (applied by RPMh
  770. * on system sleep).
  771. * We send ACTIVE_ONLY votes for resources without any peers. For others,
  772. * which have an active only peer, all 3 votes are sent.
  773. */
  774. static int rpmhpd_aggregate_corner(struct rpmhpd *pd, unsigned int corner)
  775. {
  776. int ret;
  777. struct rpmhpd *peer = pd->peer;
  778. unsigned int active_corner, sleep_corner;
  779. unsigned int this_active_corner = 0, this_sleep_corner = 0;
  780. unsigned int peer_active_corner = 0, peer_sleep_corner = 0;
  781. unsigned int peer_enabled_corner;
  782. if (pd->state_synced) {
  783. to_active_sleep(pd, corner, &this_active_corner, &this_sleep_corner);
  784. } else {
  785. /* Clamp to highest corner if sync_state hasn't happened */
  786. this_active_corner = pd->level_count - 1;
  787. this_sleep_corner = pd->level_count - 1;
  788. }
  789. if (peer && peer->enabled) {
  790. peer_enabled_corner = max(peer->corner, peer->enable_corner);
  791. to_active_sleep(peer, peer_enabled_corner, &peer_active_corner,
  792. &peer_sleep_corner);
  793. }
  794. active_corner = max(this_active_corner, peer_active_corner);
  795. ret = rpmhpd_send_corner(pd, RPMH_ACTIVE_ONLY_STATE, active_corner,
  796. active_corner > pd->active_corner);
  797. if (ret)
  798. return ret;
  799. pd->active_corner = active_corner;
  800. if (peer) {
  801. peer->active_corner = active_corner;
  802. ret = rpmhpd_send_corner(pd, RPMH_WAKE_ONLY_STATE,
  803. active_corner, false);
  804. if (ret)
  805. return ret;
  806. sleep_corner = max(this_sleep_corner, peer_sleep_corner);
  807. return rpmhpd_send_corner(pd, RPMH_SLEEP_STATE, sleep_corner,
  808. false);
  809. }
  810. return ret;
  811. }
  812. static int rpmhpd_power_on(struct generic_pm_domain *domain)
  813. {
  814. struct rpmhpd *pd = domain_to_rpmhpd(domain);
  815. unsigned int corner;
  816. int ret;
  817. mutex_lock(&rpmhpd_lock);
  818. corner = max(pd->corner, pd->enable_corner);
  819. ret = rpmhpd_aggregate_corner(pd, corner);
  820. if (!ret)
  821. pd->enabled = true;
  822. mutex_unlock(&rpmhpd_lock);
  823. return ret;
  824. }
  825. static int rpmhpd_power_off(struct generic_pm_domain *domain)
  826. {
  827. struct rpmhpd *pd = domain_to_rpmhpd(domain);
  828. int ret;
  829. mutex_lock(&rpmhpd_lock);
  830. ret = rpmhpd_aggregate_corner(pd, 0);
  831. if (!ret)
  832. pd->enabled = false;
  833. mutex_unlock(&rpmhpd_lock);
  834. return ret;
  835. }
  836. static int rpmhpd_set_performance_state(struct generic_pm_domain *domain,
  837. unsigned int level)
  838. {
  839. struct rpmhpd *pd = domain_to_rpmhpd(domain);
  840. int ret, i;
  841. guard(mutex)(&rpmhpd_lock);
  842. for (i = 0; i < pd->level_count; i++)
  843. if (level <= pd->level[i])
  844. break;
  845. /*
  846. * If the level requested is more than that supported by the
  847. * max corner, just set it to max anyway.
  848. */
  849. if (i == pd->level_count)
  850. i--;
  851. if (pd->enabled) {
  852. /* Ensure that the domain isn't turn off */
  853. if (i < pd->enable_corner)
  854. i = pd->enable_corner;
  855. ret = rpmhpd_aggregate_corner(pd, i);
  856. if (ret)
  857. return ret;
  858. }
  859. pd->corner = i;
  860. return 0;
  861. }
  862. static int rpmhpd_update_level_mapping(struct rpmhpd *rpmhpd)
  863. {
  864. int i;
  865. const u16 *buf;
  866. buf = cmd_db_read_aux_data(rpmhpd->res_name, &rpmhpd->level_count);
  867. if (IS_ERR(buf))
  868. return PTR_ERR(buf);
  869. /* 2 bytes used for each command DB aux data entry */
  870. rpmhpd->level_count >>= 1;
  871. if (rpmhpd->level_count > RPMH_ARC_MAX_LEVELS)
  872. return -EINVAL;
  873. for (i = 0; i < rpmhpd->level_count; i++) {
  874. if (rpmhpd->skip_retention_level && buf[i] == RPMH_REGULATOR_LEVEL_RETENTION)
  875. continue;
  876. rpmhpd->level[i] = buf[i];
  877. /* Remember the first corner with non-zero level */
  878. if (!rpmhpd->level[rpmhpd->enable_corner] && rpmhpd->level[i])
  879. rpmhpd->enable_corner = i;
  880. /*
  881. * The AUX data may be zero padded. These 0 valued entries at
  882. * the end of the map must be ignored.
  883. */
  884. if (i > 0 && rpmhpd->level[i] == 0) {
  885. rpmhpd->level_count = i;
  886. break;
  887. }
  888. pr_debug("%s: ARC hlvl=%2d --> vlvl=%4u\n", rpmhpd->res_name, i,
  889. rpmhpd->level[i]);
  890. }
  891. return 0;
  892. }
  893. static int rpmhpd_probe(struct platform_device *pdev)
  894. {
  895. int i, ret;
  896. size_t num_pds;
  897. struct device *dev = &pdev->dev;
  898. struct genpd_onecell_data *data;
  899. struct rpmhpd **rpmhpds;
  900. const struct rpmhpd_desc *desc;
  901. desc = of_device_get_match_data(dev);
  902. if (!desc)
  903. return -EINVAL;
  904. rpmhpds = desc->rpmhpds;
  905. num_pds = desc->num_pds;
  906. data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
  907. if (!data)
  908. return -ENOMEM;
  909. data->domains = devm_kcalloc(dev, num_pds, sizeof(*data->domains),
  910. GFP_KERNEL);
  911. if (!data->domains)
  912. return -ENOMEM;
  913. data->num_domains = num_pds;
  914. for (i = 0; i < num_pds; i++) {
  915. if (!rpmhpds[i])
  916. continue;
  917. rpmhpds[i]->dev = dev;
  918. rpmhpds[i]->addr = cmd_db_read_addr(rpmhpds[i]->res_name);
  919. if (!rpmhpds[i]->addr) {
  920. dev_err(dev, "Could not find RPMh address for resource %s\n",
  921. rpmhpds[i]->res_name);
  922. return -ENODEV;
  923. }
  924. ret = cmd_db_read_slave_id(rpmhpds[i]->res_name);
  925. if (ret != CMD_DB_HW_ARC) {
  926. dev_err(dev, "RPMh slave ID mismatch\n");
  927. return -EINVAL;
  928. }
  929. ret = rpmhpd_update_level_mapping(rpmhpds[i]);
  930. if (ret)
  931. return ret;
  932. rpmhpds[i]->pd.power_off = rpmhpd_power_off;
  933. rpmhpds[i]->pd.power_on = rpmhpd_power_on;
  934. rpmhpds[i]->pd.set_performance_state = rpmhpd_set_performance_state;
  935. pm_genpd_init(&rpmhpds[i]->pd, NULL, true);
  936. data->domains[i] = &rpmhpds[i]->pd;
  937. }
  938. /* Add subdomains */
  939. for (i = 0; i < num_pds; i++) {
  940. if (!rpmhpds[i])
  941. continue;
  942. if (rpmhpds[i]->parent)
  943. pm_genpd_add_subdomain(rpmhpds[i]->parent,
  944. &rpmhpds[i]->pd);
  945. }
  946. return of_genpd_add_provider_onecell(pdev->dev.of_node, data);
  947. }
  948. static void rpmhpd_sync_state(struct device *dev)
  949. {
  950. const struct rpmhpd_desc *desc = of_device_get_match_data(dev);
  951. struct rpmhpd **rpmhpds = desc->rpmhpds;
  952. unsigned int corner;
  953. struct rpmhpd *pd;
  954. unsigned int i;
  955. int ret;
  956. of_genpd_sync_state(dev->of_node);
  957. mutex_lock(&rpmhpd_lock);
  958. for (i = 0; i < desc->num_pds; i++) {
  959. pd = rpmhpds[i];
  960. if (!pd)
  961. continue;
  962. pd->state_synced = true;
  963. if (pd->enabled)
  964. corner = max(pd->corner, pd->enable_corner);
  965. else
  966. corner = 0;
  967. ret = rpmhpd_aggregate_corner(pd, corner);
  968. if (ret)
  969. dev_err(dev, "failed to sync %s\n", pd->res_name);
  970. }
  971. mutex_unlock(&rpmhpd_lock);
  972. }
  973. static struct platform_driver rpmhpd_driver = {
  974. .driver = {
  975. .name = "qcom-rpmhpd",
  976. .of_match_table = rpmhpd_match_table,
  977. .suppress_bind_attrs = true,
  978. .sync_state = rpmhpd_sync_state,
  979. },
  980. .probe = rpmhpd_probe,
  981. };
  982. static int __init rpmhpd_init(void)
  983. {
  984. return platform_driver_register(&rpmhpd_driver);
  985. }
  986. core_initcall(rpmhpd_init);
  987. MODULE_DESCRIPTION("Qualcomm Technologies, Inc. RPMh Power Domain Driver");
  988. MODULE_LICENSE("GPL v2");