2 * Copyright (c) 2013 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
15 DECLARE_GLOBAL_DATA_PTR
;
22 int num_chars
; /* Number of non-space characters output so far */
25 /* Crazy little function to draw shapes on the console */
26 static int shape_hello(struct device
*dev
, int ch
)
28 const struct dm_demo_pdata
*pdata
= dev_get_platdata(dev
);
29 struct shape_data
*data
= dev_get_priv(dev
);
30 static const struct shape
{
38 { HEIGHT
/ 2 - 1, WIDTH
- HEIGHT
/ 2 + 1, -1, 1},
42 int line
, pos
, inside
;
43 const char *colour
= pdata
->colour
;
47 ch
= pdata
->default_char
;
51 index
= (pdata
->sides
/ 2) - 1;
52 if (index
>= ARRAY_SIZE(shapes
))
54 shape
= shapes
[index
];
56 for (line
= 0; line
< HEIGHT
; line
++) {
58 for (pos
= 0; pos
< WIDTH
; pos
++) {
59 inside
= pos
>= shape
.start
&& pos
< shape
.end
;
61 putc(first
? *colour
++ : ch
);
65 colour
= pdata
->colour
;
71 shape
.start
+= shape
.dstart
;
72 shape
.end
+= shape
.dend
;
73 if (shape
.start
< 0) {
74 shape
.dstart
= -shape
.dstart
;
75 shape
.dend
= -shape
.dend
;
76 shape
.start
+= shape
.dstart
;
77 shape
.end
+= shape
.dend
;
84 static int shape_status(struct device
*dev
, int *status
)
86 struct shape_data
*data
= dev_get_priv(dev
);
88 *status
= data
->num_chars
;
92 static const struct demo_ops shape_ops
= {
94 .status
= shape_status
,
97 static int shape_ofdata_to_platdata(struct device
*dev
)
99 struct dm_demo_pdata
*pdata
= dev_get_platdata(dev
);
102 /* Parse the data that is common with all demo devices */
103 ret
= demo_parse_dt(dev
);
107 /* Parse the data that only we need */
108 pdata
->default_char
= fdtdec_get_int(gd
->fdt_blob
, dev
->of_offset
,
114 static const struct device_id demo_shape_id
[] = {
119 U_BOOT_DRIVER(demo_shape_drv
) = {
120 .name
= "demo_shape_drv",
121 .of_match
= demo_shape_id
,
123 .ofdata_to_platdata
= shape_ofdata_to_platdata
,
125 .priv_auto_alloc_size
= sizeof(struct shape_data
),
126 .platdata_auto_alloc_size
= sizeof(struct dm_demo_pdata
),