1 // SPDX-License-Identifier: GPL-2.0+
7 #include <linux/device.h>
8 #include <linux/interconnect.h>
9 #include <linux/module.h>
10 #include <linux/of_device.h>
11 #include <linux/platform_device.h>
12 #include <linux/pm_domain.h>
13 #include <linux/pm_runtime.h>
14 #include <linux/regmap.h>
15 #include <linux/clk.h>
17 #include <dt-bindings/power/imx8mm-power.h>
18 #include <dt-bindings/power/imx8mn-power.h>
19 #include <dt-bindings/power/imx8mp-power.h>
20 #include <dt-bindings/power/imx8mq-power.h>
22 #define BLK_SFT_RSTN 0x0
23 #define BLK_CLK_EN 0x4
24 #define BLK_MIPI_RESET_DIV 0x8 /* Mini/Nano/Plus DISPLAY_BLK_CTRL only */
26 struct imx8m_blk_ctrl_domain;
28 struct imx8m_blk_ctrl {
30 struct notifier_block power_nb;
31 struct device *bus_power_dev;
32 struct regmap *regmap;
33 struct imx8m_blk_ctrl_domain *domains;
34 struct genpd_onecell_data onecell_data;
37 struct imx8m_blk_ctrl_domain_data {
39 const char * const *clk_names;
41 const char * const *path_names;
48 * i.MX8M Mini, Nano and Plus have a third DISPLAY_BLK_CTRL register
49 * which is used to control the reset for the MIPI Phy.
50 * Since it's only present in certain circumstances,
51 * an if-statement should be used before setting and clearing this
54 u32 mipi_phy_rst_mask;
57 #define DOMAIN_MAX_CLKS 4
58 #define DOMAIN_MAX_PATHS 4
60 struct imx8m_blk_ctrl_domain {
61 struct generic_pm_domain genpd;
62 const struct imx8m_blk_ctrl_domain_data *data;
63 struct clk_bulk_data clks[DOMAIN_MAX_CLKS];
64 struct icc_bulk_data paths[DOMAIN_MAX_PATHS];
65 struct device *power_dev;
66 struct imx8m_blk_ctrl *bc;
70 struct imx8m_blk_ctrl_data {
72 notifier_fn_t power_notifier_fn;
73 const struct imx8m_blk_ctrl_domain_data *domains;
77 static inline struct imx8m_blk_ctrl_domain *
78 to_imx8m_blk_ctrl_domain(struct generic_pm_domain *genpd)
80 return container_of(genpd, struct imx8m_blk_ctrl_domain, genpd);
83 static int imx8m_blk_ctrl_power_on(struct generic_pm_domain *genpd)
85 struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
86 const struct imx8m_blk_ctrl_domain_data *data = domain->data;
87 struct imx8m_blk_ctrl *bc = domain->bc;
90 /* make sure bus domain is awake */
91 ret = pm_runtime_get_sync(bc->bus_power_dev);
93 pm_runtime_put_noidle(bc->bus_power_dev);
94 dev_err(bc->dev, "failed to power up bus domain\n");
98 /* put devices into reset */
99 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
100 if (data->mipi_phy_rst_mask)
101 regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
103 /* enable upstream and blk-ctrl clocks to allow reset to propagate */
104 ret = clk_bulk_prepare_enable(data->num_clks, domain->clks);
106 dev_err(bc->dev, "failed to enable clocks\n");
109 regmap_set_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
111 /* power up upstream GPC domain */
112 ret = pm_runtime_get_sync(domain->power_dev);
114 dev_err(bc->dev, "failed to power up peripheral domain\n");
118 /* wait for reset to propagate */
122 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
123 if (data->mipi_phy_rst_mask)
124 regmap_set_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
126 ret = icc_bulk_set_bw(domain->num_paths, domain->paths);
128 dev_err(bc->dev, "failed to set icc bw\n");
130 /* disable upstream clocks */
131 clk_bulk_disable_unprepare(data->num_clks, domain->clks);
136 clk_bulk_disable_unprepare(data->num_clks, domain->clks);
138 pm_runtime_put(bc->bus_power_dev);
143 static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
145 struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
146 const struct imx8m_blk_ctrl_domain_data *data = domain->data;
147 struct imx8m_blk_ctrl *bc = domain->bc;
149 /* put devices into reset and disable clocks */
150 if (data->mipi_phy_rst_mask)
151 regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
153 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
154 regmap_clear_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
156 /* power down upstream GPC domain */
157 pm_runtime_put(domain->power_dev);
159 /* allow bus domain to suspend */
160 pm_runtime_put(bc->bus_power_dev);
165 static struct lock_class_key blk_ctrl_genpd_lock_class;
167 static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
169 const struct imx8m_blk_ctrl_data *bc_data;
170 struct device *dev = &pdev->dev;
171 struct imx8m_blk_ctrl *bc;
175 struct regmap_config regmap_config = {
181 bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL);
187 bc_data = of_device_get_match_data(dev);
189 base = devm_platform_ioremap_resource(pdev, 0);
191 return PTR_ERR(base);
193 regmap_config.max_register = bc_data->max_reg;
194 bc->regmap = devm_regmap_init_mmio(dev, base, ®map_config);
195 if (IS_ERR(bc->regmap))
196 return dev_err_probe(dev, PTR_ERR(bc->regmap),
197 "failed to init regmap\n");
199 bc->domains = devm_kcalloc(dev, bc_data->num_domains,
200 sizeof(struct imx8m_blk_ctrl_domain),
205 bc->onecell_data.num_domains = bc_data->num_domains;
206 bc->onecell_data.domains =
207 devm_kcalloc(dev, bc_data->num_domains,
208 sizeof(struct generic_pm_domain *), GFP_KERNEL);
209 if (!bc->onecell_data.domains)
212 bc->bus_power_dev = genpd_dev_pm_attach_by_name(dev, "bus");
213 if (IS_ERR(bc->bus_power_dev)) {
214 if (PTR_ERR(bc->bus_power_dev) == -ENODEV)
215 return dev_err_probe(dev, -EPROBE_DEFER,
216 "failed to attach power domain \"bus\"\n");
218 return dev_err_probe(dev, PTR_ERR(bc->bus_power_dev),
219 "failed to attach power domain \"bus\"\n");
222 for (i = 0; i < bc_data->num_domains; i++) {
223 const struct imx8m_blk_ctrl_domain_data *data = &bc_data->domains[i];
224 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
228 domain->num_paths = data->num_paths;
230 for (j = 0; j < data->num_clks; j++)
231 domain->clks[j].id = data->clk_names[j];
233 for (j = 0; j < data->num_paths; j++) {
234 domain->paths[j].name = data->path_names[j];
235 /* Fake value for now, just let ICC could configure NoC mode/priority */
236 domain->paths[j].avg_bw = 1;
237 domain->paths[j].peak_bw = 1;
240 ret = devm_of_icc_bulk_get(dev, data->num_paths, domain->paths);
242 if (ret != -EPROBE_DEFER) {
243 dev_warn_once(dev, "Could not get interconnect paths, NoC will stay unconfigured!\n");
244 domain->num_paths = 0;
246 dev_err_probe(dev, ret, "failed to get noc entries\n");
251 ret = devm_clk_bulk_get(dev, data->num_clks, domain->clks);
253 dev_err_probe(dev, ret, "failed to get clock\n");
258 dev_pm_domain_attach_by_name(dev, data->gpc_name);
259 if (IS_ERR(domain->power_dev)) {
260 dev_err_probe(dev, PTR_ERR(domain->power_dev),
261 "failed to attach power domain \"%s\"\n",
263 ret = PTR_ERR(domain->power_dev);
267 domain->genpd.name = data->name;
268 domain->genpd.power_on = imx8m_blk_ctrl_power_on;
269 domain->genpd.power_off = imx8m_blk_ctrl_power_off;
272 ret = pm_genpd_init(&domain->genpd, NULL, true);
274 dev_err_probe(dev, ret,
275 "failed to init power domain \"%s\"\n",
277 dev_pm_domain_detach(domain->power_dev, true);
282 * We use runtime PM to trigger power on/off of the upstream GPC
283 * domain, as a strict hierarchical parent/child power domain
284 * setup doesn't allow us to meet the sequencing requirements.
285 * This means we have nested locking of genpd locks, without the
286 * nesting being visible at the genpd level, so we need a
287 * separate lock class to make lockdep aware of the fact that
288 * this are separate domain locks that can be nested without a
291 lockdep_set_class(&domain->genpd.mlock,
292 &blk_ctrl_genpd_lock_class);
294 bc->onecell_data.domains[i] = &domain->genpd;
297 ret = of_genpd_add_provider_onecell(dev->of_node, &bc->onecell_data);
299 dev_err_probe(dev, ret, "failed to add power domain provider\n");
303 bc->power_nb.notifier_call = bc_data->power_notifier_fn;
304 ret = dev_pm_genpd_add_notifier(bc->bus_power_dev, &bc->power_nb);
306 dev_err_probe(dev, ret, "failed to add power notifier\n");
307 goto cleanup_provider;
310 dev_set_drvdata(dev, bc);
315 of_genpd_del_provider(dev->of_node);
317 for (i--; i >= 0; i--) {
318 pm_genpd_remove(&bc->domains[i].genpd);
319 dev_pm_domain_detach(bc->domains[i].power_dev, true);
322 dev_pm_domain_detach(bc->bus_power_dev, true);
327 static int imx8m_blk_ctrl_remove(struct platform_device *pdev)
329 struct imx8m_blk_ctrl *bc = dev_get_drvdata(&pdev->dev);
332 of_genpd_del_provider(pdev->dev.of_node);
334 for (i = 0; bc->onecell_data.num_domains; i++) {
335 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
337 pm_genpd_remove(&domain->genpd);
338 dev_pm_domain_detach(domain->power_dev, true);
341 dev_pm_genpd_remove_notifier(bc->bus_power_dev);
343 dev_pm_domain_detach(bc->bus_power_dev, true);
348 #ifdef CONFIG_PM_SLEEP
349 static int imx8m_blk_ctrl_suspend(struct device *dev)
351 struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
355 * This may look strange, but is done so the generic PM_SLEEP code
356 * can power down our domains and more importantly power them up again
357 * after resume, without tripping over our usage of runtime PM to
358 * control the upstream GPC domains. Things happen in the right order
359 * in the system suspend/resume paths due to the device parent/child
362 ret = pm_runtime_get_sync(bc->bus_power_dev);
364 pm_runtime_put_noidle(bc->bus_power_dev);
368 for (i = 0; i < bc->onecell_data.num_domains; i++) {
369 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
371 ret = pm_runtime_get_sync(domain->power_dev);
373 pm_runtime_put_noidle(domain->power_dev);
381 for (i--; i >= 0; i--)
382 pm_runtime_put(bc->domains[i].power_dev);
384 pm_runtime_put(bc->bus_power_dev);
389 static int imx8m_blk_ctrl_resume(struct device *dev)
391 struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
394 for (i = 0; i < bc->onecell_data.num_domains; i++)
395 pm_runtime_put(bc->domains[i].power_dev);
397 pm_runtime_put(bc->bus_power_dev);
403 static const struct dev_pm_ops imx8m_blk_ctrl_pm_ops = {
404 SET_SYSTEM_SLEEP_PM_OPS(imx8m_blk_ctrl_suspend, imx8m_blk_ctrl_resume)
407 static int imx8mm_vpu_power_notifier(struct notifier_block *nb,
408 unsigned long action, void *data)
410 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
413 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
417 * The ADB in the VPUMIX domain has no separate reset and clock
418 * enable bits, but is ungated together with the VPU clocks. To
419 * allow the handshake with the GPC to progress we put the VPUs
420 * in reset and ungate the clocks.
422 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1) | BIT(2));
423 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1) | BIT(2));
425 if (action == GENPD_NOTIFY_ON) {
427 * On power up we have no software backchannel to the GPC to
428 * wait for the ADB handshake to happen, so we just delay for a
429 * bit. On power down the GPC driver waits for the handshake.
433 /* set "fuse" bits to enable the VPUs */
434 regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
435 regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
436 regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
437 regmap_set_bits(bc->regmap, 0x14, 0xffffffff);
443 static const struct imx8m_blk_ctrl_domain_data imx8mm_vpu_blk_ctl_domain_data[] = {
444 [IMX8MM_VPUBLK_PD_G1] = {
446 .clk_names = (const char *[]){ "g1", },
452 [IMX8MM_VPUBLK_PD_G2] = {
454 .clk_names = (const char *[]){ "g2", },
460 [IMX8MM_VPUBLK_PD_H1] = {
462 .clk_names = (const char *[]){ "h1", },
470 static const struct imx8m_blk_ctrl_data imx8mm_vpu_blk_ctl_dev_data = {
472 .power_notifier_fn = imx8mm_vpu_power_notifier,
473 .domains = imx8mm_vpu_blk_ctl_domain_data,
474 .num_domains = ARRAY_SIZE(imx8mm_vpu_blk_ctl_domain_data),
477 static const struct imx8m_blk_ctrl_domain_data imx8mp_vpu_blk_ctl_domain_data[] = {
478 [IMX8MP_VPUBLK_PD_G1] = {
480 .clk_names = (const char *[]){ "g1", },
485 .path_names = (const char *[]){"g1"},
488 [IMX8MP_VPUBLK_PD_G2] = {
490 .clk_names = (const char *[]){ "g2", },
495 .path_names = (const char *[]){"g2"},
498 [IMX8MP_VPUBLK_PD_VC8000E] = {
499 .name = "vpublk-vc8000e",
500 .clk_names = (const char *[]){ "vc8000e", },
502 .gpc_name = "vc8000e",
505 .path_names = (const char *[]){"vc8000e"},
510 static const struct imx8m_blk_ctrl_data imx8mp_vpu_blk_ctl_dev_data = {
512 .power_notifier_fn = imx8mm_vpu_power_notifier,
513 .domains = imx8mp_vpu_blk_ctl_domain_data,
514 .num_domains = ARRAY_SIZE(imx8mp_vpu_blk_ctl_domain_data),
517 static int imx8mm_disp_power_notifier(struct notifier_block *nb,
518 unsigned long action, void *data)
520 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
523 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
526 /* Enable bus clock and deassert bus reset */
527 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(12));
528 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(6));
531 * On power up we have no software backchannel to the GPC to
532 * wait for the ADB handshake to happen, so we just delay for a
533 * bit. On power down the GPC driver waits for the handshake.
535 if (action == GENPD_NOTIFY_ON)
542 static const struct imx8m_blk_ctrl_domain_data imx8mm_disp_blk_ctl_domain_data[] = {
543 [IMX8MM_DISPBLK_PD_CSI_BRIDGE] = {
544 .name = "dispblk-csi-bridge",
545 .clk_names = (const char *[]){ "csi-bridge-axi", "csi-bridge-apb",
546 "csi-bridge-core", },
548 .gpc_name = "csi-bridge",
549 .rst_mask = BIT(0) | BIT(1) | BIT(2),
550 .clk_mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5),
552 [IMX8MM_DISPBLK_PD_LCDIF] = {
553 .name = "dispblk-lcdif",
554 .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
557 .clk_mask = BIT(6) | BIT(7),
559 [IMX8MM_DISPBLK_PD_MIPI_DSI] = {
560 .name = "dispblk-mipi-dsi",
561 .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
563 .gpc_name = "mipi-dsi",
565 .clk_mask = BIT(8) | BIT(9),
566 .mipi_phy_rst_mask = BIT(17),
568 [IMX8MM_DISPBLK_PD_MIPI_CSI] = {
569 .name = "dispblk-mipi-csi",
570 .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
572 .gpc_name = "mipi-csi",
573 .rst_mask = BIT(3) | BIT(4),
574 .clk_mask = BIT(10) | BIT(11),
575 .mipi_phy_rst_mask = BIT(16),
579 static const struct imx8m_blk_ctrl_data imx8mm_disp_blk_ctl_dev_data = {
581 .power_notifier_fn = imx8mm_disp_power_notifier,
582 .domains = imx8mm_disp_blk_ctl_domain_data,
583 .num_domains = ARRAY_SIZE(imx8mm_disp_blk_ctl_domain_data),
587 static int imx8mn_disp_power_notifier(struct notifier_block *nb,
588 unsigned long action, void *data)
590 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
593 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
596 /* Enable bus clock and deassert bus reset */
597 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
598 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
601 * On power up we have no software backchannel to the GPC to
602 * wait for the ADB handshake to happen, so we just delay for a
603 * bit. On power down the GPC driver waits for the handshake.
605 if (action == GENPD_NOTIFY_ON)
612 static const struct imx8m_blk_ctrl_domain_data imx8mn_disp_blk_ctl_domain_data[] = {
613 [IMX8MN_DISPBLK_PD_MIPI_DSI] = {
614 .name = "dispblk-mipi-dsi",
615 .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
617 .gpc_name = "mipi-dsi",
618 .rst_mask = BIT(0) | BIT(1),
619 .clk_mask = BIT(0) | BIT(1),
620 .mipi_phy_rst_mask = BIT(17),
622 [IMX8MN_DISPBLK_PD_MIPI_CSI] = {
623 .name = "dispblk-mipi-csi",
624 .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
626 .gpc_name = "mipi-csi",
627 .rst_mask = BIT(2) | BIT(3),
628 .clk_mask = BIT(2) | BIT(3),
629 .mipi_phy_rst_mask = BIT(16),
631 [IMX8MN_DISPBLK_PD_LCDIF] = {
632 .name = "dispblk-lcdif",
633 .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
636 .rst_mask = BIT(4) | BIT(5),
637 .clk_mask = BIT(4) | BIT(5),
639 [IMX8MN_DISPBLK_PD_ISI] = {
640 .name = "dispblk-isi",
641 .clk_names = (const char *[]){ "disp_axi", "disp_apb", "disp_axi_root",
645 .rst_mask = BIT(6) | BIT(7),
646 .clk_mask = BIT(6) | BIT(7),
650 static const struct imx8m_blk_ctrl_data imx8mn_disp_blk_ctl_dev_data = {
652 .power_notifier_fn = imx8mn_disp_power_notifier,
653 .domains = imx8mn_disp_blk_ctl_domain_data,
654 .num_domains = ARRAY_SIZE(imx8mn_disp_blk_ctl_domain_data),
657 static int imx8mp_media_power_notifier(struct notifier_block *nb,
658 unsigned long action, void *data)
660 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
663 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
666 /* Enable bus clock and deassert bus reset */
667 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
668 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
671 * On power up we have no software backchannel to the GPC to
672 * wait for the ADB handshake to happen, so we just delay for a
673 * bit. On power down the GPC driver waits for the handshake.
675 if (action == GENPD_NOTIFY_ON)
682 * From i.MX 8M Plus Applications Processor Reference Manual, Rev. 1,
683 * section 13.2.2, 13.2.3
684 * isp-ahb and dwe are not in Figure 13-5. Media BLK_CTRL Clocks
686 static const struct imx8m_blk_ctrl_domain_data imx8mp_media_blk_ctl_domain_data[] = {
687 [IMX8MP_MEDIABLK_PD_MIPI_DSI_1] = {
688 .name = "mediablk-mipi-dsi-1",
689 .clk_names = (const char *[]){ "apb", "phy", },
691 .gpc_name = "mipi-dsi1",
692 .rst_mask = BIT(0) | BIT(1),
693 .clk_mask = BIT(0) | BIT(1),
694 .mipi_phy_rst_mask = BIT(17),
696 [IMX8MP_MEDIABLK_PD_MIPI_CSI2_1] = {
697 .name = "mediablk-mipi-csi2-1",
698 .clk_names = (const char *[]){ "apb", "cam1" },
700 .gpc_name = "mipi-csi1",
701 .rst_mask = BIT(2) | BIT(3),
702 .clk_mask = BIT(2) | BIT(3),
703 .mipi_phy_rst_mask = BIT(16),
705 [IMX8MP_MEDIABLK_PD_LCDIF_1] = {
706 .name = "mediablk-lcdif-1",
707 .clk_names = (const char *[]){ "disp1", "apb", "axi", },
709 .gpc_name = "lcdif1",
710 .rst_mask = BIT(4) | BIT(5) | BIT(23),
711 .clk_mask = BIT(4) | BIT(5) | BIT(23),
712 .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
715 [IMX8MP_MEDIABLK_PD_ISI] = {
716 .name = "mediablk-isi",
717 .clk_names = (const char *[]){ "axi", "apb" },
720 .rst_mask = BIT(6) | BIT(7),
721 .clk_mask = BIT(6) | BIT(7),
722 .path_names = (const char *[]){"isi0", "isi1", "isi2"},
725 [IMX8MP_MEDIABLK_PD_MIPI_CSI2_2] = {
726 .name = "mediablk-mipi-csi2-2",
727 .clk_names = (const char *[]){ "apb", "cam2" },
729 .gpc_name = "mipi-csi2",
730 .rst_mask = BIT(9) | BIT(10),
731 .clk_mask = BIT(9) | BIT(10),
732 .mipi_phy_rst_mask = BIT(30),
734 [IMX8MP_MEDIABLK_PD_LCDIF_2] = {
735 .name = "mediablk-lcdif-2",
736 .clk_names = (const char *[]){ "disp2", "apb", "axi", },
738 .gpc_name = "lcdif2",
739 .rst_mask = BIT(11) | BIT(12) | BIT(24),
740 .clk_mask = BIT(11) | BIT(12) | BIT(24),
741 .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
744 [IMX8MP_MEDIABLK_PD_ISP] = {
745 .name = "mediablk-isp",
746 .clk_names = (const char *[]){ "isp", "axi", "apb" },
749 .rst_mask = BIT(16) | BIT(17) | BIT(18),
750 .clk_mask = BIT(16) | BIT(17) | BIT(18),
751 .path_names = (const char *[]){"isp0", "isp1"},
754 [IMX8MP_MEDIABLK_PD_DWE] = {
755 .name = "mediablk-dwe",
756 .clk_names = (const char *[]){ "axi", "apb" },
759 .rst_mask = BIT(19) | BIT(20) | BIT(21),
760 .clk_mask = BIT(19) | BIT(20) | BIT(21),
761 .path_names = (const char *[]){"dwe"},
764 [IMX8MP_MEDIABLK_PD_MIPI_DSI_2] = {
765 .name = "mediablk-mipi-dsi-2",
766 .clk_names = (const char *[]){ "phy", },
768 .gpc_name = "mipi-dsi2",
771 .mipi_phy_rst_mask = BIT(29),
775 static const struct imx8m_blk_ctrl_data imx8mp_media_blk_ctl_dev_data = {
777 .power_notifier_fn = imx8mp_media_power_notifier,
778 .domains = imx8mp_media_blk_ctl_domain_data,
779 .num_domains = ARRAY_SIZE(imx8mp_media_blk_ctl_domain_data),
782 static int imx8mq_vpu_power_notifier(struct notifier_block *nb,
783 unsigned long action, void *data)
785 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
788 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
792 * The ADB in the VPUMIX domain has no separate reset and clock
793 * enable bits, but is ungated and reset together with the VPUs. The
794 * reset and clock enable inputs to the ADB is a logical OR of the
795 * VPU bits. In order to set the G2 fuse bits, the G2 clock must
798 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1));
799 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1));
801 if (action == GENPD_NOTIFY_ON) {
803 * On power up we have no software backchannel to the GPC to
804 * wait for the ADB handshake to happen, so we just delay for a
805 * bit. On power down the GPC driver waits for the handshake.
809 /* set "fuse" bits to enable the VPUs */
810 regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
811 regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
812 regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
818 static const struct imx8m_blk_ctrl_domain_data imx8mq_vpu_blk_ctl_domain_data[] = {
819 [IMX8MQ_VPUBLK_PD_G1] = {
821 .clk_names = (const char *[]){ "g1", },
827 [IMX8MQ_VPUBLK_PD_G2] = {
829 .clk_names = (const char *[]){ "g2", },
837 static const struct imx8m_blk_ctrl_data imx8mq_vpu_blk_ctl_dev_data = {
839 .power_notifier_fn = imx8mq_vpu_power_notifier,
840 .domains = imx8mq_vpu_blk_ctl_domain_data,
841 .num_domains = ARRAY_SIZE(imx8mq_vpu_blk_ctl_domain_data),
844 static const struct of_device_id imx8m_blk_ctrl_of_match[] = {
846 .compatible = "fsl,imx8mm-vpu-blk-ctrl",
847 .data = &imx8mm_vpu_blk_ctl_dev_data
849 .compatible = "fsl,imx8mm-disp-blk-ctrl",
850 .data = &imx8mm_disp_blk_ctl_dev_data
852 .compatible = "fsl,imx8mn-disp-blk-ctrl",
853 .data = &imx8mn_disp_blk_ctl_dev_data
855 .compatible = "fsl,imx8mp-media-blk-ctrl",
856 .data = &imx8mp_media_blk_ctl_dev_data
858 .compatible = "fsl,imx8mq-vpu-blk-ctrl",
859 .data = &imx8mq_vpu_blk_ctl_dev_data
861 .compatible = "fsl,imx8mp-vpu-blk-ctrl",
862 .data = &imx8mp_vpu_blk_ctl_dev_data
867 MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
869 static struct platform_driver imx8m_blk_ctrl_driver = {
870 .probe = imx8m_blk_ctrl_probe,
871 .remove = imx8m_blk_ctrl_remove,
873 .name = "imx8m-blk-ctrl",
874 .pm = &imx8m_blk_ctrl_pm_ops,
875 .of_match_table = imx8m_blk_ctrl_of_match,
878 module_platform_driver(imx8m_blk_ctrl_driver);