Skip to contentSkip to conversation

dt-bindings: power: supply: Add MediaTek MT6370 Charger

PATCH Applied ChiaEn Wu 7 participants 20 messages Aug 30, 2022 – Sep 23, 2022 1 message not in the archive

Subsystems (9)

v9 of 15 Applied Latest is v15 →

lore
Share & tools
lore

ChiaEn Wu

author
#0 lore raw

PATCH v9 1/10 dt-bindings: power: supply: Add MediaTek MT6370 Charger

From: ChiaEn Wu <[email protected]>

Add MediaTek MT6370 Charger binding documentation.

---
 .../power/supply/mediatek,mt6370-charger.yaml      | 88 ++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/power/supply/mediatek,mt6370-charger.yaml
Documentation/devicetree/bindings/power/supply/mediatek,mt6370-charger.yaml new file +88 -0
new file mode 100644
index 0000000..bd09a0a
@@ -0,0 +1,88 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/power/supply/mediatek,mt6370-charger.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT6370 Battery Charger
+
+maintainers:
+  - ChiaEn Wu <[email protected]>
+
+description: |
+  This module is part of the MT6370 MFD device.
+  Provides Battery Charger, Boost for OTG devices and BC1.2 detection.
+
+properties:
+  compatible:
+    const: mediatek,mt6370-charger
+
+  interrupts:
+    description: |
+      Specify what irqs are needed to be handled by MT6370 Charger driver. IRQ
+      "MT6370_IRQ_CHG_MIVR", "MT6370_IRQ_ATTACH" and "MT6370_IRQ_OVPCTRL_UVP_D"
+      are required.
+    items:
+      - description: BC1.2 done irq
+      - description: usb plug in irq
+      - description: mivr irq
+
+  interrupt-names:
+    items:
+      - const: attach_i
+      - const: uvp_d_evt
+      - const: mivr
+
+  io-channels:
+    description: |
+      Use ADC channel to read VBUS, IBUS, IBAT, etc., info.
+    minItems: 1
+    items:
+      - description: |
+          VBUS voltage with lower accuracy (+-75mV) but higher measure
+          range (1~22V)
+      - description: |
+          VBUS voltage with higher accuracy (+-30mV) but lower measure
+          range (1~9.76V)
+      - description: the main system input voltage
+      - description: battery voltage
+      - description: battery temperature-sense input voltage
+      - description: IBUS current (required)
+      - description: battery current
+      - description: |
+          regulated output voltage to supply for the PWM low-side gate driver
+          and the bootstrap capacitor
+      - description: IC junction temperature
+
+  io-channel-names:
+    minItems: 1
+    items:
+      - const: vbusdiv5
+      - const: vbusdiv2
+      - const: vsys
+      - const: vbat
+      - const: ts_bat
+      - const: ibus
+      - const: ibat
+      - const: chg_vddp
+      - const: temp_jc
+
+  usb-otg-vbus-regulator:
+    type: object
+    description: OTG boost regulator.
+    unevaluatedProperties: false
+    $ref: /schemas/regulator/regulator.yaml#
+
+    properties:
+      enable-gpios:
+        maxItems: 1
+
+required:
+  - compatible
+  - interrupts
+  - interrupt-names
+  - io-channels
+
+additionalProperties: false
+
+...
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v9 2/10 dt-bindings: leds: mt6370: Add MediaTek MT6370 current sink type LED indicator

From: ChiYuan Huang <[email protected]>

Add MediaTek MT6370 current sink type LED indicator binding documentation.

---
 .../bindings/leds/mediatek,mt6370-indicator.yaml   | 81 ++++++++++++++++++++++
 1 file changed, 81 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml
Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml new file +81 -0
new file mode 100644
index 0000000..204b103
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/mediatek,mt6370-indicator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: LED driver for MT6370 PMIC from MediaTek Integrated.
+
+maintainers:
+  - Alice Chen <[email protected]>
+
+description: |
+  This module is part of the MT6370 MFD device.
+  Add MT6370 LED driver include 4-channel RGB LED support Register/PWM/Breath Mode
+
+allOf:
+  - $ref: leds-class-multicolor.yaml#
+
+properties:
+  compatible:
+    const: mediatek,mt6370-indicator
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^multi-led@[0-3]$":
+    type: object
+
+    properties:
+      reg:
+        enum: [0, 1, 2, 3]
+
+      "#address-cells":
+        const: 1
+
+      "#size-cells":
+        const: 0
+
+    patternProperties:
+      "^led@[0-2]$":
+        type: object
+        $ref: common.yaml#
+        unevaluatedProperties: false
+
+        properties:
+          reg:
+            enum: [0, 1, 2]
+
+        required:
+          - reg
+          - color
+
+    required:
+      - reg
+      - color
+      - "#address-cells"
+      - "#size-cells"
+
+  "^led@[0-3]$":
+    type: object
+    $ref: common.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        enum: [0, 1, 2, 3]
+
+    required:
+      - reg
+      - color
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
Signature · 1 line
2.7.4
author
#2 lore raw

PATCH v9 3/10 dt-bindings: leds: Add MediaTek MT6370 flashlight

In reply to ChiaEn Wu

From: Alice Chen <[email protected]>

Add MediaTek MT6370 flashlight binding documentation.

---
 .../bindings/leds/mediatek,mt6370-flashlight.yaml  | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml
Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml new file +41 -0
new file mode 100644
index 0000000..e9d02ed
@@ -0,0 +1,41 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/mediatek,mt6370-flashlight.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Flash LED driver for MT6370 PMIC from MediaTek Integrated.
+
+maintainers:
+  - Alice Chen <[email protected]>
+
+description: |
+  This module is part of the MT6370 MFD device.
+  Add MT6370 flash LED driver include 2-channel flash LED support Torch/Strobe Mode.
+
+properties:
+  compatible:
+    const: mediatek,mt6370-flashlight
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^led@[0-1]$":
+    type: object
+    $ref: common.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        enum: [0, 1]
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v9 4/10 dt-bindings: backlight: Add MediaTek MT6370 backlight

In reply to ChiaEn Wu

From: ChiYuan Huang <[email protected]>

Add MT6370 backlight binding documentation.

