Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/sun4i: tcon-top: Add helpers for mux switching

We want to be able to set TCON TOP muxes at runtime. Add helpers for
that.

Old, static configuration of muxes at probe time is preserved for now.
It will be removed when R40 TCON starts using them.

Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net>
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180710203511.18454-12-jernej.skrabec@siol.net

authored by

Jernej Skrabec and committed by
Maxime Ripard
05db311a e0f56782

+78
+74
drivers/gpu/drm/sun4i/sun8i_tcon_top.c
··· 14 14 15 15 #include "sun8i_tcon_top.h" 16 16 17 + static bool sun8i_tcon_top_node_is_tcon_top(struct device_node *node) 18 + { 19 + return !!of_match_node(sun8i_tcon_top_of_table, node); 20 + } 21 + 22 + int sun8i_tcon_top_set_hdmi_src(struct device *dev, int tcon) 23 + { 24 + struct sun8i_tcon_top *tcon_top = dev_get_drvdata(dev); 25 + unsigned long flags; 26 + u32 val; 27 + 28 + if (!sun8i_tcon_top_node_is_tcon_top(dev->of_node)) { 29 + dev_err(dev, "Device is not TCON TOP!\n"); 30 + return -EINVAL; 31 + } 32 + 33 + if (tcon < 2 || tcon > 3) { 34 + dev_err(dev, "TCON index must be 2 or 3!\n"); 35 + return -EINVAL; 36 + } 37 + 38 + spin_lock_irqsave(&tcon_top->reg_lock, flags); 39 + 40 + val = readl(tcon_top->regs + TCON_TOP_GATE_SRC_REG); 41 + val &= ~TCON_TOP_HDMI_SRC_MSK; 42 + val |= FIELD_PREP(TCON_TOP_HDMI_SRC_MSK, tcon - 1); 43 + writel(val, tcon_top->regs + TCON_TOP_GATE_SRC_REG); 44 + 45 + spin_unlock_irqrestore(&tcon_top->reg_lock, flags); 46 + 47 + return 0; 48 + } 49 + EXPORT_SYMBOL(sun8i_tcon_top_set_hdmi_src); 50 + 51 + int sun8i_tcon_top_de_config(struct device *dev, int mixer, int tcon) 52 + { 53 + struct sun8i_tcon_top *tcon_top = dev_get_drvdata(dev); 54 + unsigned long flags; 55 + u32 reg; 56 + 57 + if (!sun8i_tcon_top_node_is_tcon_top(dev->of_node)) { 58 + dev_err(dev, "Device is not TCON TOP!\n"); 59 + return -EINVAL; 60 + } 61 + 62 + if (mixer > 1) { 63 + dev_err(dev, "Mixer index is too high!\n"); 64 + return -EINVAL; 65 + } 66 + 67 + if (tcon > 3) { 68 + dev_err(dev, "TCON index is too high!\n"); 69 + return -EINVAL; 70 + } 71 + 72 + spin_lock_irqsave(&tcon_top->reg_lock, flags); 73 + 74 + reg = readl(tcon_top->regs + TCON_TOP_PORT_SEL_REG); 75 + if (mixer == 0) { 76 + reg &= ~TCON_TOP_PORT_DE0_MSK; 77 + reg |= FIELD_PREP(TCON_TOP_PORT_DE0_MSK, tcon); 78 + } else { 79 + reg &= ~TCON_TOP_PORT_DE1_MSK; 80 + reg |= FIELD_PREP(TCON_TOP_PORT_DE1_MSK, tcon); 81 + } 82 + writel(reg, tcon_top->regs + TCON_TOP_PORT_SEL_REG); 83 + 84 + spin_unlock_irqrestore(&tcon_top->reg_lock, flags); 85 + 86 + return 0; 87 + } 88 + EXPORT_SYMBOL(sun8i_tcon_top_de_config); 89 + 17 90 static int sun8i_tcon_top_get_connected_ep_id(struct device_node *node, 18 91 int port_id) 19 92 { ··· 182 109 183 110 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 184 111 regs = devm_ioremap_resource(dev, res); 112 + tcon_top->regs = regs; 185 113 if (IS_ERR(regs)) 186 114 return PTR_ERR(regs); 187 115
+4
drivers/gpu/drm/sun4i/sun8i_tcon_top.h
··· 26 26 struct sun8i_tcon_top { 27 27 struct clk *bus; 28 28 struct clk_hw_onecell_data *clk_data; 29 + void __iomem *regs; 29 30 struct reset_control *rst; 30 31 31 32 /* ··· 37 36 }; 38 37 39 38 extern const struct of_device_id sun8i_tcon_top_of_table[]; 39 + 40 + int sun8i_tcon_top_set_hdmi_src(struct device *dev, int tcon); 41 + int sun8i_tcon_top_de_config(struct device *dev, int mixer, int tcon); 40 42 41 43 #endif /* _SUN8I_TCON_TOP_H_ */