1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (c) 2017 Rockchip Electronics Co. Ltd.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
5*4882a593Smuzhiyun * it under the terms of the GNU General Public License as published by
6*4882a593Smuzhiyun * the Free Software Foundation; either version 2 of the License, or
7*4882a593Smuzhiyun * (at your option) any later version.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful,
10*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12*4882a593Smuzhiyun * GNU General Public License for more details.
13*4882a593Smuzhiyun */
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #include <linux/clk.h>
16*4882a593Smuzhiyun #include <linux/clk-provider.h>
17*4882a593Smuzhiyun #include <linux/delay.h>
18*4882a593Smuzhiyun #include <linux/init.h>
19*4882a593Smuzhiyun #include <linux/interrupt.h>
20*4882a593Smuzhiyun #include <linux/io.h>
21*4882a593Smuzhiyun #include <linux/iopoll.h>
22*4882a593Smuzhiyun #include <linux/kernel.h>
23*4882a593Smuzhiyun #include <linux/module.h>
24*4882a593Smuzhiyun #include <linux/nvmem-consumer.h>
25*4882a593Smuzhiyun #include <linux/of.h>
26*4882a593Smuzhiyun #include <linux/phy/phy.h>
27*4882a593Smuzhiyun #include <linux/platform_device.h>
28*4882a593Smuzhiyun #include <linux/regmap.h>
29*4882a593Smuzhiyun #include <linux/rockchip/cpu.h>
30*4882a593Smuzhiyun #include <linux/slab.h>
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun #define INNO_HDMI_PHY_TIMEOUT_LOOP_COUNT 1000
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define UPDATE(x, h, l) (((x) << (l)) & GENMASK((h), (l)))
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun /* REG: 0x00 */
37*4882a593Smuzhiyun #define PRE_PLL_REFCLK_SEL_MASK BIT(0)
38*4882a593Smuzhiyun #define PRE_PLL_REFCLK_SEL_PCLK BIT(0)
39*4882a593Smuzhiyun #define PRE_PLL_REFCLK_SEL_OSCCLK 0
40*4882a593Smuzhiyun /* REG: 0x01 */
41*4882a593Smuzhiyun #define BYPASS_RXSENSE_EN_MASK BIT(2)
42*4882a593Smuzhiyun #define BYPASS_RXSENSE_EN BIT(2)
43*4882a593Smuzhiyun #define BYPASS_PWRON_EN_MASK BIT(1)
44*4882a593Smuzhiyun #define BYPASS_PWRON_EN BIT(1)
45*4882a593Smuzhiyun #define BYPASS_PLLPD_EN_MASK BIT(0)
46*4882a593Smuzhiyun #define BYPASS_PLLPD_EN BIT(0)
47*4882a593Smuzhiyun /* REG: 0x02 */
48*4882a593Smuzhiyun #define BYPASS_PDATA_EN_MASK BIT(4)
49*4882a593Smuzhiyun #define BYPASS_PDATA_EN BIT(4)
50*4882a593Smuzhiyun #define PDATAEN_MASK BIT(0)
51*4882a593Smuzhiyun #define PDATAEN_DISABLE BIT(0)
52*4882a593Smuzhiyun #define PDATAEN_ENABLE 0
53*4882a593Smuzhiyun /* REG: 0x03 */
54*4882a593Smuzhiyun #define BYPASS_AUTO_TERM_RES_CAL BIT(7)
55*4882a593Smuzhiyun #define AUDO_TERM_RES_CAL_SPEED_14_8(x) UPDATE(x, 6, 0)
56*4882a593Smuzhiyun /* REG: 0x04 */
57*4882a593Smuzhiyun #define AUDO_TERM_RES_CAL_SPEED_7_0(x) UPDATE(x, 7, 0)
58*4882a593Smuzhiyun /* REG: 0xaa */
59*4882a593Smuzhiyun #define POST_PLL_CTRL_MASK BIT(0)
60*4882a593Smuzhiyun #define POST_PLL_CTRL_MANUAL BIT(0)
61*4882a593Smuzhiyun /* REG: 0xe0 */
62*4882a593Smuzhiyun #define POST_PLL_POWER_MASK BIT(5)
63*4882a593Smuzhiyun #define POST_PLL_POWER_DOWN BIT(5)
64*4882a593Smuzhiyun #define POST_PLL_POWER_UP 0
65*4882a593Smuzhiyun #define PRE_PLL_POWER_MASK BIT(4)
66*4882a593Smuzhiyun #define PRE_PLL_POWER_DOWN BIT(4)
67*4882a593Smuzhiyun #define PRE_PLL_POWER_UP 0
68*4882a593Smuzhiyun #define RXSENSE_CLK_CH_MASK BIT(3)
69*4882a593Smuzhiyun #define RXSENSE_CLK_CH_ENABLE BIT(3)
70*4882a593Smuzhiyun #define RXSENSE_DATA_CH2_MASK BIT(2)
71*4882a593Smuzhiyun #define RXSENSE_DATA_CH2_ENABLE BIT(2)
72*4882a593Smuzhiyun #define RXSENSE_DATA_CH1_MASK BIT(1)
73*4882a593Smuzhiyun #define RXSENSE_DATA_CH1_ENABLE BIT(1)
74*4882a593Smuzhiyun #define RXSENSE_DATA_CH0_MASK BIT(0)
75*4882a593Smuzhiyun #define RXSENSE_DATA_CH0_ENABLE BIT(0)
76*4882a593Smuzhiyun /* REG: 0xe1 */
77*4882a593Smuzhiyun #define BANDGAP_MASK BIT(4)
78*4882a593Smuzhiyun #define BANDGAP_ENABLE BIT(4)
79*4882a593Smuzhiyun #define BANDGAP_DISABLE 0
80*4882a593Smuzhiyun #define TMDS_DRIVER_MASK GENMASK(3, 0)
81*4882a593Smuzhiyun #define TMDS_DRIVER_ENABLE UPDATE(0xf, 3, 0)
82*4882a593Smuzhiyun #define TMDS_DRIVER_DISABLE 0
83*4882a593Smuzhiyun /* REG: 0xe2 */
84*4882a593Smuzhiyun #define PRE_PLL_FB_DIV_8_MASK BIT(7)
85*4882a593Smuzhiyun #define PRE_PLL_FB_DIV_8_SHIFT 7
86*4882a593Smuzhiyun #define PRE_PLL_FB_DIV_8(x) UPDATE(x, 7, 7)
87*4882a593Smuzhiyun #define PCLK_VCO_DIV_5_MASK BIT(5)
88*4882a593Smuzhiyun #define PCLK_VCO_DIV_5_SHIFT 5
89*4882a593Smuzhiyun #define PCLK_VCO_DIV_5(x) UPDATE(x, 5, 5)
90*4882a593Smuzhiyun #define PRE_PLL_PRE_DIV_MASK GENMASK(4, 0)
91*4882a593Smuzhiyun #define PRE_PLL_PRE_DIV(x) UPDATE(x, 4, 0)
92*4882a593Smuzhiyun /* REG: 0xe3 */
93*4882a593Smuzhiyun #define PRE_PLL_FB_DIV_7_0(x) UPDATE(x, 7, 0)
94*4882a593Smuzhiyun /* REG: 0xe4 */
95*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_B_MASK GENMASK(6, 5)
96*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_B_SHIFT 5
97*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_B(x) UPDATE(x, 6, 5)
98*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_A_MASK GENMASK(4, 0)
99*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_A_SHIFT 0
100*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_A(x) UPDATE(x, 4, 0)
101*4882a593Smuzhiyun /* REG: 0xe5 */
102*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_C_MASK GENMASK(6, 5)
103*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_C_SHIFT 5
104*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_C(x) UPDATE(x, 6, 5)
105*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_D_MASK GENMASK(4, 0)
106*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_D_SHIFT 0
107*4882a593Smuzhiyun #define PRE_PLL_PCLK_DIV_D(x) UPDATE(x, 4, 0)
108*4882a593Smuzhiyun /* REG: 0xe6 */
109*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_C_MASK GENMASK(5, 4)
110*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_C(x) UPDATE(x, 5, 4)
111*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_A_MASK GENMASK(3, 2)
112*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_A(x) UPDATE(x, 3, 2)
113*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_B_MASK GENMASK(1, 0)
114*4882a593Smuzhiyun #define PRE_PLL_TMDSCLK_DIV_B(x) UPDATE(x, 1, 0)
115*4882a593Smuzhiyun /* REG: 0xe8 */
116*4882a593Smuzhiyun #define PRE_PLL_LOCK_STATUS BIT(0)
117*4882a593Smuzhiyun /* REG: 0xe9 */
118*4882a593Smuzhiyun #define POST_PLL_POST_DIV_EN_MASK GENMASK(7, 6)
119*4882a593Smuzhiyun #define POST_PLL_POST_DIV_ENABLE UPDATE(3, 7, 6)
120*4882a593Smuzhiyun #define POST_PLL_POST_DIV_DISABLE 0
121*4882a593Smuzhiyun #define POST_PLL_PRE_DIV_MASK GENMASK(4, 0)
122*4882a593Smuzhiyun #define POST_PLL_PRE_DIV(x) UPDATE(x, 4, 0)
123*4882a593Smuzhiyun /* REG: 0xea */
124*4882a593Smuzhiyun #define POST_PLL_FB_DIV_7_0(x) UPDATE(x, 7, 0)
125*4882a593Smuzhiyun /* REG: 0xeb */
126*4882a593Smuzhiyun #define POST_PLL_FB_DIV_8_MASK BIT(7)
127*4882a593Smuzhiyun #define POST_PLL_FB_DIV_8(x) UPDATE(x, 7, 7)
128*4882a593Smuzhiyun #define POST_PLL_POST_DIV_MASK GENMASK(5, 4)
129*4882a593Smuzhiyun #define POST_PLL_POST_DIV(x) UPDATE(x, 5, 4)
130*4882a593Smuzhiyun #define POST_PLL_LOCK_STATUS BIT(0)
131*4882a593Smuzhiyun /* REG: 0xee */
132*4882a593Smuzhiyun #define TMDS_CH_TA_MASK GENMASK(7, 4)
133*4882a593Smuzhiyun #define TMDS_CH_TA_ENABLE UPDATE(0xf, 7, 4)
134*4882a593Smuzhiyun #define TMDS_CH_TA_DISABLE 0
135*4882a593Smuzhiyun /* REG: 0xef */
136*4882a593Smuzhiyun #define TMDS_CLK_CH_TA(x) UPDATE(x, 7, 6)
137*4882a593Smuzhiyun #define TMDS_DATA_CH2_TA(x) UPDATE(x, 5, 4)
138*4882a593Smuzhiyun #define TMDS_DATA_CH1_TA(x) UPDATE(x, 3, 2)
139*4882a593Smuzhiyun #define TMDS_DATA_CH0_TA(x) UPDATE(x, 1, 0)
140*4882a593Smuzhiyun /* REG: 0xf0 */
141*4882a593Smuzhiyun #define TMDS_DATA_CH2_PRE_EMPHASIS_MASK GENMASK(5, 4)
142*4882a593Smuzhiyun #define TMDS_DATA_CH2_PRE_EMPHASIS(x) UPDATE(x, 5, 4)
143*4882a593Smuzhiyun #define TMDS_DATA_CH1_PRE_EMPHASIS_MASK GENMASK(3, 2)
144*4882a593Smuzhiyun #define TMDS_DATA_CH1_PRE_EMPHASIS(x) UPDATE(x, 3, 2)
145*4882a593Smuzhiyun #define TMDS_DATA_CH0_PRE_EMPHASIS_MASK GENMASK(1, 0)
146*4882a593Smuzhiyun #define TMDS_DATA_CH0_PRE_EMPHASIS(x) UPDATE(x, 1, 0)
147*4882a593Smuzhiyun /* REG: 0xf1 */
148*4882a593Smuzhiyun #define TMDS_CLK_CH_OUTPUT_SWING(x) UPDATE(x, 7, 4)
149*4882a593Smuzhiyun #define TMDS_DATA_CH2_OUTPUT_SWING(x) UPDATE(x, 3, 0)
150*4882a593Smuzhiyun /* REG: 0xf2 */
151*4882a593Smuzhiyun #define TMDS_DATA_CH1_OUTPUT_SWING(x) UPDATE(x, 7, 4)
152*4882a593Smuzhiyun #define TMDS_DATA_CH0_OUTPUT_SWING(x) UPDATE(x, 3, 0)
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun enum inno_hdmi_phy_type {
155*4882a593Smuzhiyun INNO_HDMI_PHY_RK3228,
156*4882a593Smuzhiyun INNO_HDMI_PHY_RK3328,
157*4882a593Smuzhiyun INNO_HDMI_PHY_RK3528
158*4882a593Smuzhiyun };
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun struct phy_config {
161*4882a593Smuzhiyun unsigned long tmdsclock;
162*4882a593Smuzhiyun u8 regs[14];
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun struct inno_hdmi_phy_drv_data;
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun struct inno_hdmi_phy {
168*4882a593Smuzhiyun struct device *dev;
169*4882a593Smuzhiyun struct regmap *regmap;
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun int irq;
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun struct phy *phy;
174*4882a593Smuzhiyun struct clk *sysclk;
175*4882a593Smuzhiyun struct phy_config *phy_cfg;
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun /* platform data */
178*4882a593Smuzhiyun struct inno_hdmi_phy_drv_data *plat_data;
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun /* efuse flag */
181*4882a593Smuzhiyun bool efuse_flag;
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun /* clk provider */
184*4882a593Smuzhiyun struct clk_hw hw;
185*4882a593Smuzhiyun struct clk *pclk;
186*4882a593Smuzhiyun unsigned long pixclock;
187*4882a593Smuzhiyun unsigned long tmdsclock;
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun struct pre_pll_config {
191*4882a593Smuzhiyun unsigned long pixclock;
192*4882a593Smuzhiyun unsigned long tmdsclock;
193*4882a593Smuzhiyun u8 prediv;
194*4882a593Smuzhiyun u16 fbdiv;
195*4882a593Smuzhiyun u8 tmds_div_a;
196*4882a593Smuzhiyun u8 tmds_div_b;
197*4882a593Smuzhiyun u8 tmds_div_c;
198*4882a593Smuzhiyun u8 pclk_div_a;
199*4882a593Smuzhiyun u8 pclk_div_b;
200*4882a593Smuzhiyun u8 pclk_div_c;
201*4882a593Smuzhiyun u8 pclk_div_d;
202*4882a593Smuzhiyun u8 vco_div_5_en;
203*4882a593Smuzhiyun u32 fracdiv;
204*4882a593Smuzhiyun };
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun struct post_pll_config {
207*4882a593Smuzhiyun unsigned long tmdsclock;
208*4882a593Smuzhiyun u8 prediv;
209*4882a593Smuzhiyun u16 fbdiv;
210*4882a593Smuzhiyun u8 postdiv;
211*4882a593Smuzhiyun u8 version;
212*4882a593Smuzhiyun };
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun struct inno_hdmi_phy_ops {
215*4882a593Smuzhiyun void (*init)(struct inno_hdmi_phy *inno);
216*4882a593Smuzhiyun int (*power_on)(struct inno_hdmi_phy *inno,
217*4882a593Smuzhiyun const struct post_pll_config *cfg,
218*4882a593Smuzhiyun const struct phy_config *phy_cfg);
219*4882a593Smuzhiyun void (*power_off)(struct inno_hdmi_phy *inno);
220*4882a593Smuzhiyun int (*pre_pll_update)(struct inno_hdmi_phy *inno,
221*4882a593Smuzhiyun const struct pre_pll_config *cfg);
222*4882a593Smuzhiyun unsigned long (*recalc_rate)(struct inno_hdmi_phy *inno,
223*4882a593Smuzhiyun unsigned long parent_rate);
224*4882a593Smuzhiyun };
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun struct inno_hdmi_phy_drv_data {
227*4882a593Smuzhiyun enum inno_hdmi_phy_type dev_type;
228*4882a593Smuzhiyun const struct inno_hdmi_phy_ops *ops;
229*4882a593Smuzhiyun const struct phy_config *phy_cfg_table;
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun /*
233*4882a593Smuzhiyun * If only using integer freq div can't get frequency we want, frac
234*4882a593Smuzhiyun * freq div is needed. For example, pclk 88.75 Mhz and tmdsclk
235*4882a593Smuzhiyun * 110.9375 Mhz must use frac div 0xF00000. The actual frequency is different
236*4882a593Smuzhiyun * from the target frequency. Such as the tmds clock 110.9375 Mhz,
237*4882a593Smuzhiyun * the actual tmds clock we get is 110.93719 Mhz. It is important
238*4882a593Smuzhiyun * to note that RK322X platforms do not support frac div.
239*4882a593Smuzhiyun */
240*4882a593Smuzhiyun static const struct pre_pll_config pre_pll_cfg_table[] = {
241*4882a593Smuzhiyun { 27000000, 27000000, 1, 90, 3, 2, 2, 10, 3, 3, 4, 0, 0},
242*4882a593Smuzhiyun { 27000000, 33750000, 1, 90, 1, 3, 3, 10, 3, 3, 4, 0, 0},
243*4882a593Smuzhiyun { 40000000, 40000000, 1, 80, 2, 2, 2, 12, 2, 2, 2, 0, 0},
244*4882a593Smuzhiyun { 40000000, 50000000, 1, 100, 2, 2, 2, 1, 0, 0, 15, 0, 0},
245*4882a593Smuzhiyun { 59341000, 59341000, 1, 98, 3, 1, 2, 1, 3, 3, 4, 0, 0xE6AE6B},
246*4882a593Smuzhiyun { 59400000, 59400000, 1, 99, 3, 1, 1, 1, 3, 3, 4, 0, 0},
247*4882a593Smuzhiyun { 59341000, 74176250, 1, 98, 0, 3, 3, 1, 3, 3, 4, 0, 0xE6AE6B},
248*4882a593Smuzhiyun { 59400000, 74250000, 1, 99, 1, 2, 2, 1, 3, 3, 4, 0, 0},
249*4882a593Smuzhiyun { 65000000, 65000000, 1, 130, 2, 2, 2, 1, 0, 0, 12, 0, 0},
250*4882a593Smuzhiyun { 65000000, 81250000, 3, 325, 0, 3, 3, 1, 0, 0, 10, 0, 0},
251*4882a593Smuzhiyun { 71000000, 71000000, 3, 284, 0, 3, 3, 1, 0, 0, 8, 0, 0},
252*4882a593Smuzhiyun { 71000000, 88750000, 3, 355, 0, 3, 3, 1, 0, 0, 10, 0, 0},
253*4882a593Smuzhiyun { 74176000, 74176000, 1, 98, 1, 2, 2, 1, 2, 3, 4, 0, 0xE6AE6B},
254*4882a593Smuzhiyun { 74250000, 74250000, 1, 99, 1, 2, 2, 1, 2, 3, 4, 0, 0},
255*4882a593Smuzhiyun { 74176000, 92720000, 4, 494, 1, 2, 2, 1, 3, 3, 4, 0, 0x816817},
256*4882a593Smuzhiyun { 74250000, 92812500, 4, 495, 1, 2, 2, 1, 3, 3, 4, 0, 0},
257*4882a593Smuzhiyun { 83500000, 83500000, 2, 167, 2, 1, 1, 1, 0, 0, 6, 0, 0},
258*4882a593Smuzhiyun { 83500000, 104375000, 1, 104, 2, 1, 1, 1, 1, 0, 5, 0, 0x600000},
259*4882a593Smuzhiyun { 85750000, 85750000, 3, 343, 0, 3, 3, 1, 0, 0, 8, 0, 0},
260*4882a593Smuzhiyun { 88750000, 88750000, 3, 355, 0, 3, 3, 1, 0, 0, 8, 0, 0},
261*4882a593Smuzhiyun { 88750000, 110937500, 1, 110, 2, 1, 1, 1, 1, 0, 5, 0, 0xF00000},
262*4882a593Smuzhiyun {108000000, 108000000, 1, 90, 3, 0, 0, 1, 0, 0, 5, 0, 0},
263*4882a593Smuzhiyun {108000000, 135000000, 1, 90, 0, 2, 2, 1, 0, 0, 5, 0, 0},
264*4882a593Smuzhiyun {119000000, 119000000, 1, 119, 2, 1, 1, 1, 0, 0, 6, 0, 0},
265*4882a593Smuzhiyun {119000000, 148750000, 1, 99, 0, 2, 2, 1, 0, 0, 5, 0, 0x2AAAAA},
266*4882a593Smuzhiyun {148352000, 148352000, 1, 98, 1, 1, 1, 1, 2, 2, 2, 0, 0xE6AE6B},
267*4882a593Smuzhiyun {148500000, 148500000, 1, 99, 1, 1, 1, 1, 2, 2, 2, 0, 0},
268*4882a593Smuzhiyun {148352000, 185440000, 4, 494, 0, 2, 2, 1, 3, 2, 2, 0, 0x816817},
269*4882a593Smuzhiyun {148500000, 185625000, 4, 495, 0, 2, 2, 1, 3, 2, 2, 0, 0},
270*4882a593Smuzhiyun {162000000, 162000000, 1, 108, 0, 2, 2, 1, 0, 0, 4, 0, 0},
271*4882a593Smuzhiyun {162000000, 202500000, 1, 135, 0, 2, 2, 1, 0, 0, 5, 0, 0},
272*4882a593Smuzhiyun {296703000, 296703000, 1, 98, 0, 1, 1, 1, 0, 2, 2, 0, 0xE6AE6B},
273*4882a593Smuzhiyun {297000000, 297000000, 1, 99, 0, 1, 1, 1, 0, 2, 2, 0, 0},
274*4882a593Smuzhiyun {296703000, 370878750, 4, 494, 1, 2, 0, 1, 3, 1, 1, 0, 0x816817},
275*4882a593Smuzhiyun {297000000, 371250000, 4, 495, 1, 2, 0, 1, 3, 1, 1, 0, 0},
276*4882a593Smuzhiyun {593407000, 296703500, 1, 98, 0, 1, 1, 1, 0, 2, 1, 0, 0xE6AE6B},
277*4882a593Smuzhiyun {594000000, 297000000, 1, 99, 0, 1, 1, 1, 0, 2, 1, 0, 0},
278*4882a593Smuzhiyun {593407000, 370879375, 4, 494, 1, 2, 0, 1, 3, 1, 1, 1, 0x816817},
279*4882a593Smuzhiyun {594000000, 371250000, 4, 495, 1, 2, 0, 1, 3, 1, 1, 1, 0},
280*4882a593Smuzhiyun {593407000, 593407000, 1, 98, 0, 2, 0, 1, 0, 1, 1, 0, 0xE6AE6B},
281*4882a593Smuzhiyun {594000000, 594000000, 1, 99, 0, 2, 0, 1, 0, 1, 1, 0, 0},
282*4882a593Smuzhiyun { ~0UL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
283*4882a593Smuzhiyun };
284*4882a593Smuzhiyun
285*4882a593Smuzhiyun static const struct post_pll_config post_pll_cfg_table[] = {
286*4882a593Smuzhiyun {33750000, 1, 40, 8, 1},
287*4882a593Smuzhiyun {33750000, 1, 80, 8, 2},
288*4882a593Smuzhiyun {33750000, 1, 10, 2, 4},
289*4882a593Smuzhiyun {74250000, 1, 40, 8, 1},
290*4882a593Smuzhiyun {74250000, 18, 80, 8, 2},
291*4882a593Smuzhiyun {74250000, 1, 20, 4, 8},
292*4882a593Smuzhiyun {148500000, 2, 40, 4, 3},
293*4882a593Smuzhiyun {148500000, 1, 10, 2, 8},
294*4882a593Smuzhiyun {297000000, 4, 40, 2, 3},
295*4882a593Smuzhiyun {297000000, 2, 20, 2, 8},
296*4882a593Smuzhiyun {594000000, 8, 40, 1, 3},
297*4882a593Smuzhiyun {594000000, 4, 20, 1, 8},
298*4882a593Smuzhiyun { ~0UL, 0, 0, 0, 0}
299*4882a593Smuzhiyun };
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun static const struct phy_config rk3228_phy_cfg[] = {
302*4882a593Smuzhiyun { 165000000, {
303*4882a593Smuzhiyun 0xaa, 0x00, 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00,
304*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
305*4882a593Smuzhiyun },
306*4882a593Smuzhiyun }, {
307*4882a593Smuzhiyun 340000000, {
308*4882a593Smuzhiyun 0xaa, 0x15, 0x6a, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00,
309*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
310*4882a593Smuzhiyun },
311*4882a593Smuzhiyun }, {
312*4882a593Smuzhiyun 594000000, {
313*4882a593Smuzhiyun 0xaa, 0x15, 0x7a, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00,
314*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
315*4882a593Smuzhiyun },
316*4882a593Smuzhiyun }, {
317*4882a593Smuzhiyun ~0UL, {
318*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
320*4882a593Smuzhiyun },
321*4882a593Smuzhiyun }
322*4882a593Smuzhiyun };
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun static const struct phy_config rk3328_phy_cfg[] = {
325*4882a593Smuzhiyun { 165000000, {
326*4882a593Smuzhiyun 0x07, 0x0a, 0x0a, 0x0a, 0x00, 0x00, 0x08, 0x08, 0x08,
327*4882a593Smuzhiyun 0x00, 0xac, 0xcc, 0xcc, 0xcc,
328*4882a593Smuzhiyun },
329*4882a593Smuzhiyun }, {
330*4882a593Smuzhiyun 340000000, {
331*4882a593Smuzhiyun 0x0b, 0x0d, 0x0d, 0x0d, 0x07, 0x15, 0x08, 0x08, 0x08,
332*4882a593Smuzhiyun 0x3f, 0xac, 0xcc, 0xcd, 0xdd,
333*4882a593Smuzhiyun },
334*4882a593Smuzhiyun }, {
335*4882a593Smuzhiyun 594000000, {
336*4882a593Smuzhiyun 0x10, 0x1a, 0x1a, 0x1a, 0x07, 0x15, 0x08, 0x08, 0x08,
337*4882a593Smuzhiyun 0x00, 0xac, 0xcc, 0xcc, 0xcc,
338*4882a593Smuzhiyun },
339*4882a593Smuzhiyun }, {
340*4882a593Smuzhiyun ~0UL, {
341*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
342*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
343*4882a593Smuzhiyun },
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun };
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun static const struct phy_config rk3528_phy_cfg[] = {
348*4882a593Smuzhiyun /* tmdsclk bias-clk bias-data voltage-clk voltage-data pre-emphasis-data */
349*4882a593Smuzhiyun { 165000000, {
350*4882a593Smuzhiyun 0x03, 0x04, 0x0c, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
351*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
352*4882a593Smuzhiyun },
353*4882a593Smuzhiyun }, {
354*4882a593Smuzhiyun 340000000, {
355*4882a593Smuzhiyun 0x03, 0x04, 0x0c, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00,
356*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
357*4882a593Smuzhiyun },
358*4882a593Smuzhiyun }, {
359*4882a593Smuzhiyun 594000000, {
360*4882a593Smuzhiyun 0x02, 0x08, 0x0d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00,
361*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
362*4882a593Smuzhiyun },
363*4882a593Smuzhiyun }, {
364*4882a593Smuzhiyun ~0UL, {
365*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
366*4882a593Smuzhiyun 0x00, 0x00, 0x00, 0x00, 0x00,
367*4882a593Smuzhiyun },
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun };
370*4882a593Smuzhiyun
to_inno_hdmi_phy(struct clk_hw * hw)371*4882a593Smuzhiyun static inline struct inno_hdmi_phy *to_inno_hdmi_phy(struct clk_hw *hw)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun return container_of(hw, struct inno_hdmi_phy, hw);
374*4882a593Smuzhiyun }
375*4882a593Smuzhiyun
inno_write(struct inno_hdmi_phy * inno,u32 reg,u8 val)376*4882a593Smuzhiyun static inline void inno_write(struct inno_hdmi_phy *inno, u32 reg, u8 val)
377*4882a593Smuzhiyun {
378*4882a593Smuzhiyun regmap_write(inno->regmap, reg * 4, val);
379*4882a593Smuzhiyun }
380*4882a593Smuzhiyun
inno_read(struct inno_hdmi_phy * inno,u32 reg)381*4882a593Smuzhiyun static inline u8 inno_read(struct inno_hdmi_phy *inno, u32 reg)
382*4882a593Smuzhiyun {
383*4882a593Smuzhiyun u32 val;
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun regmap_read(inno->regmap, reg * 4, &val);
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun return val;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
inno_update_bits(struct inno_hdmi_phy * inno,u8 reg,u8 mask,u8 val)390*4882a593Smuzhiyun static inline void inno_update_bits(struct inno_hdmi_phy *inno, u8 reg,
391*4882a593Smuzhiyun u8 mask, u8 val)
392*4882a593Smuzhiyun {
393*4882a593Smuzhiyun regmap_update_bits(inno->regmap, reg * 4, mask, val);
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
inno_hdmi_phy_get_tmdsclk(struct inno_hdmi_phy * inno,int rate)396*4882a593Smuzhiyun static u32 inno_hdmi_phy_get_tmdsclk(struct inno_hdmi_phy *inno, int rate)
397*4882a593Smuzhiyun {
398*4882a593Smuzhiyun int bus_width = phy_get_bus_width(inno->phy);
399*4882a593Smuzhiyun u32 tmdsclk;
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun switch (bus_width) {
402*4882a593Smuzhiyun case 4:
403*4882a593Smuzhiyun tmdsclk = (u32)rate / 2;
404*4882a593Smuzhiyun break;
405*4882a593Smuzhiyun case 5:
406*4882a593Smuzhiyun tmdsclk = (u32)rate * 5 / 8;
407*4882a593Smuzhiyun break;
408*4882a593Smuzhiyun case 6:
409*4882a593Smuzhiyun tmdsclk = (u32)rate * 3 / 4;
410*4882a593Smuzhiyun break;
411*4882a593Smuzhiyun case 10:
412*4882a593Smuzhiyun tmdsclk = (u32)rate * 5 / 4;
413*4882a593Smuzhiyun break;
414*4882a593Smuzhiyun case 12:
415*4882a593Smuzhiyun tmdsclk = (u32)rate * 3 / 2;
416*4882a593Smuzhiyun break;
417*4882a593Smuzhiyun case 16:
418*4882a593Smuzhiyun tmdsclk = (u32)rate * 2;
419*4882a593Smuzhiyun break;
420*4882a593Smuzhiyun default:
421*4882a593Smuzhiyun tmdsclk = rate;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun return tmdsclk;
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun
inno_hdmi_phy_hardirq(int irq,void * dev_id)427*4882a593Smuzhiyun static irqreturn_t inno_hdmi_phy_hardirq(int irq, void *dev_id)
428*4882a593Smuzhiyun {
429*4882a593Smuzhiyun struct inno_hdmi_phy *inno = dev_id;
430*4882a593Smuzhiyun int intr_stat1, intr_stat2, intr_stat3;
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228)
433*4882a593Smuzhiyun return IRQ_NONE;
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun intr_stat1 = inno_read(inno, 0x04);
436*4882a593Smuzhiyun intr_stat2 = inno_read(inno, 0x06);
437*4882a593Smuzhiyun intr_stat3 = inno_read(inno, 0x08);
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun if (intr_stat1)
440*4882a593Smuzhiyun inno_write(inno, 0x04, intr_stat1);
441*4882a593Smuzhiyun if (intr_stat2)
442*4882a593Smuzhiyun inno_write(inno, 0x06, intr_stat2);
443*4882a593Smuzhiyun if (intr_stat3)
444*4882a593Smuzhiyun inno_write(inno, 0x08, intr_stat3);
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun if (intr_stat1 || intr_stat2 || intr_stat3)
447*4882a593Smuzhiyun return IRQ_WAKE_THREAD;
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun return IRQ_HANDLED;
450*4882a593Smuzhiyun }
451*4882a593Smuzhiyun
inno_hdmi_phy_irq(int irq,void * dev_id)452*4882a593Smuzhiyun static irqreturn_t inno_hdmi_phy_irq(int irq, void *dev_id)
453*4882a593Smuzhiyun {
454*4882a593Smuzhiyun struct inno_hdmi_phy *inno = dev_id;
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228)
457*4882a593Smuzhiyun return IRQ_NONE;
458*4882a593Smuzhiyun /* set pdata_en to 0 */
459*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 0);
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun udelay(10);
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun /* set pdata_en to 1 */
464*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 1);
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun return IRQ_HANDLED;
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun static int inno_hdmi_phy_clk_set_rate(struct clk_hw *hw, unsigned long rate,
470*4882a593Smuzhiyun unsigned long parent_rate);
471*4882a593Smuzhiyun
inno_hdmi_phy_power_on(struct phy * phy)472*4882a593Smuzhiyun static int inno_hdmi_phy_power_on(struct phy *phy)
473*4882a593Smuzhiyun {
474*4882a593Smuzhiyun struct inno_hdmi_phy *inno = phy_get_drvdata(phy);
475*4882a593Smuzhiyun const struct post_pll_config *cfg = post_pll_cfg_table;
476*4882a593Smuzhiyun const struct phy_config *phy_cfg = inno->plat_data->phy_cfg_table;
477*4882a593Smuzhiyun u32 tmdsclock = inno_hdmi_phy_get_tmdsclk(inno, inno->pixclock);
478*4882a593Smuzhiyun u32 chipversion = 1;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun if (inno->phy_cfg)
481*4882a593Smuzhiyun phy_cfg = inno->phy_cfg;
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun if (!tmdsclock) {
484*4882a593Smuzhiyun dev_err(inno->dev, "TMDS clock is zero!\n");
485*4882a593Smuzhiyun return -EINVAL;
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun
488*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3328 &&
489*4882a593Smuzhiyun rockchip_get_cpu_version())
490*4882a593Smuzhiyun chipversion = 2;
491*4882a593Smuzhiyun else if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228 &&
492*4882a593Smuzhiyun tmdsclock <= 33750000 && inno->efuse_flag)
493*4882a593Smuzhiyun chipversion = 4;
494*4882a593Smuzhiyun else if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3528)
495*4882a593Smuzhiyun chipversion = 8;
496*4882a593Smuzhiyun
497*4882a593Smuzhiyun for (; cfg->tmdsclock != ~0UL; cfg++)
498*4882a593Smuzhiyun if (tmdsclock <= cfg->tmdsclock &&
499*4882a593Smuzhiyun cfg->version & chipversion)
500*4882a593Smuzhiyun break;
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun for (; phy_cfg->tmdsclock != ~0UL; phy_cfg++)
503*4882a593Smuzhiyun if (tmdsclock <= phy_cfg->tmdsclock)
504*4882a593Smuzhiyun break;
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun if (cfg->tmdsclock == ~0UL || phy_cfg->tmdsclock == ~0UL)
507*4882a593Smuzhiyun return -EINVAL;
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun dev_dbg(inno->dev, "Inno HDMI PHY Power On\n");
510*4882a593Smuzhiyun inno_hdmi_phy_clk_set_rate(&inno->hw, inno->pixclock, 0);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun if (inno->plat_data->ops->power_on)
513*4882a593Smuzhiyun return inno->plat_data->ops->power_on(inno, cfg, phy_cfg);
514*4882a593Smuzhiyun else
515*4882a593Smuzhiyun return -EINVAL;
516*4882a593Smuzhiyun }
517*4882a593Smuzhiyun
inno_hdmi_phy_power_off(struct phy * phy)518*4882a593Smuzhiyun static int inno_hdmi_phy_power_off(struct phy *phy)
519*4882a593Smuzhiyun {
520*4882a593Smuzhiyun struct inno_hdmi_phy *inno = phy_get_drvdata(phy);
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun if (inno->plat_data->ops->power_off)
523*4882a593Smuzhiyun inno->plat_data->ops->power_off(inno);
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun inno->tmdsclock = 0;
526*4882a593Smuzhiyun dev_dbg(inno->dev, "Inno HDMI PHY Power Off\n");
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun return 0;
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun static const struct phy_ops inno_hdmi_phy_ops = {
532*4882a593Smuzhiyun .owner = THIS_MODULE,
533*4882a593Smuzhiyun .power_on = inno_hdmi_phy_power_on,
534*4882a593Smuzhiyun .power_off = inno_hdmi_phy_power_off,
535*4882a593Smuzhiyun };
536*4882a593Smuzhiyun
inno_hdmi_phy_clk_is_prepared(struct clk_hw * hw)537*4882a593Smuzhiyun static int inno_hdmi_phy_clk_is_prepared(struct clk_hw *hw)
538*4882a593Smuzhiyun {
539*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
540*4882a593Smuzhiyun u8 status;
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228)
543*4882a593Smuzhiyun status = inno_read(inno, 0xe0) & PRE_PLL_POWER_MASK;
544*4882a593Smuzhiyun else
545*4882a593Smuzhiyun status = inno_read(inno, 0xa0) & 1;
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun return status ? 0 : 1;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
inno_hdmi_phy_clk_prepare(struct clk_hw * hw)550*4882a593Smuzhiyun static int inno_hdmi_phy_clk_prepare(struct clk_hw *hw)
551*4882a593Smuzhiyun {
552*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228)
555*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK,
556*4882a593Smuzhiyun PRE_PLL_POWER_UP);
557*4882a593Smuzhiyun else
558*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 1, 0);
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun return 0;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun
inno_hdmi_phy_clk_unprepare(struct clk_hw * hw)563*4882a593Smuzhiyun static void inno_hdmi_phy_clk_unprepare(struct clk_hw *hw)
564*4882a593Smuzhiyun {
565*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
566*4882a593Smuzhiyun
567*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3228)
568*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK,
569*4882a593Smuzhiyun PRE_PLL_POWER_DOWN);
570*4882a593Smuzhiyun else
571*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 1, 1);
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun
inno_hdmi_phy_clk_recalc_rate(struct clk_hw * hw,unsigned long parent_rate)574*4882a593Smuzhiyun static unsigned long inno_hdmi_phy_clk_recalc_rate(struct clk_hw *hw,
575*4882a593Smuzhiyun unsigned long parent_rate)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun if (inno->plat_data->ops->recalc_rate)
580*4882a593Smuzhiyun return inno->plat_data->ops->recalc_rate(inno, parent_rate);
581*4882a593Smuzhiyun else
582*4882a593Smuzhiyun return inno->pixclock;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun
inno_hdmi_phy_clk_round_rate(struct clk_hw * hw,unsigned long rate,unsigned long * parent_rate)585*4882a593Smuzhiyun static long inno_hdmi_phy_clk_round_rate(struct clk_hw *hw, unsigned long rate,
586*4882a593Smuzhiyun unsigned long *parent_rate)
587*4882a593Smuzhiyun {
588*4882a593Smuzhiyun int i;
589*4882a593Smuzhiyun const struct pre_pll_config *cfg = pre_pll_cfg_table;
590*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
591*4882a593Smuzhiyun u32 tmdsclock = inno_hdmi_phy_get_tmdsclk(inno, rate);
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun for (; cfg->pixclock != ~0UL; cfg++)
594*4882a593Smuzhiyun if (cfg->pixclock == rate)
595*4882a593Smuzhiyun break;
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun /* XXX: Limit pixel clock under 600MHz */
598*4882a593Smuzhiyun if (cfg->pixclock > 600000000)
599*4882a593Smuzhiyun return -EINVAL;
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun /*
602*4882a593Smuzhiyun * If there is no dts phy cfg table, use default phy cfg table.
603*4882a593Smuzhiyun * The tmds clock maximum is 594MHz. So there is no need to check
604*4882a593Smuzhiyun * whether tmds clock is out of range.
605*4882a593Smuzhiyun */
606*4882a593Smuzhiyun if (!inno->phy_cfg)
607*4882a593Smuzhiyun return cfg->pixclock;
608*4882a593Smuzhiyun
609*4882a593Smuzhiyun /* Check if tmds clock is out of dts phy config's range. */
610*4882a593Smuzhiyun for (i = 0; inno->phy_cfg[i].tmdsclock != ~0UL; i++) {
611*4882a593Smuzhiyun if (inno->phy_cfg[i].tmdsclock >= tmdsclock)
612*4882a593Smuzhiyun break;
613*4882a593Smuzhiyun }
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun if (inno->phy_cfg[i].tmdsclock == ~0UL)
616*4882a593Smuzhiyun return -EINVAL;
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun return cfg->pixclock;
619*4882a593Smuzhiyun }
620*4882a593Smuzhiyun
inno_hdmi_phy_clk_set_rate(struct clk_hw * hw,unsigned long rate,unsigned long parent_rate)621*4882a593Smuzhiyun static int inno_hdmi_phy_clk_set_rate(struct clk_hw *hw, unsigned long rate,
622*4882a593Smuzhiyun unsigned long parent_rate)
623*4882a593Smuzhiyun {
624*4882a593Smuzhiyun struct inno_hdmi_phy *inno = to_inno_hdmi_phy(hw);
625*4882a593Smuzhiyun const struct pre_pll_config *cfg = pre_pll_cfg_table;
626*4882a593Smuzhiyun u32 tmdsclock = inno_hdmi_phy_get_tmdsclk(inno, rate);
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun dev_dbg(inno->dev, "%s rate %lu tmdsclk %u\n",
629*4882a593Smuzhiyun __func__, rate, tmdsclock);
630*4882a593Smuzhiyun
631*4882a593Smuzhiyun if (inno->tmdsclock == tmdsclock)
632*4882a593Smuzhiyun return 0;
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun for (; cfg->pixclock != ~0UL; cfg++)
635*4882a593Smuzhiyun if (cfg->pixclock == rate && cfg->tmdsclock == tmdsclock)
636*4882a593Smuzhiyun break;
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun if (cfg->pixclock == ~0UL) {
639*4882a593Smuzhiyun dev_err(inno->dev, "unsupported rate %lu\n", rate);
640*4882a593Smuzhiyun return -EINVAL;
641*4882a593Smuzhiyun }
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun if (inno->plat_data->ops->pre_pll_update)
644*4882a593Smuzhiyun inno->plat_data->ops->pre_pll_update(inno, cfg);
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun inno->pixclock = rate;
647*4882a593Smuzhiyun inno->tmdsclock = tmdsclock;
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun return 0;
650*4882a593Smuzhiyun }
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun static const struct clk_ops inno_hdmi_phy_clk_ops = {
653*4882a593Smuzhiyun .prepare = inno_hdmi_phy_clk_prepare,
654*4882a593Smuzhiyun .unprepare = inno_hdmi_phy_clk_unprepare,
655*4882a593Smuzhiyun .is_prepared = inno_hdmi_phy_clk_is_prepared,
656*4882a593Smuzhiyun .recalc_rate = inno_hdmi_phy_clk_recalc_rate,
657*4882a593Smuzhiyun .round_rate = inno_hdmi_phy_clk_round_rate,
658*4882a593Smuzhiyun .set_rate = inno_hdmi_phy_clk_set_rate,
659*4882a593Smuzhiyun };
660*4882a593Smuzhiyun
inno_hdmi_phy_clk_register(struct inno_hdmi_phy * inno)661*4882a593Smuzhiyun static int inno_hdmi_phy_clk_register(struct inno_hdmi_phy *inno)
662*4882a593Smuzhiyun {
663*4882a593Smuzhiyun struct device *dev = inno->dev;
664*4882a593Smuzhiyun struct device_node *np = dev->of_node;
665*4882a593Smuzhiyun struct device_node *clk_np = NULL;
666*4882a593Smuzhiyun struct clk_init_data init = {};
667*4882a593Smuzhiyun struct clk *refclk;
668*4882a593Smuzhiyun const char *parent_name;
669*4882a593Smuzhiyun int ret;
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun if (inno->plat_data->dev_type == INNO_HDMI_PHY_RK3528)
672*4882a593Smuzhiyun clk_np = of_get_child_by_name(np, "clk-port");
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun if (!clk_np)
675*4882a593Smuzhiyun clk_np = np;
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun refclk = devm_clk_get(dev, "refclk");
678*4882a593Smuzhiyun if (IS_ERR(refclk)) {
679*4882a593Smuzhiyun dev_err(dev, "failed to get ref clock\n");
680*4882a593Smuzhiyun return PTR_ERR(refclk);
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun parent_name = __clk_get_name(refclk);
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun init.parent_names = &parent_name;
686*4882a593Smuzhiyun init.num_parents = 1;
687*4882a593Smuzhiyun init.flags = 0;
688*4882a593Smuzhiyun init.name = "pin_hd20_pclk";
689*4882a593Smuzhiyun init.ops = &inno_hdmi_phy_clk_ops;
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun /* optional override of the clock name */
692*4882a593Smuzhiyun of_property_read_string(clk_np, "clock-output-names", &init.name);
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun inno->hw.init = &init;
695*4882a593Smuzhiyun
696*4882a593Smuzhiyun inno->pclk = devm_clk_register(dev, &inno->hw);
697*4882a593Smuzhiyun if (IS_ERR(inno->pclk)) {
698*4882a593Smuzhiyun ret = PTR_ERR(inno->pclk);
699*4882a593Smuzhiyun dev_err(dev, "failed to register clock: %d\n", ret);
700*4882a593Smuzhiyun return ret;
701*4882a593Smuzhiyun }
702*4882a593Smuzhiyun
703*4882a593Smuzhiyun ret = of_clk_add_provider(clk_np, of_clk_src_simple_get, inno->pclk);
704*4882a593Smuzhiyun if (ret) {
705*4882a593Smuzhiyun dev_err(dev, "failed to register OF clock provider: %d\n", ret);
706*4882a593Smuzhiyun return ret;
707*4882a593Smuzhiyun }
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun return 0;
710*4882a593Smuzhiyun }
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3228_power_on(struct inno_hdmi_phy * inno,const struct post_pll_config * cfg,const struct phy_config * phy_cfg)713*4882a593Smuzhiyun inno_hdmi_phy_rk3228_power_on(struct inno_hdmi_phy *inno,
714*4882a593Smuzhiyun const struct post_pll_config *cfg,
715*4882a593Smuzhiyun const struct phy_config *phy_cfg)
716*4882a593Smuzhiyun {
717*4882a593Smuzhiyun int pll_tries;
718*4882a593Smuzhiyun u32 m, v;
719*4882a593Smuzhiyun
720*4882a593Smuzhiyun /* pdata_en disable */
721*4882a593Smuzhiyun inno_update_bits(inno, 0x02, PDATAEN_MASK, PDATAEN_DISABLE);
722*4882a593Smuzhiyun
723*4882a593Smuzhiyun /* Power down Post-PLL */
724*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK, PRE_PLL_POWER_DOWN);
725*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, POST_PLL_POWER_MASK, POST_PLL_POWER_DOWN);
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun /* Post-PLL update */
728*4882a593Smuzhiyun m = POST_PLL_PRE_DIV_MASK;
729*4882a593Smuzhiyun v = POST_PLL_PRE_DIV(cfg->prediv);
730*4882a593Smuzhiyun inno_update_bits(inno, 0xe9, m, v);
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun m = POST_PLL_FB_DIV_8_MASK;
733*4882a593Smuzhiyun v = POST_PLL_FB_DIV_8(cfg->fbdiv >> 8);
734*4882a593Smuzhiyun inno_update_bits(inno, 0xeb, m, v);
735*4882a593Smuzhiyun inno_write(inno, 0xea, POST_PLL_FB_DIV_7_0(cfg->fbdiv));
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun if (cfg->postdiv == 1) {
738*4882a593Smuzhiyun /* Disable Post-PLL post divider */
739*4882a593Smuzhiyun m = POST_PLL_POST_DIV_EN_MASK;
740*4882a593Smuzhiyun v = POST_PLL_POST_DIV_DISABLE;
741*4882a593Smuzhiyun inno_update_bits(inno, 0xe9, m, v);
742*4882a593Smuzhiyun } else {
743*4882a593Smuzhiyun /* Enable Post-PLL post divider */
744*4882a593Smuzhiyun m = POST_PLL_POST_DIV_EN_MASK;
745*4882a593Smuzhiyun v = POST_PLL_POST_DIV_ENABLE;
746*4882a593Smuzhiyun inno_update_bits(inno, 0xe9, m, v);
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun m = POST_PLL_POST_DIV_MASK;
749*4882a593Smuzhiyun v = POST_PLL_POST_DIV(cfg->postdiv / 2 - 1);
750*4882a593Smuzhiyun inno_update_bits(inno, 0xeb, m, v);
751*4882a593Smuzhiyun }
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun for (v = 0; v < 4; v++)
754*4882a593Smuzhiyun inno_write(inno, 0xef + v, phy_cfg->regs[v]);
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun /* Power up Post-PLL */
757*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, POST_PLL_POWER_MASK, POST_PLL_POWER_UP);
758*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK, PRE_PLL_POWER_UP);
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun /* BandGap enable */
761*4882a593Smuzhiyun inno_update_bits(inno, 0xe1, BANDGAP_MASK, BANDGAP_ENABLE);
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun /* TMDS driver enable */
764*4882a593Smuzhiyun inno_update_bits(inno, 0xe1, TMDS_DRIVER_MASK, TMDS_DRIVER_ENABLE);
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun /* Wait for post PLL lock */
767*4882a593Smuzhiyun pll_tries = 0;
768*4882a593Smuzhiyun while (!(inno_read(inno, 0xeb) & POST_PLL_LOCK_STATUS)) {
769*4882a593Smuzhiyun if (pll_tries == INNO_HDMI_PHY_TIMEOUT_LOOP_COUNT) {
770*4882a593Smuzhiyun dev_err(inno->dev, "Post-PLL unlock\n");
771*4882a593Smuzhiyun return -ETIMEDOUT;
772*4882a593Smuzhiyun }
773*4882a593Smuzhiyun
774*4882a593Smuzhiyun pll_tries++;
775*4882a593Smuzhiyun usleep_range(100, 110);
776*4882a593Smuzhiyun }
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun if (cfg->tmdsclock > 340000000)
779*4882a593Smuzhiyun msleep(100);
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun /* pdata_en enable */
782*4882a593Smuzhiyun inno_update_bits(inno, 0x02, PDATAEN_MASK, PDATAEN_ENABLE);
783*4882a593Smuzhiyun return 0;
784*4882a593Smuzhiyun }
785*4882a593Smuzhiyun
inno_hdmi_phy_rk3228_power_off(struct inno_hdmi_phy * inno)786*4882a593Smuzhiyun static void inno_hdmi_phy_rk3228_power_off(struct inno_hdmi_phy *inno)
787*4882a593Smuzhiyun {
788*4882a593Smuzhiyun /* TMDS driver Disable */
789*4882a593Smuzhiyun inno_update_bits(inno, 0xe1, TMDS_DRIVER_MASK, TMDS_DRIVER_DISABLE);
790*4882a593Smuzhiyun
791*4882a593Smuzhiyun /* BandGap Disable */
792*4882a593Smuzhiyun inno_update_bits(inno, 0xe1, BANDGAP_MASK, BANDGAP_DISABLE);
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun /* Post-PLL power down */
795*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, POST_PLL_POWER_MASK, POST_PLL_POWER_DOWN);
796*4882a593Smuzhiyun }
797*4882a593Smuzhiyun
inno_hdmi_phy_rk3228_init(struct inno_hdmi_phy * inno)798*4882a593Smuzhiyun static void inno_hdmi_phy_rk3228_init(struct inno_hdmi_phy *inno)
799*4882a593Smuzhiyun {
800*4882a593Smuzhiyun u32 m, v;
801*4882a593Smuzhiyun struct nvmem_cell *cell;
802*4882a593Smuzhiyun unsigned char *efuse_buf;
803*4882a593Smuzhiyun size_t len;
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun /*
806*4882a593Smuzhiyun * Use phy internal register control
807*4882a593Smuzhiyun * rxsense/poweron/pllpd/pdataen signal.
808*4882a593Smuzhiyun */
809*4882a593Smuzhiyun m = BYPASS_RXSENSE_EN_MASK | BYPASS_PWRON_EN_MASK |
810*4882a593Smuzhiyun BYPASS_PLLPD_EN_MASK;
811*4882a593Smuzhiyun v = BYPASS_RXSENSE_EN | BYPASS_PWRON_EN | BYPASS_PLLPD_EN;
812*4882a593Smuzhiyun inno_update_bits(inno, 0x01, m, v);
813*4882a593Smuzhiyun inno_update_bits(inno, 0x02, BYPASS_PDATA_EN_MASK, BYPASS_PDATA_EN);
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun /*
816*4882a593Smuzhiyun * reg0xe9 default value is 0xe4, reg0xea is 0x50.
817*4882a593Smuzhiyun * if phy had been set in uboot, one of them will be different.
818*4882a593Smuzhiyun */
819*4882a593Smuzhiyun if ((inno_read(inno, 0xe9) != 0xe4 || inno_read(inno, 0xea) != 0x50)) {
820*4882a593Smuzhiyun dev_info(inno->dev, "phy had been powered up\n");
821*4882a593Smuzhiyun inno->phy->power_count = 1;
822*4882a593Smuzhiyun } else {
823*4882a593Smuzhiyun inno_hdmi_phy_rk3228_power_off(inno);
824*4882a593Smuzhiyun /* manual power down post-PLL */
825*4882a593Smuzhiyun inno_update_bits(inno, 0xaa,
826*4882a593Smuzhiyun POST_PLL_CTRL_MASK, POST_PLL_CTRL_MANUAL);
827*4882a593Smuzhiyun }
828*4882a593Smuzhiyun
829*4882a593Smuzhiyun cell = nvmem_cell_get(inno->dev, "hdmi_phy_flag");
830*4882a593Smuzhiyun if (IS_ERR(cell)) {
831*4882a593Smuzhiyun dev_err(inno->dev,
832*4882a593Smuzhiyun "failed to get id cell: %ld\n", PTR_ERR(cell));
833*4882a593Smuzhiyun return;
834*4882a593Smuzhiyun }
835*4882a593Smuzhiyun efuse_buf = nvmem_cell_read(cell, &len);
836*4882a593Smuzhiyun nvmem_cell_put(cell);
837*4882a593Smuzhiyun if (len == 1)
838*4882a593Smuzhiyun inno->efuse_flag = efuse_buf[0] ? true : false;
839*4882a593Smuzhiyun kfree(efuse_buf);
840*4882a593Smuzhiyun }
841*4882a593Smuzhiyun
842*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3228_pre_pll_update(struct inno_hdmi_phy * inno,const struct pre_pll_config * cfg)843*4882a593Smuzhiyun inno_hdmi_phy_rk3228_pre_pll_update(struct inno_hdmi_phy *inno,
844*4882a593Smuzhiyun const struct pre_pll_config *cfg)
845*4882a593Smuzhiyun {
846*4882a593Smuzhiyun int pll_tries;
847*4882a593Smuzhiyun u32 m, v;
848*4882a593Smuzhiyun
849*4882a593Smuzhiyun /* Power down PRE-PLL */
850*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK, PRE_PLL_POWER_DOWN);
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun m = PRE_PLL_FB_DIV_8_MASK | PCLK_VCO_DIV_5_MASK | PRE_PLL_PRE_DIV_MASK;
853*4882a593Smuzhiyun v = PRE_PLL_FB_DIV_8(cfg->fbdiv >> 8) |
854*4882a593Smuzhiyun PCLK_VCO_DIV_5(cfg->vco_div_5_en) | PRE_PLL_PRE_DIV(cfg->prediv);
855*4882a593Smuzhiyun inno_update_bits(inno, 0xe2, m, v);
856*4882a593Smuzhiyun
857*4882a593Smuzhiyun inno_write(inno, 0xe3, PRE_PLL_FB_DIV_7_0(cfg->fbdiv));
858*4882a593Smuzhiyun
859*4882a593Smuzhiyun m = PRE_PLL_PCLK_DIV_B_MASK | PRE_PLL_PCLK_DIV_A_MASK;
860*4882a593Smuzhiyun v = PRE_PLL_PCLK_DIV_B(cfg->pclk_div_b) |
861*4882a593Smuzhiyun PRE_PLL_PCLK_DIV_A(cfg->pclk_div_a);
862*4882a593Smuzhiyun inno_update_bits(inno, 0xe4, m, v);
863*4882a593Smuzhiyun
864*4882a593Smuzhiyun m = PRE_PLL_PCLK_DIV_C_MASK | PRE_PLL_PCLK_DIV_D_MASK;
865*4882a593Smuzhiyun v = PRE_PLL_PCLK_DIV_C(cfg->pclk_div_c) |
866*4882a593Smuzhiyun PRE_PLL_PCLK_DIV_D(cfg->pclk_div_d);
867*4882a593Smuzhiyun inno_update_bits(inno, 0xe5, m, v);
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun m = PRE_PLL_TMDSCLK_DIV_C_MASK | PRE_PLL_TMDSCLK_DIV_A_MASK |
870*4882a593Smuzhiyun PRE_PLL_TMDSCLK_DIV_B_MASK;
871*4882a593Smuzhiyun v = PRE_PLL_TMDSCLK_DIV_C(cfg->tmds_div_c) |
872*4882a593Smuzhiyun PRE_PLL_TMDSCLK_DIV_A(cfg->tmds_div_a) |
873*4882a593Smuzhiyun PRE_PLL_TMDSCLK_DIV_B(cfg->tmds_div_b);
874*4882a593Smuzhiyun inno_update_bits(inno, 0xe6, m, v);
875*4882a593Smuzhiyun
876*4882a593Smuzhiyun /* Power up PRE-PLL */
877*4882a593Smuzhiyun inno_update_bits(inno, 0xe0, PRE_PLL_POWER_MASK, PRE_PLL_POWER_UP);
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun /* Wait for Pre-PLL lock */
880*4882a593Smuzhiyun pll_tries = 0;
881*4882a593Smuzhiyun while (!(inno_read(inno, 0xe8) & PRE_PLL_LOCK_STATUS)) {
882*4882a593Smuzhiyun if (pll_tries == INNO_HDMI_PHY_TIMEOUT_LOOP_COUNT) {
883*4882a593Smuzhiyun dev_err(inno->dev, "Pre-PLL unlock\n");
884*4882a593Smuzhiyun return -ETIMEDOUT;
885*4882a593Smuzhiyun }
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun pll_tries++;
888*4882a593Smuzhiyun usleep_range(100, 110);
889*4882a593Smuzhiyun }
890*4882a593Smuzhiyun
891*4882a593Smuzhiyun return 0;
892*4882a593Smuzhiyun }
893*4882a593Smuzhiyun
894*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3328_power_on(struct inno_hdmi_phy * inno,const struct post_pll_config * cfg,const struct phy_config * phy_cfg)895*4882a593Smuzhiyun inno_hdmi_phy_rk3328_power_on(struct inno_hdmi_phy *inno,
896*4882a593Smuzhiyun const struct post_pll_config *cfg,
897*4882a593Smuzhiyun const struct phy_config *phy_cfg)
898*4882a593Smuzhiyun {
899*4882a593Smuzhiyun u32 val;
900*4882a593Smuzhiyun u64 temp;
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun /* set pdata_en to 0 */
903*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 0);
904*4882a593Smuzhiyun /* Power off post PLL */
905*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 1);
906*4882a593Smuzhiyun
907*4882a593Smuzhiyun val = cfg->fbdiv & 0xff;
908*4882a593Smuzhiyun inno_write(inno, 0xac, val);
909*4882a593Smuzhiyun if (cfg->postdiv == 1) {
910*4882a593Smuzhiyun inno_write(inno, 0xaa, 2);
911*4882a593Smuzhiyun val = (cfg->fbdiv >> 8) | cfg->prediv;
912*4882a593Smuzhiyun inno_write(inno, 0xab, val);
913*4882a593Smuzhiyun } else {
914*4882a593Smuzhiyun val = (cfg->postdiv / 2) - 1;
915*4882a593Smuzhiyun inno_write(inno, 0xad, val);
916*4882a593Smuzhiyun val = (cfg->fbdiv >> 8) | cfg->prediv;
917*4882a593Smuzhiyun inno_write(inno, 0xab, val);
918*4882a593Smuzhiyun inno_write(inno, 0xaa, 0x0e);
919*4882a593Smuzhiyun }
920*4882a593Smuzhiyun
921*4882a593Smuzhiyun for (val = 0; val < 14; val++)
922*4882a593Smuzhiyun inno_write(inno, 0xb5 + val, phy_cfg->regs[val]);
923*4882a593Smuzhiyun
924*4882a593Smuzhiyun /* bit[7:6] of reg c8/c9/ca/c8 is ESD detect threshold:
925*4882a593Smuzhiyun * 00 - 340mV
926*4882a593Smuzhiyun * 01 - 280mV
927*4882a593Smuzhiyun * 10 - 260mV
928*4882a593Smuzhiyun * 11 - 240mV
929*4882a593Smuzhiyun * default is 240mV, now we set it to 340mV
930*4882a593Smuzhiyun */
931*4882a593Smuzhiyun inno_write(inno, 0xc8, 0);
932*4882a593Smuzhiyun inno_write(inno, 0xc9, 0);
933*4882a593Smuzhiyun inno_write(inno, 0xca, 0);
934*4882a593Smuzhiyun inno_write(inno, 0xcb, 0);
935*4882a593Smuzhiyun
936*4882a593Smuzhiyun if (phy_cfg->tmdsclock > 340000000) {
937*4882a593Smuzhiyun /* Set termination resistor to 100ohm */
938*4882a593Smuzhiyun val = clk_get_rate(inno->sysclk) / 100000;
939*4882a593Smuzhiyun inno_write(inno, 0xc5, ((val >> 8) & 0xff) | 0x80);
940*4882a593Smuzhiyun inno_write(inno, 0xc6, val & 0xff);
941*4882a593Smuzhiyun inno_write(inno, 0xc7, 3 << 1);
942*4882a593Smuzhiyun inno_write(inno, 0xc5, ((val >> 8) & 0xff));
943*4882a593Smuzhiyun } else {
944*4882a593Smuzhiyun inno_write(inno, 0xc5, 0x81);
945*4882a593Smuzhiyun /* clk termination resistor is 50ohm */
946*4882a593Smuzhiyun if (phy_cfg->tmdsclock > 165000000)
947*4882a593Smuzhiyun inno_write(inno, 0xc8, 0x30);
948*4882a593Smuzhiyun /* data termination resistor is 150ohm */
949*4882a593Smuzhiyun inno_write(inno, 0xc9, 0x10);
950*4882a593Smuzhiyun inno_write(inno, 0xca, 0x10);
951*4882a593Smuzhiyun inno_write(inno, 0xcb, 0x10);
952*4882a593Smuzhiyun }
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun /* set TMDS sync detection counter length */
955*4882a593Smuzhiyun temp = 47520000000;
956*4882a593Smuzhiyun do_div(temp, inno->tmdsclock);
957*4882a593Smuzhiyun inno_write(inno, 0xd8, (temp >> 8) & 0xff);
958*4882a593Smuzhiyun inno_write(inno, 0xd9, temp & 0xff);
959*4882a593Smuzhiyun
960*4882a593Smuzhiyun /* Power up post PLL */
961*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 0);
962*4882a593Smuzhiyun /* Power up tmds driver */
963*4882a593Smuzhiyun inno_update_bits(inno, 0xb0, 4, 4);
964*4882a593Smuzhiyun inno_write(inno, 0xb2, 0x0f);
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun /* Wait for post PLL lock */
967*4882a593Smuzhiyun for (val = 0; val < 5; val++) {
968*4882a593Smuzhiyun if (inno_read(inno, 0xaf) & 1)
969*4882a593Smuzhiyun break;
970*4882a593Smuzhiyun usleep_range(1000, 2000);
971*4882a593Smuzhiyun }
972*4882a593Smuzhiyun if (!(inno_read(inno, 0xaf) & 1)) {
973*4882a593Smuzhiyun dev_err(inno->dev, "HDMI PHY Post PLL unlock\n");
974*4882a593Smuzhiyun return -ETIMEDOUT;
975*4882a593Smuzhiyun }
976*4882a593Smuzhiyun if (phy_cfg->tmdsclock > 340000000)
977*4882a593Smuzhiyun msleep(100);
978*4882a593Smuzhiyun /* set pdata_en to 1 */
979*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 1);
980*4882a593Smuzhiyun
981*4882a593Smuzhiyun /* Enable PHY IRQ */
982*4882a593Smuzhiyun inno_write(inno, 0x05, 0x22);
983*4882a593Smuzhiyun inno_write(inno, 0x07, 0x22);
984*4882a593Smuzhiyun return 0;
985*4882a593Smuzhiyun }
986*4882a593Smuzhiyun
inno_hdmi_phy_rk3328_power_off(struct inno_hdmi_phy * inno)987*4882a593Smuzhiyun static void inno_hdmi_phy_rk3328_power_off(struct inno_hdmi_phy *inno)
988*4882a593Smuzhiyun {
989*4882a593Smuzhiyun /* Power off driver */
990*4882a593Smuzhiyun inno_write(inno, 0xb2, 0);
991*4882a593Smuzhiyun /* Power off band gap */
992*4882a593Smuzhiyun inno_update_bits(inno, 0xb0, 4, 0);
993*4882a593Smuzhiyun /* Power off post pll */
994*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 1);
995*4882a593Smuzhiyun
996*4882a593Smuzhiyun /* Disable PHY IRQ */
997*4882a593Smuzhiyun inno_write(inno, 0x05, 0);
998*4882a593Smuzhiyun inno_write(inno, 0x07, 0);
999*4882a593Smuzhiyun }
1000*4882a593Smuzhiyun
inno_hdmi_phy_rk3328_init(struct inno_hdmi_phy * inno)1001*4882a593Smuzhiyun static void inno_hdmi_phy_rk3328_init(struct inno_hdmi_phy *inno)
1002*4882a593Smuzhiyun {
1003*4882a593Smuzhiyun /*
1004*4882a593Smuzhiyun * Use phy internal register control
1005*4882a593Smuzhiyun * rxsense/poweron/pllpd/pdataen signal.
1006*4882a593Smuzhiyun */
1007*4882a593Smuzhiyun inno_write(inno, 0x01, 0x07);
1008*4882a593Smuzhiyun inno_write(inno, 0x02, 0x91);
1009*4882a593Smuzhiyun
1010*4882a593Smuzhiyun /*
1011*4882a593Smuzhiyun * reg0xc8 default value is 0xc0, if phy had been set in uboot,
1012*4882a593Smuzhiyun * the value of bit[7:6] will be zero.
1013*4882a593Smuzhiyun */
1014*4882a593Smuzhiyun if ((inno_read(inno, 0xc8) & 0xc0) == 0) {
1015*4882a593Smuzhiyun dev_info(inno->dev, "phy had been powered up\n");
1016*4882a593Smuzhiyun inno->phy->power_count = 1;
1017*4882a593Smuzhiyun } else {
1018*4882a593Smuzhiyun /* manual power down post-PLL */
1019*4882a593Smuzhiyun inno_hdmi_phy_rk3328_power_off(inno);
1020*4882a593Smuzhiyun }
1021*4882a593Smuzhiyun }
1022*4882a593Smuzhiyun
1023*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3328_pre_pll_update(struct inno_hdmi_phy * inno,const struct pre_pll_config * cfg)1024*4882a593Smuzhiyun inno_hdmi_phy_rk3328_pre_pll_update(struct inno_hdmi_phy *inno,
1025*4882a593Smuzhiyun const struct pre_pll_config *cfg)
1026*4882a593Smuzhiyun {
1027*4882a593Smuzhiyun u32 val;
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun /* Power off PLL */
1030*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 1, 1);
1031*4882a593Smuzhiyun /* Configure pre-pll */
1032*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 2, (cfg->vco_div_5_en & 1) << 1);
1033*4882a593Smuzhiyun inno_write(inno, 0xa1, cfg->prediv);
1034*4882a593Smuzhiyun if (cfg->fracdiv)
1035*4882a593Smuzhiyun val = ((cfg->fbdiv >> 8) & 0x0f) | 0xc0;
1036*4882a593Smuzhiyun else
1037*4882a593Smuzhiyun val = ((cfg->fbdiv >> 8) & 0x0f) | 0xf0;
1038*4882a593Smuzhiyun inno_write(inno, 0xa2, val);
1039*4882a593Smuzhiyun inno_write(inno, 0xa3, cfg->fbdiv & 0xff);
1040*4882a593Smuzhiyun val = (cfg->pclk_div_a & 0x1f) |
1041*4882a593Smuzhiyun ((cfg->pclk_div_b & 3) << 5);
1042*4882a593Smuzhiyun inno_write(inno, 0xa5, val);
1043*4882a593Smuzhiyun val = (cfg->pclk_div_d & 0x1f) |
1044*4882a593Smuzhiyun ((cfg->pclk_div_c & 3) << 5);
1045*4882a593Smuzhiyun inno_write(inno, 0xa6, val);
1046*4882a593Smuzhiyun val = ((cfg->tmds_div_a & 3) << 4) |
1047*4882a593Smuzhiyun ((cfg->tmds_div_b & 3) << 2) |
1048*4882a593Smuzhiyun (cfg->tmds_div_c & 3);
1049*4882a593Smuzhiyun inno_write(inno, 0xa4, val);
1050*4882a593Smuzhiyun
1051*4882a593Smuzhiyun if (cfg->fracdiv) {
1052*4882a593Smuzhiyun val = cfg->fracdiv & 0xff;
1053*4882a593Smuzhiyun inno_write(inno, 0xd3, val);
1054*4882a593Smuzhiyun val = (cfg->fracdiv >> 8) & 0xff;
1055*4882a593Smuzhiyun inno_write(inno, 0xd2, val);
1056*4882a593Smuzhiyun val = (cfg->fracdiv >> 16) & 0xff;
1057*4882a593Smuzhiyun inno_write(inno, 0xd1, val);
1058*4882a593Smuzhiyun } else {
1059*4882a593Smuzhiyun inno_write(inno, 0xd3, 0);
1060*4882a593Smuzhiyun inno_write(inno, 0xd2, 0);
1061*4882a593Smuzhiyun inno_write(inno, 0xd1, 0);
1062*4882a593Smuzhiyun }
1063*4882a593Smuzhiyun
1064*4882a593Smuzhiyun /* Power up PLL */
1065*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 1, 0);
1066*4882a593Smuzhiyun
1067*4882a593Smuzhiyun /* Wait for PLL lock */
1068*4882a593Smuzhiyun for (val = 0; val < 5; val++) {
1069*4882a593Smuzhiyun if (inno_read(inno, 0xa9) & 1)
1070*4882a593Smuzhiyun break;
1071*4882a593Smuzhiyun usleep_range(1000, 2000);
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun if (val == 5) {
1074*4882a593Smuzhiyun dev_err(inno->dev, "Pre-PLL unlock\n");
1075*4882a593Smuzhiyun return -ETIMEDOUT;
1076*4882a593Smuzhiyun }
1077*4882a593Smuzhiyun
1078*4882a593Smuzhiyun return 0;
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun
1081*4882a593Smuzhiyun static unsigned long
inno_hdmi_rk3328_phy_pll_recalc_rate(struct inno_hdmi_phy * inno,unsigned long parent_rate)1082*4882a593Smuzhiyun inno_hdmi_rk3328_phy_pll_recalc_rate(struct inno_hdmi_phy *inno,
1083*4882a593Smuzhiyun unsigned long parent_rate)
1084*4882a593Smuzhiyun {
1085*4882a593Smuzhiyun unsigned long frac;
1086*4882a593Smuzhiyun u8 nd, no_a, no_b, no_d;
1087*4882a593Smuzhiyun u16 nf;
1088*4882a593Smuzhiyun u64 vco = parent_rate;
1089*4882a593Smuzhiyun
1090*4882a593Smuzhiyun nd = inno_read(inno, 0xa1) & 0x3f;
1091*4882a593Smuzhiyun nf = ((inno_read(inno, 0xa2) & 0x0f) << 8) | inno_read(inno, 0xa3);
1092*4882a593Smuzhiyun vco *= nf;
1093*4882a593Smuzhiyun if ((inno_read(inno, 0xa2) & 0x30) == 0) {
1094*4882a593Smuzhiyun frac = inno_read(inno, 0xd3) |
1095*4882a593Smuzhiyun (inno_read(inno, 0xd2) << 8) |
1096*4882a593Smuzhiyun (inno_read(inno, 0xd1) << 16);
1097*4882a593Smuzhiyun vco += DIV_ROUND_CLOSEST(parent_rate * frac, (1 << 24));
1098*4882a593Smuzhiyun }
1099*4882a593Smuzhiyun if (inno_read(inno, 0xa0) & 2) {
1100*4882a593Smuzhiyun do_div(vco, nd * 5);
1101*4882a593Smuzhiyun } else {
1102*4882a593Smuzhiyun no_a = inno_read(inno, 0xa5) & 0x1f;
1103*4882a593Smuzhiyun no_b = ((inno_read(inno, 0xa5) >> 5) & 7) + 2;
1104*4882a593Smuzhiyun no_d = inno_read(inno, 0xa6) & 0x1f;
1105*4882a593Smuzhiyun if (no_a == 1)
1106*4882a593Smuzhiyun do_div(vco, nd * no_b * no_d * 2);
1107*4882a593Smuzhiyun else
1108*4882a593Smuzhiyun do_div(vco, nd * no_a * no_d * 2);
1109*4882a593Smuzhiyun }
1110*4882a593Smuzhiyun
1111*4882a593Smuzhiyun frac = vco;
1112*4882a593Smuzhiyun inno->pixclock = DIV_ROUND_CLOSEST(frac, 1000) * 1000;
1113*4882a593Smuzhiyun
1114*4882a593Smuzhiyun dev_dbg(inno->dev, "%s rate %lu\n", __func__, inno->pixclock);
1115*4882a593Smuzhiyun
1116*4882a593Smuzhiyun return frac;
1117*4882a593Smuzhiyun }
1118*4882a593Smuzhiyun
1119*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3528_power_on(struct inno_hdmi_phy * inno,const struct post_pll_config * cfg,const struct phy_config * phy_cfg)1120*4882a593Smuzhiyun inno_hdmi_phy_rk3528_power_on(struct inno_hdmi_phy *inno,
1121*4882a593Smuzhiyun const struct post_pll_config *cfg,
1122*4882a593Smuzhiyun const struct phy_config *phy_cfg)
1123*4882a593Smuzhiyun {
1124*4882a593Smuzhiyun u32 val;
1125*4882a593Smuzhiyun u64 temp;
1126*4882a593Smuzhiyun
1127*4882a593Smuzhiyun /* Power off post PLL */
1128*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 0);
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun val = cfg->prediv;
1131*4882a593Smuzhiyun inno_write(inno, 0xab, val);
1132*4882a593Smuzhiyun
1133*4882a593Smuzhiyun if (cfg->postdiv == 1) {
1134*4882a593Smuzhiyun inno_write(inno, 0xad, 0x8);
1135*4882a593Smuzhiyun inno_write(inno, 0xaa, 2);
1136*4882a593Smuzhiyun } else {
1137*4882a593Smuzhiyun val = (cfg->postdiv / 2) - 1;
1138*4882a593Smuzhiyun inno_write(inno, 0xad, val);
1139*4882a593Smuzhiyun inno_write(inno, 0xaa, 0x0e);
1140*4882a593Smuzhiyun }
1141*4882a593Smuzhiyun
1142*4882a593Smuzhiyun val = cfg->fbdiv & 0xff;
1143*4882a593Smuzhiyun inno_write(inno, 0xac, val);
1144*4882a593Smuzhiyun val = (cfg->fbdiv >> 8) & BIT(0);
1145*4882a593Smuzhiyun inno_update_bits(inno, 0xad, BIT(4), val);
1146*4882a593Smuzhiyun
1147*4882a593Smuzhiyun /* current bias clk/data 2 */
1148*4882a593Smuzhiyun val = phy_cfg->regs[0] << 4 | phy_cfg->regs[1];
1149*4882a593Smuzhiyun inno_write(inno, 0xbf, val);
1150*4882a593Smuzhiyun
1151*4882a593Smuzhiyun /* current bias data 1/0 */
1152*4882a593Smuzhiyun val = phy_cfg->regs[1] << 4 | phy_cfg->regs[1];
1153*4882a593Smuzhiyun inno_write(inno, 0xc0, val);
1154*4882a593Smuzhiyun
1155*4882a593Smuzhiyun /* output voltage */
1156*4882a593Smuzhiyun inno_write(inno, 0xb5, phy_cfg->regs[2]);
1157*4882a593Smuzhiyun inno_write(inno, 0xb6, phy_cfg->regs[3]);
1158*4882a593Smuzhiyun inno_write(inno, 0xb7, phy_cfg->regs[3]);
1159*4882a593Smuzhiyun inno_write(inno, 0xb8, phy_cfg->regs[3]);
1160*4882a593Smuzhiyun
1161*4882a593Smuzhiyun /* pre-emphasis */
1162*4882a593Smuzhiyun inno_write(inno, 0xbb, phy_cfg->regs[4]);
1163*4882a593Smuzhiyun inno_write(inno, 0xbc, phy_cfg->regs[4]);
1164*4882a593Smuzhiyun inno_write(inno, 0xbd, phy_cfg->regs[4]);
1165*4882a593Smuzhiyun
1166*4882a593Smuzhiyun /* enable LDO */
1167*4882a593Smuzhiyun inno_write(inno, 0xb4, 0x7);
1168*4882a593Smuzhiyun
1169*4882a593Smuzhiyun /* enable serializer */
1170*4882a593Smuzhiyun inno_write(inno, 0xbe, 0x70);
1171*4882a593Smuzhiyun
1172*4882a593Smuzhiyun inno_write(inno, 0xb2, 0x0f);
1173*4882a593Smuzhiyun
1174*4882a593Smuzhiyun for (val = 0; val < 5; val++) {
1175*4882a593Smuzhiyun if (inno_read(inno, 0xaf) & 1)
1176*4882a593Smuzhiyun break;
1177*4882a593Smuzhiyun udelay(1000);
1178*4882a593Smuzhiyun }
1179*4882a593Smuzhiyun if (!(inno_read(inno, 0xaf) & 1)) {
1180*4882a593Smuzhiyun dev_err(inno->dev, "HDMI PHY Post PLL unlock\n");
1181*4882a593Smuzhiyun return -ETIMEDOUT;
1182*4882a593Smuzhiyun }
1183*4882a593Smuzhiyun
1184*4882a593Smuzhiyun /* set termination resistance */
1185*4882a593Smuzhiyun if (phy_cfg->tmdsclock > 340000000) {
1186*4882a593Smuzhiyun inno_write(inno, 0xc7, 0x76);
1187*4882a593Smuzhiyun inno_write(inno, 0xc5, 0x83);
1188*4882a593Smuzhiyun inno_write(inno, 0xc8, 0x00);
1189*4882a593Smuzhiyun inno_write(inno, 0xc9, 0x2f);
1190*4882a593Smuzhiyun inno_write(inno, 0xca, 0x2f);
1191*4882a593Smuzhiyun inno_write(inno, 0xcb, 0x2f);
1192*4882a593Smuzhiyun } else {
1193*4882a593Smuzhiyun inno_write(inno, 0xc7, 0x76);
1194*4882a593Smuzhiyun inno_write(inno, 0xc5, 0x83);
1195*4882a593Smuzhiyun inno_write(inno, 0xc8, 0x00);
1196*4882a593Smuzhiyun inno_write(inno, 0xc9, 0x0f);
1197*4882a593Smuzhiyun inno_write(inno, 0xca, 0x0f);
1198*4882a593Smuzhiyun inno_write(inno, 0xcb, 0x0f);
1199*4882a593Smuzhiyun }
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun /* set TMDS sync detection counter length */
1202*4882a593Smuzhiyun temp = 47520000000;
1203*4882a593Smuzhiyun do_div(temp, inno->tmdsclock);
1204*4882a593Smuzhiyun inno_write(inno, 0xd8, (temp >> 8) & 0xff);
1205*4882a593Smuzhiyun inno_write(inno, 0xd9, temp & 0xff);
1206*4882a593Smuzhiyun
1207*4882a593Smuzhiyun /* Power up post PLL */
1208*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 0);
1209*4882a593Smuzhiyun /* Power up tmds driver */
1210*4882a593Smuzhiyun inno_update_bits(inno, 0xb0, 4, 4);
1211*4882a593Smuzhiyun inno_write(inno, 0xb2, 0x0f);
1212*4882a593Smuzhiyun
1213*4882a593Smuzhiyun if (phy_cfg->tmdsclock > 340000000)
1214*4882a593Smuzhiyun msleep(100);
1215*4882a593Smuzhiyun /* set pdata_en to 0/1 */
1216*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 0);
1217*4882a593Smuzhiyun inno_update_bits(inno, 0x02, 1, 1);
1218*4882a593Smuzhiyun
1219*4882a593Smuzhiyun /* Enable PHY IRQ */
1220*4882a593Smuzhiyun inno_write(inno, 0x05, 0x22);
1221*4882a593Smuzhiyun inno_write(inno, 0x07, 0x22);
1222*4882a593Smuzhiyun inno_write(inno, 0xcc, 0x0f);
1223*4882a593Smuzhiyun
1224*4882a593Smuzhiyun return 0;
1225*4882a593Smuzhiyun }
1226*4882a593Smuzhiyun
inno_hdmi_phy_rk3528_power_off(struct inno_hdmi_phy * inno)1227*4882a593Smuzhiyun static void inno_hdmi_phy_rk3528_power_off(struct inno_hdmi_phy *inno)
1228*4882a593Smuzhiyun {
1229*4882a593Smuzhiyun /* Power off driver */
1230*4882a593Smuzhiyun inno_write(inno, 0xb2, 0);
1231*4882a593Smuzhiyun /* Power off serializer */
1232*4882a593Smuzhiyun inno_write(inno, 0xbe, 0);
1233*4882a593Smuzhiyun /* Power off post pll */
1234*4882a593Smuzhiyun inno_update_bits(inno, 0xaa, 1, 1);
1235*4882a593Smuzhiyun /* Power off rxsense detection circuit */
1236*4882a593Smuzhiyun inno_write(inno, 0xcc, 0);
1237*4882a593Smuzhiyun /* Power off band gap */
1238*4882a593Smuzhiyun inno_update_bits(inno, 0xb0, 4, 0);
1239*4882a593Smuzhiyun /* Disable PHY IRQ */
1240*4882a593Smuzhiyun inno_write(inno, 0x05, 0);
1241*4882a593Smuzhiyun inno_write(inno, 0x07, 0);
1242*4882a593Smuzhiyun }
1243*4882a593Smuzhiyun
inno_hdmi_phy_rk3528_init(struct inno_hdmi_phy * inno)1244*4882a593Smuzhiyun static void inno_hdmi_phy_rk3528_init(struct inno_hdmi_phy *inno)
1245*4882a593Smuzhiyun {
1246*4882a593Smuzhiyun /*
1247*4882a593Smuzhiyun * Use phy internal register control
1248*4882a593Smuzhiyun * rxsense/poweron/pllpd/pdataen signal.
1249*4882a593Smuzhiyun */
1250*4882a593Smuzhiyun inno_write(inno, 0x02, 0x81);
1251*4882a593Smuzhiyun
1252*4882a593Smuzhiyun /* if phy had been set in uboot, pll is locked */
1253*4882a593Smuzhiyun if (inno_read(inno, 0xa9) & BIT(0)) {
1254*4882a593Smuzhiyun dev_info(inno->dev, "phy had been powered up\n");
1255*4882a593Smuzhiyun inno->phy->power_count = 1;
1256*4882a593Smuzhiyun } else {
1257*4882a593Smuzhiyun /* manual power down post-PLL */
1258*4882a593Smuzhiyun inno_hdmi_phy_rk3528_power_off(inno);
1259*4882a593Smuzhiyun }
1260*4882a593Smuzhiyun }
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun static int
inno_hdmi_phy_rk3528_pre_pll_update(struct inno_hdmi_phy * inno,const struct pre_pll_config * cfg)1263*4882a593Smuzhiyun inno_hdmi_phy_rk3528_pre_pll_update(struct inno_hdmi_phy *inno,
1264*4882a593Smuzhiyun const struct pre_pll_config *cfg)
1265*4882a593Smuzhiyun {
1266*4882a593Smuzhiyun u32 val;
1267*4882a593Smuzhiyun
1268*4882a593Smuzhiyun inno_update_bits(inno, 0xb0, 4, 4);
1269*4882a593Smuzhiyun inno_write(inno, 0xcc, 0x0f);
1270*4882a593Smuzhiyun
1271*4882a593Smuzhiyun /* Power on PLL */
1272*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 1, 0);
1273*4882a593Smuzhiyun /* Configure pre-pll */
1274*4882a593Smuzhiyun inno_update_bits(inno, 0xa0, 2, (cfg->vco_div_5_en & 1) << 1);
1275*4882a593Smuzhiyun inno_write(inno, 0xa1, cfg->prediv);
1276*4882a593Smuzhiyun if (cfg->fracdiv)
1277*4882a593Smuzhiyun val = ((cfg->fbdiv >> 8) & 0x0f) | 0xc0;
1278*4882a593Smuzhiyun else
1279*4882a593Smuzhiyun val = ((cfg->fbdiv >> 8) & 0x0f) | 0xf0;
1280*4882a593Smuzhiyun inno_write(inno, 0xa2, val);
1281*4882a593Smuzhiyun inno_write(inno, 0xa3, cfg->fbdiv & 0xff);
1282*4882a593Smuzhiyun val = (cfg->pclk_div_a & 0x1f) |
1283*4882a593Smuzhiyun ((cfg->pclk_div_b & 3) << 5);
1284*4882a593Smuzhiyun inno_write(inno, 0xa5, val);
1285*4882a593Smuzhiyun val = (cfg->pclk_div_d & 0x1f) |
1286*4882a593Smuzhiyun ((cfg->pclk_div_c & 3) << 5);
1287*4882a593Smuzhiyun inno_write(inno, 0xa6, val);
1288*4882a593Smuzhiyun val = ((cfg->tmds_div_a & 3) << 4) |
1289*4882a593Smuzhiyun ((cfg->tmds_div_b & 3) << 2) |
1290*4882a593Smuzhiyun (cfg->tmds_div_c & 3);
1291*4882a593Smuzhiyun inno_write(inno, 0xa4, val);
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun if (cfg->fracdiv) {
1294*4882a593Smuzhiyun val = cfg->fracdiv & 0xff;
1295*4882a593Smuzhiyun inno_write(inno, 0xd3, val);
1296*4882a593Smuzhiyun val = (cfg->fracdiv >> 8) & 0xff;
1297*4882a593Smuzhiyun inno_write(inno, 0xd2, val);
1298*4882a593Smuzhiyun val = (cfg->fracdiv >> 16) & 0xff;
1299*4882a593Smuzhiyun inno_write(inno, 0xd1, val);
1300*4882a593Smuzhiyun } else {
1301*4882a593Smuzhiyun inno_write(inno, 0xd3, 0);
1302*4882a593Smuzhiyun inno_write(inno, 0xd2, 0);
1303*4882a593Smuzhiyun inno_write(inno, 0xd1, 0);
1304*4882a593Smuzhiyun }
1305*4882a593Smuzhiyun
1306*4882a593Smuzhiyun /* Wait for PLL lock */
1307*4882a593Smuzhiyun for (val = 0; val < 5; val++) {
1308*4882a593Smuzhiyun if (inno_read(inno, 0xa9) & 1)
1309*4882a593Smuzhiyun break;
1310*4882a593Smuzhiyun usleep_range(1000, 2000);
1311*4882a593Smuzhiyun }
1312*4882a593Smuzhiyun if (val == 5) {
1313*4882a593Smuzhiyun dev_err(inno->dev, "Pre-PLL unlock\n");
1314*4882a593Smuzhiyun return -ETIMEDOUT;
1315*4882a593Smuzhiyun }
1316*4882a593Smuzhiyun
1317*4882a593Smuzhiyun return 0;
1318*4882a593Smuzhiyun }
1319*4882a593Smuzhiyun
1320*4882a593Smuzhiyun static unsigned long
inno_hdmi_rk3528_phy_pll_recalc_rate(struct inno_hdmi_phy * inno,unsigned long parent_rate)1321*4882a593Smuzhiyun inno_hdmi_rk3528_phy_pll_recalc_rate(struct inno_hdmi_phy *inno,
1322*4882a593Smuzhiyun unsigned long parent_rate)
1323*4882a593Smuzhiyun {
1324*4882a593Smuzhiyun unsigned long frac;
1325*4882a593Smuzhiyun u8 nd, no_a, no_b, no_d;
1326*4882a593Smuzhiyun u16 nf;
1327*4882a593Smuzhiyun u64 vco = parent_rate;
1328*4882a593Smuzhiyun
1329*4882a593Smuzhiyun nd = inno_read(inno, 0xa1) & 0x3f;
1330*4882a593Smuzhiyun nf = ((inno_read(inno, 0xa2) & 0x0f) << 8) | inno_read(inno, 0xa3);
1331*4882a593Smuzhiyun vco *= nf;
1332*4882a593Smuzhiyun if ((inno_read(inno, 0xa2) & 0x30) == 0) {
1333*4882a593Smuzhiyun frac = inno_read(inno, 0xd3) |
1334*4882a593Smuzhiyun (inno_read(inno, 0xd2) << 8) |
1335*4882a593Smuzhiyun (inno_read(inno, 0xd1) << 16);
1336*4882a593Smuzhiyun vco += DIV_ROUND_CLOSEST(parent_rate * frac, (1 << 24));
1337*4882a593Smuzhiyun }
1338*4882a593Smuzhiyun if (inno_read(inno, 0xa0) & 2) {
1339*4882a593Smuzhiyun do_div(vco, nd * 5);
1340*4882a593Smuzhiyun } else {
1341*4882a593Smuzhiyun no_a = inno_read(inno, 0xa5) & 0x1f;
1342*4882a593Smuzhiyun no_b = ((inno_read(inno, 0xa5) >> 5) & 7) + 2;
1343*4882a593Smuzhiyun no_d = inno_read(inno, 0xa6) & 0x1f;
1344*4882a593Smuzhiyun if (no_a == 1)
1345*4882a593Smuzhiyun do_div(vco, nd * no_b * no_d * 2);
1346*4882a593Smuzhiyun else
1347*4882a593Smuzhiyun do_div(vco, nd * no_a * no_d * 2);
1348*4882a593Smuzhiyun }
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun frac = vco;
1351*4882a593Smuzhiyun inno->pixclock = DIV_ROUND_CLOSEST(frac, 1000) * 1000;
1352*4882a593Smuzhiyun
1353*4882a593Smuzhiyun dev_dbg(inno->dev, "%s rate %lu\n", __func__, inno->pixclock);
1354*4882a593Smuzhiyun
1355*4882a593Smuzhiyun return frac;
1356*4882a593Smuzhiyun }
1357*4882a593Smuzhiyun
1358*4882a593Smuzhiyun static unsigned long
inno_hdmi_rk3228_phy_pll_recalc_rate(struct inno_hdmi_phy * inno,unsigned long parent_rate)1359*4882a593Smuzhiyun inno_hdmi_rk3228_phy_pll_recalc_rate(struct inno_hdmi_phy *inno,
1360*4882a593Smuzhiyun unsigned long parent_rate)
1361*4882a593Smuzhiyun {
1362*4882a593Smuzhiyun u8 nd, no_a, no_b, no_d;
1363*4882a593Smuzhiyun u16 nf;
1364*4882a593Smuzhiyun u64 vco = parent_rate;
1365*4882a593Smuzhiyun
1366*4882a593Smuzhiyun nd = inno_read(inno, 0xe2) & 0x1f;
1367*4882a593Smuzhiyun nf = ((inno_read(inno, 0xe2) & 0x80) << 1) | inno_read(inno, 0xe3);
1368*4882a593Smuzhiyun vco *= nf;
1369*4882a593Smuzhiyun
1370*4882a593Smuzhiyun if ((inno_read(inno, 0xe2) >> 5) & 0x1) {
1371*4882a593Smuzhiyun do_div(vco, nd * 5);
1372*4882a593Smuzhiyun } else {
1373*4882a593Smuzhiyun no_a = inno_read(inno, 0xe4) & 0x1f;
1374*4882a593Smuzhiyun if (!no_a)
1375*4882a593Smuzhiyun no_a = 1;
1376*4882a593Smuzhiyun no_b = ((inno_read(inno, 0xe4) >> 5) & 0x3) + 2;
1377*4882a593Smuzhiyun no_d = inno_read(inno, 0xe5) & 0x1f;
1378*4882a593Smuzhiyun
1379*4882a593Smuzhiyun if (no_a == 1)
1380*4882a593Smuzhiyun do_div(vco, nd * no_b * no_d * 2);
1381*4882a593Smuzhiyun else
1382*4882a593Smuzhiyun do_div(vco, nd * no_a * no_d * 2);
1383*4882a593Smuzhiyun }
1384*4882a593Smuzhiyun
1385*4882a593Smuzhiyun inno->pixclock = vco;
1386*4882a593Smuzhiyun
1387*4882a593Smuzhiyun dev_dbg(inno->dev, "%s rate %lu\n", __func__, inno->pixclock);
1388*4882a593Smuzhiyun
1389*4882a593Smuzhiyun return inno->pixclock;
1390*4882a593Smuzhiyun }
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun static const struct inno_hdmi_phy_ops rk3228_hdmi_phy_ops = {
1393*4882a593Smuzhiyun .init = inno_hdmi_phy_rk3228_init,
1394*4882a593Smuzhiyun .power_on = inno_hdmi_phy_rk3228_power_on,
1395*4882a593Smuzhiyun .power_off = inno_hdmi_phy_rk3228_power_off,
1396*4882a593Smuzhiyun .pre_pll_update = inno_hdmi_phy_rk3228_pre_pll_update,
1397*4882a593Smuzhiyun .recalc_rate = inno_hdmi_rk3228_phy_pll_recalc_rate,
1398*4882a593Smuzhiyun };
1399*4882a593Smuzhiyun
1400*4882a593Smuzhiyun static const struct inno_hdmi_phy_ops rk3328_hdmi_phy_ops = {
1401*4882a593Smuzhiyun .init = inno_hdmi_phy_rk3328_init,
1402*4882a593Smuzhiyun .power_on = inno_hdmi_phy_rk3328_power_on,
1403*4882a593Smuzhiyun .power_off = inno_hdmi_phy_rk3328_power_off,
1404*4882a593Smuzhiyun .pre_pll_update = inno_hdmi_phy_rk3328_pre_pll_update,
1405*4882a593Smuzhiyun .recalc_rate = inno_hdmi_rk3328_phy_pll_recalc_rate,
1406*4882a593Smuzhiyun };
1407*4882a593Smuzhiyun
1408*4882a593Smuzhiyun static const struct inno_hdmi_phy_ops rk3528_hdmi_phy_ops = {
1409*4882a593Smuzhiyun .init = inno_hdmi_phy_rk3528_init,
1410*4882a593Smuzhiyun .power_on = inno_hdmi_phy_rk3528_power_on,
1411*4882a593Smuzhiyun .power_off = inno_hdmi_phy_rk3528_power_off,
1412*4882a593Smuzhiyun .pre_pll_update = inno_hdmi_phy_rk3528_pre_pll_update,
1413*4882a593Smuzhiyun .recalc_rate = inno_hdmi_rk3528_phy_pll_recalc_rate,
1414*4882a593Smuzhiyun };
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun static const struct inno_hdmi_phy_drv_data rk3228_hdmi_phy_drv_data = {
1417*4882a593Smuzhiyun .dev_type = INNO_HDMI_PHY_RK3228,
1418*4882a593Smuzhiyun .ops = &rk3228_hdmi_phy_ops,
1419*4882a593Smuzhiyun .phy_cfg_table = rk3228_phy_cfg,
1420*4882a593Smuzhiyun };
1421*4882a593Smuzhiyun
1422*4882a593Smuzhiyun static const struct inno_hdmi_phy_drv_data rk3328_hdmi_phy_drv_data = {
1423*4882a593Smuzhiyun .dev_type = INNO_HDMI_PHY_RK3328,
1424*4882a593Smuzhiyun .ops = &rk3328_hdmi_phy_ops,
1425*4882a593Smuzhiyun .phy_cfg_table = rk3328_phy_cfg,
1426*4882a593Smuzhiyun };
1427*4882a593Smuzhiyun
1428*4882a593Smuzhiyun static const struct inno_hdmi_phy_drv_data rk3528_hdmi_phy_drv_data = {
1429*4882a593Smuzhiyun .dev_type = INNO_HDMI_PHY_RK3528,
1430*4882a593Smuzhiyun .ops = &rk3528_hdmi_phy_ops,
1431*4882a593Smuzhiyun .phy_cfg_table = rk3528_phy_cfg,
1432*4882a593Smuzhiyun };
1433*4882a593Smuzhiyun
1434*4882a593Smuzhiyun static const struct of_device_id inno_hdmi_phy_of_match[] = {
1435*4882a593Smuzhiyun { .compatible = "rockchip,rk3228-hdmi-phy",
1436*4882a593Smuzhiyun .data = &rk3228_hdmi_phy_drv_data
1437*4882a593Smuzhiyun },
1438*4882a593Smuzhiyun { .compatible = "rockchip,rk3328-hdmi-phy",
1439*4882a593Smuzhiyun .data = &rk3328_hdmi_phy_drv_data
1440*4882a593Smuzhiyun },
1441*4882a593Smuzhiyun { .compatible = "rockchip,rk3528-hdmi-phy",
1442*4882a593Smuzhiyun .data = &rk3528_hdmi_phy_drv_data
1443*4882a593Smuzhiyun },
1444*4882a593Smuzhiyun {}
1445*4882a593Smuzhiyun };
1446*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, inno_hdmi_phy_of_match);
1447*4882a593Smuzhiyun
1448*4882a593Smuzhiyun static const struct regmap_config inno_hdmi_phy_regmap_config = {
1449*4882a593Smuzhiyun .reg_bits = 32,
1450*4882a593Smuzhiyun .val_bits = 32,
1451*4882a593Smuzhiyun .reg_stride = 4,
1452*4882a593Smuzhiyun .max_register = 0x400,
1453*4882a593Smuzhiyun };
1454*4882a593Smuzhiyun
1455*4882a593Smuzhiyun static
inno_hdmi_update_phy_table(struct inno_hdmi_phy * inno,u32 * config,struct phy_config * phy_cfg,int phy_table_size)1456*4882a593Smuzhiyun int inno_hdmi_update_phy_table(struct inno_hdmi_phy *inno, u32 *config,
1457*4882a593Smuzhiyun struct phy_config *phy_cfg,
1458*4882a593Smuzhiyun int phy_table_size)
1459*4882a593Smuzhiyun {
1460*4882a593Smuzhiyun int i, j;
1461*4882a593Smuzhiyun
1462*4882a593Smuzhiyun for (i = 0; i < phy_table_size; i++) {
1463*4882a593Smuzhiyun phy_cfg[i].tmdsclock =
1464*4882a593Smuzhiyun (unsigned long)config[i * 15];
1465*4882a593Smuzhiyun
1466*4882a593Smuzhiyun for (j = 0; j < 14; j++)
1467*4882a593Smuzhiyun phy_cfg[i].regs[j] = (u8)config[i * 15 + 1 + j];
1468*4882a593Smuzhiyun }
1469*4882a593Smuzhiyun
1470*4882a593Smuzhiyun /*
1471*4882a593Smuzhiyun * The last set of phy cfg is used to indicate whether
1472*4882a593Smuzhiyun * there is no more phy cfg data.
1473*4882a593Smuzhiyun */
1474*4882a593Smuzhiyun phy_cfg[i].tmdsclock = ~0UL;
1475*4882a593Smuzhiyun for (j = 0; j < 14; j++)
1476*4882a593Smuzhiyun phy_cfg[i].regs[j] = 0;
1477*4882a593Smuzhiyun
1478*4882a593Smuzhiyun return 0;
1479*4882a593Smuzhiyun }
1480*4882a593Smuzhiyun
1481*4882a593Smuzhiyun #define PHY_TAB_LEN 60
1482*4882a593Smuzhiyun
inno_hdmi_phy_probe(struct platform_device * pdev)1483*4882a593Smuzhiyun static int inno_hdmi_phy_probe(struct platform_device *pdev)
1484*4882a593Smuzhiyun {
1485*4882a593Smuzhiyun struct device *dev = &pdev->dev;
1486*4882a593Smuzhiyun struct device_node *np = dev->of_node;
1487*4882a593Smuzhiyun struct inno_hdmi_phy *inno;
1488*4882a593Smuzhiyun const struct of_device_id *match;
1489*4882a593Smuzhiyun struct phy_provider *phy_provider;
1490*4882a593Smuzhiyun struct resource *res;
1491*4882a593Smuzhiyun void __iomem *regs;
1492*4882a593Smuzhiyun u32 *phy_config;
1493*4882a593Smuzhiyun int ret, val, phy_table_size;
1494*4882a593Smuzhiyun
1495*4882a593Smuzhiyun inno = devm_kzalloc(dev, sizeof(*inno), GFP_KERNEL);
1496*4882a593Smuzhiyun if (!inno)
1497*4882a593Smuzhiyun return -ENOMEM;
1498*4882a593Smuzhiyun
1499*4882a593Smuzhiyun inno->dev = dev;
1500*4882a593Smuzhiyun
1501*4882a593Smuzhiyun match = of_match_node(inno_hdmi_phy_of_match, pdev->dev.of_node);
1502*4882a593Smuzhiyun inno->plat_data = (struct inno_hdmi_phy_drv_data *)match->data;
1503*4882a593Smuzhiyun if (!inno->plat_data || !inno->plat_data->ops)
1504*4882a593Smuzhiyun return -EINVAL;
1505*4882a593Smuzhiyun
1506*4882a593Smuzhiyun res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1507*4882a593Smuzhiyun regs = devm_ioremap_resource(dev, res);
1508*4882a593Smuzhiyun if (IS_ERR(regs))
1509*4882a593Smuzhiyun return PTR_ERR(regs);
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun inno->sysclk = devm_clk_get(inno->dev, "sysclk");
1512*4882a593Smuzhiyun if (IS_ERR(inno->sysclk)) {
1513*4882a593Smuzhiyun ret = PTR_ERR(inno->sysclk);
1514*4882a593Smuzhiyun dev_err(inno->dev, "Unable to get inno phy sysclk: %d\n", ret);
1515*4882a593Smuzhiyun return ret;
1516*4882a593Smuzhiyun }
1517*4882a593Smuzhiyun ret = clk_prepare_enable(inno->sysclk);
1518*4882a593Smuzhiyun if (ret) {
1519*4882a593Smuzhiyun dev_err(inno->dev, "Cannot enable inno phy sysclk: %d\n", ret);
1520*4882a593Smuzhiyun return ret;
1521*4882a593Smuzhiyun }
1522*4882a593Smuzhiyun
1523*4882a593Smuzhiyun inno->regmap = devm_regmap_init_mmio(dev, regs,
1524*4882a593Smuzhiyun &inno_hdmi_phy_regmap_config);
1525*4882a593Smuzhiyun if (IS_ERR(inno->regmap)) {
1526*4882a593Smuzhiyun ret = PTR_ERR(inno->regmap);
1527*4882a593Smuzhiyun dev_err(dev, "failed to init regmap: %d\n", ret);
1528*4882a593Smuzhiyun goto err_regsmap;
1529*4882a593Smuzhiyun }
1530*4882a593Smuzhiyun
1531*4882a593Smuzhiyun inno->phy = devm_phy_create(dev, NULL, &inno_hdmi_phy_ops);
1532*4882a593Smuzhiyun if (IS_ERR(inno->phy)) {
1533*4882a593Smuzhiyun dev_err(dev, "failed to create HDMI PHY\n");
1534*4882a593Smuzhiyun ret = PTR_ERR(inno->phy);
1535*4882a593Smuzhiyun goto err_regsmap;
1536*4882a593Smuzhiyun }
1537*4882a593Smuzhiyun
1538*4882a593Smuzhiyun if (of_get_property(np, "rockchip,phy-table", &val)) {
1539*4882a593Smuzhiyun if (val % PHY_TAB_LEN || !val) {
1540*4882a593Smuzhiyun dev_err(dev, "Invalid phy cfg table format!\n");
1541*4882a593Smuzhiyun ret = -EINVAL;
1542*4882a593Smuzhiyun goto err_regsmap;
1543*4882a593Smuzhiyun }
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun phy_config = kmalloc(val, GFP_KERNEL);
1546*4882a593Smuzhiyun if (!phy_config) {
1547*4882a593Smuzhiyun dev_err(dev, "kmalloc phy table failed\n");
1548*4882a593Smuzhiyun ret = -ENOMEM;
1549*4882a593Smuzhiyun goto err_regsmap;
1550*4882a593Smuzhiyun }
1551*4882a593Smuzhiyun
1552*4882a593Smuzhiyun phy_table_size = val / PHY_TAB_LEN;
1553*4882a593Smuzhiyun /* Effective phy cfg data and the end of phy cfg table */
1554*4882a593Smuzhiyun inno->phy_cfg = devm_kzalloc(dev, val + PHY_TAB_LEN,
1555*4882a593Smuzhiyun GFP_KERNEL);
1556*4882a593Smuzhiyun if (!inno->phy_cfg) {
1557*4882a593Smuzhiyun kfree(phy_config);
1558*4882a593Smuzhiyun ret = -ENOMEM;
1559*4882a593Smuzhiyun goto err_regsmap;
1560*4882a593Smuzhiyun }
1561*4882a593Smuzhiyun of_property_read_u32_array(np, "rockchip,phy-table",
1562*4882a593Smuzhiyun phy_config, val / sizeof(u32));
1563*4882a593Smuzhiyun ret = inno_hdmi_update_phy_table(inno, phy_config,
1564*4882a593Smuzhiyun inno->phy_cfg,
1565*4882a593Smuzhiyun phy_table_size);
1566*4882a593Smuzhiyun if (ret) {
1567*4882a593Smuzhiyun kfree(phy_config);
1568*4882a593Smuzhiyun goto err_regsmap;
1569*4882a593Smuzhiyun }
1570*4882a593Smuzhiyun kfree(phy_config);
1571*4882a593Smuzhiyun } else {
1572*4882a593Smuzhiyun dev_dbg(dev, "use default hdmi phy table\n");
1573*4882a593Smuzhiyun }
1574*4882a593Smuzhiyun
1575*4882a593Smuzhiyun phy_set_drvdata(inno->phy, inno);
1576*4882a593Smuzhiyun phy_set_bus_width(inno->phy, 8);
1577*4882a593Smuzhiyun
1578*4882a593Smuzhiyun phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
1579*4882a593Smuzhiyun if (IS_ERR(phy_provider)) {
1580*4882a593Smuzhiyun dev_err(dev, "failed to register PHY provider\n");
1581*4882a593Smuzhiyun ret = PTR_ERR(phy_provider);
1582*4882a593Smuzhiyun goto err_regsmap;
1583*4882a593Smuzhiyun }
1584*4882a593Smuzhiyun
1585*4882a593Smuzhiyun if (inno->plat_data->ops->init)
1586*4882a593Smuzhiyun inno->plat_data->ops->init(inno);
1587*4882a593Smuzhiyun
1588*4882a593Smuzhiyun ret = inno_hdmi_phy_clk_register(inno);
1589*4882a593Smuzhiyun if (ret)
1590*4882a593Smuzhiyun goto err_regsmap;
1591*4882a593Smuzhiyun
1592*4882a593Smuzhiyun inno->irq = platform_get_irq(pdev, 0);
1593*4882a593Smuzhiyun if (inno->irq > 0) {
1594*4882a593Smuzhiyun ret = devm_request_threaded_irq(inno->dev, inno->irq,
1595*4882a593Smuzhiyun inno_hdmi_phy_hardirq,
1596*4882a593Smuzhiyun inno_hdmi_phy_irq, IRQF_SHARED,
1597*4882a593Smuzhiyun dev_name(inno->dev), inno);
1598*4882a593Smuzhiyun if (ret)
1599*4882a593Smuzhiyun goto err_irq;
1600*4882a593Smuzhiyun }
1601*4882a593Smuzhiyun platform_set_drvdata(pdev, inno);
1602*4882a593Smuzhiyun return 0;
1603*4882a593Smuzhiyun
1604*4882a593Smuzhiyun err_irq:
1605*4882a593Smuzhiyun of_clk_del_provider(pdev->dev.of_node);
1606*4882a593Smuzhiyun err_regsmap:
1607*4882a593Smuzhiyun clk_disable_unprepare(inno->sysclk);
1608*4882a593Smuzhiyun return ret;
1609*4882a593Smuzhiyun }
1610*4882a593Smuzhiyun
inno_hdmi_phy_remove(struct platform_device * pdev)1611*4882a593Smuzhiyun static int inno_hdmi_phy_remove(struct platform_device *pdev)
1612*4882a593Smuzhiyun {
1613*4882a593Smuzhiyun struct inno_hdmi_phy *inno = platform_get_drvdata(pdev);
1614*4882a593Smuzhiyun
1615*4882a593Smuzhiyun of_clk_del_provider(pdev->dev.of_node);
1616*4882a593Smuzhiyun clk_disable_unprepare(inno->sysclk);
1617*4882a593Smuzhiyun return 0;
1618*4882a593Smuzhiyun }
1619*4882a593Smuzhiyun
1620*4882a593Smuzhiyun static struct platform_driver inno_hdmi_phy_driver = {
1621*4882a593Smuzhiyun .probe = inno_hdmi_phy_probe,
1622*4882a593Smuzhiyun .remove = inno_hdmi_phy_remove,
1623*4882a593Smuzhiyun .driver = {
1624*4882a593Smuzhiyun .name = "inno-hdmi-phy",
1625*4882a593Smuzhiyun .of_match_table = of_match_ptr(inno_hdmi_phy_of_match),
1626*4882a593Smuzhiyun },
1627*4882a593Smuzhiyun };
1628*4882a593Smuzhiyun
1629*4882a593Smuzhiyun module_platform_driver(inno_hdmi_phy_driver);
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun MODULE_DESCRIPTION("Innosilion HDMI 2.0 Transmitter PHY Driver");
1632*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
1633