1 // SPDX-License-Identifier: GPL-2.0+
3 * MIPI-DSI Sony ACX424AKP panel driver. This is a 480x864
4 * AMOLED panel with a command-only DSI interface.
6 * Copyright (C) Linaro Ltd. 2019
7 * Author: Linus Walleij
8 * Based on code and know-how from Marcus Lorentzon
9 * Copyright (C) ST-Ericsson SA 2010
11 #include <linux/backlight.h>
12 #include <linux/delay.h>
13 #include <linux/gpio/consumer.h>
14 #include <linux/module.h>
16 #include <linux/regulator/consumer.h>
18 #include <video/mipi_display.h>
20 #include <drm/drm_mipi_dsi.h>
21 #include <drm/drm_modes.h>
22 #include <drm/drm_panel.h>
24 #define ACX424_DCS_READ_ID1 0xDA
25 #define ACX424_DCS_READ_ID2 0xDB
26 #define ACX424_DCS_READ_ID3 0xDC
27 #define ACX424_DCS_SET_MDDI 0xAE
30 * Sony seems to use vendor ID 0x81
32 #define DISPLAY_SONY_ACX424AKP_ID1 0x811b
33 #define DISPLAY_SONY_ACX424AKP_ID2 0x811a
35 * The third ID looks like a bug, vendor IDs begin at 0x80
36 * and panel 00 ... seems like default values.
38 #define DISPLAY_SONY_ACX424AKP_ID3 0x8000
41 struct drm_panel panel
;
43 struct backlight_device
*bl
;
44 struct regulator
*supply
;
45 struct gpio_desc
*reset_gpio
;
49 static const struct drm_display_mode sony_acx424akp_vid_mode
= {
52 .hsync_start
= 480 + 15,
53 .hsync_end
= 480 + 15 + 0,
54 .htotal
= 480 + 15 + 0 + 15,
56 .vsync_start
= 864 + 14,
57 .vsync_end
= 864 + 14 + 1,
58 .vtotal
= 864 + 14 + 1 + 11,
61 .flags
= DRM_MODE_FLAG_PVSYNC
,
65 * The timings are not very helpful as the display is used in
66 * command mode using the maximum HS frequency.
68 static const struct drm_display_mode sony_acx424akp_cmd_mode
= {
71 .hsync_start
= 480 + 154,
72 .hsync_end
= 480 + 154 + 16,
73 .htotal
= 480 + 154 + 16 + 32,
75 .vsync_start
= 864 + 1,
76 .vsync_end
= 864 + 1 + 1,
77 .vtotal
= 864 + 1 + 1 + 1,
79 * Some desired refresh rate, experiments at the maximum "pixel"
80 * clock speed (HS clock 420 MHz) yields around 117Hz.
86 static inline struct acx424akp
*panel_to_acx424akp(struct drm_panel
*panel
)
88 return container_of(panel
, struct acx424akp
, panel
);
91 #define FOSC 20 /* 20Mhz */
92 #define SCALE_FACTOR_NS_DIV_MHZ 1000
94 static int acx424akp_set_brightness(struct backlight_device
*bl
)
96 struct acx424akp
*acx
= bl_get_data(bl
);
97 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(acx
->dev
);
99 int duty_ns
= bl
->props
.brightness
;
105 /* Calculate the PWM duty cycle in n/256's */
106 pwm_ratio
= max(((duty_ns
* 256) / period_ns
) - 1, 1);
108 ((FOSC
* period_ns
) / 256) /
109 SCALE_FACTOR_NS_DIV_MHZ
);
111 /* Set up PWM dutycycle ONE byte (differs from the standard) */
112 dev_dbg(acx
->dev
, "calculated duty cycle %02x\n", pwm_ratio
);
113 ret
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_SET_DISPLAY_BRIGHTNESS
,
116 dev_err(acx
->dev
, "failed to set display PWM ratio (%d)\n", ret
);
121 * Sequence to write PWMDIV:
123 * 0xF3 0xAA CMD2 Unlock
124 * 0x00 0x01 Enter CMD2 page 0
125 * 0X7D 0x01 No reload MTP of CMD2 P1
127 * 0x7F 0xAA CMD2 page 1 lock
130 ret
= mipi_dsi_dcs_write(dsi
, 0xf3, &par
, 1);
132 dev_err(acx
->dev
, "failed to unlock CMD 2 (%d)\n", ret
);
136 ret
= mipi_dsi_dcs_write(dsi
, 0x00, &par
, 1);
138 dev_err(acx
->dev
, "failed to enter page 1 (%d)\n", ret
);
142 ret
= mipi_dsi_dcs_write(dsi
, 0x7d, &par
, 1);
144 dev_err(acx
->dev
, "failed to disable MTP reload (%d)\n", ret
);
147 ret
= mipi_dsi_dcs_write(dsi
, 0x22, &pwm_div
, 1);
149 dev_err(acx
->dev
, "failed to set PWM divisor (%d)\n", ret
);
153 ret
= mipi_dsi_dcs_write(dsi
, 0x7f, &par
, 1);
155 dev_err(acx
->dev
, "failed to lock CMD 2 (%d)\n", ret
);
159 /* Enable backlight */
161 ret
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_WRITE_CONTROL_DISPLAY
,
164 dev_err(acx
->dev
, "failed to enable display backlight (%d)\n", ret
);
171 static const struct backlight_ops acx424akp_bl_ops
= {
172 .update_status
= acx424akp_set_brightness
,
175 static int acx424akp_read_id(struct acx424akp
*acx
)
177 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(acx
->dev
);
178 u8 vendor
, version
, panel
;
182 ret
= mipi_dsi_dcs_read(dsi
, ACX424_DCS_READ_ID1
, &vendor
, 1);
184 dev_err(acx
->dev
, "could not vendor ID byte\n");
187 ret
= mipi_dsi_dcs_read(dsi
, ACX424_DCS_READ_ID2
, &version
, 1);
189 dev_err(acx
->dev
, "could not read device version byte\n");
192 ret
= mipi_dsi_dcs_read(dsi
, ACX424_DCS_READ_ID3
, &panel
, 1);
194 dev_err(acx
->dev
, "could not read panel ID byte\n");
198 if (vendor
== 0x00) {
199 dev_err(acx
->dev
, "device vendor ID is zero\n");
203 val
= (vendor
<< 8) | panel
;
205 case DISPLAY_SONY_ACX424AKP_ID1
:
206 case DISPLAY_SONY_ACX424AKP_ID2
:
207 case DISPLAY_SONY_ACX424AKP_ID3
:
208 dev_info(acx
->dev
, "MTP vendor: %02x, version: %02x, panel: %02x\n",
209 vendor
, version
, panel
);
212 dev_info(acx
->dev
, "unknown vendor: %02x, version: %02x, panel: %02x\n",
213 vendor
, version
, panel
);
220 static int acx424akp_power_on(struct acx424akp
*acx
)
224 ret
= regulator_enable(acx
->supply
);
226 dev_err(acx
->dev
, "failed to enable supply (%d)\n", ret
);
231 gpiod_set_value_cansleep(acx
->reset_gpio
, 1);
233 /* De-assert RESET */
234 gpiod_set_value_cansleep(acx
->reset_gpio
, 0);
235 usleep_range(11000, 20000);
240 static void acx424akp_power_off(struct acx424akp
*acx
)
243 gpiod_set_value_cansleep(acx
->reset_gpio
, 1);
244 usleep_range(11000, 20000);
246 regulator_disable(acx
->supply
);
249 static int acx424akp_prepare(struct drm_panel
*panel
)
251 struct acx424akp
*acx
= panel_to_acx424akp(panel
);
252 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(acx
->dev
);
256 ret
= acx424akp_power_on(acx
);
260 ret
= acx424akp_read_id(acx
);
262 dev_err(acx
->dev
, "failed to read panel ID (%d)\n", ret
);
266 /* Enabe tearing mode: send TE (tearing effect) at VBLANK */
267 ret
= mipi_dsi_dcs_set_tear_on(dsi
,
268 MIPI_DSI_DCS_TEAR_MODE_VBLANK
);
270 dev_err(acx
->dev
, "failed to enable vblank TE (%d)\n", ret
);
277 * This presumably deactivates the Qualcomm MDDI interface and
278 * selects DSI, similar code is found in other drivers such as the
279 * Sharp LS043T1LE01 which makes us suspect that this panel may be
280 * using a Novatek NT35565 or similar display driver chip that shares
281 * this command. Due to the lack of documentation we cannot know for
284 ret
= mipi_dsi_dcs_write(dsi
, ACX424_DCS_SET_MDDI
,
285 &mddi
, sizeof(mddi
));
287 dev_err(acx
->dev
, "failed to set MDDI (%d)\n", ret
);
291 /* Exit sleep mode */
292 ret
= mipi_dsi_dcs_exit_sleep_mode(dsi
);
294 dev_err(acx
->dev
, "failed to exit sleep mode (%d)\n", ret
);
299 ret
= mipi_dsi_dcs_set_display_on(dsi
);
301 dev_err(acx
->dev
, "failed to turn display on (%d)\n", ret
);
304 if (acx
->video_mode
) {
305 /* In video mode turn peripheral on */
306 ret
= mipi_dsi_turn_on_peripheral(dsi
);
308 dev_err(acx
->dev
, "failed to turn on peripheral\n");
313 acx
->bl
->props
.power
= FB_BLANK_NORMAL
;
318 acx424akp_power_off(acx
);
322 static int acx424akp_unprepare(struct drm_panel
*panel
)
324 struct acx424akp
*acx
= panel_to_acx424akp(panel
);
325 struct mipi_dsi_device
*dsi
= to_mipi_dsi_device(acx
->dev
);
329 /* Disable backlight */
331 ret
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_WRITE_CONTROL_DISPLAY
,
334 dev_err(acx
->dev
, "failed to disable display backlight (%d)\n", ret
);
338 ret
= mipi_dsi_dcs_set_display_off(dsi
);
340 dev_err(acx
->dev
, "failed to turn display off (%d)\n", ret
);
344 /* Enter sleep mode */
345 ret
= mipi_dsi_dcs_enter_sleep_mode(dsi
);
347 dev_err(acx
->dev
, "failed to enter sleep mode (%d)\n", ret
);
352 acx424akp_power_off(acx
);
353 acx
->bl
->props
.power
= FB_BLANK_POWERDOWN
;
358 static int acx424akp_enable(struct drm_panel
*panel
)
360 struct acx424akp
*acx
= panel_to_acx424akp(panel
);
363 * The backlight is on as long as the display is on
364 * so no use to call backlight_enable() here.
366 acx
->bl
->props
.power
= FB_BLANK_UNBLANK
;
371 static int acx424akp_disable(struct drm_panel
*panel
)
373 struct acx424akp
*acx
= panel_to_acx424akp(panel
);
376 * The backlight is on as long as the display is on
377 * so no use to call backlight_disable() here.
379 acx
->bl
->props
.power
= FB_BLANK_NORMAL
;
384 static int acx424akp_get_modes(struct drm_panel
*panel
,
385 struct drm_connector
*connector
)
387 struct acx424akp
*acx
= panel_to_acx424akp(panel
);
388 struct drm_display_mode
*mode
;
391 mode
= drm_mode_duplicate(connector
->dev
,
392 &sony_acx424akp_vid_mode
);
394 mode
= drm_mode_duplicate(connector
->dev
,
395 &sony_acx424akp_cmd_mode
);
397 dev_err(panel
->dev
, "bad mode or failed to add mode\n");
400 drm_mode_set_name(mode
);
401 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
403 connector
->display_info
.width_mm
= mode
->width_mm
;
404 connector
->display_info
.height_mm
= mode
->height_mm
;
406 drm_mode_probed_add(connector
, mode
);
408 return 1; /* Number of modes */
411 static const struct drm_panel_funcs acx424akp_drm_funcs
= {
412 .disable
= acx424akp_disable
,
413 .unprepare
= acx424akp_unprepare
,
414 .prepare
= acx424akp_prepare
,
415 .enable
= acx424akp_enable
,
416 .get_modes
= acx424akp_get_modes
,
419 static int acx424akp_probe(struct mipi_dsi_device
*dsi
)
421 struct device
*dev
= &dsi
->dev
;
422 struct acx424akp
*acx
;
425 acx
= devm_kzalloc(dev
, sizeof(struct acx424akp
), GFP_KERNEL
);
428 acx
->video_mode
= of_property_read_bool(dev
->of_node
,
429 "enforce-video-mode");
431 mipi_dsi_set_drvdata(dsi
, acx
);
435 dsi
->format
= MIPI_DSI_FMT_RGB888
;
437 * FIXME: these come from the ST-Ericsson vendor driver for the
438 * HREF520 and seems to reflect limitations in the PLLs on that
439 * platform, if you have the datasheet, please cross-check the
442 dsi
->lp_rate
= 19200000;
443 dsi
->hs_rate
= 420160000;
446 /* Burst mode using event for sync */
448 MIPI_DSI_MODE_VIDEO
|
449 MIPI_DSI_MODE_VIDEO_BURST
;
452 MIPI_DSI_CLOCK_NON_CONTINUOUS
|
453 MIPI_DSI_MODE_EOT_PACKET
;
455 acx
->supply
= devm_regulator_get(dev
, "vddi");
456 if (IS_ERR(acx
->supply
))
457 return PTR_ERR(acx
->supply
);
459 /* This asserts RESET by default */
460 acx
->reset_gpio
= devm_gpiod_get_optional(dev
, "reset",
462 if (IS_ERR(acx
->reset_gpio
)) {
463 ret
= PTR_ERR(acx
->reset_gpio
);
464 if (ret
!= -EPROBE_DEFER
)
465 dev_err(dev
, "failed to request GPIO (%d)\n", ret
);
469 drm_panel_init(&acx
->panel
, dev
, &acx424akp_drm_funcs
,
470 DRM_MODE_CONNECTOR_DSI
);
472 acx
->bl
= devm_backlight_device_register(dev
, "acx424akp", dev
, acx
,
473 &acx424akp_bl_ops
, NULL
);
474 if (IS_ERR(acx
->bl
)) {
475 dev_err(dev
, "failed to register backlight device\n");
476 return PTR_ERR(acx
->bl
);
478 acx
->bl
->props
.max_brightness
= 1023;
479 acx
->bl
->props
.brightness
= 512;
480 acx
->bl
->props
.power
= FB_BLANK_POWERDOWN
;
482 drm_panel_add(&acx
->panel
);
484 ret
= mipi_dsi_attach(dsi
);
486 drm_panel_remove(&acx
->panel
);
493 static int acx424akp_remove(struct mipi_dsi_device
*dsi
)
495 struct acx424akp
*acx
= mipi_dsi_get_drvdata(dsi
);
497 mipi_dsi_detach(dsi
);
498 drm_panel_remove(&acx
->panel
);
503 static const struct of_device_id acx424akp_of_match
[] = {
504 { .compatible
= "sony,acx424akp" },
507 MODULE_DEVICE_TABLE(of
, acx424akp_of_match
);
509 static struct mipi_dsi_driver acx424akp_driver
= {
510 .probe
= acx424akp_probe
,
511 .remove
= acx424akp_remove
,
513 .name
= "panel-sony-acx424akp",
514 .of_match_table
= acx424akp_of_match
,
517 module_mipi_dsi_driver(acx424akp_driver
);
519 MODULE_AUTHOR("Linus Wallei <linus.walleij@linaro.org>");
520 MODULE_DESCRIPTION("MIPI-DSI Sony acx424akp Panel Driver");
521 MODULE_LICENSE("GPL v2");