blob: 815f8de6453bcc4d222619ef7fd8e05c0f19d0bc [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass39f76112014-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 Glass39f76112014-02-26 15:59:23 -07007 */
8
9#include <common.h>
10#include <dm.h>
11#include <dm-demo.h>
12#include <errno.h>
13#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Simon Glass39f76112014-02-26 15:59:23 -070015#include <malloc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Simon Glass39f76112014-02-26 15:59:23 -070017#include <asm/io.h>
18#include <linux/list.h>
19
20DECLARE_GLOBAL_DATA_PTR;
21
22UCLASS_DRIVER(demo) = {
Simon Glass74f96da2014-07-23 06:55:24 -060023 .name = "demo",
Simon Glass39f76112014-02-26 15:59:23 -070024 .id = UCLASS_DEMO,
25};
26
Heiko Schocher54c5d082014-05-22 12:43:05 +020027int demo_hello(struct udevice *dev, int ch)
Simon Glass39f76112014-02-26 15:59:23 -070028{
29 const struct demo_ops *ops = device_get_ops(dev);
30
31 if (!ops->hello)
32 return -ENOSYS;
33
34 return ops->hello(dev, ch);
35}
36
Heiko Schocher54c5d082014-05-22 12:43:05 +020037int demo_status(struct udevice *dev, int *status)
Simon Glass39f76112014-02-26 15:59:23 -070038{
39 const struct demo_ops *ops = device_get_ops(dev);
40
41 if (!ops->status)
42 return -ENOSYS;
43
44 return ops->status(dev, status);
45}
46
Simon Glassa02af4a2015-01-05 20:05:31 -070047int demo_get_light(struct udevice *dev)
48{
49 const struct demo_ops *ops = device_get_ops(dev);
50
51 if (!ops->get_light)
52 return -ENOSYS;
53
54 return ops->get_light(dev);
55}
56
57int demo_set_light(struct udevice *dev, int light)
58{
59 const struct demo_ops *ops = device_get_ops(dev);
60
61 if (!ops->set_light)
62 return -ENOSYS;
63
64 return ops->set_light(dev, light);
65}
66
Heiko Schocher54c5d082014-05-22 12:43:05 +020067int demo_parse_dt(struct udevice *dev)
Simon Glass39f76112014-02-26 15:59:23 -070068{
Simon Glassc69cda22020-12-03 16:55:20 -070069 struct dm_demo_pdata *pdata = dev_get_plat(dev);
Simon Glasse160f7d2017-01-17 16:52:55 -070070 int dn = dev_of_offset(dev);
Simon Glass39f76112014-02-26 15:59:23 -070071
72 pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
73 pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
74 if (!pdata->sides || !pdata->colour) {
75 debug("%s: Invalid device tree data\n", __func__);
76 return -EINVAL;
77 }
78
79 return 0;
80}