power: supply: mt6360_charger: add MT6360 charger support
Subsystems (5)
v5 cover power: supply: mt6360_charger: add MT6360 charger support
This patch series add MT6360 Charger support contains driver and binding document
Gene Chen (3)
lib: add linear range get selector within
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 | 11 drivers/power/supply/Makefile | 1 drivers/power/supply/mt6360_charger.c | 856 ++++++++++ include/linux/linear_range.h | 2 lib/linear_ranges.c | 31 6 files changed, 949 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
changelogs between v4 & v5
- add linear range selector mapping
- use linear range to map charger setting
PATCH v5 1/3 lib: add linear range get selector within
From: Gene Chen <[email protected]>
Add linear range get selector within for choose closest selector between minimum and maximum selector.
--- include/linux/linear_range.h | 2 ++ lib/linear_ranges.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
include/linux/linear_range.h +2 -0
@@ -41,6 +41,8 @@ int linear_range_get_selector_low(const struct linear_range *r,int linear_range_get_selector_high (const struct linear_range *r,unsigned int val,unsigned int *selector,bool *found); +void linear_range_get_selector_within (const struct linear_range *r, +unsigned int val,unsigned int *selector);int linear_range_get_selector_low_array (const struct linear_range *r,int ranges,unsigned int val,unsigned int *selector,bool *found);
lib/linear_ranges.c +31 -0
@@ -241,5 +241,36 @@ int linear_range_get_selector_high(const struct linear_range *r, }EXPORT_SYMBOL_GPL (linear_range_get_selector_high); +/** +* linear_range_get_selector_within - return linear range selector for value +* @r: pointer to linear range where selector is looked from +* @val: value for which the selector is searched +* @selector: address where found selector value is updated +* +* Return selector for which range value is closest match for given +* input value. Value is matching if it is equal or lower than given +* value. But return maximum selector if given value is higher than +* maximum value. +*/ +void linear_range_get_selector_within (const struct linear_range *r, +unsigned int val,unsigned int *selector) +{ +if (r->min > val) { + *selector = r->min_sel; +return ; + } + +if (linear_range_get_max_value (r) < val) { + *selector = r->max_sel; +return ; + } + +if (r->step ==0 ) + *selector = r->min_sel; +else + *selector = (val - r->min) / r->step + r->min_sel; +} +EXPORT_SYMBOL_GPL (linear_range_get_selector_within); +MODULE_DESCRIPTION ("linear-ranges helper" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.25.1
Re: [PATCH v5 1/3] lib: add linear range get selector within
Quoted 54 lines · Gene Chen
From: Gene Chen <[email protected]>
Add linear range get selector within for choose closest selector between minimum and maximum selector.
Signed-off-by Gene Chen <[email protected]>--- include/linux/linear_range.h | 2 ++ lib/linear_ranges.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)include/linux/linear_range.h +2
-0@@ -41,6 +41,8 @@ int linear_range_get_selector_low(const structlinear_range *r, int linear_range_get_selector_high(const struct linear_range *r,unsigned int val,unsigned int *selector,bool *found); +void linear_range_get_selector_within (const struct linear_range *r, +unsigned int val,unsigned int *selector);int linear_range_get_selector_low_array(const struct
linear_range
*r,include/linux/linear_range.h +0
-0int ranges, unsigned int val, unsigned int *selector, bool*found);
lib/linear_ranges.c +2
-0@@ -241,5 +241,36 @@ int linear_range_get_selector_high(const structlinear_range *r, }EXPORT_SYMBOL_GPL (linear_range_get_selector_high ); +/** +* linear_range_get_selector_within - return linear range selector for value
+ * @r: pointer to linear range where selector is
looked from
+ * @val: value for which the selector is searched
+ * @selector: address where found selector value is updated
+ *
+ * Return selector for which range value is closest match for given
+ * input value. Value is matching if it is equal or lower than given
+ * value. But return maximum selector if given value is higher than
+ * maximum value.
+ */lib/linear_ranges.c +2
-0+void linear_range_get_selector_within (const struct linear_range *r, + unsigned int val, unsigned int
Quoted 1 line
*selector)
I like the naming! The "within" sounds good to me :)
It slightly bothers my "style eye" to see this not returning a value (void) - but still returning the value via parameter (selector). It may be slightly more complicated to read when used.
Please consider for first time reading code like:
unsigned int do_something(const struct linear_range *r, unsigned int val, int *myvalue)
{
int ret;
...
linear_range_get_selector_within(r, val, myvalue);
...
return ret;
}to reading code like:
unsigned int do_something(const struct linear_range *r, unsigned int val, int *myvalue)
{
int ret;
...
*myvalue = linear_range_get_selector_within(r, val);
...
return ret;
}For me reading the latter shows better where the myvalue is really set.
OTOH, Your suggestion is consistent with the other functions so I am not asking for a change if this is Ok with others :) Thanks a lot!
Quoted 20 lines
lib/linear_ranges.c +18
-0+{ +if (r->min > val) { + *selector = r->min_sel; +return ; + } + +if (linear_range_get_max_value (r) < val) { + *selector = r->max_sel; +return ; + } + +if (r->step ==0 ) + *selector = r->min_sel; +else + *selector = (val - r->min) / r->step + r->min_sel; +} +EXPORT_SYMBOL_GPL (linear_range_get_selector_within); +MODULE_DESCRIPTION ("linear-ranges helper" );MODULE_LICENSE ("GPL" );
PATCH v5 2/3 dt-bindings: power: Add bindings document for Charger support on MT6360 PMIC
In reply to Gene ChenFrom: Gene Chen <[email protected]>
Add bindings document for Charger support on MT6360 PMIC
--- .../bindings/power/supply/mt6360_charger.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml
Documentation/devicetree/bindings/power/supply/mt6360_charger.yaml new file +48 -0
@@ -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 <[email protected]> + +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: [ 5500000, 6500000, 11000000, 14500000 ] + + + 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 = <14500000>; + + 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>; + }; + }; +...
Signature · 1 line
2.25.1
PATCH v5 3/3 power: supply: mt6360_charger: add MT6360 charger support
In reply to Gene ChenFrom: Gene Chen <[email protected]>
Add basic support for the battery charger for MT6360 PMIC
--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6360_charger.c | 856 ++++++++++++++++++++++++++ 3 files changed, 868 insertions(+) create mode 100644 drivers/power/supply/mt6360_charger.c
drivers/power/supply/Kconfig +11 -0
@@ -577,6 +577,17 @@ 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 + select LINEAR_RANGES + 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
drivers/power/supply/Makefile +1 -0
@@ -78,6 +78,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
drivers/power/supply/mt6360_charger.c new file +856 -0
856 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 159 lines · Gene Chen
From: Gene Chen <[email protected]>
Add basic support for the battery charger for MT6360 PMIC
Signed-off-by Gene Chen <[email protected]>--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6360_charger.c | 856 ++++++++++++++++++++++++++ 3 files changed, 868 insertions(+) create mode 100644 drivers/power/supply/mt6360_charger.cdrivers/power/supply/Kconfig +0
-0@@ -577,6 +577,17 @@ config CHARGER_MP2629 Battery charger. This driver provides Battery charger powermanagement
drivers/power/supply/Kconfig +11
-0functions on the systems. +config CHARGER_MT6360 + tristate "Mediatek MT6360 Charger Driver" + depends on MFD_MT6360 + depends on REGULATOR + select LINEAR_RANGES + 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_TESTdrivers/power/supply/Makefile +0
-0@@ -78,6 +78,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.odrivers/power/supply/Makefile +1
-0+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.odrivers/power/supply/mt6360_charger.c new file +90
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/linear_range.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/property.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> + +#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_STAT 0x34A +#define MT6360_PMU_CHG_CTRL19 0x361 +#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_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_MASK BIT(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) + +enum { +MT6360_RANGE_VMIVR , +MT6360_RANGE_ICHG , +MT6360_RANGE_VOREG , +MT6360_RANGE_AICR , +MT6360_RANGE_IPREC , +MT6360_RANGE_IEOC , +MT6360_RANGE_MAX , +}; + +#define MT6360_LINEAR_RANGE (idx, _min, _min_sel, _max_sel, _step)\
drivers/power/supply/mt6360_charger.c new file +2
-0+ [idx] = { \ + .min = _min,\
drivers/power/supply/mt6360_charger.c new file +1
-0+ .min_sel = _min_sel,\
drivers/power/supply/mt6360_charger.c new file +1
-0+ .max_sel = _max_sel,\
drivers/power/supply/mt6360_charger.c new file +1
-0+ .step = _step,\
drivers/power/supply/mt6360_charger.c
Quoted 1 line
drivers/power/supply/mt6360_charger.c new file +1
-0+ }
Do you think REGULATOR_LINEAR_RANGE() would fit this? Or is the naming a problem there? (Just a minor thing, no need to re-spin for this)
//snip
Quoted 6 lines
drivers/power/supply/mt6360_charger.c new file +6
-0+static int mt6360_charger_probe (struct platform_device *pdev) +{ +struct mt6360_chg_info *mci; +struct power_supply_config charger_cfg = {}; +struct regulator_config config = { }; +int ret;
drivers/power/supply/mt6360_charger.c line 781
Quoted 10 lines
drivers/power/supply/mt6360_charger.c new file +10
-0+ + mci =devm_kzalloc (&pdev->dev,sizeof (*mci),GFP_KERNEL ); +if (!mci) +return -ENOMEM ; + + mci->dev = &pdev->dev; + mci->vinovp =6500000 ; +mutex_init (&mci->chgdet_lock); +platform_set_drvdata (pdev, mci); +INIT_WORK (&mci->chrdet_work, &mt6360_chrdet_work);
//snip
drivers/power/supply/mt6360_charger.c line 829
Quoted 9 lines
drivers/power/supply/mt6360_charger.c new file +9
-0+ +static int mt6360_charger_remove (struct platform_device *pdev) +{ +struct mt6360_chg_info *mci =platform_get_drvdata (pdev); + +cancel_work_sync (&mci->chrdet_work); + +return 0 ; +}
Just as a note, devm_work_autocancel() should hopefully be included at next cycle. Then you might be able to drop the .remove().
FWIW:
Best Regards
Matti Vaittinen
is is
Matti Vaittinen <[email protected]> 於 2021年5月28日 週五 下午5:47寫道:
Quoted 158 lines · Gene Chen
Quoted 155 lines
From: Gene Chen <[email protected]>
Add basic support for the battery charger for MT6360 PMIC
Signed-off-by Gene Chen <[email protected]>--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6360_charger.c | 856 ++++++++++++++++++++++++++ 3 files changed, 868 insertions(+) create mode 100644 drivers/power/supply/mt6360_charger.cdrivers/power/supply/Kconfig +0
-0@@ -577,6 +577,17 @@ config CHARGER_MP2629 Battery charger. This driver provides Battery charger powermanagement
functions on the systems.drivers/power/supply/Kconfig +11
-0+config CHARGER_MT6360 + tristate "Mediatek MT6360 Charger Driver" + depends on MFD_MT6360 + depends on REGULATOR + select LINEAR_RANGES + 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_TESTdrivers/power/supply/Makefile +0
-0@@ -78,6 +78,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.odrivers/power/supply/Makefile +1
-0+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.odrivers/power/supply/mt6360_charger.c new file +90
-0@@ -0,0 +1,856 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2021 MediaTek Inc. +*/ + +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/linear_range.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/property.h> +#include <linux/regmap.h> +#include <linux/regulator/driver.h> + +#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_STAT 0x34A +#define MT6360_PMU_CHG_CTRL19 0x361 +#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_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_MASK BIT(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) + +enum { +MT6360_RANGE_VMIVR , +MT6360_RANGE_ICHG , +MT6360_RANGE_VOREG , +MT6360_RANGE_AICR , +MT6360_RANGE_IPREC , +MT6360_RANGE_IEOC , +MT6360_RANGE_MAX , +}; + +#define MT6360_LINEAR_RANGE (idx, _min, _min_sel, _max_sel, _step)\
drivers/power/supply/mt6360_charger.c new file +2
-0+ [idx] = { \ + .min = _min,\
+ .min_sel =_min_sel,
\
+ .max_sel =_max_sel,
Quoted 9 lines
Quoted 5 lines
\
+ .step =_step,
\
+ }Do you think
REGULATOR_LINEAR_RANGE()would fit this? Or is the naming a problem there? (Just a minor thing, no need to re-spin for this)
Yes, it is fit for this but REGULATOR_LINEAR_RANGE is used for regulator which is defined in regulator/driver.h.
I think it's better to defined ours and add idx for easy to read. Is it better to re-use REGULATOR_LINEAR_RANGE?
Quoted 21 lines
//snip
Quoted 6 lines
drivers/power/supply/mt6360_charger.c new file +6
-0+static int mt6360_charger_probe (struct platform_device *pdev) +{ +struct mt6360_chg_info *mci; +struct power_supply_config charger_cfg = {}; +struct regulator_config config = { }; +int ret;drivers/power/supply/mt6360_charger.c line 781
Quoted 10 lines
drivers/power/supply/mt6360_charger.c new file +10
-0+ + mci =devm_kzalloc (&pdev->dev,sizeof (*mci),GFP_KERNEL ); +if (!mci) +return -ENOMEM ; + + mci->dev = &pdev->dev; + mci->vinovp =6500000 ; +mutex_init (&mci->chgdet_lock); +platform_set_drvdata (pdev, mci); +INIT_WORK (&mci->chrdet_work, &mt6360_chrdet_work);//snip
Quoted 13 lines
drivers/power/supply/mt6360_charger.c line 829
Quoted 9 lines
drivers/power/supply/mt6360_charger.c new file +9
-0+ +static int mt6360_charger_remove (struct platform_device *pdev) +{ +struct mt6360_chg_info *mci =platform_get_drvdata (pdev); + +cancel_work_sync (&mci->chrdet_work); + +return 0 ; +}Just as a note,
devm_work_autocancel()should hopefully be included at next cycle. Then you might be able to drop the .remove().
ACK, I will replace it, thanks.
Quoted 6 lines
FWIW:
Reviewed-by Matti Vaittinen <[email protected]>Best Regards
Matti Vaittinen
Hi,
Quoted 12 lines · Gene Chen
Quoted 11 lines
drivers/power/supply/mt6360_charger.c line 829
Quoted 8 lines
drivers/power/supply/mt6360_charger.c new file +8
-0+static int mt6360_charger_remove (struct platform_device *pdev) +{ +struct mt6360_chg_info *mci =platform_get_drvdata (pdev); + +cancel_work_sync (&mci->chrdet_work); + +return 0 ; +}Just as a note,
devm_work_autocancel()should hopefully be included at next cycle. Then you might be able to drop the .remove().
Quoted 4 lines
ACK, I will replace it, thanks.
Quoted 2 lines
FWIW:
Reviewed-by Matti Vaittinen <[email protected]>
Did I miss a newer revision?
-- Sebastian
Quoted 7 lines · Gene Chen
drivers/power/supply/Kconfig +0
-0@@ -577,6 +577,17 @@ config CHARGER_MP2629 Battery charger. This driver provides Battery charger power management functions on the systems.
drivers/power/supply/Kconfig config CHARGER_MP2629 · line 588
Quoted 10 lines
drivers/power/supply/Kconfig +9
-0+config CHARGER_MT6360 + tristate "Mediatek MT6360 Charger Driver" + depends on MFD_MT6360 + depends on REGULATOR + select LINEAR_RANGES + help + Say Y here to enable MT6360 Charger Part. + The device supports High-Accuracy Voltage/Current Regulation, + Average Input Current Regulation, Battery Tempature Sensing,
Temperature
drivers/power/supply/Kconfig config CHARGER_MP2629 · line 589
Quoted 1 line
drivers/power/supply/Kconfig +1
-0+ Over-Temperature Protection, DPDM Detection for BC1.2
BC1.2.
thanks.
Signature · 1 line
~Randy