diff --git a/BUILD.gn b/BUILD.gn index 77b4c9e98edc894574880071e649e05ee2f210b0..d8aad09421e656a98002c4d12ea5fc51c763a2d6 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -95,6 +95,7 @@ group("drivers") { "mipi_dsi", "mmc", "pwm", + "regulator", "rtc", "spi", "uart", diff --git a/lite.mk b/lite.mk index 390ebe7faa7ff50370a66cb3e9c365278379f2ea..6191f6e2765dc46568376367070419d030452a7e 100644 --- a/lite.mk +++ b/lite.mk @@ -98,6 +98,11 @@ ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_DMAC), y) LIB_SUBDIRS += $(HISILICON_DRIVERS_ROOT)/dmac endif +ifeq ($(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR), y) + LITEOS_BASELIB += -lhdf_regulator + LIB_SUBDIRS += $(HISILICON_DRIVERS_ROOT)/regulator +endif + ifeq ($(BUILD_FROM_SOURCE), y) ifeq ($(LOSCFG_DRIVERS_HIEDMAC), y) LITEOS_BASELIB += -lhiedmac diff --git a/regulator/BUILD.gn b/regulator/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1f0cce8ac8fe4d5ca3f3e4392c86aa109b660c2e --- /dev/null +++ b/regulator/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//drivers/adapter/khdf/liteos/hdf.gni") + +module_switch = defined(LOSCFG_DRIVERS_HDF_PLATFORM_REGULATOR) +module_name = "hdf_regulator" +hdf_driver(module_name) { + sources = [ "regulator_dummy.c" ] +} diff --git a/regulator/Makefile b/regulator/Makefile new file mode 100755 index 0000000000000000000000000000000000000000..01c6e086e3e4c3ff993274598f1b7822896cf767 --- /dev/null +++ b/regulator/Makefile @@ -0,0 +1,28 @@ +# +# Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include $(LITEOSTOPDIR)/config.mk +include $(LITEOSTOPDIR)/../../drivers/adapter/khdf/liteos/lite.mk + +MODULE_NAME := hdf_regulator + +LOCAL_CFLAGS += $(HDF_INCLUDE) + +LOCAL_SRCS += regulator_dummy.c \ + +LOCAL_CFLAGS += -fstack-protector-strong -Wextra -Wall -Werror -fsigned-char -fno-strict-aliasing -fno-common + +include $(HDF_DRIVER) + diff --git a/regulator/regulator_dummy.c b/regulator/regulator_dummy.c new file mode 100755 index 0000000000000000000000000000000000000000..5f38bbd9bdb4de19eb5258fed8d4ee31b9f9e324 --- /dev/null +++ b/regulator/regulator_dummy.c @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "device_resource_if.h" +#include "hdf_device_desc.h" +#include "hdf_log.h" +#include "osal_io.h" +#include "osal_mem.h" +#include "osal_spinlock.h" +#include "regulator_core.h" +#include "string.h" + +#define HDF_LOG_TAG regulator_dummy + +static int32_t DummyRegulatorEnable(struct RegulatorCntlr *cntlr) +{ + if (cntlr == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorEnable cntlr null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + cntlr->regulatorInfo.status = REGULATOR_STATUS_ON; + REGULATOR_PRINT_LOG_DBG("DummyRegulatorEnable %s success !\n", cntlr->regulatorInfo.pName); + return HDF_SUCCESS; +} + +int32_t DummyRegulatorDisable(struct RegulatorCntlr *cntlr) +{ + if (cntlr == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorDisable cntlr null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + cntlr->regulatorInfo.status = REGULATOR_STATUS_OFF; + REGULATOR_PRINT_LOG_DBG("DummyRegulatorDisable %s success !\n", cntlr->regulatorInfo.pName); + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorSetVoltage(struct RegulatorCntlr *cntlr, uint32_t minUv, uint32_t maxUv) +{ + if (cntlr == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorEnable cntlr null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + REGULATOR_PRINT_LOG_DBG("DummyRegulatorSetVoltage %s [%d, %d] success!\n", + cntlr->regulatorInfo.pName, minUv, maxUv); + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorGetVoltage(struct RegulatorCntlr *cntlr, uint32_t *voltage) +{ + if (cntlr == NULL || voltage == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorGetVoltage param null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + *voltage = 2500; + REGULATOR_PRINT_LOG_DBG("DummyRegulatorGetVoltage get %s %d success !\n", cntlr->regulatorInfo.pName, *voltage); + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorSetCurrent(struct RegulatorCntlr *cntlr, uint32_t minUa, uint32_t maxUa) +{ + if (cntlr == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorSetCurrent cntlr null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + REGULATOR_PRINT_LOG_DBG("DummyRegulatorSetCurrent %s [%d, %d] success!\n", + cntlr->regulatorInfo.pName, minUa, maxUa); + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorGetCurrent(struct RegulatorCntlr *cntlr, uint32_t *current) +{ + if (cntlr == NULL || current == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorGetCurrent param null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + *current = 2500; + REGULATOR_PRINT_LOG_DBG("DummyRegulatorGetCurrent get %s %d success !\n", cntlr->regulatorInfo.pName, *current); + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorGetStatus(struct RegulatorCntlr *cntlr, uint32_t *status) +{ + if (cntlr == NULL || status == NULL) { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorGetStatus param null\n"); + return HDF_ERR_INVALID_OBJECT; + } + + *status = cntlr->regulatorInfo.status; + REGULATOR_PRINT_LOG_DBG("DummyRegulatorGetStatus get %s %d success !\n", cntlr->regulatorInfo.pName, *status); + return HDF_SUCCESS; +} + +static struct RegulatorMethod g_method = { + .enable = DummyRegulatorEnable, + .disable = DummyRegulatorDisable, + .setVoltage = DummyRegulatorSetVoltage, + .getVoltage = DummyRegulatorGetVoltage, + .setCurrent = DummyRegulatorSetCurrent, + .getCurrent = DummyRegulatorGetCurrent, + .getStatus = DummyRegulatorGetStatus, +}; + +static int32_t DummyRegulatorReadHcs(struct RegulatorCntlr *cntrl, const struct DeviceResourceNode *node) +{ + int32_t ret; + struct DeviceResourceIface *drsOps = NULL; + + REGULATOR_PRINT_LOG_DBG("DummyRegulatorReadHcs enter:"); + + drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); + if (drsOps == NULL || drsOps->GetString == NULL) { + REGULATOR_PRINT_LOG_ERR("%s: invalid drs ops fail!", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetString(node, "name", &(cntrl->regulatorInfo.pName), "ERROR"); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read name fail!", __func__); + return HDF_FAILURE; + } + if (cntrl->regulatorInfo.pName != NULL) { + REGULATOR_PRINT_LOG_DBG("DummyRegulatorReadHcs:pName[%s]", cntrl->regulatorInfo.pName); + } else { + REGULATOR_PRINT_LOG_ERR("DummyRegulatorReadHcs:pName NULL"); + return HDF_FAILURE; + } + + ret = drsOps->GetString(node, "supplyName", &(cntrl->regulatorInfo.pSupplyName), "ERROR"); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read supplyName fail!", __func__); + return HDF_FAILURE; + } + if (cntrl->regulatorInfo.pSupplyName != NULL) { + REGULATOR_PRINT_LOG_DBG("DummyRegulatorReadHcs:pSupplyName[%s]", cntrl->regulatorInfo.pSupplyName); + } + + REGULATOR_PRINT_LOG_DBG("DummyRegulatorReadHcs enter:"); + cntrl->regulatorInfo.constraints.alwaysOn = drsOps->GetBool(node, "alwaysOn"); + REGULATOR_PRINT_LOG_DBG("DummyRegulatorReadHcs:alwaysOn[%d]", cntrl->regulatorInfo.constraints.alwaysOn); + + ret = drsOps->GetUint8(node, "mode", &cntrl->regulatorInfo.constraints.mode, 0); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read mode fail!", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint32(node, "minUv", &cntrl->regulatorInfo.constraints.minUv, 0); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read minUv fail!", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint32(node, "maxUv", &cntrl->regulatorInfo.constraints.maxUv, 0); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read maxUv fail!", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint32(node, "minUa", &cntrl->regulatorInfo.constraints.minUa, 0); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read minUa fail!", __func__); + return HDF_FAILURE; + } + + ret = drsOps->GetUint32(node, "maxUa", &cntrl->regulatorInfo.constraints.maxUa, 0); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read maxUa fail!", __func__); + return HDF_FAILURE; + } + + REGULATOR_PRINT_LOG_DBG("regulatorInfo:[%s][%d][%d]--[%d][%d]--[%d][%d]!", + cntrl->regulatorInfo.pName, cntrl->regulatorInfo.constraints.alwaysOn, cntrl->regulatorInfo.constraints.mode, + cntrl->regulatorInfo.constraints.minUv, cntrl->regulatorInfo.constraints.maxUv, + cntrl->regulatorInfo.constraints.minUa, cntrl->regulatorInfo.constraints.maxUa); + + return HDF_SUCCESS; +} + +static int32_t DummyRegulatorParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node) +{ + int32_t ret; + struct RegulatorCntlr *cntrl = NULL; + (void)device; + + cntrl = (struct RegulatorCntlr *)OsalMemCalloc(sizeof(*cntrl)); + if (cntrl == NULL) { + REGULATOR_PRINT_LOG_ERR("%s: malloc cntrl fail!", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + REGULATOR_PRINT_LOG_DBG("DummyRegulatorParseAndInit"); + + ret = DummyRegulatorReadHcs(cntrl, node); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: read drs fail! ret:%d", __func__, ret); + goto __ERR__; + } + + cntrl->priv = (void *)node; + cntrl->ops = &g_method; + + ret = RegulatorCntlrAdd(cntrl); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s: add regulator controller fail:%d!", __func__, ret); + goto __ERR__; + } + return HDF_SUCCESS; + +__ERR__: + REGULATOR_PRINT_LOG_ERR("%s:fail ret:%d", __func__, ret); + if (cntrl != NULL) { + OsalMemFree(cntrl); + cntrl = NULL; + } + return ret; +} + +static int32_t DummyRegulatorInit(struct HdfDeviceObject *device) +{ + int32_t ret = HDF_SUCCESS; + const struct DeviceResourceNode *childNode = NULL; + + REGULATOR_PRINT_LOG_INF("%s: Enter", __func__); + if (device == NULL || device->property == NULL) { + REGULATOR_PRINT_LOG_ERR("%s: device or property is NULL", __func__); + return HDF_ERR_INVALID_OBJECT; + } + + REGULATOR_PRINT_LOG_INF("%s:", __func__); + + DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) { + ret = DummyRegulatorParseAndInit(device, childNode); + if (ret != HDF_SUCCESS) { + REGULATOR_PRINT_LOG_ERR("%s:DummyRegulatorParseAndInit fail", __func__); + RegulatorCntlrRemoveAll(); + return HDF_FAILURE; + } + } + + RegulatorCntlrInitDone(); + REGULATOR_PRINT_LOG_INF("%s: success", __func__); + return HDF_SUCCESS; +} + +static void DummyRegulatorRelease(struct HdfDeviceObject *device) +{ + REGULATOR_PRINT_LOG_INF("%s: enter", __func__); + + if (device == NULL || device->property == NULL) { + REGULATOR_PRINT_LOG_ERR("%s: device or property is NULL", __func__); + return; + } + + RegulatorCntlrRemoveAll(); +} + +struct HdfDriverEntry g_regulatorDriverEntry = { + .moduleVersion = 1, + .moduleName = "hisilicon_dummy_regulator_driver", + .Init = DummyRegulatorInit, + .Release = DummyRegulatorRelease, +}; +HDF_INIT(g_regulatorDriverEntry); diff --git a/regulator/regulator_dummy.h b/regulator/regulator_dummy.h new file mode 100755 index 0000000000000000000000000000000000000000..9d723ca868bdc38fcd6a77095b20d903b1e05596 --- /dev/null +++ b/regulator/regulator_dummy.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* hcs topology for example +* +dev ---+-> Regulator-1(voltage) -+-> Regulator-2(voltage) -+-> Regulator-3(voltage) -+-> Regulator-4(voltage) + | | + | | -+-> Regulator-5(voltage) -+-> Regulator-6(voltage) -+-> Regulator-7(voltage) -+-> Regulator-8(voltage) + | | + | | -+-> Regulator-9 + | + ---+-> Regulator-10(current) + | + | + ---+-> Regulator-11(current) -+-> Regulator-12(current) -+-> Regulator-14(current) + | | + | | -+-> Regulator-13(current) +* +* +*/ + +#ifndef REGULATOR_DUMMY_H +#define REGULATOR_DUMMY_H +#include "los_vm_zone.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif /* REGULATOR_DUMMY_H */ +