ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[firefly-linux-kernel-4.4.55.git] / drivers / phy / phy-rockchip-inno-mipi-dphy.c
1 /*
2  * Copyright (c) 2017 Rockchip Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/init.h>
17 #include <linux/io.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/phy/phy.h>
21 #include <linux/platform_device.h>
22 #include <linux/regmap.h>
23 #include <linux/reset.h>
24
25 #include <drm/drm_mipi_dsi.h>
26
27 #include <video/mipi_display.h>
28 #include <video/of_videomode.h>
29 #include <video/videomode.h>
30
31 #define DRV_NAME        "inno-mipi-dphy"
32
33 #define INNO_PHY_LANE_CTRL      0x00000
34 #define INNO_PHY_POWER_CTRL     0x00004
35 #define INNO_PHY_PLL_CTRL_0     0x0000c
36 #define INNO_PHY_PLL_CTRL_1     0x00010
37 #define INNO_PHY_DIG_CTRL       0x00080
38 #define INNO_PHY_PIN_CTRL       0x00084
39
40 #define INNO_CLOCK_LANE_REG_BASE        0x00100
41 #define INNO_DATA_LANE_0_REG_BASE       0x00180
42 #define INNO_DATA_LANE_1_REG_BASE       0x00200
43 #define INNO_DATA_LANE_2_REG_BASE       0x00280
44 #define INNO_DATA_LANE_3_REG_BASE       0x00300
45
46 #define T_LPX_OFFSET            0x00014
47 #define T_HS_PREPARE_OFFSET     0x00018
48 #define T_HS_ZERO_OFFSET        0x0001c
49 #define T_HS_TRAIL_OFFSET       0x00020
50 #define T_HS_EXIT_OFFSET        0x00024
51 #define T_CLK_POST_OFFSET       0x00028
52 #define T_WAKUP_H_OFFSET        0x00030
53 #define T_WAKUP_L_OFFSET        0x00034
54 #define T_CLK_PRE_OFFSET        0x00038
55 #define T_TA_GO_OFFSET          0x00040
56 #define T_TA_SURE_OFFSET        0x00044
57 #define T_TA_WAIT_OFFSET        0x00048
58
59 #define CLK_LANE_EN_MASK        BIT(6)
60 #define DATA_LANE_3_EN_MASK     BIT(5)
61 #define DATA_LANE_2_EN_MASK     BIT(4)
62 #define DATA_LANE_1_EN_MASK     BIT(3)
63 #define DATA_LANE_0_EN_MASK     BIT(2)
64 #define CLK_LANE_EN             BIT(6)
65 #define DATA_LANE_3_EN          BIT(5)
66 #define DATA_LANE_2_EN          BIT(4)
67 #define DATA_LANE_1_EN          BIT(3)
68 #define DATA_LANE_0_EN          BIT(2)
69 #define FBDIV_8_MASK            BIT(5)
70 #define PREDIV_MASK             (0x1f << 0)
71 #define FBDIV_7_0_MASK          (0xff << 0)
72 #define FBDIV_8(x)              (((x) & 0x1) << 5)
73 #define PREDIV(x)               (((x) & 0x1f) << 0)
74 #define FBDIV_7_0(x)            (((x) & 0xff) << 0)
75 #define T_LPX_MASK              (0x3f << 0)
76 #define T_HS_PREPARE_MASK       (0x7f << 0)
77 #define T_HS_ZERO_MASK          (0x3f << 0)
78 #define T_HS_TRAIL_MASK         (0x7f << 0)
79 #define T_HS_EXIT_MASK          (0x1f << 0)
80 #define T_CLK_POST_MASK         (0xf << 0)
81 #define T_WAKUP_H_MASK          (0x3 << 0)
82 #define T_WAKUP_L_MASK          (0xff << 0)
83 #define T_CLK_PRE_MASK          (0xf << 0)
84 #define T_TA_GO_MASK            (0x3f << 0)
85 #define T_TA_SURE_MASK          (0x3f << 0)
86 #define T_TA_WAIT_MASK          (0x3f << 0)
87 #define T_LPX(x)                (((x) & 0x3f) << 0)
88 #define T_HS_PREPARE(x)         (((x) & 0x7f) << 0)
89 #define T_HS_ZERO(x)            (((x) & 0x3f) << 0)
90 #define T_HS_TRAIL(x)           (((x) & 0x7f) << 0)
91 #define T_HS_EXIT(x)            (((x) & 0x1f) << 0)
92 #define T_CLK_POST(x)           (((x) & 0xf) << 0)
93 #define T_WAKUP_H(x)            (((x) & 0x3) << 0)
94 #define T_WAKUP_L(x)            (((x) & 0xff) << 0)
95 #define T_CLK_PRE(x)            (((x) & 0xf) << 0)
96 #define T_TA_GO(x)              (((x) & 0x3f) << 0)
97 #define T_TA_SURE(x)            (((x) & 0x3f) << 0)
98 #define T_TA_WAIT(x)            (((x) & 0x3f) << 0)
99
100 enum lane_type {
101         CLOCK_LANE,
102         DATA_LANE_0,
103         DATA_LANE_1,
104         DATA_LANE_2,
105         DATA_LANE_3,
106 };
107
108 struct t_param {
109         u32 hs_clk_rate;
110         u8 t_hs_prepare;
111         u8 clock_lane_t_hs_zero;
112         u8 data_lane_t_hs_zero;
113         u8 t_hs_trail;
114 };
115
116 struct mipi_dphy_timing {
117         unsigned int clkmiss;
118         unsigned int clkpost;
119         unsigned int clkpre;
120         unsigned int clkprepare;
121         unsigned int clksettle;
122         unsigned int clktermen;
123         unsigned int clktrail;
124         unsigned int clkzero;
125         unsigned int dtermen;
126         unsigned int eot;
127         unsigned int hsexit;
128         unsigned int hsprepare;
129         unsigned int hszero;
130         unsigned int hssettle;
131         unsigned int hsskip;
132         unsigned int hstrail;
133         unsigned int init;
134         unsigned int lpx;
135         unsigned int taget;
136         unsigned int tago;
137         unsigned int tasure;
138         unsigned int wakeup;
139 };
140
141 struct inno_mipi_dphy_timing {
142         u8 t_lpx;
143         u8 t_hs_prepare;
144         u8 t_hs_zero;
145         u8 t_hs_trail;
146         u8 t_hs_exit;
147         u8 t_clk_post;
148         u8 t_wakup_h;
149         u8 t_wakup_l;
150         u8 t_clk_pre;
151         u8 t_ta_go;
152         u8 t_ta_sure;
153         u8 t_ta_wait;
154 };
155
156 struct dsi_panel {
157         struct videomode vm;
158         int bpp;
159 };
160
161 struct inno_mipi_dphy {
162         struct device *dev;
163         struct phy *phy;
164         void __iomem *regs;
165         struct clk *ref_clk;
166         struct clk *pclk;
167         struct reset_control *rst;
168
169         struct dsi_panel *panel;
170         u32 lanes;
171         u32 lane_mbps;
172 };
173
174 static const u32 lane_reg_offset[] = {
175         [CLOCK_LANE] = INNO_CLOCK_LANE_REG_BASE,
176         [DATA_LANE_0] = INNO_DATA_LANE_0_REG_BASE,
177         [DATA_LANE_1] = INNO_DATA_LANE_1_REG_BASE,
178         [DATA_LANE_2] = INNO_DATA_LANE_2_REG_BASE,
179         [DATA_LANE_3] = INNO_DATA_LANE_3_REG_BASE,
180 };
181
182 static const struct t_param t_fixed_param_table[] = {
183         { 110, 0x20, 0x16, 0x02, 0x22},
184         { 150, 0x06, 0x16, 0x03, 0x45},
185         { 200, 0x18, 0x17, 0x04, 0x0b},
186         { 250, 0x05, 0x17, 0x05, 0x16},
187         { 300, 0x51, 0x18, 0x06, 0x2c},
188         { 400, 0x64, 0x19, 0x07, 0x33},
189         { 500, 0x20, 0x1b, 0x07, 0x4e},
190         { 600, 0x6a, 0x1d, 0x08, 0x3a},
191         { 700, 0x3e, 0x1e, 0x08, 0x6a},
192         { 800, 0x21, 0x1f, 0x09, 0x29},
193         {1000, 0x09, 0x20, 0x09, 0x27}
194 };
195
196 static inline void inno_write(struct inno_mipi_dphy *inno, u32 reg, u32 val)
197 {
198         writel_relaxed(val, inno->regs + reg);
199 }
200
201 static inline u32 inno_read(struct inno_mipi_dphy *inno, u32 reg)
202 {
203         return readl_relaxed(inno->regs + reg);
204 }
205
206 static inline void inno_update_bits(struct inno_mipi_dphy *inno, u32 reg,
207                                     u32 mask, u32 val)
208 {
209         u32 tmp, orig;
210
211         orig = inno_read(inno, reg);
212         tmp = orig & ~mask;
213         tmp |= val & mask;
214         inno_write(inno, reg, tmp);
215 }
216
217 static void mipi_dphy_timing_get_default(struct mipi_dphy_timing *timing,
218                                          unsigned long period)
219 {
220         /* Global Operation Timing Parameters */
221         timing->clkmiss = 0;
222         timing->clkpost = 70 + 52 * period;
223         timing->clkpre = 8;
224         timing->clkprepare = 65;
225         timing->clksettle = 95;
226         timing->clktermen = 0;
227         timing->clktrail = 80;
228         timing->clkzero = 260;
229         timing->dtermen = 0;
230         timing->eot = 0;
231         timing->hsexit = 120;
232         timing->hsprepare = 65 + 5 * period;
233         timing->hszero = 145 + 5 * period;
234         timing->hssettle = 85 + 6 * period;
235         timing->hsskip = 40;
236         timing->hstrail = max(4 * 8 * period, 60 + 4 * 4 * period);
237         timing->init = 100000;
238         timing->lpx = 60;
239         timing->taget = 5 * timing->lpx;
240         timing->tago = 4 * timing->lpx;
241         timing->tasure = timing->lpx;
242         timing->wakeup = 1000000;
243 }
244
245 static void inno_mipi_dphy_timing_update(struct inno_mipi_dphy *inno,
246                                          enum lane_type lane_type,
247                                          struct inno_mipi_dphy_timing *t)
248 {
249         u32 base = lane_reg_offset[lane_type];
250         u32 val, mask;
251
252         mask = T_HS_PREPARE_MASK;
253         val = T_HS_PREPARE(t->t_hs_prepare);
254         inno_update_bits(inno, base + T_HS_PREPARE_OFFSET, mask, val);
255
256         mask = T_HS_ZERO_MASK;
257         val = T_HS_ZERO(t->t_hs_zero);
258         inno_update_bits(inno, base + T_HS_ZERO_OFFSET, mask, val);
259
260         mask = T_HS_TRAIL_MASK;
261         val = T_HS_TRAIL(t->t_hs_trail);
262         inno_update_bits(inno, base + T_HS_TRAIL_OFFSET, mask, val);
263
264         mask = T_HS_EXIT_MASK;
265         val = T_HS_EXIT(t->t_hs_exit);
266         inno_update_bits(inno, base + T_HS_EXIT_OFFSET, mask, val);
267
268         if (lane_type == CLOCK_LANE) {
269                 mask = T_CLK_POST_MASK;
270                 val = T_CLK_POST(t->t_clk_post);
271                 inno_update_bits(inno, base + T_CLK_POST_OFFSET, mask, val);
272
273                 mask = T_CLK_PRE_MASK;
274                 val = T_CLK_PRE(t->t_clk_pre);
275                 inno_update_bits(inno, base + T_CLK_PRE_OFFSET, mask, val);
276         }
277
278         mask = T_WAKUP_H_MASK;
279         val = T_WAKUP_H(t->t_wakup_h);
280         inno_update_bits(inno, base + T_WAKUP_H_OFFSET, mask, val);
281
282         mask = T_WAKUP_L_MASK;
283         val = T_WAKUP_L(t->t_wakup_l);
284         inno_update_bits(inno, base + T_WAKUP_L_OFFSET, mask, val);
285
286         mask = T_LPX_MASK;
287         val = T_LPX(t->t_lpx);
288         inno_update_bits(inno, base + T_LPX_OFFSET, mask, val);
289
290         mask = T_TA_GO_MASK;
291         val = T_TA_GO(t->t_ta_go);
292         inno_update_bits(inno, base + T_TA_GO_OFFSET, mask, val);
293
294         mask = T_TA_SURE_MASK;
295         val = T_TA_SURE(t->t_ta_sure);
296         inno_update_bits(inno, base + T_TA_SURE_OFFSET, mask, val);
297
298         mask = T_TA_WAIT_MASK;
299         val = T_TA_WAIT(t->t_ta_wait);
300         inno_update_bits(inno, base + T_TA_WAIT_OFFSET, mask, val);
301 }
302
303 static int inno_mipi_dphy_get_fixed_param(struct inno_mipi_dphy_timing *t,
304                                           u32 hs_clk_rate,
305                                           enum lane_type lane_type)
306 {
307         const struct t_param *param;
308         int i;
309
310         for (i = 0; i < ARRAY_SIZE(t_fixed_param_table); i++) {
311                 if (hs_clk_rate <= t_fixed_param_table[i].hs_clk_rate)
312                         break;
313         }
314
315         if (i == ARRAY_SIZE(t_fixed_param_table))
316                 return -EINVAL;
317
318         param = &t_fixed_param_table[i];
319
320         if (lane_type == CLOCK_LANE)
321                 t->t_hs_zero = param->clock_lane_t_hs_zero;
322         else
323                 t->t_hs_zero = param->data_lane_t_hs_zero;
324
325         t->t_hs_prepare = param->t_hs_prepare;
326         t->t_hs_trail = param->t_hs_trail;
327
328         return 0;
329 }
330
331 static void inno_mipi_dphy_lane_timing_init(struct inno_mipi_dphy *inno,
332                                             enum lane_type lane_type)
333 {
334         struct mipi_dphy_timing timing;
335         struct inno_mipi_dphy_timing data;
336         u32 txbyteclkhs = inno->lane_mbps / 8;  /* MHz */
337         u32 txclkesc = 20;      /* MHz */
338         u32 UI = DIV_ROUND_CLOSEST(NSEC_PER_USEC, inno->lane_mbps);     /* ns */
339
340         memset(&timing, 0, sizeof(timing));
341         memset(&data, 0, sizeof(data));
342
343         mipi_dphy_timing_get_default(&timing, UI);
344         inno_mipi_dphy_get_fixed_param(&data, inno->lane_mbps, lane_type);
345
346         /* txbyteclkhs domain */
347         data.t_hs_exit = DIV_ROUND_UP(txbyteclkhs * timing.hsexit,
348                                       NSEC_PER_USEC);
349         data.t_clk_post = DIV_ROUND_UP(txbyteclkhs * timing.clkpost,
350                                        NSEC_PER_USEC);
351         data.t_clk_pre = DIV_ROUND_UP(txbyteclkhs * timing.clkpre,
352                                       NSEC_PER_USEC);
353         data.t_wakup_h = 0x3;
354         data.t_wakup_l = 0xff;
355         data.t_lpx = txbyteclkhs * timing.lpx / NSEC_PER_USEC;
356
357         /* txclkesc domain */
358         data.t_ta_go = DIV_ROUND_UP(txclkesc * timing.tago, NSEC_PER_USEC);
359         data.t_ta_sure = DIV_ROUND_UP(txclkesc * timing.tasure, NSEC_PER_USEC);
360         data.t_ta_wait = DIV_ROUND_UP(txclkesc * timing.taget, NSEC_PER_USEC);
361
362         inno_mipi_dphy_timing_update(inno, lane_type, &data);
363 }
364
365 static void inno_mipi_dphy_pll_init(struct inno_mipi_dphy *inno)
366 {
367         struct dsi_panel *panel = inno->panel;
368         unsigned int i, pre;
369         unsigned int mpclk, pllref, tmp;
370         unsigned int target_mbps = 1000;
371         unsigned int max_mbps = 1000;
372         u32 fbdiv = 1, prediv = 1;
373         u32 val, mask;
374
375         mpclk = DIV_ROUND_UP(panel->vm.pixelclock, USEC_PER_SEC);
376         if (mpclk) {
377                 /* take 1 / 0.9, since mbps must big than bandwidth of RGB */
378                 tmp = mpclk * (panel->bpp / inno->lanes) * 10 / 9;
379                 if (tmp < max_mbps)
380                         target_mbps = tmp;
381                 else
382                         dev_err(inno->dev, "DPHY clock frequency is out of range\n");
383         }
384
385         pllref = DIV_ROUND_UP(clk_get_rate(inno->ref_clk) / 2, USEC_PER_SEC);
386         tmp = pllref;
387
388         for (i = 1; i < 6; i++) {
389                 if (pllref % i)
390                         continue;
391                 pre = pllref / i;
392                 if ((tmp > (target_mbps % pre)) && (target_mbps / pre < 512)) {
393                         tmp = target_mbps % pre;
394                         prediv = i;
395                         fbdiv = target_mbps / pre;
396                 }
397                 if (tmp == 0)
398                         break;
399         }
400
401         inno->lane_mbps = pllref / prediv * fbdiv;
402         phy_set_bus_width(inno->phy, inno->lane_mbps);
403
404         mask = FBDIV_8_MASK | PREDIV_MASK;
405         val = FBDIV_8(fbdiv >> 8) | PREDIV(prediv);
406         inno_update_bits(inno, INNO_PHY_PLL_CTRL_0, mask, val);
407
408         mask = FBDIV_7_0_MASK;
409         val = FBDIV_7_0(fbdiv);
410         inno_update_bits(inno, INNO_PHY_PLL_CTRL_1, mask, val);
411
412         dev_info(inno->dev, "fin=%d, target_mbps=%d, fout=%d, prediv=%d, fbdiv=%d\n",
413                  pllref, target_mbps, inno->lane_mbps, prediv, fbdiv);
414 }
415
416 static void inno_mipi_dphy_reset(struct inno_mipi_dphy *inno)
417 {
418         /* Reset analog */
419         inno_write(inno, INNO_PHY_POWER_CTRL, 0xe0);
420         udelay(10);
421         /* Reset digital */
422         inno_write(inno, INNO_PHY_DIG_CTRL, 0x1e);
423         udelay(10);
424         inno_write(inno, INNO_PHY_DIG_CTRL, 0x1f);
425         udelay(10);
426 }
427
428 static void inno_mipi_dphy_timing_init(struct inno_mipi_dphy *inno)
429 {
430         switch (inno->lanes) {
431         case 4:
432                 inno_mipi_dphy_lane_timing_init(inno, DATA_LANE_3);
433                 /* Fall through */
434         case 3:
435                 inno_mipi_dphy_lane_timing_init(inno, DATA_LANE_2);
436                 /* Fall through */
437         case 2:
438                 inno_mipi_dphy_lane_timing_init(inno, DATA_LANE_1);
439                 /* Fall through */
440         case 1:
441         default:
442                 inno_mipi_dphy_lane_timing_init(inno, DATA_LANE_0);
443                 inno_mipi_dphy_lane_timing_init(inno, CLOCK_LANE);
444                 break;
445         }
446 }
447
448 static inline void inno_mipi_dphy_lane_enable(struct inno_mipi_dphy *inno)
449 {
450         u32 val = 0;
451         u32 mask = 0;
452
453         switch (inno->lanes) {
454         case 4:
455                 mask |= DATA_LANE_3_EN_MASK;
456                 val |= DATA_LANE_3_EN;
457                 /* Fall through */
458         case 3:
459                 mask |= DATA_LANE_2_EN_MASK;
460                 val |= DATA_LANE_2_EN;
461                 /* Fall through */
462         case 2:
463                 mask |= DATA_LANE_1_EN_MASK;
464                 val |= DATA_LANE_1_EN;
465                 /* Fall through */
466         default:
467         case 1:
468                 mask |= DATA_LANE_0_EN_MASK | CLK_LANE_EN_MASK;
469                 val |= DATA_LANE_0_EN | CLK_LANE_EN;
470                 break;
471         }
472
473         inno_update_bits(inno, INNO_PHY_LANE_CTRL, mask, val);
474 }
475
476 static inline void inno_mipi_dphy_pll_ldo_enable(struct inno_mipi_dphy *inno)
477 {
478         inno_write(inno, INNO_PHY_POWER_CTRL, 0xe4);
479         udelay(10);
480 }
481
482 static int inno_mipi_dphy_power_on(struct phy *phy)
483 {
484         struct inno_mipi_dphy *inno = phy_get_drvdata(phy);
485
486         clk_prepare_enable(inno->ref_clk);
487         clk_prepare_enable(inno->pclk);
488
489         if (inno->rst) {
490                 /* MIPI DSI PHY APB software reset request. */
491                 reset_control_assert(inno->rst);
492                 usleep_range(20, 40);
493                 reset_control_deassert(inno->rst);
494         }
495
496         inno_mipi_dphy_pll_init(inno);
497         inno_mipi_dphy_pll_ldo_enable(inno);
498         inno_mipi_dphy_lane_enable(inno);
499         inno_mipi_dphy_reset(inno);
500         inno_mipi_dphy_timing_init(inno);
501
502         dev_info(inno->dev, "Inno MIPI-DPHY Power-On\n");
503
504         return 0;
505 }
506
507 static inline void inno_mipi_dphy_lane_disable(struct inno_mipi_dphy *inno)
508 {
509         inno_update_bits(inno, INNO_PHY_LANE_CTRL, 0x7c, 0x00);
510 }
511
512 static inline void inno_mipi_dphy_pll_ldo_disable(struct inno_mipi_dphy *inno)
513 {
514         inno_write(inno, INNO_PHY_POWER_CTRL, 0xe3);
515         udelay(10);
516 }
517
518 static int inno_mipi_dphy_power_off(struct phy *phy)
519 {
520         struct inno_mipi_dphy *inno = phy_get_drvdata(phy);
521
522         inno_mipi_dphy_lane_disable(inno);
523         inno_mipi_dphy_pll_ldo_disable(inno);
524
525         clk_disable_unprepare(inno->pclk);
526         clk_disable_unprepare(inno->ref_clk);
527
528         dev_info(inno->dev, "Inno MIPI-DPHY Power-Off\n");
529
530         return 0;
531 }
532
533 static const struct phy_ops inno_mipi_dphy_ops = {
534         .power_on = inno_mipi_dphy_power_on,
535         .power_off = inno_mipi_dphy_power_off,
536         .owner = THIS_MODULE,
537 };
538
539 static int get_bpp(struct device_node *np)
540 {
541         u32 format = 0;
542
543         if (of_property_read_u32(np, "dsi,format", &format))
544                 return 24;
545
546         switch (format) {
547         case MIPI_DSI_FMT_RGB666_PACKED:
548                 return 18;
549         case MIPI_DSI_FMT_RGB565:
550                 return 16;
551         case MIPI_DSI_FMT_RGB888:
552         case MIPI_DSI_FMT_RGB666:
553         default:
554                 return 24;
555         }
556 }
557
558 static int inno_mipi_dphy_parse_dt(struct device_node *np,
559                                    struct inno_mipi_dphy *inno)
560 {
561         struct device_node *panel_node;
562         struct dsi_panel *panel;
563         int ret;
564
565         panel_node = of_parse_phandle(np, "rockchip,dsi-panel", 0);
566         if (!panel_node) {
567                 dev_err(inno->dev, "Missing 'rockchip,dsi-panel' property");
568                 return -ENODEV;
569         }
570
571         panel = devm_kzalloc(inno->dev, sizeof(*panel), GFP_KERNEL);
572         if (!panel) {
573                 ret = -ENOMEM;
574                 goto put_panel_node;
575         }
576
577         ret = of_get_videomode(panel_node, &panel->vm, 0);
578         if (ret < 0)
579                 goto put_panel_node;
580
581         panel->bpp = get_bpp(panel_node);
582
583         if (of_property_read_u32(panel_node, "dsi,lanes", &inno->lanes))
584                 inno->lanes = 4;
585
586         of_node_put(panel_node);
587
588         inno->panel = panel;
589
590         return 0;
591
592 put_panel_node:
593         of_node_put(panel_node);
594         return ret;
595 }
596
597 static int inno_mipi_dphy_probe(struct platform_device *pdev)
598 {
599         struct device_node *np = pdev->dev.of_node;
600         struct inno_mipi_dphy *inno;
601         struct phy_provider *phy_provider;
602         struct resource *res;
603         int ret;
604
605         inno = devm_kzalloc(&pdev->dev, sizeof(*inno), GFP_KERNEL);
606         if (!inno)
607                 return -ENOMEM;
608
609         inno->dev = &pdev->dev;
610         platform_set_drvdata(pdev, inno);
611
612         ret = inno_mipi_dphy_parse_dt(np, inno);
613         if (ret) {
614                 dev_err(&pdev->dev, "failed to parse DT\n");
615                 return ret;
616         }
617
618         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
619         inno->regs = devm_ioremap_resource(&pdev->dev, res);
620         if (IS_ERR(inno->regs))
621                 return PTR_ERR(inno->regs);
622
623         inno->ref_clk = devm_clk_get(&pdev->dev, "ref");
624         if (IS_ERR(inno->ref_clk)) {
625                 dev_err(&pdev->dev, "failed to get mipi dphy ref clk\n");
626                 return PTR_ERR(inno->ref_clk);
627         }
628
629         clk_set_rate(inno->ref_clk, 24000000);
630
631         inno->pclk = devm_clk_get(&pdev->dev, "pclk");
632         if (IS_ERR(inno->pclk)) {
633                 dev_err(&pdev->dev, "failed to get mipi dphy pclk\n");
634                 return PTR_ERR(inno->pclk);
635         }
636
637         inno->rst = devm_reset_control_get_optional(&pdev->dev, "apb");
638         if (IS_ERR(inno->rst)) {
639                 dev_info(&pdev->dev, "No reset control specified\n");
640                 inno->rst = NULL;
641         }
642
643         inno->phy = devm_phy_create(&pdev->dev, NULL, &inno_mipi_dphy_ops);
644         if (IS_ERR(inno->phy)) {
645                 dev_err(&pdev->dev, "failed to create MIPI D-PHY\n");
646                 return PTR_ERR(inno->phy);
647         }
648
649         phy_set_drvdata(inno->phy, inno);
650
651         phy_provider = devm_of_phy_provider_register(&pdev->dev,
652                                                      of_phy_simple_xlate);
653         if (IS_ERR(phy_provider)) {
654                 dev_err(&pdev->dev, "failed to register phy provider\n");
655                 return PTR_ERR(phy_provider);
656         }
657
658         dev_info(&pdev->dev, "Inno MIPI-DPHY Driver Probe\n");
659
660         return 0;
661 }
662
663 static const struct of_device_id inno_mipi_dphy_of_match[] = {
664         { .compatible = "rockchip,rk3368-mipi-dphy", },
665         { /* Sentinel */ }
666 };
667 MODULE_DEVICE_TABLE(of, inno_mipi_dphy_of_match);
668
669 static struct platform_driver inno_mipi_dphy_driver = {
670         .probe  = inno_mipi_dphy_probe,
671         .driver = {
672                 .name   = DRV_NAME,
673                 .of_match_table = inno_mipi_dphy_of_match,
674         }
675 };
676
677 module_platform_driver(inno_mipi_dphy_driver);
678
679 MODULE_DESCRIPTION("Innosilicon MIPI D-PHY Driver");
680 MODULE_LICENSE("GPL v2");