1 /* 2 * Copyright (c) 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 #ifndef HDF_CHIP_H 10 #define HDF_CHIP_H 11 12 #include "hdf_chip_config.h" 13 #include "osal_time.h" 14 15 struct HdfReset; 16 struct HdfPower; 17 18 struct HdfPowerOps { 19 /** 20 * @brief Powers on the device using a specified power manage interface. 21 * 22 * @param powerMgr Indicates the pointer to the power manage interface. 23 * @return Returns <b>0</b> if the device is powered on; returns a negative value otherwise. 24 * 25 * @since 1.0 26 * @version 1.0 27 */ 28 int32_t (*On)(struct HdfPower *powerMgr); 29 30 /** 31 * @brief Powers off the device using a specified power manage interface. 32 * 33 * @param powerMgr Indicates the pointer to the power manage interface. 34 * @return Returns <b>0</b> if the device is powered off; returns a negative value otherwise. 35 * 36 * @since 1.0 37 * @version 1.0 38 */ 39 int32_t (*Off)(struct HdfPower *powerMgr); 40 41 /** 42 * @brief Releases power using a specified power manage interface. 43 * 44 * @param powerMgr Indicates the pointer to the power manage interface. 45 * 46 * @since 1.0 47 * @version 1.0 48 */ 49 void (*Release)(struct HdfPower *powerMgr); 50 }; 51 /** 52 * @brief Provides functions for powering on and off the device, releasing power, and creating a power manage interface. 53 * 54 * @since 1.0 55 * @version 1.0 56 */ 57 struct HdfPower { 58 const struct HdfPowerOps *ops; 59 }; 60 61 struct HdfResetOps { 62 /** 63 * @brief Resets the WLAN module using a specified reset manage interface. 64 * 65 * @param resetManager Indicates the pointer to the reset manage interface. 66 * @return Returns <b>0</b> if the WLAN module is reset; returns a negative value otherwise. 67 * 68 * @since 1.0 69 * @version 1.0 70 */ 71 int32_t (*Reset)(struct HdfReset *resetManager); 72 73 /** 74 * @brief Releases a specified reset manage interface. 75 * 76 * @param resetMgr Indicates the pointer to the reset manage interface. 77 * 78 * @since 1.0 79 * @version 1.0 80 */ 81 void (*Release)(struct HdfReset *resetMgr); 82 }; 83 84 /** 85 * @brief Describes the reset manage interface, including its configuration and functions. 86 * 87 * @since 1.0 88 * @version 1.0 89 */ 90 struct HdfReset { 91 const struct HdfResetOps *ops; 92 }; 93 94 struct HdfUartBus { 95 const char *name; 96 }; 97 98 struct HdfBus { 99 uint8_t type; 100 union { 101 struct HdfUartBus uart; 102 }; 103 }; 104 105 enum FunctionType { FUNC_TYPE_WLAN = 0, FUNC_TYPE_BT }; 106 107 struct HdfVirtualDevice { 108 const char *name; 109 struct HdfCompositeDevice *parent; 110 struct HdfPower *power; 111 struct HdfReset *reset; 112 struct HdfBus *bus; 113 uint8_t bootUpTimeOut; 114 uint8_t functionType; 115 }; 116 117 struct HdfVirtualDevice *CreateVirtualDevice(const struct HdfChipConfig *config); 118 void ReleaseVirtualDevice(struct HdfVirtualDevice *device); 119 HdfPowerOnVirtualDevice(struct HdfVirtualDevice * device)120inline static int32_t HdfPowerOnVirtualDevice(struct HdfVirtualDevice *device) 121 { 122 if (device == NULL) { 123 return HDF_FAILURE; 124 } 125 if (device->power == NULL || device->power->ops == NULL || device->power->ops->On == NULL) { 126 return HDF_FAILURE; 127 } 128 return device->power->ops->On(device->power); 129 } HdfPowerOffVirtualDevice(struct HdfVirtualDevice * device)130inline static int32_t HdfPowerOffVirtualDevice(struct HdfVirtualDevice *device) 131 { 132 if (device == NULL) { 133 return HDF_FAILURE; 134 } 135 if (device->power == NULL || device->power->ops == NULL || device->power->ops->Off == NULL) { 136 return HDF_FAILURE; 137 } 138 return device->power->ops->Off(device->power); 139 } HdfResetVirtualDevice(struct HdfVirtualDevice * device)140inline static int32_t HdfResetVirtualDevice(struct HdfVirtualDevice *device) 141 { 142 int32_t ret; 143 if (device == NULL || device->reset == NULL || device->reset->ops == NULL || device->reset->ops->Reset == NULL) { 144 return HDF_FAILURE; 145 } 146 ret = device->reset->ops->Reset(device->reset); 147 OsalMSleep(device->bootUpTimeOut); 148 return ret; 149 } 150 151 #endif