blob: 636fd8831f5d152310cdd8d7cee1ac7e33c8b492 [file] [log] [blame]
Simon Glass39f76112014-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) = {
22 .id = UCLASS_DEMO,
23};
24
Heiko Schocher54c5d082014-05-22 12:43:05 +020025int demo_hello(struct udevice *dev, int ch)
Simon Glass39f76112014-02-26 15:59:23 -070026{
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
Heiko Schocher54c5d082014-05-22 12:43:05 +020035int demo_status(struct udevice *dev, int *status)
Simon Glass39f76112014-02-26 15:59:23 -070036{
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
Heiko Schocher54c5d082014-05-22 12:43:05 +020045int demo_parse_dt(struct udevice *dev)
Simon Glass39f76112014-02-26 15:59:23 -070046{
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}