---
 .../leds/backlight/mediatek,mt6370-backlight.yaml  | 121 +++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml
Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml new file +121 -0
new file mode 100644
index 0000000..5533b65
@@ -0,0 +1,121 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/backlight/mediatek,mt6370-backlight.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MediaTek MT6370 Backlight
+
+maintainers:
+  - ChiaEn Wu <[email protected]>
+
+description: |
+  This module is part of the MT6370 MFD device.
+  The MT6370 Backlight WLED driver supports up to a 29V output voltage for
+  4 channels of 8 series WLEDs. Each channel supports up to 30mA of current
+  capability with 2048 current steps (11 bits, only for MT6370/MT6371) or
+  16384 current steps (14 bits, only for MT6372) in exponential or linear
+  mapping curves.
+
+allOf:
+  - $ref: common.yaml#
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt6370-backlight
+      - mediatek,mt6372-backlight
+
+  default-brightness:
+    minimum: 0
+
+  max-brightness:
+    minimum: 0
+
+  enable-gpios:
+    description: External backlight 'enable' pin
+    maxItems: 1
+
+  mediatek,bled-pwm-enable:
+    description: |
+      Enable external PWM input for backlight dimming
+    type: boolean
+
+  mediatek,bled-pwm-hys-enable:
+    description: |
+      Enable the backlight input-hysteresis for PWM mode
+    type: boolean
+
+  mediatek,bled-pwm-hys-input-th-steps:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    enum: [1, 4, 16, 64]
+    description: |
+      The selection of the upper and lower bounds threshold of backlight
+      PWM resolution. If we choose selection 64, the variation of PWM
+      resolution needs more than 64 steps.
+
+  mediatek,bled-ovp-shutdown:
+    description: |
+      Enable the backlight shutdown when OVP level triggered
+    type: boolean
+
+  mediatek,bled-ovp-microvolt:
+    enum: [17000000, 21000000, 25000000, 29000000]
+    description: |
+      Backlight OVP level selection.
+
+  mediatek,bled-ocp-shutdown:
+    description: |
+      Enable the backlight shutdown when OCP level triggerred.
+    type: boolean
+
+  mediatek,bled-ocp-microamp:
+    enum: [900000, 1200000, 1500000, 1800000]
+    description: |
+      Backlight OC level selection.
+
+  mediatek,bled-exponential-mode-enable:
+    description: |
+      Enable the exponential mode of backlight brightness. If this property
+      is not enabled, the default is to use linear mode.
+    type: boolean
+
+  mediatek,bled-channel-use:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    description: |
+      Backlight LED channel to be used.
+      Each bit mapping to:
+        - 0: CH4
+        - 1: CH3
+        - 2: CH2
+        - 3: CH1
+    minimum: 1
+    maximum: 15
+
+if:
+  properties:
+    compatible:
+      contains:
+        const: mediatek,mt6372-backlight
+
+then:
+  properties:
+    default-brightness:
+      maximum: 16384
+
+    max-brightness:
+      maximum: 16384
+
+else:
+  properties:
+    default-brightness:
+      maximum: 2048
+
+    max-brightness:
+      maximum: 2048
+
+required:
+  - compatible
+  - mediatek,bled-channel-use
+
+additionalProperties: false
Signature · 1 line
2.7.4
maintainer Applied
#4 lore raw

Re: [PATCH v9 04/10] dt-bindings: backlight: Add MediaTek MT6370 backlight

Quoted 4 lines · ChiaEn Wu

From: ChiYuan Huang <[email protected]>

Add MT6370 backlight binding documentation.

Quoted 8 lines
---
 .../leds/backlight/mediatek,mt6370-backlight.yaml  | 121 +++++++++++++++++++++
 1 file changed, 121 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml

Applied, thanks.

Signature · 1 line
Lee Jones [李琼斯]
author
#5 lore raw

PATCH v9 5/10 lib: add linear range index macro

In reply to ChiaEn Wu

From: ChiaEn Wu <[email protected]>

Add linear_range_idx macro for declaring the linear_range struct simply.

---

v9
- Revise LINEAR_RANGE() and LINEAR_RANGE_IDX()

---
 include/linux/linear_range.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
include/linux/linear_range.h +11 -0
index fd3d0b3..2e4f4c3 100644
@@ -26,6 +26,17 @@ struct linear_range {
 	unsigned int step;
 };
 
+#define LINEAR_RANGE(_min, _min_sel, _max_sel, _step)		\
+	{							\
+		.min = _min,					\
+		.min_sel = _min_sel,				\
+		.max_sel = _max_sel,				\
+		.step = _step,					\
+	}
+
+#define LINEAR_RANGE_IDX(_idx, _min, _min_sel, _max_sel, _step)	\
+	[_idx] = LINEAR_RANGE(_min, _min_sel, _max_sel, _step)
+
 unsigned int linear_range_values_in_range(const struct linear_range *r);
 unsigned int linear_range_values_in_range_array(const struct linear_range *r,
 						int ranges);
Signature · 1 line
2.7.4
reviewer Reviewed-by on v9 5/10
#6 lore raw

Re: [PATCH v9 05/10] lib: add linear range index macro

Quoted 5 lines · ChiaEn Wu

From: ChiaEn Wu <[email protected]>

Add linear_range_idx macro for declaring the linear_range struct simply.

Quoted 30 lines

---

v9
- Revise LINEAR_RANGE() and LINEAR_RANGE_IDX()

---
  include/linux/linear_range.h | 11 +++++++++++
  1 file changed, 11 insertions(+)
include/linux/linear_range.h +11 -0
index fd3d0b3..2e4f4c3 100644
@@ -26,6 +26,17 @@ struct linear_range {
  	unsigned int step;
  };
 
+#define LINEAR_RANGE(_min, _min_sel, _max_sel, _step)		\
+	{							\
+		.min = _min,					\
+		.min_sel = _min_sel,				\
+		.max_sel = _max_sel,				\
+		.step = _step,					\
+	}
+
+#define LINEAR_RANGE_IDX(_idx, _min, _min_sel, _max_sel, _step)	\
+	[_idx] = LINEAR_RANGE(_min, _min_sel, _max_sel, _step)
+
  unsigned int linear_range_values_in_range(const struct linear_range *r);
  unsigned int linear_range_values_in_range_array(const struct linear_range *r,
  						int ranges);
Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
author
#7 lore raw

PATCH v9 6/10 iio: adc: mt6370: Add MediaTek MT6370 support

In reply to ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MT6370 ADC driver for system monitoring, including charger current, voltage, and temperature.

---
 drivers/iio/adc/Kconfig      |  12 ++
 drivers/iio/adc/Makefile     |   1 +
 drivers/iio/adc/mt6370-adc.c | 305 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 318 insertions(+)
 create mode 100644 drivers/iio/adc/mt6370-adc.c
drivers/iio/adc/Kconfig +12 -0
index 7fe5930..995cbb5 100644
@@ -736,6 +736,18 @@ config MEDIATEK_MT6360_ADC
 	  is used in smartphones and tablets and supports a 11 channel
 	  general purpose ADC.
 
+config MEDIATEK_MT6370_ADC
+	tristate "MediaTek MT6370 ADC driver"
+	depends on MFD_MT6370
+	help
+	  Say yes here to enable MediaTek MT6370 ADC support.
+
+	  This ADC driver provides 9 channels for system monitoring (charger
+	  current, voltage, and temperature).
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "mt6370-adc".
+
 config MEDIATEK_MT6577_AUXADC
 	tristate "MediaTek AUXADC driver"
 	depends on ARCH_MEDIATEK || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
