diff --git a/CODEOWNERS b/CODEOWNERS index 2a3d3ccb249..a66b68c16c7 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -373,6 +373,7 @@ /drivers/led_strip/ @mbolivar-ampere /drivers/lora/ @Mani-Sadhasivam /drivers/mbox/ @carlocaione +/drivers/mfd/mfd_max20335.c @bbilas /drivers/misc/ @tejlmand /drivers/misc/ft8xx/ @hubertmis /drivers/mm/ @dcpleung diff --git a/drivers/mfd/CMakeLists.txt b/drivers/mfd/CMakeLists.txt index e8e59dd1692..7c5e048fcc6 100644 --- a/drivers/mfd/CMakeLists.txt +++ b/drivers/mfd/CMakeLists.txt @@ -3,6 +3,7 @@ zephyr_library() +zephyr_library_sources_ifdef(CONFIG_MFD_MAX20335 mfd_max20335.c) zephyr_library_sources_ifdef(CONFIG_MFD_NCT38XX mfd_nct38xx.c) zephyr_library_sources_ifdef(CONFIG_MFD_NPM1300 mfd_npm1300.c) zephyr_library_sources_ifdef(CONFIG_MFD_NPM6001 mfd_npm6001.c) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 3edbbab1fc4..1a80cf446f5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -19,6 +19,7 @@ config MFD_INIT_PRIORITY Multi-function devices initialization priority. source "drivers/mfd/Kconfig.axp192" +source "drivers/mfd/Kconfig.max20335" source "drivers/mfd/Kconfig.nct38xx" source "drivers/mfd/Kconfig.npm1300" source "drivers/mfd/Kconfig.npm6001" diff --git a/drivers/mfd/Kconfig.max20335 b/drivers/mfd/Kconfig.max20335 new file mode 100644 index 00000000000..3d146de17f0 --- /dev/null +++ b/drivers/mfd/Kconfig.max20335 @@ -0,0 +1,10 @@ +# Copyright (c) 2023 Grinn +# SPDX -License-Identifier: Apache-2.0 + +config MFD_MAX20335 + bool "MAX20335 PMIC multi-function device driver" + default y + depends on DT_HAS_MAXIM_MAX20335_ENABLED + select I2C + help + Enable the Maxim MAX20335 PMIC multi-function device driver diff --git a/drivers/mfd/mfd_max20335.c b/drivers/mfd/mfd_max20335.c new file mode 100644 index 00000000000..7ea6a9f198c --- /dev/null +++ b/drivers/mfd/mfd_max20335.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 Grinn + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT maxim_max20335 + +#include + +#include +#include + +#define MAX20335_REG_CHIP_ID 0x00 +#define MAX20335_CHIP_ID_VAL 0x04 + +struct mfd_max20335_config { + struct i2c_dt_spec bus; +}; + +static int mfd_max20335_init(const struct device *dev) +{ + const struct mfd_max20335_config *config = dev->config; + uint8_t val; + int ret; + + if (!i2c_is_ready_dt(&config->bus)) { + return -ENODEV; + } + + ret = i2c_reg_read_byte_dt(&config->bus, MAX20335_REG_CHIP_ID, &val); + if (ret < 0) { + return ret; + } + + if (val != MAX20335_CHIP_ID_VAL) { + return -ENODEV; + } + + return 0; +} + +#define MFD_MA20335_DEFINE(inst) \ + static const struct mfd_max20335_config mfd_max20335_config##inst = { \ + .bus = I2C_DT_SPEC_INST_GET(inst), \ + }; \ + \ + DEVICE_DT_INST_DEFINE(inst, mfd_max20335_init, NULL, NULL, \ + &mfd_max20335_config##inst, POST_KERNEL, \ + CONFIG_MFD_INIT_PRIORITY, NULL); + +DT_INST_FOREACH_STATUS_OKAY(MFD_MA20335_DEFINE) diff --git a/dts/bindings/mfd/maxim,max20335.yaml b/dts/bindings/mfd/maxim,max20335.yaml new file mode 100644 index 00000000000..deec53c872d --- /dev/null +++ b/dts/bindings/mfd/maxim,max20335.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2023 Grinn +# SPDX-License-Identifier: Apache-2.0 + +description: Maxim MAX20335 + +compatible: "maxim,max20335" + +include: i2c-device.yaml + +properties: + reg: + required: true