^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2014 NVIDIA Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/regulator/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <video/mipi_display.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <drm/drm_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <drm/drm_mipi_dsi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <drm/drm_panel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct sharp_panel {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct drm_panel base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* the datasheet refers to them as DSI-LINK1 and DSI-LINK2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct mipi_dsi_device *link1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct mipi_dsi_device *link2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct regulator *supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) bool prepared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) bool enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) const struct drm_display_mode *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static inline struct sharp_panel *to_sharp_panel(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return container_of(panel, struct sharp_panel, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static void sharp_wait_frames(struct sharp_panel *sharp, unsigned int frames)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int refresh = drm_mode_vrefresh(sharp->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (WARN_ON(frames > refresh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) msleep(1000 / (refresh / frames));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static int sharp_panel_write(struct sharp_panel *sharp, u16 offset, u8 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u8 payload[3] = { offset >> 8, offset & 0xff, value };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct mipi_dsi_device *dsi = sharp->link1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) err = mipi_dsi_generic_write(dsi, payload, sizeof(payload));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) dev_err(&dsi->dev, "failed to write %02x to %04x: %zd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) value, offset, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) err = mipi_dsi_dcs_nop(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dev_err(&dsi->dev, "failed to send DCS nop: %zd\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) usleep_range(10, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static __maybe_unused int sharp_panel_read(struct sharp_panel *sharp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) u16 offset, u8 *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ssize_t err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) cpu_to_be16s(&offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) err = mipi_dsi_generic_read(sharp->link1, &offset, sizeof(offset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) value, sizeof(*value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) dev_err(&sharp->link1->dev, "failed to read from %04x: %zd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) offset, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static int sharp_panel_disable(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct sharp_panel *sharp = to_sharp_panel(panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (!sharp->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) sharp->enabled = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int sharp_panel_unprepare(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct sharp_panel *sharp = to_sharp_panel(panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (!sharp->prepared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) sharp_wait_frames(sharp, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) err = mipi_dsi_dcs_set_display_off(sharp->link1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dev_err(panel->dev, "failed to set display off: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) err = mipi_dsi_dcs_enter_sleep_mode(sharp->link1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) dev_err(panel->dev, "failed to enter sleep mode: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) msleep(120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) regulator_disable(sharp->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) sharp->prepared = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int sharp_setup_symmetrical_split(struct mipi_dsi_device *left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct mipi_dsi_device *right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) const struct drm_display_mode *mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) err = mipi_dsi_dcs_set_column_address(left, 0, mode->hdisplay / 2 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) dev_err(&left->dev, "failed to set column address: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) err = mipi_dsi_dcs_set_page_address(left, 0, mode->vdisplay - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) dev_err(&left->dev, "failed to set page address: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err = mipi_dsi_dcs_set_column_address(right, mode->hdisplay / 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) mode->hdisplay - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) dev_err(&right->dev, "failed to set column address: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) err = mipi_dsi_dcs_set_page_address(right, 0, mode->vdisplay - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) dev_err(&right->dev, "failed to set page address: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int sharp_panel_prepare(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct sharp_panel *sharp = to_sharp_panel(panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) u8 format = MIPI_DCS_PIXEL_FMT_24BIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (sharp->prepared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) err = regulator_enable(sharp->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * According to the datasheet, the panel needs around 10 ms to fully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * power up. At least another 120 ms is required before exiting sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * mode to make sure the panel is ready. Throw in another 20 ms for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * good measure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) msleep(150);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) err = mipi_dsi_dcs_exit_sleep_mode(sharp->link1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) dev_err(panel->dev, "failed to exit sleep mode: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * The MIPI DCS specification mandates this delay only between the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * exit_sleep_mode and enter_sleep_mode commands, so it isn't strictly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * necessary here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) msleep(120);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* set left-right mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) err = sharp_panel_write(sharp, 0x1000, 0x2a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) dev_err(panel->dev, "failed to set left-right mode: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* enable command mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) err = sharp_panel_write(sharp, 0x1001, 0x01);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) dev_err(panel->dev, "failed to enable command mode: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) err = mipi_dsi_dcs_set_pixel_format(sharp->link1, format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) dev_err(panel->dev, "failed to set pixel format: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * TODO: The device supports both left-right and even-odd split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * configurations, but this driver currently supports only the left-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * right split. To support a different mode a mechanism needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * put in place to communicate the configuration back to the DSI host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * controller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) err = sharp_setup_symmetrical_split(sharp->link1, sharp->link2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) sharp->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) dev_err(panel->dev, "failed to set up symmetrical split: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) err = mipi_dsi_dcs_set_display_on(sharp->link1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) dev_err(panel->dev, "failed to set display on: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) goto poweroff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) sharp->prepared = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /* wait for 6 frames before continuing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) sharp_wait_frames(sharp, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) poweroff:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) regulator_disable(sharp->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int sharp_panel_enable(struct drm_panel *panel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) struct sharp_panel *sharp = to_sharp_panel(panel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (sharp->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) sharp->enabled = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static const struct drm_display_mode default_mode = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .clock = 278000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .hdisplay = 2560,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .hsync_start = 2560 + 128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .hsync_end = 2560 + 128 + 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .htotal = 2560 + 128 + 64 + 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) .vdisplay = 1600,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .vsync_start = 1600 + 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .vsync_end = 1600 + 4 + 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .vtotal = 1600 + 4 + 8 + 32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static int sharp_panel_get_modes(struct drm_panel *panel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct drm_connector *connector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct drm_display_mode *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) mode = drm_mode_duplicate(connector->dev, &default_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) dev_err(panel->dev, "failed to add mode %ux%ux@%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) default_mode.hdisplay, default_mode.vdisplay,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) drm_mode_vrefresh(&default_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) drm_mode_set_name(mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) drm_mode_probed_add(connector, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) connector->display_info.width_mm = 217;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) connector->display_info.height_mm = 136;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static const struct drm_panel_funcs sharp_panel_funcs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .disable = sharp_panel_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .unprepare = sharp_panel_unprepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .prepare = sharp_panel_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) .enable = sharp_panel_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) .get_modes = sharp_panel_get_modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static const struct of_device_id sharp_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) { .compatible = "sharp,lq101r1sx01", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) MODULE_DEVICE_TABLE(of, sharp_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static int sharp_panel_add(struct sharp_panel *sharp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) sharp->mode = &default_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) sharp->supply = devm_regulator_get(&sharp->link1->dev, "power");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (IS_ERR(sharp->supply))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return PTR_ERR(sharp->supply);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) drm_panel_init(&sharp->base, &sharp->link1->dev, &sharp_panel_funcs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) DRM_MODE_CONNECTOR_DSI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ret = drm_panel_of_backlight(&sharp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) drm_panel_add(&sharp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static void sharp_panel_del(struct sharp_panel *sharp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (sharp->base.dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) drm_panel_remove(&sharp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (sharp->link2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) put_device(&sharp->link2->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int sharp_panel_probe(struct mipi_dsi_device *dsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct mipi_dsi_device *secondary = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct sharp_panel *sharp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) dsi->lanes = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) dsi->format = MIPI_DSI_FMT_RGB888;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) dsi->mode_flags = MIPI_DSI_MODE_LPM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* Find DSI-LINK1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) np = of_parse_phandle(dsi->dev.of_node, "link2", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) secondary = of_find_mipi_dsi_device_by_node(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return -EPROBE_DEFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* register a panel for only the DSI-LINK1 interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) if (secondary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) sharp = devm_kzalloc(&dsi->dev, sizeof(*sharp), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (!sharp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) put_device(&secondary->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) mipi_dsi_set_drvdata(dsi, sharp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) sharp->link2 = secondary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) sharp->link1 = dsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) err = sharp_panel_add(sharp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) put_device(&secondary->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) err = mipi_dsi_attach(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) if (secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) sharp_panel_del(sharp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static int sharp_panel_remove(struct mipi_dsi_device *dsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct sharp_panel *sharp = mipi_dsi_get_drvdata(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* only detach from host for the DSI-LINK2 interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (!sharp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) mipi_dsi_detach(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) err = drm_panel_disable(&sharp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) dev_err(&dsi->dev, "failed to disable panel: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) err = mipi_dsi_detach(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) sharp_panel_del(sharp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) static void sharp_panel_shutdown(struct mipi_dsi_device *dsi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) struct sharp_panel *sharp = mipi_dsi_get_drvdata(dsi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) /* nothing to do for DSI-LINK2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!sharp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) drm_panel_disable(&sharp->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) static struct mipi_dsi_driver sharp_panel_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) .name = "panel-sharp-lq101r1sx01",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) .of_match_table = sharp_of_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) .probe = sharp_panel_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) .remove = sharp_panel_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) .shutdown = sharp_panel_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) module_mipi_dsi_driver(sharp_panel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) MODULE_DESCRIPTION("Sharp LQ101R1SX01 panel driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) MODULE_LICENSE("GPL v2");