index 1772a54..c6bc35f 100644
@@ -68,6 +68,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
 obj-$(CONFIG_MCP3422) += mcp3422.o
 obj-$(CONFIG_MCP3911) += mcp3911.o
 obj-$(CONFIG_MEDIATEK_MT6360_ADC) += mt6360-adc.o
+obj-$(CONFIG_MEDIATEK_MT6370_ADC) += mt6370-adc.o
 obj-$(CONFIG_MEDIATEK_MT6577_AUXADC) += mt6577_auxadc.o
 obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
 obj-$(CONFIG_MESON_SARADC) += meson_saradc.o
drivers/iio/adc/mt6370-adc.c new file +305 -0

305 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#8 lore raw

PATCH v9 7/10 power: supply: mt6370: Add MediaTek MT6370 charger driver

In reply to ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MediaTek MT6370 Charger driver. The charger module of MT6370 supports High-Accuracy Voltage/Current Regulation, Average Input Current Regulation, Battery Temperature Sensing, Over-Temperature Protection, DPDM Detection for BC1.2.

---

v9
- Fix wrong 'F_IINLMTSEL' setting in 'mt6370_chg_init_setting()'
- Revise the usage of LINEAR_RANGE_IDX()

---
 drivers/power/supply/Kconfig          |  14 +
 drivers/power/supply/Makefile         |   1 +
 drivers/power/supply/mt6370-charger.c | 957 ++++++++++++++++++++++++++++++++++
 3 files changed, 972 insertions(+)
 create mode 100644 drivers/power/supply/mt6370-charger.c
drivers/power/supply/Kconfig +14 -0
index 1aa8323..591deb8 100644
@@ -619,6 +619,20 @@ config CHARGER_MT6360
 	  Average Input Current Regulation, Battery Temperature Sensing,
 	  Over-Temperature Protection, DPDM Detection for BC1.2.
 
+config CHARGER_MT6370
+	tristate "MediaTek MT6370 Charger Driver"
+	depends on MFD_MT6370
+	depends on REGULATOR
+	select LINEAR_RANGES
+	help
+	  Say Y here to enable MT6370 Charger Part.
+	  The device supports High-Accuracy Voltage/Current Regulation,
+	  Average Input Current Regulation, Battery Temperature Sensing,
+	  Over-Temperature Protection, DPDM Detection for BC1.2.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "mt6370-charger".
+
 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
index 7f02f36..8c95276 100644
@@ -82,6 +82,7 @@ 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_MT6370)	+= mt6370-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/mt6370-charger.c new file +957 -0

957 lines not on this page · raw message

Signature · 1 line
2.7.4
#9 lore raw

Re: [PATCH v9 07/10] power: supply: mt6370: Add MediaTek MT6370 charger driver

Quoted 17 lines · ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MediaTek MT6370 Charger driver. The charger module of MT6370 supports High-Accuracy Voltage/Current Regulation, Average Input Current Regulation, Battery Temperature Sensing, Over-Temperature Protection, DPDM Detection for BC1.2.

---

drivers/power/supply/mt6370-charger.c line 137

Quoted 9 lines
drivers/power/supply/mt6370-charger.c new file +9 -0
+
+static const struct linear_range mt6370_chg_ranges[MT6370_RANGE_F_MAX] = {
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_IAICR, 100000, 0x0, 0x3F, 50000),
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_VOREG, 3900000, 0x0, 0x51, 10000),
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_VMIVR, 3900000, 0x0, 0x5F, 100000),
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_ICHG, 900000, 0x08, 0x31, 100000),
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_IPREC, 100000, 0x0, 0x0F, 50000),
+	LINEAR_RANGE_IDX(MT6370_RANGE_F_IEOC, 100000, 0x0, 0x0F, 50000),
+};

This looks good to me now :) Thanks for the linear-range improvement!

drivers/power/supply/mt6370-charger.c line 924

Quoted 5 lines
drivers/power/supply/mt6370-charger.c new file +5 -0
+	INIT_DELAYED_WORK(&priv->mivr_dwork, mt6370_chg_mivr_dwork_func);
+	ret = devm_add_action_or_reset(dev, mt6370_chg_cancel_mivr_dwork,
+				       &priv->mivr_dwork);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to init mivr dwork\n");

I just noticed this. Maybe this could be done using devm_delayed_work_autocancel() ?

Yours
-- Matti

Signature · 5 lines
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~
author
#10 lore raw

PATCH v9 8/10 leds: rgb: mt6370: Add MediaTek MT6370 current sink type LED Indicator support

In reply to ChiaEn Wu

From: ChiYuan Huang <[email protected]>

The MediaTek MT6370 is a highly-integrated smart power management IC, which includes a single cell Li-Ion/Li-Polymer switching battery charger, a USB Type-C & Power Delivery (PD) controller, dual Flash LED current sources, a RGB LED driver, a backlight WLED driver, a display bias driver and a general LDO for portable devices.

Add support for the MediaTek MT6370 Current Sink Type LED Indicator driver. It can control four channels current-sink RGB LEDs with 3 modes:
constant current, PWM, and breath mode.

---
 drivers/leds/rgb/Kconfig           |   13 +
 drivers/leds/rgb/Makefile          |    1 +
 drivers/leds/rgb/leds-mt6370-rgb.c | 1010 ++++++++++++++++++++++++++++++++++++
 3 files changed, 1024 insertions(+)
 create mode 100644 drivers/leds/rgb/leds-mt6370-rgb.c
drivers/leds/rgb/Kconfig +13 -0
index 204cf47..7d86bb2 100644
@@ -26,4 +26,17 @@ config LEDS_QCOM_LPG
 
 	  If compiled as a module, the module will be named leds-qcom-lpg.
 
+config LEDS_MT6370_RGB
+	tristate "LED Support for MediaTek MT6370 PMIC"
+	depends on MFD_MT6370
+	select LINEAR_RANGE
+	help
+	  Say Y here to enable support for MT6370_RGB LED device.
+	  In MT6370, there are four channel current-sink LED drivers that
+	  support hardware pattern for constant current, PWM, and breath mode.
+	  Isink4 channel can also be used as a CHG_VIN power good indicator.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "leds-mt6370-rgb".
+
 endif # LEDS_CLASS_MULTICOLOR
drivers/leds/rgb/Makefile +1 -0
index 0675bc0..8c01daf 100644
@@ -2,3 +2,4 @@
 
 obj-$(CONFIG_LEDS_PWM_MULTICOLOR)	+= leds-pwm-multicolor.o
 obj-$(CONFIG_LEDS_QCOM_LPG)		+= leds-qcom-lpg.o
