2 * Copyright (C) STMicroelectronics SA 2014
3 * Author: Benjamin Gaignard <benjamin.gaignard@st.com> for STMicroelectronics.
4 * License terms: GNU General Public License (GPL), version 2
9 #include <linux/module.h>
11 #include <linux/platform_device.h>
15 /* registers offset */
16 #define VTAC_CONFIG 0x00
17 #define VTAC_RX_FIFO_CONFIG 0x04
18 #define VTAC_FIFO_CONFIG_VAL 0x04
20 #define VTAC_SYS_CFG8521 0x824
21 #define VTAC_SYS_CFG8522 0x828
23 /* Number of phyts per pixel */
24 #define VTAC_2_5_PPP 0x0005
25 #define VTAC_3_PPP 0x0006
26 #define VTAC_4_PPP 0x0008
27 #define VTAC_5_PPP 0x000A
28 #define VTAC_6_PPP 0x000C
29 #define VTAC_13_PPP 0x001A
30 #define VTAC_14_PPP 0x001C
31 #define VTAC_15_PPP 0x001E
32 #define VTAC_16_PPP 0x0020
33 #define VTAC_17_PPP 0x0022
34 #define VTAC_18_PPP 0x0024
37 #define VTAC_ENABLE 0x3003
39 #define VTAC_TX_PHY_ENABLE_CLK_PHY BIT(0)
40 #define VTAC_TX_PHY_ENABLE_CLK_DLL BIT(1)
41 #define VTAC_TX_PHY_PLL_NOT_OSC_MODE BIT(3)
42 #define VTAC_TX_PHY_RST_N_DLL_SWITCH BIT(4)
43 #define VTAC_TX_PHY_PROG_N3 BIT(9)
49 * @vid_in_width: Video Data Resolution
50 * @phyts_width: Width of phyt buses(phyt low and phyt high).
51 * @phyts_per_pixel: Number of phyts sent per pixel
53 struct sti_vtac_mode {
59 static const struct sti_vtac_mode vtac_mode_main = {0x2, 0x2, VTAC_5_PPP};
60 static const struct sti_vtac_mode vtac_mode_aux = {0x1, 0x0, VTAC_17_PPP};
65 * @dev: pointer to device structure
66 * @regs: ioremapped registers for RX and TX devices
67 * @phy_regs: phy registers for TX device
69 * @mode: main or auxillary configuration mode
74 void __iomem *phy_regs;
76 const struct sti_vtac_mode *mode;
79 static void sti_vtac_rx_set_config(struct sti_vtac *vtac)
83 /* Enable VTAC clock */
84 if (clk_prepare_enable(vtac->clk))
85 DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n");
87 writel(VTAC_FIFO_CONFIG_VAL, vtac->regs + VTAC_RX_FIFO_CONFIG);
90 config |= vtac->mode->vid_in_width << 4;
91 config |= vtac->mode->phyts_width << 16;
92 config |= vtac->mode->phyts_per_pixel << 23;
93 writel(config, vtac->regs + VTAC_CONFIG);
96 static void sti_vtac_tx_set_config(struct sti_vtac *vtac)
101 /* Enable VTAC clock */
102 if (clk_prepare_enable(vtac->clk))
103 DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n");
105 /* Configure vtac phy */
106 phy_config = 0x00000000;
107 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8522);
108 phy_config = VTAC_TX_PHY_ENABLE_CLK_PHY;
109 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
110 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
111 phy_config |= VTAC_TX_PHY_PROG_N3;
112 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
113 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
114 phy_config |= VTAC_TX_PHY_ENABLE_CLK_DLL;
115 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
116 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
117 phy_config |= VTAC_TX_PHY_RST_N_DLL_SWITCH;
118 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
119 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
120 phy_config |= VTAC_TX_PHY_PLL_NOT_OSC_MODE;
121 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
123 /* Configure vtac tx */
124 config = VTAC_ENABLE;
125 config |= vtac->mode->vid_in_width << 4;
126 config |= vtac->mode->phyts_width << 16;
127 config |= vtac->mode->phyts_per_pixel << 23;
128 writel(config, vtac->regs + VTAC_CONFIG);
131 static const struct of_device_id vtac_of_match[] = {
133 .compatible = "st,vtac-main",
134 .data = &vtac_mode_main,
136 .compatible = "st,vtac-aux",
137 .data = &vtac_mode_aux,
142 MODULE_DEVICE_TABLE(of, vtac_of_match);
144 static int sti_vtac_probe(struct platform_device *pdev)
146 struct device *dev = &pdev->dev;
147 struct device_node *np = dev->of_node;
148 const struct of_device_id *id;
149 struct sti_vtac *vtac;
150 struct resource *res;
152 vtac = devm_kzalloc(dev, sizeof(*vtac), GFP_KERNEL);
158 id = of_match_node(vtac_of_match, np);
162 vtac->mode = id->data;
164 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
166 DRM_ERROR("Invalid resource\n");
169 vtac->regs = devm_ioremap_resource(dev, res);
170 if (IS_ERR(vtac->regs))
171 return PTR_ERR(vtac->regs);
174 vtac->clk = devm_clk_get(dev, "vtac");
175 if (IS_ERR(vtac->clk)) {
176 DRM_ERROR("Cannot get vtac clock\n");
177 return PTR_ERR(vtac->clk);
180 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
182 vtac->phy_regs = devm_ioremap_nocache(dev, res->start,
184 sti_vtac_tx_set_config(vtac);
187 sti_vtac_rx_set_config(vtac);
190 platform_set_drvdata(pdev, vtac);
191 DRM_INFO("%s %s\n", __func__, dev_name(vtac->dev));
196 static int sti_vtac_remove(struct platform_device *pdev)
201 struct platform_driver sti_vtac_driver = {
204 .owner = THIS_MODULE,
205 .of_match_table = vtac_of_match,
207 .probe = sti_vtac_probe,
208 .remove = sti_vtac_remove,
211 module_platform_driver(sti_vtac_driver);
213 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
214 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
215 MODULE_LICENSE("GPL");