!581 Using common bind method for gpio drivers

Merge pull request !581 from NickYang/dev
This commit is contained in:
openharmony_ci
2022-01-22 03:33:34 +00:00
committed by Gitee
7 changed files with 36 additions and 36 deletions
@@ -231,21 +231,22 @@ int32_t PlatformDeviceBind(struct PlatformDevice *device, struct HdfDeviceObject
* @brief Unbind from a hdf device object.
*
* @param device Indicates the pointer to the platform device.
* @param hdfDevice Indicates the pointer to the hdf device object.
*
* @since 1.0
*/
void PlatformDeviceUnbind(struct PlatformDevice *device);
void PlatformDeviceUnbind(struct PlatformDevice *device, struct HdfDeviceObject *hdfDevice);
/**
* @brief Get the platform device from a hdf device object.
* @brief Transform a hdf device object to a platform device object.
*
* @param device Indicates the pointer to the platform device.
*
* @return Returns 0 if get successfully; returns a negative value otherwise.
* @return Returns the pointer to the platform device object on success; otherwise null.
* @since 1.0
*/
int32_t PlatformDeviceGetFromHdfDev(struct HdfDeviceObject *hdfDev, struct PlatformDevice **device);
struct PlatformDevice *PlatformDeviceFromHdfDev(struct HdfDeviceObject *hdfDev);
#ifdef __cplusplus
#if __cplusplus
+3 -3
View File
@@ -166,9 +166,9 @@ void GpioCntlrRemove(struct GpioCntlr *cntlr);
* @return Retrns the pointer of the GpioCntlr on success; returns NULL otherwise.
* @since 1.0
*/
static inline struct GpioCntlr *GpioCntlrFromDevice(struct HdfDeviceObject *device)
static inline struct GpioCntlr *GpioCntlrFromHdfDev(struct HdfDeviceObject *device)
{
return (device == NULL) ? NULL : (struct GpioCntlr *)device->service;
return (struct GpioCntlr *)PlatformDeviceFromHdfDev(device);
}
int32_t GpioCntlrWrite(struct GpioCntlr *cntlr, uint16_t local, uint16_t val);
@@ -193,7 +193,7 @@ void GpioCntlrIrqCallback(struct GpioCntlr *cntlr, uint16_t local);
struct PlatformManager *GpioManagerGet(void);
struct GpioCntlr *GpioCntlrGet(uint16_t gpio);
struct GpioCntlr *GpioCntlrGetByGpio(uint16_t gpio);
static inline void GpioCntlrPut(struct GpioCntlr *cntlr)
{
+9 -8
View File
@@ -288,7 +288,7 @@ int32_t PlatformDeviceBind(struct PlatformDevice *device, struct HdfDeviceObject
return HDF_SUCCESS;
}
void PlatformDeviceUnbind(struct PlatformDevice *device)
void PlatformDeviceUnbind(struct PlatformDevice *device, struct HdfDeviceObject *hdfDev)
{
if (device == NULL) {
return;
@@ -296,23 +296,24 @@ void PlatformDeviceUnbind(struct PlatformDevice *device)
if (device->hdfDev == NULL) {
return;
}
if (device->hdfDev != hdfDev) {
PLAT_LOGW("PlatformDeviceUnbind: hdf device not match!");
return;
}
device->hdfDev->service = NULL;
device->hdfDev->priv = NULL;
device->hdfDev = NULL;
}
int32_t PlatformDeviceGetFromHdfDev(struct HdfDeviceObject *hdfDev, struct PlatformDevice **device)
struct PlatformDevice *PlatformDeviceFromHdfDev(struct HdfDeviceObject *hdfDev)
{
if (hdfDev == NULL || hdfDev->priv == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
if (device == NULL) {
return HDF_ERR_INVALID_PARAM;
PLAT_LOGE("PlatformDeviceFromHdfDev: hdf device or priv null");
return NULL;
}
*device = (struct PlatformDevice *)hdfDev->priv;
return HDF_SUCCESS;
return (struct PlatformDevice *)hdfDev->priv;
}
int32_t PlatformDevicePostEvent(struct PlatformDevice *device, uint32_t events)
+9 -9
View File
@@ -19,7 +19,7 @@
#include "hdf_base.h"
#define PLAT_LOG_TAG gpio_if
#define HDF_LOG_TAG gpio_if
#ifdef __USER__
@@ -247,7 +247,7 @@ int32_t GpioDisableIrq(uint16_t gpio)
int32_t GpioRead(uint16_t gpio, uint16_t *val)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrRead(cntlr, GpioCntlrGetLocal(cntlr, gpio), val);
@@ -258,7 +258,7 @@ int32_t GpioRead(uint16_t gpio, uint16_t *val)
int32_t GpioWrite(uint16_t gpio, uint16_t val)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrWrite(cntlr, GpioCntlrGetLocal(cntlr, gpio), val);
@@ -269,7 +269,7 @@ int32_t GpioWrite(uint16_t gpio, uint16_t val)
int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrSetDir(cntlr, GpioCntlrGetLocal(cntlr, gpio), dir);
@@ -280,7 +280,7 @@ int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrGetDir(cntlr, GpioCntlrGetLocal(cntlr, gpio), dir);
@@ -291,7 +291,7 @@ int32_t GpioGetDir(uint16_t gpio, uint16_t *dir)
int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrSetIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio), mode, func, arg);
@@ -302,7 +302,7 @@ int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg)
int32_t GpioUnsetIrq(uint16_t gpio, void *arg)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrUnsetIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio), arg);
@@ -313,7 +313,7 @@ int32_t GpioUnsetIrq(uint16_t gpio, void *arg)
int32_t GpioEnableIrq(uint16_t gpio)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrEnableIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio));
@@ -324,7 +324,7 @@ int32_t GpioEnableIrq(uint16_t gpio)
int32_t GpioDisableIrq(uint16_t gpio)
{
int32_t ret;
struct GpioCntlr *cntlr = GpioCntlrGet(gpio);
struct GpioCntlr *cntlr = GpioCntlrGetByGpio(gpio);
ret = GpioCntlrDisableIrq(cntlr, GpioCntlrGetLocal(cntlr, gpio));
+3 -3
View File
@@ -199,20 +199,20 @@ static bool GpioCntlrFindMatch(struct PlatformDevice *device, void *data)
return false;
}
struct GpioCntlr *GpioCntlrGet(uint16_t gpio)
struct GpioCntlr *GpioCntlrGetByGpio(uint16_t gpio)
{
struct PlatformManager *gpioMgr = NULL;
struct PlatformDevice *device = NULL;
gpioMgr = GpioManagerGet();
if (gpioMgr == NULL) {
PLAT_LOGE("GpioCntlrRemove: get gpio manager failed");
PLAT_LOGE("GpioCntlrGetByGpio: get gpio manager failed");
return NULL;
}
device = PlatformManagerFindDevice(gpioMgr, (void *)(uintptr_t)gpio, GpioCntlrFindMatch);
if (device == NULL) {
PLAT_LOGE("%s: gpio %u not in any controllers!", __func__, gpio);
PLAT_LOGE("GpioCntlrGetByGpio: gpio %u not in any controllers!", gpio);
return NULL;
}
return CONTAINER_OF(device, struct GpioCntlr, device);
+1 -1
View File
@@ -207,7 +207,7 @@ static void GpioServiceRelease(struct HdfDeviceObject *device)
return;
}
(void)PlatformDeviceUnbind(&gpioMgr->device);
(void)PlatformDeviceUnbind(&gpioMgr->device, device);
(void)PlatformDeviceDestroyService(&gpioMgr->device);
PLAT_LOGI("GpioServiceRelease: done");
}
@@ -194,11 +194,10 @@ static int32_t PlatformDeviceTestBindDevice(struct PlatformDevice *device)
CHECK_EQ_RETURN(device->hdfDev, &hdfDev, HDF_FAILURE);
CHECK_EQ_RETURN(device->service, hdfDev.service, HDF_FAILURE);
ret = PlatformDeviceGetFromHdfDev(&hdfDev, &devFromHdf);
CHECK_EQ_RETURN(ret, HDF_SUCCESS, ret);
devFromHdf = PlatformDeviceFromHdfDev(&hdfDev);
CHECK_EQ_RETURN(device, devFromHdf, HDF_FAILURE);
PlatformDeviceUnbind(device);
PlatformDeviceUnbind(device, &hdfDev);
CHECK_EQ_RETURN(device->hdfDev, NULL, ret);
CHECK_EQ_RETURN(hdfDev.service, NULL, ret);
@@ -252,12 +251,11 @@ static int32_t PlatformDeviceTestReliability(struct PlatformDevice *device)
CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE);
ret = PlatformDeviceBind(NULL, &hdfDev);
CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE);
PlatformDeviceUnbind(NULL);
PlatformDeviceUnbind(device, NULL);
PlatformDeviceUnbind(NULL, NULL);
ret = PlatformDeviceGetFromHdfDev(&hdfDev, NULL);
CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE);
ret = PlatformDeviceGetFromHdfDev(NULL, &devGet);
CHECK_NE_RETURN(ret, HDF_SUCCESS, HDF_FAILURE);
devGet = PlatformDeviceFromHdfDev(NULL);
CHECK_NULL_RETURN(devGet, HDF_FAILURE);
PLAT_LOGD("%s: exit", __func__);
return HDF_SUCCESS;