Re: [PATCH v7 04/11] mfd: mt6360: Combine mt6360 pmic/ldo resources into mt6360 regulator resources
Gene Chen 於 2021年3月2日 週二 下午3:16寫道: > > Lee Jones 於 2021年1月15日 週五 下午3:32寫道: > > > > On Fri, 15 Jan 2021, Gene Chen wrote: > > > > > Matthias Brugger 於 2021年1月12日 週二 下午8:32寫道: > > > > > > > > > > > > > > > > On 12/11/2020 11:39, Gene Chen wrote: > > > > > From: Gene Chen > > > > > > > > > > Combine mt6360 pmic/ldo resources into mt6360 regulator resources > > > > > to simplify the similar resources object. > > > > > > > > > > Signed-off-by: Gene Chen > > > > > Acked-for-MFD-by: Lee Jones > > > > > --- > > > > > drivers/mfd/mt6360-core.c | 11 +++ > > > > > 1 file changed, 3 insertions(+), 8 deletions(-) > > > > > > > > > > diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c > > > > > index 692e47b..5119e51 100644 > > > > > --- a/drivers/mfd/mt6360-core.c > > > > > +++ b/drivers/mfd/mt6360-core.c > > > > > @@ -265,7 +265,7 @@ static const struct resource > > > > > mt6360_led_resources[] = { > > > > > DEFINE_RES_IRQ_NAMED(MT6360_FLED1_STRB_TO_EVT, > > > > > "fled1_strb_to_evt"), > > > > > }; > > > > > > > > > > -static const struct resource mt6360_pmic_resources[] = { > > > > > +static const struct resource mt6360_regulator_resources[] = { > > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_PGB_EVT, "buck1_pgb_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OC_EVT, "buck1_oc_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OV_EVT, "buck1_ov_evt"), > > > > > @@ -278,9 +278,6 @@ static const struct resource > > > > > mt6360_pmic_resources[] = { > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_OC_EVT, "ldo7_oc_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO6_PGB_EVT, "ldo6_pgb_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_PGB_EVT, "ldo7_pgb_evt"), > > > > > -}; > > > > > - > > > > > -static const struct resource mt6360_ldo_resources[] = { > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO1_OC_EVT, "ldo1_oc_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO2_OC_EVT, "ldo2_oc_evt"), > > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO3_OC_EVT, "ldo3_oc_evt"), > > > > > @@ -298,10 +295,8 @@ static const struct mfd_cell mt6360_devs[] = { > > > > > NULL, 0, 0, "mediatek,mt6360-chg"), > > > > > OF_MFD_CELL("mt6360-led", mt6360_led_resources, > > > > > NULL, 0, 0, "mediatek,mt6360-led"), > > > > > - OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, > > > > > - NULL, 0, 0, "mediatek,mt6360-pmic"), > > > > > - OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, > > > > > - NULL, 0, 0, "mediatek,mt6360-ldo"), > > > > > + OF_MFD_CELL("mt6360-regulator", mt6360_regulator_resources, > > > > > + NULL, 0, 0, "mediatek,mt6360-regulator"), > > > > > > > > As discussed with the MFD maintainer [1], the regulator (and probably > > > > all cells) > > > > shouldn't have a DT binding. > > > > > > > > So please send a new version which fixes that. > > > > > > > > Regards, > > > > Matthias > > > > > > > > [1] > > > > https://lore.kernel.org/linux-mediatek/2021064118.ge4...@sirena.org.uk/ > > > > I don't think Mark is correct here. > > > > We usually do implement compatible strings for sub-devices and they do > > tend to have their own device nodes. > > > > It's a very long time ago since I coded this up myself, but from > > memory, you can't have 2 devices share a compatible string. > > > > Either Mark or Lee suggestion is work. > Is there a conclusion that we can apply it? > If MFD is already supported of_compatible, we prefer use of_compatible > mapping. > Is there any update? > > > Should I use parent's device to find sub-devices of_node if without > > > compatible name? > > > I trace the function mfd_add_device, > > > > > > if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) { > > > . > > > ret = mfd_match_of_node_to_dev(pdev, np, cell); > > > . > > > } > > > > > > which is binding mfd sub-device with compatible. Does it be removed in > > > the feature? > > > > > > > > OF_MFD_CELL("mt6360-tcpc", NULL, > > > > > NULL, 0, 0, "mediatek,mt6360-tcpc"), > > > > > }; > > > > > > > > > -- > > Lee Jones [李琼斯] > > Senior Technical Lead - Developer Services > > Linaro.org │ Open source software for Arm SoCs > > Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v4 2/2] power: supply: mt6360_charger: add MT6360 charger support
Gene Chen 於 2021年3月2日 週二 下午3:27寫道: > > Gene Chen 於 2021年1月18日 週一 下午8:42寫道: > > > > From: Gene Chen > > > > Add basic support for the battery charger for MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > drivers/power/supply/Kconfig | 10 + > > drivers/power/supply/Makefile | 1 + > > drivers/power/supply/mt6360_charger.c | 914 > > ++ > > 3 files changed, 925 insertions(+) > > create mode 100644 drivers/power/supply/mt6360_charger.c > > > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > > index eec646c..dd63bed 100644 > > --- a/drivers/power/supply/Kconfig > > +++ b/drivers/power/supply/Kconfig > > @@ -567,6 +567,16 @@ config CHARGER_MP2629 > > Battery charger. This driver provides Battery charger power > > management > > functions on the systems. > > > > +config CHARGER_MT6360 > > + tristate "Mediatek MT6360 Charger Driver" > > + depends on MFD_MT6360 > > + depends on REGULATOR > > + help > > + Say Y here to enable MT6360 Charger Part. > > + The device supports High-Accuracy Voltage/Current Regulation, > > + Average Input Current Regulation, Battery Tempature Sensing, > > + Over-Temperature Protection, DPDM Detection for BC1.2 > > + > > config CHARGER_QCOM_SMBB > > tristate "Qualcomm Switch-Mode Battery Charger and Boost" > > depends on MFD_SPMI_PMIC || COMPILE_TEST > > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > > index dd4b863..9bd0804 100644 > > --- a/drivers/power/supply/Makefile > > +++ b/drivers/power/supply/Makefile > > @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= > > max77693_charger.o > > obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o > > obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o > > obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o > > +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o > > obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o > > obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o > > obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o > > diff --git a/drivers/power/supply/mt6360_charger.c > > b/drivers/power/supply/mt6360_charger.c > > new file mode 100644 > > index 000..d80bdad > > --- /dev/null > > +++ b/drivers/power/supply/mt6360_charger.c > > @@ -0,0 +1,914 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2021 MediaTek Inc. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define MT6360_PMU_CHG_CTRL1 0x311 > > +#define MT6360_PMU_CHG_CTRL2 0x312 > > +#define MT6360_PMU_CHG_CTRL3 0x313 > > +#define MT6360_PMU_CHG_CTRL4 0x314 > > +#define MT6360_PMU_CHG_CTRL5 0x315 > > +#define MT6360_PMU_CHG_CTRL6 0x316 > > +#define MT6360_PMU_CHG_CTRL7 0x317 > > +#define MT6360_PMU_CHG_CTRL8 0x318 > > +#define MT6360_PMU_CHG_CTRL9 0x319 > > +#define MT6360_PMU_CHG_CTRL10 0x31A > > +#define MT6360_PMU_DEVICE_TYPE 0x322 > > +#define MT6360_PMU_USB_STATUS1 0x327 > > +#define MT6360_PMU_CHG_STAT0x34A > > +#define MT6360_PMU_CHG_CTRL19 0x361 > > +#define MT6360_PMU_FOD_STAT0x3E7 > > + > > +/* MT6360_PMU_CHG_CTRL1 */ > > +#define MT6360_FSLP_SHFT (3) > > +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) > > +#define MT6360_OPA_MODE_SHFT (0) > > +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) > > +/* MT6360_PMU_CHG_CTRL2 */ > > +#define MT6360_IINLMTSEL_SHFT (2) > > +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) > > +/* MT6360_PMU_CHG_CTRL3 */ > > +#define MT6360_IAICR_SHFT (2) > > +#define MT6360_IAICR_MASK GENMASK(7, 2) > > +#define MT6360_ILIM_EN_MASKBIT(0) > > +/* MT6360_PMU_CHG_CTRL4 */ > > +#define MT6360_VOREG_SHFT (1) > > +#define MT6360_VOREG_MASK GENMASK(7, 1) > > +/* MT6360_PMU_CHG_CTRL5 */ > > +#define MT6360_VOBST_MASK GENMASK(7, 2) > > +/* MT6360_PMU_CHG_CTRL6 */ > > +#define MT6360_VMIVR_SHFT (1) > > +#define MT6360_VMIVR_MASK GENMASK(7, 1) > > +/* MT6360_PMU_CHG_CTRL7 */ > > +#define MT6360_ICHG_SHFT (2) > > +#define MT6360_ICHG_MASK GENMASK(7, 2) > > +/* MT6360_PMU_CHG_CTRL8 */ > &g
Re: [PATCH v13 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
Gene Chen 於 2021年3月2日 週二 下午2:08寫道: > > Pavel Machek 於 2021年2月19日 週五 下午6:47寫道: > > > > Hi! > > > > > From: Gene Chen > > > > > > Add LED_FUNCTION_MOONLIGHT definitions > > > > > > Signed-off-by: Gene Chen > > > Acked-by: Jacek Anaszewski > > > Acked-by: Rob Herring > > > > No, sorry, I don't believe we need another define for flash/torch. > > > > As previous discuss, > > We use term "Moonlight" as reference says > > "When you are trying to imitate moonlight you need to use low voltage, > > softer lighting. You don’t want something that’s too bright" > > which is focus on brightness instead of color. > > If any concern about this change, maybe we use LED_FUNCTION_INDICATOR instead? > (refs: https://lkml.org/lkml/2020/11/24/1267) Is there any update? > > Best regards, > > Pavel > > -- > > http://www.livejournal.com/~pavelmachek
Re: [PATCH v4 2/2] power: supply: mt6360_charger: add MT6360 charger support
Gene Chen 於 2021年1月18日 週一 下午8:42寫道: > > From: Gene Chen > > Add basic support for the battery charger for MT6360 PMIC > > Signed-off-by: Gene Chen > --- > drivers/power/supply/Kconfig | 10 + > drivers/power/supply/Makefile | 1 + > drivers/power/supply/mt6360_charger.c | 914 > ++ > 3 files changed, 925 insertions(+) > create mode 100644 drivers/power/supply/mt6360_charger.c > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index eec646c..dd63bed 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -567,6 +567,16 @@ config CHARGER_MP2629 > Battery charger. This driver provides Battery charger power > management > functions on the systems. > > +config CHARGER_MT6360 > + tristate "Mediatek MT6360 Charger Driver" > + depends on MFD_MT6360 > + depends on REGULATOR > + help > + Say Y here to enable MT6360 Charger Part. > + The device supports High-Accuracy Voltage/Current Regulation, > + Average Input Current Regulation, Battery Tempature Sensing, > + Over-Temperature Protection, DPDM Detection for BC1.2 > + > config CHARGER_QCOM_SMBB > tristate "Qualcomm Switch-Mode Battery Charger and Boost" > depends on MFD_SPMI_PMIC || COMPILE_TEST > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index dd4b863..9bd0804 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= max77693_charger.o > obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o > obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o > obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o > +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o > obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o > obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o > obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o > diff --git a/drivers/power/supply/mt6360_charger.c > b/drivers/power/supply/mt6360_charger.c > new file mode 100644 > index 000..d80bdad > --- /dev/null > +++ b/drivers/power/supply/mt6360_charger.c > @@ -0,0 +1,914 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2021 MediaTek Inc. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define MT6360_PMU_CHG_CTRL1 0x311 > +#define MT6360_PMU_CHG_CTRL2 0x312 > +#define MT6360_PMU_CHG_CTRL3 0x313 > +#define MT6360_PMU_CHG_CTRL4 0x314 > +#define MT6360_PMU_CHG_CTRL5 0x315 > +#define MT6360_PMU_CHG_CTRL6 0x316 > +#define MT6360_PMU_CHG_CTRL7 0x317 > +#define MT6360_PMU_CHG_CTRL8 0x318 > +#define MT6360_PMU_CHG_CTRL9 0x319 > +#define MT6360_PMU_CHG_CTRL10 0x31A > +#define MT6360_PMU_DEVICE_TYPE 0x322 > +#define MT6360_PMU_USB_STATUS1 0x327 > +#define MT6360_PMU_CHG_STAT0x34A > +#define MT6360_PMU_CHG_CTRL19 0x361 > +#define MT6360_PMU_FOD_STAT0x3E7 > + > +/* MT6360_PMU_CHG_CTRL1 */ > +#define MT6360_FSLP_SHFT (3) > +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) > +#define MT6360_OPA_MODE_SHFT (0) > +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) > +/* MT6360_PMU_CHG_CTRL2 */ > +#define MT6360_IINLMTSEL_SHFT (2) > +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) > +/* MT6360_PMU_CHG_CTRL3 */ > +#define MT6360_IAICR_SHFT (2) > +#define MT6360_IAICR_MASK GENMASK(7, 2) > +#define MT6360_ILIM_EN_MASKBIT(0) > +/* MT6360_PMU_CHG_CTRL4 */ > +#define MT6360_VOREG_SHFT (1) > +#define MT6360_VOREG_MASK GENMASK(7, 1) > +/* MT6360_PMU_CHG_CTRL5 */ > +#define MT6360_VOBST_MASK GENMASK(7, 2) > +/* MT6360_PMU_CHG_CTRL6 */ > +#define MT6360_VMIVR_SHFT (1) > +#define MT6360_VMIVR_MASK GENMASK(7, 1) > +/* MT6360_PMU_CHG_CTRL7 */ > +#define MT6360_ICHG_SHFT (2) > +#define MT6360_ICHG_MASK GENMASK(7, 2) > +/* MT6360_PMU_CHG_CTRL8 */ > +#define MT6360_IPREC_SHFT (0) > +#define MT6360_IPREC_MASK GENMASK(3, 0) > +/* MT6360_PMU_CHG_CTRL9 */ > +#define MT6360_IEOC_SHFT (4) > +#define MT6360_IEOC_MASK GENMASK(7, 4) > +/* MT6360_PMU_CHG_CTRL10 */ > +#define MT6360_OTG_OC_MASK GENMASK(3, 0) > +/* MT6360_PMU_DEVICE_TYPE */ > +#define MT6360_USBCHGEN_MASK BIT(7) > +/* MT6360_PMU_USB_STATUS1 */ > +#define MT6360_USB_STATUS_SHFT (4) > +#define MT6360_USB_STATUS_MASK GENMASK(6, 4) > +/* MT6360_PMU_CHG_STAT */ > +#define MT6360_CHG_STAT_SHFT (6) > +#define MT6360_CHG_STAT_M
Re: [PATCH v7 04/11] mfd: mt6360: Combine mt6360 pmic/ldo resources into mt6360 regulator resources
Lee Jones 於 2021年1月15日 週五 下午3:32寫道: > > On Fri, 15 Jan 2021, Gene Chen wrote: > > > Matthias Brugger 於 2021年1月12日 週二 下午8:32寫道: > > > > > > > > > > > > On 12/11/2020 11:39, Gene Chen wrote: > > > > From: Gene Chen > > > > > > > > Combine mt6360 pmic/ldo resources into mt6360 regulator resources > > > > to simplify the similar resources object. > > > > > > > > Signed-off-by: Gene Chen > > > > Acked-for-MFD-by: Lee Jones > > > > --- > > > > drivers/mfd/mt6360-core.c | 11 +++ > > > > 1 file changed, 3 insertions(+), 8 deletions(-) > > > > > > > > diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c > > > > index 692e47b..5119e51 100644 > > > > --- a/drivers/mfd/mt6360-core.c > > > > +++ b/drivers/mfd/mt6360-core.c > > > > @@ -265,7 +265,7 @@ static const struct resource mt6360_led_resources[] > > > > = { > > > > DEFINE_RES_IRQ_NAMED(MT6360_FLED1_STRB_TO_EVT, > > > > "fled1_strb_to_evt"), > > > > }; > > > > > > > > -static const struct resource mt6360_pmic_resources[] = { > > > > +static const struct resource mt6360_regulator_resources[] = { > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_PGB_EVT, "buck1_pgb_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OC_EVT, "buck1_oc_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OV_EVT, "buck1_ov_evt"), > > > > @@ -278,9 +278,6 @@ static const struct resource > > > > mt6360_pmic_resources[] = { > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_OC_EVT, "ldo7_oc_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO6_PGB_EVT, "ldo6_pgb_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_PGB_EVT, "ldo7_pgb_evt"), > > > > -}; > > > > - > > > > -static const struct resource mt6360_ldo_resources[] = { > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO1_OC_EVT, "ldo1_oc_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO2_OC_EVT, "ldo2_oc_evt"), > > > > DEFINE_RES_IRQ_NAMED(MT6360_LDO3_OC_EVT, "ldo3_oc_evt"), > > > > @@ -298,10 +295,8 @@ static const struct mfd_cell mt6360_devs[] = { > > > > NULL, 0, 0, "mediatek,mt6360-chg"), > > > > OF_MFD_CELL("mt6360-led", mt6360_led_resources, > > > > NULL, 0, 0, "mediatek,mt6360-led"), > > > > - OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, > > > > - NULL, 0, 0, "mediatek,mt6360-pmic"), > > > > - OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, > > > > - NULL, 0, 0, "mediatek,mt6360-ldo"), > > > > + OF_MFD_CELL("mt6360-regulator", mt6360_regulator_resources, > > > > + NULL, 0, 0, "mediatek,mt6360-regulator"), > > > > > > As discussed with the MFD maintainer [1], the regulator (and probably all > > > cells) > > > shouldn't have a DT binding. > > > > > > So please send a new version which fixes that. > > > > > > Regards, > > > Matthias > > > > > > [1] > > > https://lore.kernel.org/linux-mediatek/2021064118.ge4...@sirena.org.uk/ > > I don't think Mark is correct here. > > We usually do implement compatible strings for sub-devices and they do > tend to have their own device nodes. > > It's a very long time ago since I coded this up myself, but from > memory, you can't have 2 devices share a compatible string. > Either Mark or Lee suggestion is work. Is there a conclusion that we can apply it? If MFD is already supported of_compatible, we prefer use of_compatible mapping. > > Should I use parent's device to find sub-devices of_node if without > > compatible name? > > I trace the function mfd_add_device, > > > > if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) { > > . > > ret = mfd_match_of_node_to_dev(pdev, np, cell); > > . > > } > > > > which is binding mfd sub-device with compatible. Does it be removed in > > the feature? > > > > > > OF_MFD_CELL("mt6360-tcpc", NULL, > > > > NULL, 0, 0, "mediatek,mt6360-tcpc"), > > > > }; > > > > > > -- > Lee Jones [李琼斯] > Senior Technical Lead - Developer Services > Linaro.org │ Open source software for Arm SoCs > Follow Linaro: Facebook | Twitter | Blog
Re: [PATCH v13 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
Pavel Machek 於 2021年2月19日 週五 下午6:47寫道: > > Hi! > > > From: Gene Chen > > > > Add LED_FUNCTION_MOONLIGHT definitions > > > > Signed-off-by: Gene Chen > > Acked-by: Jacek Anaszewski > > Acked-by: Rob Herring > > No, sorry, I don't believe we need another define for flash/torch. > As previous discuss, > We use term "Moonlight" as reference says > "When you are trying to imitate moonlight you need to use low voltage, > softer lighting. You don’t want something that’s too bright" > which is focus on brightness instead of color. If any concern about this change, maybe we use LED_FUNCTION_INDICATOR instead? (refs: https://lkml.org/lkml/2020/11/24/1267) > Best regards, > Pavel > -- > http://www.livejournal.com/~pavelmachek
[PATCH v4 2/2] power: supply: mt6360_charger: add MT6360 charger support
From: Gene Chen Add basic support for the battery charger for MT6360 PMIC Signed-off-by: Gene Chen --- drivers/power/supply/Kconfig | 10 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6360_charger.c | 914 ++ 3 files changed, 925 insertions(+) create mode 100644 drivers/power/supply/mt6360_charger.c diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index eec646c..dd63bed 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -567,6 +567,16 @@ config CHARGER_MP2629 Battery charger. This driver provides Battery charger power management functions on the systems. +config CHARGER_MT6360 + tristate "Mediatek MT6360 Charger Driver" + depends on MFD_MT6360 + depends on REGULATOR + help + Say Y here to enable MT6360 Charger Part. + The device supports High-Accuracy Voltage/Current Regulation, + Average Input Current Regulation, Battery Tempature Sensing, + Over-Temperature Protection, DPDM Detection for BC1.2 + config CHARGER_QCOM_SMBB tristate "Qualcomm Switch-Mode Battery Charger and Boost" depends on MFD_SPMI_PMIC || COMPILE_TEST diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index dd4b863..9bd0804 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= max77693_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/mt6360_charger.c new file mode 100644 index 000..d80bdad --- /dev/null +++ b/drivers/power/supply/mt6360_charger.c @@ -0,0 +1,914 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MT6360_PMU_CHG_CTRL1 0x311 +#define MT6360_PMU_CHG_CTRL2 0x312 +#define MT6360_PMU_CHG_CTRL3 0x313 +#define MT6360_PMU_CHG_CTRL4 0x314 +#define MT6360_PMU_CHG_CTRL5 0x315 +#define MT6360_PMU_CHG_CTRL6 0x316 +#define MT6360_PMU_CHG_CTRL7 0x317 +#define MT6360_PMU_CHG_CTRL8 0x318 +#define MT6360_PMU_CHG_CTRL9 0x319 +#define MT6360_PMU_CHG_CTRL10 0x31A +#define MT6360_PMU_DEVICE_TYPE 0x322 +#define MT6360_PMU_USB_STATUS1 0x327 +#define MT6360_PMU_CHG_STAT0x34A +#define MT6360_PMU_CHG_CTRL19 0x361 +#define MT6360_PMU_FOD_STAT0x3E7 + +/* MT6360_PMU_CHG_CTRL1 */ +#define MT6360_FSLP_SHFT (3) +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) +#define MT6360_OPA_MODE_SHFT (0) +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) +/* MT6360_PMU_CHG_CTRL2 */ +#define MT6360_IINLMTSEL_SHFT (2) +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) +/* MT6360_PMU_CHG_CTRL3 */ +#define MT6360_IAICR_SHFT (2) +#define MT6360_IAICR_MASK GENMASK(7, 2) +#define MT6360_ILIM_EN_MASKBIT(0) +/* MT6360_PMU_CHG_CTRL4 */ +#define MT6360_VOREG_SHFT (1) +#define MT6360_VOREG_MASK GENMASK(7, 1) +/* MT6360_PMU_CHG_CTRL5 */ +#define MT6360_VOBST_MASK GENMASK(7, 2) +/* MT6360_PMU_CHG_CTRL6 */ +#define MT6360_VMIVR_SHFT (1) +#define MT6360_VMIVR_MASK GENMASK(7, 1) +/* MT6360_PMU_CHG_CTRL7 */ +#define MT6360_ICHG_SHFT (2) +#define MT6360_ICHG_MASK GENMASK(7, 2) +/* MT6360_PMU_CHG_CTRL8 */ +#define MT6360_IPREC_SHFT (0) +#define MT6360_IPREC_MASK GENMASK(3, 0) +/* MT6360_PMU_CHG_CTRL9 */ +#define MT6360_IEOC_SHFT (4) +#define MT6360_IEOC_MASK GENMASK(7, 4) +/* MT6360_PMU_CHG_CTRL10 */ +#define MT6360_OTG_OC_MASK GENMASK(3, 0) +/* MT6360_PMU_DEVICE_TYPE */ +#define MT6360_USBCHGEN_MASK BIT(7) +/* MT6360_PMU_USB_STATUS1 */ +#define MT6360_USB_STATUS_SHFT (4) +#define MT6360_USB_STATUS_MASK GENMASK(6, 4) +/* MT6360_PMU_CHG_STAT */ +#define MT6360_CHG_STAT_SHFT (6) +#define MT6360_CHG_STAT_MASK GENMASK(7, 6) +#define MT6360_VBAT_LVL_MASK BIT(5) +/* MT6360_PMU_CHG_CTRL19 */ +#define MT6360_VINOVP_SHFT (5) +#define MT6360_VINOVP_MASK GENMASK(6, 5) +/* MT6360_PMU_FOD_STAT */ +#define MT6360_CHRDET_EXT_MASK BIT(4) + +/* uV */ +#define MT6360_VMIVR_MIN 390 +#define MT6360_VMIVR_MAX 1340 +#define MT6360_VMIVR_STEP 10 +/* uA */ +#define MT6360_ICHG_MIN10 +#define MT6360_ICHG_MAX500 +#define MT6360_ICHG_STEP 10 +/* uV */ +#define MT6360_VOREG_MIN 390 +#define MT6360_VOREG_MAX 471 +#define MT6360_VOREG_STEP 1 +/* uA */ +#de
[PATCH v4 1/2] dt-bindings: power: Add bindings document for Charger support on MT6360 PMIC
From: Gene Chen Add bindings document for Charger support on MT6360 PMIC Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../bindings/power/supply/mt6360_charger.yaml | 48 ++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml diff --git a/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml b/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml new file mode 100644 index 000..b89b15a --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/mt6360_charger.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Battery charger driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + Provides Battery Charger, Boost for OTG devices and BC1.2 detection. + +properties: + compatible: +const: mediatek,mt6360-chg + + richtek,vinovp-microvolt: +description: Maximum CHGIN regulation voltage in uV. +enum: [ 550, 650, 1100, 1450 ] + + + usb-otg-vbus-regulator: +type: object +description: OTG boost regulator. +$ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + +additionalProperties: false + +examples: + - | +mt6360_charger: charger { + compatible = "mediatek,mt6360-chg"; + richtek,vinovp-microvolt = <1450>; + + otg_vbus_regulator: usb-otg-vbus-regulator { +regulator-compatible = "usb-otg-vbus"; +regulator-name = "usb-otg-vbus"; +regulator-min-microvolt = <4425000>; +regulator-max-microvolt = <5825000>; + }; +}; +... -- 2.7.4
[PATCH v4 0/2] power: supply: mt6360_charger: add MT6360 charger support
This patch series add MT6360 Charger support contains driver and binding document Gene Chen (2) dt-bindings: power: Add bindings document for Charger support on MT6360 PMIC power: supply: mt6360_charger: add MT6360 charger support Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml | 48 drivers/power/supply/Kconfig | 10 drivers/power/supply/Makefile |1 drivers/power/supply/mt6360_charger.c | 914 ++ 4 files changed, 973 insertions(+) changelogs between v1 & v2 - Add binding property with unit and custom name prefix - Remove extcon device, redundant brackets and interrupts - Fix power supply prop "charger type" changelogs between v2 & v3 - Add register selector to value mapping changelogs between v3 & v4 - move pdata vinovp to mt6360_chg_info - remove unuse sysfs attribute - refactor debug log and warning - add power supply prop input voltage limit
Re: [PATCH v3 2/2] power: supply: mt6360_charger: add MT6360 charger support
Sebastian Reichel 於 2021年1月16日 週六 下午6:12寫道: > > Hi, > > On Mon, Jan 11, 2021 at 08:15:33PM +0800, Gene Chen wrote: > > Sebastian Reichel 於 2021年1月7日 週四 上午4:16寫道: > > > > + last_usb_type = mci->psy_usb_type; > > > > + /* Plug in */ > > > > + ret = regmap_read(mci->regmap, MT6360_PMU_USB_STATUS1, > > > > &usb_status); > > > > + if (ret < 0) > > > > + goto out; > > > > + usb_status &= MT6360_USB_STATUS_MASK; > > > > + usb_status >>= MT6360_USB_STATUS_SHFT; > > > > + switch (usb_status) { > > > > + case MT6360_CHG_TYPE_UNDER_GOING: > > > > + dev_info(mci->dev, "%s: under going...\n", __func__); > > > > + goto out; > > > > > > IDK what this is supposed to tell me. Do you mean "detection in > > > progress"? Also why is this info level? I would expect either > > > debug (assuming it happens regularly and is normal) or warning > > > (assuming it should not happen). > > > > > > > When handling attach interrupt and cable plug out at the same > > time, HW change register status. So we don' need to handle this > > attach interrupt at this case. > > So this is basically for debouncing? I suggest adding a comment: > > /* Received attach IRQ followed by detach event, so nothing to do */ > dev_dbg(mci->dev, "under going...\n"); > goto out; > Sorry I have a little misunderstand. under going is "detect in progress". Attachi irq will trigger when power ready(vbus=5V) and bc12 chargedetection done. Another irq, Detachi, is indicated power not ready(vbus=0V) and which is be masked. So, if the usb status is not SDP/NONSTD/CDP/DCP, the result can be ignored. (e.q. NO VBUS/Under going/BC12 disabled/Reserved address) > [...] > > > > > + config.dev = &pdev->dev; > > > > + config.regmap = mci->regmap; > > > > + mci->otg_rdev = devm_regulator_register(&pdev->dev, > > > > &mt6360_otg_rdesc, > > > > + &config); > > > > + if (IS_ERR(mci->otg_rdev)) > > > > + return PTR_ERR(mci->otg_rdev); > > > > + > > > > + ret = mt6360_sysfs_create_group(mci); > > > > + if (ret) { > > > > + dev_err(&pdev->dev, > > > > + "%s: Failed to create sysfs attrs\n", __func__); > > > > + return ret; > > > > + } > > > > > > Use charger_cfg.attr_grp to register custom sysfs group for > > > power-supply devices. Otherwise your code is racy (udev may not pick > > > up the sysfs attributes). Also custom sysfs attributes need to be > > > documented in Documentation/ABI/testing/sysfs-class-power-. > > > > > > Looking at the attributes you are planning to expose, I don't think they > > > are suitable for sysfs anyways. Looks more like a debug interface, which > > > should go into debugfs instead. But it's hard to tell without any > > > documentation > > > being provided :) > > > > ACK, I will change to charger_cfg.attr_grp. > > I assumed the charger algorithm thread is in user space, and take > > control by sysfs node from charger device, like bq24190.c. > > Should I change to debugfs? > > It's hard to tell without knowing more about the attributes > your are trying to expose. In debugfs we have relaxed ABI rules, > so it's easier to adopt naming e.t.c. later. > I briefly classify the whole attributes. There are either unused, or can be replaced by POWER_SUPPLY PROPERTY, so I will remove unuse part. HIZ = VBUS_IN high impedance mode. VMIVR = Maximum input voltage regulation. Let input power can provide at the predetermined voltage level. (like POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT) SYSREG = Config system minimum regulation voltage. OTG_OC = maximum current of battery boost OTG 5V. ICHG = maximum Charging current. (like POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT) IEOC = Like POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT VOREG = Input voltage regulation. (like POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE) LBP = Low battery protection for battery boost OTG 5V. VPREC = Pre-charge volatge level. (maybe can add new prop POWER_SUPPLY_PROP_PRECHARGE_VOLTAGE) TE = Charge termination enable/disable. CHG_WDT_EN = Charger Watch dog timer enable/disable. CHG_WDT = Charger Watch dog timer, 8/40/80/160s. WT_FC = Fast charge Timer, 4~20hr. BAT_COMP = Battery IR compensation resistor setting. VCLAMP = Battery IR compensation maximum voltage clamp. USBCHGEN = USB charger detection flow enable/disable. CHG_EN = Battery charging enable/disable. CHRDET_EXT = VBUS_IN is between VBUS_UV_TH(3.7V) and VBUS_OV_TH(10.5V) > -- Sebastian
Re: [PATCH v7 04/11] mfd: mt6360: Combine mt6360 pmic/ldo resources into mt6360 regulator resources
Matthias Brugger 於 2021年1月12日 週二 下午8:32寫道: > > > > On 12/11/2020 11:39, Gene Chen wrote: > > From: Gene Chen > > > > Combine mt6360 pmic/ldo resources into mt6360 regulator resources > > to simplify the similar resources object. > > > > Signed-off-by: Gene Chen > > Acked-for-MFD-by: Lee Jones > > --- > > drivers/mfd/mt6360-core.c | 11 +++ > > 1 file changed, 3 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c > > index 692e47b..5119e51 100644 > > --- a/drivers/mfd/mt6360-core.c > > +++ b/drivers/mfd/mt6360-core.c > > @@ -265,7 +265,7 @@ static const struct resource mt6360_led_resources[] = { > > DEFINE_RES_IRQ_NAMED(MT6360_FLED1_STRB_TO_EVT, "fled1_strb_to_evt"), > > }; > > > > -static const struct resource mt6360_pmic_resources[] = { > > +static const struct resource mt6360_regulator_resources[] = { > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_PGB_EVT, "buck1_pgb_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OC_EVT, "buck1_oc_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OV_EVT, "buck1_ov_evt"), > > @@ -278,9 +278,6 @@ static const struct resource mt6360_pmic_resources[] = { > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_OC_EVT, "ldo7_oc_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_LDO6_PGB_EVT, "ldo6_pgb_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_LDO7_PGB_EVT, "ldo7_pgb_evt"), > > -}; > > - > > -static const struct resource mt6360_ldo_resources[] = { > > DEFINE_RES_IRQ_NAMED(MT6360_LDO1_OC_EVT, "ldo1_oc_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_LDO2_OC_EVT, "ldo2_oc_evt"), > > DEFINE_RES_IRQ_NAMED(MT6360_LDO3_OC_EVT, "ldo3_oc_evt"), > > @@ -298,10 +295,8 @@ static const struct mfd_cell mt6360_devs[] = { > > NULL, 0, 0, "mediatek,mt6360-chg"), > > OF_MFD_CELL("mt6360-led", mt6360_led_resources, > > NULL, 0, 0, "mediatek,mt6360-led"), > > - OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, > > - NULL, 0, 0, "mediatek,mt6360-pmic"), > > - OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, > > - NULL, 0, 0, "mediatek,mt6360-ldo"), > > + OF_MFD_CELL("mt6360-regulator", mt6360_regulator_resources, > > + NULL, 0, 0, "mediatek,mt6360-regulator"), > > As discussed with the MFD maintainer [1], the regulator (and probably all > cells) > shouldn't have a DT binding. > > So please send a new version which fixes that. > > Regards, > Matthias > > [1] > https://lore.kernel.org/linux-mediatek/2021064118.ge4...@sirena.org.uk/ > Should I use parent's device to find sub-devices of_node if without compatible name? I trace the function mfd_add_device, if (IS_ENABLED(CONFIG_OF) && parent->of_node && cell->of_compatible) { . ret = mfd_match_of_node_to_dev(pdev, np, cell); . } which is binding mfd sub-device with compatible. Does it be removed in the feature? > > OF_MFD_CELL("mt6360-tcpc", NULL, > > NULL, 0, 0, "mediatek,mt6360-tcpc"), > > }; > >
Re: [PATCH] mfd: mt6360: Fix MFD cell names and compatibles
Hi Lee, This change exists in [PATCH v7 03/11] mfd: mt6360: Indicate sub-dev compatible name by using "-". Does patch v7 also merge together to mfd-next? 於 2021年1月11日 週一 下午8:35寫道: > > From: Matthias Brugger > > MFD cell names and compatibles use '_' instead of '-', which is common > practice for names and the standard for DT compatibles. > This will also fix the probing for the drivers already implemented > (mt6360-adc and mt6360-tcpc). > > Fixes: 7edd363421da ("mfd: Add support for PMIC MT6360") > Fixes: 1f4877218f7e ("iio: adc: mt6360: Add ADC driver for MT6360") > Fixes: e1aefcdd394f ("usb typec: mt6360: Add support for mt6360 Type-C > driver") > Signed-off-by: Matthias Brugger > > --- > > drivers/mfd/mt6360-core.c | 24 > 1 file changed, 12 insertions(+), 12 deletions(-) > > diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c > index 4661c1b29a72..14e649ffe50f 100644 > --- a/drivers/mfd/mt6360-core.c > +++ b/drivers/mfd/mt6360-core.c > @@ -292,18 +292,18 @@ static const struct resource mt6360_ldo_resources[] = { > }; > > static const struct mfd_cell mt6360_devs[] = { > - OF_MFD_CELL("mt6360_adc", mt6360_adc_resources, > - NULL, 0, 0, "mediatek,mt6360_adc"), > - OF_MFD_CELL("mt6360_chg", mt6360_chg_resources, > - NULL, 0, 0, "mediatek,mt6360_chg"), > - OF_MFD_CELL("mt6360_led", mt6360_led_resources, > - NULL, 0, 0, "mediatek,mt6360_led"), > - OF_MFD_CELL("mt6360_pmic", mt6360_pmic_resources, > - NULL, 0, 0, "mediatek,mt6360_pmic"), > - OF_MFD_CELL("mt6360_ldo", mt6360_ldo_resources, > - NULL, 0, 0, "mediatek,mt6360_ldo"), > - OF_MFD_CELL("mt6360_tcpc", NULL, > - NULL, 0, 0, "mediatek,mt6360_tcpc"), > + OF_MFD_CELL("mt6360-adc", mt6360_adc_resources, > + NULL, 0, 0, "mediatek,mt6360-adc"), > + OF_MFD_CELL("mt6360-chg", mt6360_chg_resources, > + NULL, 0, 0, "mediatek,mt6360-chg"), > + OF_MFD_CELL("mt6360-led", mt6360_led_resources, > + NULL, 0, 0, "mediatek,mt6360-led"), > + OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, > + NULL, 0, 0, "mediatek,mt6360-pmic"), > + OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, > + NULL, 0, 0, "mediatek,mt6360-ldo"), > + OF_MFD_CELL("mt6360-tcpc", NULL, > + NULL, 0, 0, "mediatek,mt6360-tcpc"), > }; > > static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { > -- > 2.29.2 >
Re: [PATCH v3 2/2] power: supply: mt6360_charger: add MT6360 charger support
Sebastian Reichel 於 2021年1月7日 週四 上午4:16寫道: > > Hi Gene, > > I have a bunch of comments, please take a look at my inline > comments. > > On Thu, Dec 24, 2020 at 03:48:04PM +0800, Gene Chen wrote: > > From: Gene Chen > > > > Add basic support for the battery charger for MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > drivers/power/supply/Kconfig | 10 + > > drivers/power/supply/Makefile |1 + > > drivers/power/supply/mt6360_charger.c | 1054 > > + > > 3 files changed, 1065 insertions(+) > > create mode 100644 drivers/power/supply/mt6360_charger.c > > > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > > index eec646c..dd63bed 100644 > > --- a/drivers/power/supply/Kconfig > > +++ b/drivers/power/supply/Kconfig > > @@ -567,6 +567,16 @@ config CHARGER_MP2629 > > Battery charger. This driver provides Battery charger power > > management > > functions on the systems. > > > > +config CHARGER_MT6360 > > + tristate "Mediatek MT6360 Charger Driver" > > + depends on MFD_MT6360 > > + depends on REGULATOR > > + help > > + Say Y here to enable MT6360 Charger Part. > > + The device supports High-Accuracy Voltage/Current Regulation, > > + Average Input Current Regulation, Battery Tempature Sensing, > > + Over-Temperature Protection, DPDM Detection for BC1.2 > > + > > config CHARGER_QCOM_SMBB > > tristate "Qualcomm Switch-Mode Battery Charger and Boost" > > depends on MFD_SPMI_PMIC || COMPILE_TEST > > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > > index dd4b863..9bd0804 100644 > > --- a/drivers/power/supply/Makefile > > +++ b/drivers/power/supply/Makefile > > @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o > > obj-$(CONFIG_CHARGER_MAX8997)+= max8997_charger.o > > obj-$(CONFIG_CHARGER_MAX8998)+= max8998_charger.o > > obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o > > +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o > > obj-$(CONFIG_CHARGER_QCOM_SMBB) += qcom_smbb.o > > obj-$(CONFIG_CHARGER_BQ2415X)+= bq2415x_charger.o > > obj-$(CONFIG_CHARGER_BQ24190)+= bq24190_charger.o > > diff --git a/drivers/power/supply/mt6360_charger.c > > b/drivers/power/supply/mt6360_charger.c > > new file mode 100644 > > index 000..f1dcb97 > > --- /dev/null > > +++ b/drivers/power/supply/mt6360_charger.c > > @@ -0,0 +1,1054 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2019 MediaTek Inc. > > 2019-2021? :) > ACK > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > change of.h to after implementing my later > change request. > ACK > > +#include > > +#include > > +#include > > + > > +#define MT6360_PMU_CHG_CTRL1 0x311 > > +#define MT6360_PMU_CHG_CTRL2 0x312 > > +#define MT6360_PMU_CHG_CTRL3 0x313 > > +#define MT6360_PMU_CHG_CTRL4 0x314 > > +#define MT6360_PMU_CHG_CTRL5 0x315 > > +#define MT6360_PMU_CHG_CTRL6 0x316 > > +#define MT6360_PMU_CHG_CTRL7 0x317 > > +#define MT6360_PMU_CHG_CTRL8 0x318 > > +#define MT6360_PMU_CHG_CTRL9 0x319 > > +#define MT6360_PMU_CHG_CTRL100x31A > > +#define MT6360_PMU_CHG_CTRL110x31B > > +#define MT6360_PMU_CHG_CTRL120x31C > > +#define MT6360_PMU_CHG_CTRL130x31D > > +#define MT6360_PMU_DEVICE_TYPE 0x322 > > +#define MT6360_PMU_USB_STATUS1 0x327 > > +#define MT6360_PMU_CHG_CTRL170x32B > > +#define MT6360_PMU_CHG_CTRL180x32C > > +#define MT6360_PMU_CHG_STAT 0x34A > > +#define MT6360_PMU_CHG_CTRL190x361 > > +#define MT6360_PMU_FOD_STAT 0x3E7 > > + > > +/* MT6360_PMU_CHG_CTRL1 */ > > +#define MT6360_FSLP_SHFT (3) > > +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) > > +#define MT6360_HIZ_SHFT (2) > > +#define MT6360_HIZ_MASK BIT(MT6360_HIZ_SHFT) > > +#define MT6360_OPA_MODE_SHFT (0) > > +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) > > +/* MT6360_PMU_CHG_CTRL2 */ > > +#define MT6360_TE_SHFT (4) > > +#define MT6360_TE_MASK BIT(MT6360_TE_SHFT) > > +#define MT6360_IINLMTSEL_SHFT(2) > > +#define MT6360_IINLMTSEL_MASKGENMASK(3, 2) > > +#d
Re: [PATCH resend] dt-bindings: mfd: mediatek: Add bindings for MT6360 PMIC
Vaittinen, Matti 於 2021年1月11日 週一 下午5:13寫道: > > Hello Peeps, > > On Thu, 2020-12-24 at 11:19 +0800, Gene Chen wrote: > > From: Gene Chen > > > > Add bindings for MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > Documentation/devicetree/bindings/mfd/mt6360.yaml | 69 > > +++ > > 1 file changed, 69 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/mfd/mt6360.yaml > > > > diff --git a/Documentation/devicetree/bindings/mfd/mt6360.yaml > > b/Documentation/devicetree/bindings/mfd/mt6360.yaml > > new file mode 100644 > > index 000..2781c31 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/mfd/mt6360.yaml > > @@ -0,0 +1,69 @@ > > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) > > +%YAML 1.2 > > +--- > > +$id: http://devicetree.org/schemas/mfd/mt6360.yaml# > > +$schema: http://devicetree.org/meta-schemas/core.yaml# > > + > > +title: MT6360 PMIC from MediaTek Integrated > > + > > +maintainers: > > + - Gene Chen > > + > > +description: | > > + MT6360 is a PMIC device with the following sub modules. > > + It is interfaced to host controller using I2C interface. > > + > > + This document describes the binding for PMIC device and its sub > > module. > > + > > +properties: > > + compatible: > > +const: mediatek,mt6360 > > + > > + reg: > > +description: > > + I2C device address. > > +maxItems: 1 > > + > > + wakeup-source: true > > + > > + interrupts: > > +maxItems: 1 > > + > > + interrupt-names: > > + enum: > > +- IRQB > > + > > + interrupt-controller: true > > + > > + "#interrupt-cells": > > +const: 1 > > +description: > > + The first cell is the IRQ number. > > + > > +required: > > + - compatible > > + - reg > > + - interrupts > > + - interrupt-controller > > + - "#interrupt-cells" > > + > > +additionalProperties: false > > + > > +examples: > > + - | > > +#include > > +#include > > +i2c { > > +#address-cells = <1>; > > +#size-cells = <0>; > > + > > +mt6360@34 { > > +compatible = "mediatek,mt6360"; > > +reg = <0x34>; > > +wakeup-source; > > +interrupts-extended = <&gpio26 0 IRQ_TYPE_LEVEL_LOW>; > > +interrupt-names = "IRQB"; > > +interrupt-controller; > > +#interrupt-cells = <1>; > > Out of the curiosity - is this the complete node? I would assume some > sub-devices like regulators here? > After all sub-devices module review done, I will add new patch to add reference description. e.g. max77650.yaml leds: $ref: ../leds/leds-max77650.yaml > > +}; > > +}; >
[PATCH v3 2/2] power: supply: mt6360_charger: add MT6360 charger support
From: Gene Chen Add basic support for the battery charger for MT6360 PMIC Signed-off-by: Gene Chen --- drivers/power/supply/Kconfig | 10 + drivers/power/supply/Makefile |1 + drivers/power/supply/mt6360_charger.c | 1054 + 3 files changed, 1065 insertions(+) create mode 100644 drivers/power/supply/mt6360_charger.c diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index eec646c..dd63bed 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -567,6 +567,16 @@ config CHARGER_MP2629 Battery charger. This driver provides Battery charger power management functions on the systems. +config CHARGER_MT6360 + tristate "Mediatek MT6360 Charger Driver" + depends on MFD_MT6360 + depends on REGULATOR + help + Say Y here to enable MT6360 Charger Part. + The device supports High-Accuracy Voltage/Current Regulation, + Average Input Current Regulation, Battery Tempature Sensing, + Over-Temperature Protection, DPDM Detection for BC1.2 + config CHARGER_QCOM_SMBB tristate "Qualcomm Switch-Mode Battery Charger and Boost" depends on MFD_SPMI_PMIC || COMPILE_TEST diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index dd4b863..9bd0804 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= max77693_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o diff --git a/drivers/power/supply/mt6360_charger.c b/drivers/power/supply/mt6360_charger.c new file mode 100644 index 000..f1dcb97 --- /dev/null +++ b/drivers/power/supply/mt6360_charger.c @@ -0,0 +1,1054 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MT6360_PMU_CHG_CTRL1 0x311 +#define MT6360_PMU_CHG_CTRL2 0x312 +#define MT6360_PMU_CHG_CTRL3 0x313 +#define MT6360_PMU_CHG_CTRL4 0x314 +#define MT6360_PMU_CHG_CTRL5 0x315 +#define MT6360_PMU_CHG_CTRL6 0x316 +#define MT6360_PMU_CHG_CTRL7 0x317 +#define MT6360_PMU_CHG_CTRL8 0x318 +#define MT6360_PMU_CHG_CTRL9 0x319 +#define MT6360_PMU_CHG_CTRL10 0x31A +#define MT6360_PMU_CHG_CTRL11 0x31B +#define MT6360_PMU_CHG_CTRL12 0x31C +#define MT6360_PMU_CHG_CTRL13 0x31D +#define MT6360_PMU_DEVICE_TYPE 0x322 +#define MT6360_PMU_USB_STATUS1 0x327 +#define MT6360_PMU_CHG_CTRL17 0x32B +#define MT6360_PMU_CHG_CTRL18 0x32C +#define MT6360_PMU_CHG_STAT0x34A +#define MT6360_PMU_CHG_CTRL19 0x361 +#define MT6360_PMU_FOD_STAT0x3E7 + +/* MT6360_PMU_CHG_CTRL1 */ +#define MT6360_FSLP_SHFT (3) +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) +#define MT6360_HIZ_SHFT(2) +#define MT6360_HIZ_MASKBIT(MT6360_HIZ_SHFT) +#define MT6360_OPA_MODE_SHFT (0) +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) +/* MT6360_PMU_CHG_CTRL2 */ +#define MT6360_TE_SHFT (4) +#define MT6360_TE_MASK BIT(MT6360_TE_SHFT) +#define MT6360_IINLMTSEL_SHFT (2) +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) +#define MT6360_CHG_EN_SHFT (0) +#define MT6360_CHG_EN_MASK BIT(MT6360_CHG_EN_SHFT) +/* MT6360_PMU_CHG_CTRL3 */ +#define MT6360_IAICR_SHFT (2) +#define MT6360_IAICR_MASK GENMASK(7, 2) +#define MT6360_ILIM_EN_MASKBIT(0) +/* MT6360_PMU_CHG_CTRL4 */ +#define MT6360_VOREG_SHFT (1) +#define MT6360_VOREG_MASK GENMASK(7, 1) +/* MT6360_PMU_CHG_CTRL5 */ +#define MT6360_VOBST_MASK GENMASK(7, 2) +/* MT6360_PMU_CHG_CTRL6 */ +#define MT6360_VMIVR_SHFT (1) +#define MT6360_VMIVR_MASK GENMASK(7, 1) +/* MT6360_PMU_CHG_CTRL7 */ +#define MT6360_ICHG_SHFT (2) +#define MT6360_ICHG_MASK GENMASK(7, 2) +/* MT6360_PMU_CHG_CTRL8 */ +#define MT6360_IPREC_SHFT (0) +#define MT6360_IPREC_MASK GENMASK(3, 0) +/* MT6360_PMU_CHG_CTRL9 */ +#define MT6360_IEOC_SHFT (4) +#define MT6360_IEOC_MASK GENMASK(7, 4) +/* MT6360_PMU_CHG_CTRL10 */ +#define MT6360_LBP_SHFT(4) +#define MT6360_LBP_MASKGENMASK(7, 4) +#define MT6360_OTG_OC_SHFT (0) +#define MT6360_OTG_OC_MASK GENMASK(3, 0) +/* MT6360_PMU_CHG_CTRL11 */ +#define MT6360_SYSREG_SHFT (2) +#define MT6360_SYSREG_MASK GENMASK(4, 2) +#define MT6360_VREC_SHFT (0) +#define MT6360_VREC_MASK GENMASK(2, 0) +/* MT6360_PMU_CHG_CTRL12 */ +#define MT6360_WT_FC_SHFT (5) +#define MT6360_WT_FC_MASK GENMASK(7, 5) +/* MT6360_PMU_CH
[PATCH v3 1/2] dt-bindings: power: Add bindings document for Charger support on MT6360 PMIC
From: Gene Chen Add bindings document for Charger support on MT6360 PMIC Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../bindings/power/supply/mt6360_charger.yaml | 48 ++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml diff --git a/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml b/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml new file mode 100644 index 000..b89b15a --- /dev/null +++ b/Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/supply/mt6360_charger.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Battery charger driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + Provides Battery Charger, Boost for OTG devices and BC1.2 detection. + +properties: + compatible: +const: mediatek,mt6360-chg + + richtek,vinovp-microvolt: +description: Maximum CHGIN regulation voltage in uV. +enum: [ 550, 650, 1100, 1450 ] + + + usb-otg-vbus-regulator: +type: object +description: OTG boost regulator. +$ref: /schemas/regulator/regulator.yaml# + +required: + - compatible + +additionalProperties: false + +examples: + - | +mt6360_charger: charger { + compatible = "mediatek,mt6360-chg"; + richtek,vinovp-microvolt = <1450>; + + otg_vbus_regulator: usb-otg-vbus-regulator { +regulator-compatible = "usb-otg-vbus"; +regulator-name = "usb-otg-vbus"; +regulator-min-microvolt = <4425000>; +regulator-max-microvolt = <5825000>; + }; +}; +... -- 2.7.4
[PATCH v3 0/2] power: supply: mt6360_charger: add MT6360 charger support
This patch series add MT6360 Charger support contains driver and binding document Gene Chen (2) dt-bindings: power: Add bindings document for Charger support on MT6360 PMIC power: supply: mt6360_charger: add MT6360 charger support Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml | 48 drivers/power/supply/Kconfig | 10 drivers/power/supply/Makefile |1 drivers/power/supply/mt6360_charger.c | 1022 ++ 4 files changed, 1081 insertions(+) changelogs between v1 & v2 - Add binding property with unit and custom name prefix - Remove extcon device, redundant brackets and interrupts - Fix power supply prop "charger type" changelogs between v2 & v3 - Add register selector to value mapping
[PATCH resend] dt-bindings: mfd: mediatek: Add bindings for MT6360 PMIC
From: Gene Chen Add bindings for MT6360 PMIC Signed-off-by: Gene Chen --- Documentation/devicetree/bindings/mfd/mt6360.yaml | 69 +++ 1 file changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/mt6360.yaml diff --git a/Documentation/devicetree/bindings/mfd/mt6360.yaml b/Documentation/devicetree/bindings/mfd/mt6360.yaml new file mode 100644 index 000..2781c31 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/mt6360.yaml @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MT6360 PMIC from MediaTek Integrated + +maintainers: + - Gene Chen + +description: | + MT6360 is a PMIC device with the following sub modules. + It is interfaced to host controller using I2C interface. + + This document describes the binding for PMIC device and its sub module. + +properties: + compatible: +const: mediatek,mt6360 + + reg: +description: + I2C device address. +maxItems: 1 + + wakeup-source: true + + interrupts: +maxItems: 1 + + interrupt-names: + enum: +- IRQB + + interrupt-controller: true + + "#interrupt-cells": +const: 1 +description: + The first cell is the IRQ number. + +required: + - compatible + - reg + - interrupts + - interrupt-controller + - "#interrupt-cells" + +additionalProperties: false + +examples: + - | +#include +#include +i2c { +#address-cells = <1>; +#size-cells = <0>; + +mt6360@34 { +compatible = "mediatek,mt6360"; +reg = <0x34>; +wakeup-source; +interrupts-extended = <&gpio26 0 IRQ_TYPE_LEVEL_LOW>; +interrupt-names = "IRQB"; +interrupt-controller; +#interrupt-cells = <1>; +}; +}; -- 2.7.4
[PATCH resend v13 5/5] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 826 + 3 files changed, 840 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 849d3c5..3c1999d 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index 73e603e..cdb1ffb 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..86caaac --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,826 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_MAX_LEDS +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +/* Virtual definition for multicolor */ +#define MT6360_VIRTUAL_MULTICOLOR (MT6360_MAX_LEDS + 1) +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH resend v13 4/5] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../devicetree/bindings/leds/leds-mt6360.yaml | 159 + 1 file changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..cb1f4b7 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^(multi-)?led@[0-5]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output ISINK1 + - 1 # LED output ISINK2 + - 2 # LED output ISINK3 + - 3 # LED output ISINKML + - 4 # LED output FLASH1 + - 5 # LED output FLASH2 + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + multi-led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + led@0 { + reg = <0>; + color = ; + }; + led@1 { + reg = <1>; + color = ; + }; + led@2 { + reg = <2>; + color = ; + }; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH resend v13 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski Acked-by: Rob Herring --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH resend v13 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH resend v13 2/5] leds: flash: Fix multicolor no-ops registration by return 0
From: Gene Chen Fix multicolor no-ops registration by return 0, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH resend v13 0/5] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (5) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor no-ops registration by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 159 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 827 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 7 files changed, 1049 insertions(+), 36 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header changelogs between v9 & v10 - add comment for reuse registration functions in flash and multicolor changelogs between v10 & v11 - match dt-binding reg property comment to the functionality name - remove exist patch in linux-next - dicide multicolor channel by color definitiion changelogs between v11 & v12 - Fix print size_t by %zu - Fix dt-binding name regular experssion changelogs between v12 & v13 - Fix kbuild test rebot build error
Re: [PATCH] dt-bindings: mfd: mediatek: Add bindings for MT6360 PMIC
Dear Reviewers, Should I wait for all sub-devices dt-binding review done, then send the integral binding document? Gene Chen 於 2020年11月13日 週五 下午1:54寫道: > > Dear Reviewers, > >Please let me know if there is anything need to be revised. > > Gene Chen 於 2020年8月20日 週四 下午4:36寫道: > > > > From: Gene Chen > > > > Add bindings for MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > Documentation/devicetree/bindings/mfd/mt6360.yaml | 142 > > ++ > > 1 file changed, 142 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/mfd/mt6360.yaml > > > > diff --git a/Documentation/devicetree/bindings/mfd/mt6360.yaml > > b/Documentation/devicetree/bindings/mfd/mt6360.yaml > > new file mode 100644 > > index 000..5ad1afd > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/mfd/mt6360.yaml > > @@ -0,0 +1,142 @@ > > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) > > +%YAML 1.2 > > +--- > > +$id: http://devicetree.org/schemas/mfd/mt6360.yaml# > > +$schema: http://devicetree.org/meta-schemas/core.yaml# > > + > > +title: MT6360 PMIC from MediaTek Integrated > > + > > +maintainers: > > + - Gene Chen > > + > > +description: | > > + MT6360 is a PMIC device with the following sub modules. > > + It is interfaced to host controller using I2C interface. > > + > > + This document describes the binding for PMIC device and its sub module. > > + > > +properties: > > + compatible: > > +const: mediatek,mt6360 > > + > > + reg: > > +description: > > + I2C device address. > > +maxItems: 1 > > + > > + wakeup-source: true > > + > > + interrupts: > > +maxItems: 1 > > + > > + interrupt-names: > > + enum: > > +- IRQB > > + > > + interrupt-controller: true > > + > > + "#interrupt-cells": > > +const: 1 > > +description: > > + The first cell is the IRQ number. > > + > > + regulator: > > +$ref: ../regulator/mt6360-regulator.yaml > > + > > +required: > > + - compatible > > + - reg > > + - interrupts > > + - interrupt-controller > > + - "#interrupt-cells" > > + > > +additionalProperties: false > > + > > +examples: > > + - | > > +#include > > +#include > > +i2c { > > +#address-cells = <1>; > > +#size-cells = <0>; > > + > > +mt6360@34 { > > +compatible = "mediatek,mt6360"; > > +reg = <0x34>; > > +wakeup-source; > > +interrupts-extended = <&gpio26 0 IRQ_TYPE_LEVEL_LOW>; > > +interrupt-names = "IRQB"; > > +interrupt-controller; > > +#interrupt-cells = <1>; > > +regulator { > > +compatible = "mediatek,mt6360-regulator"; > > +LDO_VIN3-supply = <&BUCK2>; > > +buck1 { > > +regulator-compatible = "BUCK1"; > > +regulator-name = "mt6360,buck1"; > > +regulator-min-microvolt = <30>; > > +regulator-max-microvolt = <130>; > > +regulator-allowed-modes = > + MT6360_OPMODE_LP > > + MT6360_OPMODE_ULP>; > > +}; > > +BUCK2: buck2 { > > +regulator-compatible = "BUCK2"; > > +regulator-name = "mt6360,buck2"; > > +regulator-min-microvolt = <30>; > > +regulator-max-microvolt = <130>; > > +regulator-allowed-modes = > + MT6360_OPMODE_LP > > + MT6360_OPMODE_ULP>; > > +}; > > +ldo6 { > > +regulator-compatible = "LDO6"; > > +regulator-name = "mt6360,ldo6"; > > +regulator-min-microvolt = <50>; > > +regulator-max-microvolt = <210>; > > +regulator-allowed-modes = > +
[PATCH v13 5/5] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 827 + 3 files changed, 841 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..b485e05 --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,827 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_MAX_LEDS +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +/* Virtual definition for multicolor */ +#define MT6360_VIRTUAL_MULTICOLOR (MT6360_MAX_LEDS + 1) +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH v13 4/5] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen Reviewed-by: Rob Herring --- .../devicetree/bindings/leds/leds-mt6360.yaml | 159 + 1 file changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..cb1f4b7 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^(multi-)?led@[0-5]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output ISINK1 + - 1 # LED output ISINK2 + - 2 # LED output ISINK3 + - 3 # LED output ISINKML + - 4 # LED output FLASH1 + - 5 # LED output FLASH2 + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + multi-led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + led@0 { + reg = <0>; + color = ; + }; + led@1 { + reg = <1>; + color = ; + }; + led@2 { + reg = <2>; + color = ; + }; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v13 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v13 2/5] leds: flash: Fix multicolor no-ops registration by return 0
From: Gene Chen Fix multicolor no-ops registration by return 0, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH v13 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski Acked-by: Rob Herring --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v13 0/5] leds: mt6360: Add LED driver for MT6360
In-Reply-To: This patch series add MT6360 LED support contains driver and binding document Gene Chen (5) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor no-ops registration by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 159 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 827 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 7 files changed, 1049 insertions(+), 36 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header changelogs between v9 & v10 - add comment for reuse registration functions in flash and multicolor changelogs between v10 & v11 - match dt-binding reg property comment to the functionality name - remove exist patch in linux-next - dicide multicolor channel by color definitiion changelogs between v11 & v12 - Fix print size_t by %zu - Fix dt-binding name regular experssion changelogs between v12 & v13 - Fix kbuild test rebot build error
[PATCH v12 2/5] leds: flash: Fix multicolor no-ops registration by return 0
From: Gene Chen Fix multicolor no-ops registration by return 0, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH v12 5/5] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 827 + 3 files changed, 841 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..42d18a8 --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,827 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_MAX_LEDS +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +/* Virtual definition for multicolor */ +#define MT6360_VIRTUAL_MULTICOLOR (MT6360_MAX_LEDS + 1) +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH v12 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v12 4/5] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 159 + 1 file changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..cb1f4b7 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^(multi-)?led@[0-5]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output ISINK1 + - 1 # LED output ISINK2 + - 2 # LED output ISINK3 + - 3 # LED output ISINKML + - 4 # LED output FLASH1 + - 5 # LED output FLASH2 + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + multi-led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + led@0 { + reg = <0>; + color = ; + }; + led@1 { + reg = <1>; + color = ; + }; + led@2 { + reg = <2>; + color = ; + }; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v12 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski Acked-by: Rob Herring --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v12 0/5] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (5) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor no-ops registration by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 159 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 827 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 7 files changed, 1049 insertions(+), 36 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header changelogs between v9 & v10 - add comment for reuse registration functions in flash and multicolor changelogs between v10 & v11 - match dt-binding reg property comment to the functionality name - remove exist patch in linux-next - dicide multicolor channel by color definitiion changelogs between v11 & v12 - Fix print size_t by %lu - Fix dt-binding name regular experssion
Re: [PATCH v2 2/2] power: supply: mt6360_charger: add MT6360 charger support
Resend again, Gene Chen 於 2020年11月19日 週四 上午10:24寫道: > > Dear Reviewers, > >Please let me know if there is anything need to be revised. > > Gene Chen 於 2020年11月3日 週二 下午6:41寫道: > > > > From: Gene Chen > > > > Add basic support for the battery charger for MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > drivers/power/supply/Kconfig | 10 + > > drivers/power/supply/Makefile |1 + > > drivers/power/supply/mt6360_charger.c | 1022 > > + > > 3 files changed, 1033 insertions(+) > > create mode 100644 drivers/power/supply/mt6360_charger.c > > > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > > index faf2830..e2d53a3 100644 > > --- a/drivers/power/supply/Kconfig > > +++ b/drivers/power/supply/Kconfig > > @@ -562,6 +562,16 @@ config CHARGER_MP2629 > > Battery charger. This driver provides Battery charger power > > management > > functions on the systems. > > > > +config CHARGER_MT6360 > > + tristate "Mediatek MT6360 Charger Driver" > > + depends on MFD_MT6360 > > + depends on REGULATOR > > + help > > + Say Y here to enable MT6360 Charger Part. > > + The device supports High-Accuracy Voltage/Current Regulation, > > + Average Input Current Regulation, Battery Tempature Sensing, > > + Over-Temperature Protection, DPDM Detection for BC1.2 > > + > > config CHARGER_QCOM_SMBB > > tristate "Qualcomm Switch-Mode Battery Charger and Boost" > > depends on MFD_SPMI_PMIC || COMPILE_TEST > > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > > index b3c694a..9abecb9c 100644 > > --- a/drivers/power/supply/Makefile > > +++ b/drivers/power/supply/Makefile > > @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= > > max77693_charger.o > > obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o > > obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o > > obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o > > +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o > > obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o > > obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o > > obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o > > diff --git a/drivers/power/supply/mt6360_charger.c > > b/drivers/power/supply/mt6360_charger.c > > new file mode 100644 > > index 000..5631875 > > --- /dev/null > > +++ b/drivers/power/supply/mt6360_charger.c > > @@ -0,0 +1,1022 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (c) 2019 MediaTek Inc. > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define MT6360_PMU_CHG_CTRL1 0x311 > > +#define MT6360_PMU_CHG_CTRL2 0x312 > > +#define MT6360_PMU_CHG_CTRL3 0x313 > > +#define MT6360_PMU_CHG_CTRL4 0x314 > > +#define MT6360_PMU_CHG_CTRL5 0x315 > > +#define MT6360_PMU_CHG_CTRL6 0x316 > > +#define MT6360_PMU_CHG_CTRL7 0x317 > > +#define MT6360_PMU_CHG_CTRL8 0x318 > > +#define MT6360_PMU_CHG_CTRL9 0x319 > > +#define MT6360_PMU_CHG_CTRL10 0x31A > > +#define MT6360_PMU_CHG_CTRL11 0x31B > > +#define MT6360_PMU_CHG_CTRL12 0x31C > > +#define MT6360_PMU_CHG_CTRL13 0x31D > > +#define MT6360_PMU_DEVICE_TYPE 0x322 > > +#define MT6360_PMU_USB_STATUS1 0x327 > > +#define MT6360_PMU_CHG_CTRL17 0x32B > > +#define MT6360_PMU_CHG_CTRL18 0x32C > > +#define MT6360_PMU_CHG_STAT0x34A > > +#define MT6360_PMU_CHG_CTRL19 0x361 > > +#define MT6360_PMU_FOD_STAT0x3E7 > > + > > +/* MT6360_PMU_CHG_CTRL1 */ > > +#define MT6360_FSLP_SHFT (3) > > +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) > > +#define MT6360_HIZ_SHFT(2) > > +#define MT6360_HIZ_MASKBIT(MT6360_HIZ_SHFT) > > +#define MT6360_OPA_MODE_SHFT (0) > > +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) > > +/* MT6360_PMU_CHG_CTRL2 */ > > +#define MT6360_TE_SHFT (4) > > +#define MT6360_TE_MASK BIT(MT6360_TE_SHFT) > > +#define MT6360_IINLMTSEL_SHFT (2) > > +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) > > +#define MT6360_CHG_EN_SHFT (0) > > +#define MT6360_CHG_EN_MASK BIT(MT6360_CHG_EN_SHFT) > > +/* MT6360_PMU_CHG_CTRL3 */ > > +#define MT
Re: [PATCH v11 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
Pavel Machek 於 2020年12月2日 週三 下午8:23寫道: > > On Wed 2020-12-02 18:46:49, Gene Chen wrote: > > From: Gene Chen > > > > Add LED_FUNCTION_MOONLIGHT definitions > > > > Signed-off-by: Gene Chen > > Acked-by: Jacek Anaszewski > > Acked-by: Rob Herring > > --- > > include/dt-bindings/leds/common.h | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/include/dt-bindings/leds/common.h > > b/include/dt-bindings/leds/common.h > > index 52b619d..843e65d 100644 > > --- a/include/dt-bindings/leds/common.h > > +++ b/include/dt-bindings/leds/common.h > > @@ -78,6 +78,7 @@ > > #define LED_FUNCTION_INDICATOR "indicator" > > #define LED_FUNCTION_LAN "lan" > > #define LED_FUNCTION_MAIL "mail" > > +#define LED_FUNCTION_MOONLIGHT "moonlight" > > There's "torch" function that should be used for this. I guess comment > should be added with explanation what exactly that is and how should > the LED be named. > According to mail, 11/25 "Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions", The Moonlight LED is LED which maximum current more than torch, but less than flash. Such as front camera fill light. I think our channel is moonlight, not torch. I will add this description to comment. We can't exactly define moonlight current level, because every vendor has their own specification. > Best regards, > Pavel > -- > http://www.livejournal.com/~pavelmachek
[PATCH v11 4/5] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 159 + 1 file changed, 159 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..73c67b1 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,159 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "(^led@[0-5]$|led)": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output ISINK1 + - 1 # LED output ISINK2 + - 2 # LED output ISINK3 + - 3 # LED output ISINKML + - 4 # LED output FLASH1 + - 5 # LED output FLASH2 + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + multi-led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + led@0 { + reg = <0>; + color = ; + }; + led@1 { + reg = <1>; + color = ; + }; + led@2 { + reg = <2>; + color = ; + }; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v11 5/5] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 827 + 3 files changed, 841 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..42d18a8 --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,827 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_MAX_LEDS +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +/* Virtual definition for multicolor */ +#define MT6360_VIRTUAL_MULTICOLOR (MT6360_MAX_LEDS + 1) +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH v11 2/5] leds: flash: Fix multicolor no-ops registration by return 0
From: Gene Chen Fix multicolor no-ops registration by return 0, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH v11 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH, and move the same registration functions outside of #ifdef block. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v11 3/5] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski Acked-by: Rob Herring --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v11 0/5] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (5) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor no-ops registration by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 159 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 827 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 7 files changed, 1049 insertions(+), 36 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header changelogs between v9 & v10 - add comment for reuse registration functions in flash and multicolor changelogs between v10 & v11 - match dt-binding reg property comment to the functionality name - remove exist patch in linux-next - dicide multicolor channel by color definitiion
[PATCH v10 1/6] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH, and reuse same registration functions no matter flash class exist or not. Signed-off-by: Gene Chen --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v10 6/6] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 811 + 3 files changed, 825 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..94836bb --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,811 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_LED_MULTICOLOR, + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH v10 5/6] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 164 + 1 file changed, 164 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..b2ffbc6 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-6]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output INDICATOR1_RED + - 1 # LED output INDICATOR1_GREEN + - 2 # LED output INDICATOR1_BLUE + - 3 # LED output INDICATOR2_ML + - 4 # LED output FLED1 + - 5 # LED output FLED2 + - 6 # LED output MULTICOLOR + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@6 { + reg = <6>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v10 3/6] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v10 4/6] dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size
From: Gene Chen Increase LED_COLOR_ID maximum size for LED_COLOR_ID_RGB Signed-off-by: Gene Chen --- Documentation/devicetree/bindings/leds/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index a2a541b..0c9f912 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -43,7 +43,7 @@ properties: LED_COLOR_ID available, add a new one. $ref: /schemas/types.yaml#definitions/uint32 minimum: 0 -maximum: 8 +maximum: 9 function-enumerator: description: -- 2.7.4
[PATCH v10 2/6] leds: flash: Fix multicolor no-ops registration by return 0
From: Gene Chen Fix multicolor no-ops registration by return 0, and reuse same registration functions no matter multicolor class exist or not. Signed-off-by: Gene Chen --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH v10 0/6] leds: mt6360: Add LED driver for MT6360
[PATCH v10 0/6] leds: mt6360: Add LED driver for MT6360 This patch series add MT6360 LED support contains driver and binding document Gene Chen (6) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor no-ops registration by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/common.yaml |2 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 164 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 811 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 8 files changed, 1039 insertions(+), 37 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header changelogs between v9 & v10 - add comment for reuse registration functions in flash and multicolor
[PATCH v9 0/6] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (6) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor registration no-ops by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/common.yaml |2 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 164 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 811 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 42 include/linux/led-class-multicolor.h| 42 8 files changed, 1039 insertions(+), 37 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT changelogs between v8 & v9 - reuse api in flash and multicolor header
[PATCH v9 6/6] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 811 + 3 files changed, 825 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..94836bb --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,811 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_LED_MULTICOLOR, + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; +
[PATCH v9 5/6] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 164 + 1 file changed, 164 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..b2ffbc6 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-6]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output INDICATOR1_RED + - 1 # LED output INDICATOR1_GREEN + - 2 # LED output INDICATOR1_BLUE + - 3 # LED output INDICATOR2_ML + - 4 # LED output FLED1 + - 5 # LED output FLED2 + - 6 # LED output MULTICOLOR + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@6 { + reg = <6>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v9 4/6] dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size
From: Gene Chen Increase LED_COLOR_ID maximum size for LED_COLOR_ID_RGB Signed-off-by: Gene Chen --- Documentation/devicetree/bindings/leds/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index a2a541b..0c9f912 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -43,7 +43,7 @@ properties: LED_COLOR_ID available, add a new one. $ref: /schemas/types.yaml#definitions/uint32 minimum: 0 -maximum: 8 +maximum: 9 function-enumerator: description: -- 2.7.4
[PATCH v9 3/6] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen Acked-by: Jacek Anaszewski --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v9 1/6] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH Signed-off-by: Gene Chen --- include/linux/led-class-flash.h | 42 - 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..612b4ca 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -98,12 +99,6 @@ int led_classdev_flash_register_ext(struct device *parent, struct led_classdev_flash *fled_cdev, struct led_init_data *init_data); -static inline int led_classdev_flash_register(struct device *parent, - struct led_classdev_flash *fled_cdev) -{ - return led_classdev_flash_register_ext(parent, fled_cdev, NULL); -} - /** * led_classdev_flash_unregister - unregisters an object of led_classdev class *with support for flash LEDs @@ -118,15 +113,44 @@ int devm_led_classdev_flash_register_ext(struct device *parent, struct led_init_data *init_data); +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev); + +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + static inline int devm_led_classdev_flash_register(struct device *parent, struct led_classdev_flash *fled_cdev) { return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); } -void devm_led_classdev_flash_unregister(struct device *parent, - struct led_classdev_flash *fled_cdev); - /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v9 2/6] leds: flash: Fix multicolor registration no-ops by return 0
From: Gene Chen Fix multicolor registration no-ops by return 0 Signed-off-by: Gene Chen --- include/linux/led-class-multicolor.h | 42 +--- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..210d57b 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -44,12 +44,6 @@ int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); -} - /** * led_classdev_multicolor_unregister - unregisters an object of led_classdev * class with support for multicolor LEDs @@ -68,13 +62,6 @@ int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data); -static inline int devm_led_classdev_multicolor_register(struct device *parent, -struct led_classdev_mc *mcled_cdev) -{ - return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev, -NULL); -} - void devm_led_classdev_multicolor_unregister(struct device *parent, struct led_classdev_mc *mcled_cdev); #else @@ -83,27 +70,33 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; -} - -static inline int led_classdev_multicolor_register(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{ - return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); + return 0; } static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {}; static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; +} + +static inline void devm_led_classdev_multicolor_unregister(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ + +static inline int led_classdev_multicolor_register(struct device *parent, + struct led_classdev_mc *mcled_cdev) +{ + return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL); } static inline int devm_led_classdev_multicolor_register(struct device *parent, @@ -113,9 +106,4 @@ static inline int devm_led_classdev_multicolor_register(struct device *parent, NULL); } -static inline void devm_led_classdev_multicolor_unregister(struct device *parent, - struct led_classdev_mc *mcled_cdev) -{}; - -#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */ #endif /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */ -- 2.7.4
[PATCH v8 6/6] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 811 + 3 files changed, 825 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..94836bb --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,811 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_LED_MULTICOLOR, + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; + struct led_classdev_mc mc; +
[PATCH v8 5/6] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 164 + 1 file changed, 164 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..b2ffbc6 --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-6]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output INDICATOR1_RED + - 1 # LED output INDICATOR1_GREEN + - 2 # LED output INDICATOR1_BLUE + - 3 # LED output INDICATOR2_ML + - 4 # LED output FLED1 + - 5 # LED output FLED2 + - 6 # LED output MULTICOLOR + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@6 { + reg = <6>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_MOONLIGHT; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v8 0/6] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (6) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH leds: flash: Fix multicolor registration no-ops by return 0 dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/common.yaml |2 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 164 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 811 include/dt-bindings/leds/common.h |1 include/linux/led-class-flash.h | 36 include/linux/led-class-multicolor.h|6 8 files changed, 1030 insertions(+), 4 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device changelogs between v7 & v8 - Add mutex for led fault get ops - Fix flash and multicolor no-ops return 0 - Add LED_FUNCTION_MOONLIGHT
[PATCH v8 1/6] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH Signed-off-by: Gene Chen --- include/linux/led-class-flash.h | 36 1 file changed, 36 insertions(+) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..5f36eae 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -127,6 +128,41 @@ static inline int devm_led_classdev_flash_register(struct device *parent, void devm_led_classdev_flash_unregister(struct device *parent, struct led_classdev_flash *fled_cdev); +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return 0; +} + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return 0; +} + +static inline int devm_led_classdev_flash_register(struct device *parent, +struct led_classdev_flash *fled_cdev) +{ + return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + +static inline void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v8 4/6] dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size
From: Gene Chen Increase LED_COLOR_ID maximum size for LED_COLOR_ID_RGB Signed-off-by: Gene Chen --- Documentation/devicetree/bindings/leds/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index a2a541b..0c9f912 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -43,7 +43,7 @@ properties: LED_COLOR_ID available, add a new one. $ref: /schemas/types.yaml#definitions/uint32 minimum: 0 -maximum: 8 +maximum: 9 function-enumerator: description: -- 2.7.4
[PATCH v8 3/6] dt-bindings: leds: Add LED_FUNCTION_MOONLIGHT definitions
From: Gene Chen Add LED_FUNCTION_MOONLIGHT definitions Signed-off-by: Gene Chen --- include/dt-bindings/leds/common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..843e65d 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -78,6 +78,7 @@ #define LED_FUNCTION_INDICATOR "indicator" #define LED_FUNCTION_LAN "lan" #define LED_FUNCTION_MAIL "mail" +#define LED_FUNCTION_MOONLIGHT "moonlight" #define LED_FUNCTION_MTD "mtd" #define LED_FUNCTION_PANIC "panic" #define LED_FUNCTION_PROGRAMMING "programming" -- 2.7.4
[PATCH v8 2/6] leds: flash: Fix multicolor registration no-ops by return 0
From: Gene Chen Fix multicolor registration no-ops by return 0 Signed-off-by: Gene Chen --- include/linux/led-class-multicolor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/led-class-multicolor.h b/include/linux/led-class-multicolor.h index 5116f9a..dbf3832 100644 --- a/include/linux/led-class-multicolor.h +++ b/include/linux/led-class-multicolor.h @@ -83,7 +83,7 @@ static inline int led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; } static inline int led_classdev_multicolor_register(struct device *parent, @@ -96,14 +96,14 @@ static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mc static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev, enum led_brightness brightness) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register_ext(struct device *parent, struct led_classdev_mc *mcled_cdev, struct led_init_data *init_data) { - return -EINVAL; + return 0; } static inline int devm_led_classdev_multicolor_register(struct device *parent, -- 2.7.4
Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
Fix Typo. Gene Chen 於 2020年11月24日 週二 下午3:33寫道: > > Jacek Anaszewski 於 2020年11月24日 週二 上午4:52寫道: > > > > On 11/23/20 4:00 AM, Gene Chen wrote: > > > Jacek Anaszewski 於 2020年11月20日 週五 上午6:26寫道: > > >> > > >> On 11/19/20 10:57 PM, Pavel Machek wrote: > > >>> On Thu 2020-11-19 22:03:14, Jacek Anaszewski wrote: > > >>>> Hi Pavel, Gene, > > >>>> > > >>>> On 11/18/20 10:37 PM, Pavel Machek wrote: > > >>>>> Hi! > > >>>>> > > >>>>>> From: Gene Chen > > >>>>>> > > >>>>>> Add LED_COLOR_ID_MOONLIGHT definitions > > >>>>> > > >>>>> Why is moonlight a color? Camera flashes are usually white, no? > > >>>>> > > >>>>> At least it needs a comment... > > >>>> > > >>>> That's my fault, In fact I should have asked about adding > > >>>> LED_FUNCTION_MOONLIGHT, it was evidently too late for me that > > >>>> evening... > > >>> > > >>> Aha, that makes more sense. > > >>> > > >>> But please let's call it "torch" if we do that, as that is already > > >>> used in kernel sources... and probably in the interface, too: > > >> > > >> I'd say that torch is something different that moonlight, > > >> but we would need more input from Gene to learn more about > > >> the nature of light emitted by ML LED on his device. > > >> > > >> Please note that torch is usually meant as the other mode of > > >> flash LED (sometimes it is called "movie mode"), which is already > > >> handled by brightness file of LED class flash device (i.e. its LED class > > >> subset), and which also maps to v4l2-flash TORCH mode. > > >> > > > > > > It's used to front camera fill light. > > > More brightness than screen backlight, and more soft light than flash. > > > I think LED_ID_COLOR_WHITE is okay. > > > > So why in v6 you assigned LED_COLOR_ID_AMBER to it? > > we suppose Moonlight can be white or amber. > > Regardless of that, now we're talking about LED function - you chose > > LED_FUNCTION_INDICATOR for it, but inferring from your above description > > - it certainly doesn't fit here. > > > > Also register names, containing part "ML" indicate that this LED's > > intended function is moonlinght, which your description somehow > > corroborates. > > > > Moonlight LEDs become ubiquitous nowadays so sooner or later we will > > need to add this function anyway [0]. > > > > [0] > > https://landscapelightingoakville.com/what-is-moon-lighting-and-why-does-it-remain-so-popular/ > > > > According to reference, > "When you are trying to imitate moonlight you need to use low voltage, > softer lighting. You don’t want something that’s too bright" > which is focus on brightness instead of color. > > So we suppose Moonlight can be white or amber. > > Should I add LED_FUNCTION_MOONLIGHT and set LED_COLOR_ID_WHITE? > > > -- > > Best regards, > > Jacek Anaszewski
Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
Jacek Anaszewski 於 2020年11月24日 週二 上午4:52寫道: > > On 11/23/20 4:00 AM, Gene Chen wrote: > > Jacek Anaszewski 於 2020年11月20日 週五 上午6:26寫道: > >> > >> On 11/19/20 10:57 PM, Pavel Machek wrote: > >>> On Thu 2020-11-19 22:03:14, Jacek Anaszewski wrote: > >>>> Hi Pavel, Gene, > >>>> > >>>> On 11/18/20 10:37 PM, Pavel Machek wrote: > >>>>> Hi! > >>>>> > >>>>>> From: Gene Chen > >>>>>> > >>>>>> Add LED_COLOR_ID_MOONLIGHT definitions > >>>>> > >>>>> Why is moonlight a color? Camera flashes are usually white, no? > >>>>> > >>>>> At least it needs a comment... > >>>> > >>>> That's my fault, In fact I should have asked about adding > >>>> LED_FUNCTION_MOONLIGHT, it was evidently too late for me that evening... > >>> > >>> Aha, that makes more sense. > >>> > >>> But please let's call it "torch" if we do that, as that is already > >>> used in kernel sources... and probably in the interface, too: > >> > >> I'd say that torch is something different that moonlight, > >> but we would need more input from Gene to learn more about > >> the nature of light emitted by ML LED on his device. > >> > >> Please note that torch is usually meant as the other mode of > >> flash LED (sometimes it is called "movie mode"), which is already > >> handled by brightness file of LED class flash device (i.e. its LED class > >> subset), and which also maps to v4l2-flash TORCH mode. > >> > > > > It's used to front camera fill light. > > More brightness than screen backlight, and more soft light than flash. > > I think LED_ID_COLOR_WHITE is okay. > > So why in v6 you assigned LED_COLOR_ID_AMBER to it? > > Regardless of that, now we're talking about LED function - you chose > LED_FUNCTION_INDICATOR for it, but inferring from your above description > - it certainly doesn't fit here. > > Also register names, containing part "ML" indicate that this LED's > intended function is moonlinght, which your description somehow > corroborates. > > Moonlight LEDs become ubiquitous nowadays so sooner or later we will > need to add this function anyway [0]. > > [0] > https://landscapelightingoakville.com/what-is-moon-lighting-and-why-does-it-remain-so-popular/ > We use term "Moonlight" as reference says "When you are trying to imitate moonlight you need to use low voltage, softer lighting. You don’t want something that’s too bright" which is focus on brightness instead of color. So we surpose Moonlight can be white or amber. Should I add LED_FUNCTION_MOONLIGHT and set LED_COLOR_ID_WHITE? > -- > Best regards, > Jacek Anaszewski
Re: [PATCH v7 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
Jacek Anaszewski 於 2020年11月24日 週二 上午5:07寫道: > > On 11/23/20 4:20 AM, Gene Chen wrote: > > Jacek Anaszewski 於 2020年11月20日 週五 上午6:29寫道: > >> > >> Hi Gene, > >> > >> On 11/18/20 11:47 AM, Gene Chen wrote: > >>> From: Gene Chen > >>> > >>> Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH > >>> > >>> Signed-off-by: Gene Chen > >>> --- > >>>include/linux/led-class-flash.h | 36 > >>> > >>>1 file changed, 36 insertions(+) > >>> > >>> diff --git a/include/linux/led-class-flash.h > >>> b/include/linux/led-class-flash.h > >>> index 21a3358..4f56c28 100644 > >>> --- a/include/linux/led-class-flash.h > >>> +++ b/include/linux/led-class-flash.h > >>> @@ -85,6 +85,7 @@ static inline struct led_classdev_flash > >>> *lcdev_to_flcdev( > >>>return container_of(lcdev, struct led_classdev_flash, led_cdev); > >>>} > >>> > >>> +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) > >>>/** > >>> * led_classdev_flash_register_ext - register a new object of LED > >>> class with > >>> * init data and with support for flash > >>> LEDs > >>> @@ -127,6 +128,41 @@ static inline int > >>> devm_led_classdev_flash_register(struct device *parent, > >>>void devm_led_classdev_flash_unregister(struct device *parent, > >>>struct led_classdev_flash > >>> *fled_cdev); > >>> > >>> +#else > >>> + > >>> +static inline int led_classdev_flash_register_ext(struct device *parent, > >>> + struct led_classdev_flash *fled_cdev, > >>> + struct led_init_data *init_data) > >>> +{ > >>> + return -EINVAL; > >> > >> s/-EINVAL/0/ > >> > >> The goal here is to assure that client will not fail when using no-op. > >> > >>> +} > >>> + > >>> +static inline int led_classdev_flash_register(struct device *parent, > >>> +struct led_classdev_flash > >>> *fled_cdev) > >>> +{ > >>> + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); > >>> +} > >> > >> This function should be placed after #ifdef block because its > >> shape is the same for both cases. > >> > >>> +static inline void led_classdev_flash_unregister(struct > >>> led_classdev_flash *fled_cdev) {}; > >>> +static inline int devm_led_classdev_flash_register_ext(struct device > >>> *parent, > >>> + struct led_classdev_flash *fled_cdev, > >>> + struct led_init_data *init_data) > >>> +{ > >>> + return -EINVAL; > >> > >> /-EINVAL/0/ > >> > >> Please do the same fix in all no-ops in the led-class-multicolor.h, > >> as we've discussed. > >> > > > > I think return -EINVAL is correct, because I should register flash > > light device if I define FLED in DTS node. > > I don't quite follow your logic here. > > No-op function's purpose is to simplify the code on the caller's side. > Therefore it should report success. > > Please return 0 from it. > Just like those functions in led-class-multicolor.h, caller may use return value to check whether FLED is registered successfully or not. For this case, is returning 0 a little bit misleading? > -- > Best regards, > Jacek Anaszewski
Re: [PATCH v7 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
Jacek Anaszewski 於 2020年11月20日 週五 上午6:29寫道: > > Hi Gene, > > On 11/18/20 11:47 AM, Gene Chen wrote: > > From: Gene Chen > > > > Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH > > > > Signed-off-by: Gene Chen > > --- > > include/linux/led-class-flash.h | 36 > > 1 file changed, 36 insertions(+) > > > > diff --git a/include/linux/led-class-flash.h > > b/include/linux/led-class-flash.h > > index 21a3358..4f56c28 100644 > > --- a/include/linux/led-class-flash.h > > +++ b/include/linux/led-class-flash.h > > @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( > > return container_of(lcdev, struct led_classdev_flash, led_cdev); > > } > > > > +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) > > /** > >* led_classdev_flash_register_ext - register a new object of LED class > > with > >* init data and with support for flash LEDs > > @@ -127,6 +128,41 @@ static inline int > > devm_led_classdev_flash_register(struct device *parent, > > void devm_led_classdev_flash_unregister(struct device *parent, > > struct led_classdev_flash *fled_cdev); > > > > +#else > > + > > +static inline int led_classdev_flash_register_ext(struct device *parent, > > + struct led_classdev_flash *fled_cdev, > > + struct led_init_data *init_data) > > +{ > > + return -EINVAL; > > s/-EINVAL/0/ > > The goal here is to assure that client will not fail when using no-op. > > > +} > > + > > +static inline int led_classdev_flash_register(struct device *parent, > > +struct led_classdev_flash > > *fled_cdev) > > +{ > > + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); > > +} > > This function should be placed after #ifdef block because its > shape is the same for both cases. > > > +static inline void led_classdev_flash_unregister(struct led_classdev_flash > > *fled_cdev) {}; > > +static inline int devm_led_classdev_flash_register_ext(struct device > > *parent, > > + struct led_classdev_flash *fled_cdev, > > + struct led_init_data *init_data) > > +{ > > + return -EINVAL; > > /-EINVAL/0/ > > Please do the same fix in all no-ops in the led-class-multicolor.h, > as we've discussed. > I think return -EINVAL is correct, because I should register flash light device if I define FLED in DTS node. > > +} > > + > > +static inline int devm_led_classdev_flash_register(struct device *parent, > > + struct led_classdev_flash *fled_cdev) > > +{ > > + return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); > > +} > > > This function should also be placed after #ifdef block. > Please make the same optimizations in the led-class-multicolor.h as you > are at it. > > > + > > +void devm_led_classdev_flash_unregister(struct device *parent, > > s/void/static inline void/ > > That's the reason why you got warning from buildbot. > ACK > > + struct led_classdev_flash *fled_cdev) > > +{}; > > + > > +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ > > + > > /** > >* led_set_flash_strobe - setup flash strobe > >* @fled_cdev: the flash LED to set strobe on > > > > -- > Best regards, > Jacek Anaszewski
Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
Jacek Anaszewski 於 2020年11月20日 週五 上午6:26寫道: > > On 11/19/20 10:57 PM, Pavel Machek wrote: > > On Thu 2020-11-19 22:03:14, Jacek Anaszewski wrote: > >> Hi Pavel, Gene, > >> > >> On 11/18/20 10:37 PM, Pavel Machek wrote: > >>> Hi! > >>> > >>>> From: Gene Chen > >>>> > >>>> Add LED_COLOR_ID_MOONLIGHT definitions > >>> > >>> Why is moonlight a color? Camera flashes are usually white, no? > >>> > >>> At least it needs a comment... > >> > >> That's my fault, In fact I should have asked about adding > >> LED_FUNCTION_MOONLIGHT, it was evidently too late for me that evening... > > > > Aha, that makes more sense. > > > > But please let's call it "torch" if we do that, as that is already > > used in kernel sources... and probably in the interface, too: > > I'd say that torch is something different that moonlight, > but we would need more input from Gene to learn more about > the nature of light emitted by ML LED on his device. > > Please note that torch is usually meant as the other mode of > flash LED (sometimes it is called "movie mode"), which is already > handled by brightness file of LED class flash device (i.e. its LED class > subset), and which also maps to v4l2-flash TORCH mode. > It's used to front camera fill light. More brightness than screen backlight, and more soft light than flash. I think LED_ID_COLOR_WHITE is okay. > > ./arch/arm/mach-pxa/ezx.c: .name = "a910::torch", > > > > Best regards, > > Pavel > > > > -- > Best regards, > Jacek Anaszewski
Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
Pavel Machek 於 2020年11月19日 週四 下午3:44寫道: > > Hi! > > > > > From: Gene Chen > > > > > > > > Add LED_COLOR_ID_MOONLIGHT definitions > > > > > > Why is moonlight a color? Camera flashes are usually white, no? > > > > > > At least it needs a comment... > > > > > > Best regards, > > > Pavel > > > > > > > Moonlight has more current level(150mA) from general RGB LED (24mA). > > It can be used as night-light and usually use color AMBER. > > Camera flashes are usually use two flash LED. One is YELLOW, and one > >is WHITE. > > From what I seen, night-lights are usually differetent "temperatures" > of white. Cool white + warm white. > > I believe "warm white" would be easier to understand than > "moonlight"... > ACK, I will change color "LED_COLOR_ID_WHITE" > Best regards, > Pavel > > -- > http://www.livejournal.com/~pavelmachek
Re: [PATCH v2 2/2] power: supply: mt6360_charger: add MT6360 charger support
Dear Reviewers, Please let me know if there is anything need to be revised. Gene Chen 於 2020年11月3日 週二 下午6:41寫道: > > From: Gene Chen > > Add basic support for the battery charger for MT6360 PMIC > > Signed-off-by: Gene Chen > --- > drivers/power/supply/Kconfig | 10 + > drivers/power/supply/Makefile |1 + > drivers/power/supply/mt6360_charger.c | 1022 > + > 3 files changed, 1033 insertions(+) > create mode 100644 drivers/power/supply/mt6360_charger.c > > diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig > index faf2830..e2d53a3 100644 > --- a/drivers/power/supply/Kconfig > +++ b/drivers/power/supply/Kconfig > @@ -562,6 +562,16 @@ config CHARGER_MP2629 > Battery charger. This driver provides Battery charger power > management > functions on the systems. > > +config CHARGER_MT6360 > + tristate "Mediatek MT6360 Charger Driver" > + depends on MFD_MT6360 > + depends on REGULATOR > + help > + Say Y here to enable MT6360 Charger Part. > + The device supports High-Accuracy Voltage/Current Regulation, > + Average Input Current Regulation, Battery Tempature Sensing, > + Over-Temperature Protection, DPDM Detection for BC1.2 > + > config CHARGER_QCOM_SMBB > tristate "Qualcomm Switch-Mode Battery Charger and Boost" > depends on MFD_SPMI_PMIC || COMPILE_TEST > diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile > index b3c694a..9abecb9c 100644 > --- a/drivers/power/supply/Makefile > +++ b/drivers/power/supply/Makefile > @@ -77,6 +77,7 @@ obj-$(CONFIG_CHARGER_MAX77693)+= max77693_charger.o > obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o > obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o > obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o > +obj-$(CONFIG_CHARGER_MT6360) += mt6360_charger.o > obj-$(CONFIG_CHARGER_QCOM_SMBB)+= qcom_smbb.o > obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o > obj-$(CONFIG_CHARGER_BQ24190) += bq24190_charger.o > diff --git a/drivers/power/supply/mt6360_charger.c > b/drivers/power/supply/mt6360_charger.c > new file mode 100644 > index 000..5631875 > --- /dev/null > +++ b/drivers/power/supply/mt6360_charger.c > @@ -0,0 +1,1022 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (c) 2019 MediaTek Inc. > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define MT6360_PMU_CHG_CTRL1 0x311 > +#define MT6360_PMU_CHG_CTRL2 0x312 > +#define MT6360_PMU_CHG_CTRL3 0x313 > +#define MT6360_PMU_CHG_CTRL4 0x314 > +#define MT6360_PMU_CHG_CTRL5 0x315 > +#define MT6360_PMU_CHG_CTRL6 0x316 > +#define MT6360_PMU_CHG_CTRL7 0x317 > +#define MT6360_PMU_CHG_CTRL8 0x318 > +#define MT6360_PMU_CHG_CTRL9 0x319 > +#define MT6360_PMU_CHG_CTRL10 0x31A > +#define MT6360_PMU_CHG_CTRL11 0x31B > +#define MT6360_PMU_CHG_CTRL12 0x31C > +#define MT6360_PMU_CHG_CTRL13 0x31D > +#define MT6360_PMU_DEVICE_TYPE 0x322 > +#define MT6360_PMU_USB_STATUS1 0x327 > +#define MT6360_PMU_CHG_CTRL17 0x32B > +#define MT6360_PMU_CHG_CTRL18 0x32C > +#define MT6360_PMU_CHG_STAT0x34A > +#define MT6360_PMU_CHG_CTRL19 0x361 > +#define MT6360_PMU_FOD_STAT0x3E7 > + > +/* MT6360_PMU_CHG_CTRL1 */ > +#define MT6360_FSLP_SHFT (3) > +#define MT6360_FSLP_MASK BIT(MT6360_FSLP_SHFT) > +#define MT6360_HIZ_SHFT(2) > +#define MT6360_HIZ_MASKBIT(MT6360_HIZ_SHFT) > +#define MT6360_OPA_MODE_SHFT (0) > +#define MT6360_OPA_MODE_MASK BIT(MT6360_OPA_MODE_SHFT) > +/* MT6360_PMU_CHG_CTRL2 */ > +#define MT6360_TE_SHFT (4) > +#define MT6360_TE_MASK BIT(MT6360_TE_SHFT) > +#define MT6360_IINLMTSEL_SHFT (2) > +#define MT6360_IINLMTSEL_MASK GENMASK(3, 2) > +#define MT6360_CHG_EN_SHFT (0) > +#define MT6360_CHG_EN_MASK BIT(MT6360_CHG_EN_SHFT) > +/* MT6360_PMU_CHG_CTRL3 */ > +#define MT6360_IAICR_SHFT (2) > +#define MT6360_IAICR_MASK GENMASK(7, 2) > +#define MT6360_ILIM_EN_MASKBIT(0) > +/* MT6360_PMU_CHG_CTRL4 */ > +#define MT6360_VOREG_SHFT (1) > +#define MT6360_VOREG_MASK GENMASK(7, 1) > +/* MT6360_PMU_CHG_CTRL5 */ > +#define MT6360_VOBST_MASK GENMASK(7, 2) > +/* MT6360_PMU_CHG_CTRL6 */ > +#define MT6360_VMIVR_SHFT (1) > +#define MT6360_VMIVR_MASK GENMASK(7, 1) > +/* MT6360_PMU_CHG_CTRL7 */ > +#define MT6360_ICHG_SHFT (2) > +#define MT6360_ICHG_MASK GENMASK(7, 2) > +/* MT6360_PMU_CHG_CTRL8 */ > +#define MT636
Re: [PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
Pavel Machek 於 2020年11月19日 週四 上午5:37寫道: > > Hi! > > > From: Gene Chen > > > > Add LED_COLOR_ID_MOONLIGHT definitions > > Why is moonlight a color? Camera flashes are usually white, no? > > At least it needs a comment... > > Best regards, > Pavel > Moonlight has more current level(150mA) from general RGB LED (24mA). It can be used as night-light and usually use color AMBER. Camera flashes are usually use two flash LED. One is YELLOW, and one is WHITE. > > > > Signed-off-by: Gene Chen > > --- > > include/dt-bindings/leds/common.h | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/include/dt-bindings/leds/common.h > > b/include/dt-bindings/leds/common.h > > index 52b619d..1409e9a 100644 > > --- a/include/dt-bindings/leds/common.h > > +++ b/include/dt-bindings/leds/common.h > > @@ -33,7 +33,8 @@ > > #define LED_COLOR_ID_MULTI 8 /* For multicolor LEDs */ > > #define LED_COLOR_ID_RGB 9 /* For multicolor LEDs that can do > > arbitrary color, > > so this would include RGBW and > > similar */ > > -#define LED_COLOR_ID_MAX 10 > > +#define LED_COLOR_ID_MOONLIGHT 10 > > +#define LED_COLOR_ID_MAX 11 > > > > /* Standard LED functions */ > > /* Keyboard LEDs, usually it would be input4::capslock etc. */ > > -- > http://www.livejournal.com/~pavelmachek
Re: [PATCH v7 4/5] dt-bindings: leds: Add bindings for MT6360 LED
Rob Herring 於 2020年11月19日 週四 上午5:25寫道: > > On Wed, 18 Nov 2020 18:47:41 +0800, Gene Chen wrote: > > From: Gene Chen > > > > Add bindings document for LED support on MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > .../devicetree/bindings/leds/leds-mt6360.yaml | 164 > > + > > 1 file changed, 164 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > > > > My bot found errors running 'make dt_binding_check' on your patch: > > yamllint warnings/errors: > ./Documentation/devicetree/bindings/leds/leds-mt6360.yaml:57:2: [warning] > wrong indentation: expected 2 but found 1 (indentation) > > dtschema/dtc warnings/errors: > /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/leds/leds-mt6360.example.dt.yaml: > led-controller: led@3:color:0:0: 10 is greater than the maximum of 9 > From schema: > /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/leds/leds-mt6360.yaml > /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/leds/leds-mt6360.example.dt.yaml: > led-controller: led@3:color:0:0: 10 is greater than the maximum of 9 > From schema: > /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > ACK, I will add description to this patch by “this patch depends on patch [PATCH v7 3/5] dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size" > See https://patchwork.ozlabs.org/patch/1402193 > > The base for the patch is generally the last rc1. Any dependencies > should be noted. > > If you already ran 'make dt_binding_check' and didn't see the above > error(s), then make sure 'yamllint' is installed and dt-schema is up to > date: > > pip3 install dtschema --upgrade > > Please check and re-submit. >
[PATCH v7 4/5] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 164 + 1 file changed, 164 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..9bd6cbe --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,164 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-6]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output INDICATOR1_RED + - 1 # LED output INDICATOR1_GREEN + - 2 # LED output INDICATOR1_BLUE + - 3 # LED output INDICATOR2_ML + - 4 # LED output FLED1 + - 5 # LED output FLED2 + - 6 # LED output MULTICOLOR + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@3 { + reg = <3>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@6 { + reg = <6>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + }; + }; + + - | + + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + }; +... -- 2.7.4
[PATCH v7 5/5] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 808 + 3 files changed, 822 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..8432901 --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,808 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_LED_MULTICOLOR, + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; + struct led_classdev_mc mc; +
[PATCH v7 2/5] dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions
From: Gene Chen Add LED_COLOR_ID_MOONLIGHT definitions Signed-off-by: Gene Chen --- include/dt-bindings/leds/common.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/dt-bindings/leds/common.h b/include/dt-bindings/leds/common.h index 52b619d..1409e9a 100644 --- a/include/dt-bindings/leds/common.h +++ b/include/dt-bindings/leds/common.h @@ -33,7 +33,8 @@ #define LED_COLOR_ID_MULTI 8 /* For multicolor LEDs */ #define LED_COLOR_ID_RGB 9 /* For multicolor LEDs that can do arbitrary color, so this would include RGBW and similar */ -#define LED_COLOR_ID_MAX 10 +#define LED_COLOR_ID_MOONLIGHT 10 +#define LED_COLOR_ID_MAX 11 /* Standard LED functions */ /* Keyboard LEDs, usually it would be input4::capslock etc. */ -- 2.7.4
[PATCH v7 3/5] dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size
From: Gene Chen Increase LED_COLOR_ID_* maximum size Signed-off-by: Gene Chen --- Documentation/devicetree/bindings/leds/common.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/leds/common.yaml b/Documentation/devicetree/bindings/leds/common.yaml index a2a541b..f356b61 100644 --- a/Documentation/devicetree/bindings/leds/common.yaml +++ b/Documentation/devicetree/bindings/leds/common.yaml @@ -43,7 +43,7 @@ properties: LED_COLOR_ID available, add a new one. $ref: /schemas/types.yaml#definitions/uint32 minimum: 0 -maximum: 8 +maximum: 10 function-enumerator: description: -- 2.7.4
[PATCH v7 1/5] leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH
From: Gene Chen Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH Signed-off-by: Gene Chen --- include/linux/led-class-flash.h | 36 1 file changed, 36 insertions(+) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 21a3358..4f56c28 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -85,6 +85,7 @@ static inline struct led_classdev_flash *lcdev_to_flcdev( return container_of(lcdev, struct led_classdev_flash, led_cdev); } +#if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) /** * led_classdev_flash_register_ext - register a new object of LED class with * init data and with support for flash LEDs @@ -127,6 +128,41 @@ static inline int devm_led_classdev_flash_register(struct device *parent, void devm_led_classdev_flash_unregister(struct device *parent, struct led_classdev_flash *fled_cdev); +#else + +static inline int led_classdev_flash_register_ext(struct device *parent, + struct led_classdev_flash *fled_cdev, + struct led_init_data *init_data) +{ + return -EINVAL; +} + +static inline int led_classdev_flash_register(struct device *parent, + struct led_classdev_flash *fled_cdev) +{ + return led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + +static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {}; +static inline int devm_led_classdev_flash_register_ext(struct device *parent, +struct led_classdev_flash *fled_cdev, +struct led_init_data *init_data) +{ + return -EINVAL; +} + +static inline int devm_led_classdev_flash_register(struct device *parent, +struct led_classdev_flash *fled_cdev) +{ + return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL); +} + +void devm_led_classdev_flash_unregister(struct device *parent, + struct led_classdev_flash *fled_cdev) +{}; + +#endif /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */ + /** * led_set_flash_strobe - setup flash strobe * @fled_cdev: the flash LED to set strobe on -- 2.7.4
[PATCH v7 0/5] leds: mt6360: Add LED driver for MT6360
In-Reply-To: Gene Chen (5) leds: flash: Add flash registration with undefined CONFIG_LEDS_CLASS_FLASH dt-bindings: leds: Add LED_COLOR_ID_MOONLIGHT definitions dt-bindings: leds: common: Increase LED_COLOR_ID_* maximum size dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/common.yaml |2 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 164 +++ drivers/leds/Kconfig| 13 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 808 include/dt-bindings/leds/common.h |3 include/linux/led-class-flash.h | 36 7 files changed, 1025 insertions(+), 2 deletions(-) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only changelogs between v6 & v7 - Add binding multicolor device sample code - Add flash ops mutex lock - Remove V4L2 init with indicator device
Re: [PATCH v6 1/2] dt-bindings: leds: Add bindings for MT6360 LED
Jacek Anaszewski 於 2020年11月18日 週三 上午6:24寫道: > > Hi Gene, > > Thank you for the patch. > > On 11/17/20 11:55 AM, Gene Chen wrote: > > From: Gene Chen > > > > Add bindings document for LED support on MT6360 PMIC > > > > Signed-off-by: Gene Chen > > --- > > .../devicetree/bindings/leds/leds-mt6360.yaml | 114 > > + > > 1 file changed, 114 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > > > diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > new file mode 100644 > > index 000..871db4d > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml > > @@ -0,0 +1,114 @@ > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > > +%YAML 1.2 > > +--- > > +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# > > +$schema: http://devicetree.org/meta-schemas/core.yaml# > > + > > +title: LED driver for MT6360 PMIC from MediaTek Integrated. > > + > > +maintainers: > > + - Gene Chen > > + > > +description: | > > + This module is part of the MT6360 MFD device. > > + see Documentation/devicetree/bindings/mfd/mt6360.yaml > > + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, > > + and 4-channel RGB LED support Register/Flash/Breath Mode > > What actually is the Register mode? > Register mode is equal to S/W mode. Red LED indicator ic default is H/W mode. LED enable when charger plug in. > > + > > +properties: > > + compatible: > > +const: mediatek,mt6360-led > > + > > + "#address-cells": > > +const: 1 > > + > > + "#size-cells": > > +const: 0 > > + > > +patternProperties: > > + "^led@[0-6]$": > > +type: object > > +$ref: common.yaml# > > +description: > > + Properties for a single LED. > > + > > +properties: > > + reg: > > +description: Index of the LED. > > +enum: > > + - 0 # LED output INDICATOR1_RED > > + - 1 # LED output INDICATOR1_GREEN > > + - 2 # LED output INDICATOR1_BLUE > > + - 3 # LED output INDICATOR2_ML > > + - 4 # LED output FLED1 > > + - 5 # LED output FLED2 > > + - 6 # LED output MULTICOLOR > > + > > +unevaluatedProperties: false > > + > > +required: > > + - compatible > > + - "#address-cells" > > + - "#size-cells" > > + > > +additionalProperties: false > > + > > +examples: > > + - | > > + #include > > + led-controller { > > + compatible = "mediatek,mt6360-led"; > > + #address-cells = <1>; > > + #size-cells = <0>; > > + > > + led@0 { > > + reg = <0>; > > + function = LED_FUNCTION_INDICATOR; > > + color = ; > > + led-max-microamp = <24000>; > > + }; > > + led@3 { > > + reg = <3>; > > + function = LED_FUNCTION_INDICATOR; > > + color = ; > > You should really have here LED_COLOR_ID_MOONLIGHT if this is > a moonlight LED. You'll need to add it to dt-bindings/leds/common.h. > > > + led-max-microamp = <15>; > > + }; > > + led@4 { > > + reg = <4>; > > + function = LED_FUNCTION_FLASH; > > + color = ; > > + function-enumerator = <1>; > > + led-max-microamp = <20>; > > + flash-max-microamp = <50>; > > + flash-max-timeout-us = <1024000>; > > + }; > > + led@5 { > > + reg = <5>; > > + function = LED_FUNCTION_FLASH; > > + color = ; > > + function-enumerator = <2>; > > + led-max-microamp = <20>; > > + flash-max-microamp = <50>; > > + flash-max-timeout-us = <1024000>; > > + }; > > + led@6 { > > + reg = <6>; > > + function = LED_FUNCTION_INDICATOR; > > + color = ; > > + led-max-microamp = <24000>; > > + #address-cells = <1>; > > + #size-cells = <0>; > > + > > + led@1 { > > + reg = <1>; > > + function = LED_FUNCTION_INDICATOR; > > + color = ; > > + }; > > + led@2 { > > + reg = <2>; > > + function = LED_FUNCTION_INDICATOR; > > + color = ; > > + }; > > + }; > > It is of little avail to have multicolor LED with only two LEDs. > I propose not to allow such setup - i.e. you should have either > one multicolor LED comprising three sub-LEDs (regs: 0, 1, 2), > and with main color property set to LED_COLOR_ID_RGB, or three separate > LEDs. > > Effectively, you should have two separate DT examples here to make it > clear: one for the case with three LED class devices and one with > LED multicolor class device. > ACK > > + }; > > +... > > > > -- > Best regards, > Jacek Anaszewski
Re: [PATCH v6 2/2] leds: mt6360: Add LED driver for MT6360
Jacek Anaszewski 於 2020年11月18日 週三 上午6:25寫道: > > Hi Gene, > > On 11/17/20 11:55 AM, Gene Chen wrote: > > From: Gene Chen > > > > Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, > > 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for > > moonlight LED. > > > > Signed-off-by: Gene Chen > > --- > > drivers/leds/Kconfig | 13 + > > drivers/leds/Makefile | 1 + > > drivers/leds/leds-mt6360.c | 817 > > + > > 3 files changed, 831 insertions(+) > > create mode 100644 drivers/leds/leds-mt6360.c > > > > diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > > index 1c181df..4f533bc 100644 > > --- a/drivers/leds/Kconfig > > +++ b/drivers/leds/Kconfig > > @@ -271,6 +271,19 @@ config LEDS_MT6323 > > This option enables support for on-chip LED drivers found on > > Mediatek MT6323 PMIC. > > > > +config LEDS_MT6360 > > + tristate "LED Support for Mediatek MT6360 PMIC" > > + depends on LEDS_CLASS && OF > > + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH > > + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR > > + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS > > + depends on MFD_MT6360 > > + help > > + This option enables support for dual Flash LED drivers found on > > + Mediatek MT6360 PMIC. > > + Independent current sources supply for each flash LED support torch > > + and strobe mode. > > + > > config LEDS_S3C24XX > > tristate "LED Support for Samsung S3C24XX GPIO LEDs" > > depends on LEDS_CLASS > > diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile > > index c2c7d7a..5596427 100644 > > --- a/drivers/leds/Makefile > > +++ b/drivers/leds/Makefile > > @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o > > obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o > > obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o > > obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o > > +obj-$(CONFIG_LEDS_MT6360)+= leds-mt6360.o > > obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o > > obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o > > obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o > > diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c > > new file mode 100644 > > index 000..e3a30bd > > --- /dev/null > > +++ b/drivers/leds/leds-mt6360.c > > @@ -0,0 +1,817 @@ > > +// SPDX-License-Identifier: GPL-2.0-only > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +enum { > > + MT6360_LED_ISNK1 = 0, > > + MT6360_LED_ISNK2, > > + MT6360_LED_ISNK3, > > + MT6360_LED_ISNKML, > > + MT6360_LED_FLASH1, > > + MT6360_LED_FLASH2, > > + MT6360_LED_MULTICOLOR, > > + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR > > +}; > > + > > +#define MT6360_REG_RGBEN 0x380 > > +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) > > +#define MT6360_ISNK_ENMASK(_led_no) BIT(7 - (_led_no)) > > +#define MT6360_ISNK_MASK GENMASK(4, 0) > > +#define MT6360_CHRINDSEL_MASKBIT(3) > > + > > +#define MULTICOLOR_NUM_CHANNELS 3 > > + > > +#define MT6360_REG_FLEDEN0x37E > > +#define MT6360_REG_STRBTO0x373 > > +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - > > MT6360_LED_FLASH1)) > > +#define MT6360_REG_FLEDISTRB(_id)(MT6360_REG_FLEDBASE(_id) + 2) > > +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) > > +#define MT6360_REG_CHGSTAT2 0x3E1 > > +#define MT6360_REG_FLEDSTAT1 0x3E9 > > +#define MT6360_ITORCH_MASK GENMASK(4, 0) > > +#define MT6360_ISTROBE_MASK GENMASK(6, 0) > > +#define MT6360_STRBTO_MASK GENMASK(6, 0) > > +#define MT6360_TORCHEN_MASK BIT(3) > > +#define MT6360_STROBEN_MASK BIT(2) > > +#define MT6360_FLCSEN_MASK(_id) BIT(MT6360_LED_FLASH2 - _id) > > +#define MT6360_FLEDCHGVINOVP_MASKBIT(3) > > +#define MT6360_FLED1STRBTO_MASK BIT(11) > > +#define MT6360_FLED2STRBTO_MASK BIT(10)
[PATCH v6 1/2] dt-bindings: leds: Add bindings for MT6360 LED
From: Gene Chen Add bindings document for LED support on MT6360 PMIC Signed-off-by: Gene Chen --- .../devicetree/bindings/leds/leds-mt6360.yaml | 114 + 1 file changed, 114 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/leds-mt6360.yaml diff --git a/Documentation/devicetree/bindings/leds/leds-mt6360.yaml b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml new file mode 100644 index 000..871db4d --- /dev/null +++ b/Documentation/devicetree/bindings/leds/leds-mt6360.yaml @@ -0,0 +1,114 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/leds/leds-mt6360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LED driver for MT6360 PMIC from MediaTek Integrated. + +maintainers: + - Gene Chen + +description: | + This module is part of the MT6360 MFD device. + see Documentation/devicetree/bindings/mfd/mt6360.yaml + Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, + and 4-channel RGB LED support Register/Flash/Breath Mode + +properties: + compatible: +const: mediatek,mt6360-led + + "#address-cells": +const: 1 + + "#size-cells": +const: 0 + +patternProperties: + "^led@[0-6]$": +type: object +$ref: common.yaml# +description: + Properties for a single LED. + +properties: + reg: +description: Index of the LED. +enum: + - 0 # LED output INDICATOR1_RED + - 1 # LED output INDICATOR1_GREEN + - 2 # LED output INDICATOR1_BLUE + - 3 # LED output INDICATOR2_ML + - 4 # LED output FLED1 + - 5 # LED output FLED2 + - 6 # LED output MULTICOLOR + +unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + led-controller { + compatible = "mediatek,mt6360-led"; + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <15>; + }; + led@4 { + reg = <4>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <1>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@5 { + reg = <5>; + function = LED_FUNCTION_FLASH; + color = ; + function-enumerator = <2>; + led-max-microamp = <20>; + flash-max-microamp = <50>; + flash-max-timeout-us = <1024000>; + }; + led@6 { + reg = <6>; + function = LED_FUNCTION_INDICATOR; + color = ; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + + led@1 { + reg = <1>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + led@2 { + reg = <2>; + function = LED_FUNCTION_INDICATOR; + color = ; + }; + }; + }; +... -- 2.7.4
[PATCH v6 2/2] leds: mt6360: Add LED driver for MT6360
From: Gene Chen Add MT6360 LED driver include 2-channel Flash LED with torch/strobe mode, 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel for moonlight LED. Signed-off-by: Gene Chen --- drivers/leds/Kconfig | 13 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6360.c | 817 + 3 files changed, 831 insertions(+) create mode 100644 drivers/leds/leds-mt6360.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 1c181df..4f533bc 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -271,6 +271,19 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6360 + tristate "LED Support for Mediatek MT6360 PMIC" + depends on LEDS_CLASS && OF + depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH + depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR + depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS + depends on MFD_MT6360 + help + This option enables support for dual Flash LED drivers found on + Mediatek MT6360 PMIC. + Independent current sources supply for each flash LED support torch + and strobe mode. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index c2c7d7a..5596427 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -66,6 +66,7 @@ obj-$(CONFIG_LEDS_MIKROTIK_RB532) += leds-rb532.o obj-$(CONFIG_LEDS_MLXCPLD) += leds-mlxcpld.o obj-$(CONFIG_LEDS_MLXREG) += leds-mlxreg.o obj-$(CONFIG_LEDS_MT6323) += leds-mt6323.o +obj-$(CONFIG_LEDS_MT6360) += leds-mt6360.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o diff --git a/drivers/leds/leds-mt6360.c b/drivers/leds/leds-mt6360.c new file mode 100644 index 000..e3a30bd --- /dev/null +++ b/drivers/leds/leds-mt6360.c @@ -0,0 +1,817 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MT6360_LED_ISNK1 = 0, + MT6360_LED_ISNK2, + MT6360_LED_ISNK3, + MT6360_LED_ISNKML, + MT6360_LED_FLASH1, + MT6360_LED_FLASH2, + MT6360_LED_MULTICOLOR, + MT6360_MAX_LEDS = MT6360_LED_MULTICOLOR +}; + +#define MT6360_REG_RGBEN 0x380 +#define MT6360_REG_ISNK(_led_no) (0x381 + (_led_no)) +#define MT6360_ISNK_ENMASK(_led_no)BIT(7 - (_led_no)) +#define MT6360_ISNK_MASK GENMASK(4, 0) +#define MT6360_CHRINDSEL_MASK BIT(3) + +#define MULTICOLOR_NUM_CHANNELS3 + +#define MT6360_REG_FLEDEN 0x37E +#define MT6360_REG_STRBTO 0x373 +#define MT6360_REG_FLEDBASE(_id) (0x372 + 4 * (_id - MT6360_LED_FLASH1)) +#define MT6360_REG_FLEDISTRB(_id) (MT6360_REG_FLEDBASE(_id) + 2) +#define MT6360_REG_FLEDITOR(_id) (MT6360_REG_FLEDBASE(_id) + 3) +#define MT6360_REG_CHGSTAT20x3E1 +#define MT6360_REG_FLEDSTAT1 0x3E9 +#define MT6360_ITORCH_MASK GENMASK(4, 0) +#define MT6360_ISTROBE_MASKGENMASK(6, 0) +#define MT6360_STRBTO_MASK GENMASK(6, 0) +#define MT6360_TORCHEN_MASKBIT(3) +#define MT6360_STROBEN_MASKBIT(2) +#define MT6360_FLCSEN_MASK(_id)BIT(MT6360_LED_FLASH2 - _id) +#define MT6360_FLEDCHGVINOVP_MASK BIT(3) +#define MT6360_FLED1STRBTO_MASKBIT(11) +#define MT6360_FLED2STRBTO_MASKBIT(10) +#define MT6360_FLED1STRB_MASK BIT(9) +#define MT6360_FLED2STRB_MASK BIT(8) +#define MT6360_FLED1SHORT_MASK BIT(7) +#define MT6360_FLED2SHORT_MASK BIT(6) +#define MT6360_FLEDLVF_MASKBIT(3) + +#define MT6360_ISNKRGB_STEPUA 2000 +#define MT6360_ISNKRGB_MAXUA 24000 +#define MT6360_ISNKML_STEPUA 5000 +#define MT6360_ISNKML_MAXUA15 + +#define MT6360_ITORCH_MINUA25000 +#define MT6360_ITORCH_STEPUA 12500 +#define MT6360_ITORCH_MAXUA40 +#define MT6360_ISTRB_MINUA 5 +#define MT6360_ISTRB_STEPUA12500 +#define MT6360_ISTRB_MAXUA 150 +#define MT6360_STRBTO_MINUS64000 +#define MT6360_STRBTO_STEPUS 32000 +#define MT6360_STRBTO_MAXUS2432000 + +#define STATE_OFF 0 +#define STATE_KEEP 1 +#define STATE_ON 2 + +struct mt6360_led { + union { + struct led_classdev isnk; + struct led_classdev_mc mc; +
[PATCH v6 0/2] leds: mt6360: Add LED driver for MT6360
This patch series add MT6360 LED support contains driver and binding document Gene Chen (2) dt-bindings: leds: Add bindings for MT6360 LED leds: mt6360: Add LED driver for MT6360 Documentation/devicetree/bindings/leds/leds-mt6360.yaml | 95 + drivers/leds/Kconfig| 12 drivers/leds/Makefile |1 drivers/leds/leds-mt6360.c | 783 4 files changed, 891 insertions(+) changelogs between v1 & v2 - add led driver with mfd changelogs between v2 & v3 - independent add led driver - add dt-binding document - refactor macros definition for easy to debug - parse device tree by fwnode - use devm*ext to register led class device changelogs between v3 & v4 - fix binding document description - use GENMASK and add unit postfix to definition - isink register led class device changelogs between v4 & v5 - change rgb isink to multicolor control - add binding reference to mfd yaml changelogs between v5 & v6 - Use DT to decide RGB LED is multicolor device or indicator device only
Re: [PATCH v5 2/2] leds: mt6360: Add LED driver for MT6360
Jacek Anaszewski 於 2020年11月17日 週二 上午2:25寫道: > > On 11/16/20 11:01 AM, Gene Chen wrote: > > Jacek Anaszewski 於 2020年10月31日 週六 上午6:34寫道: > >> > >> On 10/30/20 9:51 AM, Gene Chen wrote: > >>> Jacek Anaszewski 於 2020年10月28日 週三 上午1:28寫道: > >>>> > >>>> On 10/27/20 10:28 AM, Gene Chen wrote: > >>>>> Jacek Anaszewski 於 2020年10月21日 週三 上午5:47寫道: > >>>>>> > >>>>>> On 10/20/20 8:44 AM, Gene Chen wrote: > >>>>>>> Jacek Anaszewski 於 2020年10月9日 週五 > >>>>>>> 上午5:51寫道: > >>>>>>>> > >>>>>>>> Hi Gene, > >>>>>>>> > >>>>>>>> On 10/7/20 3:42 AM, Gene Chen wrote: > >>>>>>>>> From: Gene Chen > >>>>>>>>> > >>>>>>>>> Add MT6360 LED driver include 2-channel Flash LED with torch/strobe > >>>>>>>>> mode, > >>>>>>>>> 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel > >>>>>>>>> for > >>>>>>>>> moonlight LED. > >>>>>>>>> > >>>>>>>>> Signed-off-by: Gene Chen > >>>>>>>>> --- > >>>>>>>>> drivers/leds/Kconfig | 12 + > >>>>>>>>> drivers/leds/Makefile | 1 + > >>>>>>>>> drivers/leds/leds-mt6360.c | 783 > >>>>>>>>> + > >>>>>>>>> 3 files changed, 796 insertions(+) > >>>>>>>>> create mode 100644 drivers/leds/leds-mt6360.c > >>>>>>>>> > >>>>>>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>>>>>>>> index 1c181df..c7192dd 100644 > >>>>>>>>> --- a/drivers/leds/Kconfig > >>>>>>>>> +++ b/drivers/leds/Kconfig > >>>>>>>>> @@ -271,6 +271,18 @@ config LEDS_MT6323 > >>>>>>>>> This option enables support for on-chip LED drivers > >>>>>>>>> found on > >>>>>>>>> Mediatek MT6323 PMIC. > >>>>>>>>> > >>>>>>>>> +config LEDS_MT6360 > >>>>>>>>> + tristate "LED Support for Mediatek MT6360 PMIC" > >>>>>>>>> + depends on LEDS_CLASS_FLASH && OF > >>>>>>>>> + depends on LEDS_CLASS_MULTICOLOR > >>>>>>>> > >>>>>>>> Since CONFIG_LED_CLASS_MULTICOLOR can be turned off you need to have > >>>>>>>> below instead: > >>>>>>>> > >>>>>>>> depends on LEDS_CLASS_MULTICOLOR || !!LEDS_CLASS_MULTICOLOR > >>>> > >>>> My typo here, should be one "!": > >>>> > >>>> depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR > >>>> > >>>> And you should also have > >>>> > >>>> depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH > >>>> > >>>> But to make it work correctly you would have to add registration > >>>> stubs to include/linux/led-class-flash.h similarly to LED mc stubs > >>>> in include/linux/led-class-multicolor.h. > >>>> > >>>>>>>> > >>>>>>>> Unless you want to prevent enabling the driver without RGB LED, > >>>>>>>> but that does not seem to be reasonable at first glance. > >>>>>>>> > >>>>>>> > >>>>>>> May I change to "select LEDS_CLASS_MULTICOLOR"? > >>>>>>> I suppose RGB always use multicolor mode. > >>>>>> > >>>>>> You will also have moonlight LED that will not need multicolor > >>>>>> framework. Is it somehow troublesome to keep "depends on"? > >>>>>> > >>>>> > >>>>> If only use ML LED and FLED, DTSI will only define ML LED and FLED. > >>>>> Therefore, the drivers probe will not register rgb multicolor device. > >>>> > >>>> Ple
Re: [PATCH v5 2/2] leds: mt6360: Add LED driver for MT6360
Jacek Anaszewski 於 2020年10月31日 週六 上午6:34寫道: > > On 10/30/20 9:51 AM, Gene Chen wrote: > > Jacek Anaszewski 於 2020年10月28日 週三 上午1:28寫道: > >> > >> On 10/27/20 10:28 AM, Gene Chen wrote: > >>> Jacek Anaszewski 於 2020年10月21日 週三 上午5:47寫道: > >>>> > >>>> On 10/20/20 8:44 AM, Gene Chen wrote: > >>>>> Jacek Anaszewski 於 2020年10月9日 週五 上午5:51寫道: > >>>>>> > >>>>>> Hi Gene, > >>>>>> > >>>>>> On 10/7/20 3:42 AM, Gene Chen wrote: > >>>>>>> From: Gene Chen > >>>>>>> > >>>>>>> Add MT6360 LED driver include 2-channel Flash LED with torch/strobe > >>>>>>> mode, > >>>>>>> 3-channel RGB LED support Register/Flash/Breath Mode, and 1-channel > >>>>>>> for > >>>>>>> moonlight LED. > >>>>>>> > >>>>>>> Signed-off-by: Gene Chen > >>>>>>> --- > >>>>>>> drivers/leds/Kconfig | 12 + > >>>>>>> drivers/leds/Makefile | 1 + > >>>>>>> drivers/leds/leds-mt6360.c | 783 > >>>>>>> + > >>>>>>> 3 files changed, 796 insertions(+) > >>>>>>> create mode 100644 drivers/leds/leds-mt6360.c > >>>>>>> > >>>>>>> diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig > >>>>>>> index 1c181df..c7192dd 100644 > >>>>>>> --- a/drivers/leds/Kconfig > >>>>>>> +++ b/drivers/leds/Kconfig > >>>>>>> @@ -271,6 +271,18 @@ config LEDS_MT6323 > >>>>>>>This option enables support for on-chip LED drivers found > >>>>>>> on > >>>>>>>Mediatek MT6323 PMIC. > >>>>>>> > >>>>>>> +config LEDS_MT6360 > >>>>>>> + tristate "LED Support for Mediatek MT6360 PMIC" > >>>>>>> + depends on LEDS_CLASS_FLASH && OF > >>>>>>> + depends on LEDS_CLASS_MULTICOLOR > >>>>>> > >>>>>> Since CONFIG_LED_CLASS_MULTICOLOR can be turned off you need to have > >>>>>> below instead: > >>>>>> > >>>>>> depends on LEDS_CLASS_MULTICOLOR || !!LEDS_CLASS_MULTICOLOR > >> > >> My typo here, should be one "!": > >> > >> depends on LEDS_CLASS_MULTICOLOR || !LEDS_CLASS_MULTICOLOR > >> > >> And you should also have > >> > >> depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH > >> > >> But to make it work correctly you would have to add registration > >> stubs to include/linux/led-class-flash.h similarly to LED mc stubs > >> in include/linux/led-class-multicolor.h. > >> > >>>>>> > >>>>>> Unless you want to prevent enabling the driver without RGB LED, > >>>>>> but that does not seem to be reasonable at first glance. > >>>>>> > >>>>> > >>>>> May I change to "select LEDS_CLASS_MULTICOLOR"? > >>>>> I suppose RGB always use multicolor mode. > >>>> > >>>> You will also have moonlight LED that will not need multicolor > >>>> framework. Is it somehow troublesome to keep "depends on"? > >>>> > >>> > >>> If only use ML LED and FLED, DTSI will only define ML LED and FLED. > >>> Therefore, the drivers probe will not register rgb multicolor device. > >> > >> Please test your use case again with my fixed "depends on". > >> > >> In case when there is only ML LED and FLED in the DT it should > >> register both devices if LEDS_CLASS_FLASH is turned on. > >> Multicolor framework has nothing to do in this case. > >> > >> But if you additionally had MC LED node, then it should > >> be registered only if LEDS_CLASS_MULTICOLOR is enabled. > >> > >> Similarly, when FLED node is present, but LEDS_CLASS_FLASH > >> is off, and LEDS_CLASS_MULTICOLOR is on, the driver should still > >> compile, but register only LED MC device (if its node is present). > >> > > > > I think this case only regis
Re: [PATCH] dt-bindings: mfd: mediatek: Add bindings for MT6360 PMIC
Dear Reviewers, Please let me know if there is anything need to be revised. Gene Chen 於 2020年8月20日 週四 下午4:36寫道: > > From: Gene Chen > > Add bindings for MT6360 PMIC > > Signed-off-by: Gene Chen > --- > Documentation/devicetree/bindings/mfd/mt6360.yaml | 142 > ++ > 1 file changed, 142 insertions(+) > create mode 100644 Documentation/devicetree/bindings/mfd/mt6360.yaml > > diff --git a/Documentation/devicetree/bindings/mfd/mt6360.yaml > b/Documentation/devicetree/bindings/mfd/mt6360.yaml > new file mode 100644 > index 000..5ad1afd > --- /dev/null > +++ b/Documentation/devicetree/bindings/mfd/mt6360.yaml > @@ -0,0 +1,142 @@ > +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/mfd/mt6360.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: MT6360 PMIC from MediaTek Integrated > + > +maintainers: > + - Gene Chen > + > +description: | > + MT6360 is a PMIC device with the following sub modules. > + It is interfaced to host controller using I2C interface. > + > + This document describes the binding for PMIC device and its sub module. > + > +properties: > + compatible: > +const: mediatek,mt6360 > + > + reg: > +description: > + I2C device address. > +maxItems: 1 > + > + wakeup-source: true > + > + interrupts: > +maxItems: 1 > + > + interrupt-names: > + enum: > +- IRQB > + > + interrupt-controller: true > + > + "#interrupt-cells": > +const: 1 > +description: > + The first cell is the IRQ number. > + > + regulator: > +$ref: ../regulator/mt6360-regulator.yaml > + > +required: > + - compatible > + - reg > + - interrupts > + - interrupt-controller > + - "#interrupt-cells" > + > +additionalProperties: false > + > +examples: > + - | > +#include > +#include > +i2c { > +#address-cells = <1>; > +#size-cells = <0>; > + > +mt6360@34 { > +compatible = "mediatek,mt6360"; > +reg = <0x34>; > +wakeup-source; > +interrupts-extended = <&gpio26 0 IRQ_TYPE_LEVEL_LOW>; > +interrupt-names = "IRQB"; > +interrupt-controller; > +#interrupt-cells = <1>; > +regulator { > +compatible = "mediatek,mt6360-regulator"; > +LDO_VIN3-supply = <&BUCK2>; > +buck1 { > +regulator-compatible = "BUCK1"; > +regulator-name = "mt6360,buck1"; > +regulator-min-microvolt = <30>; > +regulator-max-microvolt = <130>; > +regulator-allowed-modes = + MT6360_OPMODE_LP > + MT6360_OPMODE_ULP>; > +}; > +BUCK2: buck2 { > +regulator-compatible = "BUCK2"; > +regulator-name = "mt6360,buck2"; > +regulator-min-microvolt = <30>; > +regulator-max-microvolt = <130>; > +regulator-allowed-modes = + MT6360_OPMODE_LP > + MT6360_OPMODE_ULP>; > +}; > +ldo6 { > +regulator-compatible = "LDO6"; > +regulator-name = "mt6360,ldo6"; > +regulator-min-microvolt = <50>; > +regulator-max-microvolt = <210>; > +regulator-allowed-modes = + MT6360_OPMODE_LP>; > +}; > +ldo7 { > +regulator-compatible = "LDO7"; > +regulator-name = "mt6360,ldo7"; > +regulator-min-microvolt = <50>; > +regulator-max-microvolt = <210>; > +regulator-allowed-modes = + MT6360_OPMODE_LP>; > +}; > +ldo1 { > +regulator-compatible = "LDO1"; > +regulator-name = "mt6360,ldo1"; > +regulator-min-microvolt = <120>; > +regula
[PATCH v7 03/11] mfd: mt6360: Indicate sub-dev compatible name by using "-"
From: Gene Chen Indicate sub-dev compatible name by using "-". Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 24 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index befee70..692e47b 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -292,18 +292,18 @@ static const struct resource mt6360_ldo_resources[] = { }; static const struct mfd_cell mt6360_devs[] = { - OF_MFD_CELL("mt6360_adc", mt6360_adc_resources, - NULL, 0, 0, "mediatek,mt6360_adc"), - OF_MFD_CELL("mt6360_chg", mt6360_chg_resources, - NULL, 0, 0, "mediatek,mt6360_chg"), - OF_MFD_CELL("mt6360_led", mt6360_led_resources, - NULL, 0, 0, "mediatek,mt6360_led"), - OF_MFD_CELL("mt6360_pmic", mt6360_pmic_resources, - NULL, 0, 0, "mediatek,mt6360_pmic"), - OF_MFD_CELL("mt6360_ldo", mt6360_ldo_resources, - NULL, 0, 0, "mediatek,mt6360_ldo"), - OF_MFD_CELL("mt6360_tcpc", NULL, - NULL, 0, 0, "mediatek,mt6360_tcpc"), + OF_MFD_CELL("mt6360-adc", mt6360_adc_resources, + NULL, 0, 0, "mediatek,mt6360-adc"), + OF_MFD_CELL("mt6360-chg", mt6360_chg_resources, + NULL, 0, 0, "mediatek,mt6360-chg"), + OF_MFD_CELL("mt6360-led", mt6360_led_resources, + NULL, 0, 0, "mediatek,mt6360-led"), + OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, + NULL, 0, 0, "mediatek,mt6360-pmic"), + OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, + NULL, 0, 0, "mediatek,mt6360-ldo"), + OF_MFD_CELL("mt6360-tcpc", NULL, + NULL, 0, 0, "mediatek,mt6360-tcpc"), }; static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { -- 2.7.4
[PATCH v7 04/11] mfd: mt6360: Combine mt6360 pmic/ldo resources into mt6360 regulator resources
From: Gene Chen Combine mt6360 pmic/ldo resources into mt6360 regulator resources to simplify the similar resources object. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 11 +++ 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 692e47b..5119e51 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -265,7 +265,7 @@ static const struct resource mt6360_led_resources[] = { DEFINE_RES_IRQ_NAMED(MT6360_FLED1_STRB_TO_EVT, "fled1_strb_to_evt"), }; -static const struct resource mt6360_pmic_resources[] = { +static const struct resource mt6360_regulator_resources[] = { DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_PGB_EVT, "buck1_pgb_evt"), DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OC_EVT, "buck1_oc_evt"), DEFINE_RES_IRQ_NAMED(MT6360_BUCK1_OV_EVT, "buck1_ov_evt"), @@ -278,9 +278,6 @@ static const struct resource mt6360_pmic_resources[] = { DEFINE_RES_IRQ_NAMED(MT6360_LDO7_OC_EVT, "ldo7_oc_evt"), DEFINE_RES_IRQ_NAMED(MT6360_LDO6_PGB_EVT, "ldo6_pgb_evt"), DEFINE_RES_IRQ_NAMED(MT6360_LDO7_PGB_EVT, "ldo7_pgb_evt"), -}; - -static const struct resource mt6360_ldo_resources[] = { DEFINE_RES_IRQ_NAMED(MT6360_LDO1_OC_EVT, "ldo1_oc_evt"), DEFINE_RES_IRQ_NAMED(MT6360_LDO2_OC_EVT, "ldo2_oc_evt"), DEFINE_RES_IRQ_NAMED(MT6360_LDO3_OC_EVT, "ldo3_oc_evt"), @@ -298,10 +295,8 @@ static const struct mfd_cell mt6360_devs[] = { NULL, 0, 0, "mediatek,mt6360-chg"), OF_MFD_CELL("mt6360-led", mt6360_led_resources, NULL, 0, 0, "mediatek,mt6360-led"), - OF_MFD_CELL("mt6360-pmic", mt6360_pmic_resources, - NULL, 0, 0, "mediatek,mt6360-pmic"), - OF_MFD_CELL("mt6360-ldo", mt6360_ldo_resources, - NULL, 0, 0, "mediatek,mt6360-ldo"), + OF_MFD_CELL("mt6360-regulator", mt6360_regulator_resources, + NULL, 0, 0, "mediatek,mt6360-regulator"), OF_MFD_CELL("mt6360-tcpc", NULL, NULL, 0, 0, "mediatek,mt6360-tcpc"), }; -- 2.7.4
[PATCH v7 06/11] mfd: mt6360: Rename mt6360_pmu by mt6360
From: Gene Chen Rename mt6360_pmu by mt6360, because of including not only PMU part, but also entire MT6360 IC Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 41 - 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 332eb5d..f75122b 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -119,7 +119,7 @@ #define MT6360_LDO6_PGB_EVT126 #define MT6360_LDO7_PGB_EVT127 -static const struct regmap_irq mt6360_pmu_irqs[] = { +static const struct regmap_irq mt6360_irqs[] = { REGMAP_IRQ_REG_LINE(MT6360_CHG_TREG_EVT, 8), REGMAP_IRQ_REG_LINE(MT6360_CHG_AICR_EVT, 8), REGMAP_IRQ_REG_LINE(MT6360_CHG_MIVR_EVT, 8), @@ -216,9 +216,9 @@ static int mt6360_pmu_handle_post_irq(void *irq_drv_data) MT6360_PMU_IRQ_SET, MT6360_IRQ_RETRIG, MT6360_IRQ_RETRIG); } -static struct regmap_irq_chip mt6360_pmu_irq_chip = { - .irqs = mt6360_pmu_irqs, - .num_irqs = ARRAY_SIZE(mt6360_pmu_irqs), +static struct regmap_irq_chip mt6360_irq_chip = { + .irqs = mt6360_irqs, + .num_irqs = ARRAY_SIZE(mt6360_irqs), .num_regs = MT6360_PMU_IRQ_REGNUM, .mask_base = MT6360_PMU_CHG_MASK1, .status_base = MT6360_PMU_CHG_IRQ1, @@ -308,7 +308,7 @@ static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { MT6360_TCPC_SLAVEID, }; -static int mt6360_pmu_probe(struct i2c_client *client) +static int mt6360_probe(struct i2c_client *client) { struct mt6360_ddata *ddata; unsigned int reg_data; @@ -339,10 +339,10 @@ static int mt6360_pmu_probe(struct i2c_client *client) return -ENODEV; } - mt6360_pmu_irq_chip.irq_drv_data = ddata; + mt6360_irq_chip.irq_drv_data = ddata; ret = devm_regmap_add_irq_chip(&client->dev, ddata->regmap, client->irq, IRQF_TRIGGER_FALLING, 0, - &mt6360_pmu_irq_chip, &ddata->irq_data); + &mt6360_irq_chip, &ddata->irq_data); if (ret) { dev_err(&client->dev, "Failed to add Regmap IRQ Chip\n"); return ret; @@ -374,7 +374,7 @@ static int mt6360_pmu_probe(struct i2c_client *client) return 0; } -static int __maybe_unused mt6360_pmu_suspend(struct device *dev) +static int __maybe_unused mt6360_suspend(struct device *dev) { struct i2c_client *i2c = to_i2c_client(dev); @@ -384,7 +384,7 @@ static int __maybe_unused mt6360_pmu_suspend(struct device *dev) return 0; } -static int __maybe_unused mt6360_pmu_resume(struct device *dev) +static int __maybe_unused mt6360_resume(struct device *dev) { struct i2c_client *i2c = to_i2c_client(dev); @@ -395,25 +395,24 @@ static int __maybe_unused mt6360_pmu_resume(struct device *dev) return 0; } -static SIMPLE_DEV_PM_OPS(mt6360_pmu_pm_ops, -mt6360_pmu_suspend, mt6360_pmu_resume); +static SIMPLE_DEV_PM_OPS(mt6360_pm_ops, mt6360_suspend, mt6360_resume); -static const struct of_device_id __maybe_unused mt6360_pmu_of_id[] = { - { .compatible = "mediatek,mt6360_pmu", }, +static const struct of_device_id __maybe_unused mt6360_of_id[] = { + { .compatible = "mediatek,mt6360", }, {}, }; -MODULE_DEVICE_TABLE(of, mt6360_pmu_of_id); +MODULE_DEVICE_TABLE(of, mt6360_of_id); -static struct i2c_driver mt6360_pmu_driver = { +static struct i2c_driver mt6360_driver = { .driver = { - .name = "mt6360_pmu", - .pm = &mt6360_pmu_pm_ops, - .of_match_table = of_match_ptr(mt6360_pmu_of_id), + .name = "mt6360", + .pm = &mt6360_pm_ops, + .of_match_table = of_match_ptr(mt6360_of_id), }, - .probe_new = mt6360_pmu_probe, + .probe_new = mt6360_probe, }; -module_i2c_driver(mt6360_pmu_driver); +module_i2c_driver(mt6360_driver); MODULE_AUTHOR("Gene Chen "); -MODULE_DESCRIPTION("MT6360 PMU I2C Driver"); +MODULE_DESCRIPTION("MT6360 I2C Driver"); MODULE_LICENSE("GPL v2"); -- 2.7.4
[PATCH v7 07/11] mfd: mt6360: Remove handle_post_irq callback function
From: Gene Chen Remove handle_post_irq which is used to retrigger IRQ. Set IRQ level low trigger in dtsi to keep IRQ always be handled. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 17 - include/linux/mfd/mt6360.h | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index f75122b..2356d99 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -208,15 +208,8 @@ static const struct regmap_irq mt6360_irqs[] = { REGMAP_IRQ_REG_LINE(MT6360_LDO7_PGB_EVT, 8), }; -static int mt6360_pmu_handle_post_irq(void *irq_drv_data) -{ - struct mt6360_ddata *ddata = irq_drv_data; - - return regmap_update_bits(ddata->regmap, - MT6360_PMU_IRQ_SET, MT6360_IRQ_RETRIG, MT6360_IRQ_RETRIG); -} - -static struct regmap_irq_chip mt6360_irq_chip = { +static const struct regmap_irq_chip mt6360_irq_chip = { + .name = "mt6360_irqs", .irqs = mt6360_irqs, .num_irqs = ARRAY_SIZE(mt6360_irqs), .num_regs = MT6360_PMU_IRQ_REGNUM, @@ -225,7 +218,6 @@ static struct regmap_irq_chip mt6360_irq_chip = { .ack_base = MT6360_PMU_CHG_IRQ1, .init_ack_masked = true, .use_ack = true, - .handle_post_irq = mt6360_pmu_handle_post_irq, }; static const struct regmap_config mt6360_pmu_regmap_config = { @@ -339,10 +331,9 @@ static int mt6360_probe(struct i2c_client *client) return -ENODEV; } - mt6360_irq_chip.irq_drv_data = ddata; ret = devm_regmap_add_irq_chip(&client->dev, ddata->regmap, client->irq, - IRQF_TRIGGER_FALLING, 0, - &mt6360_irq_chip, &ddata->irq_data); + 0, 0, &mt6360_irq_chip, + &ddata->irq_data); if (ret) { dev_err(&client->dev, "Failed to add Regmap IRQ Chip\n"); return ret; diff --git a/include/linux/mfd/mt6360.h b/include/linux/mfd/mt6360.h index 81bca7c..ef8257d 100644 --- a/include/linux/mfd/mt6360.h +++ b/include/linux/mfd/mt6360.h @@ -230,7 +230,7 @@ struct mt6360_ddata { #define MT6360_PMU_MAXREG MT6360_PMU_LDO_MASK2 /* MT6360_PMU_IRQ_SET */ -#define MT6360_PMU_IRQ_REGNUM (MT6360_PMU_LDO_IRQ2 - MT6360_PMU_CHG_IRQ1 + 1) +#define MT6360_PMU_IRQ_REGNUM 16 #define MT6360_IRQ_RETRIG BIT(2) #define CHIP_VEN_MASK 0xF0 -- 2.7.4
[PATCH v7 09/11] mfd: mt6360: Merge header file into driver and remove unuse register define
From: Gene Chen Merge header file into driver and remove unuse register define Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 48 - include/linux/mfd/mt6360.h | 240 - 2 files changed, 47 insertions(+), 241 deletions(-) delete mode 100644 include/linux/mfd/mt6360.h diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index de002fe..14a9927 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -14,7 +14,53 @@ #include #include -#include +enum { + MT6360_SLAVE_TCPC = 0, + MT6360_SLAVE_PMIC, + MT6360_SLAVE_LDO, + MT6360_SLAVE_PMU, + MT6360_SLAVE_MAX, +}; + +struct mt6360_ddata { + struct i2c_client *i2c[MT6360_SLAVE_MAX]; + struct device *dev; + struct regmap *regmap; + struct regmap_irq_chip_data *irq_data; + unsigned int chip_rev; + u8 crc8_tbl[CRC8_TABLE_SIZE]; +}; + +#define MT6360_TCPC_SLAVEID0x4E +#define MT6360_PMIC_SLAVEID0x1A +#define MT6360_LDO_SLAVEID 0x64 +#define MT6360_PMU_SLAVEID 0x34 + +#define MT6360_REG_TCPCSTART 0x00 +#define MT6360_REG_TCPCEND 0xFF +#define MT6360_REG_PMICSTART 0x100 +#define MT6360_REG_PMICEND 0x13B +#define MT6360_REG_LDOSTART0x200 +#define MT6360_REG_LDOEND 0x21C +#define MT6360_REG_PMUSTART0x300 +#define MT6360_PMU_DEV_INFO0x300 +#define MT6360_PMU_CHG_IRQ10x3D0 +#define MT6360_PMU_CHG_MASK1 0x3F0 +#define MT6360_REG_PMUEND 0x3FF + +#define MT6360_PMU_IRQ_REGNUM 16 + +#define CHIP_VEN_MASK 0xF0 +#define CHIP_VEN_MT63600x50 +#define CHIP_REV_MASK 0x0F + +#define MT6360_ADDRESS_MASK0x3F +#define MT6360_DATA_SIZE_1_BYTE0x00 +#define MT6360_DATA_SIZE_2_BYTES 0x40 +#define MT6360_DATA_SIZE_3_BYTES 0x80 +#define MT6360_DATA_SIZE_4_BYTES 0xC0 + +#define MT6360_CRC8_POLYNOMIAL 0x7 /* reg 0 -> 0 ~ 7 */ #define MT6360_CHG_TREG_EVT4 diff --git a/include/linux/mfd/mt6360.h b/include/linux/mfd/mt6360.h deleted file mode 100644 index ef8257d..000 --- a/include/linux/mfd/mt6360.h +++ /dev/null @@ -1,240 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * Copyright (c) 2020 MediaTek Inc. - */ - -#ifndef __MT6360_H__ -#define __MT6360_H__ - -#include - -enum { - MT6360_SLAVE_PMU = 0, - MT6360_SLAVE_PMIC, - MT6360_SLAVE_LDO, - MT6360_SLAVE_TCPC, - MT6360_SLAVE_MAX, -}; - -#define MT6360_PMU_SLAVEID 0x34 -#define MT6360_PMIC_SLAVEID0x1A -#define MT6360_LDO_SLAVEID 0x64 -#define MT6360_TCPC_SLAVEID0x4E - -struct mt6360_ddata { - struct i2c_client *i2c[MT6360_SLAVE_MAX]; - struct device *dev; - struct regmap *regmap; - struct regmap_irq_chip_data *irq_data; - unsigned int chip_rev; -}; - -/* PMU register defininition */ -#define MT6360_PMU_DEV_INFO0x00 -#define MT6360_PMU_CORE_CTRL1 0x01 -#define MT6360_PMU_RST10x02 -#define MT6360_PMU_CRCEN 0x03 -#define MT6360_PMU_RST_PAS_CODE1 0x04 -#define MT6360_PMU_RST_PAS_CODE2 0x05 -#define MT6360_PMU_CORE_CTRL2 0x06 -#define MT6360_PMU_TM_PAS_CODE10x07 -#define MT6360_PMU_TM_PAS_CODE20x08 -#define MT6360_PMU_TM_PAS_CODE30x09 -#define MT6360_PMU_TM_PAS_CODE40x0A -#define MT6360_PMU_IRQ_IND 0x0B -#define MT6360_PMU_IRQ_MASK0x0C -#define MT6360_PMU_IRQ_SET 0x0D -#define MT6360_PMU_SHDN_CTRL 0x0E -#define MT6360_PMU_TM_INF 0x0F -#define MT6360_PMU_I2C_CTRL0x10 -#define MT6360_PMU_CHG_CTRL1 0x11 -#define MT6360_PMU_CHG_CTRL2 0x12 -#define MT6360_PMU_CHG_CTRL3 0x13 -#define MT6360_PMU_CHG_CTRL4 0x14 -#define MT6360_PMU_CHG_CTRL5 0x15 -#define MT6360_PMU_CHG_CTRL6 0x16 -#define MT6360_PMU_CHG_CTRL7 0x17 -#define MT6360_PMU_CHG_CTRL8 0x18 -#define MT6360_PMU_CHG_CTRL9 0x19 -#define MT6360_PMU_CHG_CTRL10 0x1A -#define MT6360_PMU_CHG_CTRL11 0x1B -#define MT6360_PMU_CHG_CTRL12 0x1C -#define MT6360_PMU_CHG_CTRL13 0x1D -#define MT6360_PMU_CHG_CTRL14 0x1E -#define MT6360_PMU_CHG_CTRL15 0x1F -#define MT6360_PMU_CHG_CTRL16 0x20 -#define MT6360_PMU_CHG_AICC_RESULT 0x21 -#define MT6360_PMU_DEVICE_TYPE 0x22 -#def
[PATCH v7 11/11] mfd: mt6360: Remove MT6360 regulator of_compatible attribute
From: Gene Chen Remove MT6360 regulator of_compatible attribute because MFD device should just instantiate the platform device. Signed-off-by: Gene Chen --- drivers/mfd/mt6360-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 4bcfa7f..3b6490c 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -339,8 +339,7 @@ static const struct mfd_cell mt6360_devs[] = { NULL, 0, 0, "mediatek,mt6360-chg"), OF_MFD_CELL("mt6360-led", mt6360_led_resources, NULL, 0, 0, "mediatek,mt6360-led"), - OF_MFD_CELL("mt6360-regulator", mt6360_regulator_resources, - NULL, 0, 0, "mediatek,mt6360-regulator"), + MFD_CELL_RES("mt6360-regulator", mt6360_regulator_resources), OF_MFD_CELL("mt6360-tcpc", NULL, NULL, 0, 0, "mediatek,mt6360-tcpc"), }; -- 2.7.4
[PATCH v7 0/11] mfd: mt6360: Merge different sub-devices I2C read/write
This patch series merge different sub-device I2C read/write into one Regmap and fix coding style for well-organized. Gene Chen (11) mfd: mt6360: Rearrange include file mfd: mt6360: Remove redundant brackets around raw numbers mfd: mt6360: Indicate sub-dev compatible name by using mfd: mt6360: Combine mt6360 pmic/ldo resources into mt6360 mfd: mt6360: Rename mt6360_pmu_data by mt6360_ddata mfd: mt6360: Rename mt6360_pmu by mt6360 mfd: mt6360: Remove handle_post_irq callback function mfd: mt6360: Fix flow which is used to check ic exist mfd: mt6360: Merge header file into driver and remove unuse register define mfd: mt6360: Merge different sub-devices I2C read/write mfd: mt6360: Remove MT6360 regulator of_compatible b/drivers/mfd/Kconfig |1 b/drivers/mfd/mt6360-core.c | 554 +--- include/linux/mfd/mt6360.h | 240 --- 3 files changed, 376 insertions(+), 419 deletions(-) changelogs between v2 & v3 - Replace mt6360_data to mt6360_ddata - Split I2C read/write to regmap driver changelogs between v3 & v4 - Merge back mt6360 regmap driver to MFD driver changelogs between v4 & v5 - use devm_regmap_init - define crc calculation magic number changelogs between v5 & v6 - Remove unrelated change - Remove regulator device of_compatible changelogs between v6 & v7 - Replace OF_MFD_CELL by MFD_CELL_RES
[PATCH v7 05/11] mfd: mt6360: Rename mt6360_pmu_data by mt6360_ddata
From: Gene Chen Rename mt6360_pmu_data by mt6360_ddata because of including not only PMU part, but also entire MT6360 IC. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 44 ++-- include/linux/mfd/mt6360.h | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 5119e51..332eb5d 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -210,9 +210,9 @@ static const struct regmap_irq mt6360_pmu_irqs[] = { static int mt6360_pmu_handle_post_irq(void *irq_drv_data) { - struct mt6360_pmu_data *mpd = irq_drv_data; + struct mt6360_ddata *ddata = irq_drv_data; - return regmap_update_bits(mpd->regmap, + return regmap_update_bits(ddata->regmap, MT6360_PMU_IRQ_SET, MT6360_IRQ_RETRIG, MT6360_IRQ_RETRIG); } @@ -310,61 +310,61 @@ static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { static int mt6360_pmu_probe(struct i2c_client *client) { - struct mt6360_pmu_data *mpd; + struct mt6360_ddata *ddata; unsigned int reg_data; int i, ret; - mpd = devm_kzalloc(&client->dev, sizeof(*mpd), GFP_KERNEL); - if (!mpd) + ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL); + if (!ddata) return -ENOMEM; - mpd->dev = &client->dev; - i2c_set_clientdata(client, mpd); + ddata->dev = &client->dev; + i2c_set_clientdata(client, ddata); - mpd->regmap = devm_regmap_init_i2c(client, &mt6360_pmu_regmap_config); - if (IS_ERR(mpd->regmap)) { + ddata->regmap = devm_regmap_init_i2c(client, &mt6360_pmu_regmap_config); + if (IS_ERR(ddata->regmap)) { dev_err(&client->dev, "Failed to register regmap\n"); - return PTR_ERR(mpd->regmap); + return PTR_ERR(ddata->regmap); } - ret = regmap_read(mpd->regmap, MT6360_PMU_DEV_INFO, ®_data); + ret = regmap_read(ddata->regmap, MT6360_PMU_DEV_INFO, ®_data); if (ret) { dev_err(&client->dev, "Device not found\n"); return ret; } - mpd->chip_rev = reg_data & CHIP_REV_MASK; - if (mpd->chip_rev != CHIP_VEN_MT6360) { + ddata->chip_rev = reg_data & CHIP_REV_MASK; + if (ddata->chip_rev != CHIP_VEN_MT6360) { dev_err(&client->dev, "Device not supported\n"); return -ENODEV; } - mt6360_pmu_irq_chip.irq_drv_data = mpd; - ret = devm_regmap_add_irq_chip(&client->dev, mpd->regmap, client->irq, + mt6360_pmu_irq_chip.irq_drv_data = ddata; + ret = devm_regmap_add_irq_chip(&client->dev, ddata->regmap, client->irq, IRQF_TRIGGER_FALLING, 0, - &mt6360_pmu_irq_chip, &mpd->irq_data); + &mt6360_pmu_irq_chip, &ddata->irq_data); if (ret) { dev_err(&client->dev, "Failed to add Regmap IRQ Chip\n"); return ret; } - mpd->i2c[0] = client; + ddata->i2c[0] = client; for (i = 1; i < MT6360_SLAVE_MAX; i++) { - mpd->i2c[i] = devm_i2c_new_dummy_device(&client->dev, + ddata->i2c[i] = devm_i2c_new_dummy_device(&client->dev, client->adapter, mt6360_slave_addr[i]); - if (IS_ERR(mpd->i2c[i])) { + if (IS_ERR(ddata->i2c[i])) { dev_err(&client->dev, "Failed to get new dummy I2C device for address 0x%x", mt6360_slave_addr[i]); - return PTR_ERR(mpd->i2c[i]); + return PTR_ERR(ddata->i2c[i]); } - i2c_set_clientdata(mpd->i2c[i], mpd); + i2c_set_clientdata(ddata->i2c[i], ddata); } ret = devm_mfd_add_devices(&client->dev, PLATFORM_DEVID_AUTO, mt6360_devs, ARRAY_SIZE(mt6360_devs), NULL, - 0, regmap_irq_get_domain(mpd->irq_data)); + 0, regmap_irq_get_domain(ddata->irq_data)); if (ret) { dev_err(&client->dev, "Failed to register subordinate devices\n"); diff --git a/include/linux/mfd/mt6360.h b/include/linux/mfd/mt6360.h index 72edf13..81bca7c 100644 --- a/include/linux/mfd/mt6360.h +++ b/include/linux/mfd/mt6360.h @@ -21,7 +21,7 @@ enum { #define MT6360_LDO_SLAVEID 0x64 #define MT6360_TCPC_SLAVEID0x4E -struct mt6360_pmu_data { +struct mt6360_ddata { struct i2c_client *i2c[MT6360_SLAVE_MAX]; struct device *dev; struct regmap *regmap; -- 2.7.4
[PATCH v7 10/11] mfd: mt6360: Merge different sub-devices I2C read/write
From: Gene Chen Merge different sub-devices I2C read/write functions into one Regmap, because PMIC and LDO part need CRC bits for access protection. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/Kconfig | 1 + drivers/mfd/mt6360-core.c | 203 -- 2 files changed, 181 insertions(+), 23 deletions(-) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 33df083..1dfe446 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -913,6 +913,7 @@ config MFD_MT6360 select MFD_CORE select REGMAP_I2C select REGMAP_IRQ + select CRC8 depends on I2C help Say Y here to enable MT6360 PMU/PMIC/LDO functional support. diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 14a9927..4bcfa7f 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -62,6 +62,18 @@ struct mt6360_ddata { #define MT6360_CRC8_POLYNOMIAL 0x7 +#define MT6360_CRC_I2C_ADDR_SIZE 1 +#define MT6360_CRC_REG_ADDR_SIZE 1 +/* prealloca read size = i2c device addr + i2c reg addr + val ... + crc8 */ +#define MT6360_ALLOC_READ_SIZE(_size) (_size + 3) +/* prealloca write size = i2c device addr + i2c reg addr + val ... + crc8 + dummy byte */ +#define MT6360_ALLOC_WRITE_SIZE(_size) (_size + 4) +#define MT6360_CRC_PREDATA_OFFSET (MT6360_CRC_I2C_ADDR_SIZE + MT6360_CRC_REG_ADDR_SIZE) +#define MT6360_CRC_CRC8_SIZE 1 +#define MT6360_CRC_DUMMY_BYTE_SIZE 1 +#define MT6360_REGMAP_REG_BYTE_SIZE2 +#define I2C_ADDR_XLATE_8BIT(_addr, _rw)(((_addr & 0x7F) << 1) + _rw) + /* reg 0 -> 0 ~ 7 */ #define MT6360_CHG_TREG_EVT4 #define MT6360_CHG_AICR_EVT5 @@ -266,12 +278,6 @@ static const struct regmap_irq_chip mt6360_irq_chip = { .use_ack = true, }; -static const struct regmap_config mt6360_pmu_regmap_config = { - .reg_bits = 8, - .val_bits = 8, - .max_register = MT6360_PMU_MAXREG, -}; - static const struct resource mt6360_adc_resources[] = { DEFINE_RES_IRQ_NAMED(MT6360_ADC_DONEI, "adc_donei"), }; @@ -359,10 +365,160 @@ static int mt6360_check_vendor_info(struct mt6360_ddata *ddata) } static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { - MT6360_PMU_SLAVEID, + MT6360_TCPC_SLAVEID, MT6360_PMIC_SLAVEID, MT6360_LDO_SLAVEID, - MT6360_TCPC_SLAVEID, + MT6360_PMU_SLAVEID, +}; + +static int mt6360_xlate_pmicldo_addr(u8 *addr, int rw_size) +{ + /* Address is already in encoded [5:0] */ + *addr &= MT6360_ADDRESS_MASK; + + switch (rw_size) { + case 1: + *addr |= MT6360_DATA_SIZE_1_BYTE; + break; + case 2: + *addr |= MT6360_DATA_SIZE_2_BYTES; + break; + case 3: + *addr |= MT6360_DATA_SIZE_3_BYTES; + break; + case 4: + *addr |= MT6360_DATA_SIZE_4_BYTES; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int mt6360_regmap_read(void *context, const void *reg, size_t reg_size, + void *val, size_t val_size) +{ + struct mt6360_ddata *ddata = context; + u8 bank = *(u8 *)reg; + u8 reg_addr = *(u8 *)(reg + 1); + struct i2c_client *i2c = ddata->i2c[bank]; + bool crc_needed = false; + u8 *buf; + int buf_len = MT6360_ALLOC_READ_SIZE(val_size); + int read_size = val_size; + u8 crc; + int ret; + + if (bank == MT6360_SLAVE_PMIC || bank == MT6360_SLAVE_LDO) { + crc_needed = true; + ret = mt6360_xlate_pmicldo_addr(®_addr, val_size); + if (ret < 0) + return ret; + read_size += MT6360_CRC_CRC8_SIZE; + } + + buf = kzalloc(buf_len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + buf[0] = I2C_ADDR_XLATE_8BIT(i2c->addr, I2C_SMBUS_READ); + buf[1] = reg_addr; + + ret = i2c_smbus_read_i2c_block_data(i2c, reg_addr, read_size, + buf + MT6360_CRC_PREDATA_OFFSET); + if (ret < 0) + goto out; + else if (ret != read_size) { + ret = -EIO; + goto out; + } + + if (crc_needed) { + crc = crc8(ddata->crc8_tbl, buf, val_size + MT6360_CRC_PREDATA_OFFSET, 0); + if (crc != buf[val_size + MT6360_CRC_PREDATA_OFFSET]) { + ret = -EIO; + goto out; + } + } + + memcpy(val, buf + MT6360_CRC_PREDATA_OFFSET, val_size); +out: + kfree(buf); + return (ret < 0) ? ret : 0; +} + +static int mt6360_regmap_write(void *context, const void *val, size_t val_size) +{ + struct mt6360_ddata *ddata = context; +
[PATCH v7 08/11] mfd: mt6360: Fix flow which is used to check ic exist
From: Gene Chen Fix flow which is used to check ic exist. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 32 +--- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index 2356d99..de002fe 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -293,6 +293,25 @@ static const struct mfd_cell mt6360_devs[] = { NULL, 0, 0, "mediatek,mt6360-tcpc"), }; +static int mt6360_check_vendor_info(struct mt6360_ddata *ddata) +{ + u32 info; + int ret; + + ret = regmap_read(ddata->regmap, MT6360_PMU_DEV_INFO, &info); + if (ret < 0) + return ret; + + if ((info & CHIP_VEN_MASK) != CHIP_VEN_MT6360) { + dev_err(ddata->dev, "Device not supported\n"); + return -ENODEV; + } + + ddata->chip_rev = info & CHIP_REV_MASK; + + return 0; +} + static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { MT6360_PMU_SLAVEID, MT6360_PMIC_SLAVEID, @@ -303,7 +322,6 @@ static const unsigned short mt6360_slave_addr[MT6360_SLAVE_MAX] = { static int mt6360_probe(struct i2c_client *client) { struct mt6360_ddata *ddata; - unsigned int reg_data; int i, ret; ddata = devm_kzalloc(&client->dev, sizeof(*ddata), GFP_KERNEL); @@ -319,17 +337,9 @@ static int mt6360_probe(struct i2c_client *client) return PTR_ERR(ddata->regmap); } - ret = regmap_read(ddata->regmap, MT6360_PMU_DEV_INFO, ®_data); - if (ret) { - dev_err(&client->dev, "Device not found\n"); + ret = mt6360_check_vendor_info(ddata); + if (ret) return ret; - } - - ddata->chip_rev = reg_data & CHIP_REV_MASK; - if (ddata->chip_rev != CHIP_VEN_MT6360) { - dev_err(&client->dev, "Device not supported\n"); - return -ENODEV; - } ret = devm_regmap_add_irq_chip(&client->dev, ddata->regmap, client->irq, 0, 0, &mt6360_irq_chip, -- 2.7.4
[PATCH v7 02/11] mfd: mt6360: Remove redundant brackets around raw numbers
From: Gene Chen Remove redundant brackets around raw numbers. Signed-off-by: Gene Chen Acked-for-MFD-by: Lee Jones --- drivers/mfd/mt6360-core.c | 172 +-- include/linux/mfd/mt6360.h | 410 ++--- 2 files changed, 291 insertions(+), 291 deletions(-) diff --git a/drivers/mfd/mt6360-core.c b/drivers/mfd/mt6360-core.c index c7a955f..befee70 100644 --- a/drivers/mfd/mt6360-core.c +++ b/drivers/mfd/mt6360-core.c @@ -17,107 +17,107 @@ #include /* reg 0 -> 0 ~ 7 */ -#define MT6360_CHG_TREG_EVT(4) -#define MT6360_CHG_AICR_EVT(5) -#define MT6360_CHG_MIVR_EVT(6) -#define MT6360_PWR_RDY_EVT (7) +#define MT6360_CHG_TREG_EVT4 +#define MT6360_CHG_AICR_EVT5 +#define MT6360_CHG_MIVR_EVT6 +#define MT6360_PWR_RDY_EVT 7 /* REG 1 -> 8 ~ 15 */ -#define MT6360_CHG_BATSYSUV_EVT(9) -#define MT6360_FLED_CHG_VINOVP_EVT (11) -#define MT6360_CHG_VSYSUV_EVT (12) -#define MT6360_CHG_VSYSOV_EVT (13) -#define MT6360_CHG_VBATOV_EVT (14) -#define MT6360_CHG_VBUSOV_EVT (15) +#define MT6360_CHG_BATSYSUV_EVT9 +#define MT6360_FLED_CHG_VINOVP_EVT 11 +#define MT6360_CHG_VSYSUV_EVT 12 +#define MT6360_CHG_VSYSOV_EVT 13 +#define MT6360_CHG_VBATOV_EVT 14 +#define MT6360_CHG_VBUSOV_EVT 15 /* REG 2 -> 16 ~ 23 */ /* REG 3 -> 24 ~ 31 */ -#define MT6360_WD_PMU_DET (25) -#define MT6360_WD_PMU_DONE (26) -#define MT6360_CHG_TMRI(27) -#define MT6360_CHG_ADPBADI (29) -#define MT6360_CHG_RVPI(30) -#define MT6360_OTPI(31) +#define MT6360_WD_PMU_DET 25 +#define MT6360_WD_PMU_DONE 26 +#define MT6360_CHG_TMRI27 +#define MT6360_CHG_ADPBADI 29 +#define MT6360_CHG_RVPI30 +#define MT6360_OTPI31 /* REG 4 -> 32 ~ 39 */ -#define MT6360_CHG_AICCMEASL (32) -#define MT6360_CHGDET_DONEI(34) -#define MT6360_WDTMRI (35) -#define MT6360_SSFINISHI (36) -#define MT6360_CHG_RECHGI (37) -#define MT6360_CHG_TERMI (38) -#define MT6360_CHG_IEOCI (39) +#define MT6360_CHG_AICCMEASL 32 +#define MT6360_CHGDET_DONEI34 +#define MT6360_WDTMRI 35 +#define MT6360_SSFINISHI 36 +#define MT6360_CHG_RECHGI 37 +#define MT6360_CHG_TERMI 38 +#define MT6360_CHG_IEOCI 39 /* REG 5 -> 40 ~ 47 */ -#define MT6360_PUMPX_DONEI (40) -#define MT6360_BAT_OVP_ADC_EVT (41) -#define MT6360_TYPEC_OTP_EVT (42) -#define MT6360_ADC_WAKEUP_EVT (43) -#define MT6360_ADC_DONEI (44) -#define MT6360_BST_BATUVI (45) -#define MT6360_BST_VBUSOVI (46) -#define MT6360_BST_OLPI(47) +#define MT6360_PUMPX_DONEI 40 +#define MT6360_BAT_OVP_ADC_EVT 41 +#define MT6360_TYPEC_OTP_EVT 42 +#define MT6360_ADC_WAKEUP_EVT 43 +#define MT6360_ADC_DONEI 44 +#define MT6360_BST_BATUVI 45 +#define MT6360_BST_VBUSOVI 46 +#define MT6360_BST_OLPI47 /* REG 6 -> 48 ~ 55 */ -#define MT6360_ATTACH_I(48) -#define MT6360_DETACH_I(49) -#define MT6360_QC30_STPDONE(51) -#define MT6360_QC_VBUSDET_DONE (52) -#define MT6360_HVDCP_DET (53) -#define MT6360_CHGDETI (54) -#define MT6360_DCDTI (55) +#define MT6360_ATTACH_I48 +#define MT6360_DETACH_I49 +#define MT6360_QC30_STPDONE51 +#define MT6360_QC_VBUSDET_DONE 52 +#define MT6360_HVDCP_DET 53 +#define MT6360_CHGDETI 54 +#define MT6360_DCDTI 55 /* REG 7 -> 56 ~ 63 */ -#define MT6360_FOD_DONE_EVT(56) -#define MT6360_FOD_OV_EVT (57) -#define MT6360_CHRDET_UVP_EVT (58) -#define MT6360_CHRDET_OVP_EVT (59) -#define MT6360_CHRDET_EXT_EVT (60) -#define MT6360_FOD_LR_EVT (61) -#define MT6360_FOD_HR_EVT (62) -#define MT6360_FOD_DISCHG_FAIL_EVT (63) +#define MT6360_FOD_DONE_EVT56 +#define MT6360_FOD_OV_EVT 57 +#define MT6360_CHRDET_UVP_EVT 58 +#define MT6360_CHRDET_OVP_EVT 59 +#define MT6360_CHRDET_EXT_EVT 60 +#define MT6360_FOD_LR_EVT 61 +#define MT6360_FOD_HR_EVT 62 +#define MT6360_FOD_DISCHG_FAIL_EVT 63 /* REG 8 -> 64 ~ 71 */ -#define MT6360_USBID_EVT (64) -#define MT6360_APWDTRST_EVT(65) -#define MT6360_