Input: xpad - add support for Xbox1 PDP Camo series gamepad
[linux/fpc-iii.git] / drivers / gpu / drm / sti / sti_vtac.c
blobcf7fe8a1db42e1b21b59ba9db7df431302d03259
1 /*
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
5 */
7 #include <linux/clk.h>
8 #include <linux/io.h>
9 #include <linux/module.h>
10 #include <linux/of.h>
11 #include <linux/platform_device.h>
13 #include <drm/drmP.h>
15 #include "sti_drv.h"
17 /* registers offset */
18 #define VTAC_CONFIG 0x00
19 #define VTAC_RX_FIFO_CONFIG 0x04
20 #define VTAC_FIFO_CONFIG_VAL 0x04
22 #define VTAC_SYS_CFG8521 0x824
23 #define VTAC_SYS_CFG8522 0x828
25 /* Number of phyts per pixel */
26 #define VTAC_2_5_PPP 0x0005
27 #define VTAC_3_PPP 0x0006
28 #define VTAC_4_PPP 0x0008
29 #define VTAC_5_PPP 0x000A
30 #define VTAC_6_PPP 0x000C
31 #define VTAC_13_PPP 0x001A
32 #define VTAC_14_PPP 0x001C
33 #define VTAC_15_PPP 0x001E
34 #define VTAC_16_PPP 0x0020
35 #define VTAC_17_PPP 0x0022
36 #define VTAC_18_PPP 0x0024
38 /* enable bits */
39 #define VTAC_ENABLE 0x3003
41 #define VTAC_TX_PHY_ENABLE_CLK_PHY BIT(0)
42 #define VTAC_TX_PHY_ENABLE_CLK_DLL BIT(1)
43 #define VTAC_TX_PHY_PLL_NOT_OSC_MODE BIT(3)
44 #define VTAC_TX_PHY_RST_N_DLL_SWITCH BIT(4)
45 #define VTAC_TX_PHY_PROG_N3 BIT(9)
48 /**
49 * VTAC mode structure
51 * @vid_in_width: Video Data Resolution
52 * @phyts_width: Width of phyt buses(phyt low and phyt high).
53 * @phyts_per_pixel: Number of phyts sent per pixel
55 struct sti_vtac_mode {
56 u32 vid_in_width;
57 u32 phyts_width;
58 u32 phyts_per_pixel;
61 static const struct sti_vtac_mode vtac_mode_main = {
62 .vid_in_width = 0x2,
63 .phyts_width = 0x2,
64 .phyts_per_pixel = VTAC_5_PPP,
66 static const struct sti_vtac_mode vtac_mode_aux = {
67 .vid_in_width = 0x1,
68 .phyts_width = 0x0,
69 .phyts_per_pixel = VTAC_17_PPP,
72 /**
73 * VTAC structure
75 * @dev: pointer to device structure
76 * @regs: ioremapped registers for RX and TX devices
77 * @phy_regs: phy registers for TX device
78 * @clk: clock
79 * @mode: main or auxillary configuration mode
81 struct sti_vtac {
82 struct device *dev;
83 void __iomem *regs;
84 void __iomem *phy_regs;
85 struct clk *clk;
86 const struct sti_vtac_mode *mode;
89 static void sti_vtac_rx_set_config(struct sti_vtac *vtac)
91 u32 config;
93 /* Enable VTAC clock */
94 if (clk_prepare_enable(vtac->clk))
95 DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n");
97 writel(VTAC_FIFO_CONFIG_VAL, vtac->regs + VTAC_RX_FIFO_CONFIG);
99 config = VTAC_ENABLE;
100 config |= vtac->mode->vid_in_width << 4;
101 config |= vtac->mode->phyts_width << 16;
102 config |= vtac->mode->phyts_per_pixel << 23;
103 writel(config, vtac->regs + VTAC_CONFIG);
106 static void sti_vtac_tx_set_config(struct sti_vtac *vtac)
108 u32 phy_config;
109 u32 config;
111 /* Enable VTAC clock */
112 if (clk_prepare_enable(vtac->clk))
113 DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n");
115 /* Configure vtac phy */
116 phy_config = 0x00000000;
117 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8522);
118 phy_config = VTAC_TX_PHY_ENABLE_CLK_PHY;
119 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
120 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
121 phy_config |= VTAC_TX_PHY_PROG_N3;
122 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
123 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
124 phy_config |= VTAC_TX_PHY_ENABLE_CLK_DLL;
125 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
126 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
127 phy_config |= VTAC_TX_PHY_RST_N_DLL_SWITCH;
128 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
129 phy_config = readl(vtac->phy_regs + VTAC_SYS_CFG8521);
130 phy_config |= VTAC_TX_PHY_PLL_NOT_OSC_MODE;
131 writel(phy_config, vtac->phy_regs + VTAC_SYS_CFG8521);
133 /* Configure vtac tx */
134 config = VTAC_ENABLE;
135 config |= vtac->mode->vid_in_width << 4;
136 config |= vtac->mode->phyts_width << 16;
137 config |= vtac->mode->phyts_per_pixel << 23;
138 writel(config, vtac->regs + VTAC_CONFIG);
141 static const struct of_device_id vtac_of_match[] = {
143 .compatible = "st,vtac-main",
144 .data = &vtac_mode_main,
145 }, {
146 .compatible = "st,vtac-aux",
147 .data = &vtac_mode_aux,
148 }, {
149 /* end node */
152 MODULE_DEVICE_TABLE(of, vtac_of_match);
154 static int sti_vtac_probe(struct platform_device *pdev)
156 struct device *dev = &pdev->dev;
157 struct device_node *np = dev->of_node;
158 const struct of_device_id *id;
159 struct sti_vtac *vtac;
160 struct resource *res;
162 vtac = devm_kzalloc(dev, sizeof(*vtac), GFP_KERNEL);
163 if (!vtac)
164 return -ENOMEM;
166 vtac->dev = dev;
168 id = of_match_node(vtac_of_match, np);
169 if (!id)
170 return -ENOMEM;
172 vtac->mode = id->data;
174 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
175 if (!res) {
176 DRM_ERROR("Invalid resource\n");
177 return -ENOMEM;
179 vtac->regs = devm_ioremap_resource(dev, res);
180 if (IS_ERR(vtac->regs))
181 return PTR_ERR(vtac->regs);
184 vtac->clk = devm_clk_get(dev, "vtac");
185 if (IS_ERR(vtac->clk)) {
186 DRM_ERROR("Cannot get vtac clock\n");
187 return PTR_ERR(vtac->clk);
190 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
191 if (res) {
192 vtac->phy_regs = devm_ioremap_nocache(dev, res->start,
193 resource_size(res));
194 sti_vtac_tx_set_config(vtac);
195 } else {
197 sti_vtac_rx_set_config(vtac);
200 platform_set_drvdata(pdev, vtac);
201 DRM_INFO("%s %s\n", __func__, dev_name(vtac->dev));
203 return 0;
206 static int sti_vtac_remove(struct platform_device *pdev)
208 return 0;
211 struct platform_driver sti_vtac_driver = {
212 .driver = {
213 .name = "sti-vtac",
214 .owner = THIS_MODULE,
215 .of_match_table = vtac_of_match,
217 .probe = sti_vtac_probe,
218 .remove = sti_vtac_remove,
221 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
222 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
223 MODULE_LICENSE("GPL");