This patch adds regulator driver for MAX77659. Signed-off-by: Nurettin Bolucu <Nurettin.Bolucu@xxxxxxxxxx> Signed-off-by: Zeynep Arslanbenzer <Zeynep.Arslanbenzer@xxxxxxxxxx> --- MAINTAINERS | 1 + drivers/regulator/Kconfig | 8 +++ drivers/regulator/Makefile | 1 + drivers/regulator/max77659-regulator.c | 98 ++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 drivers/regulator/max77659-regulator.c diff --git a/MAINTAINERS b/MAINTAINERS index 5cb8fa452f2d..13c062a8cda2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12649,6 +12649,7 @@ F: Documentation/devicetree/bindings/mfd/adi,max77659.yaml F: Documentation/devicetree/bindings/power/supply/adi,max77659-charger.yaml F: drivers/mfd/max77659.c F: drivers/power/supply/max77659-charger.c +F: drivers/regulator/max77659-regulator.c F: include/linux/mfd/max77659.h MAXIM MAX77714 PMIC MFD DRIVER diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 820c9a0788e5..4a9852c7050f 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -573,6 +573,14 @@ config REGULATOR_MAX77650 Semiconductor. This device has a SIMO with three independent power rails and an LDO. +config REGULATOR_MAX77659 + tristate "Analog Devices MAX77659 Regulator" + depends on MFD_MAX77659 + help + Regulator driver for MAX77659 PMIC from Analog Devices. + This driver supports an LDO regulator. + Say Y here to enable the regulator driver. + config REGULATOR_MAX8649 tristate "Maxim 8649 voltage regulator" depends on I2C diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index b9f5eb35bf5f..a7e91b56fb3f 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o obj-$(CONFIG_REGULATOR_MAX597X) += max597x-regulator.o obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o +obj-$(CONFIG_REGULATOR_MAX77659) += max77659-regulator.o obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o obj-$(CONFIG_REGULATOR_MAX8893) += max8893.o diff --git a/drivers/regulator/max77659-regulator.c b/drivers/regulator/max77659-regulator.c new file mode 100644 index 000000000000..03a565013851 --- /dev/null +++ b/drivers/regulator/max77659-regulator.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/mfd/max77659.h> +#include <linux/of_irq.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/regulator/driver.h> +#include <linux/regulator/of_regulator.h> + +#define MAX77659_LDO_VOLT_REG_MAX 0x7F +#define MAX77659_LDO_VOLT_N_RANGE 0x80 +#define MAX77659_LDO_VOLT_STEP 25000 +#define MAX77659_LDO_VOLT_BASE 500000 + +#define MAX77659_REG_CNFG_LDO0_A 0x38 +#define MAX77659_REG_CNFG_LDO0_B 0x39 + +#define MAX77659_BITS_CONFIG_LDO0_A_TV_LDO GENMASK(6, 0) +#define MAX77659_BITS_CONFIG_LDO0_B_EN_LDO GENMASK(2, 0) + +/* + * 0.500 to 3.675V (25mV step) + */ +static const struct linear_range MAX77659_LDO_volts[] = { + REGULATOR_LINEAR_RANGE(MAX77659_LDO_VOLT_BASE, 0x00, MAX77659_LDO_VOLT_REG_MAX, + MAX77659_LDO_VOLT_STEP), +}; + +static const struct regulator_ops max77659_LDO_ops = { + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_ascend, + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, +}; + +static struct regulator_desc max77659_LDO_desc = { + .name = "LDO", + .id = 0, + .regulators_node = of_match_ptr("regulator"), + .ops = &max77659_LDO_ops, + .type = REGULATOR_VOLTAGE, + .owner = THIS_MODULE, + .n_linear_ranges = MAX77659_LDO_VOLT_N_RANGE, + .linear_ranges = MAX77659_LDO_volts, + .vsel_reg = MAX77659_REG_CNFG_LDO0_A, + .vsel_mask = MAX77659_BITS_CONFIG_LDO0_A_TV_LDO, + .enable_reg = MAX77659_REG_CNFG_LDO0_B, + .enable_mask = MAX77659_BITS_CONFIG_LDO0_B_EN_LDO, + .enable_val = 0x06, + .disable_val = 0x04, +}; + +static int max77659_regulator_probe(struct platform_device *pdev) +{ + struct regulator_dev *rdev; + struct regulator_config config = {}; + + config.dev = &pdev->dev; + + rdev = devm_regulator_register(&pdev->dev, &max77659_LDO_desc, &config); + + if (IS_ERR(rdev)) + return dev_err_probe(&pdev->dev, PTR_ERR(rdev), + "Failed to register regulator %s\n", max77659_LDO_desc.name); + + return 0; +} + +static const struct of_device_id max77659_regulator_of_id[] = { + { .compatible = "adi,max77659-regulator" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, max77659_regulator_of_id); + +static const struct platform_device_id max77659_regulator_id[] = { + { MAX77659_REGULATOR_NAME, 0, }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, max77659_regulator_id); + +static struct platform_driver max77659_regulator_driver = { + .driver = { + .name = MAX77659_REGULATOR_NAME, + .of_match_table = of_match_ptr(max77659_regulator_of_id), + }, + .probe = max77659_regulator_probe, + .id_table = max77659_regulator_id, +}; + +module_platform_driver(max77659_regulator_driver); + +MODULE_DESCRIPTION("max77659 Regulator Driver"); +MODULE_AUTHOR("Nurettin.Bolucu@xxxxxxxxxx, Zeynep.Arslanbenzer@xxxxxxxxxx"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("1.0"); -- 2.25.1