1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright 2021 Pengutronix, Lucas Stach <kernel@pengutronix.de>
7 #include <linux/bitfield.h>
8 #include <linux/device.h>
9 #include <linux/interconnect.h>
10 #include <linux/module.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_device.h>
14 #include <linux/pm_domain.h>
15 #include <linux/pm_runtime.h>
16 #include <linux/regmap.h>
17 #include <linux/clk.h>
19 #include <dt-bindings/power/imx8mm-power.h>
20 #include <dt-bindings/power/imx8mn-power.h>
21 #include <dt-bindings/power/imx8mp-power.h>
22 #include <dt-bindings/power/imx8mq-power.h>
24 #define BLK_SFT_RSTN 0x0
25 #define BLK_CLK_EN 0x4
26 #define BLK_MIPI_RESET_DIV 0x8 /* Mini/Nano/Plus DISPLAY_BLK_CTRL only */
28 struct imx8m_blk_ctrl_domain;
30 struct imx8m_blk_ctrl {
32 struct notifier_block power_nb;
33 struct device *bus_power_dev;
34 struct regmap *regmap;
35 struct imx8m_blk_ctrl_domain *domains;
36 struct genpd_onecell_data onecell_data;
39 struct imx8m_blk_ctrl_domain_data {
41 const char * const *clk_names;
42 const char * const *path_names;
50 * i.MX8M Mini, Nano and Plus have a third DISPLAY_BLK_CTRL register
51 * which is used to control the reset for the MIPI Phy.
52 * Since it's only present in certain circumstances,
53 * an if-statement should be used before setting and clearing this
56 u32 mipi_phy_rst_mask;
59 #define DOMAIN_MAX_CLKS 4
60 #define DOMAIN_MAX_PATHS 4
62 struct imx8m_blk_ctrl_domain {
63 struct generic_pm_domain genpd;
64 const struct imx8m_blk_ctrl_domain_data *data;
65 struct clk_bulk_data clks[DOMAIN_MAX_CLKS];
66 struct icc_bulk_data paths[DOMAIN_MAX_PATHS];
67 struct device *power_dev;
68 struct imx8m_blk_ctrl *bc;
72 struct imx8m_blk_ctrl_data {
74 notifier_fn_t power_notifier_fn;
75 const struct imx8m_blk_ctrl_domain_data *domains;
79 static inline struct imx8m_blk_ctrl_domain *
80 to_imx8m_blk_ctrl_domain(struct generic_pm_domain *genpd)
82 return container_of(genpd, struct imx8m_blk_ctrl_domain, genpd);
85 static int imx8m_blk_ctrl_power_on(struct generic_pm_domain *genpd)
87 struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
88 const struct imx8m_blk_ctrl_domain_data *data = domain->data;
89 struct imx8m_blk_ctrl *bc = domain->bc;
92 /* make sure bus domain is awake */
93 ret = pm_runtime_get_sync(bc->bus_power_dev);
95 pm_runtime_put_noidle(bc->bus_power_dev);
96 dev_err(bc->dev, "failed to power up bus domain\n");
100 /* put devices into reset */
101 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
102 if (data->mipi_phy_rst_mask)
103 regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
105 /* enable upstream and blk-ctrl clocks to allow reset to propagate */
106 ret = clk_bulk_prepare_enable(data->num_clks, domain->clks);
108 dev_err(bc->dev, "failed to enable clocks\n");
111 regmap_set_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
113 /* power up upstream GPC domain */
114 ret = pm_runtime_get_sync(domain->power_dev);
116 dev_err(bc->dev, "failed to power up peripheral domain\n");
120 /* wait for reset to propagate */
124 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
125 if (data->mipi_phy_rst_mask)
126 regmap_set_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
128 ret = icc_bulk_set_bw(domain->num_paths, domain->paths);
130 dev_err(bc->dev, "failed to set icc bw\n");
132 /* disable upstream clocks */
133 clk_bulk_disable_unprepare(data->num_clks, domain->clks);
138 clk_bulk_disable_unprepare(data->num_clks, domain->clks);
140 pm_runtime_put(bc->bus_power_dev);
145 static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
147 struct imx8m_blk_ctrl_domain *domain = to_imx8m_blk_ctrl_domain(genpd);
148 const struct imx8m_blk_ctrl_domain_data *data = domain->data;
149 struct imx8m_blk_ctrl *bc = domain->bc;
151 /* put devices into reset and disable clocks */
152 if (data->mipi_phy_rst_mask)
153 regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
155 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, data->rst_mask);
156 regmap_clear_bits(bc->regmap, BLK_CLK_EN, data->clk_mask);
158 /* power down upstream GPC domain */
159 pm_runtime_put(domain->power_dev);
161 /* allow bus domain to suspend */
162 pm_runtime_put(bc->bus_power_dev);
167 static struct lock_class_key blk_ctrl_genpd_lock_class;
169 static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
171 const struct imx8m_blk_ctrl_data *bc_data;
172 struct device *dev = &pdev->dev;
173 struct imx8m_blk_ctrl *bc;
177 struct regmap_config regmap_config = {
183 bc = devm_kzalloc(dev, sizeof(*bc), GFP_KERNEL);
189 bc_data = of_device_get_match_data(dev);
191 base = devm_platform_ioremap_resource(pdev, 0);
193 return PTR_ERR(base);
195 regmap_config.max_register = bc_data->max_reg;
196 bc->regmap = devm_regmap_init_mmio(dev, base, ®map_config);
197 if (IS_ERR(bc->regmap))
198 return dev_err_probe(dev, PTR_ERR(bc->regmap),
199 "failed to init regmap\n");
201 bc->domains = devm_kcalloc(dev, bc_data->num_domains,
202 sizeof(struct imx8m_blk_ctrl_domain),
207 bc->onecell_data.num_domains = bc_data->num_domains;
208 bc->onecell_data.domains =
209 devm_kcalloc(dev, bc_data->num_domains,
210 sizeof(struct generic_pm_domain *), GFP_KERNEL);
211 if (!bc->onecell_data.domains)
214 bc->bus_power_dev = dev_pm_domain_attach_by_name(dev, "bus");
215 if (IS_ERR(bc->bus_power_dev)) {
216 if (PTR_ERR(bc->bus_power_dev) == -ENODEV)
217 return dev_err_probe(dev, -EPROBE_DEFER,
218 "failed to attach power domain \"bus\"\n");
220 return dev_err_probe(dev, PTR_ERR(bc->bus_power_dev),
221 "failed to attach power domain \"bus\"\n");
224 for (i = 0; i < bc_data->num_domains; i++) {
225 const struct imx8m_blk_ctrl_domain_data *data = &bc_data->domains[i];
226 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
230 domain->num_paths = data->num_paths;
232 for (j = 0; j < data->num_clks; j++)
233 domain->clks[j].id = data->clk_names[j];
235 for (j = 0; j < data->num_paths; j++) {
236 domain->paths[j].name = data->path_names[j];
237 /* Fake value for now, just let ICC could configure NoC mode/priority */
238 domain->paths[j].avg_bw = 1;
239 domain->paths[j].peak_bw = 1;
242 ret = devm_of_icc_bulk_get(dev, data->num_paths, domain->paths);
244 if (ret != -EPROBE_DEFER) {
245 dev_warn_once(dev, "Could not get interconnect paths, NoC will stay unconfigured!\n");
246 domain->num_paths = 0;
248 dev_err_probe(dev, ret, "failed to get noc entries\n");
253 ret = devm_clk_bulk_get(dev, data->num_clks, domain->clks);
255 dev_err_probe(dev, ret, "failed to get clock\n");
260 dev_pm_domain_attach_by_name(dev, data->gpc_name);
261 if (IS_ERR_OR_NULL(domain->power_dev)) {
262 if (!domain->power_dev)
265 ret = PTR_ERR(domain->power_dev);
266 dev_err_probe(dev, ret,
267 "failed to attach power domain \"%s\"\n",
272 domain->genpd.name = data->name;
273 domain->genpd.power_on = imx8m_blk_ctrl_power_on;
274 domain->genpd.power_off = imx8m_blk_ctrl_power_off;
277 ret = pm_genpd_init(&domain->genpd, NULL, true);
279 dev_err_probe(dev, ret,
280 "failed to init power domain \"%s\"\n",
282 dev_pm_domain_detach(domain->power_dev, true);
287 * We use runtime PM to trigger power on/off of the upstream GPC
288 * domain, as a strict hierarchical parent/child power domain
289 * setup doesn't allow us to meet the sequencing requirements.
290 * This means we have nested locking of genpd locks, without the
291 * nesting being visible at the genpd level, so we need a
292 * separate lock class to make lockdep aware of the fact that
293 * this are separate domain locks that can be nested without a
296 lockdep_set_class(&domain->genpd.mlock,
297 &blk_ctrl_genpd_lock_class);
299 bc->onecell_data.domains[i] = &domain->genpd;
302 ret = of_genpd_add_provider_onecell(dev->of_node, &bc->onecell_data);
304 dev_err_probe(dev, ret, "failed to add power domain provider\n");
308 bc->power_nb.notifier_call = bc_data->power_notifier_fn;
309 ret = dev_pm_genpd_add_notifier(bc->bus_power_dev, &bc->power_nb);
311 dev_err_probe(dev, ret, "failed to add power notifier\n");
312 goto cleanup_provider;
315 dev_set_drvdata(dev, bc);
317 ret = devm_of_platform_populate(dev);
319 goto cleanup_provider;
324 of_genpd_del_provider(dev->of_node);
326 for (i--; i >= 0; i--) {
327 pm_genpd_remove(&bc->domains[i].genpd);
328 dev_pm_domain_detach(bc->domains[i].power_dev, true);
331 dev_pm_domain_detach(bc->bus_power_dev, true);
336 static void imx8m_blk_ctrl_remove(struct platform_device *pdev)
338 struct imx8m_blk_ctrl *bc = dev_get_drvdata(&pdev->dev);
341 of_genpd_del_provider(pdev->dev.of_node);
343 for (i = 0; bc->onecell_data.num_domains; i++) {
344 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
346 pm_genpd_remove(&domain->genpd);
347 dev_pm_domain_detach(domain->power_dev, true);
350 dev_pm_genpd_remove_notifier(bc->bus_power_dev);
352 dev_pm_domain_detach(bc->bus_power_dev, true);
355 #ifdef CONFIG_PM_SLEEP
356 static int imx8m_blk_ctrl_suspend(struct device *dev)
358 struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
362 * This may look strange, but is done so the generic PM_SLEEP code
363 * can power down our domains and more importantly power them up again
364 * after resume, without tripping over our usage of runtime PM to
365 * control the upstream GPC domains. Things happen in the right order
366 * in the system suspend/resume paths due to the device parent/child
369 ret = pm_runtime_get_sync(bc->bus_power_dev);
371 pm_runtime_put_noidle(bc->bus_power_dev);
375 for (i = 0; i < bc->onecell_data.num_domains; i++) {
376 struct imx8m_blk_ctrl_domain *domain = &bc->domains[i];
378 ret = pm_runtime_get_sync(domain->power_dev);
380 pm_runtime_put_noidle(domain->power_dev);
388 for (i--; i >= 0; i--)
389 pm_runtime_put(bc->domains[i].power_dev);
391 pm_runtime_put(bc->bus_power_dev);
396 static int imx8m_blk_ctrl_resume(struct device *dev)
398 struct imx8m_blk_ctrl *bc = dev_get_drvdata(dev);
401 for (i = 0; i < bc->onecell_data.num_domains; i++)
402 pm_runtime_put(bc->domains[i].power_dev);
404 pm_runtime_put(bc->bus_power_dev);
410 static const struct dev_pm_ops imx8m_blk_ctrl_pm_ops = {
411 SET_SYSTEM_SLEEP_PM_OPS(imx8m_blk_ctrl_suspend, imx8m_blk_ctrl_resume)
414 static int imx8mm_vpu_power_notifier(struct notifier_block *nb,
415 unsigned long action, void *data)
417 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
420 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
424 * The ADB in the VPUMIX domain has no separate reset and clock
425 * enable bits, but is ungated together with the VPU clocks. To
426 * allow the handshake with the GPC to progress we put the VPUs
427 * in reset and ungate the clocks.
429 regmap_clear_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1) | BIT(2));
430 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1) | BIT(2));
432 if (action == GENPD_NOTIFY_ON) {
434 * On power up we have no software backchannel to the GPC to
435 * wait for the ADB handshake to happen, so we just delay for a
436 * bit. On power down the GPC driver waits for the handshake.
440 /* set "fuse" bits to enable the VPUs */
441 regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
442 regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
443 regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
444 regmap_set_bits(bc->regmap, 0x14, 0xffffffff);
450 static const struct imx8m_blk_ctrl_domain_data imx8mm_vpu_blk_ctl_domain_data[] = {
451 [IMX8MM_VPUBLK_PD_G1] = {
453 .clk_names = (const char *[]){ "g1", },
459 [IMX8MM_VPUBLK_PD_G2] = {
461 .clk_names = (const char *[]){ "g2", },
467 [IMX8MM_VPUBLK_PD_H1] = {
469 .clk_names = (const char *[]){ "h1", },
477 static const struct imx8m_blk_ctrl_data imx8mm_vpu_blk_ctl_dev_data = {
479 .power_notifier_fn = imx8mm_vpu_power_notifier,
480 .domains = imx8mm_vpu_blk_ctl_domain_data,
481 .num_domains = ARRAY_SIZE(imx8mm_vpu_blk_ctl_domain_data),
484 static const struct imx8m_blk_ctrl_domain_data imx8mp_vpu_blk_ctl_domain_data[] = {
485 [IMX8MP_VPUBLK_PD_G1] = {
487 .clk_names = (const char *[]){ "g1", },
492 .path_names = (const char *[]){"g1"},
495 [IMX8MP_VPUBLK_PD_G2] = {
497 .clk_names = (const char *[]){ "g2", },
502 .path_names = (const char *[]){"g2"},
505 [IMX8MP_VPUBLK_PD_VC8000E] = {
506 .name = "vpublk-vc8000e",
507 .clk_names = (const char *[]){ "vc8000e", },
509 .gpc_name = "vc8000e",
512 .path_names = (const char *[]){"vc8000e"},
517 static const struct imx8m_blk_ctrl_data imx8mp_vpu_blk_ctl_dev_data = {
519 .power_notifier_fn = imx8mm_vpu_power_notifier,
520 .domains = imx8mp_vpu_blk_ctl_domain_data,
521 .num_domains = ARRAY_SIZE(imx8mp_vpu_blk_ctl_domain_data),
524 static int imx8mm_disp_power_notifier(struct notifier_block *nb,
525 unsigned long action, void *data)
527 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
530 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
533 /* Enable bus clock and deassert bus reset */
534 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(12));
535 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(6));
538 * On power up we have no software backchannel to the GPC to
539 * wait for the ADB handshake to happen, so we just delay for a
540 * bit. On power down the GPC driver waits for the handshake.
542 if (action == GENPD_NOTIFY_ON)
549 static const struct imx8m_blk_ctrl_domain_data imx8mm_disp_blk_ctl_domain_data[] = {
550 [IMX8MM_DISPBLK_PD_CSI_BRIDGE] = {
551 .name = "dispblk-csi-bridge",
552 .clk_names = (const char *[]){ "csi-bridge-axi", "csi-bridge-apb",
553 "csi-bridge-core", },
555 .gpc_name = "csi-bridge",
556 .rst_mask = BIT(0) | BIT(1) | BIT(2),
557 .clk_mask = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5),
559 [IMX8MM_DISPBLK_PD_LCDIF] = {
560 .name = "dispblk-lcdif",
561 .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
564 .clk_mask = BIT(6) | BIT(7),
566 [IMX8MM_DISPBLK_PD_MIPI_DSI] = {
567 .name = "dispblk-mipi-dsi",
568 .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
570 .gpc_name = "mipi-dsi",
572 .clk_mask = BIT(8) | BIT(9),
573 .mipi_phy_rst_mask = BIT(17),
575 [IMX8MM_DISPBLK_PD_MIPI_CSI] = {
576 .name = "dispblk-mipi-csi",
577 .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
579 .gpc_name = "mipi-csi",
580 .rst_mask = BIT(3) | BIT(4),
581 .clk_mask = BIT(10) | BIT(11),
582 .mipi_phy_rst_mask = BIT(16),
586 static const struct imx8m_blk_ctrl_data imx8mm_disp_blk_ctl_dev_data = {
588 .power_notifier_fn = imx8mm_disp_power_notifier,
589 .domains = imx8mm_disp_blk_ctl_domain_data,
590 .num_domains = ARRAY_SIZE(imx8mm_disp_blk_ctl_domain_data),
594 static int imx8mn_disp_power_notifier(struct notifier_block *nb,
595 unsigned long action, void *data)
597 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
600 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
603 /* Enable bus clock and deassert bus reset */
604 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
605 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
608 * On power up we have no software backchannel to the GPC to
609 * wait for the ADB handshake to happen, so we just delay for a
610 * bit. On power down the GPC driver waits for the handshake.
612 if (action == GENPD_NOTIFY_ON)
619 static const struct imx8m_blk_ctrl_domain_data imx8mn_disp_blk_ctl_domain_data[] = {
620 [IMX8MN_DISPBLK_PD_MIPI_DSI] = {
621 .name = "dispblk-mipi-dsi",
622 .clk_names = (const char *[]){ "dsi-pclk", "dsi-ref", },
624 .gpc_name = "mipi-dsi",
625 .rst_mask = BIT(0) | BIT(1),
626 .clk_mask = BIT(0) | BIT(1),
627 .mipi_phy_rst_mask = BIT(17),
629 [IMX8MN_DISPBLK_PD_MIPI_CSI] = {
630 .name = "dispblk-mipi-csi",
631 .clk_names = (const char *[]){ "csi-aclk", "csi-pclk" },
633 .gpc_name = "mipi-csi",
634 .rst_mask = BIT(2) | BIT(3),
635 .clk_mask = BIT(2) | BIT(3),
636 .mipi_phy_rst_mask = BIT(16),
638 [IMX8MN_DISPBLK_PD_LCDIF] = {
639 .name = "dispblk-lcdif",
640 .clk_names = (const char *[]){ "lcdif-axi", "lcdif-apb", "lcdif-pix", },
643 .rst_mask = BIT(4) | BIT(5),
644 .clk_mask = BIT(4) | BIT(5),
646 [IMX8MN_DISPBLK_PD_ISI] = {
647 .name = "dispblk-isi",
648 .clk_names = (const char *[]){ "disp_axi", "disp_apb", "disp_axi_root",
652 .rst_mask = BIT(6) | BIT(7),
653 .clk_mask = BIT(6) | BIT(7),
657 static const struct imx8m_blk_ctrl_data imx8mn_disp_blk_ctl_dev_data = {
659 .power_notifier_fn = imx8mn_disp_power_notifier,
660 .domains = imx8mn_disp_blk_ctl_domain_data,
661 .num_domains = ARRAY_SIZE(imx8mn_disp_blk_ctl_domain_data),
664 #define LCDIF_ARCACHE_CTRL 0x4c
665 #define LCDIF_1_RD_HURRY GENMASK(15, 13)
666 #define LCDIF_0_RD_HURRY GENMASK(12, 10)
668 static int imx8mp_media_power_notifier(struct notifier_block *nb,
669 unsigned long action, void *data)
671 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
674 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
677 /* Enable bus clock and deassert bus reset */
678 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(8));
679 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(8));
681 if (action == GENPD_NOTIFY_ON) {
683 * On power up we have no software backchannel to the GPC to
684 * wait for the ADB handshake to happen, so we just delay for a
685 * bit. On power down the GPC driver waits for the handshake.
690 * Set panic read hurry level for both LCDIF interfaces to
691 * maximum priority to minimize chances of display FIFO
694 regmap_set_bits(bc->regmap, LCDIF_ARCACHE_CTRL,
695 FIELD_PREP(LCDIF_1_RD_HURRY, 7) |
696 FIELD_PREP(LCDIF_0_RD_HURRY, 7));
703 * From i.MX 8M Plus Applications Processor Reference Manual, Rev. 1,
704 * section 13.2.2, 13.2.3
705 * isp-ahb and dwe are not in Figure 13-5. Media BLK_CTRL Clocks
707 static const struct imx8m_blk_ctrl_domain_data imx8mp_media_blk_ctl_domain_data[] = {
708 [IMX8MP_MEDIABLK_PD_MIPI_DSI_1] = {
709 .name = "mediablk-mipi-dsi-1",
710 .clk_names = (const char *[]){ "apb", "phy", },
712 .gpc_name = "mipi-dsi1",
713 .rst_mask = BIT(0) | BIT(1),
714 .clk_mask = BIT(0) | BIT(1),
715 .mipi_phy_rst_mask = BIT(17),
717 [IMX8MP_MEDIABLK_PD_MIPI_CSI2_1] = {
718 .name = "mediablk-mipi-csi2-1",
719 .clk_names = (const char *[]){ "apb", "cam1" },
721 .gpc_name = "mipi-csi1",
722 .rst_mask = BIT(2) | BIT(3),
723 .clk_mask = BIT(2) | BIT(3),
724 .mipi_phy_rst_mask = BIT(16),
726 [IMX8MP_MEDIABLK_PD_LCDIF_1] = {
727 .name = "mediablk-lcdif-1",
728 .clk_names = (const char *[]){ "disp1", "apb", "axi", },
730 .gpc_name = "lcdif1",
731 .rst_mask = BIT(4) | BIT(5) | BIT(23),
732 .clk_mask = BIT(4) | BIT(5) | BIT(23),
733 .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
736 [IMX8MP_MEDIABLK_PD_ISI] = {
737 .name = "mediablk-isi",
738 .clk_names = (const char *[]){ "axi", "apb" },
741 .rst_mask = BIT(6) | BIT(7),
742 .clk_mask = BIT(6) | BIT(7),
743 .path_names = (const char *[]){"isi0", "isi1", "isi2"},
746 [IMX8MP_MEDIABLK_PD_MIPI_CSI2_2] = {
747 .name = "mediablk-mipi-csi2-2",
748 .clk_names = (const char *[]){ "apb", "cam2" },
750 .gpc_name = "mipi-csi2",
751 .rst_mask = BIT(9) | BIT(10),
752 .clk_mask = BIT(9) | BIT(10),
753 .mipi_phy_rst_mask = BIT(30),
755 [IMX8MP_MEDIABLK_PD_LCDIF_2] = {
756 .name = "mediablk-lcdif-2",
757 .clk_names = (const char *[]){ "disp2", "apb", "axi", },
759 .gpc_name = "lcdif2",
760 .rst_mask = BIT(11) | BIT(12) | BIT(24),
761 .clk_mask = BIT(11) | BIT(12) | BIT(24),
762 .path_names = (const char *[]){"lcdif-rd", "lcdif-wr"},
765 [IMX8MP_MEDIABLK_PD_ISP] = {
766 .name = "mediablk-isp",
767 .clk_names = (const char *[]){ "isp", "axi", "apb" },
770 .rst_mask = BIT(16) | BIT(17) | BIT(18),
771 .clk_mask = BIT(16) | BIT(17) | BIT(18),
772 .path_names = (const char *[]){"isp0", "isp1"},
775 [IMX8MP_MEDIABLK_PD_DWE] = {
776 .name = "mediablk-dwe",
777 .clk_names = (const char *[]){ "axi", "apb" },
780 .rst_mask = BIT(19) | BIT(20) | BIT(21),
781 .clk_mask = BIT(19) | BIT(20) | BIT(21),
782 .path_names = (const char *[]){"dwe"},
785 [IMX8MP_MEDIABLK_PD_MIPI_DSI_2] = {
786 .name = "mediablk-mipi-dsi-2",
787 .clk_names = (const char *[]){ "phy", },
789 .gpc_name = "mipi-dsi2",
792 .mipi_phy_rst_mask = BIT(29),
796 static const struct imx8m_blk_ctrl_data imx8mp_media_blk_ctl_dev_data = {
798 .power_notifier_fn = imx8mp_media_power_notifier,
799 .domains = imx8mp_media_blk_ctl_domain_data,
800 .num_domains = ARRAY_SIZE(imx8mp_media_blk_ctl_domain_data),
803 static int imx8mq_vpu_power_notifier(struct notifier_block *nb,
804 unsigned long action, void *data)
806 struct imx8m_blk_ctrl *bc = container_of(nb, struct imx8m_blk_ctrl,
809 if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF)
813 * The ADB in the VPUMIX domain has no separate reset and clock
814 * enable bits, but is ungated and reset together with the VPUs. The
815 * reset and clock enable inputs to the ADB is a logical OR of the
816 * VPU bits. In order to set the G2 fuse bits, the G2 clock must
819 regmap_set_bits(bc->regmap, BLK_SFT_RSTN, BIT(0) | BIT(1));
820 regmap_set_bits(bc->regmap, BLK_CLK_EN, BIT(0) | BIT(1));
822 if (action == GENPD_NOTIFY_ON) {
824 * On power up we have no software backchannel to the GPC to
825 * wait for the ADB handshake to happen, so we just delay for a
826 * bit. On power down the GPC driver waits for the handshake.
830 /* set "fuse" bits to enable the VPUs */
831 regmap_set_bits(bc->regmap, 0x8, 0xffffffff);
832 regmap_set_bits(bc->regmap, 0xc, 0xffffffff);
833 regmap_set_bits(bc->regmap, 0x10, 0xffffffff);
839 static const struct imx8m_blk_ctrl_domain_data imx8mq_vpu_blk_ctl_domain_data[] = {
840 [IMX8MQ_VPUBLK_PD_G1] = {
842 .clk_names = (const char *[]){ "g1", },
848 [IMX8MQ_VPUBLK_PD_G2] = {
850 .clk_names = (const char *[]){ "g2", },
858 static const struct imx8m_blk_ctrl_data imx8mq_vpu_blk_ctl_dev_data = {
860 .power_notifier_fn = imx8mq_vpu_power_notifier,
861 .domains = imx8mq_vpu_blk_ctl_domain_data,
862 .num_domains = ARRAY_SIZE(imx8mq_vpu_blk_ctl_domain_data),
865 static const struct of_device_id imx8m_blk_ctrl_of_match[] = {
867 .compatible = "fsl,imx8mm-vpu-blk-ctrl",
868 .data = &imx8mm_vpu_blk_ctl_dev_data
870 .compatible = "fsl,imx8mm-disp-blk-ctrl",
871 .data = &imx8mm_disp_blk_ctl_dev_data
873 .compatible = "fsl,imx8mn-disp-blk-ctrl",
874 .data = &imx8mn_disp_blk_ctl_dev_data
876 .compatible = "fsl,imx8mp-media-blk-ctrl",
877 .data = &imx8mp_media_blk_ctl_dev_data
879 .compatible = "fsl,imx8mq-vpu-blk-ctrl",
880 .data = &imx8mq_vpu_blk_ctl_dev_data
882 .compatible = "fsl,imx8mp-vpu-blk-ctrl",
883 .data = &imx8mp_vpu_blk_ctl_dev_data
888 MODULE_DEVICE_TABLE(of, imx8m_blk_ctrl_of_match);
890 static struct platform_driver imx8m_blk_ctrl_driver = {
891 .probe = imx8m_blk_ctrl_probe,
892 .remove_new = imx8m_blk_ctrl_remove,
894 .name = "imx8m-blk-ctrl",
895 .pm = &imx8m_blk_ctrl_pm_ops,
896 .of_match_table = imx8m_blk_ctrl_of_match,
899 module_platform_driver(imx8m_blk_ctrl_driver);
900 MODULE_LICENSE("GPL");