Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | // SPDX-License-Identifier: GPL-2.0+ /* * Renesas R61307 panel driver * * Copyright (c) 2022 Svyatoslav Ryhel <clamor95@gmail.com> */ #include <backlight.h> #include <dm.h> #include <panel.h> #include <log.h> #include <misc.h> #include <mipi_display.h> #include <mipi_dsi.h> #include <asm/gpio.h> #include <linux/delay.h> #include <linux/err.h> #include <power/regulator.h> /* * The datasheet is not publicly available, all values are * taken from the downstream. If you have access to datasheets, * corrections are welcome. */ #define R61307_MACP 0xB0 /* Manufacturer CMD Protect */ #define R61307_INVERSION 0xC1 #define R61307_GAMMA_SET_A 0xC8 /* Gamma Setting A */ #define R61307_GAMMA_SET_B 0xC9 /* Gamma Setting B */ #define R61307_GAMMA_SET_C 0xCA /* Gamma Setting C */ #define R61307_CONTRAST_SET 0xCC struct renesas_r61307_priv { struct udevice *vcc; struct udevice *iovcc; struct udevice *backlight; struct gpio_desc reset_gpio; bool dig_cont_adj; bool inversion; u32 gamma; }; static const u8 macp_on[] = { R61307_MACP, 0x03 }; static const u8 macp_off[] = { R61307_MACP, 0x04 }; static const u8 address_mode[] = { MIPI_DCS_SET_ADDRESS_MODE }; static const u8 contrast_setting[] = { R61307_CONTRAST_SET, 0xdc, 0xb4, 0xff }; static const u8 column_inversion[] = { R61307_INVERSION, 0x00, 0x50, 0x03, 0x22, 0x16, 0x06, 0x60, 0x11 }; static const u8 line_inversion[] = { R61307_INVERSION, 0x00, 0x10, 0x03, 0x22, 0x16, 0x06, 0x60, 0x01 }; static const u8 gamma_setting[][25] = { {}, { R61307_GAMMA_SET_A, 0x00, 0x06, 0x0a, 0x0f, 0x14, 0x1f, 0x1f, 0x17, 0x12, 0x0c, 0x09, 0x06, 0x00, 0x06, 0x0a, 0x0f, 0x14, 0x1f, 0x1f, 0x17, 0x12, 0x0c, 0x09, 0x06 }, { R61307_GAMMA_SET_A, 0x00, 0x05, 0x0b, 0x0f, 0x11, 0x1d, 0x20, 0x18, 0x18, 0x09, 0x07, 0x06, 0x00, 0x05, 0x0b, 0x0f, 0x11, 0x1d, 0x20, 0x18, 0x18, 0x09, 0x07, 0x06 }, { R61307_GAMMA_SET_A, 0x0b, 0x0d, 0x10, 0x14, 0x13, 0x1d, 0x20, 0x18, 0x12, 0x09, 0x07, 0x06, 0x0a, 0x0c, 0x10, 0x14, 0x13, 0x1d, 0x20, 0x18, 0x12, 0x09, 0x07, 0x06 }, }; static struct display_timing default_timing = { .pixelclock.typ = 62000000, .hactive.typ = 768, .hfront_porch.typ = 116, .hback_porch.typ = 81, .hsync_len.typ = 5, .vactive.typ = 1024, .vfront_porch.typ = 24, .vback_porch.typ = 8, .vsync_len.typ = 2, }; static int renesas_r61307_enable_backlight(struct udevice *dev) { struct renesas_r61307_priv *priv = dev_get_priv(dev); struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); struct mipi_dsi_device *dsi = plat->device; int ret; ret = mipi_dsi_dcs_exit_sleep_mode(dsi); if (ret < 0) { log_err("failed to exit sleep mode: %d\n", ret); return ret; } mdelay(80); mipi_dsi_dcs_write_buffer(dsi, address_mode, sizeof(address_mode)); mdelay(20); ret = mipi_dsi_dcs_set_pixel_format(dsi, MIPI_DCS_PIXEL_FMT_24BIT << 4); if (ret < 0) { log_err("failed to set pixel format: %d\n", ret); return ret; } /* MACP Off */ mipi_dsi_generic_write(dsi, macp_off, sizeof(macp_off)); if (priv->dig_cont_adj) mipi_dsi_generic_write(dsi, contrast_setting, sizeof(contrast_setting)); if (priv->gamma) mipi_dsi_generic_write(dsi, gamma_setting[priv->gamma], sizeof(gamma_setting[priv->gamma])); if (priv->inversion) mipi_dsi_generic_write(dsi, column_inversion, sizeof(column_inversion)); else mipi_dsi_generic_write(dsi, line_inversion, sizeof(line_inversion)); /* MACP On */ mipi_dsi_generic_write(dsi, macp_on, sizeof(macp_on)); ret = mipi_dsi_dcs_set_display_on(dsi); if (ret < 0) { log_err("failed to set display on: %d\n", ret); return ret; } mdelay(50); return 0; } static int renesas_r61307_set_backlight(struct udevice *dev, int percent) { struct renesas_r61307_priv *priv = dev_get_priv(dev); int ret; ret = backlight_enable(priv->backlight); if (ret) return ret; mdelay(5); return backlight_set_brightness(priv->backlight, percent); } static int renesas_r61307_timings(struct udevice *dev, struct display_timing *timing) { memcpy(timing, &default_timing, sizeof(*timing)); return 0; } static int renesas_r61307_of_to_plat(struct udevice *dev) { struct renesas_r61307_priv *priv = dev_get_priv(dev); int ret; ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, "backlight", &priv->backlight); if (ret) { log_err("Cannot get backlight: ret = %d\n", ret); return ret; } ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, "vcc-supply", &priv->vcc); if (ret) { log_err("Cannot get vcc-supply: ret = %d\n", ret); return ret; } ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, "iovcc-supply", &priv->iovcc); if (ret) { log_err("Cannot get iovcc-supply: ret = %d\n", ret); return ret; } ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset_gpio, GPIOD_IS_OUT); if (ret) { log_err("Could not decode reser-gpios (%d)\n", ret); return ret; } priv->dig_cont_adj = dev_read_bool(dev, "renesas,contrast"); priv->inversion = dev_read_bool(dev, "renesas,inversion"); priv->gamma = dev_read_u32_default(dev, "renesas,gamma", 0); return 0; } static int renesas_r61307_hw_init(struct udevice *dev) { struct renesas_r61307_priv *priv = dev_get_priv(dev); int ret; ret = regulator_set_enable_if_allowed(priv->vcc, 1); if (ret) { log_debug("%s: enabling vcc-supply failed (%d)\n", __func__, ret); return ret; } mdelay(5); ret = regulator_set_enable_if_allowed(priv->iovcc, 1); if (ret) { log_debug("%s: enabling iovcc-supply failed (%d)\n", __func__, ret); return ret; } ret = dm_gpio_set_value(&priv->reset_gpio, 1); if (ret) { log_debug("%s: entering reset failed (%d)\n", __func__, ret); return ret; } mdelay(5); ret = dm_gpio_set_value(&priv->reset_gpio, 0); if (ret) { log_debug("%s: exiting reset failed (%d)\n", __func__, ret); return ret; } mdelay(5); return 0; } static int renesas_r61307_probe(struct udevice *dev) { struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); /* fill characteristics of DSI data link */ plat->lanes = 4; plat->format = MIPI_DSI_FMT_RGB888; plat->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM; return renesas_r61307_hw_init(dev); } static const struct panel_ops renesas_r61307_ops = { .enable_backlight = renesas_r61307_enable_backlight, .set_backlight = renesas_r61307_set_backlight, .get_display_timing = renesas_r61307_timings, }; static const struct udevice_id renesas_r61307_ids[] = { { .compatible = "koe,tx13d100vm0eaa" }, { .compatible = "hit,tx13d100vm0eaa" }, { } }; U_BOOT_DRIVER(renesas_r61307) = { .name = "renesas_r61307", .id = UCLASS_PANEL, .of_match = renesas_r61307_ids, .ops = &renesas_r61307_ops, .of_to_plat = renesas_r61307_of_to_plat, .probe = renesas_r61307_probe, .plat_auto = sizeof(struct mipi_dsi_panel_plat), .priv_auto = sizeof(struct renesas_r61307_priv), }; |