Add Richtek RT5120 PMIC support
Subsystems (4)
v4 cover Add Richtek RT5120 PMIC support
From: ChiYuan Huang <[email protected]>
This patch series is to add Richtek RT5120 PMIC support.
In RT5120, it integrates four channels of buck converter, one channel of LDO, and one external enable channel to control the external power source.
rt5120-regulator can be referred in the below link
Since v4:
- Add "Copyright" string and refine for GPL version string.
- Refine the comma usage in mfd. For the last uncertain terminated element in struct arrays, put the comma for it to keep the extensibility.
Since v3:
- Use a 'dev' variable and dev_err_probe to decrease the LOC in mfd.
- Simplify the power key irq handler key report
- Since press and release irq not needed to keep in private data, change 'press', 'release' irq as local variable only.
- Fix Kconfig typo for pwrkey.
Since v2:
- Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
- Fix indention and remove status for powerkey.
- Refine powerkey description for more HW details.
- For the regulator property parsing, use of_property_read_u32 instead.
- Not to overwrite regulator constraint.
- Refine regulator desc coding.
ChiYuan Huang (3):
dt-binding: mfd: Add Richtek RT5120 PMIC support
mfd: rt5120: Add Richtek PMIC support
input: misc: rt5120: Add power key support
.../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++ drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++ drivers/mfd/Kconfig | 12 ++ drivers/mfd/Makefile | 1 + drivers/mfd/rt5120.c | 124 ++++++++++++++ 7 files changed, 434 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml create mode 100644 drivers/input/misc/rt5120-pwrkey.c create mode 100644 drivers/mfd/rt5120.c
Signature · 1 line
2.7.4
PATCH v4 1/3 dt-binding: mfd: Add Richtek RT5120 PMIC support
From: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC devicetree document.
---
Since v2:
- Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
- Fix indention and remove status for powerkey.
- Refine powerkey description for more HW details.
--- .../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml new file +178 -0
@@ -0,0 +1,178 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/richtek,rt5120.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Richtek RT5120 PMIC + +maintainers: + - ChiYuan Huang <[email protected]> + +description: | + The RT5120 provides four high-efficiency buck converters and one LDO voltage + regulator. The device is targeted at providingthe processor voltage, memory, + I/O, and peripheral rails in home entertainment devices. The I2C interface is + used for dynamic voltage scaling of the processor voltage, power rails on/off + sequence control, operation mode selection. + +properties: + compatible: + enum: + - richtek,rt5120 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + interrupt-controller: true + + "#interrupt-cells": + const: 1 + + wakeup-source: true + + richtek,enable-undervolt-hiccup: + type: boolean + description: | + If used, under voltage protection trigger hiccup behavior, else latchup as + default + + richtek,enable-overvolt-hiccup: + type: boolean + description: + Like as 'enable-uv-hiccup', it configures over voltage protection to + hiccup, else latchup as default + + vin1-supply: + description: phandle for buck1 input power source + + vin2-supply: + description: phandle for buck2 input power source + + vin3-supply: + description: phandle for buck3 input power source + + vin4-supply: + description: phandle for buck4 input power source + + vinldo-supply: + description: phandle for ldo input power source + + regulators: + type: object + + patternProperties: + "^buck[1-4]$": + type: object + $ref: /schemas/regulator/regulator.yaml# + unevaluatedProperties: false + + properties: + regulator-allowed-modes: + description: | + Used to specify the allowed buck converter operating mode + mode mapping: + 0: auto mode + 1: force pwm mode + items: + enum: [0, 1] + + "^(ldo|exten)$": + type: object + $ref: /schemas/regulator/regulator.yaml# + unevaluatedProperties: false + + additionalProperties: false + + powerkey: + type: object + description: + PON key that connected to RT5120 PMIC. + + properties: + compatible: + enum: + - richtek,rt5120-pwrkey + + required: + - compatible + + additionalProperties: false + +required: + - compatible + - reg + - interrupts + - '#interrupt-cells' + - interrupt-controller + - regulators + - powerkey + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + pmic@62 { + compatible = "richtek,rt5120"; + reg = <0x62>; + interrupts-extended = <&gpio_intc 32 IRQ_TYPE_LEVEL_LOW>; + interrupt-controller; + #interrupt-cells = <1>; + wakeup-source; + + regulators { + buck1 { + regulator-name = "rt5120-buck1"; + regulator-min-microvolt = <600000>; + regulator-max-microvolt = <1393750>; + regulator-allowed-modes = <0 1>; + regulator-boot-on; + }; + buck2 { + regulator-name = "rt5120-buck2"; + regulator-min-microvolt = <1100000>; + regulator-max-microvolt = <1100000>; + regulator-allowed-modes = <0 1>; + regulator-always-on; + }; + buck3 { + regulator-name = "rt5120-buck3"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-allowed-modes = <0 1>; + regulator-always-on; + }; + buck4 { + regulator-name = "rt5120-buck4"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-allowed-modes = <0 1>; + regulator-always-on; + }; + ldo { + regulator-name = "rt5120-ldo"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + regulator-always-on; + }; + exten { + regulator-name = "rt5120-exten"; + regulator-min-microvolt = <3000000>; + regulator-max-microvolt = <3000000>; + regulator-always-on; + }; + }; + powerkey { + compatible = "richtek,rt5120-pwrkey"; + }; + }; + };
Signature · 1 line
2.7.4
PATCH v4 2/3 mfd: rt5120: Add Richtek PMIC support
In reply to cy_huangFrom: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC I2C driver.
---
Since v4:
- Add "Copyright" string and refine for GPL version string.
- For the last uncertain terminated element in struct arrays, put the comma for it to keep the extensibility.
Since v3:
- Use a 'dev' variable and dev_err_probe to decrease the LOC in mfd.
--- drivers/mfd/Kconfig | 12 +++++ drivers/mfd/Makefile | 1 + drivers/mfd/rt5120.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/mfd/rt5120.c
drivers/mfd/Kconfig +12 -0
@@ -1128,6 +1128,18 @@ config MFD_RT5033 sub-devices like charger, fuel gauge, flash LED, current source, LDO and Buck. +config MFD_RT5120 + tristate "Richtek RT5120 Power Management IC" + depends on I2C + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + The enables support for Richtek RT5120 PMIC. It includes four high + efficiency buck converters and one LDO voltage regulator. The device + is targeted at providing the CPU voltage, memory, I/O and peripheral + power rails in home entertainment devices. + config MFD_RC5T583 bool "Ricoh RC5T583 Power Management system device" depends on I2C=y
drivers/mfd/Makefile +1 -0
@@ -234,6 +234,7 @@ obj-$(CONFIG_MFD_HI655X_PMIC) += hi655x-pmic.o obj-$(CONFIG_MFD_DLN2) += dln2.o obj-$(CONFIG_MFD_RT4831) += rt4831.o obj-$(CONFIG_MFD_RT5033) += rt5033.o +obj-$(CONFIG_MFD_RT5120) += rt5120.o obj-$(CONFIG_MFD_SKY81452) += sky81452.o intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
drivers/mfd/rt5120.c new file +124 -0
124 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 3/3 input: misc: rt5120: Add power key support
In reply to cy_huangFrom: ChiYuan Huang <[email protected]>
Add RT5120 PMIC power key support.
---
Since v4:
- Add "Copyright" string and refine for GPL version string.
Since v3:
- Simplify the power key irq handler key report
- Since press and release irq not needed to keep in private data, change 'press', 'release' irq as local variable only.
- Fix Kconfig typo for pwrkey.
--- drivers/input/misc/Kconfig | 9 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 drivers/input/misc/rt5120-pwrkey.c
drivers/input/misc/Kconfig +9 -0
@@ -891,6 +891,15 @@ config INPUT_SC27XX_VIBRA To compile this driver as a module, choose M here. The module will be called sc27xx_vibra. +config INPUT_RT5120_PWRKEY + tristate "RT5120 PMIC power key support" + depends on MFD_RT5120 + help + This enables support for RT5120 PMIC power key driver. + + To compile this driver as a module, choose M here. the module will + be called rt5120-pwrkey. + config INPUT_STPMIC1_ONKEY tristate "STPMIC1 PMIC Onkey support" depends on MFD_STPMIC1
drivers/input/misc/Makefile +1 -0
@@ -69,6 +69,7 @@ obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o obj-$(CONFIG_INPUT_REGULATOR_HAPTIC) += regulator-haptic.o obj-$(CONFIG_INPUT_RETU_PWRBUTTON) += retu-pwrbutton.o +obj-$(CONFIG_INPUT_RT5120_PWRKEY) += rt5120-pwrkey.o obj-$(CONFIG_INPUT_AXP20X_PEK) += axp20x-pek.o obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o obj-$(CONFIG_INPUT_RK805_PWRKEY) += rk805-pwrkey.o
drivers/input/misc/rt5120-pwrkey.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [PATCH v4 2/3] mfd: rt5120: Add Richtek PMIC support
In reply to cy_huangQuoted 14 lines · cy_huang
From: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC I2C driver.
Signed-off-by ChiYuan Huang <[email protected]>---
Since v4:
- Add "Copyright" string and refine for GPL version string.
- For the last uncertain terminated element in struct arrays, put the comma for it to keep the extensibility.Since v3:
- Use a 'dev' variable anddev_err_probeto decrease the LOC in mfd.
Quoted 6 lines
--- drivers/mfd/Kconfig | 12 +++++ drivers/mfd/Makefile | 1 + drivers/mfd/rt5120.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 drivers/mfd/rt5120.c
Applied, thanks.
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v4 1/3] dt-binding: mfd: Add Richtek RT5120 PMIC support
In reply to cy_huangQuoted 12 lines · cy_huang
From: ChiYuan Huang <[email protected]>
Add Richtek RT5120 PMIC devicetree document.
Reviewed-by Krzysztof Kozlowski <[email protected]>Signed-off-by ChiYuan Huang <[email protected]>---
Since v2:
- Add 'unevaluatedProperties: false' for regulator buck1~4/ldo/exten.
- Fix indention and remove status for powerkey.
- Refine powerkey description for more HW details.
Quoted 4 lines
--- .../devicetree/bindings/mfd/richtek,rt5120.yaml | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/richtek,rt5120.yaml
Applied, thanks.
Signature · 1 line
Lee Jones [李琼斯]
Re: [PATCH v4 3/3] input: misc: rt5120: Add power key support
In reply to cy_huangDear reviewers:
cy_huang <[email protected]> 於 2022年8月10日 週三 上午10:55寫道:
Quoted 10 lines
From: ChiYuan Huang <[email protected]>
Add RT5120 PMIC power key support.
Signed-off-by ChiYuan Huang <[email protected]>---
Since v4:
- Add "Copyright" string and refine for GPL version string.
Quoted 6 lines
Since v3:
- Simplify the power key irq handler key report
- Since press and release irq not needed to keep in private data, change 'press', 'release' irq as local variable only.
- FixKconfigtypo for pwrkey.
Since binding/mfd/regulator are all applied, only this one is left. Any update about this pwrkey patch?
Quoted 157 lines
--- drivers/input/misc/Kconfig | 9 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/rt5120-pwrkey.c | 109 +++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 drivers/input/misc/rt5120-pwrkey.cdrivers/input/misc/Kconfig +9
-0@@ -891,6 +891,15 @@ config INPUT_SC27XX_VIBRA To compile this driver as a module, choose M here. The module will be called sc27xx_vibra. +config INPUT_RT5120_PWRKEY + tristate "RT5120 PMIC power key support" + depends on MFD_RT5120 + help + This enables support for RT5120 PMIC power key driver. + + To compile this driver as a module, choose M here. the module will + be called rt5120-pwrkey. + config INPUT_STPMIC1_ONKEY tristate "STPMIC1 PMIC Onkey support" depends on MFD_STPMIC1drivers/input/misc/Makefile +1
-0@@ -69,6 +69,7 @@ obj-$(CONFIG_INPUT_RAVE_SP_PWRBUTTON) += rave-sp-pwrbutton.o obj-$(CONFIG_INPUT_RB532_BUTTON) += rb532_button.o obj-$(CONFIG_INPUT_REGULATOR_HAPTIC) += regulator-haptic.o obj-$(CONFIG_INPUT_RETU_PWRBUTTON) += retu-pwrbutton.o +obj-$(CONFIG_INPUT_RT5120_PWRKEY) += rt5120-pwrkey.o obj-$(CONFIG_INPUT_AXP20X_PEK) += axp20x-pek.o obj-$(CONFIG_INPUT_GPIO_ROTARY_ENCODER) += rotary_encoder.o obj-$(CONFIG_INPUT_RK805_PWRKEY) += rk805-pwrkey.odrivers/input/misc/rt5120-pwrkey.c new file +109
-1@@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (C) 2022 Richtek Technology Corp. +* Author: ChiYuan Huang <[email protected]> +*/ + +#include <linux/bits.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mod_devicetable.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define RT5120_REG_INTSTAT 0x1E +#define RT5120_PWRKEYSTAT_MASK BIT(7) + +struct rt5120_priv { +struct regmap *regmap; +struct input_dev *input; +}; + +static irqreturn_t rt5120_pwrkey_handler (int irq,void *devid) +{ +struct rt5120_priv *priv = devid; +unsigned int stat; +int ret; + + ret =regmap_read (priv->regmap,RT5120_REG_INTSTAT , &stat); +if (ret) +return IRQ_NONE ; + +input_report_key (priv->input,KEY_POWER , + !(stat &RT5120_PWRKEYSTAT_MASK )); +input_sync (priv->input); + +return IRQ_HANDLED ; +} + +static int rt5120_pwrkey_probe (struct platform_device *pdev) +{ +struct rt5120_priv *priv; +struct device *dev = &pdev->dev; +int press_irq, release_irq; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->regmap =dev_get_regmap (dev->parent,NULL ); +if (!priv->regmap) +return dev_err_probe (dev, -ENODEV ,"Failed to init regmap\n" ); + + press_irq =platform_get_irq_byname (pdev,"pwrkey-press" ); +if (press_irq <0 ) +return press_irq; + + release_irq =platform_get_irq_byname (pdev,"pwrkey-release" ); +if (release_irq <0 ) +return release_irq; + +/* Make input device be device resource managed */ + priv->input =devm_input_allocate_device (dev); +if (!priv->input) +return dev_err_probe (dev, -ENOMEM , +"Failed to allocate input device\n" ); + + priv->input->name ="rt5120_pwrkey" ; + priv->input->phys ="rt5120_pwrkey/input0" ; + priv->input->id.bustype =BUS_I2C ; +input_set_capability (priv->input,EV_KEY ,KEY_POWER ); + + ret =input_register_device (priv->input); +if (ret) +return dev_err_probe (dev, ret, +"Failed to register input device\n" ); + + ret =devm_request_threaded_irq (dev, press_irq,NULL , + rt5120_pwrkey_handler,0 , +"pwrkey-press" , priv); +if (ret) +return dev_err_probe (dev, ret, +"Failed to register pwrkey press irq\n" ); + +return devm_request_threaded_irq (dev, release_irq,NULL , + rt5120_pwrkey_handler,0 , +"pwrkey-release" , priv); +} + +static const struct of_device_id r5120_pwrkey_match_table[] = { + { .compatible ="richtek,rt5120-pwrkey" }, + {} +}; +MODULE_DEVICE_TABLE (of, r5120_pwrkey_match_table); + +static struct platform_driver rt5120_pwrkey_driver = { + .driver = { + .name ="rt5120-pwrkey" , + .of_match_table = r5120_pwrkey_match_table, + }, + .probe = rt5120_pwrkey_probe, +}; +module_platform_driver (rt5120_pwrkey_driver); + +MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("Richtek RT5120 power key driver" ); +MODULE_LICENSE ("GPL v2" ); --2.7.4
Dmitry Torokhov
maintainerRe: [PATCH v4 3/3] input: misc: rt5120: Add power key support
In reply to cy_huangHi ChiYuan,
drivers/input/misc/rt5120-pwrkey.c line 109
Quoted 3 lines · cy_huang
drivers/input/misc/rt5120-pwrkey.c new file +3
-0+MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("Richtek RT5120 power key driver" ); +MODULE_LICENSE ("GPL v2" );
I changed this to be simply "GPL" (per checkpatch.pl, see commit 'bf7fbeeae6db module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity' for details) + did a couple of minor edits, and applied, thank you.
Signature · 1 line
Dmitry
Re: [PATCH v4 3/3] input: misc: rt5120: Add power key support
Dmitry Torokhov <[email protected]> 於 2022年9月1日 週四 清晨6:47寫道:
Quoted 4 lines
Hi ChiYuan,
On Wed, Aug 10, 2022 at 10:55:42AM +0800,
cy_huangwrote:
Quoted 9 lines
drivers/input/misc/rt5120-pwrkey.c line 109
Quoted 3 lines
drivers/input/misc/rt5120-pwrkey.c new file +3
-0+MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("Richtek RT5120 power key driver" ); +MODULE_LICENSE ("GPL v2" );I changed this to be simply "GPL" (per checkpatch.pl, see commit '
bf7fbeeae6dbmodule: Cure theMODULE_LICENSE"GPL" vs. "GPL v2" bogosity' for details) + did a couple of minor edits, and applied, thank you.
Ok, got it.
Old "GPL" text as GPL v2 or "later", and the "later" keyword is the problem. This patch is to fix it.
How about the SPDX license string? The same definition?
Quoted 2 lines
--
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH v4 3/3] input: misc: rt5120: Add power key support
Quoted 14 lines · ChiYuan Huang
Dmitry Torokhov <[email protected]> 於 2022年9月1日 週四 清晨6:47寫道:
Quoted 4 lines
Hi ChiYuan,
On Wed, Aug 10, 2022 at 10:55:42AM +0800,
cy_huangwrote:Quoted 9 lines
drivers/input/misc/rt5120-pwrkey.c line 109
Quoted 3 lines
drivers/input/misc/rt5120-pwrkey.c new file +3
-0+MODULE_AUTHOR ("ChiYuan Huang <[email protected]>" ); +MODULE_DESCRIPTION ("Richtek RT5120 power key driver" ); +MODULE_LICENSE ("GPL v2" );I changed this to be simply "GPL" (per checkpatch.pl, see commit '
bf7fbeeae6dbmodule: Cure theMODULE_LICENSE"GPL" vs. "GPL v2" bogosity' for details) + did a couple of minor edits, and applied, thank you.
Quoted 5 lines
Ok, got it.
Old "GPL" text as GPL v2 or "later", and the "later" keyword is the problem. This patch is to fix it.How about the SPDX license string? The same definition?
No, MODULE_LICENSE() is sorely for symbol resolution during module loading, so GPL vs GPLv2 or later, etc is all the same. SPDX denotes the actual license for the source code that governs derivative works, etc. and I did not change it - it is left exactly as you sent it:
// SPDX-License-Identifier: GPL-2.0-only
Thanks.
Signature · 1 line
Dmitry