|
31 | 31 | #include <linux/pci.h> |
32 | 32 | #include <linux/slab.h> |
33 | 33 | #include <video/edid.h> |
| 34 | +#include <video/of_videomode.h> |
| 35 | +#include <video/videomode.h> |
34 | 36 | #ifdef CONFIG_PPC_OF |
35 | 37 | #include <asm/prom.h> |
36 | 38 | #include <asm/pci-bridge.h> |
@@ -1373,6 +1375,98 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf |
1373 | 1375 | kfree(timings); |
1374 | 1376 | return err; |
1375 | 1377 | } |
| 1378 | + |
| 1379 | +#if IS_ENABLED(CONFIG_VIDEOMODE) |
| 1380 | +int fb_videomode_from_videomode(const struct videomode *vm, |
| 1381 | + struct fb_videomode *fbmode) |
| 1382 | +{ |
| 1383 | + unsigned int htotal, vtotal; |
| 1384 | + |
| 1385 | + fbmode->xres = vm->hactive; |
| 1386 | + fbmode->left_margin = vm->hback_porch; |
| 1387 | + fbmode->right_margin = vm->hfront_porch; |
| 1388 | + fbmode->hsync_len = vm->hsync_len; |
| 1389 | + |
| 1390 | + fbmode->yres = vm->vactive; |
| 1391 | + fbmode->upper_margin = vm->vback_porch; |
| 1392 | + fbmode->lower_margin = vm->vfront_porch; |
| 1393 | + fbmode->vsync_len = vm->vsync_len; |
| 1394 | + |
| 1395 | + /* prevent division by zero in KHZ2PICOS macro */ |
| 1396 | + fbmode->pixclock = vm->pixelclock ? |
| 1397 | + KHZ2PICOS(vm->pixelclock / 1000) : 0; |
| 1398 | + |
| 1399 | + fbmode->sync = 0; |
| 1400 | + fbmode->vmode = 0; |
| 1401 | + if (vm->dmt_flags & VESA_DMT_HSYNC_HIGH) |
| 1402 | + fbmode->sync |= FB_SYNC_HOR_HIGH_ACT; |
| 1403 | + if (vm->dmt_flags & VESA_DMT_HSYNC_HIGH) |
| 1404 | + fbmode->sync |= FB_SYNC_VERT_HIGH_ACT; |
| 1405 | + if (vm->data_flags & DISPLAY_FLAGS_INTERLACED) |
| 1406 | + fbmode->vmode |= FB_VMODE_INTERLACED; |
| 1407 | + if (vm->data_flags & DISPLAY_FLAGS_DOUBLESCAN) |
| 1408 | + fbmode->vmode |= FB_VMODE_DOUBLE; |
| 1409 | + fbmode->flag = 0; |
| 1410 | + |
| 1411 | + htotal = vm->hactive + vm->hfront_porch + vm->hback_porch + |
| 1412 | + vm->hsync_len; |
| 1413 | + vtotal = vm->vactive + vm->vfront_porch + vm->vback_porch + |
| 1414 | + vm->vsync_len; |
| 1415 | + /* prevent division by zero */ |
| 1416 | + if (htotal && vtotal) { |
| 1417 | + fbmode->refresh = vm->pixelclock / (htotal * vtotal); |
| 1418 | + /* a mode must have htotal and vtotal != 0 or it is invalid */ |
| 1419 | + } else { |
| 1420 | + fbmode->refresh = 0; |
| 1421 | + return -EINVAL; |
| 1422 | + } |
| 1423 | + |
| 1424 | + return 0; |
| 1425 | +} |
| 1426 | +EXPORT_SYMBOL_GPL(fb_videomode_from_videomode); |
| 1427 | +#endif |
| 1428 | + |
| 1429 | +#if IS_ENABLED(CONFIG_OF_VIDEOMODE) |
| 1430 | +static inline void dump_fb_videomode(const struct fb_videomode *m) |
| 1431 | +{ |
| 1432 | + pr_debug("fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u %u\n", |
| 1433 | + m->xres, m->yres, m->refresh, m->pixclock, m->left_margin, |
| 1434 | + m->right_margin, m->upper_margin, m->lower_margin, |
| 1435 | + m->hsync_len, m->vsync_len, m->sync, m->vmode, m->flag); |
| 1436 | +} |
| 1437 | + |
| 1438 | +/** |
| 1439 | + * of_get_fb_videomode - get a fb_videomode from devicetree |
| 1440 | + * @np: device_node with the timing specification |
| 1441 | + * @fb: will be set to the return value |
| 1442 | + * @index: index into the list of display timings in devicetree |
| 1443 | + * |
| 1444 | + * DESCRIPTION: |
| 1445 | + * This function is expensive and should only be used, if only one mode is to be |
| 1446 | + * read from DT. To get multiple modes start with of_get_display_timings ond |
| 1447 | + * work with that instead. |
| 1448 | + */ |
| 1449 | +int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb, |
| 1450 | + int index) |
| 1451 | +{ |
| 1452 | + struct videomode vm; |
| 1453 | + int ret; |
| 1454 | + |
| 1455 | + ret = of_get_videomode(np, &vm, index); |
| 1456 | + if (ret) |
| 1457 | + return ret; |
| 1458 | + |
| 1459 | + fb_videomode_from_videomode(&vm, fb); |
| 1460 | + |
| 1461 | + pr_debug("%s: got %dx%d display mode from %s\n", |
| 1462 | + of_node_full_name(np), vm.hactive, vm.vactive, np->name); |
| 1463 | + dump_fb_videomode(fb); |
| 1464 | + |
| 1465 | + return 0; |
| 1466 | +} |
| 1467 | +EXPORT_SYMBOL_GPL(of_get_fb_videomode); |
| 1468 | +#endif |
| 1469 | + |
1376 | 1470 | #else |
1377 | 1471 | int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var) |
1378 | 1472 | { |
|
0 commit comments