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 | |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <dm-demo.h> |
| 11 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 13 | #include <malloc.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <linux/list.h> |
| 16 | |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 17 | UCLASS_DRIVER(demo) = { |
Simon Glass | 54e3cdb | 2014-07-23 06:55:24 -0600 | [diff] [blame] | 18 | .name = "demo", |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 19 | .id = UCLASS_DEMO, |
| 20 | }; |
| 21 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 22 | int demo_hello(struct udevice *dev, int ch) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 23 | { |
| 24 | const struct demo_ops *ops = device_get_ops(dev); |
| 25 | |
| 26 | if (!ops->hello) |
| 27 | return -ENOSYS; |
| 28 | |
| 29 | return ops->hello(dev, ch); |
| 30 | } |
| 31 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 32 | int demo_status(struct udevice *dev, int *status) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 33 | { |
| 34 | const struct demo_ops *ops = device_get_ops(dev); |
| 35 | |
| 36 | if (!ops->status) |
| 37 | return -ENOSYS; |
| 38 | |
| 39 | return ops->status(dev, status); |
| 40 | } |
| 41 | |
Simon Glass | 120834d | 2015-01-05 20:05:31 -0700 | [diff] [blame] | 42 | int demo_get_light(struct udevice *dev) |
| 43 | { |
| 44 | const struct demo_ops *ops = device_get_ops(dev); |
| 45 | |
| 46 | if (!ops->get_light) |
| 47 | return -ENOSYS; |
| 48 | |
| 49 | return ops->get_light(dev); |
| 50 | } |
| 51 | |
| 52 | int demo_set_light(struct udevice *dev, int light) |
| 53 | { |
| 54 | const struct demo_ops *ops = device_get_ops(dev); |
| 55 | |
| 56 | if (!ops->set_light) |
| 57 | return -ENOSYS; |
| 58 | |
| 59 | return ops->set_light(dev, light); |
| 60 | } |
| 61 | |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 62 | int demo_parse_dt(struct udevice *dev) |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 63 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 64 | struct dm_demo_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 65 | |
Patrick Delaunay | 185bb7e | 2021-09-20 17:58:33 +0200 | [diff] [blame] | 66 | pdata->sides = dev_read_s32_default(dev, "sides", 0); |
| 67 | pdata->colour = dev_read_string(dev, "colour"); |
Simon Glass | 63b1757 | 2014-02-26 15:59:23 -0700 | [diff] [blame] | 68 | if (!pdata->sides || !pdata->colour) { |
| 69 | debug("%s: Invalid device tree data\n", __func__); |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |