Alexey Romanov | 6ee101a | 2023-09-21 11:13:34 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2023 SberDevices, Inc. |
| 4 | * |
| 5 | * Author: Alexey Romanov <avromanov@salutedevices.com> |
| 6 | */ |
| 7 | |
Alexey Romanov | 6ee101a | 2023-09-21 11:13:34 +0300 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <sm-uclass.h> |
| 11 | |
| 12 | static const struct sm_ops *get_sm_ops(struct udevice *dev) |
| 13 | { |
| 14 | return (const struct sm_ops *)dev->driver->ops; |
| 15 | } |
| 16 | |
| 17 | int sm_call(struct udevice *dev, u32 cmd, s32 *ret, struct pt_regs *args) |
| 18 | { |
| 19 | const struct sm_ops *ops = get_sm_ops(dev); |
| 20 | |
| 21 | if (ops->sm_call) |
| 22 | return ops->sm_call(dev, cmd, ret, args); |
| 23 | |
| 24 | return -ENOSYS; |
| 25 | } |
| 26 | |
| 27 | int sm_call_read(struct udevice *dev, void *buffer, size_t size, |
| 28 | u32 cmd, struct pt_regs *args) |
| 29 | { |
| 30 | const struct sm_ops *ops = get_sm_ops(dev); |
| 31 | |
| 32 | if (ops->sm_call_read) |
| 33 | return ops->sm_call_read(dev, buffer, size, cmd, |
| 34 | args); |
| 35 | |
| 36 | return -ENOSYS; |
| 37 | } |
| 38 | |
| 39 | int sm_call_write(struct udevice *dev, void *buffer, size_t size, |
| 40 | u32 cmd, struct pt_regs *args) |
| 41 | { |
| 42 | const struct sm_ops *ops = get_sm_ops(dev); |
| 43 | |
| 44 | if (ops->sm_call_write) |
| 45 | return ops->sm_call_write(dev, buffer, size, cmd, |
| 46 | args); |
| 47 | |
| 48 | return -ENOSYS; |
| 49 | } |
| 50 | |
| 51 | UCLASS_DRIVER(sm) = { |
| 52 | .name = "sm", |
| 53 | .id = UCLASS_SM, |
| 54 | }; |