xref: /linux/drivers/gpu/drm/panel/panel-renesas-r61307.c (revision 8d2b0853add1d7534dc0794e3c8e0b9e8c4ec640)
1*cb6c01eaSSvyatoslav Ryhel // SPDX-License-Identifier: GPL-2.0
2*cb6c01eaSSvyatoslav Ryhel 
3*cb6c01eaSSvyatoslav Ryhel #include <linux/array_size.h>
4*cb6c01eaSSvyatoslav Ryhel #include <linux/delay.h>
5*cb6c01eaSSvyatoslav Ryhel #include <linux/err.h>
6*cb6c01eaSSvyatoslav Ryhel #include <linux/gpio/consumer.h>
7*cb6c01eaSSvyatoslav Ryhel #include <linux/mod_devicetable.h>
8*cb6c01eaSSvyatoslav Ryhel #include <linux/module.h>
9*cb6c01eaSSvyatoslav Ryhel #include <linux/property.h>
10*cb6c01eaSSvyatoslav Ryhel #include <linux/regulator/consumer.h>
11*cb6c01eaSSvyatoslav Ryhel 
12*cb6c01eaSSvyatoslav Ryhel #include <video/mipi_display.h>
13*cb6c01eaSSvyatoslav Ryhel 
14*cb6c01eaSSvyatoslav Ryhel #include <drm/drm_mipi_dsi.h>
15*cb6c01eaSSvyatoslav Ryhel #include <drm/drm_modes.h>
16*cb6c01eaSSvyatoslav Ryhel #include <drm/drm_panel.h>
17*cb6c01eaSSvyatoslav Ryhel 
18*cb6c01eaSSvyatoslav Ryhel #define R61307_MACP		0xb0 /* Manufacturer CMD Protect */
19*cb6c01eaSSvyatoslav Ryhel #define   R61307_MACP_ON	0x03
20*cb6c01eaSSvyatoslav Ryhel #define   R61307_MACP_OFF	0x04
21*cb6c01eaSSvyatoslav Ryhel 
22*cb6c01eaSSvyatoslav Ryhel #define R61307_INVERSION	0xc1
23*cb6c01eaSSvyatoslav Ryhel #define R61307_GAMMA_SET_A	0xc8 /* Gamma Setting A */
24*cb6c01eaSSvyatoslav Ryhel #define R61307_GAMMA_SET_B	0xc9 /* Gamma Setting B */
25*cb6c01eaSSvyatoslav Ryhel #define R61307_GAMMA_SET_C	0xca /* Gamma Setting C */
26*cb6c01eaSSvyatoslav Ryhel #define R61307_CONTRAST_SET	0xcc
27*cb6c01eaSSvyatoslav Ryhel 
28*cb6c01eaSSvyatoslav Ryhel struct renesas_r61307 {
29*cb6c01eaSSvyatoslav Ryhel 	struct drm_panel panel;
30*cb6c01eaSSvyatoslav Ryhel 	struct mipi_dsi_device *dsi;
31*cb6c01eaSSvyatoslav Ryhel 
32*cb6c01eaSSvyatoslav Ryhel 	struct regulator *vcc_supply;
33*cb6c01eaSSvyatoslav Ryhel 	struct regulator *iovcc_supply;
34*cb6c01eaSSvyatoslav Ryhel 
35*cb6c01eaSSvyatoslav Ryhel 	struct gpio_desc *reset_gpio;
36*cb6c01eaSSvyatoslav Ryhel 
37*cb6c01eaSSvyatoslav Ryhel 	bool prepared;
38*cb6c01eaSSvyatoslav Ryhel 
39*cb6c01eaSSvyatoslav Ryhel 	bool dig_cont_adj;
40*cb6c01eaSSvyatoslav Ryhel 	bool inversion;
41*cb6c01eaSSvyatoslav Ryhel 	u32 gamma;
42*cb6c01eaSSvyatoslav Ryhel };
43*cb6c01eaSSvyatoslav Ryhel 
44*cb6c01eaSSvyatoslav Ryhel static const u8 gamma_setting[][25] = {
45*cb6c01eaSSvyatoslav Ryhel 	{ /* sentinel */ },
46*cb6c01eaSSvyatoslav Ryhel 	{
47*cb6c01eaSSvyatoslav Ryhel 		R61307_GAMMA_SET_A,
48*cb6c01eaSSvyatoslav Ryhel 		0x00, 0x06, 0x0a, 0x0f,
49*cb6c01eaSSvyatoslav Ryhel 		0x14, 0x1f, 0x1f, 0x17,
50*cb6c01eaSSvyatoslav Ryhel 		0x12, 0x0c, 0x09, 0x06,
51*cb6c01eaSSvyatoslav Ryhel 		0x00, 0x06, 0x0a, 0x0f,
52*cb6c01eaSSvyatoslav Ryhel 		0x14, 0x1f, 0x1f, 0x17,
53*cb6c01eaSSvyatoslav Ryhel 		0x12, 0x0c, 0x09, 0x06
54*cb6c01eaSSvyatoslav Ryhel 	},
55*cb6c01eaSSvyatoslav Ryhel 	{
56*cb6c01eaSSvyatoslav Ryhel 		R61307_GAMMA_SET_A,
57*cb6c01eaSSvyatoslav Ryhel 		0x00, 0x05, 0x0b, 0x0f,
58*cb6c01eaSSvyatoslav Ryhel 		0x11, 0x1d, 0x20, 0x18,
59*cb6c01eaSSvyatoslav Ryhel 		0x18, 0x09, 0x07, 0x06,
60*cb6c01eaSSvyatoslav Ryhel 		0x00, 0x05, 0x0b, 0x0f,
61*cb6c01eaSSvyatoslav Ryhel 		0x11, 0x1d, 0x20, 0x18,
62*cb6c01eaSSvyatoslav Ryhel 		0x18, 0x09, 0x07, 0x06
63*cb6c01eaSSvyatoslav Ryhel 	},
64*cb6c01eaSSvyatoslav Ryhel 	{
65*cb6c01eaSSvyatoslav Ryhel 		R61307_GAMMA_SET_A,
66*cb6c01eaSSvyatoslav Ryhel 		0x0b, 0x0d, 0x10, 0x14,
67*cb6c01eaSSvyatoslav Ryhel 		0x13, 0x1d, 0x20, 0x18,
68*cb6c01eaSSvyatoslav Ryhel 		0x12, 0x09, 0x07, 0x06,
69*cb6c01eaSSvyatoslav Ryhel 		0x0a, 0x0c, 0x10, 0x14,
70*cb6c01eaSSvyatoslav Ryhel 		0x13, 0x1d, 0x20, 0x18,
71*cb6c01eaSSvyatoslav Ryhel 		0x12, 0x09, 0x07, 0x06
72*cb6c01eaSSvyatoslav Ryhel 	},
73*cb6c01eaSSvyatoslav Ryhel };
74*cb6c01eaSSvyatoslav Ryhel 
75*cb6c01eaSSvyatoslav Ryhel static inline struct renesas_r61307 *to_renesas_r61307(struct drm_panel *panel)
76*cb6c01eaSSvyatoslav Ryhel {
77*cb6c01eaSSvyatoslav Ryhel 	return container_of(panel, struct renesas_r61307, panel);
78*cb6c01eaSSvyatoslav Ryhel }
79*cb6c01eaSSvyatoslav Ryhel 
80*cb6c01eaSSvyatoslav Ryhel static void renesas_r61307_reset(struct renesas_r61307 *priv)
81*cb6c01eaSSvyatoslav Ryhel {
82*cb6c01eaSSvyatoslav Ryhel 	gpiod_set_value_cansleep(priv->reset_gpio, 1);
83*cb6c01eaSSvyatoslav Ryhel 	usleep_range(10000, 11000);
84*cb6c01eaSSvyatoslav Ryhel 	gpiod_set_value_cansleep(priv->reset_gpio, 0);
85*cb6c01eaSSvyatoslav Ryhel 	usleep_range(2000, 3000);
86*cb6c01eaSSvyatoslav Ryhel }
87*cb6c01eaSSvyatoslav Ryhel 
88*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_prepare(struct drm_panel *panel)
89*cb6c01eaSSvyatoslav Ryhel {
90*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv = to_renesas_r61307(panel);
91*cb6c01eaSSvyatoslav Ryhel 	struct device *dev = &priv->dsi->dev;
92*cb6c01eaSSvyatoslav Ryhel 	int ret;
93*cb6c01eaSSvyatoslav Ryhel 
94*cb6c01eaSSvyatoslav Ryhel 	if (priv->prepared)
95*cb6c01eaSSvyatoslav Ryhel 		return 0;
96*cb6c01eaSSvyatoslav Ryhel 
97*cb6c01eaSSvyatoslav Ryhel 	ret = regulator_enable(priv->vcc_supply);
98*cb6c01eaSSvyatoslav Ryhel 	if (ret) {
99*cb6c01eaSSvyatoslav Ryhel 		dev_err(dev, "failed to enable vcc power supply\n");
100*cb6c01eaSSvyatoslav Ryhel 		return ret;
101*cb6c01eaSSvyatoslav Ryhel 	}
102*cb6c01eaSSvyatoslav Ryhel 
103*cb6c01eaSSvyatoslav Ryhel 	usleep_range(2000, 3000);
104*cb6c01eaSSvyatoslav Ryhel 
105*cb6c01eaSSvyatoslav Ryhel 	ret = regulator_enable(priv->iovcc_supply);
106*cb6c01eaSSvyatoslav Ryhel 	if (ret) {
107*cb6c01eaSSvyatoslav Ryhel 		dev_err(dev, "failed to enable iovcc power supply\n");
108*cb6c01eaSSvyatoslav Ryhel 		return ret;
109*cb6c01eaSSvyatoslav Ryhel 	}
110*cb6c01eaSSvyatoslav Ryhel 
111*cb6c01eaSSvyatoslav Ryhel 	usleep_range(2000, 3000);
112*cb6c01eaSSvyatoslav Ryhel 
113*cb6c01eaSSvyatoslav Ryhel 	renesas_r61307_reset(priv);
114*cb6c01eaSSvyatoslav Ryhel 
115*cb6c01eaSSvyatoslav Ryhel 	priv->prepared = true;
116*cb6c01eaSSvyatoslav Ryhel 	return 0;
117*cb6c01eaSSvyatoslav Ryhel }
118*cb6c01eaSSvyatoslav Ryhel 
119*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_enable(struct drm_panel *panel)
120*cb6c01eaSSvyatoslav Ryhel {
121*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv = to_renesas_r61307(panel);
122*cb6c01eaSSvyatoslav Ryhel 	struct mipi_dsi_multi_context ctx = { .dsi = priv->dsi };
123*cb6c01eaSSvyatoslav Ryhel 
124*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_exit_sleep_mode_multi(&ctx);
125*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_msleep(&ctx, 80);
126*cb6c01eaSSvyatoslav Ryhel 
127*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_write_seq_multi(&ctx, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
128*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_msleep(&ctx, 20);
129*cb6c01eaSSvyatoslav Ryhel 
130*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_set_pixel_format_multi(&ctx, MIPI_DCS_PIXEL_FMT_24BIT << 4);
131*cb6c01eaSSvyatoslav Ryhel 
132*cb6c01eaSSvyatoslav Ryhel 	/* MACP Off */
133*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_generic_write_seq_multi(&ctx, R61307_MACP, R61307_MACP_OFF);
134*cb6c01eaSSvyatoslav Ryhel 
135*cb6c01eaSSvyatoslav Ryhel 	if (priv->dig_cont_adj)
136*cb6c01eaSSvyatoslav Ryhel 		mipi_dsi_generic_write_seq_multi(&ctx, R61307_CONTRAST_SET,
137*cb6c01eaSSvyatoslav Ryhel 						 0xdc, 0xb4, 0xff);
138*cb6c01eaSSvyatoslav Ryhel 
139*cb6c01eaSSvyatoslav Ryhel 	if (priv->gamma)
140*cb6c01eaSSvyatoslav Ryhel 		mipi_dsi_generic_write_multi(&ctx, gamma_setting[priv->gamma],
141*cb6c01eaSSvyatoslav Ryhel 					     sizeof(gamma_setting[priv->gamma]));
142*cb6c01eaSSvyatoslav Ryhel 
143*cb6c01eaSSvyatoslav Ryhel 	if (priv->inversion)
144*cb6c01eaSSvyatoslav Ryhel 		mipi_dsi_generic_write_seq_multi(&ctx, R61307_INVERSION,
145*cb6c01eaSSvyatoslav Ryhel 						 0x00, 0x50, 0x03, 0x22,
146*cb6c01eaSSvyatoslav Ryhel 						 0x16, 0x06, 0x60, 0x11);
147*cb6c01eaSSvyatoslav Ryhel 	else
148*cb6c01eaSSvyatoslav Ryhel 		mipi_dsi_generic_write_seq_multi(&ctx, R61307_INVERSION,
149*cb6c01eaSSvyatoslav Ryhel 						 0x00, 0x10, 0x03, 0x22,
150*cb6c01eaSSvyatoslav Ryhel 						 0x16, 0x06, 0x60, 0x01);
151*cb6c01eaSSvyatoslav Ryhel 
152*cb6c01eaSSvyatoslav Ryhel 	/* MACP On */
153*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_generic_write_seq_multi(&ctx, R61307_MACP, R61307_MACP_ON);
154*cb6c01eaSSvyatoslav Ryhel 
155*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_set_display_on_multi(&ctx);
156*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_msleep(&ctx, 50);
157*cb6c01eaSSvyatoslav Ryhel 
158*cb6c01eaSSvyatoslav Ryhel 	return 0;
159*cb6c01eaSSvyatoslav Ryhel }
160*cb6c01eaSSvyatoslav Ryhel 
161*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_disable(struct drm_panel *panel)
162*cb6c01eaSSvyatoslav Ryhel {
163*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv = to_renesas_r61307(panel);
164*cb6c01eaSSvyatoslav Ryhel 	struct mipi_dsi_multi_context ctx = { .dsi = priv->dsi };
165*cb6c01eaSSvyatoslav Ryhel 
166*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_set_display_off_multi(&ctx);
167*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_msleep(&ctx, 100);
168*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_dcs_enter_sleep_mode_multi(&ctx);
169*cb6c01eaSSvyatoslav Ryhel 
170*cb6c01eaSSvyatoslav Ryhel 	return 0;
171*cb6c01eaSSvyatoslav Ryhel }
172*cb6c01eaSSvyatoslav Ryhel 
173*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_unprepare(struct drm_panel *panel)
174*cb6c01eaSSvyatoslav Ryhel {
175*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv = to_renesas_r61307(panel);
176*cb6c01eaSSvyatoslav Ryhel 
177*cb6c01eaSSvyatoslav Ryhel 	if (!priv->prepared)
178*cb6c01eaSSvyatoslav Ryhel 		return 0;
179*cb6c01eaSSvyatoslav Ryhel 
180*cb6c01eaSSvyatoslav Ryhel 	usleep_range(10000, 11000);
181*cb6c01eaSSvyatoslav Ryhel 
182*cb6c01eaSSvyatoslav Ryhel 	gpiod_set_value_cansleep(priv->reset_gpio, 1);
183*cb6c01eaSSvyatoslav Ryhel 	usleep_range(5000, 6000);
184*cb6c01eaSSvyatoslav Ryhel 
185*cb6c01eaSSvyatoslav Ryhel 	regulator_disable(priv->iovcc_supply);
186*cb6c01eaSSvyatoslav Ryhel 	usleep_range(2000, 3000);
187*cb6c01eaSSvyatoslav Ryhel 	regulator_disable(priv->vcc_supply);
188*cb6c01eaSSvyatoslav Ryhel 
189*cb6c01eaSSvyatoslav Ryhel 	priv->prepared = false;
190*cb6c01eaSSvyatoslav Ryhel 	return 0;
191*cb6c01eaSSvyatoslav Ryhel }
192*cb6c01eaSSvyatoslav Ryhel 
193*cb6c01eaSSvyatoslav Ryhel static const struct drm_display_mode renesas_r61307_mode = {
194*cb6c01eaSSvyatoslav Ryhel 	.clock = (768 + 116 + 81 + 5) * (1024 + 24 + 8 + 2) * 60 / 1000,
195*cb6c01eaSSvyatoslav Ryhel 	.hdisplay = 768,
196*cb6c01eaSSvyatoslav Ryhel 	.hsync_start = 768 + 116,
197*cb6c01eaSSvyatoslav Ryhel 	.hsync_end = 768 + 116 + 81,
198*cb6c01eaSSvyatoslav Ryhel 	.htotal = 768 + 116 + 81 + 5,
199*cb6c01eaSSvyatoslav Ryhel 	.vdisplay = 1024,
200*cb6c01eaSSvyatoslav Ryhel 	.vsync_start = 1024 + 24,
201*cb6c01eaSSvyatoslav Ryhel 	.vsync_end = 1024 + 24 + 8,
202*cb6c01eaSSvyatoslav Ryhel 	.vtotal = 1024 + 24 + 8 + 2,
203*cb6c01eaSSvyatoslav Ryhel 	.width_mm = 76,
204*cb6c01eaSSvyatoslav Ryhel 	.height_mm = 101,
205*cb6c01eaSSvyatoslav Ryhel };
206*cb6c01eaSSvyatoslav Ryhel 
207*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_get_modes(struct drm_panel *panel,
208*cb6c01eaSSvyatoslav Ryhel 				    struct drm_connector *connector)
209*cb6c01eaSSvyatoslav Ryhel {
210*cb6c01eaSSvyatoslav Ryhel 	struct drm_display_mode *mode;
211*cb6c01eaSSvyatoslav Ryhel 
212*cb6c01eaSSvyatoslav Ryhel 	mode = drm_mode_duplicate(connector->dev, &renesas_r61307_mode);
213*cb6c01eaSSvyatoslav Ryhel 	if (!mode)
214*cb6c01eaSSvyatoslav Ryhel 		return -ENOMEM;
215*cb6c01eaSSvyatoslav Ryhel 
216*cb6c01eaSSvyatoslav Ryhel 	drm_mode_set_name(mode);
217*cb6c01eaSSvyatoslav Ryhel 
218*cb6c01eaSSvyatoslav Ryhel 	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
219*cb6c01eaSSvyatoslav Ryhel 	connector->display_info.width_mm = mode->width_mm;
220*cb6c01eaSSvyatoslav Ryhel 	connector->display_info.height_mm = mode->height_mm;
221*cb6c01eaSSvyatoslav Ryhel 	drm_mode_probed_add(connector, mode);
222*cb6c01eaSSvyatoslav Ryhel 
223*cb6c01eaSSvyatoslav Ryhel 	return 1;
224*cb6c01eaSSvyatoslav Ryhel }
225*cb6c01eaSSvyatoslav Ryhel 
226*cb6c01eaSSvyatoslav Ryhel static const struct drm_panel_funcs renesas_r61307_panel_funcs = {
227*cb6c01eaSSvyatoslav Ryhel 	.prepare = renesas_r61307_prepare,
228*cb6c01eaSSvyatoslav Ryhel 	.enable = renesas_r61307_enable,
229*cb6c01eaSSvyatoslav Ryhel 	.disable = renesas_r61307_disable,
230*cb6c01eaSSvyatoslav Ryhel 	.unprepare = renesas_r61307_unprepare,
231*cb6c01eaSSvyatoslav Ryhel 	.get_modes = renesas_r61307_get_modes,
232*cb6c01eaSSvyatoslav Ryhel };
233*cb6c01eaSSvyatoslav Ryhel 
234*cb6c01eaSSvyatoslav Ryhel static int renesas_r61307_probe(struct mipi_dsi_device *dsi)
235*cb6c01eaSSvyatoslav Ryhel {
236*cb6c01eaSSvyatoslav Ryhel 	struct device *dev = &dsi->dev;
237*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv;
238*cb6c01eaSSvyatoslav Ryhel 	int ret;
239*cb6c01eaSSvyatoslav Ryhel 
240*cb6c01eaSSvyatoslav Ryhel 	priv = devm_drm_panel_alloc(dev, struct renesas_r61307, panel,
241*cb6c01eaSSvyatoslav Ryhel 				    &renesas_r61307_panel_funcs,
242*cb6c01eaSSvyatoslav Ryhel 				    DRM_MODE_CONNECTOR_DSI);
243*cb6c01eaSSvyatoslav Ryhel 	if (IS_ERR(priv))
244*cb6c01eaSSvyatoslav Ryhel 		return PTR_ERR(priv);
245*cb6c01eaSSvyatoslav Ryhel 
246*cb6c01eaSSvyatoslav Ryhel 	priv->vcc_supply = devm_regulator_get(dev, "vcc");
247*cb6c01eaSSvyatoslav Ryhel 	if (IS_ERR(priv->vcc_supply))
248*cb6c01eaSSvyatoslav Ryhel 		return dev_err_probe(dev, PTR_ERR(priv->vcc_supply),
249*cb6c01eaSSvyatoslav Ryhel 				     "Failed to get vcc-supply\n");
250*cb6c01eaSSvyatoslav Ryhel 
251*cb6c01eaSSvyatoslav Ryhel 	priv->iovcc_supply = devm_regulator_get(dev, "iovcc");
252*cb6c01eaSSvyatoslav Ryhel 	if (IS_ERR(priv->iovcc_supply))
253*cb6c01eaSSvyatoslav Ryhel 		return dev_err_probe(dev, PTR_ERR(priv->iovcc_supply),
254*cb6c01eaSSvyatoslav Ryhel 				     "Failed to get iovcc-supply\n");
255*cb6c01eaSSvyatoslav Ryhel 
256*cb6c01eaSSvyatoslav Ryhel 	priv->reset_gpio = devm_gpiod_get_optional(dev, "reset",
257*cb6c01eaSSvyatoslav Ryhel 						   GPIOD_OUT_HIGH);
258*cb6c01eaSSvyatoslav Ryhel 	if (IS_ERR(priv->reset_gpio))
259*cb6c01eaSSvyatoslav Ryhel 		return dev_err_probe(dev, PTR_ERR(priv->reset_gpio),
260*cb6c01eaSSvyatoslav Ryhel 				     "Failed to get reset gpios\n");
261*cb6c01eaSSvyatoslav Ryhel 
262*cb6c01eaSSvyatoslav Ryhel 	if (device_property_read_bool(dev, "renesas,inversion"))
263*cb6c01eaSSvyatoslav Ryhel 		priv->inversion = true;
264*cb6c01eaSSvyatoslav Ryhel 
265*cb6c01eaSSvyatoslav Ryhel 	if (device_property_read_bool(dev, "renesas,contrast"))
266*cb6c01eaSSvyatoslav Ryhel 		priv->dig_cont_adj = true;
267*cb6c01eaSSvyatoslav Ryhel 
268*cb6c01eaSSvyatoslav Ryhel 	priv->gamma = 0;
269*cb6c01eaSSvyatoslav Ryhel 	device_property_read_u32(dev, "renesas,gamma", &priv->gamma);
270*cb6c01eaSSvyatoslav Ryhel 
271*cb6c01eaSSvyatoslav Ryhel 	priv->dsi = dsi;
272*cb6c01eaSSvyatoslav Ryhel 	mipi_dsi_set_drvdata(dsi, priv);
273*cb6c01eaSSvyatoslav Ryhel 
274*cb6c01eaSSvyatoslav Ryhel 	dsi->lanes = 4;
275*cb6c01eaSSvyatoslav Ryhel 	dsi->format = MIPI_DSI_FMT_RGB888;
276*cb6c01eaSSvyatoslav Ryhel 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
277*cb6c01eaSSvyatoslav Ryhel 			  MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM;
278*cb6c01eaSSvyatoslav Ryhel 
279*cb6c01eaSSvyatoslav Ryhel 	ret = drm_panel_of_backlight(&priv->panel);
280*cb6c01eaSSvyatoslav Ryhel 	if (ret)
281*cb6c01eaSSvyatoslav Ryhel 		return dev_err_probe(dev, ret, "Failed to get backlight\n");
282*cb6c01eaSSvyatoslav Ryhel 
283*cb6c01eaSSvyatoslav Ryhel 	drm_panel_add(&priv->panel);
284*cb6c01eaSSvyatoslav Ryhel 
285*cb6c01eaSSvyatoslav Ryhel 	ret = mipi_dsi_attach(dsi);
286*cb6c01eaSSvyatoslav Ryhel 	if (ret) {
287*cb6c01eaSSvyatoslav Ryhel 		drm_panel_remove(&priv->panel);
288*cb6c01eaSSvyatoslav Ryhel 		return dev_err_probe(dev, ret, "Failed to attach to DSI host\n");
289*cb6c01eaSSvyatoslav Ryhel 	}
290*cb6c01eaSSvyatoslav Ryhel 
291*cb6c01eaSSvyatoslav Ryhel 	return 0;
292*cb6c01eaSSvyatoslav Ryhel }
293*cb6c01eaSSvyatoslav Ryhel 
294*cb6c01eaSSvyatoslav Ryhel static void renesas_r61307_remove(struct mipi_dsi_device *dsi)
295*cb6c01eaSSvyatoslav Ryhel {
296*cb6c01eaSSvyatoslav Ryhel 	struct renesas_r61307 *priv = mipi_dsi_get_drvdata(dsi);
297*cb6c01eaSSvyatoslav Ryhel 	int ret;
298*cb6c01eaSSvyatoslav Ryhel 
299*cb6c01eaSSvyatoslav Ryhel 	ret = mipi_dsi_detach(dsi);
300*cb6c01eaSSvyatoslav Ryhel 	if (ret)
301*cb6c01eaSSvyatoslav Ryhel 		dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
302*cb6c01eaSSvyatoslav Ryhel 
303*cb6c01eaSSvyatoslav Ryhel 	drm_panel_remove(&priv->panel);
304*cb6c01eaSSvyatoslav Ryhel }
305*cb6c01eaSSvyatoslav Ryhel 
306*cb6c01eaSSvyatoslav Ryhel static const struct of_device_id renesas_r61307_of_match[] = {
307*cb6c01eaSSvyatoslav Ryhel 	{ .compatible = "hit,tx13d100vm0eaa" },
308*cb6c01eaSSvyatoslav Ryhel 	{ .compatible = "koe,tx13d100vm0eaa" },
309*cb6c01eaSSvyatoslav Ryhel 	{ /* sentinel */ }
310*cb6c01eaSSvyatoslav Ryhel };
311*cb6c01eaSSvyatoslav Ryhel MODULE_DEVICE_TABLE(of, renesas_r61307_of_match);
312*cb6c01eaSSvyatoslav Ryhel 
313*cb6c01eaSSvyatoslav Ryhel static struct mipi_dsi_driver renesas_r61307_driver = {
314*cb6c01eaSSvyatoslav Ryhel 	.probe = renesas_r61307_probe,
315*cb6c01eaSSvyatoslav Ryhel 	.remove = renesas_r61307_remove,
316*cb6c01eaSSvyatoslav Ryhel 	.driver = {
317*cb6c01eaSSvyatoslav Ryhel 		.name = "panel-renesas-r61307",
318*cb6c01eaSSvyatoslav Ryhel 		.of_match_table = renesas_r61307_of_match,
319*cb6c01eaSSvyatoslav Ryhel 	},
320*cb6c01eaSSvyatoslav Ryhel };
321*cb6c01eaSSvyatoslav Ryhel module_mipi_dsi_driver(renesas_r61307_driver);
322*cb6c01eaSSvyatoslav Ryhel 
323*cb6c01eaSSvyatoslav Ryhel MODULE_AUTHOR("Svyatoslav Ryhel <clamor95@gmail.com>");
324*cb6c01eaSSvyatoslav Ryhel MODULE_DESCRIPTION("Renesas R61307-based panel driver");
325*cb6c01eaSSvyatoslav Ryhel MODULE_LICENSE("GPL");
326