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
= {
62 .phyts_per_pixel
= VTAC_5_PPP
,
64 static const struct sti_vtac_mode vtac_mode_aux
= {
67 .phyts_per_pixel
= VTAC_17_PPP
,
73 * @dev: pointer to device structure
74 * @regs: ioremapped registers for RX and TX devices
75 * @phy_regs: phy registers for TX device
77 * @mode: main or auxillary configuration mode
82 void __iomem
*phy_regs
;
84 const struct sti_vtac_mode
*mode
;
87 static void sti_vtac_rx_set_config(struct sti_vtac
*vtac
)
91 /* Enable VTAC clock */
92 if (clk_prepare_enable(vtac
->clk
))
93 DRM_ERROR("Failed to prepare/enable vtac_rx clock.\n");
95 writel(VTAC_FIFO_CONFIG_VAL
, vtac
->regs
+ VTAC_RX_FIFO_CONFIG
);
98 config
|= vtac
->mode
->vid_in_width
<< 4;
99 config
|= vtac
->mode
->phyts_width
<< 16;
100 config
|= vtac
->mode
->phyts_per_pixel
<< 23;
101 writel(config
, vtac
->regs
+ VTAC_CONFIG
);
104 static void sti_vtac_tx_set_config(struct sti_vtac
*vtac
)
109 /* Enable VTAC clock */
110 if (clk_prepare_enable(vtac
->clk
))
111 DRM_ERROR("Failed to prepare/enable vtac_tx clock.\n");
113 /* Configure vtac phy */
114 phy_config
= 0x00000000;
115 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8522
);
116 phy_config
= VTAC_TX_PHY_ENABLE_CLK_PHY
;
117 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
118 phy_config
= readl(vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
119 phy_config
|= VTAC_TX_PHY_PROG_N3
;
120 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
121 phy_config
= readl(vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
122 phy_config
|= VTAC_TX_PHY_ENABLE_CLK_DLL
;
123 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
124 phy_config
= readl(vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
125 phy_config
|= VTAC_TX_PHY_RST_N_DLL_SWITCH
;
126 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
127 phy_config
= readl(vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
128 phy_config
|= VTAC_TX_PHY_PLL_NOT_OSC_MODE
;
129 writel(phy_config
, vtac
->phy_regs
+ VTAC_SYS_CFG8521
);
131 /* Configure vtac tx */
132 config
= VTAC_ENABLE
;
133 config
|= vtac
->mode
->vid_in_width
<< 4;
134 config
|= vtac
->mode
->phyts_width
<< 16;
135 config
|= vtac
->mode
->phyts_per_pixel
<< 23;
136 writel(config
, vtac
->regs
+ VTAC_CONFIG
);
139 static const struct of_device_id vtac_of_match
[] = {
141 .compatible
= "st,vtac-main",
142 .data
= &vtac_mode_main
,
144 .compatible
= "st,vtac-aux",
145 .data
= &vtac_mode_aux
,
150 MODULE_DEVICE_TABLE(of
, vtac_of_match
);
152 static int sti_vtac_probe(struct platform_device
*pdev
)
154 struct device
*dev
= &pdev
->dev
;
155 struct device_node
*np
= dev
->of_node
;
156 const struct of_device_id
*id
;
157 struct sti_vtac
*vtac
;
158 struct resource
*res
;
160 vtac
= devm_kzalloc(dev
, sizeof(*vtac
), GFP_KERNEL
);
166 id
= of_match_node(vtac_of_match
, np
);
170 vtac
->mode
= id
->data
;
172 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
174 DRM_ERROR("Invalid resource\n");
177 vtac
->regs
= devm_ioremap_resource(dev
, res
);
178 if (IS_ERR(vtac
->regs
))
179 return PTR_ERR(vtac
->regs
);
182 vtac
->clk
= devm_clk_get(dev
, "vtac");
183 if (IS_ERR(vtac
->clk
)) {
184 DRM_ERROR("Cannot get vtac clock\n");
185 return PTR_ERR(vtac
->clk
);
188 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
190 vtac
->phy_regs
= devm_ioremap_nocache(dev
, res
->start
,
192 sti_vtac_tx_set_config(vtac
);
195 sti_vtac_rx_set_config(vtac
);
198 platform_set_drvdata(pdev
, vtac
);
199 DRM_INFO("%s %s\n", __func__
, dev_name(vtac
->dev
));
204 static int sti_vtac_remove(struct platform_device
*pdev
)
209 struct platform_driver sti_vtac_driver
= {
212 .owner
= THIS_MODULE
,
213 .of_match_table
= vtac_of_match
,
215 .probe
= sti_vtac_probe
,
216 .remove
= sti_vtac_remove
,
219 MODULE_AUTHOR("Benjamin Gaignard <benjamin.gaignard@st.com>");
220 MODULE_DESCRIPTION("STMicroelectronics SoC DRM driver");
221 MODULE_LICENSE("GPL");