Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 63b1757 | 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 | 63b1757 | 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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 15 | #include <malloc.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <linux/list.h> |
| 18 | |
| 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
| 21 | UCLASS_DRIVER(demo) = { |
Simon Glass | 54e3cdb | 2014-07-23 06:55:24 -0600 | [diff] [blame] | 22 | .name = "demo", |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 23 | .id = UCLASS_DEMO, |
| 24 | }; |
| 25 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 26 | int demo_hello(struct udevice *dev, int ch) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 27 | { |
| 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 Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 36 | int demo_status(struct udevice *dev, int *status) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 37 | { |
| 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 | |
Simon Glass | 120834d | 2015-01-05 20:05:31 -0700 | [diff] [blame] | 46 | int demo_get_light(struct udevice *dev) |
| 47 | { |
| 48 | const struct demo_ops *ops = device_get_ops(dev); |
| 49 | |
| 50 | if (!ops->get_light) |
| 51 | return -ENOSYS; |
| 52 | |
| 53 | return ops->get_light(dev); |
| 54 | } |
| 55 | |
| 56 | int demo_set_light(struct udevice *dev, int light) |
| 57 | { |
| 58 | const struct demo_ops *ops = device_get_ops(dev); |
| 59 | |
| 60 | if (!ops->set_light) |
| 61 | return -ENOSYS; |
| 62 | |
| 63 | return ops->set_light(dev, light); |
| 64 | } |
| 65 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 66 | int demo_parse_dt(struct udevice *dev) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 67 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 68 | struct dm_demo_pdata *pdata = dev_get_plat(dev); |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 69 | int dn = dev_of_offset(dev); |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 70 | |
| 71 | pdata->sides = fdtdec_get_int(gd->fdt_blob, dn, "sides", 0); |
| 72 | pdata->colour = fdt_getprop(gd->fdt_blob, dn, "colour", NULL); |
| 73 | if (!pdata->sides || !pdata->colour) { |
| 74 | debug("%s: Invalid device tree data\n", __func__); |
| 75 | return -EINVAL; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |