111696c5eSBiju Das // SPDX-License-Identifier: GPL-2.0
211696c5eSBiju Das /*
311696c5eSBiju Das * R-Car MIPI DSI Encoder
411696c5eSBiju Das *
511696c5eSBiju Das * Copyright (C) 2020 Renesas Electronics Corporation
611696c5eSBiju Das */
711696c5eSBiju Das
811696c5eSBiju Das #include <linux/clk.h>
911696c5eSBiju Das #include <linux/delay.h>
1011696c5eSBiju Das #include <linux/io.h>
1111696c5eSBiju Das #include <linux/iopoll.h>
1211696c5eSBiju Das #include <linux/math64.h>
1311696c5eSBiju Das #include <linux/module.h>
1411696c5eSBiju Das #include <linux/of.h>
1511696c5eSBiju Das #include <linux/of_graph.h>
1611696c5eSBiju Das #include <linux/platform_device.h>
1711696c5eSBiju Das #include <linux/reset.h>
1811696c5eSBiju Das #include <linux/slab.h>
1911696c5eSBiju Das
2011696c5eSBiju Das #include <drm/drm_atomic.h>
2111696c5eSBiju Das #include <drm/drm_atomic_helper.h>
2211696c5eSBiju Das #include <drm/drm_bridge.h>
2311696c5eSBiju Das #include <drm/drm_mipi_dsi.h>
2411696c5eSBiju Das #include <drm/drm_of.h>
2511696c5eSBiju Das #include <drm/drm_panel.h>
2611696c5eSBiju Das #include <drm/drm_probe_helper.h>
2711696c5eSBiju Das
2811696c5eSBiju Das #include "rcar_mipi_dsi.h"
2911696c5eSBiju Das #include "rcar_mipi_dsi_regs.h"
3011696c5eSBiju Das
3111696c5eSBiju Das #define MHZ(v) ((u32)((v) * 1000000U))
3211696c5eSBiju Das
3311696c5eSBiju Das enum rcar_mipi_dsi_hw_model {
3411696c5eSBiju Das RCAR_DSI_V3U,
3511696c5eSBiju Das RCAR_DSI_V4H,
3611696c5eSBiju Das };
3711696c5eSBiju Das
3811696c5eSBiju Das struct rcar_mipi_dsi_device_info {
3911696c5eSBiju Das enum rcar_mipi_dsi_hw_model model;
4011696c5eSBiju Das
4111696c5eSBiju Das const struct dsi_clk_config *clk_cfg;
4211696c5eSBiju Das
4311696c5eSBiju Das u8 clockset2_m_offset;
4411696c5eSBiju Das
4511696c5eSBiju Das u8 n_min;
4611696c5eSBiju Das u8 n_max;
4711696c5eSBiju Das u8 n_mul;
4811696c5eSBiju Das unsigned long fpfd_min;
4911696c5eSBiju Das unsigned long fpfd_max;
5011696c5eSBiju Das u16 m_min;
5111696c5eSBiju Das u16 m_max;
5211696c5eSBiju Das unsigned long fout_min;
5311696c5eSBiju Das unsigned long fout_max;
5411696c5eSBiju Das };
5511696c5eSBiju Das
5611696c5eSBiju Das struct rcar_mipi_dsi {
5711696c5eSBiju Das struct device *dev;
5811696c5eSBiju Das const struct rcar_mipi_dsi_device_info *info;
5911696c5eSBiju Das struct reset_control *rstc;
6011696c5eSBiju Das
6111696c5eSBiju Das struct mipi_dsi_host host;
6211696c5eSBiju Das struct drm_bridge bridge;
6311696c5eSBiju Das struct drm_bridge *next_bridge;
6411696c5eSBiju Das struct drm_connector connector;
6511696c5eSBiju Das
6611696c5eSBiju Das void __iomem *mmio;
6711696c5eSBiju Das struct {
6811696c5eSBiju Das struct clk *mod;
6911696c5eSBiju Das struct clk *pll;
7011696c5eSBiju Das struct clk *dsi;
7111696c5eSBiju Das } clocks;
7211696c5eSBiju Das
7311696c5eSBiju Das enum mipi_dsi_pixel_format format;
7411696c5eSBiju Das unsigned int num_data_lanes;
7511696c5eSBiju Das unsigned int lanes;
7611696c5eSBiju Das };
7711696c5eSBiju Das
7811696c5eSBiju Das struct dsi_setup_info {
7911696c5eSBiju Das unsigned long hsfreq;
8011696c5eSBiju Das u16 hsfreqrange;
8111696c5eSBiju Das
8211696c5eSBiju Das unsigned long fout;
8311696c5eSBiju Das u16 m;
8411696c5eSBiju Das u16 n;
8511696c5eSBiju Das u16 vclk_divider;
8611696c5eSBiju Das const struct dsi_clk_config *clkset;
8711696c5eSBiju Das };
8811696c5eSBiju Das
8911696c5eSBiju Das static inline struct rcar_mipi_dsi *
bridge_to_rcar_mipi_dsi(struct drm_bridge * bridge)9011696c5eSBiju Das bridge_to_rcar_mipi_dsi(struct drm_bridge *bridge)
9111696c5eSBiju Das {
9211696c5eSBiju Das return container_of(bridge, struct rcar_mipi_dsi, bridge);
9311696c5eSBiju Das }
9411696c5eSBiju Das
9511696c5eSBiju Das static inline struct rcar_mipi_dsi *
host_to_rcar_mipi_dsi(struct mipi_dsi_host * host)9611696c5eSBiju Das host_to_rcar_mipi_dsi(struct mipi_dsi_host *host)
9711696c5eSBiju Das {
9811696c5eSBiju Das return container_of(host, struct rcar_mipi_dsi, host);
9911696c5eSBiju Das }
10011696c5eSBiju Das
10111696c5eSBiju Das static const u32 hsfreqrange_table[][2] = {
10211696c5eSBiju Das { MHZ(80), 0x00 }, { MHZ(90), 0x10 }, { MHZ(100), 0x20 },
10311696c5eSBiju Das { MHZ(110), 0x30 }, { MHZ(120), 0x01 }, { MHZ(130), 0x11 },
10411696c5eSBiju Das { MHZ(140), 0x21 }, { MHZ(150), 0x31 }, { MHZ(160), 0x02 },
10511696c5eSBiju Das { MHZ(170), 0x12 }, { MHZ(180), 0x22 }, { MHZ(190), 0x32 },
10611696c5eSBiju Das { MHZ(205), 0x03 }, { MHZ(220), 0x13 }, { MHZ(235), 0x23 },
10711696c5eSBiju Das { MHZ(250), 0x33 }, { MHZ(275), 0x04 }, { MHZ(300), 0x14 },
10811696c5eSBiju Das { MHZ(325), 0x25 }, { MHZ(350), 0x35 }, { MHZ(400), 0x05 },
10911696c5eSBiju Das { MHZ(450), 0x16 }, { MHZ(500), 0x26 }, { MHZ(550), 0x37 },
11011696c5eSBiju Das { MHZ(600), 0x07 }, { MHZ(650), 0x18 }, { MHZ(700), 0x28 },
11111696c5eSBiju Das { MHZ(750), 0x39 }, { MHZ(800), 0x09 }, { MHZ(850), 0x19 },
11211696c5eSBiju Das { MHZ(900), 0x29 }, { MHZ(950), 0x3a }, { MHZ(1000), 0x0a },
11311696c5eSBiju Das { MHZ(1050), 0x1a }, { MHZ(1100), 0x2a }, { MHZ(1150), 0x3b },
11411696c5eSBiju Das { MHZ(1200), 0x0b }, { MHZ(1250), 0x1b }, { MHZ(1300), 0x2b },
11511696c5eSBiju Das { MHZ(1350), 0x3c }, { MHZ(1400), 0x0c }, { MHZ(1450), 0x1c },
11611696c5eSBiju Das { MHZ(1500), 0x2c }, { MHZ(1550), 0x3d }, { MHZ(1600), 0x0d },
11711696c5eSBiju Das { MHZ(1650), 0x1d }, { MHZ(1700), 0x2e }, { MHZ(1750), 0x3e },
11811696c5eSBiju Das { MHZ(1800), 0x0e }, { MHZ(1850), 0x1e }, { MHZ(1900), 0x2f },
11911696c5eSBiju Das { MHZ(1950), 0x3f }, { MHZ(2000), 0x0f }, { MHZ(2050), 0x40 },
12011696c5eSBiju Das { MHZ(2100), 0x41 }, { MHZ(2150), 0x42 }, { MHZ(2200), 0x43 },
12111696c5eSBiju Das { MHZ(2250), 0x44 }, { MHZ(2300), 0x45 }, { MHZ(2350), 0x46 },
12211696c5eSBiju Das { MHZ(2400), 0x47 }, { MHZ(2450), 0x48 }, { MHZ(2500), 0x49 },
12311696c5eSBiju Das { /* sentinel */ },
12411696c5eSBiju Das };
12511696c5eSBiju Das
12611696c5eSBiju Das struct dsi_clk_config {
12711696c5eSBiju Das u32 min_freq;
12811696c5eSBiju Das u32 max_freq;
12911696c5eSBiju Das u8 vco_cntrl;
13011696c5eSBiju Das u8 cpbias_cntrl;
13111696c5eSBiju Das u8 gmp_cntrl;
13211696c5eSBiju Das u8 int_cntrl;
13311696c5eSBiju Das u8 prop_cntrl;
13411696c5eSBiju Das };
13511696c5eSBiju Das
13611696c5eSBiju Das static const struct dsi_clk_config dsi_clk_cfg_v3u[] = {
13711696c5eSBiju Das { MHZ(40), MHZ(55), 0x3f, 0x10, 0x01, 0x00, 0x0b },
13811696c5eSBiju Das { MHZ(52.5), MHZ(80), 0x39, 0x10, 0x01, 0x00, 0x0b },
13911696c5eSBiju Das { MHZ(80), MHZ(110), 0x2f, 0x10, 0x01, 0x00, 0x0b },
14011696c5eSBiju Das { MHZ(105), MHZ(160), 0x29, 0x10, 0x01, 0x00, 0x0b },
14111696c5eSBiju Das { MHZ(160), MHZ(220), 0x1f, 0x10, 0x01, 0x00, 0x0b },
14211696c5eSBiju Das { MHZ(210), MHZ(320), 0x19, 0x10, 0x01, 0x00, 0x0b },
14311696c5eSBiju Das { MHZ(320), MHZ(440), 0x0f, 0x10, 0x01, 0x00, 0x0b },
14411696c5eSBiju Das { MHZ(420), MHZ(660), 0x09, 0x10, 0x01, 0x00, 0x0b },
14511696c5eSBiju Das { MHZ(630), MHZ(1149), 0x03, 0x10, 0x01, 0x00, 0x0b },
14611696c5eSBiju Das { MHZ(1100), MHZ(1152), 0x01, 0x10, 0x01, 0x00, 0x0b },
14711696c5eSBiju Das { MHZ(1150), MHZ(1250), 0x01, 0x10, 0x01, 0x00, 0x0c },
14811696c5eSBiju Das { /* sentinel */ },
14911696c5eSBiju Das };
15011696c5eSBiju Das
15111696c5eSBiju Das static const struct dsi_clk_config dsi_clk_cfg_v4h[] = {
15211696c5eSBiju Das { MHZ(40), MHZ(45.31), 0x2b, 0x00, 0x00, 0x08, 0x0a },
15311696c5eSBiju Das { MHZ(45.31), MHZ(54.66), 0x28, 0x00, 0x00, 0x08, 0x0a },
15411696c5eSBiju Das { MHZ(54.66), MHZ(62.5), 0x28, 0x00, 0x00, 0x08, 0x0a },
15511696c5eSBiju Das { MHZ(62.5), MHZ(75), 0x27, 0x00, 0x00, 0x08, 0x0a },
15611696c5eSBiju Das { MHZ(75), MHZ(90.63), 0x23, 0x00, 0x00, 0x08, 0x0a },
15711696c5eSBiju Das { MHZ(90.63), MHZ(109.37), 0x20, 0x00, 0x00, 0x08, 0x0a },
15811696c5eSBiju Das { MHZ(109.37), MHZ(125), 0x20, 0x00, 0x00, 0x08, 0x0a },
15911696c5eSBiju Das { MHZ(125), MHZ(150), 0x1f, 0x00, 0x00, 0x08, 0x0a },
16011696c5eSBiju Das { MHZ(150), MHZ(181.25), 0x1b, 0x00, 0x00, 0x08, 0x0a },
16111696c5eSBiju Das { MHZ(181.25), MHZ(218.75), 0x18, 0x00, 0x00, 0x08, 0x0a },
16211696c5eSBiju Das { MHZ(218.75), MHZ(250), 0x18, 0x00, 0x00, 0x08, 0x0a },
16311696c5eSBiju Das { MHZ(250), MHZ(300), 0x17, 0x00, 0x00, 0x08, 0x0a },
16411696c5eSBiju Das { MHZ(300), MHZ(362.5), 0x13, 0x00, 0x00, 0x08, 0x0a },
16511696c5eSBiju Das { MHZ(362.5), MHZ(455.48), 0x10, 0x00, 0x00, 0x08, 0x0a },
16611696c5eSBiju Das { MHZ(455.48), MHZ(500), 0x10, 0x00, 0x00, 0x08, 0x0a },
16711696c5eSBiju Das { MHZ(500), MHZ(600), 0x0f, 0x00, 0x00, 0x08, 0x0a },
16811696c5eSBiju Das { MHZ(600), MHZ(725), 0x0b, 0x00, 0x00, 0x08, 0x0a },
16911696c5eSBiju Das { MHZ(725), MHZ(875), 0x08, 0x00, 0x00, 0x08, 0x0a },
17011696c5eSBiju Das { MHZ(875), MHZ(1000), 0x08, 0x00, 0x00, 0x08, 0x0a },
17111696c5eSBiju Das { MHZ(1000), MHZ(1200), 0x07, 0x00, 0x00, 0x08, 0x0a },
17211696c5eSBiju Das { MHZ(1200), MHZ(1250), 0x03, 0x00, 0x00, 0x08, 0x0a },
17311696c5eSBiju Das { /* sentinel */ },
17411696c5eSBiju Das };
17511696c5eSBiju Das
rcar_mipi_dsi_write(struct rcar_mipi_dsi * dsi,u32 reg,u32 data)17611696c5eSBiju Das static void rcar_mipi_dsi_write(struct rcar_mipi_dsi *dsi, u32 reg, u32 data)
17711696c5eSBiju Das {
17811696c5eSBiju Das iowrite32(data, dsi->mmio + reg);
17911696c5eSBiju Das }
18011696c5eSBiju Das
rcar_mipi_dsi_read(struct rcar_mipi_dsi * dsi,u32 reg)18111696c5eSBiju Das static u32 rcar_mipi_dsi_read(struct rcar_mipi_dsi *dsi, u32 reg)
18211696c5eSBiju Das {
18311696c5eSBiju Das return ioread32(dsi->mmio + reg);
18411696c5eSBiju Das }
18511696c5eSBiju Das
rcar_mipi_dsi_clr(struct rcar_mipi_dsi * dsi,u32 reg,u32 clr)18611696c5eSBiju Das static void rcar_mipi_dsi_clr(struct rcar_mipi_dsi *dsi, u32 reg, u32 clr)
18711696c5eSBiju Das {
18811696c5eSBiju Das rcar_mipi_dsi_write(dsi, reg, rcar_mipi_dsi_read(dsi, reg) & ~clr);
18911696c5eSBiju Das }
19011696c5eSBiju Das
rcar_mipi_dsi_set(struct rcar_mipi_dsi * dsi,u32 reg,u32 set)19111696c5eSBiju Das static void rcar_mipi_dsi_set(struct rcar_mipi_dsi *dsi, u32 reg, u32 set)
19211696c5eSBiju Das {
19311696c5eSBiju Das rcar_mipi_dsi_write(dsi, reg, rcar_mipi_dsi_read(dsi, reg) | set);
19411696c5eSBiju Das }
19511696c5eSBiju Das
rcar_mipi_dsi_write_phtw(struct rcar_mipi_dsi * dsi,u32 phtw)19611696c5eSBiju Das static int rcar_mipi_dsi_write_phtw(struct rcar_mipi_dsi *dsi, u32 phtw)
19711696c5eSBiju Das {
19811696c5eSBiju Das u32 status;
19911696c5eSBiju Das int ret;
20011696c5eSBiju Das
20111696c5eSBiju Das rcar_mipi_dsi_write(dsi, PHTW, phtw);
20211696c5eSBiju Das
20311696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
20411696c5eSBiju Das !(status & (PHTW_DWEN | PHTW_CWEN)),
20511696c5eSBiju Das 2000, 10000, false, dsi, PHTW);
20611696c5eSBiju Das if (ret < 0) {
20711696c5eSBiju Das dev_err(dsi->dev, "PHY test interface write timeout (0x%08x)\n",
20811696c5eSBiju Das phtw);
20911696c5eSBiju Das return ret;
21011696c5eSBiju Das }
21111696c5eSBiju Das
21211696c5eSBiju Das return ret;
21311696c5eSBiju Das }
21411696c5eSBiju Das
rcar_mipi_dsi_write_phtw_arr(struct rcar_mipi_dsi * dsi,const u32 * phtw,unsigned int size)21511696c5eSBiju Das static int rcar_mipi_dsi_write_phtw_arr(struct rcar_mipi_dsi *dsi,
21611696c5eSBiju Das const u32 *phtw, unsigned int size)
21711696c5eSBiju Das {
21811696c5eSBiju Das for (unsigned int i = 0; i < size; i++) {
21911696c5eSBiju Das int ret = rcar_mipi_dsi_write_phtw(dsi, phtw[i]);
22011696c5eSBiju Das
22111696c5eSBiju Das if (ret < 0)
22211696c5eSBiju Das return ret;
22311696c5eSBiju Das }
22411696c5eSBiju Das
22511696c5eSBiju Das return 0;
22611696c5eSBiju Das }
22711696c5eSBiju Das
22811696c5eSBiju Das #define WRITE_PHTW(...) \
22911696c5eSBiju Das ({ \
23011696c5eSBiju Das static const u32 phtw[] = { __VA_ARGS__ }; \
23111696c5eSBiju Das int ret; \
23211696c5eSBiju Das ret = rcar_mipi_dsi_write_phtw_arr(dsi, phtw, \
23311696c5eSBiju Das ARRAY_SIZE(phtw)); \
23411696c5eSBiju Das ret; \
23511696c5eSBiju Das })
23611696c5eSBiju Das
rcar_mipi_dsi_init_phtw_v3u(struct rcar_mipi_dsi * dsi)23711696c5eSBiju Das static int rcar_mipi_dsi_init_phtw_v3u(struct rcar_mipi_dsi *dsi)
23811696c5eSBiju Das {
23911696c5eSBiju Das return WRITE_PHTW(0x01020114, 0x01600115, 0x01030116, 0x0102011d,
24011696c5eSBiju Das 0x011101a4, 0x018601a4, 0x014201a0, 0x010001a3,
24111696c5eSBiju Das 0x0101011f);
24211696c5eSBiju Das }
24311696c5eSBiju Das
rcar_mipi_dsi_post_init_phtw_v3u(struct rcar_mipi_dsi * dsi)24411696c5eSBiju Das static int rcar_mipi_dsi_post_init_phtw_v3u(struct rcar_mipi_dsi *dsi)
24511696c5eSBiju Das {
24611696c5eSBiju Das return WRITE_PHTW(0x010c0130, 0x010c0140, 0x010c0150, 0x010c0180,
24711696c5eSBiju Das 0x010c0190, 0x010a0160, 0x010a0170, 0x01800164,
24811696c5eSBiju Das 0x01800174);
24911696c5eSBiju Das }
25011696c5eSBiju Das
rcar_mipi_dsi_init_phtw_v4h(struct rcar_mipi_dsi * dsi,const struct dsi_setup_info * setup_info)25111696c5eSBiju Das static int rcar_mipi_dsi_init_phtw_v4h(struct rcar_mipi_dsi *dsi,
25211696c5eSBiju Das const struct dsi_setup_info *setup_info)
25311696c5eSBiju Das {
25411696c5eSBiju Das int ret;
25511696c5eSBiju Das
25611696c5eSBiju Das if (setup_info->hsfreq < MHZ(450)) {
25711696c5eSBiju Das ret = WRITE_PHTW(0x01010100, 0x011b01ac);
25811696c5eSBiju Das if (ret)
25911696c5eSBiju Das return ret;
26011696c5eSBiju Das }
26111696c5eSBiju Das
26211696c5eSBiju Das ret = WRITE_PHTW(0x01010100, 0x01030173, 0x01000174, 0x01500175,
26311696c5eSBiju Das 0x01030176, 0x01040166, 0x010201ad);
26411696c5eSBiju Das if (ret)
26511696c5eSBiju Das return ret;
26611696c5eSBiju Das
26711696c5eSBiju Das if (setup_info->hsfreq <= MHZ(1000))
26811696c5eSBiju Das ret = WRITE_PHTW(0x01020100, 0x01910170, 0x01020171,
26911696c5eSBiju Das 0x01110172);
27011696c5eSBiju Das else if (setup_info->hsfreq <= MHZ(1500))
27111696c5eSBiju Das ret = WRITE_PHTW(0x01020100, 0x01980170, 0x01030171,
27211696c5eSBiju Das 0x01100172);
27311696c5eSBiju Das else if (setup_info->hsfreq <= MHZ(2500))
27411696c5eSBiju Das ret = WRITE_PHTW(0x01020100, 0x0144016b, 0x01000172);
27511696c5eSBiju Das else
27611696c5eSBiju Das return -EINVAL;
27711696c5eSBiju Das
27811696c5eSBiju Das if (ret)
27911696c5eSBiju Das return ret;
28011696c5eSBiju Das
28111696c5eSBiju Das if (dsi->lanes <= 1) {
28211696c5eSBiju Das ret = WRITE_PHTW(0x01070100, 0x010e010b);
28311696c5eSBiju Das if (ret)
28411696c5eSBiju Das return ret;
28511696c5eSBiju Das }
28611696c5eSBiju Das
28711696c5eSBiju Das if (dsi->lanes <= 2) {
28811696c5eSBiju Das ret = WRITE_PHTW(0x01090100, 0x010e010b);
28911696c5eSBiju Das if (ret)
29011696c5eSBiju Das return ret;
29111696c5eSBiju Das }
29211696c5eSBiju Das
29311696c5eSBiju Das if (dsi->lanes <= 3) {
29411696c5eSBiju Das ret = WRITE_PHTW(0x010b0100, 0x010e010b);
29511696c5eSBiju Das if (ret)
29611696c5eSBiju Das return ret;
29711696c5eSBiju Das }
29811696c5eSBiju Das
29911696c5eSBiju Das if (setup_info->hsfreq <= MHZ(1500)) {
30011696c5eSBiju Das ret = WRITE_PHTW(0x01010100, 0x01c0016e);
30111696c5eSBiju Das if (ret)
30211696c5eSBiju Das return ret;
30311696c5eSBiju Das }
30411696c5eSBiju Das
30511696c5eSBiju Das return 0;
30611696c5eSBiju Das }
30711696c5eSBiju Das
30811696c5eSBiju Das static int
rcar_mipi_dsi_post_init_phtw_v4h(struct rcar_mipi_dsi * dsi,const struct dsi_setup_info * setup_info)30911696c5eSBiju Das rcar_mipi_dsi_post_init_phtw_v4h(struct rcar_mipi_dsi *dsi,
31011696c5eSBiju Das const struct dsi_setup_info *setup_info)
31111696c5eSBiju Das {
31211696c5eSBiju Das u32 status;
31311696c5eSBiju Das int ret;
31411696c5eSBiju Das
31511696c5eSBiju Das if (setup_info->hsfreq <= MHZ(1500)) {
31611696c5eSBiju Das WRITE_PHTW(0x01020100, 0x00000180);
31711696c5eSBiju Das
31811696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
31911696c5eSBiju Das status & PHTR_TEST, 2000, 10000, false,
32011696c5eSBiju Das dsi, PHTR);
32111696c5eSBiju Das if (ret < 0) {
32211696c5eSBiju Das dev_err(dsi->dev, "failed to test PHTR\n");
32311696c5eSBiju Das return ret;
32411696c5eSBiju Das }
32511696c5eSBiju Das
32611696c5eSBiju Das WRITE_PHTW(0x01010100, 0x0100016e);
32711696c5eSBiju Das }
32811696c5eSBiju Das
32911696c5eSBiju Das return 0;
33011696c5eSBiju Das }
33111696c5eSBiju Das
33211696c5eSBiju Das /* -----------------------------------------------------------------------------
33311696c5eSBiju Das * Hardware Setup
33411696c5eSBiju Das */
33511696c5eSBiju Das
rcar_mipi_dsi_pll_calc(struct rcar_mipi_dsi * dsi,unsigned long fin_rate,unsigned long fout_target,struct dsi_setup_info * setup_info)33611696c5eSBiju Das static void rcar_mipi_dsi_pll_calc(struct rcar_mipi_dsi *dsi,
33711696c5eSBiju Das unsigned long fin_rate,
33811696c5eSBiju Das unsigned long fout_target,
33911696c5eSBiju Das struct dsi_setup_info *setup_info)
34011696c5eSBiju Das {
34111696c5eSBiju Das unsigned int best_err = -1;
34211696c5eSBiju Das const struct rcar_mipi_dsi_device_info *info = dsi->info;
34311696c5eSBiju Das
34411696c5eSBiju Das for (unsigned int n = info->n_min; n <= info->n_max; n++) {
34511696c5eSBiju Das unsigned long fpfd;
34611696c5eSBiju Das
34711696c5eSBiju Das fpfd = fin_rate / n;
34811696c5eSBiju Das
34911696c5eSBiju Das if (fpfd < info->fpfd_min || fpfd > info->fpfd_max)
35011696c5eSBiju Das continue;
35111696c5eSBiju Das
35211696c5eSBiju Das for (unsigned int m = info->m_min; m <= info->m_max; m++) {
35311696c5eSBiju Das unsigned int err;
35411696c5eSBiju Das u64 fout;
35511696c5eSBiju Das
35611696c5eSBiju Das fout = div64_u64((u64)fpfd * m, dsi->info->n_mul);
35711696c5eSBiju Das
35811696c5eSBiju Das if (fout < info->fout_min || fout > info->fout_max)
35911696c5eSBiju Das continue;
36011696c5eSBiju Das
36111696c5eSBiju Das fout = div64_u64(fout, setup_info->vclk_divider);
36211696c5eSBiju Das
36311696c5eSBiju Das if (fout < setup_info->clkset->min_freq ||
36411696c5eSBiju Das fout > setup_info->clkset->max_freq)
36511696c5eSBiju Das continue;
36611696c5eSBiju Das
36711696c5eSBiju Das err = abs((long)(fout - fout_target) * 10000 /
36811696c5eSBiju Das (long)fout_target);
36911696c5eSBiju Das if (err < best_err) {
37011696c5eSBiju Das setup_info->m = m;
37111696c5eSBiju Das setup_info->n = n;
37211696c5eSBiju Das setup_info->fout = (unsigned long)fout;
37311696c5eSBiju Das best_err = err;
37411696c5eSBiju Das
37511696c5eSBiju Das if (err == 0)
37611696c5eSBiju Das return;
37711696c5eSBiju Das }
37811696c5eSBiju Das }
37911696c5eSBiju Das }
38011696c5eSBiju Das }
38111696c5eSBiju Das
rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi * dsi,struct clk * clk,unsigned long target,struct dsi_setup_info * setup_info)38211696c5eSBiju Das static void rcar_mipi_dsi_parameters_calc(struct rcar_mipi_dsi *dsi,
38311696c5eSBiju Das struct clk *clk, unsigned long target,
38411696c5eSBiju Das struct dsi_setup_info *setup_info)
38511696c5eSBiju Das {
38611696c5eSBiju Das
38711696c5eSBiju Das const struct dsi_clk_config *clk_cfg;
38811696c5eSBiju Das unsigned long fout_target;
38911696c5eSBiju Das unsigned long fin_rate;
39011696c5eSBiju Das unsigned int i;
39111696c5eSBiju Das unsigned int err;
39211696c5eSBiju Das
39311696c5eSBiju Das /*
39411696c5eSBiju Das * Calculate Fout = dot clock * ColorDepth / (2 * Lane Count)
39511696c5eSBiju Das * The range out Fout is [40 - 1250] Mhz
39611696c5eSBiju Das */
39711696c5eSBiju Das fout_target = target * mipi_dsi_pixel_format_to_bpp(dsi->format)
39811696c5eSBiju Das / (2 * dsi->lanes);
39911696c5eSBiju Das if (fout_target < MHZ(40) || fout_target > MHZ(1250))
40011696c5eSBiju Das return;
40111696c5eSBiju Das
40211696c5eSBiju Das /* Find PLL settings */
40311696c5eSBiju Das for (clk_cfg = dsi->info->clk_cfg; clk_cfg->min_freq != 0; clk_cfg++) {
40411696c5eSBiju Das if (fout_target > clk_cfg->min_freq &&
40511696c5eSBiju Das fout_target <= clk_cfg->max_freq) {
40611696c5eSBiju Das setup_info->clkset = clk_cfg;
40711696c5eSBiju Das break;
40811696c5eSBiju Das }
40911696c5eSBiju Das }
41011696c5eSBiju Das
41111696c5eSBiju Das fin_rate = clk_get_rate(clk);
41211696c5eSBiju Das
41311696c5eSBiju Das switch (dsi->info->model) {
41411696c5eSBiju Das case RCAR_DSI_V3U:
41511696c5eSBiju Das default:
41611696c5eSBiju Das setup_info->vclk_divider = 1 << ((clk_cfg->vco_cntrl >> 4) & 0x3);
41711696c5eSBiju Das break;
41811696c5eSBiju Das
41911696c5eSBiju Das case RCAR_DSI_V4H:
42011696c5eSBiju Das setup_info->vclk_divider = 1 << (((clk_cfg->vco_cntrl >> 3) & 0x7) + 1);
42111696c5eSBiju Das break;
42211696c5eSBiju Das }
42311696c5eSBiju Das
42411696c5eSBiju Das rcar_mipi_dsi_pll_calc(dsi, fin_rate, fout_target, setup_info);
42511696c5eSBiju Das
42611696c5eSBiju Das /* Find hsfreqrange */
42711696c5eSBiju Das setup_info->hsfreq = setup_info->fout * 2;
42811696c5eSBiju Das for (i = 0; i < ARRAY_SIZE(hsfreqrange_table); i++) {
42911696c5eSBiju Das if (hsfreqrange_table[i][0] >= setup_info->hsfreq) {
43011696c5eSBiju Das setup_info->hsfreqrange = hsfreqrange_table[i][1];
43111696c5eSBiju Das break;
43211696c5eSBiju Das }
43311696c5eSBiju Das }
43411696c5eSBiju Das
43511696c5eSBiju Das err = abs((long)(setup_info->fout - fout_target) * 10000 / (long)fout_target);
43611696c5eSBiju Das
43711696c5eSBiju Das dev_dbg(dsi->dev,
43811696c5eSBiju Das "Fout = %u * %lu / (%u * %u * %u) = %lu (target %lu Hz, error %d.%02u%%)\n",
43911696c5eSBiju Das setup_info->m, fin_rate, dsi->info->n_mul, setup_info->n,
44011696c5eSBiju Das setup_info->vclk_divider, setup_info->fout, fout_target,
44111696c5eSBiju Das err / 100, err % 100);
44211696c5eSBiju Das
44311696c5eSBiju Das dev_dbg(dsi->dev,
44411696c5eSBiju Das "vco_cntrl = 0x%x\tprop_cntrl = 0x%x\thsfreqrange = 0x%x\n",
44511696c5eSBiju Das clk_cfg->vco_cntrl, clk_cfg->prop_cntrl,
44611696c5eSBiju Das setup_info->hsfreqrange);
44711696c5eSBiju Das }
44811696c5eSBiju Das
rcar_mipi_dsi_set_display_timing(struct rcar_mipi_dsi * dsi,const struct drm_display_mode * mode)44911696c5eSBiju Das static void rcar_mipi_dsi_set_display_timing(struct rcar_mipi_dsi *dsi,
45011696c5eSBiju Das const struct drm_display_mode *mode)
45111696c5eSBiju Das {
45211696c5eSBiju Das u32 setr;
45311696c5eSBiju Das u32 vprmset0r;
45411696c5eSBiju Das u32 vprmset1r;
45511696c5eSBiju Das u32 vprmset2r;
45611696c5eSBiju Das u32 vprmset3r;
45711696c5eSBiju Das u32 vprmset4r;
45811696c5eSBiju Das
45911696c5eSBiju Das /* Configuration for Pixel Stream and Packet Header */
46011696c5eSBiju Das if (mipi_dsi_pixel_format_to_bpp(dsi->format) == 24)
46111696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMPSPHSETR, TXVMPSPHSETR_DT_RGB24);
46211696c5eSBiju Das else if (mipi_dsi_pixel_format_to_bpp(dsi->format) == 18)
46311696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMPSPHSETR, TXVMPSPHSETR_DT_RGB18);
46411696c5eSBiju Das else if (mipi_dsi_pixel_format_to_bpp(dsi->format) == 16)
46511696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMPSPHSETR, TXVMPSPHSETR_DT_RGB16);
46611696c5eSBiju Das else {
46711696c5eSBiju Das dev_warn(dsi->dev, "unsupported format");
46811696c5eSBiju Das return;
46911696c5eSBiju Das }
47011696c5eSBiju Das
47111696c5eSBiju Das /* Configuration for Blanking sequence and Input Pixel */
47211696c5eSBiju Das setr = TXVMSETR_HSABPEN_EN | TXVMSETR_HBPBPEN_EN
47311696c5eSBiju Das | TXVMSETR_HFPBPEN_EN | TXVMSETR_SYNSEQ_PULSES
47411696c5eSBiju Das | TXVMSETR_PIXWDTH | TXVMSETR_VSTPM;
47511696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMSETR, setr);
47611696c5eSBiju Das
47711696c5eSBiju Das /* Configuration for Video Parameters */
47811696c5eSBiju Das vprmset0r = (mode->flags & DRM_MODE_FLAG_PVSYNC ?
47911696c5eSBiju Das TXVMVPRMSET0R_VSPOL_HIG : TXVMVPRMSET0R_VSPOL_LOW)
48011696c5eSBiju Das | (mode->flags & DRM_MODE_FLAG_PHSYNC ?
48111696c5eSBiju Das TXVMVPRMSET0R_HSPOL_HIG : TXVMVPRMSET0R_HSPOL_LOW)
48211696c5eSBiju Das | TXVMVPRMSET0R_CSPC_RGB | TXVMVPRMSET0R_BPP_24;
48311696c5eSBiju Das
48411696c5eSBiju Das vprmset1r = TXVMVPRMSET1R_VACTIVE(mode->vdisplay)
48511696c5eSBiju Das | TXVMVPRMSET1R_VSA(mode->vsync_end - mode->vsync_start);
48611696c5eSBiju Das
48711696c5eSBiju Das vprmset2r = TXVMVPRMSET2R_VFP(mode->vsync_start - mode->vdisplay)
48811696c5eSBiju Das | TXVMVPRMSET2R_VBP(mode->vtotal - mode->vsync_end);
48911696c5eSBiju Das
49011696c5eSBiju Das vprmset3r = TXVMVPRMSET3R_HACTIVE(mode->hdisplay)
49111696c5eSBiju Das | TXVMVPRMSET3R_HSA(mode->hsync_end - mode->hsync_start);
49211696c5eSBiju Das
49311696c5eSBiju Das vprmset4r = TXVMVPRMSET4R_HFP(mode->hsync_start - mode->hdisplay)
49411696c5eSBiju Das | TXVMVPRMSET4R_HBP(mode->htotal - mode->hsync_end);
49511696c5eSBiju Das
49611696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMVPRMSET0R, vprmset0r);
49711696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMVPRMSET1R, vprmset1r);
49811696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMVPRMSET2R, vprmset2r);
49911696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMVPRMSET3R, vprmset3r);
50011696c5eSBiju Das rcar_mipi_dsi_write(dsi, TXVMVPRMSET4R, vprmset4r);
50111696c5eSBiju Das }
50211696c5eSBiju Das
rcar_mipi_dsi_startup(struct rcar_mipi_dsi * dsi,const struct drm_display_mode * mode)50311696c5eSBiju Das static int rcar_mipi_dsi_startup(struct rcar_mipi_dsi *dsi,
50411696c5eSBiju Das const struct drm_display_mode *mode)
50511696c5eSBiju Das {
50611696c5eSBiju Das struct dsi_setup_info setup_info = {};
50711696c5eSBiju Das unsigned int timeout;
50811696c5eSBiju Das int ret;
50911696c5eSBiju Das int dsi_format;
51011696c5eSBiju Das u32 phy_setup;
51111696c5eSBiju Das u32 clockset2, clockset3;
51211696c5eSBiju Das u32 ppisetr;
51311696c5eSBiju Das u32 vclkset;
51411696c5eSBiju Das
51511696c5eSBiju Das /* Checking valid format */
51611696c5eSBiju Das dsi_format = mipi_dsi_pixel_format_to_bpp(dsi->format);
51711696c5eSBiju Das if (dsi_format < 0) {
51811696c5eSBiju Das dev_warn(dsi->dev, "invalid format");
51911696c5eSBiju Das return -EINVAL;
52011696c5eSBiju Das }
52111696c5eSBiju Das
52211696c5eSBiju Das /* Parameters Calculation */
52311696c5eSBiju Das rcar_mipi_dsi_parameters_calc(dsi, dsi->clocks.pll,
52411696c5eSBiju Das mode->clock * 1000, &setup_info);
52511696c5eSBiju Das
52611696c5eSBiju Das /* LPCLK enable */
52711696c5eSBiju Das rcar_mipi_dsi_set(dsi, LPCLKSET, LPCLKSET_CKEN);
52811696c5eSBiju Das
52911696c5eSBiju Das /* CFGCLK enabled */
53011696c5eSBiju Das rcar_mipi_dsi_set(dsi, CFGCLKSET, CFGCLKSET_CKEN);
53111696c5eSBiju Das
53211696c5eSBiju Das rcar_mipi_dsi_clr(dsi, PHYSETUP, PHYSETUP_RSTZ);
53311696c5eSBiju Das rcar_mipi_dsi_clr(dsi, PHYSETUP, PHYSETUP_SHUTDOWNZ);
53411696c5eSBiju Das
53511696c5eSBiju Das rcar_mipi_dsi_set(dsi, PHTC, PHTC_TESTCLR);
53611696c5eSBiju Das rcar_mipi_dsi_clr(dsi, PHTC, PHTC_TESTCLR);
53711696c5eSBiju Das
53811696c5eSBiju Das /* PHY setting */
53911696c5eSBiju Das phy_setup = rcar_mipi_dsi_read(dsi, PHYSETUP);
54011696c5eSBiju Das phy_setup &= ~PHYSETUP_HSFREQRANGE_MASK;
54111696c5eSBiju Das phy_setup |= PHYSETUP_HSFREQRANGE(setup_info.hsfreqrange);
54211696c5eSBiju Das rcar_mipi_dsi_write(dsi, PHYSETUP, phy_setup);
54311696c5eSBiju Das
54411696c5eSBiju Das switch (dsi->info->model) {
54511696c5eSBiju Das case RCAR_DSI_V3U:
54611696c5eSBiju Das default:
54711696c5eSBiju Das ret = rcar_mipi_dsi_init_phtw_v3u(dsi);
54811696c5eSBiju Das if (ret < 0)
54911696c5eSBiju Das return ret;
55011696c5eSBiju Das break;
55111696c5eSBiju Das
55211696c5eSBiju Das case RCAR_DSI_V4H:
55311696c5eSBiju Das ret = rcar_mipi_dsi_init_phtw_v4h(dsi, &setup_info);
55411696c5eSBiju Das if (ret < 0)
55511696c5eSBiju Das return ret;
55611696c5eSBiju Das break;
55711696c5eSBiju Das }
55811696c5eSBiju Das
55911696c5eSBiju Das /* PLL Clock Setting */
56011696c5eSBiju Das rcar_mipi_dsi_clr(dsi, CLOCKSET1, CLOCKSET1_SHADOW_CLEAR);
56111696c5eSBiju Das rcar_mipi_dsi_set(dsi, CLOCKSET1, CLOCKSET1_SHADOW_CLEAR);
56211696c5eSBiju Das rcar_mipi_dsi_clr(dsi, CLOCKSET1, CLOCKSET1_SHADOW_CLEAR);
56311696c5eSBiju Das
56411696c5eSBiju Das clockset2 = CLOCKSET2_M(setup_info.m - dsi->info->clockset2_m_offset)
56511696c5eSBiju Das | CLOCKSET2_N(setup_info.n - 1)
56611696c5eSBiju Das | CLOCKSET2_VCO_CNTRL(setup_info.clkset->vco_cntrl);
56711696c5eSBiju Das clockset3 = CLOCKSET3_PROP_CNTRL(setup_info.clkset->prop_cntrl)
56811696c5eSBiju Das | CLOCKSET3_INT_CNTRL(setup_info.clkset->int_cntrl)
56911696c5eSBiju Das | CLOCKSET3_CPBIAS_CNTRL(setup_info.clkset->cpbias_cntrl)
57011696c5eSBiju Das | CLOCKSET3_GMP_CNTRL(setup_info.clkset->gmp_cntrl);
57111696c5eSBiju Das rcar_mipi_dsi_write(dsi, CLOCKSET2, clockset2);
57211696c5eSBiju Das rcar_mipi_dsi_write(dsi, CLOCKSET3, clockset3);
57311696c5eSBiju Das
57411696c5eSBiju Das rcar_mipi_dsi_clr(dsi, CLOCKSET1, CLOCKSET1_UPDATEPLL);
57511696c5eSBiju Das rcar_mipi_dsi_set(dsi, CLOCKSET1, CLOCKSET1_UPDATEPLL);
57611696c5eSBiju Das udelay(10);
57711696c5eSBiju Das rcar_mipi_dsi_clr(dsi, CLOCKSET1, CLOCKSET1_UPDATEPLL);
57811696c5eSBiju Das
57911696c5eSBiju Das ppisetr = PPISETR_DLEN_3 | PPISETR_CLEN;
58011696c5eSBiju Das rcar_mipi_dsi_write(dsi, PPISETR, ppisetr);
58111696c5eSBiju Das
58211696c5eSBiju Das rcar_mipi_dsi_set(dsi, PHYSETUP, PHYSETUP_SHUTDOWNZ);
58311696c5eSBiju Das rcar_mipi_dsi_set(dsi, PHYSETUP, PHYSETUP_RSTZ);
58411696c5eSBiju Das usleep_range(400, 500);
58511696c5eSBiju Das
58611696c5eSBiju Das /* Checking PPI clock status register */
58711696c5eSBiju Das for (timeout = 10; timeout > 0; --timeout) {
58811696c5eSBiju Das if ((rcar_mipi_dsi_read(dsi, PPICLSR) & PPICLSR_STPST) &&
58911696c5eSBiju Das (rcar_mipi_dsi_read(dsi, PPIDLSR) & PPIDLSR_STPST) &&
59011696c5eSBiju Das (rcar_mipi_dsi_read(dsi, CLOCKSET1) & CLOCKSET1_LOCK))
59111696c5eSBiju Das break;
59211696c5eSBiju Das
59311696c5eSBiju Das usleep_range(1000, 2000);
59411696c5eSBiju Das }
59511696c5eSBiju Das
59611696c5eSBiju Das if (!timeout) {
59711696c5eSBiju Das dev_err(dsi->dev, "failed to enable PPI clock\n");
59811696c5eSBiju Das return -ETIMEDOUT;
59911696c5eSBiju Das }
60011696c5eSBiju Das
60111696c5eSBiju Das switch (dsi->info->model) {
60211696c5eSBiju Das case RCAR_DSI_V3U:
60311696c5eSBiju Das default:
60411696c5eSBiju Das ret = rcar_mipi_dsi_post_init_phtw_v3u(dsi);
60511696c5eSBiju Das if (ret < 0)
60611696c5eSBiju Das return ret;
60711696c5eSBiju Das break;
60811696c5eSBiju Das
60911696c5eSBiju Das case RCAR_DSI_V4H:
61011696c5eSBiju Das ret = rcar_mipi_dsi_post_init_phtw_v4h(dsi, &setup_info);
61111696c5eSBiju Das if (ret < 0)
61211696c5eSBiju Das return ret;
61311696c5eSBiju Das break;
61411696c5eSBiju Das }
61511696c5eSBiju Das
61611696c5eSBiju Das /* Enable DOT clock */
61711696c5eSBiju Das vclkset = VCLKSET_CKEN;
61811696c5eSBiju Das rcar_mipi_dsi_write(dsi, VCLKSET, vclkset);
61911696c5eSBiju Das
62011696c5eSBiju Das if (dsi_format == 24)
62111696c5eSBiju Das vclkset |= VCLKSET_BPP_24;
62211696c5eSBiju Das else if (dsi_format == 18)
62311696c5eSBiju Das vclkset |= VCLKSET_BPP_18;
62411696c5eSBiju Das else if (dsi_format == 16)
62511696c5eSBiju Das vclkset |= VCLKSET_BPP_16;
62611696c5eSBiju Das else {
62711696c5eSBiju Das dev_warn(dsi->dev, "unsupported format");
62811696c5eSBiju Das return -EINVAL;
62911696c5eSBiju Das }
63011696c5eSBiju Das
63111696c5eSBiju Das vclkset |= VCLKSET_COLOR_RGB | VCLKSET_LANE(dsi->lanes - 1);
63211696c5eSBiju Das
63311696c5eSBiju Das switch (dsi->info->model) {
63411696c5eSBiju Das case RCAR_DSI_V3U:
63511696c5eSBiju Das default:
63611696c5eSBiju Das vclkset |= VCLKSET_DIV_V3U(__ffs(setup_info.vclk_divider));
63711696c5eSBiju Das break;
63811696c5eSBiju Das
63911696c5eSBiju Das case RCAR_DSI_V4H:
64011696c5eSBiju Das vclkset |= VCLKSET_DIV_V4H(__ffs(setup_info.vclk_divider) - 1);
64111696c5eSBiju Das break;
64211696c5eSBiju Das }
64311696c5eSBiju Das
64411696c5eSBiju Das rcar_mipi_dsi_write(dsi, VCLKSET, vclkset);
64511696c5eSBiju Das
64611696c5eSBiju Das /* After setting VCLKSET register, enable VCLKEN */
64711696c5eSBiju Das rcar_mipi_dsi_set(dsi, VCLKEN, VCLKEN_CKEN);
64811696c5eSBiju Das
64911696c5eSBiju Das dev_dbg(dsi->dev, "DSI device is started\n");
65011696c5eSBiju Das
65111696c5eSBiju Das return 0;
65211696c5eSBiju Das }
65311696c5eSBiju Das
rcar_mipi_dsi_shutdown(struct rcar_mipi_dsi * dsi)65411696c5eSBiju Das static void rcar_mipi_dsi_shutdown(struct rcar_mipi_dsi *dsi)
65511696c5eSBiju Das {
65611696c5eSBiju Das /* Disable VCLKEN */
65711696c5eSBiju Das rcar_mipi_dsi_write(dsi, VCLKSET, 0);
65811696c5eSBiju Das
65911696c5eSBiju Das /* Disable DOT clock */
66011696c5eSBiju Das rcar_mipi_dsi_write(dsi, VCLKSET, 0);
66111696c5eSBiju Das
66211696c5eSBiju Das rcar_mipi_dsi_clr(dsi, PHYSETUP, PHYSETUP_RSTZ);
66311696c5eSBiju Das rcar_mipi_dsi_clr(dsi, PHYSETUP, PHYSETUP_SHUTDOWNZ);
66411696c5eSBiju Das
66511696c5eSBiju Das /* CFGCLK disable */
66611696c5eSBiju Das rcar_mipi_dsi_clr(dsi, CFGCLKSET, CFGCLKSET_CKEN);
66711696c5eSBiju Das
66811696c5eSBiju Das /* LPCLK disable */
66911696c5eSBiju Das rcar_mipi_dsi_clr(dsi, LPCLKSET, LPCLKSET_CKEN);
67011696c5eSBiju Das
67111696c5eSBiju Das dev_dbg(dsi->dev, "DSI device is shutdown\n");
67211696c5eSBiju Das }
67311696c5eSBiju Das
rcar_mipi_dsi_clk_enable(struct rcar_mipi_dsi * dsi)67411696c5eSBiju Das static int rcar_mipi_dsi_clk_enable(struct rcar_mipi_dsi *dsi)
67511696c5eSBiju Das {
67611696c5eSBiju Das int ret;
67711696c5eSBiju Das
67811696c5eSBiju Das reset_control_deassert(dsi->rstc);
67911696c5eSBiju Das
68011696c5eSBiju Das ret = clk_prepare_enable(dsi->clocks.mod);
68111696c5eSBiju Das if (ret < 0)
68211696c5eSBiju Das goto err_reset;
68311696c5eSBiju Das
68411696c5eSBiju Das ret = clk_prepare_enable(dsi->clocks.dsi);
68511696c5eSBiju Das if (ret < 0)
68611696c5eSBiju Das goto err_clock;
68711696c5eSBiju Das
68811696c5eSBiju Das return 0;
68911696c5eSBiju Das
69011696c5eSBiju Das err_clock:
69111696c5eSBiju Das clk_disable_unprepare(dsi->clocks.mod);
69211696c5eSBiju Das err_reset:
69311696c5eSBiju Das reset_control_assert(dsi->rstc);
69411696c5eSBiju Das return ret;
69511696c5eSBiju Das }
69611696c5eSBiju Das
rcar_mipi_dsi_clk_disable(struct rcar_mipi_dsi * dsi)69711696c5eSBiju Das static void rcar_mipi_dsi_clk_disable(struct rcar_mipi_dsi *dsi)
69811696c5eSBiju Das {
69911696c5eSBiju Das clk_disable_unprepare(dsi->clocks.dsi);
70011696c5eSBiju Das clk_disable_unprepare(dsi->clocks.mod);
70111696c5eSBiju Das
70211696c5eSBiju Das reset_control_assert(dsi->rstc);
70311696c5eSBiju Das }
70411696c5eSBiju Das
rcar_mipi_dsi_start_hs_clock(struct rcar_mipi_dsi * dsi)70511696c5eSBiju Das static int rcar_mipi_dsi_start_hs_clock(struct rcar_mipi_dsi *dsi)
70611696c5eSBiju Das {
70711696c5eSBiju Das /*
70811696c5eSBiju Das * In HW manual, we need to check TxDDRClkHS-Q Stable? but it dont
70911696c5eSBiju Das * write how to check. So we skip this check in this patch
71011696c5eSBiju Das */
71111696c5eSBiju Das u32 status;
71211696c5eSBiju Das int ret;
71311696c5eSBiju Das
71411696c5eSBiju Das /* Start HS clock. */
71511696c5eSBiju Das rcar_mipi_dsi_set(dsi, PPICLCR, PPICLCR_TXREQHS);
71611696c5eSBiju Das
71711696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
71811696c5eSBiju Das status & PPICLSR_TOHS,
71911696c5eSBiju Das 2000, 10000, false, dsi, PPICLSR);
72011696c5eSBiju Das if (ret < 0) {
72111696c5eSBiju Das dev_err(dsi->dev, "failed to enable HS clock\n");
72211696c5eSBiju Das return ret;
72311696c5eSBiju Das }
72411696c5eSBiju Das
72511696c5eSBiju Das rcar_mipi_dsi_set(dsi, PPICLSCR, PPICLSCR_TOHS);
72611696c5eSBiju Das
72711696c5eSBiju Das return 0;
72811696c5eSBiju Das }
72911696c5eSBiju Das
rcar_mipi_dsi_start_video(struct rcar_mipi_dsi * dsi)73011696c5eSBiju Das static int rcar_mipi_dsi_start_video(struct rcar_mipi_dsi *dsi)
73111696c5eSBiju Das {
73211696c5eSBiju Das u32 status;
73311696c5eSBiju Das int ret;
73411696c5eSBiju Das
73511696c5eSBiju Das /* Wait for the link to be ready. */
73611696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
73711696c5eSBiju Das !(status & (LINKSR_LPBUSY | LINKSR_HSBUSY)),
73811696c5eSBiju Das 2000, 10000, false, dsi, LINKSR);
73911696c5eSBiju Das if (ret < 0) {
74011696c5eSBiju Das dev_err(dsi->dev, "Link failed to become ready\n");
74111696c5eSBiju Das return ret;
74211696c5eSBiju Das }
74311696c5eSBiju Das
74411696c5eSBiju Das /* De-assert video FIFO clear. */
74511696c5eSBiju Das rcar_mipi_dsi_clr(dsi, TXVMCR, TXVMCR_VFCLR);
74611696c5eSBiju Das
74711696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
74811696c5eSBiju Das status & TXVMSR_VFRDY,
74911696c5eSBiju Das 2000, 10000, false, dsi, TXVMSR);
75011696c5eSBiju Das if (ret < 0) {
75111696c5eSBiju Das dev_err(dsi->dev, "Failed to de-assert video FIFO clear\n");
75211696c5eSBiju Das return ret;
75311696c5eSBiju Das }
75411696c5eSBiju Das
75511696c5eSBiju Das /* Enable transmission in video mode. */
75611696c5eSBiju Das rcar_mipi_dsi_set(dsi, TXVMCR, TXVMCR_EN_VIDEO);
75711696c5eSBiju Das
75811696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
75911696c5eSBiju Das status & TXVMSR_RDY,
76011696c5eSBiju Das 2000, 10000, false, dsi, TXVMSR);
76111696c5eSBiju Das if (ret < 0) {
76211696c5eSBiju Das dev_err(dsi->dev, "Failed to enable video transmission\n");
76311696c5eSBiju Das return ret;
76411696c5eSBiju Das }
76511696c5eSBiju Das
76611696c5eSBiju Das return 0;
76711696c5eSBiju Das }
76811696c5eSBiju Das
rcar_mipi_dsi_stop_video(struct rcar_mipi_dsi * dsi)76911696c5eSBiju Das static void rcar_mipi_dsi_stop_video(struct rcar_mipi_dsi *dsi)
77011696c5eSBiju Das {
77111696c5eSBiju Das u32 status;
77211696c5eSBiju Das int ret;
77311696c5eSBiju Das
77411696c5eSBiju Das /* Disable transmission in video mode. */
77511696c5eSBiju Das rcar_mipi_dsi_clr(dsi, TXVMCR, TXVMCR_EN_VIDEO);
77611696c5eSBiju Das
77711696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
77811696c5eSBiju Das !(status & TXVMSR_ACT),
77911696c5eSBiju Das 2000, 100000, false, dsi, TXVMSR);
78011696c5eSBiju Das if (ret < 0) {
78111696c5eSBiju Das dev_err(dsi->dev, "Failed to disable video transmission\n");
78211696c5eSBiju Das return;
78311696c5eSBiju Das }
78411696c5eSBiju Das
78511696c5eSBiju Das /* Assert video FIFO clear. */
78611696c5eSBiju Das rcar_mipi_dsi_set(dsi, TXVMCR, TXVMCR_VFCLR);
78711696c5eSBiju Das
78811696c5eSBiju Das ret = read_poll_timeout(rcar_mipi_dsi_read, status,
78911696c5eSBiju Das !(status & TXVMSR_VFRDY),
79011696c5eSBiju Das 2000, 100000, false, dsi, TXVMSR);
79111696c5eSBiju Das if (ret < 0) {
79211696c5eSBiju Das dev_err(dsi->dev, "Failed to assert video FIFO clear\n");
79311696c5eSBiju Das return;
79411696c5eSBiju Das }
79511696c5eSBiju Das }
79611696c5eSBiju Das
79711696c5eSBiju Das /* -----------------------------------------------------------------------------
79811696c5eSBiju Das * Bridge
79911696c5eSBiju Das */
80011696c5eSBiju Das
rcar_mipi_dsi_attach(struct drm_bridge * bridge,enum drm_bridge_attach_flags flags)80111696c5eSBiju Das static int rcar_mipi_dsi_attach(struct drm_bridge *bridge,
80211696c5eSBiju Das enum drm_bridge_attach_flags flags)
80311696c5eSBiju Das {
80411696c5eSBiju Das struct rcar_mipi_dsi *dsi = bridge_to_rcar_mipi_dsi(bridge);
80511696c5eSBiju Das
80611696c5eSBiju Das return drm_bridge_attach(bridge->encoder, dsi->next_bridge, bridge,
80711696c5eSBiju Das flags);
80811696c5eSBiju Das }
80911696c5eSBiju Das
rcar_mipi_dsi_atomic_enable(struct drm_bridge * bridge,struct drm_bridge_state * old_bridge_state)81011696c5eSBiju Das static void rcar_mipi_dsi_atomic_enable(struct drm_bridge *bridge,
81111696c5eSBiju Das struct drm_bridge_state *old_bridge_state)
81211696c5eSBiju Das {
81311696c5eSBiju Das struct rcar_mipi_dsi *dsi = bridge_to_rcar_mipi_dsi(bridge);
81411696c5eSBiju Das
81511696c5eSBiju Das rcar_mipi_dsi_start_video(dsi);
81611696c5eSBiju Das }
81711696c5eSBiju Das
rcar_mipi_dsi_atomic_disable(struct drm_bridge * bridge,struct drm_bridge_state * old_bridge_state)81811696c5eSBiju Das static void rcar_mipi_dsi_atomic_disable(struct drm_bridge *bridge,
81911696c5eSBiju Das struct drm_bridge_state *old_bridge_state)
82011696c5eSBiju Das {
82111696c5eSBiju Das struct rcar_mipi_dsi *dsi = bridge_to_rcar_mipi_dsi(bridge);
82211696c5eSBiju Das
82311696c5eSBiju Das rcar_mipi_dsi_stop_video(dsi);
82411696c5eSBiju Das }
82511696c5eSBiju Das
rcar_mipi_dsi_pclk_enable(struct drm_bridge * bridge,struct drm_atomic_state * state)82611696c5eSBiju Das void rcar_mipi_dsi_pclk_enable(struct drm_bridge *bridge,
82711696c5eSBiju Das struct drm_atomic_state *state)
82811696c5eSBiju Das {
82911696c5eSBiju Das struct rcar_mipi_dsi *dsi = bridge_to_rcar_mipi_dsi(bridge);
83011696c5eSBiju Das const struct drm_display_mode *mode;
83111696c5eSBiju Das struct drm_connector *connector;
83211696c5eSBiju Das struct drm_crtc *crtc;
83311696c5eSBiju Das int ret;
83411696c5eSBiju Das
83511696c5eSBiju Das connector = drm_atomic_get_new_connector_for_encoder(state,
83611696c5eSBiju Das bridge->encoder);
83711696c5eSBiju Das crtc = drm_atomic_get_new_connector_state(state, connector)->crtc;
83811696c5eSBiju Das mode = &drm_atomic_get_new_crtc_state(state, crtc)->adjusted_mode;
83911696c5eSBiju Das
84011696c5eSBiju Das ret = rcar_mipi_dsi_clk_enable(dsi);
84111696c5eSBiju Das if (ret < 0) {
84211696c5eSBiju Das dev_err(dsi->dev, "failed to enable DSI clocks\n");
84311696c5eSBiju Das return;
84411696c5eSBiju Das }
84511696c5eSBiju Das
84611696c5eSBiju Das ret = rcar_mipi_dsi_startup(dsi, mode);
84711696c5eSBiju Das if (ret < 0)
84811696c5eSBiju Das goto err_dsi_startup;
84911696c5eSBiju Das
85011696c5eSBiju Das rcar_mipi_dsi_set_display_timing(dsi, mode);
85111696c5eSBiju Das
85211696c5eSBiju Das ret = rcar_mipi_dsi_start_hs_clock(dsi);
85311696c5eSBiju Das if (ret < 0)
85411696c5eSBiju Das goto err_dsi_start_hs;
85511696c5eSBiju Das
85611696c5eSBiju Das return;
85711696c5eSBiju Das
85811696c5eSBiju Das err_dsi_start_hs:
85911696c5eSBiju Das rcar_mipi_dsi_shutdown(dsi);
86011696c5eSBiju Das err_dsi_startup:
86111696c5eSBiju Das rcar_mipi_dsi_clk_disable(dsi);
86211696c5eSBiju Das }
86311696c5eSBiju Das EXPORT_SYMBOL_GPL(rcar_mipi_dsi_pclk_enable);
86411696c5eSBiju Das
rcar_mipi_dsi_pclk_disable(struct drm_bridge * bridge)86511696c5eSBiju Das void rcar_mipi_dsi_pclk_disable(struct drm_bridge *bridge)
86611696c5eSBiju Das {
86711696c5eSBiju Das struct rcar_mipi_dsi *dsi = bridge_to_rcar_mipi_dsi(bridge);
86811696c5eSBiju Das
86911696c5eSBiju Das rcar_mipi_dsi_shutdown(dsi);
87011696c5eSBiju Das rcar_mipi_dsi_clk_disable(dsi);
87111696c5eSBiju Das }
87211696c5eSBiju Das EXPORT_SYMBOL_GPL(rcar_mipi_dsi_pclk_disable);
87311696c5eSBiju Das
87411696c5eSBiju Das static enum drm_mode_status
rcar_mipi_dsi_bridge_mode_valid(struct drm_bridge * bridge,const struct drm_display_info * info,const struct drm_display_mode * mode)87511696c5eSBiju Das rcar_mipi_dsi_bridge_mode_valid(struct drm_bridge *bridge,
87611696c5eSBiju Das const struct drm_display_info *info,
87711696c5eSBiju Das const struct drm_display_mode *mode)
87811696c5eSBiju Das {
87911696c5eSBiju Das if (mode->clock > 297000)
88011696c5eSBiju Das return MODE_CLOCK_HIGH;
88111696c5eSBiju Das
88211696c5eSBiju Das return MODE_OK;
88311696c5eSBiju Das }
88411696c5eSBiju Das
88511696c5eSBiju Das static const struct drm_bridge_funcs rcar_mipi_dsi_bridge_ops = {
88611696c5eSBiju Das .attach = rcar_mipi_dsi_attach,
88711696c5eSBiju Das .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
88811696c5eSBiju Das .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
88911696c5eSBiju Das .atomic_reset = drm_atomic_helper_bridge_reset,
89011696c5eSBiju Das .atomic_enable = rcar_mipi_dsi_atomic_enable,
89111696c5eSBiju Das .atomic_disable = rcar_mipi_dsi_atomic_disable,
89211696c5eSBiju Das .mode_valid = rcar_mipi_dsi_bridge_mode_valid,
89311696c5eSBiju Das };
89411696c5eSBiju Das
89511696c5eSBiju Das /* -----------------------------------------------------------------------------
89611696c5eSBiju Das * Host setting
89711696c5eSBiju Das */
89811696c5eSBiju Das
rcar_mipi_dsi_host_attach(struct mipi_dsi_host * host,struct mipi_dsi_device * device)89911696c5eSBiju Das static int rcar_mipi_dsi_host_attach(struct mipi_dsi_host *host,
90011696c5eSBiju Das struct mipi_dsi_device *device)
90111696c5eSBiju Das {
90211696c5eSBiju Das struct rcar_mipi_dsi *dsi = host_to_rcar_mipi_dsi(host);
90311696c5eSBiju Das int ret;
90411696c5eSBiju Das
90511696c5eSBiju Das if (device->lanes > dsi->num_data_lanes)
90611696c5eSBiju Das return -EINVAL;
90711696c5eSBiju Das
90811696c5eSBiju Das dsi->lanes = device->lanes;
90911696c5eSBiju Das dsi->format = device->format;
91011696c5eSBiju Das
91111696c5eSBiju Das dsi->next_bridge = devm_drm_of_get_bridge(dsi->dev, dsi->dev->of_node,
91211696c5eSBiju Das 1, 0);
91311696c5eSBiju Das if (IS_ERR(dsi->next_bridge)) {
91411696c5eSBiju Das ret = PTR_ERR(dsi->next_bridge);
91511696c5eSBiju Das dev_err(dsi->dev, "failed to get next bridge: %d\n", ret);
91611696c5eSBiju Das return ret;
91711696c5eSBiju Das }
91811696c5eSBiju Das
91911696c5eSBiju Das /* Initialize the DRM bridge. */
92011696c5eSBiju Das dsi->bridge.funcs = &rcar_mipi_dsi_bridge_ops;
92111696c5eSBiju Das dsi->bridge.of_node = dsi->dev->of_node;
92211696c5eSBiju Das drm_bridge_add(&dsi->bridge);
92311696c5eSBiju Das
92411696c5eSBiju Das return 0;
92511696c5eSBiju Das }
92611696c5eSBiju Das
rcar_mipi_dsi_host_detach(struct mipi_dsi_host * host,struct mipi_dsi_device * device)92711696c5eSBiju Das static int rcar_mipi_dsi_host_detach(struct mipi_dsi_host *host,
92811696c5eSBiju Das struct mipi_dsi_device *device)
92911696c5eSBiju Das {
93011696c5eSBiju Das struct rcar_mipi_dsi *dsi = host_to_rcar_mipi_dsi(host);
93111696c5eSBiju Das
93211696c5eSBiju Das drm_bridge_remove(&dsi->bridge);
93311696c5eSBiju Das
93411696c5eSBiju Das return 0;
93511696c5eSBiju Das }
93611696c5eSBiju Das
93711696c5eSBiju Das static const struct mipi_dsi_host_ops rcar_mipi_dsi_host_ops = {
93811696c5eSBiju Das .attach = rcar_mipi_dsi_host_attach,
93911696c5eSBiju Das .detach = rcar_mipi_dsi_host_detach,
94011696c5eSBiju Das };
94111696c5eSBiju Das
94211696c5eSBiju Das /* -----------------------------------------------------------------------------
94311696c5eSBiju Das * Probe & Remove
94411696c5eSBiju Das */
94511696c5eSBiju Das
rcar_mipi_dsi_parse_dt(struct rcar_mipi_dsi * dsi)94611696c5eSBiju Das static int rcar_mipi_dsi_parse_dt(struct rcar_mipi_dsi *dsi)
94711696c5eSBiju Das {
94811696c5eSBiju Das int ret;
94911696c5eSBiju Das
95011696c5eSBiju Das ret = drm_of_get_data_lanes_count_ep(dsi->dev->of_node, 1, 0, 1, 4);
95111696c5eSBiju Das if (ret < 0) {
95211696c5eSBiju Das dev_err(dsi->dev, "missing or invalid data-lanes property\n");
95311696c5eSBiju Das return ret;
95411696c5eSBiju Das }
95511696c5eSBiju Das
95611696c5eSBiju Das dsi->num_data_lanes = ret;
95711696c5eSBiju Das return 0;
95811696c5eSBiju Das }
95911696c5eSBiju Das
rcar_mipi_dsi_get_clock(struct rcar_mipi_dsi * dsi,const char * name,bool optional)96011696c5eSBiju Das static struct clk *rcar_mipi_dsi_get_clock(struct rcar_mipi_dsi *dsi,
96111696c5eSBiju Das const char *name,
96211696c5eSBiju Das bool optional)
96311696c5eSBiju Das {
96411696c5eSBiju Das struct clk *clk;
96511696c5eSBiju Das
96611696c5eSBiju Das clk = devm_clk_get(dsi->dev, name);
96711696c5eSBiju Das if (!IS_ERR(clk))
96811696c5eSBiju Das return clk;
96911696c5eSBiju Das
97011696c5eSBiju Das if (PTR_ERR(clk) == -ENOENT && optional)
97111696c5eSBiju Das return NULL;
97211696c5eSBiju Das
97311696c5eSBiju Das dev_err_probe(dsi->dev, PTR_ERR(clk), "failed to get %s clock\n",
97411696c5eSBiju Das name ? name : "module");
97511696c5eSBiju Das
97611696c5eSBiju Das return clk;
97711696c5eSBiju Das }
97811696c5eSBiju Das
rcar_mipi_dsi_get_clocks(struct rcar_mipi_dsi * dsi)97911696c5eSBiju Das static int rcar_mipi_dsi_get_clocks(struct rcar_mipi_dsi *dsi)
98011696c5eSBiju Das {
98111696c5eSBiju Das dsi->clocks.mod = rcar_mipi_dsi_get_clock(dsi, NULL, false);
98211696c5eSBiju Das if (IS_ERR(dsi->clocks.mod))
98311696c5eSBiju Das return PTR_ERR(dsi->clocks.mod);
98411696c5eSBiju Das
98511696c5eSBiju Das dsi->clocks.pll = rcar_mipi_dsi_get_clock(dsi, "pll", true);
98611696c5eSBiju Das if (IS_ERR(dsi->clocks.pll))
98711696c5eSBiju Das return PTR_ERR(dsi->clocks.pll);
98811696c5eSBiju Das
98911696c5eSBiju Das dsi->clocks.dsi = rcar_mipi_dsi_get_clock(dsi, "dsi", true);
99011696c5eSBiju Das if (IS_ERR(dsi->clocks.dsi))
99111696c5eSBiju Das return PTR_ERR(dsi->clocks.dsi);
99211696c5eSBiju Das
99311696c5eSBiju Das if (!dsi->clocks.pll && !dsi->clocks.dsi) {
99411696c5eSBiju Das dev_err(dsi->dev, "no input clock (pll, dsi)\n");
99511696c5eSBiju Das return -EINVAL;
99611696c5eSBiju Das }
99711696c5eSBiju Das
99811696c5eSBiju Das return 0;
99911696c5eSBiju Das }
100011696c5eSBiju Das
rcar_mipi_dsi_probe(struct platform_device * pdev)100111696c5eSBiju Das static int rcar_mipi_dsi_probe(struct platform_device *pdev)
100211696c5eSBiju Das {
100311696c5eSBiju Das struct rcar_mipi_dsi *dsi;
100411696c5eSBiju Das int ret;
100511696c5eSBiju Das
100611696c5eSBiju Das dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL);
100711696c5eSBiju Das if (dsi == NULL)
100811696c5eSBiju Das return -ENOMEM;
100911696c5eSBiju Das
101011696c5eSBiju Das platform_set_drvdata(pdev, dsi);
101111696c5eSBiju Das
101211696c5eSBiju Das dsi->dev = &pdev->dev;
101311696c5eSBiju Das dsi->info = of_device_get_match_data(&pdev->dev);
101411696c5eSBiju Das
101511696c5eSBiju Das ret = rcar_mipi_dsi_parse_dt(dsi);
101611696c5eSBiju Das if (ret < 0)
101711696c5eSBiju Das return ret;
101811696c5eSBiju Das
101911696c5eSBiju Das /* Acquire resources. */
1020*6e6c74a4SYangtao Li dsi->mmio = devm_platform_ioremap_resource(pdev, 0);
102111696c5eSBiju Das if (IS_ERR(dsi->mmio))
102211696c5eSBiju Das return PTR_ERR(dsi->mmio);
102311696c5eSBiju Das
102411696c5eSBiju Das ret = rcar_mipi_dsi_get_clocks(dsi);
102511696c5eSBiju Das if (ret < 0)
102611696c5eSBiju Das return ret;
102711696c5eSBiju Das
102811696c5eSBiju Das dsi->rstc = devm_reset_control_get(dsi->dev, NULL);
102911696c5eSBiju Das if (IS_ERR(dsi->rstc)) {
103011696c5eSBiju Das dev_err(dsi->dev, "failed to get cpg reset\n");
103111696c5eSBiju Das return PTR_ERR(dsi->rstc);
103211696c5eSBiju Das }
103311696c5eSBiju Das
103411696c5eSBiju Das /* Initialize the DSI host. */
103511696c5eSBiju Das dsi->host.dev = dsi->dev;
103611696c5eSBiju Das dsi->host.ops = &rcar_mipi_dsi_host_ops;
103711696c5eSBiju Das ret = mipi_dsi_host_register(&dsi->host);
103811696c5eSBiju Das if (ret < 0)
103911696c5eSBiju Das return ret;
104011696c5eSBiju Das
104111696c5eSBiju Das return 0;
104211696c5eSBiju Das }
104311696c5eSBiju Das
rcar_mipi_dsi_remove(struct platform_device * pdev)1044de8a334fSThomas Zimmermann static void rcar_mipi_dsi_remove(struct platform_device *pdev)
104511696c5eSBiju Das {
104611696c5eSBiju Das struct rcar_mipi_dsi *dsi = platform_get_drvdata(pdev);
104711696c5eSBiju Das
104811696c5eSBiju Das mipi_dsi_host_unregister(&dsi->host);
104911696c5eSBiju Das }
105011696c5eSBiju Das
105111696c5eSBiju Das static const struct rcar_mipi_dsi_device_info v3u_data = {
105211696c5eSBiju Das .model = RCAR_DSI_V3U,
105311696c5eSBiju Das .clk_cfg = dsi_clk_cfg_v3u,
105411696c5eSBiju Das .clockset2_m_offset = 2,
105511696c5eSBiju Das .n_min = 3,
105611696c5eSBiju Das .n_max = 8,
105711696c5eSBiju Das .n_mul = 1,
105811696c5eSBiju Das .fpfd_min = MHZ(2),
105911696c5eSBiju Das .fpfd_max = MHZ(8),
106011696c5eSBiju Das .m_min = 64,
106111696c5eSBiju Das .m_max = 625,
106211696c5eSBiju Das .fout_min = MHZ(320),
106311696c5eSBiju Das .fout_max = MHZ(1250),
106411696c5eSBiju Das };
106511696c5eSBiju Das
106611696c5eSBiju Das static const struct rcar_mipi_dsi_device_info v4h_data = {
106711696c5eSBiju Das .model = RCAR_DSI_V4H,
106811696c5eSBiju Das .clk_cfg = dsi_clk_cfg_v4h,
106911696c5eSBiju Das .clockset2_m_offset = 0,
107011696c5eSBiju Das .n_min = 1,
107111696c5eSBiju Das .n_max = 8,
107211696c5eSBiju Das .n_mul = 2,
107311696c5eSBiju Das .fpfd_min = MHZ(8),
107411696c5eSBiju Das .fpfd_max = MHZ(24),
107511696c5eSBiju Das .m_min = 167,
107611696c5eSBiju Das .m_max = 1000,
107711696c5eSBiju Das .fout_min = MHZ(2000),
107811696c5eSBiju Das .fout_max = MHZ(4000),
107911696c5eSBiju Das };
108011696c5eSBiju Das
108111696c5eSBiju Das static const struct of_device_id rcar_mipi_dsi_of_table[] = {
108211696c5eSBiju Das { .compatible = "renesas,r8a779a0-dsi-csi2-tx", .data = &v3u_data },
108311696c5eSBiju Das { .compatible = "renesas,r8a779g0-dsi-csi2-tx", .data = &v4h_data },
108411696c5eSBiju Das { }
108511696c5eSBiju Das };
108611696c5eSBiju Das
108711696c5eSBiju Das MODULE_DEVICE_TABLE(of, rcar_mipi_dsi_of_table);
108811696c5eSBiju Das
108911696c5eSBiju Das static struct platform_driver rcar_mipi_dsi_platform_driver = {
109011696c5eSBiju Das .probe = rcar_mipi_dsi_probe,
1091de8a334fSThomas Zimmermann .remove_new = rcar_mipi_dsi_remove,
109211696c5eSBiju Das .driver = {
109311696c5eSBiju Das .name = "rcar-mipi-dsi",
109411696c5eSBiju Das .of_match_table = rcar_mipi_dsi_of_table,
109511696c5eSBiju Das },
109611696c5eSBiju Das };
109711696c5eSBiju Das
109811696c5eSBiju Das module_platform_driver(rcar_mipi_dsi_platform_driver);
109911696c5eSBiju Das
110011696c5eSBiju Das MODULE_DESCRIPTION("Renesas R-Car MIPI DSI Encoder Driver");
110111696c5eSBiju Das MODULE_LICENSE("GPL");
1102