+obj-$(CONFIG_LEDS_MT6370_RGB)		+= leds-mt6370-rgb.o
drivers/leds/rgb/leds-mt6370-rgb.c new file +1010 -0

1,010 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v9 9/10 leds: flash: mt6370: Add MediaTek MT6370 flashlight support

In reply to ChiaEn Wu

From: Alice Chen <[email protected]>

The MediaTek MT6370 is a highly-integrated smart power management IC, which includes a single cell Li-Ion/Li-Polymer switching battery charger, a USB Type-C & Power Delivery (PD) controller, dual Flash LED current sources, a RGB LED driver, a backlight WLED driver, a display bias driver and a general LDO for portable devices.

Add support for the MT6370 Flash LED driver. Flash LED in MT6370 has 2 channels and support torch/strobe mode.

---

v9
- Revise the format of the comments.

---
 drivers/leds/flash/Kconfig             |  14 +
 drivers/leds/flash/Makefile            |   1 +
 drivers/leds/flash/leds-mt6370-flash.c | 632 +++++++++++++++++++++++++++++++++
 3 files changed, 647 insertions(+)
 create mode 100644 drivers/leds/flash/leds-mt6370-flash.c
drivers/leds/flash/Kconfig +14 -0
index d3eb689..405bd16 100644
@@ -61,6 +61,20 @@ config LEDS_MT6360
 	  Independent current sources supply for each flash LED support torch
 	  and strobe mode.
 
+config LEDS_MT6370_FLASH
+	tristate "Flash LED Support for MediaTek MT6370 PMIC"
+	depends on LEDS_CLASS && OF
+	depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	depends on MFD_MT6370
+	help
+	  Support 2 channels and torch/strobe mode.
+	  Say Y here to enable support for
+	  MT6370_FLASH_LED device.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "leds-mt6370-flash".
+
 config LEDS_RT4505
 	tristate "LED support for RT4505 flashlight controller"
 	depends on I2C && OF
drivers/leds/flash/Makefile +1 -0
index 0acbddc..0c1f3c5 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o
 obj-$(CONFIG_LEDS_RT4505)	+= leds-rt4505.o
 obj-$(CONFIG_LEDS_RT8515)	+= leds-rt8515.o
 obj-$(CONFIG_LEDS_SGM3140)	+= leds-sgm3140.o
+obj-$(CONFIG_LEDS_MT6370_FLASH)	+= leds-mt6370-flash.o
drivers/leds/flash/leds-mt6370-flash.c new file +632 -0

632 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

Re: [PATCH v9 09/10] leds: flash: mt6370: Add MediaTek MT6370 flashlight support

Il 30/08/22 05:40, ChiaEn Wu ha scritto:

Quoted 130 lines

From: Alice Chen <[email protected]>

The MediaTek MT6370 is a highly-integrated smart power management IC, which includes a single cell Li-Ion/Li-Polymer switching battery charger, a USB Type-C & Power Delivery (PD) controller, dual Flash LED current sources, a RGB LED driver, a backlight WLED driver, a display bias driver and a general LDO for portable devices.

Add support for the MT6370 Flash LED driver. Flash LED in MT6370 has 2 channels and support torch/strobe mode.

---

v9
- Revise the format of the comments.

---
  drivers/leds/flash/Kconfig             |  14 +
  drivers/leds/flash/Makefile            |   1 +
  drivers/leds/flash/leds-mt6370-flash.c | 632 +++++++++++++++++++++++++++++++++
  3 files changed, 647 insertions(+)

create mode 100644 drivers/leds/flash/leds-mt6370-flash.c

drivers/leds/flash/Kconfig +14 -0
index d3eb689..405bd16 100644
@@ -61,6 +61,20 @@ config LEDS_MT6360
  	  Independent current sources supply for each flash LED support torch
  	  and strobe mode.
 
+config LEDS_MT6370_FLASH
+	tristate "Flash LED Support for MediaTek MT6370 PMIC"
+	depends on LEDS_CLASS && OF
+	depends on LEDS_CLASS_FLASH || !LEDS_CLASS_FLASH
+	depends on V4L2_FLASH_LED_CLASS || !V4L2_FLASH_LED_CLASS
+	depends on MFD_MT6370
+	help
+	  Support 2 channels and torch/strobe mode.
+	  Say Y here to enable support for
+	  MT6370_FLASH_LED device.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "leds-mt6370-flash".
+
  config LEDS_RT4505
  	tristate "LED support for RT4505 flashlight controller"
  	depends on I2C && OF
drivers/leds/flash/Makefile +1 -0
index 0acbddc..0c1f3c5 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_LEDS_MAX77693)	+= leds-max77693.o
  obj-$(CONFIG_LEDS_RT4505)	+= leds-rt4505.o
  obj-$(CONFIG_LEDS_RT8515)	+= leds-rt8515.o
  obj-$(CONFIG_LEDS_SGM3140)	+= leds-sgm3140.o
+obj-$(CONFIG_LEDS_MT6370_FLASH)	+= leds-mt6370-flash.o
drivers/leds/flash/leds-mt6370-flash.c new file +66 -0
new file mode 100644
index 0000000..a8ec7e1
@@ -0,0 +1,632 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2022 Richtek Technology Corp.
+ *
+ * Author: Alice Chen <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/led-class-flash.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+
+#include <media/v4l2-flash-led-class.h>
+
+enum {
+	MT6370_LED_FLASH1,
+	MT6370_LED_FLASH2,
+	MT6370_MAX_LEDS
+};
+
+/* Virtual definition for multicolor */
+
+#define MT6370_REG_FLEDEN		0x17E
+#define MT6370_REG_STRBTO		0x173
+#define MT6370_REG_CHGSTAT2		0x1D1
+#define MT6370_REG_FLEDSTAT1		0x1D9
+#define MT6370_REG_FLEDISTRB(_id)	(0x174 + 4 * (_id))
+#define MT6370_REG_FLEDITOR(_id)	(0x175 + 4 * (_id))
+#define MT6370_ITORCH_MASK		GENMASK(4, 0)
+#define MT6370_ISTROBE_MASK		GENMASK(6, 0)
+#define MT6370_STRBTO_MASK		GENMASK(6, 0)
+#define MT6370_TORCHEN_MASK		BIT(3)
+#define MT6370_STROBEN_MASK		BIT(2)
+#define MT6370_FLCSEN_MASK(_id)		BIT(MT6370_LED_FLASH2 - (_id))
+#define MT6370_FLCSEN_MASK_ALL		GENMASK(1, 0)
+#define MT6370_FLEDCHGVINOVP_MASK	BIT(3)
+#define MT6370_FLED1STRBTO_MASK		BIT(11)
+#define MT6370_FLED2STRBTO_MASK		BIT(10)
+#define MT6370_FLED1STRB_MASK		BIT(9)
+#define MT6370_FLED2STRB_MASK		BIT(8)
+#define MT6370_FLED1SHORT_MASK		BIT(7)
+#define MT6370_FLED2SHORT_MASK		BIT(6)
+#define MT6370_FLEDLVF_MASK		BIT(3)
+
+#define MT6370_LED_JOINT		2
+#define MT6370_RANGE_FLED_REG		4
+#define MT6370_ITORCH_MIN_uA		25000
+#define MT6370_ITORCH_STEP_uA		12500
+#define MT6370_ITORCH_MAX_uA		400000
+#define MT6370_ITORCH_DOUBLE_MAX_uA	800000
+#define MT6370_ISTRB_MIN_uA		50000
+#define MT6370_ISTRB_STEP_uA		12500
+#define MT6370_ISTRB_MAX_uA		1500000
+#define MT6370_ISTRB_DOUBLE_MAX_uA	3000000
+#define MT6370_STRBTO_MIN_US		64000
+#define MT6370_STRBTO_STEP_US		32000
+#define MT6370_STRBTO_MAX_US		2432000
+
+#define STATE_OFF			0

