feat:add linux hdf regulator

Signed-off-by: s00442234 <susha@huawei.com>
This commit is contained in:
s00442234
2021-12-18 18:38:20 +08:00
parent 8998029717
commit fa2d5c10a4
9 changed files with 710 additions and 1 deletions
+8 -1
View File
@@ -91,4 +91,11 @@ config PWM_HI35XX
bool "hi35xx pwm driver"
depends on PWM
help
Answer Y to enable hi35xx pwm driver
Answer Y to enable hi35xx pwm driver
config DRIVERS_HDF_PLATFORM_REGULATOR
bool "Enable HDF platform regulator driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform regulator driver.
+1
View File
@@ -22,3 +22,4 @@ obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += pwm/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_UART) += uart/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SPI) += spi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_RTC) += rtc/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR) += regulator/
+1
View File
@@ -29,6 +29,7 @@ ccflags-$(CONFIG_DRIVERS_HDF_PLATFORM) +=-I$(srctree)/drivers/hdf/framework/incl
-I$(srctree)/drivers/hdf/framework/support/platform/include/spi \
-I$(srctree)/drivers/hdf/framework/support/platform/include/uart \
-I$(srctree)/drivers/hdf/framework/support/platform/include/watchdog \
-I$(srctree)/drivers/hdf/framework/support/platform/include/regulator \
-I$(srctree)/drivers/hdf/framework/model/storage/include \
-I$(srctree)/drivers/hdf/framework/model/storage/include/mmc \
-I$(srctree)/drivers/hdf/framework/model/storage/include/mtd \
+20
View File
@@ -0,0 +1,20 @@
#
# Copyright (c) 2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR) += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/regulator/regulator_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/regulator/regulator_tree_mgr.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/regulator/regulator_if.o \
regulator_adapter.o \
regulator_adapter_consumer.o
+523
View File
@@ -0,0 +1,523 @@
/*
* regulator driver adapter of linux
*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "regulator_adapter.h"
#include "regulator_adapter_consumer.h"
#include "regulator_core.h"
#include <linux/regulator/consumer.h>
#include "device_resource_if.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "osal_mem.h"
#define HDF_LOG_TAG regulator_linux_adapter
static int32_t LinuxRegulatorOpen(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if(info->adapterReg == NULL) {
const char *devname = dev_name(info->dev);
if ((devname == NULL) || (strcmp(devname, info->devName) != 0)) {
HDF_LOGE("%s:dev info error [%s][%s]!", __func__, devname, info->devName);
return HDF_FAILURE;
}
info->adapterReg = regulator_get(info->dev, info->supplyName);
if (IS_ERR(info->adapterReg)) {
HDF_LOGE("%s: regulator_get [%s][%s] ERROR!", __func__, devname, info->supplyName);
info->adapterReg = NULL;
return HDF_FAILURE;
}
if (info->adapterReg == NULL) {
HDF_LOGE("%s: regulator_get [%s][%s]!", __func__, devname, info->supplyName);
return HDF_FAILURE;
}
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorClose(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if(info->adapterReg != NULL) {
if (regulator_disable(info->adapterReg) != HDF_SUCCESS) {
HDF_LOGE("%s:regulator_disable[%s][%s] FAIL", __func__, node->regulatorInfo.name, info->supplyName);
}
regulator_put(info->adapterReg);
info->adapterReg = NULL;
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorRemove(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
HDF_LOGI("%s:regulator [%s][%s] release!", __func__, info->devName, info->supplyName);
if(LinuxRegulatorClose(node) != HDF_SUCCESS) {
HDF_LOGE("%s:LinuxRegulatorClose fail[%s][%s]!", __func__, info->devName, info->supplyName);
}
OsalMemFree(info);
node->priv = NULL;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorEnable(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
int ret = regulator_enable(info->adapterReg);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:[%s][%s][%d] FAIL", __func__, node->regulatorInfo.name, info->supplyName, ret);
return HDF_FAILURE;
}
if (regulator_is_enabled(info->adapterReg) > 0) {
node->regulatorInfo.status = REGULATOR_STATUS_ON;
} else {
node->regulatorInfo.status = REGULATOR_STATUS_OFF;
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorDisable(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (regulator_disable(info->adapterReg) != HDF_SUCCESS) {
HDF_LOGE("%s:[%s][%s] FAIL", __func__, node->regulatorInfo.name, info->supplyName);
return HDF_FAILURE;
}
// node maybe alwayson
if (regulator_is_enabled(info->adapterReg) > 0) {
node->regulatorInfo.status = REGULATOR_STATUS_ON;
} else {
node->regulatorInfo.status = REGULATOR_STATUS_OFF;
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorForceDisable(struct RegulatorNode *node)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (regulator_force_disable(info->adapterReg) != HDF_SUCCESS) {
HDF_LOGE("regulator_force_disable[%s][%s] FAIL", node->regulatorInfo.name, info->supplyName);
return HDF_FAILURE;
}
node->regulatorInfo.status = REGULATOR_STATUS_OFF;
HDF_LOGI("%s:[%s][%s] success!", __func__, info->devName, info->supplyName);
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorSetVoltage(struct RegulatorNode *node, uint32_t minUv, uint32_t maxUv)
{
if (node == NULL || node->priv == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (regulator_set_voltage(info->adapterReg, minUv, maxUv) != HDF_SUCCESS) {
HDF_LOGE("%s: [%s][%s] FAIL", __func__, node->regulatorInfo.name, info->supplyName);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorGetVoltage(struct RegulatorNode *node, uint32_t *voltage)
{
if (node == NULL || node->priv == NULL || voltage == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
int ret = regulator_get_voltage(info->adapterReg);
if (ret < 0) {
HDF_LOGE("%s: [%s] FAIL", __func__, node->regulatorInfo.name);
return HDF_FAILURE;
}
*voltage = ret;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorSetCurrent(struct RegulatorNode *node, uint32_t minUa, uint32_t maxUa)
{
if (node == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (regulator_set_current_limit(info->adapterReg, minUa, maxUa) != HDF_SUCCESS) {
HDF_LOGE("%s: [%s][%s] FAIL", __func__, node->regulatorInfo.name, info->supplyName);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorGetCurrent(struct RegulatorNode *node, uint32_t *regCurrent)
{
if (node == NULL || regCurrent == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
int ret = regulator_get_current_limit(info->adapterReg);
if (ret < 0) {
HDF_LOGE("%s: [%s] FAIL", __func__, node->regulatorInfo.name);
return HDF_FAILURE;
}
*regCurrent = ret;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorGetStatus(struct RegulatorNode *node, uint32_t *status)
{
if (node == NULL || status == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
struct LinuxRegulatorInfo *info = (struct LinuxRegulatorInfo *)node->priv;
if (info->adapterReg == NULL) {
HDF_LOGE("%s adapterReg null, please open dev", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (regulator_is_enabled(info->adapterReg) > 0) {
*status = REGULATOR_STATUS_ON;
} else {
*status = REGULATOR_STATUS_OFF;
}
return HDF_SUCCESS;
}
static struct RegulatorMethod g_method = {
.open = LinuxRegulatorOpen,
.close = LinuxRegulatorClose,
.release = LinuxRegulatorRemove,
.enable = LinuxRegulatorEnable,
.disable = LinuxRegulatorDisable,
.forceDisable = LinuxRegulatorForceDisable,
.setVoltage = LinuxRegulatorSetVoltage,
.getVoltage = LinuxRegulatorGetVoltage,
.setCurrent = LinuxRegulatorSetCurrent,
.getCurrent = LinuxRegulatorGetCurrent,
.getStatus = LinuxRegulatorGetStatus,
};
static struct device *g_consumer_dev;
int32_t LinuxRegulatorSetConsumerDev(struct device *dev)
{
if (dev == NULL) {
HDF_LOGE("%s: node null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
g_consumer_dev = dev;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorBind(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorReadHcs(struct RegulatorNode *regNode, const struct DeviceResourceNode *node)
{
int32_t ret;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetString == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetString(node, "name", &(regNode->regulatorInfo.name), "ERROR");
if ((ret != HDF_SUCCESS) || (regNode->regulatorInfo.name == NULL)) {
HDF_LOGE("%s: read name fail!", __func__);
return HDF_FAILURE;
}
HDF_LOGD("%s:name[%s]", __func__, regNode->regulatorInfo.name);
ret = drsOps->GetUint8(node, "mode", &regNode->regulatorInfo.constraints.mode, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read mode fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "minUv", &regNode->regulatorInfo.constraints.minUv, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read minUv fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "maxUv", &regNode->regulatorInfo.constraints.maxUv, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read maxUv fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "minUa", &regNode->regulatorInfo.constraints.minUa, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read minUa fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "maxUa", &regNode->regulatorInfo.constraints.maxUa, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read maxUa fail!", __func__);
return HDF_FAILURE;
}
regNode->regulatorInfo.parentName = NULL;
regNode->regulatorInfo.status = REGULATOR_STATUS_OFF;
HDF_LOGI("%s: name[%s][%d]--[%d][%d]--[%d][%d]", __func__,
regNode->regulatorInfo.name, regNode->regulatorInfo.constraints.mode,
regNode->regulatorInfo.constraints.minUv, regNode->regulatorInfo.constraints.maxUv,
regNode->regulatorInfo.constraints.minUa, regNode->regulatorInfo.constraints.maxUa);
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorReadAdapterHcs(struct LinuxRegulatorInfo *info, const struct DeviceResourceNode *node)
{
int32_t ret;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (info == NULL || drsOps == NULL || drsOps->GetString == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetString(node, "devName", &(info->devName), "ERROR");
if ((ret != HDF_SUCCESS) || (info->devName == NULL)) {
HDF_LOGE("%s: read devName fail!", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s:devName[%s]", __func__,info->devName);
ret = drsOps->GetString(node, "supplyName", &(info->supplyName), "ERROR");
if ((ret != HDF_SUCCESS) || (info->supplyName == NULL)) {
HDF_LOGE("%s: read supplyName fail!", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s:supplyName[%s]", __func__, info->supplyName);
info->dev = g_consumer_dev;
return HDF_SUCCESS;
}
static int32_t LinuxRegulatorParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node)
{
int32_t ret;
struct RegulatorNode *regNode = NULL;
struct LinuxRegulatorInfo *info = NULL;
(void)device;
regNode = (struct RegulatorNode *)OsalMemCalloc(sizeof(*regNode));
if (regNode == NULL) {
HDF_LOGE("%s: malloc regNode fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
info = (struct LinuxRegulatorInfo *)OsalMemCalloc(sizeof(*info));
if (info == NULL) {
HDF_LOGE("%s: malloc info fail!", __func__);
OsalMemFree(regNode);
regNode = NULL;
return HDF_ERR_MALLOC_FAIL;
}
do {
ret = LinuxRegulatorReadHcs(regNode, node);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read drs fail! ret:%d", __func__, ret);
break;
}
ret = LinuxRegulatorReadAdapterHcs(info, node);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: LinuxRegulatorReadAdapterHcs fail! ret:%d", __func__, ret);
break;
}
HDF_LOGI("%s: name[%s][%d]--[%d][%d]--[%d][%d]--[%s][%s]", __func__,
regNode->regulatorInfo.name, regNode->regulatorInfo.constraints.mode,
regNode->regulatorInfo.constraints.minUv, regNode->regulatorInfo.constraints.maxUv,
regNode->regulatorInfo.constraints.minUa, regNode->regulatorInfo.constraints.maxUa,
info->devName, info->supplyName);
regNode->priv = (void *)info;
regNode->ops = &g_method;
ret = RegulatorNodeAdd(regNode);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: add regulator controller fail:%d!", __func__, ret);
break;
}
} while(0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail [%d]!", __func__, ret);
OsalMemFree(regNode);
regNode = NULL;
OsalMemFree(info);
info = NULL;
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
/* get all linux regulator, then add to hdf */
static int32_t LinuxRegulatorInit(struct HdfDeviceObject *device)
{
int32_t ret;
const struct DeviceResourceNode *childNode = NULL;
RegulatorAdapterConsumerInit();
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {
ret = LinuxRegulatorParseAndInit(device, childNode);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:LinuxRegulatorParseAndInit fail", __func__);
return HDF_FAILURE;
}
}
return ret;
}
static int32_t LinuxRegulatorParseAndRelease(struct HdfDeviceObject *device, const struct DeviceResourceNode *node)
{
int32_t ret;
struct LinuxRegulatorInfo *info = NULL;
struct DeviceResourceIface *drsOps = NULL;
(void)device;
HDF_LOGI("LinuxRegulatorParseAndRelease");
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetString == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return HDF_FAILURE;
}
const char *name;
ret = drsOps->GetString(node, "name", &(name), "ERROR");
if ((ret != HDF_SUCCESS) || (name == NULL)) {
HDF_LOGE("%s: read name fail!", __func__);
return HDF_FAILURE;
}
HDF_LOGI("LinuxRegulatorParseAndRelease: name[%s]", name);
ret = RegulatorNodeRemove(name);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: LinuxRegulatorRelease fail:%d!", __func__, ret);
return HDF_FAILURE;
}
HDF_LOGI("LinuxRegulatorParseAndRelease: name[%s] success", name);
return HDF_SUCCESS;
}
static void LinuxRegulatorRelease(struct HdfDeviceObject *device)
{
HDF_LOGI("%s: enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return;
}
const struct DeviceResourceNode *childNode = NULL;
DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {
int ret = LinuxRegulatorParseAndRelease(device, childNode);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:LinuxRegulatorParseAndInit fail", __func__);
}
}
}
struct HdfDriverEntry g_regulatorLinuxDriverEntry = {
.moduleVersion = 1,
.Bind = LinuxRegulatorBind,
.Init = LinuxRegulatorInit,
.Release = LinuxRegulatorRelease,
.moduleName = "linux_regulator_adapter",
};
HDF_INIT(g_regulatorLinuxDriverEntry);
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef REGULATOR_ADAPTER_H
#define REGULATOR_ADAPTER_H
#include "hdf_base.h"
#define VOLTAGE_2500_UV 2500
#define CURRENT_2500_UA 2500
struct LinuxRegulatorInfo {
const char *devName; // note:linux kernel constraints:len(devName) + len(supplyName) < REG_STR_SIZE(64)
const char *supplyName; // note:linux kernel constraints:len(devName) + len(supplyName) < REG_STR_SIZE(64)
struct device *dev;
struct regulator *adapterReg;
};
int32_t LinuxRegulatorSetConsumerDev(struct device *dev);
#endif /* REGULATOR_ADAPTER_H */
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "regulator_adapter_consumer.h"
#include "regulator_adapter.h"
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
#include <linux/regulator/consumer.h>
#include "hdf_log.h"
#define HDF_LOG_TAG regulator_linux_adapter
static void RegulatorAdapterConsumerDevRelease(struct device *dev)
{
}
static struct platform_device RegulatorAdapterConsumerPlatformDevice = {
.name = "regulator_adapter_consumer01",
.id = -1,
.dev = {
.release = RegulatorAdapterConsumerDevRelease,
}
};
struct platform_device *g_regulatorAdapterDev;
static int RegulatorAdapterConsumerPlatformProbe(struct platform_device *platform_dev)
{
if (platform_dev != NULL) {
g_regulatorAdapterDev = platform_dev;
LinuxRegulatorSetConsumerDev(&platform_dev->dev);
HDF_LOGI("%s success", __func__);
return HDF_SUCCESS;
}
HDF_LOGE("%s: fail", __func__);
return HDF_FAILURE;
}
static int RegulatorAdapterConsumerPlatformRemove(struct platform_device *platform_dev)
{
if (platform_dev == NULL) {
HDF_LOGE("%s: fail", __func__);
return HDF_FAILURE;
}
HDF_LOGI("%s: success", __func__);
return HDF_SUCCESS;
}
static struct platform_driver RegulatorAdapterConsumerPlatformDriver = {
.driver = {
.name = "regulator_adapter_consumer01",
.owner = THIS_MODULE,
},
.probe = RegulatorAdapterConsumerPlatformProbe,
.remove = RegulatorAdapterConsumerPlatformRemove,
};
int RegulatorAdapterConsumerInit(void)
{
int ret;
ret = platform_device_register(&RegulatorAdapterConsumerPlatformDevice);
if(ret != 0) {
HDF_LOGE("%s: fail", __func__);
return ret;
}
ret = platform_driver_register(&RegulatorAdapterConsumerPlatformDriver);
return ret;
}
int __init RegulatorAdapterConsumerModuleInit(void)
{
int ret;
ret = platform_device_register(&RegulatorAdapterConsumerPlatformDevice);
if(ret != 0) {
HDF_LOGE("%s: fail", __func__);
return ret;
}
ret = platform_driver_register(&RegulatorAdapterConsumerPlatformDriver);
return ret;
}
void __exit RegulatorAdapterConsumerExit(void)
{
platform_device_unregister(&RegulatorAdapterConsumerPlatformDevice);
platform_driver_unregister(&RegulatorAdapterConsumerPlatformDriver);
}
MODULE_DESCRIPTION("Regulator Adapter Consumer Platform Device");
MODULE_LICENSE("GPL");
+20
View File
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef REGULATOR_ADAPTER_CONSUMER_H
#define REGULATOR_ADAPTER_CONSUMER_H
#include "hdf_base.h"
int RegulatorAdapterConsumerInit(void);
#endif /* REGULATOR_ADAPTER_CONSUMER_H */
+4
View File
@@ -48,6 +48,10 @@ obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI) += $(HDF_FRAMWORK_TEST_ROOT)/platfor
$(HDF_FRAMWORK_TEST_ROOT)/platform/entry/hdf_mipi_dsi_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/mipi_csi_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/entry/hdf_mipi_csi_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/regulator_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/entry/hdf_regulator_entry_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/virtual/regulator_linux_voltage_virtual_driver.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/virtual/regulator_linux_current_virtual_driver.o
obj-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_FRAMWORK_TEST_ROOT)/wifi/hdf_wifi_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/netdevice/net_device_test.o \