firmware: PSCI: Fix PSCI support for OF live trees
[oweals/u-boot.git] / drivers / video / console_normal.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2015 Google, Inc
4  * (C) Copyright 2001-2015
5  * DENX Software Engineering -- wd@denx.de
6  * Compulab Ltd - http://compulab.co.il/
7  * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
8  */
9
10 #include <common.h>
11 #include <dm.h>
12 #include <video.h>
13 #include <video_console.h>
14 #include <video_font.h>         /* Get font data, width and height */
15
16 static int console_normal_set_row(struct udevice *dev, uint row, int clr)
17 {
18         struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
19         void *line;
20         int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
21         int i;
22
23         line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
24         switch (vid_priv->bpix) {
25         case VIDEO_BPP8:
26                 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
27                         uint8_t *dst = line;
28
29                         for (i = 0; i < pixels; i++)
30                                 *dst++ = clr;
31                         break;
32                 }
33         case VIDEO_BPP16:
34                 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
35                         uint16_t *dst = line;
36
37                         for (i = 0; i < pixels; i++)
38                                 *dst++ = clr;
39                         break;
40                 }
41         case VIDEO_BPP32:
42                 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
43                         uint32_t *dst = line;
44
45                         for (i = 0; i < pixels; i++)
46                                 *dst++ = clr;
47                         break;
48                 }
49         default:
50                 return -ENOSYS;
51         }
52
53         return 0;
54 }
55
56 static int console_normal_move_rows(struct udevice *dev, uint rowdst,
57                                      uint rowsrc, uint count)
58 {
59         struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
60         void *dst;
61         void *src;
62
63         dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
64         src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
65         memmove(dst, src, VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
66
67         return 0;
68 }
69
70 static int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y,
71                                   char ch)
72 {
73         struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
74         struct udevice *vid = dev->parent;
75         struct video_priv *vid_priv = dev_get_uclass_priv(vid);
76         int i, row;
77         void *line = vid_priv->fb + y * vid_priv->line_length +
78                 VID_TO_PIXEL(x_frac) * VNBYTES(vid_priv->bpix);
79
80         if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
81                 return -EAGAIN;
82
83         for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
84                 unsigned int idx = (u8)ch * VIDEO_FONT_HEIGHT + row;
85                 uchar bits = video_fontdata[idx];
86
87                 switch (vid_priv->bpix) {
88                 case VIDEO_BPP8:
89                         if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
90                                 uint8_t *dst = line;
91
92                                 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
93                                         *dst++ = (bits & 0x80) ?
94                                                 vid_priv->colour_fg :
95                                                 vid_priv->colour_bg;
96                                         bits <<= 1;
97                                 }
98                                 break;
99                         }
100                 case VIDEO_BPP16:
101                         if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
102                                 uint16_t *dst = line;
103
104                                 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
105                                         *dst++ = (bits & 0x80) ?
106                                                 vid_priv->colour_fg :
107                                                 vid_priv->colour_bg;
108                                         bits <<= 1;
109                                 }
110                                 break;
111                         }
112                 case VIDEO_BPP32:
113                         if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
114                                 uint32_t *dst = line;
115
116                                 for (i = 0; i < VIDEO_FONT_WIDTH; i++) {
117                                         *dst++ = (bits & 0x80) ?
118                                                 vid_priv->colour_fg :
119                                                 vid_priv->colour_bg;
120                                         bits <<= 1;
121                                 }
122                                 break;
123                         }
124                 default:
125                         return -ENOSYS;
126                 }
127                 line += vid_priv->line_length;
128         }
129
130         return VID_TO_POS(VIDEO_FONT_WIDTH);
131 }
132
133 static int console_normal_probe(struct udevice *dev)
134 {
135         struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
136         struct udevice *vid_dev = dev->parent;
137         struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
138
139         vc_priv->x_charsize = VIDEO_FONT_WIDTH;
140         vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
141         vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
142         vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
143
144         return 0;
145 }
146
147 struct vidconsole_ops console_normal_ops = {
148         .putc_xy        = console_normal_putc_xy,
149         .move_rows      = console_normal_move_rows,
150         .set_row        = console_normal_set_row,
151 };
152
153 U_BOOT_DRIVER(vidconsole_normal) = {
154         .name   = "vidconsole0",
155         .id     = UCLASS_VIDEO_CONSOLE,
156         .ops    = &console_normal_ops,
157         .probe  = console_normal_probe,
158 };