blob: 6a8b70262937502b762d853f20c7637440da86c7 [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
8#include <common.h>
9#include <dm.h>
10#include <errno.h>
11#include <sm-uclass.h>
12
13static const struct sm_ops *get_sm_ops(struct udevice *dev)
14{
15 return (const struct sm_ops *)dev->driver->ops;
16}
17
18int sm_call(struct udevice *dev, u32 cmd, s32 *ret, struct pt_regs *args)
19{
20 const struct sm_ops *ops = get_sm_ops(dev);
21
22 if (ops->sm_call)
23 return ops->sm_call(dev, cmd, ret, args);
24
25 return -ENOSYS;
26}
27
28int sm_call_read(struct udevice *dev, void *buffer, size_t size,
29 u32 cmd, struct pt_regs *args)
30{
31 const struct sm_ops *ops = get_sm_ops(dev);
32
33 if (ops->sm_call_read)
34 return ops->sm_call_read(dev, buffer, size, cmd,
35 args);
36
37 return -ENOSYS;
38}
39
40int sm_call_write(struct udevice *dev, void *buffer, size_t size,
41 u32 cmd, struct pt_regs *args)
42{
43 const struct sm_ops *ops = get_sm_ops(dev);
44
45 if (ops->sm_call_write)
46 return ops->sm_call_write(dev, buffer, size, cmd,
47 args);
48
49 return -ENOSYS;
50}
51
52UCLASS_DRIVER(sm) = {
53 .name = "sm",
54 .id = UCLASS_SM,
55};