Add Allwinner A733 TCON TOP1 and TCON TV0 support with runtime PM. TCON TOP1 omits the DE-to-TCON mux and uses an optional AHB clock.
Signed-off-by: Alastair D'Silva <[email protected]> --- drivers/gpu/drm/sun4i/sun4i_tcon.c | 74 +++++++++++++++++++++----- drivers/gpu/drm/sun4i/sun4i_tcon.h | 8 +++ drivers/gpu/drm/sun4i/sun8i_tcon_top.c | 61 +++++++++++++++++++-- drivers/gpu/drm/sun4i/sun8i_tcon_top.h | 3 ++ 4 files changed, 127 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index 20740fa10ce8..927601a7be07 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -13,6 +13,7 @@ #include <linux/of.h> #include <linux/of_platform.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <linux/regmap.h> #include <linux/reset.h> @@ -604,6 +605,14 @@ static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, WARN_ON(!tcon->quirks->has_channel_1); + /* A733 TCON TV0 requires a reset before reprogramming timings */ + if (tcon->quirks->basic1_vtotal) { + clk_disable_unprepare(tcon->clk); + reset_control_reset(tcon->lcd_rst); + if (clk_prepare_enable(tcon->clk)) + dev_err(tcon->dev, "Failed to re-enable TCON bus clock\n"); + } + /* Configure the dot clock */ clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000); @@ -622,15 +631,22 @@ static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, SUN4I_TCON1_CTL_INTERLACE_ENABLE, val); + vtotal = mode->vtotal; + if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) + vtotal = vtotal * 2; + /* Set the input resolution */ regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG, SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) | SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay)); - /* Set the upscaling resolution */ - regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, - SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) | - SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay)); + /* Set the upscaling resolution (or extended vtotal on A733) */ + if (tcon->quirks->basic1_vtotal) + regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, vtotal); + else + regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, + SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) | + SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay)); /* Set the output resolution */ regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG, @@ -662,10 +678,6 @@ static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, * To work around this, we will always use vtotal, and * multiply by two only if we're not in interlace. */ - vtotal = mode->vtotal; - if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) - vtotal = vtotal * 2; - /* Set vertical display timings */ regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG, SUN4I_TCON1_BASIC4_V_TOTAL(vtotal) | @@ -703,6 +715,16 @@ static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, regmap_write(tcon->regs, SUN4I_TCON1_IO_POL_REG, val); } + if (tcon->quirks->has_pixel_depth) { + regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0); + regmap_write(tcon->regs, SUN4I_TCON1_DATA_IO_POL0_REG, 0); + regmap_write(tcon->regs, SUN4I_TCON1_DATA_IO_POL1_REG, 0); + regmap_write(tcon->regs, SUN4I_TCON1_DATA_IO_TRI0_REG, 0); + regmap_write(tcon->regs, SUN4I_TCON1_DATA_IO_TRI1_REG, 0); + regmap_write(tcon->regs, SUN4I_TCON1_PIXEL_DEPTH_REG, + SUN4I_TCON1_PIXEL_DEPTH_8BIT); + } + /* Map output pins to channel 1 */ regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, SUN4I_TCON_GCTL_IOMAP_MASK, @@ -1136,23 +1158,30 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, tcon->id = engine->id; tcon->quirks = of_device_get_match_data(dev); + pm_runtime_enable(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + goto err_pm_disable; + tcon->lcd_rst = devm_reset_control_get(dev, "lcd"); if (IS_ERR(tcon->lcd_rst)) { dev_err(dev, "Couldn't get our reset line\n"); - return PTR_ERR(tcon->lcd_rst); + ret = PTR_ERR(tcon->lcd_rst); + goto err_pm_put; } if (tcon->quirks->needs_edp_reset) { edp_rstc = devm_reset_control_get_shared(dev, "edp"); if (IS_ERR(edp_rstc)) { dev_err(dev, "Couldn't get edp reset line\n"); - return PTR_ERR(edp_rstc); + ret = PTR_ERR(edp_rstc); + goto err_pm_put; } ret = reset_control_deassert(edp_rstc); if (ret) { dev_err(dev, "Couldn't deassert edp reset line\n"); - return ret; + goto err_pm_put; } } @@ -1160,7 +1189,7 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, ret = reset_control_reset(tcon->lcd_rst); if (ret) { dev_err(dev, "Couldn't deassert our reset line\n"); - return ret; + goto err_pm_put; } if (tcon->quirks->supports_lvds) { @@ -1174,7 +1203,8 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds"); if (IS_ERR(tcon->lvds_rst)) { dev_err(dev, "Couldn't get our reset line\n"); - return PTR_ERR(tcon->lvds_rst); + ret = PTR_ERR(tcon->lvds_rst); + goto err_pm_put; } else if (tcon->lvds_rst) { has_lvds_rst = true; reset_control_reset(tcon->lvds_rst); @@ -1196,7 +1226,8 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, has_lvds_alt = false; } else { dev_err(dev, "Couldn't get the LVDS PLL\n"); - return PTR_ERR(tcon->lvds_pll); + ret = PTR_ERR(tcon->lvds_pll); + goto err_pm_put; } } else { has_lvds_alt = true; @@ -1296,6 +1327,10 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, sun4i_dclk_free(tcon); err_assert_reset: reset_control_assert(tcon->lcd_rst); +err_pm_put: + pm_runtime_put_sync(dev); +err_pm_disable: + pm_runtime_disable(dev); return ret; } @@ -1307,6 +1342,8 @@ static void sun4i_tcon_unbind(struct device *dev, struct device *master, list_del(&tcon->list); if (tcon->quirks->has_channel_0) sun4i_dclk_free(tcon); + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); } static const struct component_ops sun4i_tcon_ops = { @@ -1546,6 +1583,14 @@ static const struct sun4i_tcon_quirks sun20i_d1_lcd_quirks = { .set_mux = sun8i_r40_tcon_tv_set_mux, }; +static const struct sun4i_tcon_quirks sun60i_a733_tv_quirks = { + .has_channel_1 = true, + .polarity_in_ch0 = true, + .basic1_vtotal = true, + .has_pixel_depth = true, + .set_mux = sun8i_r40_tcon_tv_set_mux, +}; + /* sun4i_drv uses this list to check if a device node is a TCON */ const struct of_device_id sun4i_tcon_of_table[] = { { .compatible = "allwinner,sun4i-a10-tcon", .data = &sun4i_a10_quirks }, @@ -1565,6 +1610,7 @@ const struct of_device_id sun4i_tcon_of_table[] = { { .compatible = "allwinner,sun9i-a80-tcon-tv", .data = &sun9i_a80_tcon_tv_quirks }, { .compatible = "allwinner,sun20i-d1-tcon-lcd", .data = &sun20i_d1_lcd_quirks }, { .compatible = "allwinner,sun20i-d1-tcon-tv", .data = &sun8i_r40_tv_quirks }, + { .compatible = "allwinner,sun60i-a733-tcon-tv", .data = &sun60i_a733_tv_quirks }, { } }; MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table); diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.h b/drivers/gpu/drm/sun4i/sun4i_tcon.h index fa23aa23fe4a..35932cbf5a51 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.h +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.h @@ -229,6 +229,12 @@ #define SUN4I_TCON1_FILL_BEG2_REG 0x31c #define SUN4I_TCON1_FILL_END2_REG 0x320 #define SUN4I_TCON1_FILL_DATA2_REG 0x324 +#define SUN4I_TCON1_DATA_IO_POL0_REG 0x330 +#define SUN4I_TCON1_DATA_IO_POL1_REG 0x334 +#define SUN4I_TCON1_DATA_IO_TRI0_REG 0x338 +#define SUN4I_TCON1_DATA_IO_TRI1_REG 0x33c +#define SUN4I_TCON1_PIXEL_DEPTH_REG 0x340 +#define SUN4I_TCON1_PIXEL_DEPTH_8BIT 0 #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400 #define SUN4I_TCON_MAX_CHANNELS 2 @@ -243,6 +249,8 @@ struct sun4i_tcon_quirks { bool needs_edp_reset; /* a80 edp reset needed for tcon0 access */ bool supports_lvds; /* Does the TCON support an LVDS output? */ bool polarity_in_ch0; /* some tcon1 channels have polarity bits in tcon0 pol register */ + bool basic1_vtotal; /* sun60i tcon-tv stores extended vtotal in BASIC1 */ + bool has_pixel_depth; /* sun60i tcon-tv has data io pol/tri and pixel depth regs */ u8 dclk_min_div; /* minimum divider for TCON0 DCLK */ /* callback to handle tcon muxing options */ diff --git a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c index 86e1e8fed03a..9a40a5b7df6d 100644 --- a/drivers/gpu/drm/sun4i/sun8i_tcon_top.c +++ b/drivers/gpu/drm/sun4i/sun8i_tcon_top.c @@ -10,6 +10,7 @@ #include <linux/of.h> #include <linux/of_graph.h> #include <linux/platform_device.h> +#include <linux/pm_runtime.h> #include <dt-bindings/clock/sun8i-tcon-top.h> @@ -18,6 +19,11 @@ struct sun8i_tcon_top_quirks { bool has_tcon_tv1; bool has_dsi; + /* + * DE-to-TCON routing is handled in DE3.5 TOP; pre-route TCON_TV0 + * to HDMI and clear TVE mode in TCON_TOP_TCON_TV_SETUP_REG. + */ + bool no_de_mux; }; static bool sun8i_tcon_top_node_is_tcon_top(struct device_node *node) @@ -109,6 +115,9 @@ int sun8i_tcon_top_de_config(struct device *dev, int mixer, int tcon) return -EINVAL; } + if (tcon_top->no_de_mux) + return 0; + if (mixer > 1) { dev_err(dev, "Mixer index is too high!\n"); return -EINVAL; @@ -193,10 +202,11 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master, clk_data->num = CLK_NUM; tcon_top->clk_data = clk_data; tcon_top->tcon_map = sun8i_tcon_top_get_tcon_map(dev->of_node); + tcon_top->no_de_mux = quirks->no_de_mux; spin_lock_init(&tcon_top->reg_lock); - tcon_top->rst = devm_reset_control_get(dev, NULL); + tcon_top->rst = devm_reset_control_array_get_exclusive(dev); if (IS_ERR(tcon_top->rst)) { dev_err(dev, "Couldn't get our reset line\n"); return PTR_ERR(tcon_top->rst); @@ -208,25 +218,49 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master, return PTR_ERR(tcon_top->bus); } + tcon_top->ahb = devm_clk_get_optional(dev, "ahb"); + if (IS_ERR(tcon_top->ahb)) + return PTR_ERR(tcon_top->ahb); + regs = devm_platform_ioremap_resource(pdev, 0); tcon_top->regs = regs; if (IS_ERR(regs)) return PTR_ERR(regs); + pm_runtime_enable(dev); + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + goto err_pm_disable; + ret = reset_control_deassert(tcon_top->rst); if (ret) { dev_err(dev, "Could not deassert ctrl reset control\n"); - return ret; + goto err_pm_put; + } + + ret = clk_prepare_enable(tcon_top->ahb); + if (ret) { + dev_err(dev, "Could not enable ahb clock\n"); + goto err_assert_reset; } ret = clk_prepare_enable(tcon_top->bus); if (ret) { dev_err(dev, "Could not enable bus clock\n"); - goto err_assert_reset; + goto err_disable_ahb; } - writel(0, regs + TCON_TOP_PORT_SEL_REG); - writel(0, regs + TCON_TOP_GATE_SRC_REG); + if (quirks->no_de_mux) { + writel(readl(regs + TCON_TOP_TCON_TV_SETUP_REG) & + ~TCON_TOP_TV_SETUP_TVE_MODE, + regs + TCON_TOP_TCON_TV_SETUP_REG); + /* Route TCON_TV0 as HDMI source so DW-HDMI bus access works */ + writel(FIELD_PREP(TCON_TOP_HDMI_SRC_MSK, 1), + regs + TCON_TOP_GATE_SRC_REG); + } else { + writel(0, regs + TCON_TOP_PORT_SEL_REG); + writel(0, regs + TCON_TOP_GATE_SRC_REG); + } /* * TCON TOP has two muxes, which select parent clock for each TCON TV @@ -274,8 +308,14 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master, if (!IS_ERR_OR_NULL(clk_data->hws[i])) clk_hw_unregister_gate(clk_data->hws[i]); clk_disable_unprepare(tcon_top->bus); +err_disable_ahb: + clk_disable_unprepare(tcon_top->ahb); err_assert_reset: reset_control_assert(tcon_top->rst); +err_pm_put: + pm_runtime_put_sync(dev); +err_pm_disable: + pm_runtime_disable(dev); return ret; } @@ -293,7 +333,10 @@ static void sun8i_tcon_top_unbind(struct device *dev, struct device *master, clk_hw_unregister_gate(clk_data->hws[i]); clk_disable_unprepare(tcon_top->bus); + clk_disable_unprepare(tcon_top->ahb); reset_control_assert(tcon_top->rst); + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); } static const struct component_ops sun8i_tcon_top_ops = { @@ -324,6 +367,10 @@ static const struct sun8i_tcon_top_quirks sun50i_h6_tcon_top_quirks = { /* Nothing special */ }; +static const struct sun8i_tcon_top_quirks sun60i_a733_tcon_top_quirks = { + .no_de_mux = true, +}; + /* sun4i_drv uses this list to check if a device node is a TCON TOP */ const struct of_device_id sun8i_tcon_top_of_table[] = { { @@ -338,6 +385,10 @@ const struct of_device_id sun8i_tcon_top_of_table[] = { .compatible = "allwinner,sun50i-h6-tcon-top", .data = &sun50i_h6_tcon_top_quirks }, + { + .compatible = "allwinner,sun60i-a733-tcon-top", + .data = &sun60i_a733_tcon_top_quirks + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, sun8i_tcon_top_of_table); diff --git a/drivers/gpu/drm/sun4i/sun8i_tcon_top.h b/drivers/gpu/drm/sun4i/sun8i_tcon_top.h index 2b887470a49f..2010672943a3 100644 --- a/drivers/gpu/drm/sun4i/sun8i_tcon_top.h +++ b/drivers/gpu/drm/sun4i/sun8i_tcon_top.h @@ -10,6 +10,7 @@ #include <linux/spinlock.h> #define TCON_TOP_TCON_TV_SETUP_REG 0x00 +#define TCON_TOP_TV_SETUP_TVE_MODE BIT(3) #define TCON_TOP_PORT_SEL_REG 0x1C #define TCON_TOP_PORT_DE0_MSK GENMASK(1, 0) @@ -29,11 +30,13 @@ struct sun8i_tcon_top { struct clk *bus; + struct clk *ahb; struct clk_hw_onecell_data *clk_data; void __iomem *regs; struct reset_control *rst; unsigned int tcon_map; + bool no_de_mux; /* * spinlock is used to synchronize access to same -- 2.53.0
