blob: d7b1305dc65df180f8db8b434cde578374ad6f2a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass63b17572014-02-26 15:59:23 -07002/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
Simon Glass63b17572014-02-26 15:59:23 -07007 */
8
Simon Glass63b17572014-02-26 15:59:23 -07009#include <dm.h>
10#include <dm-demo.h>
11#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass63b17572014-02-26 15:59:23 -070013#include <malloc.h>
14#include <asm/io.h>
15#include <linux/list.h>
16
Simon Glass63b17572014-02-26 15:59:23 -070017UCLASS_DRIVER(demo) = {
Simon Glass54e3cdb2014-07-23 06:55:24 -060018 .name = "demo",
Simon Glass63b17572014-02-26 15:59:23 -070019 .id = UCLASS_DEMO,
20};
21
Heiko Schocherb74fcb42014-05-22 12:43:05 +020022int demo_hello(struct udevice *dev, int ch)
Simon Glass63b17572014-02-26 15:59:23 -070023{
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
Heiko Schocherb74fcb42014-05-22 12:43:05 +020032int demo_status(struct udevice *dev, int *status)
Simon Glass63b17572014-02-26 15:59:23 -070033{
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
Simon Glass120834d2015-01-05 20:05:31 -070042int 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
52int 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
Heiko Schocherb74fcb42014-05-22 12:43:05 +020062int demo_parse_dt(struct udevice *dev)
Simon Glass63b17572014-02-26 15:59:23 -070063{
Simon Glassfa20e932020-12-03 16:55:20 -070064 struct dm_demo_pdata *pdata = dev_get_plat(dev);
Simon Glass63b17572014-02-26 15:59:23 -070065
Patrick Delaunay185bb7e2021-09-20 17:58:33 +020066 pdata->sides = dev_read_s32_default(dev, "sides", 0);
67 pdata->colour = dev_read_string(dev, "colour");
Simon Glass63b17572014-02-26 15:59:23 -070068 if (!pdata->sides || !pdata->colour) {
69 debug("%s: Invalid device tree data\n", __func__);
70 return -EINVAL;
71 }
72
73 return 0;
74}