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 | |
Patrick Delaunay | b953ec2 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_MISC |
| 7 | |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <errno.h> |
| 11 | #include <misc.h> |
| 12 | |
| 13 | /* |
| 14 | * Implement a miscellaneous uclass for those do not fit other more |
| 15 | * general classes. A set of generic read, write and ioctl methods may |
| 16 | * be used to access the device. |
| 17 | */ |
| 18 | |
| 19 | int misc_read(struct udevice *dev, int offset, void *buf, int size) |
| 20 | { |
| 21 | const struct misc_ops *ops = device_get_ops(dev); |
| 22 | |
| 23 | if (!ops->read) |
| 24 | return -ENOSYS; |
| 25 | |
| 26 | return ops->read(dev, offset, buf, size); |
| 27 | } |
| 28 | |
| 29 | int misc_write(struct udevice *dev, int offset, void *buf, int size) |
| 30 | { |
| 31 | const struct misc_ops *ops = device_get_ops(dev); |
| 32 | |
| 33 | if (!ops->write) |
| 34 | return -ENOSYS; |
| 35 | |
| 36 | return ops->write(dev, offset, buf, size); |
| 37 | } |
| 38 | |
| 39 | int misc_ioctl(struct udevice *dev, unsigned long request, void *buf) |
| 40 | { |
| 41 | const struct misc_ops *ops = device_get_ops(dev); |
| 42 | |
| 43 | if (!ops->ioctl) |
| 44 | return -ENOSYS; |
| 45 | |
| 46 | return ops->ioctl(dev, request, buf); |
| 47 | } |
| 48 | |
Stephen Warren | b647f55 | 2016-08-08 09:41:33 -0600 | [diff] [blame] | 49 | int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, |
| 50 | void *rx_msg, int rx_size) |
| 51 | { |
| 52 | const struct misc_ops *ops = device_get_ops(dev); |
| 53 | |
| 54 | if (!ops->call) |
| 55 | return -ENOSYS; |
| 56 | |
| 57 | return ops->call(dev, msgid, tx_msg, tx_size, rx_msg, rx_size); |
| 58 | } |
| 59 | |
Mario Six | 440bc11 | 2018-07-31 14:24:13 +0200 | [diff] [blame] | 60 | int misc_set_enabled(struct udevice *dev, bool val) |
| 61 | { |
| 62 | const struct misc_ops *ops = device_get_ops(dev); |
| 63 | |
| 64 | if (!ops->set_enabled) |
| 65 | return -ENOSYS; |
| 66 | |
| 67 | return ops->set_enabled(dev, val); |
| 68 | } |
| 69 | |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 70 | UCLASS_DRIVER(misc) = { |
| 71 | .id = UCLASS_MISC, |
| 72 | .name = "misc", |
Simon Glass | 414cc15 | 2021-08-07 07:24:03 -0600 | [diff] [blame] | 73 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | e5d6116 | 2018-12-27 13:24:36 -0700 | [diff] [blame] | 74 | .post_bind = dm_scan_fdt_dev, |
| 75 | #endif |
Thomas Chou | 4395e06 | 2015-10-07 20:20:51 +0800 | [diff] [blame] | 76 | }; |