1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
| // SPDX-License-Identifier: GPL-2.0+
| /*
| * (C) Copyright 2008-2018 Fuzhou Rockchip Electronics Co., Ltd
| *
| * Author: Wyon Bi <bivvy.bi@rock-chips.com>
| */
|
| #include <config.h>
| #include <common.h>
| #include <errno.h>
| #include <dm.h>
| #include <asm/io.h>
| #include <linux/iopoll.h>
|
| #include "rockchip_phy.h"
|
| /* Register: 0x0030 */
| #define DISABLE_PLL BIT(3)
| /* Register: 0x003c */
| #define PLL_LOCK BIT(1)
| /* Register: 0x0084 */
| #define ENABLE_TX BIT(7)
|
| struct inno_video_phy {
| void __iomem *base;
| enum phy_mode mode;
| bool dual_channel;
| };
|
| struct reg_sequence {
| unsigned int reg;
| unsigned int def;
| unsigned int delay_us;
| };
|
| static const struct reg_sequence ttl_mode[] = {
| { 0x0000, 0x7f },
| { 0x0004, 0x3f },
| { 0x0008, 0x80 },
| { 0x0010, 0x3f },
| { 0x0014, 0x3f },
| { 0x0080, 0x44 },
|
| { 0x0100, 0x7f },
| { 0x0104, 0x3f },
| { 0x0108, 0x80 },
| { 0x0110, 0x3f },
| { 0x0114, 0x3f },
| { 0x0180, 0x44 },
| };
|
| static const struct reg_sequence lvds_mode_single_channel[] = {
| { 0x0000, 0xbf },
| { 0x0004, 0x3f },
| { 0x0008, 0xfe },
| { 0x0010, 0x00 },
| { 0x0014, 0x00 },
| { 0x0080, 0x44 },
|
| { 0x0100, 0x00 },
| { 0x0104, 0x00 },
| { 0x0108, 0x00 },
| { 0x0110, 0x00 },
| { 0x0114, 0x00 },
| { 0x0180, 0x44 },
| };
|
| static const struct reg_sequence lvds_mode_dual_channel[] = {
| { 0x0000, 0xbf },
| { 0x0004, 0x3f },
| { 0x0008, 0xfe },
| { 0x0010, 0x00 },
| { 0x0014, 0x00 },
| { 0x0080, 0x44 },
|
| { 0x0100, 0xbf },
| { 0x0104, 0x3f },
| { 0x0108, 0xfe },
| { 0x0110, 0x00 },
| { 0x0114, 0x00 },
| { 0x0180, 0x44 },
| };
|
| static inline void phy_write(struct inno_video_phy *inno, u32 reg, u32 val)
| {
| writel(val, inno->base + reg);
| }
|
| static inline u32 phy_read(struct inno_video_phy *inno, u32 reg)
| {
| return readl(inno->base + reg);
| }
|
| static inline void phy_update_bits(struct inno_video_phy *inno,
| u32 reg, u32 mask, u32 val)
| {
| u32 tmp, orig;
|
| orig = phy_read(inno, reg);
| tmp = orig & ~mask;
| tmp |= val & mask;
| phy_write(inno, reg, tmp);
| }
|
| static void phy_multi_write(struct inno_video_phy *inno,
| const struct reg_sequence *regs, int num_regs)
| {
| int i;
|
| for (i = 0; i < num_regs; i++) {
| phy_write(inno, regs[i].reg, regs[i].def);
|
| if (regs[i].delay_us)
| udelay(regs[i].delay_us);
| }
| }
|
| static int inno_video_phy_power_on(struct rockchip_phy *phy)
| {
| struct inno_video_phy *inno = dev_get_priv(phy->dev);
| const struct reg_sequence *wseq;
| int nregs;
| u32 status;
| int ret;
|
| switch (inno->mode) {
| case PHY_MODE_VIDEO_LVDS:
| if (inno->dual_channel) {
| wseq = lvds_mode_dual_channel;
| nregs = ARRAY_SIZE(lvds_mode_dual_channel);
| } else {
| wseq = lvds_mode_single_channel;
| nregs = ARRAY_SIZE(lvds_mode_single_channel);
| }
| break;
| case PHY_MODE_VIDEO_TTL:
| wseq = ttl_mode;
| nregs = ARRAY_SIZE(ttl_mode);
| break;
| default:
| return -EINVAL;
| }
|
| phy_multi_write(inno, wseq, nregs);
|
| phy_update_bits(inno, 0x0030, DISABLE_PLL, 0);
| ret = readl_poll_timeout(inno->base + 0x003c, status,
| status & PLL_LOCK, 100000);
| if (ret) {
| dev_err(phy->dev, "PLL is not lock\n");
| return ret;
| }
|
| phy_update_bits(inno, 0x0084, ENABLE_TX, ENABLE_TX);
|
| return 0;
| }
|
| static int inno_video_phy_power_off(struct rockchip_phy *phy)
| {
| struct inno_video_phy *inno = dev_get_priv(phy->dev);
|
| phy_update_bits(inno, 0x0084, ENABLE_TX, 0);
| phy_update_bits(inno, 0x0030, DISABLE_PLL, DISABLE_PLL);
|
| return 0;
| }
|
| static int inno_video_phy_set_mode(struct rockchip_phy *phy,
| enum phy_mode mode)
| {
| struct inno_video_phy *inno = dev_get_priv(phy->dev);
|
| switch (mode) {
| case PHY_MODE_VIDEO_LVDS:
| case PHY_MODE_VIDEO_TTL:
| inno->mode = mode;
| break;
| default:
| return -EINVAL;
| }
|
| return 0;
| }
|
| static int
| inno_video_phy_set_bus_width(struct rockchip_phy *phy, u32 bus_width)
| {
| struct inno_video_phy *inno = dev_get_priv(phy->dev);
|
| inno->dual_channel = (bus_width == 2) ? true : false;
|
| return 0;
| }
|
| static const struct rockchip_phy_funcs inno_video_phy_funcs = {
| .power_on = inno_video_phy_power_on,
| .power_off = inno_video_phy_power_off,
| .set_mode = inno_video_phy_set_mode,
| .set_bus_width = inno_video_phy_set_bus_width,
| };
|
| static int inno_video_phy_probe(struct udevice *dev)
| {
| struct inno_video_phy *inno = dev_get_priv(dev);
| struct rockchip_phy *phy =
| (struct rockchip_phy *)dev_get_driver_data(dev);
|
| inno->base = dev_read_addr_ptr(dev);
| phy->dev = dev;
|
| return 0;
| }
|
| static struct rockchip_phy inno_video_phy_driver_data = {
| .funcs = &inno_video_phy_funcs,
| };
|
| static const struct udevice_id inno_video_phy_ids[] = {
| {
| .compatible = "rockchip,rk3288-video-phy",
| .data = (ulong)&inno_video_phy_driver_data,
| },
| {}
| };
|
| U_BOOT_DRIVER(inno_video_phy) = {
| .name = "inno_video_phy",
| .id = UCLASS_PHY,
| .of_match = inno_video_phy_ids,
| .probe = inno_video_phy_probe,
| .priv_auto_alloc_size = sizeof(struct inno_video_phy),
| };
|
|