• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 #include "hdf_log.h"
10 #include "osal_spinlock.h"
11 #include "platform_core.h"
12 
13 static struct PlatformModuleInfo g_platformModules[] = {
14 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_GPIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_GPIO)
15     {
16         .moduleType = PLATFORM_MODULE_GPIO,
17         .moduleName = "PLATFORM_MODULE_GPIO",
18     },
19 #endif
20 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2C)
21     {
22         .moduleType = PLATFORM_MODULE_I2C,
23         .moduleName = "PLATFORM_MODULE_I2C",
24     },
25 #endif
26 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SPI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SPI)
27     {
28         .moduleType = PLATFORM_MODULE_SPI,
29         .moduleName = "PLATFORM_MODULE_SPI",
30     },
31 #endif
32 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PIN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PIN)
33     {
34         .moduleType = PLATFORM_MODULE_PIN,
35         .moduleName = "PLATFORM_MODULE_PIN",
36     },
37 #endif
38 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_CLOCK) || defined(CONFIG_DRIVERS_HDF_PLATFORM_CLOCK)
39     {
40         .moduleType = PLATFORM_MODULE_CLOCK,
41         .moduleName = "PLATFORM_MODULE_CLOCK",
42     },
43 #endif
44 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR) || defined(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR)
45     {
46         .moduleType = PLATFORM_MODULE_REGULATOR,
47         .moduleName = "PLATFORM_MODULE_REGULATOR",
48     },
49 #endif
50 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI)
51     {
52         .moduleType = PLATFORM_MODULE_MIPI_DSI,
53         .moduleName = "PLATFORM_MODULE_MIPI_DSI",
54     },
55 #endif
56 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_CSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI)
57     {
58         .moduleType = PLATFORM_MODULE_MIPI_CSI,
59         .moduleName = "PLATFORM_MODULE_MIPI_CSI",
60     },
61 #endif
62 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_UART) || defined(CONFIG_DRIVERS_HDF_PLATFORM_UART)
63     {
64         .moduleType = PLATFORM_MODULE_UART,
65         .moduleName = "PLATFORM_MODULE_UART",
66     },
67 #endif
68 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_SDIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_SDIO)
69     {
70         .moduleType = PLATFORM_MODULE_SDIO,
71         .moduleName = "PLATFORM_MODULE_SDIO",
72     },
73 #endif
74 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MDIO) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MDIO)
75     {
76         .moduleType = PLATFORM_MODULE_MDIO,
77         .moduleName = "PLATFORM_MODULE_MDIO",
78     },
79 #endif
80 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_APB) || defined(CONFIG_DRIVERS_HDF_PLATFORM_APB)
81     {
82         .moduleType = PLATFORM_MODULE_APB,
83         .moduleName = "PLATFORM_MODULE_APB",
84     },
85 #endif
86 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PCIE) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PCIE)
87     {
88         .moduleType = PLATFORM_MODULE_PCIE,
89         .moduleName = "PLATFORM_MODULE_PCIE",
90     },
91 #endif
92 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PCM) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PCM)
93     {
94         .moduleType = PLATFORM_MODULE_PCM,
95         .moduleName = "PLATFORM_MODULE_PCM",
96     },
97 #endif
98 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I2S) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I2S)
99     {
100         .moduleType = PLATFORM_MODULE_I2S,
101         .moduleName = "PLATFORM_MODULE_I2S",
102     },
103 #endif
104 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_PWM) || defined(CONFIG_DRIVERS_HDF_PLATFORM_PWM)
105     {
106         .moduleType = PLATFORM_MODULE_PWM,
107         .moduleName = "PLATFORM_MODULE_PWM",
108     },
109 #endif
110 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_DMA) || defined(CONFIG_DRIVERS_HDF_PLATFORM_DMA)
111     {
112         .moduleType = PLATFORM_MODULE_DMA,
113         .moduleName = "PLATFORM_MODULE_DMA",
114     },
115 #endif
116 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_ADC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_ADC)
117     {
118         .moduleType = PLATFORM_MODULE_ADC,
119         .moduleName = "PLATFORM_MODULE_ADC",
120     },
121 #endif
122 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
123     {
124         .moduleType = PLATFORM_MODULE_RTC,
125         .moduleName = "PLATFORM_MODULE_RTC",
126     },
127 #endif
128 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_WDT) || defined(CONFIG_DRIVERS_HDF_PLATFORM_WDT)
129     {
130         .moduleType = PLATFORM_MODULE_WDT,
131         .moduleName = "PLATFORM_MODULE_WDT",
132     },
133 #endif
134 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_I3C) || defined(CONFIG_DRIVERS_HDF_PLATFORM_I3C)
135     {
136         .moduleType = PLATFORM_MODULE_I3C,
137         .moduleName = "PLATFORM_MODULE_I3C",
138     },
139 #endif
140 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_CAN) || defined(CONFIG_DRIVERS_HDF_PLATFORM_CAN)
141     {
142         .moduleType = PLATFORM_MODULE_CAN,
143         .moduleName = "PLATFORM_MODULE_CAN",
144     },
145 #endif
146 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_HDMI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_HDMI)
147     {
148         .moduleType = PLATFORM_MODULE_HDMI,
149         .moduleName = "PLATFORM_MODULE_HDMI",
150     },
151 #endif
152 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MMC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MMC)
153     {
154         .moduleType = PLATFORM_MODULE_MMC,
155         .moduleName = "PLATFORM_MODULE_MMC",
156     },
157 #endif
158 #if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MTD) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MTD)
159     {
160         .moduleType = PLATFORM_MODULE_MTD,
161         .moduleName = "PLATFORM_MODULE_MTD",
162     },
163 #endif
164     {
165         .moduleType = PLATFORM_MODULE_DEFAULT,
166         .moduleName = "PLATFORM_MODULE_DEFAULT",
167     },
168 };
169 
170 static OsalSpinlock g_platformSpin;
171 static bool g_platformReady;
172 
PlatformGlobalLock(void)173 void PlatformGlobalLock(void)
174 {
175     if (g_platformReady == false) {
176         (void)OsalSpinInit(&g_platformSpin);
177         g_platformReady = true;
178     }
179     (void)OsalSpinLock(&g_platformSpin);
180 }
181 
PlatformGlobalUnlock(void)182 void PlatformGlobalUnlock(void)
183 {
184     (void)OsalSpinUnlock(&g_platformSpin);
185 }
186 
PlatformModuleInfoGet(enum PlatformModuleType moduleType)187 struct PlatformModuleInfo *PlatformModuleInfoGet(enum PlatformModuleType moduleType)
188 {
189     int32_t i;
190 
191     for (i = 0; i < PlatformModuleInfoCount(); i++) {
192         if (g_platformModules[i].moduleType == moduleType) {
193             return &g_platformModules[i];
194         }
195     }
196     return NULL;
197 }
198 
PlatformModuleInfoCount(void)199 int32_t PlatformModuleInfoCount(void)
200 {
201     return sizeof(g_platformModules) / sizeof(g_platformModules[0]);
202 }
203