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