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