Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Simplefb device tree support |
| 3 | * |
| 4 | * (C) Copyright 2015 |
| 5 | * Stephen Warren <swarren@wwwdotorg.org> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 12 | #include <lcd.h> |
| 13 | #include <fdt_support.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 15 | #include <video.h> |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | static int lcd_dt_simplefb_configure_node(void *blob, int off) |
| 20 | { |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 21 | int xsize, ysize; |
| 22 | int bpix; /* log2 of bits per pixel */ |
| 23 | const char *name; |
| 24 | ulong fb_base; |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 25 | #ifdef CONFIG_DM_VIDEO |
| 26 | struct video_uc_platdata *plat; |
| 27 | struct video_priv *uc_priv; |
| 28 | struct udevice *dev; |
| 29 | int ret; |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 30 | |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 31 | ret = uclass_first_device_err(UCLASS_VIDEO, &dev); |
| 32 | if (ret) |
| 33 | return ret; |
| 34 | uc_priv = dev_get_uclass_priv(dev); |
| 35 | plat = dev_get_uclass_platdata(dev); |
| 36 | xsize = uc_priv->xsize; |
| 37 | ysize = uc_priv->ysize; |
| 38 | bpix = uc_priv->bpix; |
| 39 | fb_base = plat->base; |
| 40 | #else |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 41 | xsize = lcd_get_pixel_width(); |
| 42 | ysize = lcd_get_pixel_height(); |
| 43 | bpix = LCD_BPP; |
| 44 | fb_base = gd->fb_base; |
Simon Glass | 55a6307 | 2017-04-05 16:23:43 -0600 | [diff] [blame] | 45 | #endif |
Simon Glass | d2ed433 | 2017-04-05 16:23:42 -0600 | [diff] [blame] | 46 | switch (bpix) { |
| 47 | case 4: /* VIDEO_BPP16 */ |
| 48 | name = "r5g6b5"; |
| 49 | break; |
| 50 | case 5: /* VIDEO_BPP32 */ |
| 51 | name = "a8r8g8b8"; |
| 52 | break; |
| 53 | default: |
| 54 | return -EINVAL; |
| 55 | } |
| 56 | |
| 57 | return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize, |
| 58 | xsize * (1 << bpix) / 8, name); |
Nikita Kiryanov | b071e4c | 2015-02-03 13:32:31 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | int lcd_dt_simplefb_add_node(void *blob) |
| 62 | { |
| 63 | static const char compat[] = "simple-framebuffer"; |
| 64 | static const char disabled[] = "disabled"; |
| 65 | int off, ret; |
| 66 | |
| 67 | off = fdt_add_subnode(blob, 0, "framebuffer"); |
| 68 | if (off < 0) |
| 69 | return -1; |
| 70 | |
| 71 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); |
| 72 | if (ret < 0) |
| 73 | return -1; |
| 74 | |
| 75 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); |
| 76 | if (ret < 0) |
| 77 | return -1; |
| 78 | |
| 79 | return lcd_dt_simplefb_configure_node(blob, off); |
| 80 | } |
| 81 | |
| 82 | int lcd_dt_simplefb_enable_existing_node(void *blob) |
| 83 | { |
| 84 | int off; |
| 85 | |
| 86 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 87 | if (off < 0) |
| 88 | return -1; |
| 89 | |
| 90 | return lcd_dt_simplefb_configure_node(blob, off); |
| 91 | } |