]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/demo/demo-shape.c
d908736cffe31e2acb1bfa787bc12b05265543b7
2 * Copyright (c) 2013 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
16 DECLARE_GLOBAL_DATA_PTR
;
23 int num_chars
; /* Number of non-space characters output so far */
24 struct gpio_desc gpio_desc
[8];
28 /* Crazy little function to draw shapes on the console */
29 static int shape_hello(struct udevice
*dev
, int ch
)
31 const struct dm_demo_pdata
*pdata
= dev_get_platdata(dev
);
32 struct shape_data
*data
= dev_get_priv(dev
);
33 static const struct shape
{
41 { HEIGHT
/ 2 - 1, WIDTH
- HEIGHT
/ 2 + 1, -1, 1},
45 int line
, pos
, inside
;
46 const char *colour
= pdata
->colour
;
50 ch
= pdata
->default_char
;
54 index
= (pdata
->sides
/ 2) - 1;
55 if (index
>= ARRAY_SIZE(shapes
))
57 shape
= shapes
[index
];
59 for (line
= 0; line
< HEIGHT
; line
++) {
61 for (pos
= 0; pos
< WIDTH
; pos
++) {
62 inside
= pos
>= shape
.start
&& pos
< shape
.end
;
64 putc(first
? *colour
++ : ch
);
68 colour
= pdata
->colour
;
74 shape
.start
+= shape
.dstart
;
75 shape
.end
+= shape
.dend
;
76 if (shape
.start
< 0) {
77 shape
.dstart
= -shape
.dstart
;
78 shape
.dend
= -shape
.dend
;
79 shape
.start
+= shape
.dstart
;
80 shape
.end
+= shape
.dend
;
87 static int shape_status(struct udevice
*dev
, int *status
)
89 struct shape_data
*data
= dev_get_priv(dev
);
91 *status
= data
->num_chars
;
95 static int set_light(struct udevice
*dev
, int light
)
97 struct shape_data
*priv
= dev_get_priv(dev
);
98 struct gpio_desc
*desc
;
102 desc
= priv
->gpio_desc
;
103 for (i
= 0; i
< priv
->gpio_count
; i
++, desc
++) {
106 ret
= dm_gpio_set_value(desc
, light
& mask
);
114 static int get_light(struct udevice
*dev
)
116 struct shape_data
*priv
= dev_get_priv(dev
);
117 struct gpio_desc
*desc
;
122 desc
= priv
->gpio_desc
;
123 for (i
= 0; i
< priv
->gpio_count
; i
++, desc
++) {
126 ret
= dm_gpio_get_value(desc
);
136 static const struct demo_ops shape_ops
= {
137 .hello
= shape_hello
,
138 .status
= shape_status
,
139 .get_light
= get_light
,
140 .set_light
= set_light
,
143 static int shape_ofdata_to_platdata(struct udevice
*dev
)
145 struct dm_demo_pdata
*pdata
= dev_get_platdata(dev
);
148 /* Parse the data that is common with all demo devices */
149 ret
= demo_parse_dt(dev
);
153 /* Parse the data that only we need */
154 pdata
->default_char
= fdtdec_get_int(gd
->fdt_blob
, dev
->of_offset
,
160 static int dm_shape_probe(struct udevice
*dev
)
162 struct shape_data
*priv
= dev_get_priv(dev
);
165 ret
= gpio_request_list_by_name(dev
, "light-gpios", priv
->gpio_desc
,
166 ARRAY_SIZE(priv
->gpio_desc
),
167 GPIOD_IS_OUT
| GPIOD_IS_OUT_ACTIVE
);
170 priv
->gpio_count
= ret
;
171 debug("%s: %d GPIOs\n", __func__
, priv
->gpio_count
);
176 static int dm_shape_remove(struct udevice
*dev
)
178 struct shape_data
*priv
= dev_get_priv(dev
);
180 return gpio_free_list(dev
, priv
->gpio_desc
, priv
->gpio_count
);
183 static const struct udevice_id demo_shape_id
[] = {
188 U_BOOT_DRIVER(demo_shape_drv
) = {
189 .name
= "demo_shape_drv",
190 .of_match
= demo_shape_id
,
192 .ofdata_to_platdata
= shape_ofdata_to_platdata
,
194 .probe
= dm_shape_probe
,
195 .remove
= dm_shape_remove
,
196 .priv_auto_alloc_size
= sizeof(struct shape_data
),
197 .platdata_auto_alloc_size
= sizeof(struct dm_demo_pdata
),