]> git.ipfire.org Git - people/ms/u-boot.git/blame - drivers/demo/demo-uclass.c
dm: core: Replace of_offset with accessor
[people/ms/u-boot.git] / drivers / demo / demo-uclass.c
CommitLineData
39f7611f
SG
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
19DECLARE_GLOBAL_DATA_PTR;
20
21UCLASS_DRIVER(demo) = {
74f96dad 22 .name = "demo",
39f7611f
SG
23 .id = UCLASS_DEMO,
24};
25
54c5d08a 26int demo_hello(struct udevice *dev, int ch)
39f7611f
SG
27{
28 const struct demo_ops *ops = device_get_ops(dev);
29
30 if (!ops->hello)
31 return -ENOSYS;
32
33 return ops->hello(dev, ch);
34}
35
54c5d08a 36int demo_status(struct udevice *dev, int *status)
39f7611f
SG
37{
38 const struct demo_ops *ops = device_get_ops(dev);
39
40 if (!ops->status)
41 return -ENOSYS;
42
43 return ops->status(dev, status);
44}
45
a02af4ae
SG
46int demo_get_light(struct udevice *dev)
47{
48 const struct demo_ops *ops = device_get_ops(dev);
49
50 if (!ops->get_light)
51 return -ENOSYS;
52
53 return ops->get_light(dev);
54}
55
56int demo_set_light(struct udevice *dev, int light)
57{
58 const struct demo_ops *ops = device_get_ops(dev);
59
60 if (!ops->set_light)
61 return -ENOSYS;
62
63 return ops->set_light(dev, light);
64}
65
54c5d08a 66int demo_parse_dt(struct udevice *dev)
39f7611f
SG
67{
68 struct dm_demo_pdata *pdata = dev_get_platdata(dev);
e160f7d4 69 int dn = dev_of_offset(dev);
39f7611f
SG
70
71 pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
72 pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
73 if (!pdata->sides || !pdata->colour) {
74 debug("%s: Invalid device tree data\n", __func__);
75 return -EINVAL;
76 }
77
78 return 0;
79}