Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <errno.h> |
| 9 | #include <misc.h> |
| 10 | |
| 11 | /* |
| 12 | * Implement a miscellaneous uclass for those do not fit other more |
| 13 | * general classes. A set of generic read, write and ioctl methods may |
| 14 | * be used to access the device. |
| 15 | */ |
| 16 | |
| 17 | int misc_read(struct udevice *dev, int offset, void *buf, int size) |
| 18 | { |
| 19 | const struct misc_ops *ops = device_get_ops(dev); |
| 20 | |
| 21 | if (!ops->read) |
| 22 | return -ENOSYS; |
| 23 | |
| 24 | return ops->read(dev, offset, buf, size); |
| 25 | } |
| 26 | |
| 27 | int misc_write(struct udevice *dev, int offset, void *buf, int size) |
| 28 | { |
| 29 | const struct misc_ops *ops = device_get_ops(dev); |
| 30 | |
| 31 | if (!ops->write) |
| 32 | return -ENOSYS; |
| 33 | |
| 34 | return ops->write(dev, offset, buf, size); |
| 35 | } |
| 36 | |
| 37 | int misc_ioctl(struct udevice *dev, unsigned long request, void *buf) |
| 38 | { |
| 39 | const struct misc_ops *ops = device_get_ops(dev); |
| 40 | |
| 41 | if (!ops->ioctl) |
| 42 | return -ENOSYS; |
| 43 | |
| 44 | return ops->ioctl(dev, request, buf); |
| 45 | } |
| 46 | |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 47 | int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 48 | void *rx_msg, int rx_size) |
| 49 | { |
| 50 | const struct misc_ops *ops = device_get_ops(dev); |
| 51 | |
| 52 | if (!ops->call) |
| 53 | return -ENOSYS; |
| 54 | |
| 55 | return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size); |
| 56 | } |
| 57 | |
Mario Six | 440bc11 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 58 | int misc_set_enabled(struct udevice *dev, bool val) |
| 59 | { |
| 60 | const struct misc_ops *ops = device_get_ops(dev); |
| 61 | |
| 62 | if (!ops->set_enabled) |
| 63 | return -ENOSYS; |
| 64 | |
| 65 | return ops->set_enabled(dev, val); |
| 66 | } |
| 67 | |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 68 | UCLASS_DRIVER(misc) = { |
| 69 | .id = UCLASS_MISC, |
| 70 | .name = "misc", |
| 71 | }; |