1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  *
5  * (C) Copyright 2012
6  * Pavel Herrmann <morpheus.ibis@gmail.com>
7  */
8 
9 #include <dm.h>
10 #include <dm-demo.h>
11 #include <errno.h>
12 #include <log.h>
13 #include <malloc.h>
14 #include <asm/io.h>
15 #include <linux/list.h>
16 
17 UCLASS_DRIVER(demo) = {
18 	.name		= "demo",
19 	.id		= UCLASS_DEMO,
20 };
21 
demo_hello(struct udevice * dev,int ch)22 int demo_hello(struct udevice *dev, int ch)
23 {
24 	const struct demo_ops *ops = device_get_ops(dev);
25 
26 	if (!ops->hello)
27 		return -ENOSYS;
28 
29 	return ops->hello(dev, ch);
30 }
31 
demo_status(struct udevice * dev,int * status)32 int demo_status(struct udevice *dev, int *status)
33 {
34 	const struct demo_ops *ops = device_get_ops(dev);
35 
36 	if (!ops->status)
37 		return -ENOSYS;
38 
39 	return ops->status(dev, status);
40 }
41 
demo_get_light(struct udevice * dev)42 int demo_get_light(struct udevice *dev)
43 {
44 	const struct demo_ops *ops = device_get_ops(dev);
45 
46 	if (!ops->get_light)
47 		return -ENOSYS;
48 
49 	return ops->get_light(dev);
50 }
51 
demo_set_light(struct udevice * dev,int light)52 int demo_set_light(struct udevice *dev, int light)
53 {
54 	const struct demo_ops *ops = device_get_ops(dev);
55 
56 	if (!ops->set_light)
57 		return -ENOSYS;
58 
59 	return ops->set_light(dev, light);
60 }
61 
demo_parse_dt(struct udevice * dev)62 int demo_parse_dt(struct udevice *dev)
63 {
64 	struct dm_demo_pdata *pdata = dev_get_plat(dev);
65 
66 	pdata->sides = dev_read_s32_default(dev, "sides", 0);
67 	pdata->colour = dev_read_string(dev, "colour");
68 	if (!pdata->sides || !pdata->colour) {
69 		debug("%s: Invalid device tree data\n", __func__);
70 		return -EINVAL;
71 	}
72 
73 	return 0;
74 }
75