File Index
Files and directories
Sign in
FILE

panel-sony-td4353-jdi.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/panel/panel-sony-td4353-jdi.c C
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (c) 2022 Konrad Dybcio <konrad.dybcio@somainline.org>
  4 *
  5 * Generated with linux-mdss-dsi-panel-driver-generator with a
  6 * substantial amount of manual adjustments.
  7 *
  8 * SONY Downstream kernel calls this one:
  9 * - "JDI ID3" for Akari  (XZ2)
 10 * - "JDI ID4" for Apollo (XZ2 Compact)
 11 */
 12
 13#include <linux/delay.h>
 14#include <linux/gpio/consumer.h>
 15#include <linux/module.h>
 16#include <linux/of.h>
 17#include <linux/regulator/consumer.h>
 18
 19#include <video/mipi_display.h>
 20
 21#include <drm/drm_mipi_dsi.h>
 22#include <drm/drm_modes.h>
 23#include <drm/drm_panel.h>
 24
 25enum {
 26	TYPE_TAMA_60HZ,
 27	/*
 28	 * Leaving room for expansion - SONY very often uses
 29	 * *truly reliably* overclockable panels on their flagships!
 30	 */
 31};
 32
 33struct sony_td4353_jdi {
 34	struct drm_panel panel;
 35	struct mipi_dsi_device *dsi;
 36	struct regulator_bulk_data supplies[3];
 37	struct gpio_desc *panel_reset_gpio;
 38	struct gpio_desc *touch_reset_gpio;
 39	int type;
 40};
 41
 42static inline struct sony_td4353_jdi *to_sony_td4353_jdi(struct drm_panel *panel)
 43{
 44	return container_of(panel, struct sony_td4353_jdi, panel);
 45}
 46
 47static int sony_td4353_jdi_on(struct sony_td4353_jdi *ctx)
 48{
 49	struct mipi_dsi_device *dsi = ctx->dsi;
 50	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 51
 52	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
 53
 54	mipi_dsi_dcs_set_column_address_multi(&dsi_ctx, 0x0000, 1080 - 1);
 55	mipi_dsi_dcs_set_page_address_multi(&dsi_ctx, 0x0000, 2160 - 1);
 56	mipi_dsi_dcs_set_tear_scanline_multi(&dsi_ctx, 0);
 57	mipi_dsi_dcs_set_tear_on_multi(&dsi_ctx, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
 58	mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_SET_ADDRESS_MODE, 0x00);
 59
 60	mipi_dsi_dcs_set_pixel_format_multi(&dsi_ctx, 0x77);
 61	mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_SET_PARTIAL_ROWS,
 62				     0x00, 0x00, 0x08, 0x6f);
 63
 64	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
 65	mipi_dsi_msleep(&dsi_ctx, 70);
 66	mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_WRITE_MEMORY_START);
 67	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
 68
 69	return dsi_ctx.accum_err;
 70}
 71
 72static void sony_td4353_jdi_off(struct sony_td4353_jdi *ctx)
 73{
 74	struct mipi_dsi_device *dsi = ctx->dsi;
 75	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 76
 77	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
 78
 79	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
 80	mipi_dsi_msleep(&dsi_ctx, 22);
 81	mipi_dsi_dcs_set_tear_off_multi(&dsi_ctx);
 82	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
 83	mipi_dsi_msleep(&dsi_ctx, 80);
 84}
 85
 86static void sony_td4353_assert_reset_gpios(struct sony_td4353_jdi *ctx, int mode)
 87{
 88	gpiod_set_value_cansleep(ctx->touch_reset_gpio, mode);
 89	gpiod_set_value_cansleep(ctx->panel_reset_gpio, mode);
 90	usleep_range(5000, 5100);
 91}
 92
 93static int sony_td4353_jdi_prepare(struct drm_panel *panel)
 94{
 95	struct sony_td4353_jdi *ctx = to_sony_td4353_jdi(panel);
 96	int ret;
 97
 98	ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
 99	if (ret < 0)
100		return ret;
101
102	msleep(100);
103
104	sony_td4353_assert_reset_gpios(ctx, 1);
105
106	ret = sony_td4353_jdi_on(ctx);
107	if (ret < 0) {
108		sony_td4353_assert_reset_gpios(ctx, 0);
109		regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
110		return ret;
111	}
112
113	return 0;
114}
115
116static int sony_td4353_jdi_unprepare(struct drm_panel *panel)
117{
118	struct sony_td4353_jdi *ctx = to_sony_td4353_jdi(panel);
119
120	sony_td4353_jdi_off(ctx);
121
122	sony_td4353_assert_reset_gpios(ctx, 0);
123	regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
124
125	return 0;
126}
127
128static const struct drm_display_mode sony_td4353_jdi_mode_tama_60hz = {
129	.clock = (1080 + 4 + 8 + 8) * (2160 + 259 + 8 + 8) * 60 / 1000,
130	.hdisplay = 1080,
131	.hsync_start = 1080 + 4,
132	.hsync_end = 1080 + 4 + 8,
133	.htotal = 1080 + 4 + 8 + 8,
134	.vdisplay = 2160,
135	.vsync_start = 2160 + 259,
136	.vsync_end = 2160 + 259 + 8,
137	.vtotal = 2160 + 259 + 8 + 8,
138	.width_mm = 64,
139	.height_mm = 128,
140};
141
142static int sony_td4353_jdi_get_modes(struct drm_panel *panel,
143				   struct drm_connector *connector)
144{
145	struct sony_td4353_jdi *ctx = to_sony_td4353_jdi(panel);
146	struct drm_display_mode *mode = NULL;
147
148	if (ctx->type == TYPE_TAMA_60HZ)
149		mode = drm_mode_duplicate(connector->dev, &sony_td4353_jdi_mode_tama_60hz);
150	else
151		return -EINVAL;
152
153	if (!mode)
154		return -ENOMEM;
155
156	drm_mode_set_name(mode);
157
158	mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
159	connector->display_info.width_mm = mode->width_mm;
160	connector->display_info.height_mm = mode->height_mm;
161	drm_mode_probed_add(connector, mode);
162
163	return 1;
164}
165
166static const struct drm_panel_funcs sony_td4353_jdi_panel_funcs = {
167	.prepare = sony_td4353_jdi_prepare,
168	.unprepare = sony_td4353_jdi_unprepare,
169	.get_modes = sony_td4353_jdi_get_modes,
170};
171
172static int sony_td4353_jdi_probe(struct mipi_dsi_device *dsi)
173{
174	struct device *dev = &dsi->dev;
175	struct sony_td4353_jdi *ctx;
176	int ret;
177
178	ctx = devm_drm_panel_alloc(dev, struct sony_td4353_jdi, panel,
179				   &sony_td4353_jdi_panel_funcs,
180				   DRM_MODE_CONNECTOR_DSI);
181	if (IS_ERR(ctx))
182		return PTR_ERR(ctx);
183
184	ctx->type = (uintptr_t)of_device_get_match_data(dev);
185
186	ctx->supplies[0].supply = "vddio";
187	ctx->supplies[1].supply = "vsp";
188	ctx->supplies[2].supply = "vsn";
189	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
190				      ctx->supplies);
191	if (ret < 0)
192		return dev_err_probe(dev, ret, "Failed to get regulators\n");
193
194	ctx->panel_reset_gpio = devm_gpiod_get(dev, "panel-reset", GPIOD_ASIS);
195	if (IS_ERR(ctx->panel_reset_gpio))
196		return dev_err_probe(dev, PTR_ERR(ctx->panel_reset_gpio),
197				     "Failed to get panel-reset-gpios\n");
198
199	ctx->touch_reset_gpio = devm_gpiod_get(dev, "touch-reset", GPIOD_ASIS);
200	if (IS_ERR(ctx->touch_reset_gpio))
201		return dev_err_probe(dev, PTR_ERR(ctx->touch_reset_gpio),
202				     "Failed to get touch-reset-gpios\n");
203
204	ctx->dsi = dsi;
205	mipi_dsi_set_drvdata(dsi, ctx);
206
207	dsi->lanes = 4;
208	dsi->format = MIPI_DSI_FMT_RGB888;
209	dsi->mode_flags = MIPI_DSI_CLOCK_NON_CONTINUOUS;
210
211	ret = drm_panel_of_backlight(&ctx->panel);
212	if (ret)
213		return dev_err_probe(dev, ret, "Failed to get backlight\n");
214
215	ctx->panel.prepare_prev_first = true;
216
217	drm_panel_add(&ctx->panel);
218
219	ret = mipi_dsi_attach(dsi);
220	if (ret < 0) {
221		dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
222		drm_panel_remove(&ctx->panel);
223		return ret;
224	}
225
226	return 0;
227}
228
229static void sony_td4353_jdi_remove(struct mipi_dsi_device *dsi)
230{
231	struct sony_td4353_jdi *ctx = mipi_dsi_get_drvdata(dsi);
232	int ret;
233
234	ret = mipi_dsi_detach(dsi);
235	if (ret < 0)
236		dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
237
238	drm_panel_remove(&ctx->panel);
239}
240
241static const struct of_device_id sony_td4353_jdi_of_match[] = {
242	{ .compatible = "sony,td4353-jdi-tama", .data = (void *)TYPE_TAMA_60HZ },
243	{ /* sentinel */ }
244};
245MODULE_DEVICE_TABLE(of, sony_td4353_jdi_of_match);
246
247static struct mipi_dsi_driver sony_td4353_jdi_driver = {
248	.probe = sony_td4353_jdi_probe,
249	.remove = sony_td4353_jdi_remove,
250	.driver = {
251		.name = "panel-sony-td4353-jdi",
252		.of_match_table = sony_td4353_jdi_of_match,
253	},
254};
255module_mipi_dsi_driver(sony_td4353_jdi_driver);
256
257MODULE_AUTHOR("Konrad Dybcio <konrad.dybcio@somainline.org>");
258MODULE_DESCRIPTION("DRM panel driver for SONY Xperia XZ2/XZ2c JDI panel");
259MODULE_LICENSE("GPL");
~/ Read-only file preview.