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 #ifndef PWM_CORE_H 10 #define PWM_CORE_H 11 12 #include "pwm_if.h" 13 #include "hdf_base.h" 14 #include "hdf_device_desc.h" 15 #include "osal_spinlock.h" 16 17 #ifdef __cplusplus 18 #if __cplusplus 19 extern "C" { 20 #endif 21 #endif /* __cplusplus */ 22 23 struct PwmMethod; 24 struct PwmDev; 25 26 struct PwmMethod { 27 int32_t (*setConfig)(struct PwmDev *pwm, struct PwmConfig *config); 28 int32_t (*open)(struct PwmDev *pwm); 29 int32_t (*close)(struct PwmDev *pwm); 30 }; 31 32 struct PwmDev { 33 struct IDeviceIoService service; 34 struct HdfDeviceObject *device; 35 struct PwmConfig cfg; 36 struct PwmMethod *method; 37 bool busy; 38 uint32_t num; 39 OsalSpinlock lock; 40 void *priv; 41 }; 42 43 int32_t PwmDeviceGet(struct PwmDev *pwm); 44 int32_t PwmDevicePut(struct PwmDev *pwm); 45 int32_t PwmDeviceSetConfig(struct PwmDev *pwm, struct PwmConfig *config); 46 int32_t PwmDeviceGetConfig(struct PwmDev *pwm, struct PwmConfig *config); 47 void *PwmGetPriv(const struct PwmDev *pwm); 48 int32_t PwmSetPriv(struct PwmDev *pwm, void *priv); 49 int32_t PwmDeviceAdd(struct HdfDeviceObject *obj, struct PwmDev *pwm); 50 void PwmDeviceRemove(struct HdfDeviceObject *obj, struct PwmDev *pwm); 51 52 #ifdef __cplusplus 53 #if __cplusplus 54 } 55 #endif 56 #endif /* __cplusplus */ 57 58 #endif /* PWM_CORE_H */ 59