From nobody Tue Jun 30 23:33:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51A17C433EF for ; Thu, 6 Jan 2022 22:44:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245237AbiAFWoK (ORCPT ); Thu, 6 Jan 2022 17:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245223AbiAFWoJ (ORCPT ); Thu, 6 Jan 2022 17:44:09 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4397BC061245; Thu, 6 Jan 2022 14:44:09 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E6E711414; Thu, 6 Jan 2022 23:44:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1641509047; bh=TTqB7Ua6ydtiTPPtx5b//2HRwPIaNssqss7QoV49ehg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zb2LdJbrzo4f85KRRUqC4P182lwxDfD5PbRtmUvB9g9eYvnILIwZwEoRZzHX9ax15 gPtqwh8Sc5HndqYqdkZdYUR2YV2fJvudNJS1tGXEwN1jZfsktczlNGPys4dIHny393 ptYFgvIxyXtax66PJ06DjBl+U50Fc1LNcWCoD5TM= From: Laurent Pinchart To: linux-kernel@vger.kernel.org Cc: Watson Chow , Liam Girdwood , Mark Brown , Laurent Pinchart , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v2 1/2] dt-bindings: regulators: Add bindings for Maxim MAX20086-MAX20089 Date: Fri, 7 Jan 2022 00:43:49 +0200 Message-Id: <20220106224350.16957-2-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220106224350.16957-1-laurent.pinchart+renesas@ideasonboard.com> References: <20220106224350.16957-1-laurent.pinchart+renesas@ideasonboard.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Laurent Pinchart The MAX20086-MAX20089 are dual/quad power protectors for cameras. Add corresponding DT bindings. Signed-off-by: Laurent Pinchart --- Changes since v1: - Make OUT nodes optional --- .../bindings/regulator/maxim,max20086.yaml | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 Documentation/devicetree/bindings/regulator/maxim,max20= 086.yaml diff --git a/Documentation/devicetree/bindings/regulator/maxim,max20086.yam= l b/Documentation/devicetree/bindings/regulator/maxim,max20086.yaml new file mode 100644 index 000000000000..05f72391185e --- /dev/null +++ b/Documentation/devicetree/bindings/regulator/maxim,max20086.yaml @@ -0,0 +1,106 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/regulator/maxim,max20086.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim Integrated MAX20086-MAX20089 Camera Power Protector + +maintainers: + - Laurent Pinchart + +description: | + The MAX20086-MAX20089 are dual/quad camera power protectors, designed to + deliver power over coax for radar and camera modules. They support + software-configurable output switching and monitoring. The output voltag= e and + current limit are fixed by the hardware design. + +properties: + compatible: + enum: + - maxim,max20086 + - maxim,max20087 + - maxim,max20088 + - maxim,max20089 + + reg: + maxItems: 1 + + enable-gpios: + maxItems: 1 + description: GPIO connected to the EN pin, active high + + in-supply: + description: Input supply for the camera outputs (IN pin, 3.0V to 15.0= V) + + vdd-supply: + description: Input supply for the device (VDD pin, 3.0V to 5.5V) + + regulators: + type: object + + patternProperties: + "^OUT[1-4]$": + type: object + $ref: regulator.yaml# + + additionalProperties: false + +required: + - compatible + - reg + - in-supply + - vdd-supply + - regulators + +allOf: + - if: + properties: + compatible: + contains: + enum: + - maxim,max20088 + - maxim,max20089 + then: + properties: + regulators: + properties: + OUT3: false + OUT4: false + +additionalProperties: false + +examples: + - | + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + regulator@28 { + compatible =3D "maxim,max20087"; + reg =3D <0x28>; + + in-supply =3D <®_12v0>; + vdd-supply =3D <®_3v3>; + + enable-gpios =3D <&gpio 108 GPIO_ACTIVE_HIGH>; + + regulators { + OUT1 { + regulator-name =3D "VOUT1"; + }; + OUT2 { + regulator-name =3D "VOUT2"; + }; + OUT3 { + regulator-name =3D "VOUT3"; + }; + OUT4 { + regulator-name =3D "VOUT4"; + }; + }; + }; + }; +... --=20 Regards, Laurent Pinchart From nobody Tue Jun 30 23:33:28 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9B89C433EF for ; Thu, 6 Jan 2022 22:44:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245261AbiAFWoO (ORCPT ); Thu, 6 Jan 2022 17:44:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245242AbiAFWoL (ORCPT ); Thu, 6 Jan 2022 17:44:11 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D55C061245 for ; Thu, 6 Jan 2022 14:44:10 -0800 (PST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B99F914C3; Thu, 6 Jan 2022 23:44:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1641509048; bh=PMoQ3qm9V9YbbkBVH0MolpRSxLTqQoE2BG2WWs2FpEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mI6p8jZ8kYf/Xu0LoE6Uv4bJErSFud3jxSZJeAe6gUtumXQBfO+A/TfT5mleeItWJ 5jVqnY6q6HkQt7bZsNJdRPmz7gTykbEByd9aHvR/woVcXNwl1W+JaAQJxtnPs4rEn/ c1ZH6IlDXSNa6/06wrBdWfRGsVJPwAldGhHtHyUo= From: Laurent Pinchart To: linux-kernel@vger.kernel.org Cc: Watson Chow , Liam Girdwood , Mark Brown Subject: [PATCH v2 2/2] regulator: Add MAX20086-MAX20089 driver Date: Fri, 7 Jan 2022 00:43:50 +0200 Message-Id: <20220106224350.16957-3-laurent.pinchart+renesas@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220106224350.16957-1-laurent.pinchart+renesas@ideasonboard.com> References: <20220106224350.16957-1-laurent.pinchart+renesas@ideasonboard.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Watson Chow The MAX20086-MAX20089 are dual/quad power protectors for cameras. Add a driver that supports controlling the outputs individually. Additional features, such as overcurrent detection, may be added later if needed. Signed-off-by: Watson Chow Signed-off-by: Laurent Pinchart --- Changes since v1: - Use C++ comment style for top header - Unconditionally register all outputs - Fix W=3D1 warning - Don't disable all outputs at probe time - Wire up enable GPIO to regulators --- MAINTAINERS | 7 + drivers/regulator/Kconfig | 10 +- drivers/regulator/Makefile | 1 + drivers/regulator/max20086-regulator.c | 332 +++++++++++++++++++++++++ 4 files changed, 349 insertions(+), 1 deletion(-) create mode 100644 drivers/regulator/max20086-regulator.c diff --git a/MAINTAINERS b/MAINTAINERS index 79fd8a012893..2891e71c0b9e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -11577,6 +11577,13 @@ S: Maintained F: Documentation/devicetree/bindings/power/supply/maxim,max17042.yaml F: drivers/power/supply/max17042_battery.c =20 +MAXIM MAX20086 CAMERA POWER PROTECTOR DRIVER +M: Laurent Pinchart +L: linux-kernel@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/regulator/maxim,max20086.yaml +F: drivers/regulator/max20086-regulator.c + MAXIM MAX77650 PMIC MFD DRIVER M: Bartosz Golaszewski L: linux-kernel@vger.kernel.org diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 6be9b1c8a615..dd5c70fe7438 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig @@ -636,6 +636,15 @@ config REGULATOR_MAX8998 via I2C bus. The provided regulator is suitable for S3C6410 and S5PC1XX chips to control VCC_CORE and VCC_USIM voltages. =20 +config REGULATOR_MAX20086 + tristate "Maxim MAX20086-MAX20089 Camera Power Protectors" + depends on I2C + select REGMAP_I2C + help + This driver controls a Maxim MAX20086-MAX20089 camera power + protectorvia I2C bus. The regulator has 2 or 4 outputs depending on + the device model. This driver is only capable to turn on/off them. + config REGULATOR_MAX77686 tristate "Maxim 77686 regulator" depends on MFD_MAX77686 || COMPILE_TEST @@ -1415,4 +1424,3 @@ config REGULATOR_QCOM_LABIBB for LCD display panel. =20 endif - diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index b07d2a22df0b..a9e986231eb8 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile @@ -78,6 +78,7 @@ obj-$(CONFIG_REGULATOR_MAX8952) +=3D max8952.o obj-$(CONFIG_REGULATOR_MAX8973) +=3D max8973-regulator.o obj-$(CONFIG_REGULATOR_MAX8997) +=3D max8997-regulator.o obj-$(CONFIG_REGULATOR_MAX8998) +=3D max8998.o +obj-$(CONFIG_REGULATOR_MAX20086) +=3D max20086-regulator.o obj-$(CONFIG_REGULATOR_MAX77686) +=3D max77686-regulator.o obj-$(CONFIG_REGULATOR_MAX77693) +=3D max77693-regulator.o obj-$(CONFIG_REGULATOR_MAX77802) +=3D max77802-regulator.o diff --git a/drivers/regulator/max20086-regulator.c b/drivers/regulator/max= 20086-regulator.c new file mode 100644 index 000000000000..fbc56b043071 --- /dev/null +++ b/drivers/regulator/max20086-regulator.c @@ -0,0 +1,332 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// +// max20086-regulator.c - MAX20086-MAX20089 camera power protector driver +// +// Copyright (C) 2022 Laurent Pinchart +// Copyright (C) 2018 Avnet, Inc. + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Register Offset */ +#define MAX20086_REG_MASK 0x00 +#define MAX20086_REG_CONFIG 0x01 +#define MAX20086_REG_ID 0x02 +#define MAX20086_REG_STAT1 0x03 +#define MAX20086_REG_STAT2_L 0x04 +#define MAX20086_REG_STAT2_H 0x05 +#define MAX20086_REG_ADC1 0x06 +#define MAX20086_REG_ADC2 0x07 +#define MAX20086_REG_ADC3 0x08 +#define MAX20086_REG_ADC4 0x09 + +/* DEVICE IDs */ +#define MAX20086_DEVICE_ID_MAX20086 0x40 +#define MAX20086_DEVICE_ID_MAX20087 0x20 +#define MAX20086_DEVICE_ID_MAX20088 0x10 +#define MAX20086_DEVICE_ID_MAX20089 0x00 +#define DEVICE_ID_MASK 0xf0 + +/* Register bits */ +#define MAX20086_EN_MASK 0x0f +#define MAX20086_EN_OUT1 0x01 +#define MAX20086_EN_OUT2 0x02 +#define MAX20086_EN_OUT3 0x04 +#define MAX20086_EN_OUT4 0x08 +#define MAX20086_INT_DISABLE_ALL 0x3f + +#define MAX20086_MAX_REGULATORS 4 + +struct max20086_chip_info { + u8 id; + unsigned int num_outputs; +}; + +struct max20086_regulator { + struct device_node *of_node; + struct regulator_init_data *init_data; + const struct regulator_desc *desc; + struct regulator_dev *rdev; +}; + +struct max20086 { + struct device *dev; + struct regmap *regmap; + struct gpio_desc *ena_gpiod; + + const struct max20086_chip_info *info; + + struct max20086_regulator regulators[MAX20086_MAX_REGULATORS]; +}; + +static const struct regulator_ops max20086_buck_ops =3D { + .enable =3D regulator_enable_regmap, + .disable =3D regulator_disable_regmap, + .is_enabled =3D regulator_is_enabled_regmap, +}; + +#define MAX20086_REGULATOR_DESC(n) \ +{ \ + .name =3D "OUT"#n, \ + .supply_name =3D "in", \ + .id =3D (n) - 1, \ + .ops =3D &max20086_buck_ops, \ + .type =3D REGULATOR_VOLTAGE, \ + .owner =3D THIS_MODULE, \ + .enable_reg =3D MAX20086_REG_CONFIG, \ + .enable_mask =3D 1 << ((n) - 1), \ + .enable_val =3D 1 << ((n) - 1), \ + .disable_val =3D 0, \ +} + +static const char * const max20086_output_names[] =3D { + "OUT1", + "OUT2", + "OUT3", + "OUT4", +}; + +static const struct regulator_desc max20086_regulators[] =3D { + MAX20086_REGULATOR_DESC(1), + MAX20086_REGULATOR_DESC(2), + MAX20086_REGULATOR_DESC(3), + MAX20086_REGULATOR_DESC(4), +}; + +static int max20086_regulators_register(struct max20086 *chip) +{ + unsigned int i; + + for (i =3D 0; i < chip->info->num_outputs; i++) { + struct max20086_regulator *reg =3D &chip->regulators[i]; + struct regulator_config config =3D { }; + struct regulator_dev *rdev; + + config.dev =3D chip->dev; + config.init_data =3D reg->init_data; + config.driver_data =3D chip; + config.of_node =3D reg->of_node; + config.regmap =3D chip->regmap; + config.ena_gpiod =3D chip->ena_gpiod; + + rdev =3D devm_regulator_register(chip->dev, reg->desc, &config); + if (IS_ERR(rdev)) { + dev_err(chip->dev, + "Failed to register regulator output %s\n", + reg->desc->name); + return PTR_ERR(rdev); + } + + reg->rdev =3D rdev; + } + + return 0; +} + +static int max20086_parse_regulators_dt(struct max20086 *chip, bool *boot_= on) +{ + struct of_regulator_match matches[MAX20086_MAX_REGULATORS] =3D { }; + struct device_node *node; + unsigned int i; + int ret; + + node =3D of_get_child_by_name(chip->dev->of_node, "regulators"); + if (!node) { + dev_err(chip->dev, "regulators node not found\n"); + return PTR_ERR(node); + } + + for (i =3D 0; i < chip->info->num_outputs; ++i) + matches[i].name =3D max20086_output_names[i]; + + ret =3D of_regulator_match(chip->dev, node, matches, + chip->info->num_outputs); + of_node_put(node); + if (ret < 0) { + dev_err(chip->dev, "Failed to match regulators\n"); + return -EINVAL; + } + + *boot_on =3D false; + + for (i =3D 0; i < chip->info->num_outputs; i++) { + struct max20086_regulator *reg =3D &chip->regulators[i]; + + reg->init_data =3D matches[i].init_data; + reg->of_node =3D matches[i].of_node; + reg->desc =3D &max20086_regulators[i]; + + if (reg->init_data) { + if (reg->init_data->constraints.always_on || + reg->init_data->constraints.boot_on) + *boot_on =3D true; + } + } + + return 0; +} + +static int max20086_detect(struct max20086 *chip) +{ + unsigned int data; + int ret; + + ret =3D regmap_read(chip->regmap, MAX20086_REG_ID, &data); + if (ret < 0) { + dev_err(chip->dev, "Failed to read DEVICE_ID reg: %d\n", ret); + return ret; + } + + if ((data & DEVICE_ID_MASK) !=3D chip->info->id) { + dev_err(chip->dev, "Invalid device ID 0x%02x\n", data); + return -ENXIO; + } + + return 0; +} + +static bool max20086_gen_is_writeable_reg(struct device *dev, unsigned int= reg) +{ + switch (reg) { + case MAX20086_REG_MASK: + case MAX20086_REG_CONFIG: + return true; + default: + return false; + } +} + +static const struct regmap_config max20086_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .writeable_reg =3D max20086_gen_is_writeable_reg, + .max_register =3D 0x9, + .cache_type =3D REGCACHE_NONE, +}; + +static int max20086_i2c_probe(struct i2c_client *i2c) +{ + struct max20086 *chip; + enum gpiod_flags flags; + bool boot_on; + int ret; + + chip =3D devm_kzalloc(&i2c->dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + chip->dev =3D &i2c->dev; + chip->info =3D device_get_match_data(chip->dev); + + i2c_set_clientdata(i2c, chip); + + chip->regmap =3D devm_regmap_init_i2c(i2c, &max20086_regmap_config); + if (IS_ERR(chip->regmap)) { + ret =3D PTR_ERR(chip->regmap); + dev_err(chip->dev, "Failed to allocate register map: %d\n", ret); + return ret; + } + + ret =3D max20086_parse_regulators_dt(chip, &boot_on); + if (ret < 0) + return ret; + + ret =3D max20086_detect(chip); + if (ret < 0) + return ret; + + /* Until IRQ support is added, just disable all interrupts. */ + ret =3D regmap_update_bits(chip->regmap, MAX20086_REG_MASK, + MAX20086_INT_DISABLE_ALL, + MAX20086_INT_DISABLE_ALL); + if (ret < 0) { + dev_err(chip->dev, "Failed to disable interrupts: %d\n", ret); + return ret; + } + + /* + * Get the enable GPIO. If any of the outputs is marked as being + * enabled at boot, request the GPIO with an initial high state to + * avoid disabling outputs that may have been turned on by the boot + * loader. Otherwise, request it with a low state to enter lower-power + * shutdown. + */ + flags =3D boot_on ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + chip->ena_gpiod =3D devm_gpiod_get(chip->dev, "enable", flags); + if (IS_ERR(chip->ena_gpiod)) { + ret =3D PTR_ERR(chip->ena_gpiod); + dev_err(chip->dev, "Failed to get enable GPIO: %d\n", ret); + return ret; + } + + ret =3D max20086_regulators_register(chip); + if (ret < 0) { + dev_err(chip->dev, "Failed to register regulators: %d\n", ret); + return ret; + } + + return 0; +} + +static const struct i2c_device_id max20086_i2c_id[] =3D { + { "max20086" }, + { "max20087" }, + { "max20088" }, + { "max20089" }, + { /* Sentinel */ }, +}; + +MODULE_DEVICE_TABLE(i2c, max20086_i2c_id); + +static const struct of_device_id max20086_dt_ids[] =3D { + { + .compatible =3D "maxim,max20086", + .data =3D &(const struct max20086_chip_info) { + .id =3D MAX20086_DEVICE_ID_MAX20086, + .num_outputs =3D 4, + } + }, { + .compatible =3D "maxim,max20087", + .data =3D &(const struct max20086_chip_info) { + .id =3D MAX20086_DEVICE_ID_MAX20087, + .num_outputs =3D 4, + } + }, { + .compatible =3D "maxim,max20088", + .data =3D &(const struct max20086_chip_info) { + .id =3D MAX20086_DEVICE_ID_MAX20088, + .num_outputs =3D 2, + } + }, { + .compatible =3D "maxim,max20089", + .data =3D &(const struct max20086_chip_info) { + .id =3D MAX20086_DEVICE_ID_MAX20089, + .num_outputs =3D 2, + } + }, + { /* Sentinel */ }, +}; + +MODULE_DEVICE_TABLE(of, max20086_dt_ids); + +static struct i2c_driver max20086_regulator_driver =3D { + .driver =3D { + .name =3D "max20086", + .of_match_table =3D of_match_ptr(max20086_dt_ids), + }, + .probe_new =3D max20086_i2c_probe, + .id_table =3D max20086_i2c_id, +}; + +module_i2c_driver(max20086_regulator_driver); + +MODULE_AUTHOR("Watson Chow "); +MODULE_DESCRIPTION("MAX20086-MAX20089 Camera Power Protector Driver"); +MODULE_LICENSE("GPL"); --=20 Regards, Laurent Pinchart