blob: abca0052e293185eb3c3f1cf36d516672f9c5356 [file] [log] [blame]
Alexey Romanov6ee101a2023-09-21 11:13:34 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2023 SberDevices, Inc.
4 *
5 * Author: Alexey Romanov <avromanov@salutedevices.com>
6 */
7
Alexey Romanov6ee101a2023-09-21 11:13:34 +03008#include <dm.h>
9#include <errno.h>
10#include <sm-uclass.h>
11
12static const struct sm_ops *get_sm_ops(struct udevice *dev)
13{
14 return (const struct sm_ops *)dev->driver->ops;
15}
16
17int 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
27int 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
39int 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
51UCLASS_DRIVER(sm) = {
52 .name = "sm",
53 .id = UCLASS_SM,
54};