Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <dm-demo.h> |
| 12 | #include <errno.h> |
| 13 | #include <fdtdec.h> |
| 14 | #include <malloc.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <linux/list.h> |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | UCLASS_DRIVER(demo) = { |
Simon Glass | 74f96da | 2014-07-23 06:55:24 -0600 | [diff] [blame] | 21 | .name = "demo", |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 22 | .id = UCLASS_DEMO, |
| 23 | }; |
| 24 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 25 | int demo_hello(struct udevice *dev, int ch) |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 26 | { |
| 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 Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 35 | int demo_status(struct udevice *dev, int *status) |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 36 | { |
| 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 | |
Simon Glass | a02af4a | 2015-01-05 20:05:31 -0700 | [diff] [blame] | 45 | int demo_get_light(struct udevice *dev) |
| 46 | { |
| 47 | const struct demo_ops *ops = device_get_ops(dev); |
| 48 | |
| 49 | if (!ops->get_light) |
| 50 | return -ENOSYS; |
| 51 | |
| 52 | return ops->get_light(dev); |
| 53 | } |
| 54 | |
| 55 | int demo_set_light(struct udevice *dev, int light) |
| 56 | { |
| 57 | const struct demo_ops *ops = device_get_ops(dev); |
| 58 | |
| 59 | if (!ops->set_light) |
| 60 | return -ENOSYS; |
| 61 | |
| 62 | return ops->set_light(dev, light); |
| 63 | } |
| 64 | |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 65 | int demo_parse_dt(struct udevice *dev) |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 66 | { |
| 67 | struct dm_demo_pdata *pdata = dev_get_platdata(dev); |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 68 | int dn = dev_of_offset(dev); |
Simon Glass | 39f7611 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 69 | |
| 70 | pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0); |
| 71 | pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL); |
| 72 | if (!pdata->sides || !pdata->colour) { |
| 73 | debug("%s: Invalid device tree data\n", __func__); |
| 74 | return -EINVAL; |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |