1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef CLOCK_CORE_H
10 #define CLOCK_CORE_H
11 
12 #include "platform_core.h"
13 #include "osal_spinlock.h"
14 #include "hdf_base.h"
15 #include "clock_if.h"
16 
17 #ifdef __cplusplus
18 #if __cplusplus
19 extern "C" {
20 #endif
21 #endif /* __cplusplus */
22 
23 #define CLOCK_DEVICES_MAX 61
24 #define CLOCK_HANDLE_SHIFT 0xFF00U
25 
26 struct ClockDevice;
27 struct ClockMethod;
28 struct ClockLockMethod;
29 
30 struct ClockDevice {
31     const struct ClockMethod *ops;
32     OsalSpinlock spin;
33     const char *deviceName;
34     const char *clockName;
35     uint32_t deviceIndex;
36     const struct ClockLockMethod *lockOps;
37     void *clk;
38     void *priv;
39     struct ClockDevice *parent;
40 };
41 
42 struct ClockMethod {
43     int32_t (*start)(struct ClockDevice *device);
44     int32_t (*stop)(struct ClockDevice *device);
45     int32_t (*setRate)(struct ClockDevice *device, uint32_t rate);
46     int32_t (*getRate)(struct ClockDevice *device, uint32_t *rate);
47     int32_t (*disable)(struct ClockDevice *device);
48     int32_t (*enable)(struct ClockDevice *device);
49     struct ClockDevice *(*getParent)(struct ClockDevice *device);
50     int32_t (*setParent)(struct ClockDevice *device, struct ClockDevice *parent);
51 };
52 
53 struct ClockLockMethod {
54     int32_t (*lock)(struct ClockDevice *device);
55     void (*unlock)(struct ClockDevice *device);
56 };
57 
58 int32_t ClockDeviceAdd(struct ClockDevice *device);
59 
60 int32_t ClockManagerGetAIdleDeviceId();
61 
62 void ClockDeviceRemove(struct ClockDevice *device);
63 
64 struct ClockDevice *ClockDeviceGet(uint32_t number);
65 
66 struct ClockDevice *ClockDeviceOpen(uint32_t number);
67 
68 int32_t ClockDeviceClose(struct ClockDevice *device);
69 
70 int32_t ClockDeviceEnable(struct ClockDevice *device);
71 
72 int32_t ClockDeviceDisable(struct ClockDevice *device);
73 
74 int32_t ClockDeviceSetRate(struct ClockDevice *device, uint32_t rate);
75 
76 int32_t ClockDeviceGetRate(struct ClockDevice *device, uint32_t *rate);
77 
78 struct ClockDevice *ClockDeviceGetParent(struct ClockDevice *device);
79 
80 int32_t ClockDeviceSetParent(struct ClockDevice *device, struct ClockDevice *parent);
81 
82 #ifdef __cplusplus
83 #if __cplusplus
84 }
85 #endif
86 #endif /* __cplusplus */
87 
88 #endif /* CLOCK_CORE_H */
89