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