drivers/leds/flash/leds-mt6370-flash.c line 76

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+#define STATE_KEEP			1
+#define STATE_ON			2
+
+#define to_mt6370_led(ptr, member) container_of(ptr, struct mt6370_led, member)
+
+struct mt6370_led {
+	struct led_classdev_flash flash;
+	struct v4l2_flash *v4l2_flash;
+	struct mt6370_priv *priv;
+	u32 led_no;

The maximum value that we will ever see for led_no is 2: this means that we don't need 32 full bits here.

	u8 led_no;

drivers/leds/flash/leds-mt6370-flash.c line 77

Quoted 1 line
drivers/leds/flash/leds-mt6370-flash.c new file +1 -0
+	u32 default_state;

This should be...

	enum led_default_state default_state;

...but then, you're never using this variable as far as I can see, apart from initializing it in mt6370_init_common_properties, for which, there's a comment below.

In any case, please either fix the initialization and actually make use of this variable, or remove it entirely.

Quoted 95 lines
drivers/leds/flash/leds-mt6370-flash.c new file +95 -0
+};
+
+struct mt6370_priv {
+	struct device *dev;
+	struct regmap *regmap;
+	struct mutex lock;
+	unsigned int fled_strobe_used;
+	unsigned int fled_torch_used;
+	unsigned int leds_active;
+	unsigned int leds_count;
+	struct mt6370_led leds[];
+};
+
+static int mt6370_torch_brightness_set(struct led_classdev *lcdev,
+				       enum led_brightness level)
+{
+	struct mt6370_led *led = to_mt6370_led(lcdev, flash.led_cdev);
+	struct mt6370_priv *priv = led->priv;
+	u32 led_enable_mask = (led->led_no == MT6370_LED_JOINT) ?
+			      MT6370_FLCSEN_MASK_ALL :
+			      MT6370_FLCSEN_MASK(led->led_no);
+	u32 enable_mask = MT6370_TORCHEN_MASK | led_enable_mask;
+	u32 val = level ? led_enable_mask : 0;
+	u32 curr;
+	int ret, i;
+
+	mutex_lock(&priv->lock);
+
+	/*
+	 * There is only one set of flash control logic, and this
+	 * flag is used to check if 'strobe' is currently being used.
+	 */
+	if (priv->fled_strobe_used) {
+		dev_warn(lcdev->dev, "Please disable strobe first [%d]\n",
+			 priv->fled_strobe_used);
+		ret = -EBUSY;
+		goto unlock;
+	}
+
+	if (level)
+		curr = priv->fled_torch_used | BIT(led->led_no);
+	else
+		curr = priv->fled_torch_used & ~BIT(led->led_no);
+
+	if (curr)
+		val |= MT6370_TORCHEN_MASK;
+
+	if (level) {
+		level -= 1;
+		if (led->led_no == MT6370_LED_JOINT) {
+			int flevel[MT6370_MAX_LEDS];
+
+			flevel[0] = level / 2;
+			flevel[1] = level - flevel[0];
+			for (i = 0; i < MT6370_MAX_LEDS; i++) {
+				ret = regmap_update_bits(priv->regmap,
+						MT6370_REG_FLEDITOR(i),
+						MT6370_ITORCH_MASK, flevel[i]);
+				if (ret)
+					goto unlock;
+			}
+		} else {
+			ret = regmap_update_bits(priv->regmap,
+					MT6370_REG_FLEDITOR(led->led_no),
+					MT6370_ITORCH_MASK, level);
+			if (ret)
+				goto unlock;
+		}
+	}
+
+	ret = regmap_update_bits(priv->regmap, MT6370_REG_FLEDEN,
+				 enable_mask, val);
+	if (ret)
+		goto unlock;
+
+	priv->fled_torch_used = curr;
+
+unlock:
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+
+static int mt6370_flash_brightness_set(struct led_classdev_flash *fl_cdev,
+				       u32 brightness)
+{
+	/*
+	 * Because of the current spikes when turning on the flash,
+	 * the brightness should be kept by the LED framework. This
+	 * empty function is used to prevent checking failure when
+	 * led_classdev_flash registers ops.
+	 */
+	return 0;
+}
+
+static int _mt6370_flash_brightness_set(struct led_classdev_flash *fl_cdev,

drivers/leds/flash/leds-mt6370-flash.c line 182

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+					u32 brightness)
+{
+	struct mt6370_led *led = to_mt6370_led(fl_cdev, flash);
+	struct mt6370_priv *priv = led->priv;
+	struct led_flash_setting *s = &fl_cdev->brightness;
+	u32 val = (brightness - s->min) / s->step;
+	int ret, i;
+
+	if (led->led_no == MT6370_LED_JOINT) {
+		int flevel[MT6370_MAX_LEDS];

Since you're writing this value to registers, please use fixed size variables. If this is really supposed to be a signed value, it would be:

		s32 flevel[MT6370_MAX_LEDS];
Quoted 7 lines
drivers/leds/flash/leds-mt6370-flash.c new file +7 -0
+
+		flevel[0] = val / 2;
+		flevel[1] = val - flevel[0];
+		for (i = 0; i < MT6370_MAX_LEDS; i++) {
+			ret = regmap_update_bits(priv->regmap,
+						 MT6370_REG_FLEDISTRB(i),
+						 MT6370_ISTROBE_MASK, flevel[i]);

drivers/leds/flash/leds-mt6370-flash.c line 199

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+			if (ret)
+				return ret;
+		}
+	} else {
+		return regmap_update_bits(priv->regmap,
+					  MT6370_REG_FLEDISTRB(led->led_no),
+					  MT6370_ISTROBE_MASK, val);
+	}
+
+	return 0;

If we reach this point, this means that led_no is out of range (which is never supposed to happen - I know).
Since that condition is something unexpected and unhandled, you should return an error here.

Quoted 43 lines
drivers/leds/flash/leds-mt6370-flash.c new file +43 -0
+}
+
+static int mt6370_strobe_set(struct led_classdev_flash *fl_cdev, bool state)
+{
+	struct mt6370_led *led = to_mt6370_led(fl_cdev, flash);
+	struct mt6370_priv *priv = led->priv;
+	struct led_classdev *lcdev = &fl_cdev->led_cdev;
+	struct led_flash_setting *s = &fl_cdev->brightness;
+	u32 led_enable_mask = (led->led_no == MT6370_LED_JOINT) ?
+			      MT6370_FLCSEN_MASK_ALL :
+			      MT6370_FLCSEN_MASK(led->led_no);
+	u32 enable_mask = MT6370_STROBEN_MASK | led_enable_mask;
+	u32 val = state ? led_enable_mask : 0;
+	u32 curr;
+	int ret;
+
+	mutex_lock(&priv->lock);
+
+	/*
+	 * There is only one set of flash control logic, and this
+	 * flag is used to check if 'torch' is currently being used.
+	 */
+	if (priv->fled_torch_used) {
+		dev_warn(lcdev->dev, "Please disable torch first [0x%x]\n",
+				      priv->fled_torch_used);
+		ret = -EBUSY;
+		goto unlock;
+	}
+
+	if (state)
+		curr = priv->fled_strobe_used | BIT(led->led_no);
+	else
+		curr = priv->fled_strobe_used & ~BIT(led->led_no);
+
+	if (curr)
+		val |= MT6370_STROBEN_MASK;
+
+	ret = regmap_update_bits(priv->regmap, MT6370_REG_FLEDEN, enable_mask,
+				 val);
+	if (ret) {
+		dev_err(lcdev->dev, "[%d] control current source %d fail\n",
+				     led->led_no, state);
+		goto unlock;

drivers/leds/flash/leds-mt6370-flash.c line 252

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+	}
+
+	/*
+	 * If the flash needs to turn on, configure the flash current to
+	 * ramp up to the setting value. Otherwise, always revert to the
+	 * minimum one.
+	 */
+	ret = _mt6370_flash_brightness_set(fl_cdev, state ? s->val : s->min);
+	if (ret)
+		goto unlock;

If this fails, I think that we should revert the previous changes to FLEDEN before returning.

Quoted 17 lines
drivers/leds/flash/leds-mt6370-flash.c new file +17 -0
+
+	/*
+	 * For the flash to turn on/off, we must wait for HW ramping
+	 * up/down time 5ms/500us to prevent the unexpected problem.
+	 */
+	if (!priv->fled_strobe_used && curr)
+		usleep_range(5000, 6000);
+	else if (priv->fled_strobe_used && !curr)
+		usleep_range(500, 600);
+
+	priv->fled_strobe_used = curr;
+
+unlock:
+	mutex_unlock(&priv->lock);
+	return ret;
+}
+

..snip..

Quoted 37 lines
drivers/leds/flash/leds-mt6370-flash.c new file +37 -0
+
+static int mt6370_init_common_properties(struct mt6370_led *led,
+					 struct led_init_data *init_data)
+{
+	const char * const states[] = { "off", "keep", "on" };
+	const char *str = states[STATE_OFF];
+	int ret;
+
+	fwnode_property_read_string(init_data->fwnode, "default-state", &str);
+	ret = match_string(states, ARRAY_SIZE(states), str);
+	if (ret >= 0)
+		led->default_state = ret;
+
+	return 0;
+}
+
+static int mt6370_led_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct mt6370_priv *priv;
+	struct fwnode_handle *child;
+	size_t count;
+	int i = 0, ret;
+
+	count = device_get_child_node_count(dev);
+	if (!count || count > MT6370_MAX_LEDS)
+		return dev_err_probe(dev, -EINVAL,
+		       "No child node or node count over max led number %zu\n", count);
+
+	priv = devm_kzalloc(dev, struct_size(priv, leds, count), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->leds_count = count;
+	priv->dev = dev;
+	mutex_init(&priv->lock);
+

drivers/leds/flash/leds-mt6370-flash.c line 597

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+	priv->regmap = dev_get_regmap(dev->parent, NULL);
+	if (!priv->regmap)
+		return dev_err_probe(dev, -ENODEV, "Failed to get parent regmap\n");
+
+	device_for_each_child_node(dev, child) {
+		struct mt6370_led *led = priv->leds + i;
+		struct led_init_data init_data = { .fwnode = child, };
+
+		led->priv = priv;
+		ret = mt6370_init_common_properties(led, &init_data);

This is only initializing the default state, for which you do have a helper.

Please use led_init_default_state_get(fwnode).

Quoted 7 lines
drivers/leds/flash/leds-mt6370-flash.c new file +7 -0
+		if (ret)
+			return ret;
+
+		ret = mt6370_init_flash_properties(led, &init_data);
+		if (ret)
+			return ret;
+

drivers/leds/flash/leds-mt6370-flash.c line 614

Quoted 10 lines
drivers/leds/flash/leds-mt6370-flash.c new file +10 -0
+		ret = mt6370_led_register(dev, led, &init_data);
+		if (ret)
+			return ret;
+
+		i++;
+	}
+
+	return 0;
+}
+

Regards,
Angelo

A message that is not in the archive (sent off-list or not yet received): CAPOBaE7rz2F-sij-LbYau6TRxFoOfmoUc=R__Z7iUrFWmZPgrg@mail.gmail.com

author
#14 lore raw

Re: [PATCH v9 09/10] leds: flash: mt6370: Add MediaTek MT6370 flashlight support

Quoted 2 lines · Han Jingoo

On Mon, Aug 29, 2022 ChiaEn Wu <[email protected]> wrote:

...

Quoted 21 lines

drivers/leds/flash/leds-mt6370-flash.c line 61

Quoted 8 lines
drivers/leds/flash/leds-mt6370-flash.c new file +8 -0
+#define MT6370_ITORCH_MIN_uA           25000
+#define MT6370_ITORCH_STEP_uA          12500
+#define MT6370_ITORCH_MAX_uA           400000
+#define MT6370_ITORCH_DOUBLE_MAX_uA    800000
+#define MT6370_ISTRB_MIN_uA            50000
+#define MT6370_ISTRB_STEP_uA           12500
+#define MT6370_ISTRB_MAX_uA            1500000
+#define MT6370_ISTRB_DOUBLE_MAX_uA     3000000

Use upper letters as below:

#define MT6370_ITORCH_MIN_UA           25000
#define MT6370_ITORCH_STEP_UA          12500
#define MT6370_ITORCH_MAX_UA           400000
#define MT6370_ITORCH_DOUBLE_MAX_UA    800000
#define MT6370_ISTRB_MIN_UA            50000
#define MT6370_ISTRB_STEP_UA           12500
#define MT6370_ISTRB_MAX_UA            1500000
#define MT6370_ISTRB_DOUBLE_MAX_UA     3000000
Quoted 4 lines

drivers/leds/flash/leds-mt6370-flash.c line 65

Quoted 4 lines
drivers/leds/flash/leds-mt6370-flash.c new file +4 -0
+#define MT6370_STRBTO_MIN_US           64000
+#define MT6370_STRBTO_STEP_US          32000
+#define MT6370_STRBTO_MAX_US           2432000
+

Hi Jingoo,

This coding style is in accordance with Andy's opinion in this mail:
https://lore.kernel.org/linux-arm-kernel/CAHp75Vciq4M4kVrabNV9vTLLcd1vR=bMe8JLEdAF9MkRTpcB5g@mail.gmail.com/

And I will revise other parts in v12.
Thanks for your review!

--
Best Regards,
ChiaEn Wu

#15 lore raw

Re: [PATCH v9 09/10] leds: flash: mt6370: Add MediaTek MT6370 flashlight support

Quoted 13 lines · ChiaEn Wu
Quoted 12 lines · Han Jingoo

drivers/leds/flash/leds-mt6370-flash.c line 61

Quoted 8 lines · On Mon, Aug 29, 2022 ChiaEn Wu <[email protected]> wrote:
drivers/leds/flash/leds-mt6370-flash.c new file +8 -0
+#define MT6370_ITORCH_MIN_uA           25000
+#define MT6370_ITORCH_STEP_uA          12500
+#define MT6370_ITORCH_MAX_uA           400000
+#define MT6370_ITORCH_DOUBLE_MAX_uA    800000
+#define MT6370_ISTRB_MIN_uA            50000
+#define MT6370_ISTRB_STEP_uA           12500
+#define MT6370_ISTRB_MAX_uA            1500000
+#define MT6370_ISTRB_DOUBLE_MAX_uA     3000000

Use upper letters as below:

For microseconds (and other -seconds) the common practice (I assume historically) is to use upper letters, indeed. But for current it's more natural to use small letters for unit multiplier as it's easier to read and understand.

Quoted 9 lines
Quoted 9 lines
#define MT6370_ITORCH_MIN_UA           25000
#define MT6370_ITORCH_STEP_UA          12500
#define MT6370_ITORCH_MAX_UA           400000
#define MT6370_ITORCH_DOUBLE_MAX_UA    800000
#define MT6370_ISTRB_MIN_UA            50000
#define MT6370_ISTRB_STEP_UA           12500
#define MT6370_ISTRB_MAX_UA            1500000
#define MT6370_ISTRB_DOUBLE_MAX_UA     3000000
Quoted 8 lines
Quoted 3 lines

drivers/leds/flash/leds-mt6370-flash.c line 64

Quoted 3 lines
drivers/leds/flash/leds-mt6370-flash.c new file +3 -0
+#define MT6370_STRBTO_MIN_US           64000
+#define MT6370_STRBTO_STEP_US          32000
+#define MT6370_STRBTO_MAX_US           2432000

Hi Jingoo,

This coding style is in accordance with Andy's opinion in this mail:
https://lore.kernel.org/linux-arm-kernel/CAHp75Vciq4M4kVrabNV9vTLLcd1vR=bMe8JLEdAF9MkRTpcB5g@mail.gmail.com/

True.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#16 lore raw

Re: [PATCH v9 09/10] leds: flash: mt6370: Add MediaTek MT6370 flashlight support

Quoted 16 lines · On Wed, Sep 21, 2022 Andy Shevchenko <[email protected]> wrote:
Quoted 13 lines · ChiaEn Wu
Quoted 12 lines · Han Jingoo

drivers/leds/flash/leds-mt6370-flash.c line 61

Quoted 8 lines · On Mon, Aug 29, 2022 ChiaEn Wu <[email protected]> wrote:
drivers/leds/flash/leds-mt6370-flash.c new file +8 -0
+#define MT6370_ITORCH_MIN_uA           25000
+#define MT6370_ITORCH_STEP_uA          12500
+#define MT6370_ITORCH_MAX_uA           400000
+#define MT6370_ITORCH_DOUBLE_MAX_uA    800000
+#define MT6370_ISTRB_MIN_uA            50000
+#define MT6370_ISTRB_STEP_uA           12500
+#define MT6370_ISTRB_MAX_uA            1500000
+#define MT6370_ISTRB_DOUBLE_MAX_uA     3000000

Use upper letters as below:

Quoted 4 lines

For microseconds (and other -seconds) the common practice (I assume historically) is to use upper letters, indeed. But for current it's more natural to use small letters for unit multiplier as it's easier to read and understand.

(CC'ed Linus Torvalds, Andrew Morton, Joe Perches, Julia Lawall, Krzysztof Kozlowski,)

Yep, it is common practice. Long time ago, I met the same problem on how to present micro-ampere:
visibility vs coding practice. At that time, I followed the coding practice. So, was there anyone who
rejected this decision to mix upper and lower letters when you gave your comment last July?
If there is no objection, or most of maintainers and long-term contributors agree with that,
I am ok with that.

To Tovalds, Andrew, Joe, Julia, Krzysztof,

I just need your feedback on coding styles. Are you ok with mixing upper and lower letters for visibility
to present micro-seconds or micro-ampere? Andy (one of very-active contributors) gives his opinion that
mixing upper and lower letters can be acceptable. I remain neutral on this coding style issue.

e.g., #define MT6370_ITORCH_DOUBLE_MAX_uA 800000

Thank you.

Best regards,
Jingoo Han

Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
#define MT6370_ITORCH_MIN_UA           25000
#define MT6370_ITORCH_STEP_UA          12500
#define MT6370_ITORCH_MAX_UA           400000
#define MT6370_ITORCH_DOUBLE_MAX_UA    800000
#define MT6370_ISTRB_MIN_UA            50000
#define MT6370_ISTRB_STEP_UA           12500
#define MT6370_ISTRB_MAX_UA            1500000
#define MT6370_ISTRB_DOUBLE_MAX_UA     3000000
Quoted 8 lines
Quoted 3 lines

drivers/leds/flash/leds-mt6370-flash.c line 64

Quoted 3 lines
drivers/leds/flash/leds-mt6370-flash.c new file +3 -0
+#define MT6370_STRBTO_MIN_US           64000
+#define MT6370_STRBTO_STEP_US          32000
+#define MT6370_STRBTO_MAX_US           2432000

Hi Jingoo,

This coding style is in accordance with Andy's opinion in this mail:
https://lore.kernel.org/linux-arm-kernel/CAHp75Vciq4M4kVrabNV9vTLLcd1vR=bMe8JLEdAF9MkRTpcB5g@mail.gmail.com/

True.

--
With Best Regards,
Andy Shevchenko

#17 lore raw

Re: [PATCH v9 09/10] leds: flash: mt6370: Add MediaTek MT6370 flashlight support

Quoted 17 lines · Han Jingoo
Quoted 16 lines · On Wed, Sep 21, 2022 Andy Shevchenko <[email protected]> wrote:
Quoted 13 lines · ChiaEn Wu
Quoted 12 lines · Han Jingoo

drivers/leds/flash/leds-mt6370-flash.c line 61

Quoted 8 lines · On Mon, Aug 29, 2022 ChiaEn Wu <[email protected]> wrote:
drivers/leds/flash/leds-mt6370-flash.c new file +8 -0
+#define MT6370_ITORCH_MIN_uA           25000
+#define MT6370_ITORCH_STEP_uA          12500
+#define MT6370_ITORCH_MAX_uA           400000
+#define MT6370_ITORCH_DOUBLE_MAX_uA    800000
+#define MT6370_ISTRB_MIN_uA            50000
+#define MT6370_ISTRB_STEP_uA           12500
+#define MT6370_ISTRB_MAX_uA            1500000
+#define MT6370_ISTRB_DOUBLE_MAX_uA     3000000

Use upper letters as below:

Quoted 4 lines
Quoted 4 lines

For microseconds (and other -seconds) the common practice (I assume historically) is to use upper letters, indeed. But for current it's more natural to use small letters for unit multiplier as it's easier to read and understand.

I think it's fine. see:

commit 22735ce857a2d9f4e6eec37c36be3fcf9d21d154

Author: Joe Perches <[email protected]>
Date:   Wed Jul 3 15:05:33 2013 -0700

checkpatch: ignore SI unit CamelCase variants like "_uV"

Many existing variable names use SI like variants that should be otherwise obvious and acceptable.

author
#18 lore raw

PATCH v9 10/10 video: backlight: mt6370: Add MediaTek MT6370 support

In reply to ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MediaTek MT6370 backlight driver. It controls 4 channels of 8 series WLEDs in
2048 (only for MT6370/MT6371) / 16384 (only for MT6372) current steps (30 mA) in exponential or linear mapping curves.

---

v9
- Revise the format of the comments.

---
 drivers/video/backlight/Kconfig            |  13 ++
 drivers/video/backlight/Makefile           |   1 +
 drivers/video/backlight/mt6370-backlight.c | 351 +++++++++++++++++++++++++++++
 3 files changed, 365 insertions(+)
 create mode 100644 drivers/video/backlight/mt6370-backlight.c
drivers/video/backlight/Kconfig +13 -0
index a003e02..936ba1e 100644
@@ -268,6 +268,19 @@ config BACKLIGHT_MAX8925
 	  If you have a LCD backlight connected to the WLED output of MAX8925
 	  WLED output, say Y here to enable this driver.
 
+config BACKLIGHT_MT6370
+	tristate "MediaTek MT6370 Backlight Driver"
+	depends on MFD_MT6370
+	help
+	  This enables support for Mediatek MT6370 Backlight driver.
+	  It's commonly used to drive the display WLED. There are 4 channels
+	  inside, and each channel supports up to 30mA of current capability
+	  with 2048 current steps (only for MT6370/MT6371) or 16384 current
+	  steps (only for MT6372) in exponential or linear mapping curves.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called "mt6370-backlight".
+
 config BACKLIGHT_APPLE
 	tristate "Apple Backlight Driver"
 	depends on X86 && ACPI
drivers/video/backlight/Makefile +1 -0
index cae2c83..e815f3f 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_BACKLIGHT_LP855X)		+= lp855x_bl.o
 obj-$(CONFIG_BACKLIGHT_LP8788)		+= lp8788_bl.o
 obj-$(CONFIG_BACKLIGHT_LV5207LP)	+= lv5207lp.o
 obj-$(CONFIG_BACKLIGHT_MAX8925)		+= max8925_bl.o
+obj-$(CONFIG_BACKLIGHT_MT6370)		+= mt6370-backlight.o
 obj-$(CONFIG_BACKLIGHT_OMAP1)		+= omap1_bl.o
 obj-$(CONFIG_BACKLIGHT_PANDORA)		+= pandora_bl.o
 obj-$(CONFIG_BACKLIGHT_PCF50633)	+= pcf50633-backlight.o
drivers/video/backlight/mt6370-backlight.c new file +351 -0

351 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer Applied
#19 lore raw

Re: [PATCH v9 10/10] video: backlight: mt6370: Add MediaTek MT6370 support

Quoted 17 lines · ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MediaTek MT6370 backlight driver. It controls 4 channels of 8 series WLEDs in
2048 (only for MT6370/MT6371) / 16384 (only for MT6372) current steps (30 mA) in exponential or linear mapping curves.

---

Quoted 8 lines

v9
- Revise the format of the comments.

---
 drivers/video/backlight/Kconfig            |  13 ++
 drivers/video/backlight/Makefile           |   1 +
 drivers/video/backlight/mt6370-backlight.c | 351 +++++++++++++++++++++++++++++
 3 files changed, 365 insertions(+)
 create mode 100644 drivers/video/backlight/mt6370-backlight.c

Applied, thanks.

Signature · 1 line
Lee Jones [李琼斯]
maintainer Applied
#20 lore raw

Re: [PATCH v9 10/10] video: backlight: mt6370: Add MediaTek MT6370 support

In reply to ChiaEn Wu
Quoted 17 lines · ChiaEn Wu

From: ChiaEn Wu <[email protected]>

MediaTek MT6370 is a SubPMIC consisting of a single cell battery charger with ADC monitoring, RGB LEDs, dual channel flashlight, WLED backlight driver, display bias voltage supply, one general purpose LDO, and the USB Type-C & PD controller complies with the latest USB Type-C and PD standards.

Add support for the MediaTek MT6370 backlight driver. It controls 4 channels of 8 series WLEDs in
2048 (only for MT6370/MT6371) / 16384 (only for MT6372) current steps (30 mA) in exponential or linear mapping curves.

---

Quoted 8 lines

v9
- Revise the format of the comments.

---
 drivers/video/backlight/Kconfig            |  13 ++
 drivers/video/backlight/Makefile           |   1 +
 drivers/video/backlight/mt6370-backlight.c | 351 +++++++++++++++++++++++++++++
 3 files changed, 365 insertions(+)
 create mode 100644 drivers/video/backlight/mt6370-backlight.c

Applied, thanks.

Signature · 1 line
Lee Jones [李琼斯]