imx8m-blk-ctrl.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2021 Pengutronix, Lucas Stach <[email protected]>
  4. */
  5. #include <linux/device.h>
  6. #include <linux/interconnect.h>
  7. #include <linux/module.h>
  8. #include <linux/of_device.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/pm_domain.h>
  11. #include <linux/pm_runtime.h>
  12. #include <linux/regmap.h>
  13. #include <linux/clk.h>
  14. #include <dt-bindings/power/imx8mm-power.h>
  15. #include <dt-bindings/power/imx8mn-power.h>
  16. #include <dt-bindings/power/imx8mp-power.h>
  17. #include <dt-bindings/power/imx8mq-power.h>
  18. #define BLK_SFT_RSTN 0x0
  19. #define BLK_CLK_EN 0x4
  20. #define BLK_MIPI_RESET_DIV 0x8 /* Mini/Nano/Plus DISPLAY_BLK_CTRL only */
  21. struct imx8m_blk_ctrl_domain;
  22. struct imx8m_blk_ctrl {
  23. struct device *dev;
  24. struct notifier_block power_nb;
  25. struct device *bus_power_dev;
  26. struct regmap *regmap;
  27. struct imx8m_blk_ctrl_domain *domains;
  28. struct genpd_onecell_data onecell_data;
  29. };
  30. struct imx8m_blk_ctrl_domain_data {
  31. const char *name;
  32. const char * const *clk_names;
  33. int num_clks;
  34. const char * const *path_names;
  35. int num_paths;
  36. const char *gpc_name;
  37. u32 rst_mask;
  38. u32 clk_mask;
  39. /*
  40. * i.MX8M Mini, Nano and Plus have a third DISPLAY_BLK_CTRL register
  41. * which is used to control the reset for the MIPI Phy.
  42. * Since it's only present in certain circumstances,
  43. * an if-statement should be used before setting and clearing this
  44. * register.
  45. */
  46. u32 mipi_phy_rst_mask;
  47. };
  48. #define DOMAIN_MAX_CLKS 4
  49. #define DOMAIN_MAX_PATHS 4
  50. struct imx8m_blk_ctrl_domain {
  51. struct generic_pm_domain genpd;
  52. const struct imx8m_blk_ctrl_domain_data *data;
  53. struct clk_bulk_data clks[DOMAIN_MAX_CLKS];
  54. struct icc_bulk_data paths[DOMAIN_MAX_PATHS];
  55. struct device *power_dev;
  56. struct imx8m_blk_ctrl *bc;
  57. int num_paths;
  58. };
  59. struct imx8m_blk_ctrl_data {
  60. int max_reg;
  61. notifier_fn_t power_notifier_fn;
  62. const struct imx8m_blk_ctrl_domain_data *domains;
  63. int num_domains;
  64. };
  65. static inline struct imx8m_blk_ctrl_domain *
  66. to_imx8m_blk_ctrl_domain(struct generic_pm_domain *genpd)
  67. {
  68. return container_of(genpd, struct imx8m_blk_ctrl_domain, genpd);
  69. }
  70. static int imx8m_blk_ctrl_power_on(struct generic_pm_domain *genpd)
  71. {
  72. struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
  73. const struct imx8m_blk_ctrl_domain_data *data = domain->data;
  74. struct imx8m_blk_ctrl *bc = domain->bc;
  75. int ret;
  76. /* make sure bus domain is awake */
  77. ret = pm_runtime_get_sync(bc->bus_power_dev);
  78. if (ret < 0) {
  79. pm_runtime_put_noidle(bc->bus_power_dev);
  80. dev_err(bc->dev, "failed to power up bus domain\n");
  81. return ret;
  82. }
  83. /* put devices into reset */
  84. regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
  85. if (data->mipi_phy_rst_mask)
  86. regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
  87. /* enable upstream and blk-ctrl clocks to allow reset to propagate */
  88. ret = clk_bulk_prepare_enable(data->num_clks, domain->clks);
  89. if (ret) {
  90. dev_err(bc->dev, "failed to enable clocks\n");
  91. goto bus_put;
  92. }
  93. regmap_set_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
  94. /* power up upstream GPC domain */
  95. ret = pm_runtime_get_sync(domain->power_dev);
  96. if (ret < 0) {
  97. dev_err(bc->dev, "failed to power up peripheral domain\n");
  98. goto clk_disable;
  99. }
  100. /* wait for reset to propagate */
  101. udelay(5);
  102. /* release reset */
  103. regmap_set_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
  104. if (data->mipi_phy_rst_mask)
  105. regmap_set_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
  106. ret = icc_bulk_set_bw(domain->num_paths, domain->paths);
  107. if (ret)
  108. dev_err(bc->dev, "failed to set icc bw\n");
  109. /* disable upstream clocks */
  110. clk_bulk_disable_unprepare(data->num_clks, domain->clks);
  111. return 0;
  112. clk_disable:
  113. clk_bulk_disable_unprepare(data->num_clks, domain->clks);
  114. bus_put:
  115. pm_runtime_put(bc->bus_power_dev);
  116. return ret;
  117. }
  118. static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
  119. {
  120. struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
  121. const struct imx8m_blk_ctrl_domain_data *data = domain->data;
  122. struct imx8m_blk_ctrl *bc = domain->bc;
  123. /* put devices into reset and disable clocks */
  124. if (data->mipi_phy_rst_mask)
  125. regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
  126. regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
  127. regmap_clear_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
  128. /* power down upstream GPC domain */
  129. pm_runtime_put(domain->power_dev);
  130. /* allow bus domain to suspend */
  131. pm_runtime_put(bc->bus_power_dev);
  132. return 0;
  133. }
  134. static struct lock_class_key blk_ctrl_genpd_lock_class;
  135. static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
  136. {
  137. const struct imx8m_blk_ctrl_data *bc_data;
  138. struct device *dev = &pdev->dev;
  139. struct imx8m_blk_ctrl *bc;
  140. void __iomem *base;
  141. int i, ret;
  142. struct regmap_config regmap_config = {
  143. .reg_bits = 32,
  144. .val_bits = 32,
  145. .reg_stride = 4,
  146. };
  147. bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL);
  148. if (!bc)
  149. return -ENOMEM;
  150. bc->dev = dev;
  151. bc_data = of_device_get_match_data(dev);
  152. base = devm_platform_ioremap_resource(pdev, 0);
  153. if (IS_ERR(base))
  154. return PTR_ERR(base);
  155. regmap_config.max_register = bc_data->max_reg;
  156. bc->regmap = devm_regmap_init_mmio(dev, base, &regmap_config);
  157. if (IS_ERR(bc->regmap))
  158. return dev_err_probe(dev, PTR_ERR(bc->regmap),
  159. "failed to init regmap\n");
  160. bc->domains = devm_kcalloc(dev, bc_data->num_domains,
  161. sizeof(struct imx8m_blk_ctrl_domain),
  162. GFP_KERNEL);
  163. if (!bc->domains)
  164. return -ENOMEM;
  165. bc->onecell_data.num_domains = bc_data->num_domains;
  166. bc->onecell_data.domains =
  167. devm_kcalloc(dev, bc_data->num_domains,
  168. sizeof(struct generic_pm_domain *), GFP_KERNEL);
  169. if (!bc->onecell_data.domains)
  170. return -ENOMEM;
  171. bc->bus_power_dev = genpd_dev_pm_attach_by_name(dev, "bus");
  172. if (IS_ERR(bc->bus_power_dev))
  173. return dev_err_probe(dev, PTR_ERR(bc->bus_power_dev),
  174. "failed to attach power domain \"bus\"\n");
  175. for (i = 0; i < bc_data->num_domains; i++) {
  176. const struct imx8m_blk_ctrl_domain_data *data = &bc_data->domains[i];
  177. struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
  178. int j;
  179. domain->data = data;
  180. domain->num_paths = data->num_paths;
  181. for (j = 0; j < data->num_clks; j++)
  182. domain->clks[j].id = data->clk_names[j];
  183. for (j = 0; j < data->num_paths; j++) {
  184. domain->paths[j].name = data->path_names[j];
  185. /* Fake value for now, just let ICC could configure NoC mode/priority */
  186. domain->paths[j].avg_bw = 1;
  187. domain->paths[j].peak_bw = 1;
  188. }
  189. ret = devm_of_icc_bulk_get(dev, data->num_paths, domain->paths);
  190. if (ret) {
  191. if (ret != -EPROBE_DEFER) {
  192. dev_warn_once(dev, "Could not get interconnect paths, NoC will stay unconfigured!\n");
  193. domain->num_paths = 0;
  194. } else {
  195. dev_err_probe(dev, ret, "failed to get noc entries\n");
  196. goto cleanup_pds;
  197. }
  198. }
  199. ret = devm_clk_bulk_get(dev, data->num_clks, domain->clks);
  200. if (ret) {
  201. dev_err_probe(dev, ret, "failed to get clock\n");
  202. goto cleanup_pds;
  203. }
  204. domain->power_dev =
  205. dev_pm_domain_attach_by_name(dev, data->gpc_name);
  206. if (IS_ERR(domain->power_dev)) {
  207. dev_err_probe(dev, PTR_ERR(domain->power_dev),
  208. "failed to attach power domain \"%s\"\n",
  209. data->gpc_name);
  210. ret = PTR_ERR(domain->power_dev);
  211. goto cleanup_pds;
  212. }
  213. domain->genpd.name = data->name;
  214. domain->genpd.power_on = imx8m_blk_ctrl_power_on;
  215. domain->genpd.power_off = imx8m_blk_ctrl_power_off;
  216. domain->bc = bc;
  217. ret = pm_genpd_init(&domain->genpd, NULL, true);
  218. if (ret) {
  219. dev_err_probe(dev, ret,
  220. "failed to init power domain \"%s\"\n",
  221. data->gpc_name);
  222. dev_pm_domain_detach(domain->power_dev, true);
  223. goto cleanup_pds;
  224. }
  225. /*
  226. * We use runtime PM to trigger power on/off of the upstream GPC
  227. * domain, as a strict hierarchical parent/child power domain
  228. * setup doesn't allow us to meet the sequencing requirements.
  229. * This means we have nested locking of genpd locks, without the
  230. * nesting being visible at the genpd level, so we need a
  231. * separate lock class to make lockdep aware of the fact that
  232. * this are separate domain locks that can be nested without a
  233. * self-deadlock.
  234. */
  235. lockdep_set_class(&domain->genpd.mlock,
  236. &blk_ctrl_genpd_lock_class);
  237. bc->onecell_data.domains[i] = &domain->genpd;
  238. }
  239. ret = of_genpd_add_provider_onecell(dev->of_node, &bc->onecell_data);
  240. if (ret) {
  241. dev_err_probe(dev, ret, "failed to add power domain provider\n");
  242. goto cleanup_pds;
  243. }
  244. bc->power_nb.notifier_call = bc_data->power_notifier_fn;
  245. ret = dev_pm_genpd_add_notifier(bc->bus_power_dev, &bc->power_nb);
  246. if (ret) {
  247. dev_err_probe(dev, ret, "failed to add power notifier\n");
  248. goto cleanup_provider;
  249. }
  250. dev_set_drvdata(dev, bc);
  251. return 0;
  252. cleanup_provider:
  253. of_genpd_del_provider(dev->of_node);
  254. cleanup_pds:
  255. for (i--; i >= 0; i--) {
  256. pm_genpd_remove(&bc->domains[i].genpd);
  257. dev_pm_domain_detach(bc->domains[i].power_dev, true);
  258. }
  259. dev_pm_domain_detach(bc->bus_power_dev, true);
  260. return ret;
  261. }
  262. static int imx8m_blk_ctrl_remove(struct platform_device *pdev)
  263. {
  264. struct imx8m_blk_ctrl *bc = dev_get_drvdata(&pdev->dev);
  265. int i;
  266. of_genpd_del_provider(pdev->dev.of_node);
  267. for (i = 0; bc->onecell_data.num_domains; i++) {
  268. struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
  269. pm_genpd_remove(&domain->genpd);
  270. dev_pm_domain_detach(domain->power_dev, true);
  271. }
  272. dev_pm_genpd_remove_notifier(bc->bus_power_dev);
  273. dev_pm_domain_detach(bc->bus_power_dev, true);
  274. return 0;
  275. }
  276. #ifdef CONFIG_PM_SLEEP
  277. static int imx8m_blk_ctrl_suspend(struct device *dev)
  278. {
  279. struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
  280. int ret, i;
  281. /*
  282. * This may look strange, but is done so the generic PM_SLEEP code
  283. * can power down our domains and more importantly power them up again
  284. * after resume, without tripping over our usage of runtime PM to
  285. * control the upstream GPC domains. Things happen in the right order
  286. * in the system suspend/resume paths due to the device parent/child
  287. * hierarchy.
  288. */
  289. ret = pm_runtime_get_sync(bc->bus_power_dev);
  290. if (ret < 0) {
  291. pm_runtime_put_noidle(bc->bus_power_dev);
  292. return ret;
  293. }
  294. for (i = 0; i < bc->onecell_data.num_domains; i++) {
  295. struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
  296. ret = pm_runtime_get_sync(domain->power_dev);
  297. if (ret < 0) {
  298. pm_runtime_put_noidle(domain->power_dev);
  299. goto out_fail;
  300. }
  301. }
  302. return 0;
  303. out_fail:
  304. for (i--; i >= 0; i--)
  305. pm_runtime_put(bc->domains[i].power_dev);
  306. pm_runtime_put(bc->bus_power_dev);
  307. return ret;
  308. }
  309. static int imx8m_blk_ctrl_resume(struct device *dev)
  310. {
  311. struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
  312. int i;
  313. for (i = 0; i < bc->onecell_data.num_domains; i++)
  314. pm_runtime_put(bc->domains[i].power_dev);
  315. pm_runtime_put(bc->bus_power_dev);
  316. return 0;
  317. }
  318. #endif
  319. static const struct dev_pm_ops imx8m_blk_ctrl_pm_ops = {
  320. SET_SYSTEM_SLEEP_PM_OPS(imx8m_blk_ctrl_suspend, imx8m_blk_ctrl_resume)
  321. };
  322. static int imx8mm_vpu_power_notifier(struct notifier_block *nb,
  323. unsigned long action, void *data)
  324. {
  325. struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
  326. power_nb);
  327. if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
  328. return NOTIFY_OK;
  329. /*
  330. * The ADB in the VPUMIX domain has no separate reset and clock
  331. * enable bits, but is ungated together with the VPU clocks. To
  332. * allow the handshake with the GPC to progress we put the VPUs
  333. * in reset and ungate the clocks.
  334. */
  335. regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1) | BIT(2));
  336. regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1) | BIT(2));
  337. if (action == GENPD_NOTIFY_ON) {
  338. /*
  339. * On power up we have no software backchannel to the GPC to
  340. * wait for the ADB handshake to happen, so we just delay for a
  341. * bit. On power down the GPC driver waits for the handshake.
  342. */
  343. udelay(5);
  344. /* set "fuse" bits to enable the VPUs */
  345. regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
  346. regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
  347. regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
  348. regmap_set_bits(bc->regmap, 0x14, 0xffffffff);
  349. }
  350. return NOTIFY_OK;
  351. }
  352. static const struct imx8m_blk_ctrl_domain_data imx8mm_vpu_blk_ctl_domain_data[] = {
  353. [IMX8MM_VPUBLK_PD_G1] = {
  354. .name = "vpublk-g1",
  355. .clk_names = (const char *[]){ "g1", },
  356. .num_clks = 1,
  357. .gpc_name = "g1",
  358. .rst_mask = BIT(1),
  359. .clk_mask = BIT(1),
  360. },
  361. [IMX8MM_VPUBLK_PD_G2] = {
  362. .name = "vpublk-g2",
  363. .clk_names = (const char *[]){ "g2", },
  364. .num_clks = 1,
  365. .gpc_name = "g2",
  366. .rst_mask = BIT(0),
  367. .clk_mask = BIT(0),
  368. },
  369. [IMX8MM_VPUBLK_PD_H1] = {
  370. .name = "vpublk-h1",
  371. .clk_names = (const char *[]){ "h1", },
  372. .num_clks = 1,
  373. .gpc_name = "h1",
  374. .rst_mask = BIT(2),
  375. .clk_mask = BIT(2),
  376. },
  377. };
  378. static const struct imx8m_blk_ctrl_data imx8mm_vpu_blk_ctl_dev_data = {
  379. .max_reg = 0x18,
  380. .power_notifier_fn = imx8mm_vpu_power_notifier,
  381. .domains = imx8mm_vpu_blk_ctl_domain_data,
  382. .num_domains = ARRAY_SIZE(imx8mm_vpu_blk_ctl_domain_data),
  383. };
  384. static const struct imx8m_blk_ctrl_domain_data imx8mp_vpu_blk_ctl_domain_data[] = {
  385. [IMX8MP_VPUBLK_PD_G1] = {
  386. .name = "vpublk-g1",
  387. .clk_names = (const char *[]){ "g1", },
  388. .num_clks = 1,
  389. .gpc_name = "g1",
  390. .rst_mask = BIT(1),
  391. .clk_mask = BIT(1),
  392. .path_names = (const char *[]){"g1"},
  393. .num_paths = 1,
  394. },
  395. [IMX8MP_VPUBLK_PD_G2] = {
  396. .name = "vpublk-g2",
  397. .clk_names = (const char *[]){ "g2", },
  398. .num_clks = 1,
  399. .gpc_name = "g2",
  400. .rst_mask = BIT(0),
  401. .clk_mask = BIT(0),
  402. .path_names = (const char *[]){"g2"},
  403. .num_paths = 1,
  404. },
  405. [IMX8MP_VPUBLK_PD_VC8000E] = {
  406. .name = "vpublk-vc8000e",
  407. .clk_names = (const char *[]){ "vc8000e", },
  408. .num_clks = 1,
  409. .gpc_name = "vc8000e",
  410. .rst_mask = BIT(2),
  411. .clk_mask = BIT(2),
  412. .path_names = (const char *[]){"vc8000e"},
  413. .num_paths = 1,
  414. },
  415. };
  416. static const struct imx8m_blk_ctrl_data imx8mp_vpu_blk_ctl_dev_data = {
  417. .max_reg = 0x18,
  418. .power_notifier_fn = imx8mm_vpu_power_notifier,
  419. .domains = imx8mp_vpu_blk_ctl_domain_data,
  420. .num_domains = ARRAY_SIZE(imx8mp_vpu_blk_ctl_domain_data),
  421. };
  422. static int imx8mm_disp_power_notifier(struct notifier_block *nb,
  423. unsigned long action, void *data)
  424. {
  425. struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
  426. power_nb);
  427. if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
  428. return NOTIFY_OK;
  429. /* Enable bus clock and deassert bus reset */
  430. regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(12));
  431. regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(6));
  432. /*
  433. * On power up we have no software backchannel to the GPC to
  434. * wait for the ADB handshake to happen, so we just delay for a
  435. * bit. On power down the GPC driver waits for the handshake.
  436. */
  437. if (action == GENPD_NOTIFY_ON)
  438. udelay(5);
  439. return NOTIFY_OK;
  440. }
  441. static const struct imx8m_blk_ctrl_domain_data imx8mm_disp_blk_ctl_domain_data[] = {
  442. [IMX8MM_DISPBLK_PD_CSI_BRIDGE] = {
  443. .name = "dispblk-csi-bridge",
  444. .clk_names = (const char *[]){ "csi-bridge-axi", "csi-bridge-apb",
  445. "csi-bridge-core", },
  446. .num_clks = 3,
  447. .gpc_name = "csi-bridge",
  448. .rst_mask = BIT(0) | BIT(1) | BIT(2),
  449. .clk_mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5),
  450. },
  451. [IMX8MM_DISPBLK_PD_LCDIF] = {
  452. .name = "dispblk-lcdif",
  453. .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
  454. .num_clks = 3,
  455. .gpc_name = "lcdif",
  456. .clk_mask = BIT(6) | BIT(7),
  457. },
  458. [IMX8MM_DISPBLK_PD_MIPI_DSI] = {
  459. .name = "dispblk-mipi-dsi",
  460. .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
  461. .num_clks = 2,
  462. .gpc_name = "mipi-dsi",
  463. .rst_mask = BIT(5),
  464. .clk_mask = BIT(8) | BIT(9),
  465. .mipi_phy_rst_mask = BIT(17),
  466. },
  467. [IMX8MM_DISPBLK_PD_MIPI_CSI] = {
  468. .name = "dispblk-mipi-csi",
  469. .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
  470. .num_clks = 2,
  471. .gpc_name = "mipi-csi",
  472. .rst_mask = BIT(3) | BIT(4),
  473. .clk_mask = BIT(10) | BIT(11),
  474. .mipi_phy_rst_mask = BIT(16),
  475. },
  476. };
  477. static const struct imx8m_blk_ctrl_data imx8mm_disp_blk_ctl_dev_data = {
  478. .max_reg = 0x2c,
  479. .power_notifier_fn = imx8mm_disp_power_notifier,
  480. .domains = imx8mm_disp_blk_ctl_domain_data,
  481. .num_domains = ARRAY_SIZE(imx8mm_disp_blk_ctl_domain_data),
  482. };
  483. static int imx8mn_disp_power_notifier(struct notifier_block *nb,
  484. unsigned long action, void *data)
  485. {
  486. struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
  487. power_nb);
  488. if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
  489. return NOTIFY_OK;
  490. /* Enable bus clock and deassert bus reset */
  491. regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
  492. regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
  493. /*
  494. * On power up we have no software backchannel to the GPC to
  495. * wait for the ADB handshake to happen, so we just delay for a
  496. * bit. On power down the GPC driver waits for the handshake.
  497. */
  498. if (action == GENPD_NOTIFY_ON)
  499. udelay(5);
  500. return NOTIFY_OK;
  501. }
  502. static const struct imx8m_blk_ctrl_domain_data imx8mn_disp_blk_ctl_domain_data[] = {
  503. [IMX8MN_DISPBLK_PD_MIPI_DSI] = {
  504. .name = "dispblk-mipi-dsi",
  505. .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
  506. .num_clks = 2,
  507. .gpc_name = "mipi-dsi",
  508. .rst_mask = BIT(0) | BIT(1),
  509. .clk_mask = BIT(0) | BIT(1),
  510. .mipi_phy_rst_mask = BIT(17),
  511. },
  512. [IMX8MN_DISPBLK_PD_MIPI_CSI] = {
  513. .name = "dispblk-mipi-csi",
  514. .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
  515. .num_clks = 2,
  516. .gpc_name = "mipi-csi",
  517. .rst_mask = BIT(2) | BIT(3),
  518. .clk_mask = BIT(2) | BIT(3),
  519. .mipi_phy_rst_mask = BIT(16),
  520. },
  521. [IMX8MN_DISPBLK_PD_LCDIF] = {
  522. .name = "dispblk-lcdif",
  523. .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
  524. .num_clks = 3,
  525. .gpc_name = "lcdif",
  526. .rst_mask = BIT(4) | BIT(5),
  527. .clk_mask = BIT(4) | BIT(5),
  528. },
  529. [IMX8MN_DISPBLK_PD_ISI] = {
  530. .name = "dispblk-isi",
  531. .clk_names = (const char *[]){ "disp_axi", "disp_apb", "disp_axi_root",
  532. "disp_apb_root"},
  533. .num_clks = 4,
  534. .gpc_name = "isi",
  535. .rst_mask = BIT(6) | BIT(7),
  536. .clk_mask = BIT(6) | BIT(7),
  537. },
  538. };
  539. static const struct imx8m_blk_ctrl_data imx8mn_disp_blk_ctl_dev_data = {
  540. .max_reg = 0x84,
  541. .power_notifier_fn = imx8mn_disp_power_notifier,
  542. .domains = imx8mn_disp_blk_ctl_domain_data,
  543. .num_domains = ARRAY_SIZE(imx8mn_disp_blk_ctl_domain_data),
  544. };
  545. static int imx8mp_media_power_notifier(struct notifier_block *nb,
  546. unsigned long action, void *data)
  547. {
  548. struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
  549. power_nb);
  550. if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
  551. return NOTIFY_OK;
  552. /* Enable bus clock and deassert bus reset */
  553. regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
  554. regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
  555. /*
  556. * On power up we have no software backchannel to the GPC to
  557. * wait for the ADB handshake to happen, so we just delay for a
  558. * bit. On power down the GPC driver waits for the handshake.
  559. */
  560. if (action == GENPD_NOTIFY_ON)
  561. udelay(5);
  562. return NOTIFY_OK;
  563. }
  564. /*
  565. * From i.MX 8M Plus Applications Processor Reference Manual, Rev. 1,
  566. * section 13.2.2, 13.2.3
  567. * isp-ahb and dwe are not in Figure 13-5. Media BLK_CTRL Clocks
  568. */
  569. static const struct imx8m_blk_ctrl_domain_data imx8mp_media_blk_ctl_domain_data[] = {
  570. [IMX8MP_MEDIABLK_PD_MIPI_DSI_1] = {
  571. .name = "mediablk-mipi-dsi-1",
  572. .clk_names = (const char *[]){ "apb", "phy", },
  573. .num_clks = 2,
  574. .gpc_name = "mipi-dsi1",
  575. .rst_mask = BIT(0) | BIT(1),
  576. .clk_mask = BIT(0) | BIT(1),
  577. .mipi_phy_rst_mask = BIT(17),
  578. },
  579. [IMX8MP_MEDIABLK_PD_MIPI_CSI2_1] = {
  580. .name = "mediablk-mipi-csi2-1",
  581. .clk_names = (const char *[]){ "apb", "cam1" },
  582. .num_clks = 2,
  583. .gpc_name = "mipi-csi1",
  584. .rst_mask = BIT(2) | BIT(3),
  585. .clk_mask = BIT(2) | BIT(3),
  586. .mipi_phy_rst_mask = BIT(16),
  587. },
  588. [IMX8MP_MEDIABLK_PD_LCDIF_1] = {
  589. .name = "mediablk-lcdif-1",
  590. .clk_names = (const char *[]){ "disp1", "apb", "axi", },
  591. .num_clks = 3,
  592. .gpc_name = "lcdif1",
  593. .rst_mask = BIT(4) | BIT(5) | BIT(23),
  594. .clk_mask = BIT(4) | BIT(5) | BIT(23),
  595. .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
  596. .num_paths = 2,
  597. },
  598. [IMX8MP_MEDIABLK_PD_ISI] = {
  599. .name = "mediablk-isi",
  600. .clk_names = (const char *[]){ "axi", "apb" },
  601. .num_clks = 2,
  602. .gpc_name = "isi",
  603. .rst_mask = BIT(6) | BIT(7),
  604. .clk_mask = BIT(6) | BIT(7),
  605. .path_names = (const char *[]){"isi0", "isi1", "isi2"},
  606. .num_paths = 3,
  607. },
  608. [IMX8MP_MEDIABLK_PD_MIPI_CSI2_2] = {
  609. .name = "mediablk-mipi-csi2-2",
  610. .clk_names = (const char *[]){ "apb", "cam2" },
  611. .num_clks = 2,
  612. .gpc_name = "mipi-csi2",
  613. .rst_mask = BIT(9) | BIT(10),
  614. .clk_mask = BIT(9) | BIT(10),
  615. .mipi_phy_rst_mask = BIT(30),
  616. },
  617. [IMX8MP_MEDIABLK_PD_LCDIF_2] = {
  618. .name = "mediablk-lcdif-2",
  619. .clk_names = (const char *[]){ "disp2", "apb", "axi", },
  620. .num_clks = 3,
  621. .gpc_name = "lcdif2",
  622. .rst_mask = BIT(11) | BIT(12) | BIT(24),
  623. .clk_mask = BIT(11) | BIT(12) | BIT(24),
  624. .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
  625. .num_paths = 2,
  626. },
  627. [IMX8MP_MEDIABLK_PD_ISP] = {
  628. .name = "mediablk-isp",
  629. .clk_names = (const char *[]){ "isp", "axi", "apb" },
  630. .num_clks = 3,
  631. .gpc_name = "isp",
  632. .rst_mask = BIT(16) | BIT(17) | BIT(18),
  633. .clk_mask = BIT(16) | BIT(17) | BIT(18),
  634. .path_names = (const char *[]){"isp0", "isp1"},
  635. .num_paths = 2,
  636. },
  637. [IMX8MP_MEDIABLK_PD_DWE] = {
  638. .name = "mediablk-dwe",
  639. .clk_names = (const char *[]){ "axi", "apb" },
  640. .num_clks = 2,
  641. .gpc_name = "dwe",
  642. .rst_mask = BIT(19) | BIT(20) | BIT(21),
  643. .clk_mask = BIT(19) | BIT(20) | BIT(21),
  644. .path_names = (const char *[]){"dwe"},
  645. .num_paths = 1,
  646. },
  647. [IMX8MP_MEDIABLK_PD_MIPI_DSI_2] = {
  648. .name = "mediablk-mipi-dsi-2",
  649. .clk_names = (const char *[]){ "phy", },
  650. .num_clks = 1,
  651. .gpc_name = "mipi-dsi2",
  652. .rst_mask = BIT(22),
  653. .clk_mask = BIT(22),
  654. .mipi_phy_rst_mask = BIT(29),
  655. },
  656. };
  657. static const struct imx8m_blk_ctrl_data imx8mp_media_blk_ctl_dev_data = {
  658. .max_reg = 0x138,
  659. .power_notifier_fn = imx8mp_media_power_notifier,
  660. .domains = imx8mp_media_blk_ctl_domain_data,
  661. .num_domains = ARRAY_SIZE(imx8mp_media_blk_ctl_domain_data),
  662. };
  663. static int imx8mq_vpu_power_notifier(struct notifier_block *nb,
  664. unsigned long action, void *data)
  665. {
  666. struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
  667. power_nb);
  668. if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
  669. return NOTIFY_OK;
  670. /*
  671. * The ADB in the VPUMIX domain has no separate reset and clock
  672. * enable bits, but is ungated and reset together with the VPUs. The
  673. * reset and clock enable inputs to the ADB is a logical OR of the
  674. * VPU bits. In order to set the G2 fuse bits, the G2 clock must
  675. * also be enabled.
  676. */
  677. regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1));
  678. regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1));
  679. if (action == GENPD_NOTIFY_ON) {
  680. /*
  681. * On power up we have no software backchannel to the GPC to
  682. * wait for the ADB handshake to happen, so we just delay for a
  683. * bit. On power down the GPC driver waits for the handshake.
  684. */
  685. udelay(5);
  686. /* set "fuse" bits to enable the VPUs */
  687. regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
  688. regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
  689. regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
  690. }
  691. return NOTIFY_OK;
  692. }
  693. static const struct imx8m_blk_ctrl_domain_data imx8mq_vpu_blk_ctl_domain_data[] = {
  694. [IMX8MQ_VPUBLK_PD_G1] = {
  695. .name = "vpublk-g1",
  696. .clk_names = (const char *[]){ "g1", },
  697. .num_clks = 1,
  698. .gpc_name = "g1",
  699. .rst_mask = BIT(1),
  700. .clk_mask = BIT(1),
  701. },
  702. [IMX8MQ_VPUBLK_PD_G2] = {
  703. .name = "vpublk-g2",
  704. .clk_names = (const char *[]){ "g2", },
  705. .num_clks = 1,
  706. .gpc_name = "g2",
  707. .rst_mask = BIT(0),
  708. .clk_mask = BIT(0),
  709. },
  710. };
  711. static const struct imx8m_blk_ctrl_data imx8mq_vpu_blk_ctl_dev_data = {
  712. .max_reg = 0x14,
  713. .power_notifier_fn = imx8mq_vpu_power_notifier,
  714. .domains = imx8mq_vpu_blk_ctl_domain_data,
  715. .num_domains = ARRAY_SIZE(imx8mq_vpu_blk_ctl_domain_data),
  716. };
  717. static const struct of_device_id imx8m_blk_ctrl_of_match[] = {
  718. {
  719. .compatible = "fsl,imx8mm-vpu-blk-ctrl",
  720. .data = &imx8mm_vpu_blk_ctl_dev_data
  721. }, {
  722. .compatible = "fsl,imx8mm-disp-blk-ctrl",
  723. .data = &imx8mm_disp_blk_ctl_dev_data
  724. }, {
  725. .compatible = "fsl,imx8mn-disp-blk-ctrl",
  726. .data = &imx8mn_disp_blk_ctl_dev_data
  727. }, {
  728. .compatible = "fsl,imx8mp-media-blk-ctrl",
  729. .data = &imx8mp_media_blk_ctl_dev_data
  730. }, {
  731. .compatible = "fsl,imx8mq-vpu-blk-ctrl",
  732. .data = &imx8mq_vpu_blk_ctl_dev_data
  733. }, {
  734. .compatible = "fsl,imx8mp-vpu-blk-ctrl",
  735. .data = &imx8mp_vpu_blk_ctl_dev_data
  736. }, {
  737. /* Sentinel */
  738. }
  739. };
  740. MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
  741. static struct platform_driver imx8m_blk_ctrl_driver = {
  742. .probe = imx8m_blk_ctrl_probe,
  743. .remove = imx8m_blk_ctrl_remove,
  744. .driver = {
  745. .name = "imx8m-blk-ctrl",
  746. .pm = &imx8m_blk_ctrl_pm_ops,
  747. .of_match_table = imx8m_blk_ctrl_of_match,
  748. },
  749. };
  750. module_platform_driver(imx8m_blk_ctrl_driver);