panel-simple.c (9d4d8572a539ef807e21c196f145aa365fd52f0e) | panel-simple.c (5dd331d4d8caa62624b7b025332ce64feea4192b) |
---|---|
1/* 2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sub license, 8 * and/or sell copies of the Software, and to permit persons to whom the --- 25 unchanged lines hidden (view full) --- 34#include <video/videomode.h> 35 36#include <drm/drm_crtc.h> 37#include <drm/drm_device.h> 38#include <drm/drm_mipi_dsi.h> 39#include <drm/drm_panel.h> 40 41/** | 1/* 2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sub license, 8 * and/or sell copies of the Software, and to permit persons to whom the --- 25 unchanged lines hidden (view full) --- 34#include <video/videomode.h> 35 36#include <drm/drm_crtc.h> 37#include <drm/drm_device.h> 38#include <drm/drm_mipi_dsi.h> 39#include <drm/drm_panel.h> 40 41/** |
42 * struct panel_desc 43 * @modes: Pointer to array of fixed modes appropriate for this panel. If 44 * only one mode then this can just be the address of this the mode. 45 * NOTE: cannot be used with "timings" and also if this is specified 46 * then you cannot override the mode in the device tree. 47 * @num_modes: Number of elements in modes array. 48 * @timings: Pointer to array of display timings. NOTE: cannot be used with 49 * "modes" and also these will be used to validate a device tree 50 * override if one is present. 51 * @num_timings: Number of elements in timings array. 52 * @bpc: Bits per color. 53 * @size: Structure containing the physical size of this panel. 54 * @delay: Structure containing various delay values for this panel. 55 * @bus_format: See MEDIA_BUS_FMT_... defines. 56 * @bus_flags: See DRM_BUS_FLAG_... defines. 57 * @connector_type: LVDS, eDP, DSI, DPI, etc. | 42 * struct panel_desc - Describes a simple panel. |
58 */ 59struct panel_desc { | 43 */ 44struct panel_desc { |
45 /** 46 * @modes: Pointer to array of fixed modes appropriate for this panel. 47 * 48 * If only one mode then this can just be the address of the mode. 49 * NOTE: cannot be used with "timings" and also if this is specified 50 * then you cannot override the mode in the device tree. 51 */ |
|
60 const struct drm_display_mode *modes; | 52 const struct drm_display_mode *modes; |
53 54 /** @num_modes: Number of elements in modes array. */ |
|
61 unsigned int num_modes; | 55 unsigned int num_modes; |
56 57 /** 58 * @timings: Pointer to array of display timings 59 * 60 * NOTE: cannot be used with "modes" and also these will be used to 61 * validate a device tree override if one is present. 62 */ |
|
62 const struct display_timing *timings; | 63 const struct display_timing *timings; |
64 65 /** @num_timings: Number of elements in timings array. */ |
|
63 unsigned int num_timings; 64 | 66 unsigned int num_timings; 67 |
68 /** @bpc: Bits per color. */ |
|
65 unsigned int bpc; 66 | 69 unsigned int bpc; 70 |
67 /** 68 * @width: width (in millimeters) of the panel's active display area 69 * @height: height (in millimeters) of the panel's active display area 70 */ | 71 /** @size: Structure containing the physical size of this panel. */ |
71 struct { | 72 struct { |
73 /** 74 * @size.width: Width (in mm) of the active display area. 75 */ |
|
72 unsigned int width; | 76 unsigned int width; |
77 78 /** 79 * @size.height: Height (in mm) of the active display area. 80 */ |
|
73 unsigned int height; 74 } size; 75 | 81 unsigned int height; 82 } size; 83 |
76 /** 77 * @prepare: the time (in milliseconds) that it takes for the panel to 78 * become ready and start receiving video data 79 * @hpd_absent_delay: Add this to the prepare delay if we know Hot 80 * Plug Detect isn't used. 81 * @enable: the time (in milliseconds) that it takes for the panel to 82 * display the first valid frame after starting to receive 83 * video data 84 * @disable: the time (in milliseconds) that it takes for the panel to 85 * turn the display off (no content is visible) 86 * @unprepare: the time (in milliseconds) that it takes for the panel 87 * to power itself down completely 88 */ | 84 /** @delay: Structure containing various delay values for this panel. */ |
89 struct { | 85 struct { |
86 /** 87 * @delay.prepare: Time for the panel to become ready. 88 * 89 * The time (in milliseconds) that it takes for the panel to 90 * become ready and start receiving video data 91 */ |
|
90 unsigned int prepare; | 92 unsigned int prepare; |
93 94 /** 95 * @delay.hpd_absent_delay: Time to wait if HPD isn't hooked up. 96 * 97 * Add this to the prepare delay if we know Hot Plug Detect 98 * isn't used. 99 */ |
|
91 unsigned int hpd_absent_delay; | 100 unsigned int hpd_absent_delay; |
101 102 /** 103 * @delay.prepare_to_enable: Time between prepare and enable. 104 * 105 * The minimum time, in milliseconds, that needs to have passed 106 * between when prepare finished and enable may begin. If at 107 * enable time less time has passed since prepare finished, 108 * the driver waits for the remaining time. 109 * 110 * If a fixed enable delay is also specified, we'll start 111 * counting before delaying for the fixed delay. 112 * 113 * If a fixed prepare delay is also specified, we won't start 114 * counting until after the fixed delay. We can't overlap this 115 * fixed delay with the min time because the fixed delay 116 * doesn't happen at the end of the function if a HPD GPIO was 117 * specified. 118 * 119 * In other words: 120 * prepare() 121 * ... 122 * // do fixed prepare delay 123 * // wait for HPD GPIO if applicable 124 * // start counting for prepare_to_enable 125 * 126 * enable() 127 * // do fixed enable delay 128 * // enforce prepare_to_enable min time 129 */ 130 unsigned int prepare_to_enable; 131 132 /** 133 * @delay.enable: Time for the panel to display a valid frame. 134 * 135 * The time (in milliseconds) that it takes for the panel to 136 * display the first valid frame after starting to receive 137 * video data. 138 */ |
|
92 unsigned int enable; | 139 unsigned int enable; |
140 141 /** 142 * @delay.disable: Time for the panel to turn the display off. 143 * 144 * The time (in milliseconds) that it takes for the panel to 145 * turn the display off (no content is visible). 146 */ |
|
93 unsigned int disable; | 147 unsigned int disable; |
148 149 /** 150 * @delay.unprepare: Time to power down completely. 151 * 152 * The time (in milliseconds) that it takes for the panel 153 * to power itself down completely. 154 * 155 * This time is used to prevent a future "prepare" from 156 * starting until at least this many milliseconds has passed. 157 * If at prepare time less time has passed since unprepare 158 * finished, the driver waits for the remaining time. 159 */ |
|
94 unsigned int unprepare; 95 } delay; 96 | 160 unsigned int unprepare; 161 } delay; 162 |
163 /** @bus_format: See MEDIA_BUS_FMT_... defines. */ |
|
97 u32 bus_format; | 164 u32 bus_format; |
165 166 /** @bus_flags: See DRM_BUS_FLAG_... defines. */ |
|
98 u32 bus_flags; | 167 u32 bus_flags; |
168 169 /** @connector_type: LVDS, eDP, DSI, DPI, etc. */ |
|
99 int connector_type; 100}; 101 102struct panel_simple { 103 struct drm_panel base; | 170 int connector_type; 171}; 172 173struct panel_simple { 174 struct drm_panel base; |
104 bool prepared; | |
105 bool enabled; 106 bool no_hpd; 107 | 175 bool enabled; 176 bool no_hpd; 177 |
178 ktime_t prepared_time; 179 ktime_t unprepared_time; 180 |
|
108 const struct panel_desc *desc; 109 110 struct regulator *supply; 111 struct i2c_adapter *ddc; 112 113 struct gpio_desc *enable_gpio; 114 struct gpio_desc *hpd_gpio; 115 --- 111 unchanged lines hidden (view full) --- 227 if (panel->desc->bus_format) 228 drm_display_info_set_bus_formats(&connector->display_info, 229 &panel->desc->bus_format, 1); 230 connector->display_info.bus_flags = panel->desc->bus_flags; 231 232 return num; 233} 234 | 181 const struct panel_desc *desc; 182 183 struct regulator *supply; 184 struct i2c_adapter *ddc; 185 186 struct gpio_desc *enable_gpio; 187 struct gpio_desc *hpd_gpio; 188 --- 111 unchanged lines hidden (view full) --- 300 if (panel->desc->bus_format) 301 drm_display_info_set_bus_formats(&connector->display_info, 302 &panel->desc->bus_format, 1); 303 connector->display_info.bus_flags = panel->desc->bus_flags; 304 305 return num; 306} 307 |
308static void panel_simple_wait(ktime_t start_ktime, unsigned int min_ms) 309{ 310 ktime_t now_ktime, min_ktime; 311 312 if (!min_ms) 313 return; 314 315 min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms)); 316 now_ktime = ktime_get(); 317 318 if (ktime_before(now_ktime, min_ktime)) 319 msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1); 320} 321 |
|
235static int panel_simple_disable(struct drm_panel *panel) 236{ 237 struct panel_simple *p = to_panel_simple(panel); 238 239 if (!p->enabled) 240 return 0; 241 242 if (p->desc->delay.disable) 243 msleep(p->desc->delay.disable); 244 245 p->enabled = false; 246 247 return 0; 248} 249 250static int panel_simple_unprepare(struct drm_panel *panel) 251{ 252 struct panel_simple *p = to_panel_simple(panel); 253 | 322static int panel_simple_disable(struct drm_panel *panel) 323{ 324 struct panel_simple *p = to_panel_simple(panel); 325 326 if (!p->enabled) 327 return 0; 328 329 if (p->desc->delay.disable) 330 msleep(p->desc->delay.disable); 331 332 p->enabled = false; 333 334 return 0; 335} 336 337static int panel_simple_unprepare(struct drm_panel *panel) 338{ 339 struct panel_simple *p = to_panel_simple(panel); 340 |
254 if (!p->prepared) | 341 if (p->prepared_time == 0) |
255 return 0; 256 257 gpiod_set_value_cansleep(p->enable_gpio, 0); 258 259 regulator_disable(p->supply); 260 | 342 return 0; 343 344 gpiod_set_value_cansleep(p->enable_gpio, 0); 345 346 regulator_disable(p->supply); 347 |
261 if (p->desc->delay.unprepare) 262 msleep(p->desc->delay.unprepare); | 348 p->prepared_time = 0; 349 p->unprepared_time = ktime_get(); |
263 | 350 |
264 p->prepared = false; 265 | |
266 return 0; 267} 268 269static int panel_simple_get_hpd_gpio(struct device *dev, 270 struct panel_simple *p, bool from_probe) 271{ 272 int err; 273 --- 19 unchanged lines hidden (view full) --- 293 294static int panel_simple_prepare(struct drm_panel *panel) 295{ 296 struct panel_simple *p = to_panel_simple(panel); 297 unsigned int delay; 298 int err; 299 int hpd_asserted; 300 | 351 return 0; 352} 353 354static int panel_simple_get_hpd_gpio(struct device *dev, 355 struct panel_simple *p, bool from_probe) 356{ 357 int err; 358 --- 19 unchanged lines hidden (view full) --- 378 379static int panel_simple_prepare(struct drm_panel *panel) 380{ 381 struct panel_simple *p = to_panel_simple(panel); 382 unsigned int delay; 383 int err; 384 int hpd_asserted; 385 |
301 if (p->prepared) | 386 if (p->prepared_time != 0) |
302 return 0; 303 | 387 return 0; 388 |
389 panel_simple_wait(p->unprepared_time, p->desc->delay.unprepare); 390 |
|
304 err = regulator_enable(p->supply); 305 if (err < 0) { 306 dev_err(panel->dev, "failed to enable supply: %d\n", err); 307 return err; 308 } 309 310 gpiod_set_value_cansleep(p->enable_gpio, 1); 311 --- 18 unchanged lines hidden (view full) --- 330 331 if (err) { 332 dev_err(panel->dev, 333 "error waiting for hpd GPIO: %d\n", err); 334 return err; 335 } 336 } 337 | 391 err = regulator_enable(p->supply); 392 if (err < 0) { 393 dev_err(panel->dev, "failed to enable supply: %d\n", err); 394 return err; 395 } 396 397 gpiod_set_value_cansleep(p->enable_gpio, 1); 398 --- 18 unchanged lines hidden (view full) --- 417 418 if (err) { 419 dev_err(panel->dev, 420 "error waiting for hpd GPIO: %d\n", err); 421 return err; 422 } 423 } 424 |
338 p->prepared = true; | 425 p->prepared_time = ktime_get(); |
339 340 return 0; 341} 342 343static int panel_simple_enable(struct drm_panel *panel) 344{ 345 struct panel_simple *p = to_panel_simple(panel); 346 347 if (p->enabled) 348 return 0; 349 350 if (p->desc->delay.enable) 351 msleep(p->desc->delay.enable); 352 | 426 427 return 0; 428} 429 430static int panel_simple_enable(struct drm_panel *panel) 431{ 432 struct panel_simple *p = to_panel_simple(panel); 433 434 if (p->enabled) 435 return 0; 436 437 if (p->desc->delay.enable) 438 msleep(p->desc->delay.enable); 439 |
440 panel_simple_wait(p->prepared_time, p->desc->delay.prepare_to_enable); 441 |
|
353 p->enabled = true; 354 355 return 0; 356} 357 358static int panel_simple_get_modes(struct drm_panel *panel, 359 struct drm_connector *connector) 360{ --- 150 unchanged lines hidden (view full) --- 511 u32 bus_flags; 512 int err; 513 514 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL); 515 if (!panel) 516 return -ENOMEM; 517 518 panel->enabled = false; | 442 p->enabled = true; 443 444 return 0; 445} 446 447static int panel_simple_get_modes(struct drm_panel *panel, 448 struct drm_connector *connector) 449{ --- 150 unchanged lines hidden (view full) --- 600 u32 bus_flags; 601 int err; 602 603 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL); 604 if (!panel) 605 return -ENOMEM; 606 607 panel->enabled = false; |
519 panel->prepared = false; | 608 panel->prepared_time = 0; |
520 panel->desc = desc; 521 522 panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd"); 523 if (!panel->no_hpd) { 524 err = panel_simple_get_hpd_gpio(dev, panel, true); 525 if (err) 526 return err; 527 } --- 785 unchanged lines hidden (view full) --- 1313 }, 1314 .delay = { 1315 .prepare = 210, 1316 .enable = 50, 1317 .unprepare = 160, 1318 }, 1319}; 1320 | 609 panel->desc = desc; 610 611 panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd"); 612 if (!panel->no_hpd) { 613 err = panel_simple_get_hpd_gpio(dev, panel, true); 614 if (err) 615 return err; 616 } --- 785 unchanged lines hidden (view full) --- 1402 }, 1403 .delay = { 1404 .prepare = 210, 1405 .enable = 50, 1406 .unprepare = 160, 1407 }, 1408}; 1409 |
1410static const struct drm_display_mode boe_nv110wtm_n61_modes[] = { 1411 { 1412 .clock = 207800, 1413 .hdisplay = 2160, 1414 .hsync_start = 2160 + 48, 1415 .hsync_end = 2160 + 48 + 32, 1416 .htotal = 2160 + 48 + 32 + 100, 1417 .vdisplay = 1440, 1418 .vsync_start = 1440 + 3, 1419 .vsync_end = 1440 + 3 + 6, 1420 .vtotal = 1440 + 3 + 6 + 31, 1421 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, 1422 }, 1423 { 1424 .clock = 138500, 1425 .hdisplay = 2160, 1426 .hsync_start = 2160 + 48, 1427 .hsync_end = 2160 + 48 + 32, 1428 .htotal = 2160 + 48 + 32 + 100, 1429 .vdisplay = 1440, 1430 .vsync_start = 1440 + 3, 1431 .vsync_end = 1440 + 3 + 6, 1432 .vtotal = 1440 + 3 + 6 + 31, 1433 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, 1434 }, 1435}; 1436 1437static const struct panel_desc boe_nv110wtm_n61 = { 1438 .modes = boe_nv110wtm_n61_modes, 1439 .num_modes = ARRAY_SIZE(boe_nv110wtm_n61_modes), 1440 .bpc = 8, 1441 .size = { 1442 .width = 233, 1443 .height = 155, 1444 }, 1445 .delay = { 1446 .hpd_absent_delay = 200, 1447 .prepare_to_enable = 80, 1448 .unprepare = 500, 1449 }, 1450 .bus_format = MEDIA_BUS_FMT_RGB888_1X24, 1451 .bus_flags = DRM_BUS_FLAG_DATA_MSB_TO_LSB, 1452 .connector_type = DRM_MODE_CONNECTOR_eDP, 1453}; 1454 |
|
1321/* Also used for boe_nv133fhm_n62 */ 1322static const struct drm_display_mode boe_nv133fhm_n61_modes = { 1323 .clock = 147840, 1324 .hdisplay = 1920, 1325 .hsync_start = 1920 + 48, 1326 .hsync_end = 1920 + 48 + 32, 1327 .htotal = 1920 + 48 + 32 + 200, 1328 .vdisplay = 1080, --- 931 unchanged lines hidden (view full) --- 2260static const struct panel_desc innolux_n116bge = { 2261 .timings = &innolux_n116bge_timing, 2262 .num_timings = 1, 2263 .bpc = 6, 2264 .size = { 2265 .width = 256, 2266 .height = 144, 2267 }, | 1455/* Also used for boe_nv133fhm_n62 */ 1456static const struct drm_display_mode boe_nv133fhm_n61_modes = { 1457 .clock = 147840, 1458 .hdisplay = 1920, 1459 .hsync_start = 1920 + 48, 1460 .hsync_end = 1920 + 48 + 32, 1461 .htotal = 1920 + 48 + 32 + 200, 1462 .vdisplay = 1080, --- 931 unchanged lines hidden (view full) --- 2394static const struct panel_desc innolux_n116bge = { 2395 .timings = &innolux_n116bge_timing, 2396 .num_timings = 1, 2397 .bpc = 6, 2398 .size = { 2399 .width = 256, 2400 .height = 144, 2401 }, |
2402 .bus_format = MEDIA_BUS_FMT_RGB666_1X18, 2403 .connector_type = DRM_MODE_CONNECTOR_eDP, |
|
2268}; 2269 2270static const struct drm_display_mode innolux_n125hce_gn1_mode = { 2271 .clock = 162000, 2272 .hdisplay = 1920, 2273 .hsync_start = 1920 + 40, 2274 .hsync_end = 1920 + 40 + 40, 2275 .htotal = 1920 + 40 + 40 + 80, --- 1753 unchanged lines hidden (view full) --- 4029 .data = &bananapi_s070wv20_ct16, 4030 }, { 4031 .compatible = "boe,hv070wsa-100", 4032 .data = &boe_hv070wsa 4033 }, { 4034 .compatible = "boe,nv101wxmn51", 4035 .data = &boe_nv101wxmn51, 4036 }, { | 2404}; 2405 2406static const struct drm_display_mode innolux_n125hce_gn1_mode = { 2407 .clock = 162000, 2408 .hdisplay = 1920, 2409 .hsync_start = 1920 + 40, 2410 .hsync_end = 1920 + 40 + 40, 2411 .htotal = 1920 + 40 + 40 + 80, --- 1753 unchanged lines hidden (view full) --- 4165 .data = &bananapi_s070wv20_ct16, 4166 }, { 4167 .compatible = "boe,hv070wsa-100", 4168 .data = &boe_hv070wsa 4169 }, { 4170 .compatible = "boe,nv101wxmn51", 4171 .data = &boe_nv101wxmn51, 4172 }, { |
4173 .compatible = "boe,nv110wtm-n61", 4174 .data = &boe_nv110wtm_n61, 4175 }, { |
|
4037 .compatible = "boe,nv133fhm-n61", 4038 .data = &boe_nv133fhm_n61, 4039 }, { 4040 .compatible = "boe,nv133fhm-n62", 4041 .data = &boe_nv133fhm_n61, 4042 }, { 4043 .compatible = "boe,nv140fhmn49", 4044 .data = &boe_nv140fhmn49, --- 611 unchanged lines hidden (view full) --- 4656 return err; 4657 4658 dsi->mode_flags = desc->flags; 4659 dsi->format = desc->format; 4660 dsi->lanes = desc->lanes; 4661 4662 err = mipi_dsi_attach(dsi); 4663 if (err) { | 4176 .compatible = "boe,nv133fhm-n61", 4177 .data = &boe_nv133fhm_n61, 4178 }, { 4179 .compatible = "boe,nv133fhm-n62", 4180 .data = &boe_nv133fhm_n61, 4181 }, { 4182 .compatible = "boe,nv140fhmn49", 4183 .data = &boe_nv140fhmn49, --- 611 unchanged lines hidden (view full) --- 4795 return err; 4796 4797 dsi->mode_flags = desc->flags; 4798 dsi->format = desc->format; 4799 dsi->lanes = desc->lanes; 4800 4801 err = mipi_dsi_attach(dsi); 4802 if (err) { |
4664 struct panel_simple *panel = dev_get_drvdata(&dsi->dev); | 4803 struct panel_simple *panel = mipi_dsi_get_drvdata(dsi); |
4665 4666 drm_panel_remove(&panel->base); 4667 } 4668 4669 return err; 4670} 4671 4672static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi) --- 57 unchanged lines hidden --- | 4804 4805 drm_panel_remove(&panel->base); 4806 } 4807 4808 return err; 4809} 4810 4811static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi) --- 57 unchanged lines hidden --- |