blob: f6510d602c83472695065b66c0f01e55f75b881b [file] [log] [blame]
Simon Glass63b17572014-02-26 15:59:23 -07001/*
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) = {
Simon Glass54e3cdb2014-07-23 06:55:24 -060022 .name = "demo",
Simon Glass63b17572014-02-26 15:59:23 -070023 .id = UCLASS_DEMO,
24};
25
Heiko Schocherb74fcb42014-05-22 12:43:05 +020026int demo_hello(struct udevice *dev, int ch)
Simon Glass63b17572014-02-26 15:59:23 -070027{
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
Heiko Schocherb74fcb42014-05-22 12:43:05 +020036int demo_status(struct udevice *dev, int *status)
Simon Glass63b17572014-02-26 15:59:23 -070037{
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
Heiko Schocherb74fcb42014-05-22 12:43:05 +020046int demo_parse_dt(struct udevice *dev)
Simon Glass63b17572014-02-26 15:59:23 -070047{
48 struct dm_demo_pdata *pdata = dev_get_platdata(dev);
49 int dn = dev->of_offset;
50
51 pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0);
52 pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL);
53 if (!pdata->sides || !pdata->colour) {
54 debug("%s: Invalid device tree data\n", __func__);
55 return -EINVAL;
56 }
57
58 return 0;
59}