xref: /openbmc/u-boot/drivers/demo/demo-uclass.c (revision dfb42fc9)
1 /*
2  * Copyright (c) 2013 Google, Inc
3  *
4  * (C) Copyright 2012
5  * Pavel Herrmann <morpheus.ibis@gmail.com>
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <dm.h>
12 #include <dm-demo.h>
13 #include <errno.h>
14 #include <fdtdec.h>
15 #include <malloc.h>
16 #include <asm/io.h>
17 #include <linux/list.h>
18 
19 DECLARE_GLOBAL_DATA_PTR;
20 
21 UCLASS_DRIVER(demo) = {
22 	.id		= UCLASS_DEMO,
23 };
24 
25 int demo_hello(struct device *dev, int ch)
26 {
27 	const struct demo_ops *ops = device_get_ops(dev);
28 
29 	if (!ops->hello)
30 		return -ENOSYS;
31 
32 	return ops->hello(dev, ch);
33 }
34 
35 int demo_status(struct device *dev, int *status)
36 {
37 	const struct demo_ops *ops = device_get_ops(dev);
38 
39 	if (!ops->status)
40 		return -ENOSYS;
41 
42 	return ops->status(dev, status);
43 }
44 
45 int demo_parse_dt(struct device *dev)
46 {
47 	struct dm_demo_pdata *pdata = dev_get_platdata(dev);
48 	int dn = dev->of_offset;
49 
50 	pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
51 	pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
52 	if (!pdata->sides || !pdata->colour) {
53 		debug("%s: Invalid device tree data\n", __func__);
54 		return -EINVAL;
55 	}
56 
57 	return 0;
58 }
59