Philippe CORNU | 2dab3bf | 2018-01-19 12:05:16 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) STMicroelectronics SA 2017 |
| 4 | * |
| 5 | * Authors: Philippe Cornu <philippe.cornu@st.com> |
| 6 | * Yannick Fertre <yannick.fertre@st.com> |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 7 | */ |
Philippe CORNU | 2dab3bf | 2018-01-19 12:05:16 +0100 | [diff] [blame] | 8 | |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 9 | #include <drm/drmP.h> |
| 10 | #include <drm/drm_mipi_dsi.h> |
| 11 | #include <drm/drm_panel.h> |
| 12 | #include <linux/backlight.h> |
| 13 | #include <linux/gpio/consumer.h> |
Philippe CORNU | ded8d7f | 2018-02-05 10:45:32 +0100 | [diff] [blame] | 14 | #include <linux/regulator/consumer.h> |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 15 | #include <video/mipi_display.h> |
| 16 | |
| 17 | #define DRV_NAME "orisetech_otm8009a" |
| 18 | |
| 19 | #define OTM8009A_BACKLIGHT_DEFAULT 240 |
| 20 | #define OTM8009A_BACKLIGHT_MAX 255 |
| 21 | |
| 22 | /* Manufacturer Command Set */ |
| 23 | #define MCS_ADRSFT 0x0000 /* Address Shift Function */ |
| 24 | #define MCS_PANSET 0xB3A6 /* Panel Type Setting */ |
| 25 | #define MCS_SD_CTRL 0xC0A2 /* Source Driver Timing Setting */ |
| 26 | #define MCS_P_DRV_M 0xC0B4 /* Panel Driving Mode */ |
| 27 | #define MCS_OSC_ADJ 0xC181 /* Oscillator Adjustment for Idle/Normal mode */ |
| 28 | #define MCS_RGB_VID_SET 0xC1A1 /* RGB Video Mode Setting */ |
| 29 | #define MCS_SD_PCH_CTRL 0xC480 /* Source Driver Precharge Control */ |
| 30 | #define MCS_NO_DOC1 0xC48A /* Command not documented */ |
| 31 | #define MCS_PWR_CTRL1 0xC580 /* Power Control Setting 1 */ |
| 32 | #define MCS_PWR_CTRL2 0xC590 /* Power Control Setting 2 for Normal Mode */ |
| 33 | #define MCS_PWR_CTRL4 0xC5B0 /* Power Control Setting 4 for DC Voltage */ |
| 34 | #define MCS_PANCTRLSET1 0xCB80 /* Panel Control Setting 1 */ |
| 35 | #define MCS_PANCTRLSET2 0xCB90 /* Panel Control Setting 2 */ |
| 36 | #define MCS_PANCTRLSET3 0xCBA0 /* Panel Control Setting 3 */ |
| 37 | #define MCS_PANCTRLSET4 0xCBB0 /* Panel Control Setting 4 */ |
| 38 | #define MCS_PANCTRLSET5 0xCBC0 /* Panel Control Setting 5 */ |
| 39 | #define MCS_PANCTRLSET6 0xCBD0 /* Panel Control Setting 6 */ |
| 40 | #define MCS_PANCTRLSET7 0xCBE0 /* Panel Control Setting 7 */ |
| 41 | #define MCS_PANCTRLSET8 0xCBF0 /* Panel Control Setting 8 */ |
| 42 | #define MCS_PANU2D1 0xCC80 /* Panel U2D Setting 1 */ |
| 43 | #define MCS_PANU2D2 0xCC90 /* Panel U2D Setting 2 */ |
| 44 | #define MCS_PANU2D3 0xCCA0 /* Panel U2D Setting 3 */ |
| 45 | #define MCS_PAND2U1 0xCCB0 /* Panel D2U Setting 1 */ |
| 46 | #define MCS_PAND2U2 0xCCC0 /* Panel D2U Setting 2 */ |
| 47 | #define MCS_PAND2U3 0xCCD0 /* Panel D2U Setting 3 */ |
| 48 | #define MCS_GOAVST 0xCE80 /* GOA VST Setting */ |
| 49 | #define MCS_GOACLKA1 0xCEA0 /* GOA CLKA1 Setting */ |
| 50 | #define MCS_GOACLKA3 0xCEB0 /* GOA CLKA3 Setting */ |
| 51 | #define MCS_GOAECLK 0xCFC0 /* GOA ECLK Setting */ |
| 52 | #define MCS_NO_DOC2 0xCFD0 /* Command not documented */ |
| 53 | #define MCS_GVDDSET 0xD800 /* GVDD/NGVDD */ |
| 54 | #define MCS_VCOMDC 0xD900 /* VCOM Voltage Setting */ |
| 55 | #define MCS_GMCT2_2P 0xE100 /* Gamma Correction 2.2+ Setting */ |
| 56 | #define MCS_GMCT2_2N 0xE200 /* Gamma Correction 2.2- Setting */ |
| 57 | #define MCS_NO_DOC3 0xF5B6 /* Command not documented */ |
| 58 | #define MCS_CMD2_ENA1 0xFF00 /* Enable Access Command2 "CMD2" */ |
| 59 | #define MCS_CMD2_ENA2 0xFF80 /* Enable Access Orise Command2 */ |
| 60 | |
| 61 | struct otm8009a { |
| 62 | struct device *dev; |
| 63 | struct drm_panel panel; |
| 64 | struct backlight_device *bl_dev; |
| 65 | struct gpio_desc *reset_gpio; |
Philippe CORNU | ded8d7f | 2018-02-05 10:45:32 +0100 | [diff] [blame] | 66 | struct regulator *supply; |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 67 | bool prepared; |
| 68 | bool enabled; |
| 69 | }; |
| 70 | |
| 71 | static const struct drm_display_mode default_mode = { |
| 72 | .clock = 32729, |
| 73 | .hdisplay = 480, |
| 74 | .hsync_start = 480 + 120, |
| 75 | .hsync_end = 480 + 120 + 63, |
| 76 | .htotal = 480 + 120 + 63 + 120, |
| 77 | .vdisplay = 800, |
| 78 | .vsync_start = 800 + 12, |
| 79 | .vsync_end = 800 + 12 + 12, |
| 80 | .vtotal = 800 + 12 + 12 + 12, |
| 81 | .vrefresh = 50, |
| 82 | .flags = 0, |
| 83 | .width_mm = 52, |
| 84 | .height_mm = 86, |
| 85 | }; |
| 86 | |
| 87 | static inline struct otm8009a *panel_to_otm8009a(struct drm_panel *panel) |
| 88 | { |
| 89 | return container_of(panel, struct otm8009a, panel); |
| 90 | } |
| 91 | |
| 92 | static void otm8009a_dcs_write_buf(struct otm8009a *ctx, const void *data, |
| 93 | size_t len) |
| 94 | { |
| 95 | struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev); |
| 96 | |
| 97 | if (mipi_dsi_dcs_write_buffer(dsi, data, len) < 0) |
| 98 | DRM_WARN("mipi dsi dcs write buffer failed\n"); |
| 99 | } |
| 100 | |
Philippe CORNU | d9f9565 | 2018-04-23 16:10:50 +0200 | [diff] [blame^] | 101 | static void otm8009a_dcs_write_buf_hs(struct otm8009a *ctx, const void *data, |
| 102 | size_t len) |
| 103 | { |
| 104 | struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev); |
| 105 | |
| 106 | /* data will be sent in dsi hs mode (ie. no lpm) */ |
| 107 | dsi->mode_flags &= ~MIPI_DSI_MODE_LPM; |
| 108 | |
| 109 | otm8009a_dcs_write_buf(ctx, data, len); |
| 110 | |
| 111 | /* restore back the dsi lpm mode */ |
| 112 | dsi->mode_flags |= MIPI_DSI_MODE_LPM; |
| 113 | } |
| 114 | |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 115 | #define dcs_write_seq(ctx, seq...) \ |
| 116 | ({ \ |
| 117 | static const u8 d[] = { seq }; \ |
| 118 | otm8009a_dcs_write_buf(ctx, d, ARRAY_SIZE(d)); \ |
| 119 | }) |
| 120 | |
| 121 | #define dcs_write_cmd_at(ctx, cmd, seq...) \ |
| 122 | ({ \ |
| 123 | dcs_write_seq(ctx, MCS_ADRSFT, (cmd) & 0xFF); \ |
| 124 | dcs_write_seq(ctx, (cmd) >> 8, seq); \ |
| 125 | }) |
| 126 | |
| 127 | static int otm8009a_init_sequence(struct otm8009a *ctx) |
| 128 | { |
| 129 | struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev); |
| 130 | int ret; |
| 131 | |
| 132 | /* Enter CMD2 */ |
| 133 | dcs_write_cmd_at(ctx, MCS_CMD2_ENA1, 0x80, 0x09, 0x01); |
| 134 | |
| 135 | /* Enter Orise Command2 */ |
| 136 | dcs_write_cmd_at(ctx, MCS_CMD2_ENA2, 0x80, 0x09); |
| 137 | |
| 138 | dcs_write_cmd_at(ctx, MCS_SD_PCH_CTRL, 0x30); |
| 139 | mdelay(10); |
| 140 | |
| 141 | dcs_write_cmd_at(ctx, MCS_NO_DOC1, 0x40); |
| 142 | mdelay(10); |
| 143 | |
| 144 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL4 + 1, 0xA9); |
| 145 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL2 + 1, 0x34); |
| 146 | dcs_write_cmd_at(ctx, MCS_P_DRV_M, 0x50); |
| 147 | dcs_write_cmd_at(ctx, MCS_VCOMDC, 0x4E); |
| 148 | dcs_write_cmd_at(ctx, MCS_OSC_ADJ, 0x66); /* 65Hz */ |
| 149 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL2 + 2, 0x01); |
| 150 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL2 + 5, 0x34); |
| 151 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL2 + 4, 0x33); |
| 152 | dcs_write_cmd_at(ctx, MCS_GVDDSET, 0x79, 0x79); |
| 153 | dcs_write_cmd_at(ctx, MCS_SD_CTRL + 1, 0x1B); |
| 154 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL1 + 2, 0x83); |
| 155 | dcs_write_cmd_at(ctx, MCS_SD_PCH_CTRL + 1, 0x83); |
| 156 | dcs_write_cmd_at(ctx, MCS_RGB_VID_SET, 0x0E); |
| 157 | dcs_write_cmd_at(ctx, MCS_PANSET, 0x00, 0x01); |
| 158 | |
| 159 | dcs_write_cmd_at(ctx, MCS_GOAVST, 0x85, 0x01, 0x00, 0x84, 0x01, 0x00); |
| 160 | dcs_write_cmd_at(ctx, MCS_GOACLKA1, 0x18, 0x04, 0x03, 0x39, 0x00, 0x00, |
| 161 | 0x00, 0x18, 0x03, 0x03, 0x3A, 0x00, 0x00, 0x00); |
| 162 | dcs_write_cmd_at(ctx, MCS_GOACLKA3, 0x18, 0x02, 0x03, 0x3B, 0x00, 0x00, |
| 163 | 0x00, 0x18, 0x01, 0x03, 0x3C, 0x00, 0x00, 0x00); |
| 164 | dcs_write_cmd_at(ctx, MCS_GOAECLK, 0x01, 0x01, 0x20, 0x20, 0x00, 0x00, |
| 165 | 0x01, 0x02, 0x00, 0x00); |
| 166 | |
| 167 | dcs_write_cmd_at(ctx, MCS_NO_DOC2, 0x00); |
| 168 | |
| 169 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 170 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 171 | 0, 0, 0, 0, 0); |
| 172 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 173 | 0, 0, 0, 0, 0); |
| 174 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 175 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET5, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, |
| 176 | 0, 0, 0, 0, 0); |
| 177 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET6, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, |
| 178 | 4, 0, 0, 0, 0); |
| 179 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); |
| 180 | dcs_write_cmd_at(ctx, MCS_PANCTRLSET8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
| 181 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); |
| 182 | |
| 183 | dcs_write_cmd_at(ctx, MCS_PANU2D1, 0x00, 0x26, 0x09, 0x0B, 0x01, 0x25, |
| 184 | 0x00, 0x00, 0x00, 0x00); |
| 185 | dcs_write_cmd_at(ctx, MCS_PANU2D2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 186 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x0A, 0x0C, 0x02); |
| 187 | dcs_write_cmd_at(ctx, MCS_PANU2D3, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 188 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); |
| 189 | dcs_write_cmd_at(ctx, MCS_PAND2U1, 0x00, 0x25, 0x0C, 0x0A, 0x02, 0x26, |
| 190 | 0x00, 0x00, 0x00, 0x00); |
| 191 | dcs_write_cmd_at(ctx, MCS_PAND2U2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 192 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x0B, 0x09, 0x01); |
| 193 | dcs_write_cmd_at(ctx, MCS_PAND2U3, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 194 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); |
| 195 | |
| 196 | dcs_write_cmd_at(ctx, MCS_PWR_CTRL1 + 1, 0x66); |
| 197 | |
| 198 | dcs_write_cmd_at(ctx, MCS_NO_DOC3, 0x06); |
| 199 | |
| 200 | dcs_write_cmd_at(ctx, MCS_GMCT2_2P, 0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, |
| 201 | 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, |
| 202 | 0x01); |
| 203 | dcs_write_cmd_at(ctx, MCS_GMCT2_2N, 0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, |
| 204 | 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, |
| 205 | 0x01); |
| 206 | |
| 207 | /* Exit CMD2 */ |
| 208 | dcs_write_cmd_at(ctx, MCS_CMD2_ENA1, 0xFF, 0xFF, 0xFF); |
| 209 | |
| 210 | ret = mipi_dsi_dcs_nop(dsi); |
| 211 | if (ret) |
| 212 | return ret; |
| 213 | |
| 214 | ret = mipi_dsi_dcs_exit_sleep_mode(dsi); |
| 215 | if (ret) |
| 216 | return ret; |
| 217 | |
| 218 | /* Wait for sleep out exit */ |
| 219 | mdelay(120); |
| 220 | |
| 221 | /* Default portrait 480x800 rgb24 */ |
| 222 | dcs_write_seq(ctx, MIPI_DCS_SET_ADDRESS_MODE, 0x00); |
| 223 | |
| 224 | ret = mipi_dsi_dcs_set_column_address(dsi, 0, |
| 225 | default_mode.hdisplay - 1); |
| 226 | if (ret) |
| 227 | return ret; |
| 228 | |
| 229 | ret = mipi_dsi_dcs_set_page_address(dsi, 0, default_mode.vdisplay - 1); |
| 230 | if (ret) |
| 231 | return ret; |
| 232 | |
| 233 | /* See otm8009a driver documentation for pixel format descriptions */ |
| 234 | ret = mipi_dsi_dcs_set_pixel_format(dsi, MIPI_DCS_PIXEL_FMT_24BIT | |
| 235 | MIPI_DCS_PIXEL_FMT_24BIT << 4); |
| 236 | if (ret) |
| 237 | return ret; |
| 238 | |
| 239 | /* Disable CABC feature */ |
| 240 | dcs_write_seq(ctx, MIPI_DCS_WRITE_POWER_SAVE, 0x00); |
| 241 | |
| 242 | ret = mipi_dsi_dcs_set_display_on(dsi); |
| 243 | if (ret) |
| 244 | return ret; |
| 245 | |
| 246 | ret = mipi_dsi_dcs_nop(dsi); |
| 247 | if (ret) |
| 248 | return ret; |
| 249 | |
| 250 | /* Send Command GRAM memory write (no parameters) */ |
| 251 | dcs_write_seq(ctx, MIPI_DCS_WRITE_MEMORY_START); |
| 252 | |
| 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | static int otm8009a_disable(struct drm_panel *panel) |
| 257 | { |
| 258 | struct otm8009a *ctx = panel_to_otm8009a(panel); |
| 259 | struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev); |
| 260 | int ret; |
| 261 | |
| 262 | if (!ctx->enabled) |
| 263 | return 0; /* This is not an issue so we return 0 here */ |
| 264 | |
| 265 | /* Power off the backlight. Note: end-user still controls brightness */ |
| 266 | ctx->bl_dev->props.power = FB_BLANK_POWERDOWN; |
| 267 | ret = backlight_update_status(ctx->bl_dev); |
| 268 | if (ret) |
| 269 | return ret; |
| 270 | |
| 271 | ret = mipi_dsi_dcs_set_display_off(dsi); |
| 272 | if (ret) |
| 273 | return ret; |
| 274 | |
| 275 | ret = mipi_dsi_dcs_enter_sleep_mode(dsi); |
| 276 | if (ret) |
| 277 | return ret; |
| 278 | |
| 279 | msleep(120); |
| 280 | |
| 281 | ctx->enabled = false; |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | static int otm8009a_unprepare(struct drm_panel *panel) |
| 287 | { |
| 288 | struct otm8009a *ctx = panel_to_otm8009a(panel); |
| 289 | |
| 290 | if (!ctx->prepared) |
| 291 | return 0; |
| 292 | |
| 293 | if (ctx->reset_gpio) { |
| 294 | gpiod_set_value_cansleep(ctx->reset_gpio, 1); |
| 295 | msleep(20); |
| 296 | } |
| 297 | |
Philippe CORNU | ded8d7f | 2018-02-05 10:45:32 +0100 | [diff] [blame] | 298 | regulator_disable(ctx->supply); |
| 299 | |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 300 | ctx->prepared = false; |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static int otm8009a_prepare(struct drm_panel *panel) |
| 306 | { |
| 307 | struct otm8009a *ctx = panel_to_otm8009a(panel); |
| 308 | int ret; |
| 309 | |
| 310 | if (ctx->prepared) |
| 311 | return 0; |
| 312 | |
Philippe CORNU | ded8d7f | 2018-02-05 10:45:32 +0100 | [diff] [blame] | 313 | ret = regulator_enable(ctx->supply); |
| 314 | if (ret < 0) { |
| 315 | DRM_ERROR("failed to enable supply: %d\n", ret); |
| 316 | return ret; |
| 317 | } |
| 318 | |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 319 | if (ctx->reset_gpio) { |
| 320 | gpiod_set_value_cansleep(ctx->reset_gpio, 0); |
| 321 | gpiod_set_value_cansleep(ctx->reset_gpio, 1); |
| 322 | msleep(20); |
| 323 | gpiod_set_value_cansleep(ctx->reset_gpio, 0); |
| 324 | msleep(100); |
| 325 | } |
| 326 | |
| 327 | ret = otm8009a_init_sequence(ctx); |
| 328 | if (ret) |
| 329 | return ret; |
| 330 | |
| 331 | ctx->prepared = true; |
| 332 | |
| 333 | /* |
| 334 | * Power on the backlight. Note: end-user still controls brightness |
| 335 | * Note: ctx->prepared must be true before updating the backlight. |
| 336 | */ |
| 337 | ctx->bl_dev->props.power = FB_BLANK_UNBLANK; |
| 338 | backlight_update_status(ctx->bl_dev); |
| 339 | |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | static int otm8009a_enable(struct drm_panel *panel) |
| 344 | { |
| 345 | struct otm8009a *ctx = panel_to_otm8009a(panel); |
| 346 | |
| 347 | ctx->enabled = true; |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int otm8009a_get_modes(struct drm_panel *panel) |
| 353 | { |
| 354 | struct drm_display_mode *mode; |
| 355 | |
| 356 | mode = drm_mode_duplicate(panel->drm, &default_mode); |
| 357 | if (!mode) { |
| 358 | DRM_ERROR("failed to add mode %ux%ux@%u\n", |
| 359 | default_mode.hdisplay, default_mode.vdisplay, |
| 360 | default_mode.vrefresh); |
| 361 | return -ENOMEM; |
| 362 | } |
| 363 | |
| 364 | drm_mode_set_name(mode); |
| 365 | |
| 366 | mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED; |
| 367 | drm_mode_probed_add(panel->connector, mode); |
| 368 | |
| 369 | panel->connector->display_info.width_mm = mode->width_mm; |
| 370 | panel->connector->display_info.height_mm = mode->height_mm; |
| 371 | |
| 372 | return 1; |
| 373 | } |
| 374 | |
| 375 | static const struct drm_panel_funcs otm8009a_drm_funcs = { |
| 376 | .disable = otm8009a_disable, |
| 377 | .unprepare = otm8009a_unprepare, |
| 378 | .prepare = otm8009a_prepare, |
| 379 | .enable = otm8009a_enable, |
| 380 | .get_modes = otm8009a_get_modes, |
| 381 | }; |
| 382 | |
| 383 | /* |
| 384 | * DSI-BASED BACKLIGHT |
| 385 | */ |
| 386 | |
| 387 | static int otm8009a_backlight_update_status(struct backlight_device *bd) |
| 388 | { |
| 389 | struct otm8009a *ctx = bl_get_data(bd); |
| 390 | u8 data[2]; |
| 391 | |
| 392 | if (!ctx->prepared) { |
| 393 | DRM_DEBUG("lcd not ready yet for setting its backlight!\n"); |
| 394 | return -ENXIO; |
| 395 | } |
| 396 | |
| 397 | if (bd->props.power <= FB_BLANK_NORMAL) { |
| 398 | /* Power on the backlight with the requested brightness |
| 399 | * Note We can not use mipi_dsi_dcs_set_display_brightness() |
| 400 | * as otm8009a driver support only 8-bit brightness (1 param). |
| 401 | */ |
| 402 | data[0] = MIPI_DCS_SET_DISPLAY_BRIGHTNESS; |
| 403 | data[1] = bd->props.brightness; |
Philippe CORNU | d9f9565 | 2018-04-23 16:10:50 +0200 | [diff] [blame^] | 404 | otm8009a_dcs_write_buf_hs(ctx, data, ARRAY_SIZE(data)); |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 405 | |
| 406 | /* set Brightness Control & Backlight on */ |
| 407 | data[1] = 0x24; |
| 408 | |
| 409 | } else { |
| 410 | /* Power off the backlight: set Brightness Control & Bl off */ |
| 411 | data[1] = 0; |
| 412 | } |
| 413 | |
| 414 | /* Update Brightness Control & Backlight */ |
| 415 | data[0] = MIPI_DCS_WRITE_CONTROL_DISPLAY; |
Philippe CORNU | d9f9565 | 2018-04-23 16:10:50 +0200 | [diff] [blame^] | 416 | otm8009a_dcs_write_buf_hs(ctx, data, ARRAY_SIZE(data)); |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static const struct backlight_ops otm8009a_backlight_ops = { |
| 422 | .update_status = otm8009a_backlight_update_status, |
| 423 | }; |
| 424 | |
| 425 | static int otm8009a_probe(struct mipi_dsi_device *dsi) |
| 426 | { |
| 427 | struct device *dev = &dsi->dev; |
| 428 | struct otm8009a *ctx; |
| 429 | int ret; |
| 430 | |
| 431 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 432 | if (!ctx) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | ctx->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); |
| 436 | if (IS_ERR(ctx->reset_gpio)) { |
| 437 | dev_err(dev, "cannot get reset-gpio\n"); |
| 438 | return PTR_ERR(ctx->reset_gpio); |
| 439 | } |
| 440 | |
Philippe CORNU | ded8d7f | 2018-02-05 10:45:32 +0100 | [diff] [blame] | 441 | ctx->supply = devm_regulator_get(dev, "power"); |
| 442 | if (IS_ERR(ctx->supply)) { |
| 443 | ret = PTR_ERR(ctx->supply); |
| 444 | dev_err(dev, "failed to request regulator: %d\n", ret); |
| 445 | return ret; |
| 446 | } |
| 447 | |
Philippe CORNU | f0a5bb9 | 2017-07-17 15:19:53 +0200 | [diff] [blame] | 448 | mipi_dsi_set_drvdata(dsi, ctx); |
| 449 | |
| 450 | ctx->dev = dev; |
| 451 | |
| 452 | dsi->lanes = 2; |
| 453 | dsi->format = MIPI_DSI_FMT_RGB888; |
| 454 | dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | |
| 455 | MIPI_DSI_MODE_LPM; |
| 456 | |
| 457 | drm_panel_init(&ctx->panel); |
| 458 | ctx->panel.dev = dev; |
| 459 | ctx->panel.funcs = &otm8009a_drm_funcs; |
| 460 | |
| 461 | ctx->bl_dev = backlight_device_register(DRV_NAME "_backlight", dev, ctx, |
| 462 | &otm8009a_backlight_ops, NULL); |
| 463 | if (IS_ERR(ctx->bl_dev)) { |
| 464 | dev_err(dev, "failed to register backlight device\n"); |
| 465 | return PTR_ERR(ctx->bl_dev); |
| 466 | } |
| 467 | |
| 468 | ctx->bl_dev->props.max_brightness = OTM8009A_BACKLIGHT_MAX; |
| 469 | ctx->bl_dev->props.brightness = OTM8009A_BACKLIGHT_DEFAULT; |
| 470 | ctx->bl_dev->props.power = FB_BLANK_POWERDOWN; |
| 471 | ctx->bl_dev->props.type = BACKLIGHT_RAW; |
| 472 | |
| 473 | drm_panel_add(&ctx->panel); |
| 474 | |
| 475 | ret = mipi_dsi_attach(dsi); |
| 476 | if (ret < 0) { |
| 477 | dev_err(dev, "mipi_dsi_attach failed. Is host ready?\n"); |
| 478 | drm_panel_remove(&ctx->panel); |
| 479 | backlight_device_unregister(ctx->bl_dev); |
| 480 | return ret; |
| 481 | } |
| 482 | |
| 483 | DRM_INFO(DRV_NAME "_panel %ux%u@%u %ubpp dsi %udl - ready\n", |
| 484 | default_mode.hdisplay, default_mode.vdisplay, |
| 485 | default_mode.vrefresh, |
| 486 | mipi_dsi_pixel_format_to_bpp(dsi->format), dsi->lanes); |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static int otm8009a_remove(struct mipi_dsi_device *dsi) |
| 492 | { |
| 493 | struct otm8009a *ctx = mipi_dsi_get_drvdata(dsi); |
| 494 | |
| 495 | mipi_dsi_detach(dsi); |
| 496 | drm_panel_remove(&ctx->panel); |
| 497 | |
| 498 | backlight_device_unregister(ctx->bl_dev); |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | static const struct of_device_id orisetech_otm8009a_of_match[] = { |
| 504 | { .compatible = "orisetech,otm8009a" }, |
| 505 | { } |
| 506 | }; |
| 507 | MODULE_DEVICE_TABLE(of, orisetech_otm8009a_of_match); |
| 508 | |
| 509 | static struct mipi_dsi_driver orisetech_otm8009a_driver = { |
| 510 | .probe = otm8009a_probe, |
| 511 | .remove = otm8009a_remove, |
| 512 | .driver = { |
| 513 | .name = DRV_NAME "_panel", |
| 514 | .of_match_table = orisetech_otm8009a_of_match, |
| 515 | }, |
| 516 | }; |
| 517 | module_mipi_dsi_driver(orisetech_otm8009a_driver); |
| 518 | |
| 519 | MODULE_AUTHOR("Philippe Cornu <philippe.cornu@st.com>"); |
| 520 | MODULE_AUTHOR("Yannick Fertre <yannick.fertre@st.com>"); |
| 521 | MODULE_DESCRIPTION("DRM driver for Orise Tech OTM8009A MIPI DSI panel"); |
| 522 | MODULE_LICENSE("GPL v2"); |