xref: /openbmc/linux/drivers/gpu/drm/panel/panel-feiyang-fy07024di26a30d.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
169dc678aSJagan Teki // SPDX-License-Identifier: GPL-2.0+
269dc678aSJagan Teki /*
369dc678aSJagan Teki  * Copyright (C) 2018 Amarula Solutions
469dc678aSJagan Teki  * Author: Jagan Teki <jagan@amarulasolutions.com>
569dc678aSJagan Teki  */
669dc678aSJagan Teki 
769dc678aSJagan Teki #include <drm/drm_mipi_dsi.h>
869dc678aSJagan Teki #include <drm/drm_modes.h>
969dc678aSJagan Teki #include <drm/drm_panel.h>
1069dc678aSJagan Teki 
1169dc678aSJagan Teki #include <linux/gpio/consumer.h>
1269dc678aSJagan Teki #include <linux/delay.h>
1369dc678aSJagan Teki #include <linux/module.h>
14*722d4f06SRob Herring #include <linux/mod_devicetable.h>
1569dc678aSJagan Teki #include <linux/regulator/consumer.h>
1669dc678aSJagan Teki 
1769dc678aSJagan Teki #define FEIYANG_INIT_CMD_LEN	2
1869dc678aSJagan Teki 
1969dc678aSJagan Teki struct feiyang {
2069dc678aSJagan Teki 	struct drm_panel	panel;
2169dc678aSJagan Teki 	struct mipi_dsi_device	*dsi;
2269dc678aSJagan Teki 
2369dc678aSJagan Teki 	struct regulator	*dvdd;
2469dc678aSJagan Teki 	struct regulator	*avdd;
2569dc678aSJagan Teki 	struct gpio_desc	*reset;
2669dc678aSJagan Teki };
2769dc678aSJagan Teki 
panel_to_feiyang(struct drm_panel * panel)2869dc678aSJagan Teki static inline struct feiyang *panel_to_feiyang(struct drm_panel *panel)
2969dc678aSJagan Teki {
3069dc678aSJagan Teki 	return container_of(panel, struct feiyang, panel);
3169dc678aSJagan Teki }
3269dc678aSJagan Teki 
3369dc678aSJagan Teki struct feiyang_init_cmd {
3469dc678aSJagan Teki 	u8 data[FEIYANG_INIT_CMD_LEN];
3569dc678aSJagan Teki };
3669dc678aSJagan Teki 
3769dc678aSJagan Teki static const struct feiyang_init_cmd feiyang_init_cmds[] = {
3869dc678aSJagan Teki 	{ .data = { 0x80, 0x58 } },
3969dc678aSJagan Teki 	{ .data = { 0x81, 0x47 } },
4069dc678aSJagan Teki 	{ .data = { 0x82, 0xD4 } },
4169dc678aSJagan Teki 	{ .data = { 0x83, 0x88 } },
4269dc678aSJagan Teki 	{ .data = { 0x84, 0xA9 } },
4369dc678aSJagan Teki 	{ .data = { 0x85, 0xC3 } },
4469dc678aSJagan Teki 	{ .data = { 0x86, 0x82 } },
4569dc678aSJagan Teki };
4669dc678aSJagan Teki 
feiyang_prepare(struct drm_panel * panel)4769dc678aSJagan Teki static int feiyang_prepare(struct drm_panel *panel)
4869dc678aSJagan Teki {
4969dc678aSJagan Teki 	struct feiyang *ctx = panel_to_feiyang(panel);
5069dc678aSJagan Teki 	struct mipi_dsi_device *dsi = ctx->dsi;
5169dc678aSJagan Teki 	unsigned int i;
5269dc678aSJagan Teki 	int ret;
5369dc678aSJagan Teki 
5469dc678aSJagan Teki 	ret = regulator_enable(ctx->dvdd);
5569dc678aSJagan Teki 	if (ret)
5669dc678aSJagan Teki 		return ret;
5769dc678aSJagan Teki 
5869dc678aSJagan Teki 	/* T1 (dvdd start + dvdd rise) 0 < T1 <= 10ms */
5969dc678aSJagan Teki 	msleep(10);
6069dc678aSJagan Teki 
6169dc678aSJagan Teki 	ret = regulator_enable(ctx->avdd);
6269dc678aSJagan Teki 	if (ret)
6369dc678aSJagan Teki 		return ret;
6469dc678aSJagan Teki 
6569dc678aSJagan Teki 	/* T3 (dvdd rise + avdd start + avdd rise) T3 >= 20ms */
6669dc678aSJagan Teki 	msleep(20);
6769dc678aSJagan Teki 
6869dc678aSJagan Teki 	gpiod_set_value(ctx->reset, 0);
6969dc678aSJagan Teki 
7069dc678aSJagan Teki 	/*
7169dc678aSJagan Teki 	 * T5 + T6 (avdd rise + video & logic signal rise)
7269dc678aSJagan Teki 	 * T5 >= 10ms, 0 < T6 <= 10ms
7369dc678aSJagan Teki 	 */
7469dc678aSJagan Teki 	msleep(20);
7569dc678aSJagan Teki 
7669dc678aSJagan Teki 	gpiod_set_value(ctx->reset, 1);
7769dc678aSJagan Teki 
7869dc678aSJagan Teki 	/* T12 (video & logic signal rise + backlight rise) T12 >= 200ms */
7969dc678aSJagan Teki 	msleep(200);
8069dc678aSJagan Teki 
8169dc678aSJagan Teki 	for (i = 0; i < ARRAY_SIZE(feiyang_init_cmds); i++) {
8269dc678aSJagan Teki 		const struct feiyang_init_cmd *cmd =
8369dc678aSJagan Teki 						&feiyang_init_cmds[i];
8469dc678aSJagan Teki 
8569dc678aSJagan Teki 		ret = mipi_dsi_dcs_write_buffer(dsi, cmd->data,
8669dc678aSJagan Teki 						FEIYANG_INIT_CMD_LEN);
8769dc678aSJagan Teki 		if (ret < 0)
8869dc678aSJagan Teki 			return ret;
8969dc678aSJagan Teki 	}
9069dc678aSJagan Teki 
9169dc678aSJagan Teki 	return 0;
9269dc678aSJagan Teki }
9369dc678aSJagan Teki 
feiyang_enable(struct drm_panel * panel)9469dc678aSJagan Teki static int feiyang_enable(struct drm_panel *panel)
9569dc678aSJagan Teki {
9669dc678aSJagan Teki 	struct feiyang *ctx = panel_to_feiyang(panel);
9769dc678aSJagan Teki 
9869dc678aSJagan Teki 	/* T12 (video & logic signal rise + backlight rise) T12 >= 200ms */
9969dc678aSJagan Teki 	msleep(200);
10069dc678aSJagan Teki 
10169dc678aSJagan Teki 	mipi_dsi_dcs_set_display_on(ctx->dsi);
10269dc678aSJagan Teki 
10369dc678aSJagan Teki 	return 0;
10469dc678aSJagan Teki }
10569dc678aSJagan Teki 
feiyang_disable(struct drm_panel * panel)10669dc678aSJagan Teki static int feiyang_disable(struct drm_panel *panel)
10769dc678aSJagan Teki {
10869dc678aSJagan Teki 	struct feiyang *ctx = panel_to_feiyang(panel);
10969dc678aSJagan Teki 
11069dc678aSJagan Teki 	return mipi_dsi_dcs_set_display_off(ctx->dsi);
11169dc678aSJagan Teki }
11269dc678aSJagan Teki 
feiyang_unprepare(struct drm_panel * panel)11369dc678aSJagan Teki static int feiyang_unprepare(struct drm_panel *panel)
11469dc678aSJagan Teki {
11569dc678aSJagan Teki 	struct feiyang *ctx = panel_to_feiyang(panel);
11669dc678aSJagan Teki 	int ret;
11769dc678aSJagan Teki 
11869dc678aSJagan Teki 	ret = mipi_dsi_dcs_set_display_off(ctx->dsi);
11969dc678aSJagan Teki 	if (ret < 0)
120a25b6b27SSam Ravnborg 		dev_err(panel->dev, "failed to set display off: %d\n", ret);
12169dc678aSJagan Teki 
12269dc678aSJagan Teki 	ret = mipi_dsi_dcs_enter_sleep_mode(ctx->dsi);
12369dc678aSJagan Teki 	if (ret < 0)
124a25b6b27SSam Ravnborg 		dev_err(panel->dev, "failed to enter sleep mode: %d\n", ret);
12569dc678aSJagan Teki 
12669dc678aSJagan Teki 	/* T13 (backlight fall + video & logic signal fall) T13 >= 200ms */
12769dc678aSJagan Teki 	msleep(200);
12869dc678aSJagan Teki 
12969dc678aSJagan Teki 	gpiod_set_value(ctx->reset, 0);
13069dc678aSJagan Teki 
13169dc678aSJagan Teki 	regulator_disable(ctx->avdd);
13269dc678aSJagan Teki 
13369dc678aSJagan Teki 	/* T11 (dvdd rise to fall) 0 < T11 <= 10ms  */
13469dc678aSJagan Teki 	msleep(10);
13569dc678aSJagan Teki 
13669dc678aSJagan Teki 	regulator_disable(ctx->dvdd);
13769dc678aSJagan Teki 
13869dc678aSJagan Teki 	return 0;
13969dc678aSJagan Teki }
14069dc678aSJagan Teki 
14169dc678aSJagan Teki static const struct drm_display_mode feiyang_default_mode = {
14269dc678aSJagan Teki 	.clock		= 55000,
14369dc678aSJagan Teki 
14469dc678aSJagan Teki 	.hdisplay	= 1024,
14569dc678aSJagan Teki 	.hsync_start	= 1024 + 310,
14669dc678aSJagan Teki 	.hsync_end	= 1024 + 310 + 20,
14769dc678aSJagan Teki 	.htotal		= 1024 + 310 + 20 + 90,
14869dc678aSJagan Teki 
14969dc678aSJagan Teki 	.vdisplay	= 600,
15069dc678aSJagan Teki 	.vsync_start	= 600 + 12,
15169dc678aSJagan Teki 	.vsync_end	= 600 + 12 + 2,
15269dc678aSJagan Teki 	.vtotal		= 600 + 12 + 2 + 21,
15369dc678aSJagan Teki 
15469dc678aSJagan Teki 	.type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
15569dc678aSJagan Teki };
15669dc678aSJagan Teki 
feiyang_get_modes(struct drm_panel * panel,struct drm_connector * connector)1570ce8ddd8SSam Ravnborg static int feiyang_get_modes(struct drm_panel *panel,
1580ce8ddd8SSam Ravnborg 			     struct drm_connector *connector)
15969dc678aSJagan Teki {
16069dc678aSJagan Teki 	struct feiyang *ctx = panel_to_feiyang(panel);
16169dc678aSJagan Teki 	struct drm_display_mode *mode;
16269dc678aSJagan Teki 
163aa6c4364SSam Ravnborg 	mode = drm_mode_duplicate(connector->dev, &feiyang_default_mode);
16469dc678aSJagan Teki 	if (!mode) {
165a25b6b27SSam Ravnborg 		dev_err(&ctx->dsi->dev, "failed to add mode %ux%u@%u\n",
16669dc678aSJagan Teki 			feiyang_default_mode.hdisplay,
16769dc678aSJagan Teki 			feiyang_default_mode.vdisplay,
1680425662fSVille Syrjälä 			drm_mode_vrefresh(&feiyang_default_mode));
16969dc678aSJagan Teki 		return -ENOMEM;
17069dc678aSJagan Teki 	}
17169dc678aSJagan Teki 
17269dc678aSJagan Teki 	drm_mode_set_name(mode);
17369dc678aSJagan Teki 
17469dc678aSJagan Teki 	drm_mode_probed_add(connector, mode);
17569dc678aSJagan Teki 
17669dc678aSJagan Teki 	return 1;
17769dc678aSJagan Teki }
17869dc678aSJagan Teki 
17969dc678aSJagan Teki static const struct drm_panel_funcs feiyang_funcs = {
18069dc678aSJagan Teki 	.disable = feiyang_disable,
18169dc678aSJagan Teki 	.unprepare = feiyang_unprepare,
18269dc678aSJagan Teki 	.prepare = feiyang_prepare,
18369dc678aSJagan Teki 	.enable = feiyang_enable,
18469dc678aSJagan Teki 	.get_modes = feiyang_get_modes,
18569dc678aSJagan Teki };
18669dc678aSJagan Teki 
feiyang_dsi_probe(struct mipi_dsi_device * dsi)18769dc678aSJagan Teki static int feiyang_dsi_probe(struct mipi_dsi_device *dsi)
18869dc678aSJagan Teki {
18969dc678aSJagan Teki 	struct feiyang *ctx;
19069dc678aSJagan Teki 	int ret;
19169dc678aSJagan Teki 
19269dc678aSJagan Teki 	ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
19369dc678aSJagan Teki 	if (!ctx)
19469dc678aSJagan Teki 		return -ENOMEM;
19569dc678aSJagan Teki 
19669dc678aSJagan Teki 	mipi_dsi_set_drvdata(dsi, ctx);
19769dc678aSJagan Teki 	ctx->dsi = dsi;
19869dc678aSJagan Teki 
1999a2654c0SLaurent Pinchart 	drm_panel_init(&ctx->panel, &dsi->dev, &feiyang_funcs,
2009a2654c0SLaurent Pinchart 		       DRM_MODE_CONNECTOR_DSI);
20169dc678aSJagan Teki 
20269dc678aSJagan Teki 	ctx->dvdd = devm_regulator_get(&dsi->dev, "dvdd");
2035ddc1e27SCai Huoqing 	if (IS_ERR(ctx->dvdd))
2045ddc1e27SCai Huoqing 		return dev_err_probe(&dsi->dev, PTR_ERR(ctx->dvdd),
2055ddc1e27SCai Huoqing 				     "Couldn't get dvdd regulator\n");
20669dc678aSJagan Teki 
20769dc678aSJagan Teki 	ctx->avdd = devm_regulator_get(&dsi->dev, "avdd");
2085ddc1e27SCai Huoqing 	if (IS_ERR(ctx->avdd))
2095ddc1e27SCai Huoqing 		return dev_err_probe(&dsi->dev, PTR_ERR(ctx->avdd),
2105ddc1e27SCai Huoqing 				     "Couldn't get avdd regulator\n");
21169dc678aSJagan Teki 
212de5db71eSPeter Geis 	ctx->reset = devm_gpiod_get_optional(&dsi->dev, "reset", GPIOD_OUT_LOW);
2135ddc1e27SCai Huoqing 	if (IS_ERR(ctx->reset))
2145ddc1e27SCai Huoqing 		return dev_err_probe(&dsi->dev, PTR_ERR(ctx->reset),
2155ddc1e27SCai Huoqing 				     "Couldn't get our reset GPIO\n");
21669dc678aSJagan Teki 
217e3e4944fSSam Ravnborg 	ret = drm_panel_of_backlight(&ctx->panel);
218e3e4944fSSam Ravnborg 	if (ret)
219e3e4944fSSam Ravnborg 		return ret;
22069dc678aSJagan Teki 
221c3ee8c65SBernard Zhao 	drm_panel_add(&ctx->panel);
22269dc678aSJagan Teki 
22369dc678aSJagan Teki 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO_BURST;
22469dc678aSJagan Teki 	dsi->format = MIPI_DSI_FMT_RGB888;
22569dc678aSJagan Teki 	dsi->lanes = 4;
22669dc678aSJagan Teki 
2279bf7123bSBrian Norris 	ret = mipi_dsi_attach(dsi);
2289bf7123bSBrian Norris 	if (ret < 0) {
2299bf7123bSBrian Norris 		drm_panel_remove(&ctx->panel);
2309bf7123bSBrian Norris 		return ret;
2319bf7123bSBrian Norris 	}
2329bf7123bSBrian Norris 
2339bf7123bSBrian Norris 	return 0;
23469dc678aSJagan Teki }
23569dc678aSJagan Teki 
feiyang_dsi_remove(struct mipi_dsi_device * dsi)23679abca2bSUwe Kleine-König static void feiyang_dsi_remove(struct mipi_dsi_device *dsi)
23769dc678aSJagan Teki {
23869dc678aSJagan Teki 	struct feiyang *ctx = mipi_dsi_get_drvdata(dsi);
23969dc678aSJagan Teki 
24069dc678aSJagan Teki 	mipi_dsi_detach(dsi);
24169dc678aSJagan Teki 	drm_panel_remove(&ctx->panel);
24269dc678aSJagan Teki }
24369dc678aSJagan Teki 
24469dc678aSJagan Teki static const struct of_device_id feiyang_of_match[] = {
24569dc678aSJagan Teki 	{ .compatible = "feiyang,fy07024di26a30d", },
24669dc678aSJagan Teki 	{ /* sentinel */ }
24769dc678aSJagan Teki };
24869dc678aSJagan Teki MODULE_DEVICE_TABLE(of, feiyang_of_match);
24969dc678aSJagan Teki 
25069dc678aSJagan Teki static struct mipi_dsi_driver feiyang_driver = {
25169dc678aSJagan Teki 	.probe = feiyang_dsi_probe,
25269dc678aSJagan Teki 	.remove = feiyang_dsi_remove,
25369dc678aSJagan Teki 	.driver = {
25469dc678aSJagan Teki 		.name = "feiyang-fy07024di26a30d",
25569dc678aSJagan Teki 		.of_match_table = feiyang_of_match,
25669dc678aSJagan Teki 	},
25769dc678aSJagan Teki };
25869dc678aSJagan Teki module_mipi_dsi_driver(feiyang_driver);
25969dc678aSJagan Teki 
26069dc678aSJagan Teki MODULE_AUTHOR("Jagan Teki <jagan@amarulasolutions.com>");
26169dc678aSJagan Teki MODULE_DESCRIPTION("Feiyang FY07024DI26A30-D MIPI-DSI LCD panel");
26269dc678aSJagan Teki MODULE_LICENSE("GPL");
263