Add Mediatek MT6370 PMIC support
Subsystems (12)
cover Add Mediatek MT6370 PMIC support
From: ChiaEn Wu <[email protected]>
Sorry, for the patch dependency, we resend this patch series and we're sorry for any inconvenience that we may have caused. This patch series add Mediatek MT6370 PMIC support. The 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.
Alice Chen (3):
dt-bindings: leds: Add Mediatek MT6370 flashlight binding
leds: mt6370: Add Mediatek MT6370 Indicator support
leds: flashlight: mt6370: Add Mediatek MT6370 flashlight support
ChiYuan Huang (7):
dt-bindings: usb: Add Mediatek MT6370 TCPC binding
dt-bindings: leds: mt6370: Add Mediatek mt6370 indicator
dt-bindings: backlight: Add Mediatek MT6370 backlight binding
dt-bindings: mfd: Add Mediatek MT6370 binding
mfd: mt6370: Add Mediatek MT6370 support
usb: typec: tcpci_mt6370: Add Mediatek MT6370 tcpci driver
regulator: mt6370: Add mt6370 DisplayBias and VibLDO support
ChiaEn Wu (4):
dt-bindings: power: supply: Add Mediatek MT6370 Charger binding
iio: adc: mt6370: Add Mediatek MT6370 support
power: supply: mt6370: Add Mediatek MT6370 charger driver
video: backlight: mt6370: Add Mediatek MT6370 support
.../backlight/mediatek,mt6370-backlight.yaml | 110 ++ .../leds/mediatek,mt6370-flashlight.yaml | 48 + .../leds/mediatek,mt6370-indicator.yaml | 57 + .../bindings/mfd/mediatek,mt6370.yaml | 282 ++++ .../power/supply/mediatek,mt6370-charger.yaml | 60 + .../bindings/usb/mediatek,mt6370-tcpc.yaml | 35 + drivers/iio/adc/Kconfig | 9 + drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6370-adc.c | 257 ++++ drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/flash/Kconfig | 9 + drivers/leds/flash/Makefile | 1 + drivers/leds/flash/leds-mt6370-flash.c | 665 ++++++++++ drivers/leds/leds-mt6370.c | 994 +++++++++++++++ drivers/mfd/Kconfig | 13 + drivers/mfd/Makefile | 1 + drivers/mfd/mt6370.c | 273 ++++ drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6370-charger.c | 1132 +++++++++++++++++ drivers/regulator/Kconfig | 8 + drivers/regulator/Makefile | 1 + drivers/regulator/mt6370-regulator.c | 389 ++++++ drivers/usb/typec/tcpm/Kconfig | 8 + drivers/usb/typec/tcpm/Makefile | 1 + drivers/usb/typec/tcpm/tcpci_mt6370.c | 212 +++ drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/mt6370-backlight.c | 338 +++++ .../dt-bindings/iio/adc/mediatek,mt6370_adc.h | 18 + include/dt-bindings/mfd/mediatek,mt6370.h | 83 ++ 32 files changed, 5038 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml create mode 100644 Documentation/devicetree/bindings/power/supply/mediatek,mt6370-charger.yaml create mode 100644 Documentation/devicetree/bindings/usb/mediatek,mt6370-tcpc.yaml create mode 100644 drivers/iio/adc/mt6370-adc.c create mode 100644 drivers/leds/flash/leds-mt6370-flash.c create mode 100644 drivers/leds/leds-mt6370.c create mode 100644 drivers/mfd/mt6370.c create mode 100644 drivers/power/supply/mt6370-charger.c create mode 100644 drivers/regulator/mt6370-regulator.c create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6370.c create mode 100644 drivers/video/backlight/mt6370-backlight.c create mode 100644 include/dt-bindings/iio/adc/mediatek,mt6370_adc.h create mode 100644 include/dt-bindings/mfd/mediatek,mt6370.h
Signature · 1 line
2.25.1
PATCH RESEND 1/14 dt-bindings: usb: Add Mediatek MT6370 TCPC binding
From: ChiYuan Huang <[email protected]>
Add Mediatek MT6370 TCPC binding documentation.
--- .../bindings/usb/mediatek,mt6370-tcpc.yaml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/mediatek,mt6370-tcpc.yaml
Documentation/devicetree/bindings/usb/mediatek,mt6370-tcpc.yaml new file +35 -0
@@ -0,0 +1,35 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/usb/mediatek,mt6370-tcpc.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek MT6370 Type-C Port Switch and Power Delivery controller DT bindings + +maintainers: + - ChiYuan Huang <[email protected]> + +description: | + Mediatek MT6370 is a multi-functional device. It integrates charger, ADC, flash, RGB indicators, + regulators (DSV/VIBLDO), and TypeC Port Switch with Power Delivery controller. + This document only describes MT6370 Type-C Port Switch and Power Delivery controller. + +properties: + compatible: + enum: + - mediatek,mt6370-tcpc + + interrupts: + maxItems: 1 + + connector: + type: object + $ref: /schemas/connector/usb-connector.yaml# + description: + Properties for usb c connector. + +additionalProperties: false + +required: + - compatible + - interrupts
Signature · 1 line
2.25.1
Re: [RESEND 01/14] dt-bindings: usb: Add Mediatek MT6370 TCPC binding
Quoted 5 lines · ChiaEn Wu
From: ChiYuan Huang <[email protected]>
Add Mediatek MT6370 TCPC binding documentation.
Signed-off-by ChiYuan Huang <[email protected]>
Please apply my previous comments.
Best regards,
Krzysztof
PATCH RESEND 2/14 dt-bindings: power: supply: Add Mediatek MT6370 Charger binding
In reply to ChiaEn WuFrom: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 Charger binding documentation.
--- .../power/supply/mediatek,mt6370-charger.yaml | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/supply/mediatek,mt6370-charger.yaml
Documentation/devicetree/bindings/power/supply/mediatek,mt6370-charger.yaml new file +60 -0
@@ -0,0 +1,60 @@ +# 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 for mt6370 charger + - description: usb plug in irq for mt6370 charger + - description: mivr irq for mt6370 charger + + 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. Ibus ADC channel + is required. + + usb-otg-vbus: + type: object + description: OTG boost regulator. + $ref: /schemas/regulator/regulator.yaml# + + properties: + enable-gpio: + maxItems: 1 + description: | + Specify a valid 'enable' gpio for the regulator and it's optional + +required: + - compatible + - interrupts + - interrupt-names + - io-channels + +additionalProperties: false + +...
Signature · 7 lines
2.25.1 _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek
Re: [RESEND 02/14] dt-bindings: power: supply: Add Mediatek MT6370 Charger binding
Quoted 4 lines · ChiaEn Wu
From: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 Charger binding documentation.
Please apply my previous comments.
Best regards,
Krzysztof
PATCH RESEND 3/14 dt-bindings: leds: mt6370: Add Mediatek mt6370 indicator
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add Mediatek mt6370 indicator documentation.
--- .../leds/mediatek,mt6370-indicator.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml
Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml new file +57 -0
@@ -0,0 +1,57 @@ +# 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. + see Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml + Add MT6370 LED driver include 4-channel RGB LED support Register/PWM/Breath Mode + +properties: + compatible: + const: mediatek,mt6370-indicator + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +patternProperties: + "^(multi-)?led@[0-3]$": + description: | + Properties for a single LED. + $ref: common.yaml# + type: object + + properties: + reg: + description: | + Index of the LED. + enum: + - 0 # LED output ISINK1 + - 1 # LED output ISINK2 + - 2 # LED output ISINK3 + - 3 # LED output ISINK4 + + mediatek,soft-start: + description: | + soft start step control, support /0.5ms/1ms/1.5ms/2ms. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 3] + + unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false
Signature · 1 line
2.25.1
Rob Herring
maintainerRe: [RESEND 03/14] dt-bindings: leds: mt6370: Add Mediatek mt6370 indicator
Quoted 10 lines · ChiaEn Wu
From: ChiYuan Huang <[email protected]>
Add Mediatek mt6370 indicator documentation.
Signed-off-by ChiYuan Huang <[email protected]>--- .../leds/mediatek,mt6370-indicator.yaml | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:
doc reference errors (make refcheckdocs):
Warning: Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml references a file that doesn't exist: Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml Documentation/devicetree/bindings/leds/mediatek,mt6370-indicator.yaml: Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
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.
Re: [RESEND 03/14] dt-bindings: leds: mt6370: Add Mediatek mt6370 indicator
In reply to ChiaEn WuQuoted 3 lines · ChiaEn Wu
From: ChiYuan Huang <[email protected]>
Add Mediatek mt6370 indicator documentation.
Please apply my previous comments.
Best regards,
Krzysztof
PATCH RESEND 4/14 dt-bindings: leds: Add Mediatek MT6370 flashlight binding
In reply to ChiaEn WuFrom: Alice Chen <[email protected]>
Add Mediatek MT6370 flashlight binding documentation
--- .../leds/mediatek,mt6370-flashlight.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml
Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.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/leds/leds-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. + see Documentation/devicetree/bindings/mfd/mt6370.yaml + 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# + description: + Properties for a single flash LED. + + properties: + reg: + description: Index of the flash LED. + enum: + - 0 #Address of LED1 + - 1 #Address of LED2 + + unevaluatedProperties: false + +required: + - compatible + - "#address-cells" + - "#size-cells" + +additionalProperties: false
Signature · 1 line
2.25.1
Rob Herring
maintainerRe: [RESEND 04/14] dt-bindings: leds: Add Mediatek MT6370 flashlight binding
Quoted 10 lines · ChiaEn Wu
From: Alice Chen <[email protected]>
Add Mediatek MT6370 flashlight binding documentation
Signed-off-by Alice Chen <[email protected]>--- .../leds/mediatek,mt6370-flashlight.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:./Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml: $id: relative path/filename doesn't match actual path or filename
expected: http://devicetree.org/schemas/leds/mediatek,mt6370-flashlight.yaml#
doc reference errors (make refcheckdocs):
Warning: Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml references a file that doesn't exist: Documentation/devicetree/bindings/mfd/mt6370.yaml Documentation/devicetree/bindings/leds/mediatek,mt6370-flashlight.yaml: Documentation/devicetree/bindings/mfd/mt6370.yaml
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
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.
Re: [RESEND 04/14] dt-bindings: leds: Add Mediatek MT6370 flashlight binding
In reply to ChiaEn WuQuoted 4 lines · ChiaEn Wu
From: Alice Chen <[email protected]>
Add Mediatek MT6370 flashlight binding documentation
Please apply my previous comments.
Best regards,
Krzysztof
PATCH RESEND 5/14 dt-bindings: backlight: Add Mediatek MT6370 backlight binding
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add mt6370 backlight binding documentation.
--- .../backlight/mediatek,mt6370-backlight.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml
Documentation/devicetree/bindings/leds/backlight/mediatek,mt6370-backlight.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# 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: | + 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. + + For the LCD backlight, it can provide 4 channel WLED driving capability. + Each channel driving current is up to 30mA + +allOf: + - $ref: common.yaml# + +properties: + compatible: + const: mediatek,mt6370-backlight + + default-brightness: + minimum: 0 + maximum: 2048 + + max-brightness: + minimum: 0 + maximum: 2048 + + 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-sel: + $ref: /schemas/types.yaml#/definitions/uint8 + enum: [0, 1, 2, 3] + description: | + Backlight PWM hysteresis input level selection. + value mapping: + - 0: 1bit + - 1: 2bit + - 2: 4bit + - 3: 6bit + + mediatek,bled-ovp-shutdown: + description: | + Enable the backlight shutdown when OVP level triggered + type: boolean + + mediatek,bled-ovp-level-sel: + $ref: /schemas/types.yaml#/definitions/uint8 + enum: [0, 1, 2, 3] + description: | + Backlight OVP level selection. + value mapping: + - 0: 17V + - 1: 21V + - 2: 25V + - 3: 29V + + mediatek,bled-ocp-shutdown: + description: | + Enable the backlight shutdown when OCP level triggerred. + type: boolean + + mediatek,bled-ocp-level-sel: + $ref: /schemas/types.yaml#/definitions/uint8 + enum: [0, 1, 2, 3] + description: | + Backlight OC level selection. + value mapping: + - 0: 900mA + - 1: 1200mA + - 2: 1500mA + - 3: 1800mA + + 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 + +required: + - compatible + - mediatek,bled-channel-use + +additionalProperties: false
Signature · 1 line
2.25.1
Re: [RESEND 05/14] dt-bindings: backlight: Add Mediatek MT6370 backlight binding
Quoted 3 lines · ChiaEn Wu
From: ChiYuan Huang <[email protected]>
Add mt6370 backlight binding documentation.
Please apply my previous comments.
Best regards,
Krzysztof
PATCH RESEND 6/14 dt-bindings: mfd: Add Mediatek MT6370 binding
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add Mediatek MT6370 binding documentation.
--- .../bindings/mfd/mediatek,mt6370.yaml | 282 ++++++++++++++++++ .../dt-bindings/iio/adc/mediatek,mt6370_adc.h | 18 ++ include/dt-bindings/mfd/mediatek,mt6370.h | 83 ++++++ 3 files changed, 383 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml create mode 100644 include/dt-bindings/iio/adc/mediatek,mt6370_adc.h create mode 100644 include/dt-bindings/mfd/mediatek,mt6370.h
Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml new file +282 -0
@@ -0,0 +1,282 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/mediatek,mt6370.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Mediatek MT6370 SubPMIC + +maintainers: + - ChiYuan Huang <[email protected]> + +description: | + 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. + +properties: + compatible: + const: mediatek,mt6370 + + reg: + maxItems: 1 + + wakeup-source: true + + interrupts: + maxItems: 1 + + interrupt-controller: true + + '#interrupt-cells': + const: 1 + + adc: + type: object + description: | + List the compatible configurations of MT6370 ADC. + + properties: + compatible: + const: mediatek,mt6370-adc + + "#io-channel-cells": + const: 1 + + required: + - compatible + - '#io-channel-cells' + + backlight: + type: object + $ref: /schemas/leds/backlight/mediatek,mt6370-backlight.yaml# + + charger: + type: object + $ref: /schemas/power/supply/mediatek,mt6370-charger.yaml# + + tcpc: + type: object + $ref: /schemas/usb/mediatek,mt6370-tcpc.yaml# + + indicator: + type: object + $ref: /schemas/leds/mediatek,mt6370-indicator.yaml# + + flashlight: + type: object + $ref: /schemas/leds/mediatek,mt6370-flashlight.yaml# + + regulators: + type: object + description: | + List all supported regulators + + patternProperties: + "^(dsvbst|vibldo)$": + $ref: /schemas/regulator/regulator.yaml# + type: object + unevaluatedProperties: false + + "^(dsvpos|dsvneg)$": + $ref: /schemas/regulator/regulator.yaml# + type: object + unevaluatedProperties: false + + properties: + enable-gpio: + maxItems: 1 + description: | + Specify a valid 'enable' gpio for the regulator and it's optional + +required: + - compatible + - reg + - interrupts + - interrupt-controller + - '#interrupt-cells' + - regulators + - adc + - backlight + - indicator + - tcpc + - charger + - flashlight + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + #include <dt-bindings/leds/common.h> + #include <dt-bindings/mfd/mediatek,mt6370.h> + #include <dt-bindings/iio/adc/mediatek,mt6370_adc.h> + #include <dt-bindings/usb/pd.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + mt6370@34 { + compatible = "mediatek,mt6370"; + reg = <0x34>; + wakeup-source; + interrupts-extended = <&gpio26 3 IRQ_TYPE_LEVEL_LOW>; + interrupt-controller; + #interrupt-cells = <1>; + + mt6370_adc: adc { + compatible = "mediatek,mt6370-adc"; + #io-channel-cells = <1>; + }; + + backlight { + compatible = "mediatek,mt6370-backlight"; + mediatek,bled-channel-use = /bits/ 8 <15>; + }; + + charger { + compatible = "mediatek,mt6370-charger"; + interrupts = <MT6370_IRQ_ATTACH>, <MT6370_IRQ_OVPCTRL_UVP_D>, + <MT6370_IRQ_CHG_MIVR>; + interrupt-names = "attach_i", "uvp_d_evt", "mivr"; + io-channels = <&mt6370_adc MT6370_CHAN_IBUS>; + + mt6370_otg_vbus: usb-otg-vbus { + regulator-compatible = "mt6370,otg-vbus"; + regulator-name = "usb-otg-vbus"; + regulator-min-microvolt = <4350000>; + regulator-max-microvolt = <5800000>; + regulator-min-microamp = <500000>; + regulator-max-microamp = <3000000>; + }; + }; + + indicator { + compatible = "mediatek,mt6370-indicator"; + #address-cells = <1>; + #size-cells = <0>; + + multi-led@0 { + reg = <0>; + function = LED_FUNCTION_INDICATOR; + color = <LED_COLOR_ID_RGB>; + led-max-microamp = <24000>; + #address-cells = <1>; + #size-cells = <0>; + mediatek,soft-start = <3>; + led@0 { + reg = <0>; + color = <LED_COLOR_ID_RED>; + }; + led@1 { + reg = <1>; + color = <LED_COLOR_ID_GREEN>; + }; + led@2 { + reg = <2>; + color = <LED_COLOR_ID_BLUE>; + }; + }; + led@3 { + reg = <3>; + function = LED_FUNCTION_INDICATOR; + color = <LED_COLOR_ID_WHITE>; + led-max-microamp = <6000>; + }; + }; + + flashlight { + compatible = "mediatek,mt6370-flashlight"; + #address-cells = <1>; + #size-cells = <0>; + led@0 { + reg = <0>; + led-sources = <0>; + function = LED_FUNCTION_FLASH; + color = <LED_COLOR_ID_WHITE>; + function-enumerator = <1>; + led-max-microamp = <200000>; + flash-max-microamp = <500000>; + flash-max-timeout-us = <1248000>; + }; + led@1 { + reg = <1>; + led-sources = <1>; + function = LED_FUNCTION_FLASH; + color = <LED_COLOR_ID_WHITE>; + function-enumerator = <2>; + led-max-microamp = <200000>; + flash-max-microamp = <500000>; + flash-max-timeout-us = <1248000>; + }; + }; + + tcpc { + compatible = "mediatek,mt6370-tcpc"; + interrupts-extended = <&gpio26 4 IRQ_TYPE_LEVEL_LOW>; + + connector { + compatible = "usb-c-connector"; + label = "USB-C"; + vbus-supply = <&mt6370_otg_vbus>; + data-role = "dual"; + power-role = "dual"; + try-power-role = "sink"; + source-pdos = <PDO_FIXED(5000, 1000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>; + sink-pdos = <PDO_FIXED(5000, 2000, PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP)>; + op-sink-microwatt = <10000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + endpoint { + remote-endpoint = <&usb_hs>; + }; + }; + port@1 { + reg = <1>; + endpoint { + remote-endpoint = <&usb_ss>; + }; + }; + port@2 { + reg = <2>; + endpoint { + remote-endpoint = <&dp_aux>; + }; + }; + }; + }; + }; + + regulators { + dsvbst { + regulator-name = "mt6370-dsv-vbst"; + regulator-min-microvolt = <4000000>; + regulator-max-microvolt = <6200000>; + }; + dsvpos { + regulator-name = "mt6370-dsv-vpos"; + regulator-min-microvolt = <4000000>; + regulator-max-microvolt = <6000000>; + regulator-boot-on; + }; + dsvneg { + regulator-name = "mt6370-dsv-vneg"; + regulator-min-microvolt = <4000000>; + regulator-max-microvolt = <6000000>; + regulator-boot-on; + }; + vibldo { + regulator-name = "mt6370-vib-ldo"; + regulator-min-microvolt = <1600000>; + regulator-max-microvolt = <4000000>; + }; + }; + }; + };
include/dt-bindings/iio/adc/mediatek,mt6370_adc.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __DT_BINDINGS_MEDIATEK_MT6370_ADC_H__ +#define __DT_BINDINGS_MEDIATEK_MT6370_ADC_H__ + +/* ADC Channel Index */ +#define MT6370_CHAN_VBUSDIV5 0 +#define MT6370_CHAN_VBUSDIV2 1 +#define MT6370_CHAN_VSYS 2 +#define MT6370_CHAN_VBAT 3 +#define MT6370_CHAN_TS_BAT 4 +#define MT6370_CHAN_IBUS 5 +#define MT6370_CHAN_IBAT 6 +#define MT6370_CHAN_CHG_VDDP 7 +#define MT6370_CHAN_TEMP_JC 8 +#define MT6370_CHAN_MAX 9 + +#endif
include/dt-bindings/mfd/mediatek,mt6370.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.25.1
Rob Herring
maintainerRe: [RESEND 06/14] dt-bindings: mfd: Add Mediatek MT6370 binding
Quoted 5 lines · ChiaEn Wu
From: ChiYuan Huang <[email protected]>
Add Mediatek MT6370 binding documentation.
Signed-off-by ChiYuan Huang <[email protected]>
Quoted 9 lines
--- .../bindings/mfd/mediatek,mt6370.yaml | 282 ++++++++++++++++++ .../dt-bindings/iio/adc/mediatek,mt6370_adc.h | 18 ++ include/dt-bindings/mfd/mediatek,mt6370.h | 83 ++++++ 3 files changed, 383 insertions(+) create mode 100644 Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml create mode 100644 include/dt-bindings/iio/adc/mediatek,mt6370_adc.h create mode 100644 include/dt-bindings/mfd/mediatek,mt6370.h
My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):
yamllint warnings/errors:
dtschema/dtc warnings/errors:./Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml: Unable to find schema file matching $id: http://devicetree.org/schemas/power/supply/mediatek,mt6370-charger.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb: mt6370@34: charger: False schema does not allow {'compatible': ['mediatek,mt6370-charger'], 'interrupts': [[48], [68], [6]], 'interrupt-names': ['attach_i', 'uvp_d_evt', 'mivr'], 'io-channels': [[1, 5]], 'usb-otg-vbus': {'regulator-compatible': ['mt6370,otg-vbus'], 'regulator-name': ['usb-otg-vbus'], 'regulator-min-microvolt': [[4350000]], 'regulator-max-microvolt': [[5800000]], 'regulator-min-microamp': [[500000]], 'regulator-max-microamp': [[3000000]], 'phandle': [[2]]}}
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb: mt6370@34: tcpc: False schema does not allow {'compatible': ['mediatek,mt6370-tcpc'], 'interrupts-extended': [[4294967295, 4, 8]], 'connector': {'compatible': ['usb-c-connector'], 'label': ['USB-C'], 'vbus-supply': [[2]], 'data-role': ['dual'], 'power-role': ['dual'], 'try-power-role': ['sink'], 'source-pdos': [[570527844]], 'sink-pdos': [[570527944]], 'op-sink-microwatt': [[10000000]], 'ports': {'#address-cells': [[1]], '#size-cells': [[0]], 'port@0': {'reg': [[0]], 'endpoint': {'remote-endpoint': [[4294967295]]}}, 'port@1': {'reg': [[1]], 'endpoint': {'remote-endpoint': [[4294967295]]}}, 'port@2': {'reg': [[2]], 'endpoint': {'remote-endpoint': [[4294967295]]}}}}}
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb: mt6370@34: indicator: False schema does not allow {'compatible': ['mediatek,mt6370-indicator'], '#address-cells': [[1]], '#size-cells': [[0]], 'multi-led@0': {'reg': [[0]], 'function': ['indicator'], 'color': [[9]], 'led-max-microamp': [[24000]], '#address-cells': [[1]], '#size-cells': [[0]], 'mediatek,soft-start': [[3]], 'led@0': {'reg': [[0]], 'color': [[1]]}, 'led@1': {'reg': [[1]], 'color': [[2]]}, 'led@2': {'reg': [[2]], 'color': [[3]]}}, 'led@3': {'reg': [[3]], 'function': ['indicator'], 'color': [[0]], 'led-max-microamp': [[6000]]}}
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.yaml
/builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb: mt6370@34: flashlight: False schema does not allow {'compatible': ['mediatek,mt6370-flashlight'], '#address-cells': [[1]], '#size-cells': [[0]], 'led@0': {'reg': [[0]], 'led-sources': [[0]], 'function': ['flash'], 'color': [[0]], 'function-enumerator': [[1]], 'led-max-microamp': [[200000]], 'flash-max-microamp': [[500000]], 'flash-max-timeout-us': [[1248000]]}, 'led@1': {'reg': [[1]], 'led-sources': [[1]], 'function': ['flash'], 'color': [[0]], 'function-enumerator': [[2]], 'led-max-microamp': [[200000]], 'flash-max-microamp': [[500000]], 'flash-max-timeout-us': [[1248000]]}}
From schema: /builds/robherring/linux-dt-review/Documentation/devicetree/bindings/mfd/mediatek,mt6370.yamlDocumentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb:0:0: /example-0/i2c/mt6370@34/charger: failed to match any schema with compatible: ['mediatek,mt6370-charger']Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb:0:0: /example-0/i2c/mt6370@34/indicator: failed to match any schema with compatible: ['mediatek,mt6370-indicator']Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb:0:0: /example-0/i2c/mt6370@34/flashlight: failed to match any schema with compatible: ['mediatek,mt6370-flashlight']Documentation/devicetree/bindings/mfd/mediatek,mt6370.example.dtb:0:0: /example-0/i2c/mt6370@34/tcpc: failed to match any schema with compatible: ['mediatek,mt6370-tcpc']
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/patch/
This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.
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 RESEND 7/14 mfd: mt6370: Add Mediatek MT6370 support
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add Mediatek MT6370 MFD support.
--- drivers/mfd/Kconfig | 13 +++ drivers/mfd/Makefile | 1 + drivers/mfd/mt6370.c | 273 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 drivers/mfd/mt6370.c
drivers/mfd/Kconfig +13 -0
@@ -937,6 +937,19 @@ config MFD_MT6360 PMIC part includes 2-channel BUCKs and 2-channel LDOs LDO part includes 4-channel LDOs +config MFD_MT6370 + tristate "Mediatek MT6370 SubPMIC" + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + depends on I2C + help + Say Y here to enable MT6370 SubPMIC functional support. + It integrate single cell battery charger with adc monitoring, RGB + LEDs, dual channel flashlight, WLED backlight driver, display bias + voltage supply, one general purpose LDO, and cc logic + controller with USBPD commmunication capable. + config MFD_MT6397 tristate "MediaTek MT6397 PMIC Support" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -242,6 +242,7 @@ obj-$(CONFIG_INTEL_SOC_PMIC_BXTWC) += intel_soc_pmic_bxtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTWC) += intel_soc_pmic_chtwc.o obj-$(CONFIG_INTEL_SOC_PMIC_CHTDC_TI) += intel_soc_pmic_chtdc_ti.o obj-$(CONFIG_MFD_MT6360) += mt6360-core.o +obj-$(CONFIG_MFD_MT6370) += mt6370.o mt6397-objs := mt6397-core.o mt6397-irq.o mt6358-irq.o obj-$(CONFIG_MFD_MT6397) += mt6397.o obj-$(CONFIG_INTEL_SOC_PMIC_MRFLD) += intel_soc_pmic_mrfld.o
drivers/mfd/mt6370.c new file +273 -0
273 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH RESEND 8/14 usb: typec: tcpci_mt6370: Add Mediatek MT6370 tcpci driver
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add chip level mt6370 tcpci driver.
--- drivers/usb/typec/tcpm/Kconfig | 8 + drivers/usb/typec/tcpm/Makefile | 1 + drivers/usb/typec/tcpm/tcpci_mt6370.c | 212 ++++++++++++++++++++++++++ 3 files changed, 221 insertions(+) create mode 100644 drivers/usb/typec/tcpm/tcpci_mt6370.c
drivers/usb/typec/tcpm/Kconfig +8 -0
@@ -35,6 +35,14 @@ config TYPEC_MT6360 USB Type-C. It works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities. +config TYPEC_TCPCI_MT6370 + tristate "Mediatek MT6370 Type-C driver" + depends on MFD_MT6370 + help + Mediatek MT6370 is a multi-functional IC that includes + USB Type-C. It works with Type-C Port Controller Manager + to provide USB PD and USB Type-C functionalities. + config TYPEC_TCPCI_MAXIM tristate "Maxim TCPCI based Type-C chip driver" help
drivers/usb/typec/tcpm/Makefile +1 -0
@@ -6,4 +6,5 @@ typec_wcove-y := wcove.o obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o obj-$(CONFIG_TYPEC_RT1711H) += tcpci_rt1711h.o obj-$(CONFIG_TYPEC_MT6360) += tcpci_mt6360.o +obj-$(CONFIG_TYPEC_TCPCI_MT6370) += tcpci_mt6370.o obj-$(CONFIG_TYPEC_TCPCI_MAXIM) += tcpci_maxim.o
drivers/usb/typec/tcpm/tcpci_mt6370.c new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH RESEND 9/14 regulator: mt6370: Add mt6370 DisplayBias and VibLDO support
In reply to ChiaEn WuFrom: ChiYuan Huang <[email protected]>
Add mt6370 DisplayBias and VibLDO support.
--- drivers/regulator/Kconfig | 8 + drivers/regulator/Makefile | 1 + drivers/regulator/mt6370-regulator.c | 389 +++++++++++++++++++++++++++ 3 files changed, 398 insertions(+) create mode 100644 drivers/regulator/mt6370-regulator.c
drivers/regulator/Kconfig +8 -0
@@ -804,6 +804,14 @@ config REGULATOR_MT6360 2-channel buck with Thermal Shutdown and Overload Protection 6-channel High PSRR and Low Dropout LDO. +config REGULATOR_MT6370 + tristate "MT6370 SubPMIC Regulator" + depends on MFD_MT6370 + help + Say Y here to enable MT6370 regulator support. + This driver support the control for DisplayBias voltages and one + general purpose LDO which commonly used to drive the vibrator. + config REGULATOR_MT6380 tristate "MediaTek MT6380 PMIC" depends on MTK_PMIC_WRAP
drivers/regulator/Makefile +1 -0
@@ -97,6 +97,7 @@ obj-$(CONFIG_REGULATOR_MT6323) += mt6323-regulator.o obj-$(CONFIG_REGULATOR_MT6358) += mt6358-regulator.o obj-$(CONFIG_REGULATOR_MT6359) += mt6359-regulator.o obj-$(CONFIG_REGULATOR_MT6360) += mt6360-regulator.o +obj-$(CONFIG_REGULATOR_MT6370) += mt6370-regulator.o obj-$(CONFIG_REGULATOR_MT6380) += mt6380-regulator.o obj-$(CONFIG_REGULATOR_MT6397) += mt6397-regulator.o obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.o
drivers/regulator/mt6370-regulator.c new file +389 -0
389 lines not on this page · raw message
Signature · 7 lines
2.25.1 _______________________________________________ Linux-mediatek mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-mediatek
PATCH RESEND 10/14 iio: adc: mt6370: Add Mediatek MT6370 support
In reply to ChiaEn WuFrom: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 ADC support.
--- drivers/iio/adc/Kconfig | 9 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6370-adc.c | 257 +++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/iio/adc/mt6370-adc.c
drivers/iio/adc/Kconfig +9 -0
@@ -737,6 +737,15 @@ 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 Y here to enable MT6370 ADC support. + Integrated for System Monitoring includes + is used in smartphones and tablets and supports a 9 channel + general purpose ADC. + config MEDIATEK_MT6577_AUXADC tristate "MediaTek AUXADC driver" depends on ARCH_MEDIATEK || COMPILE_TEST
drivers/iio/adc/Makefile +1 -0
@@ -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 +257 -0
257 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [RESEND 10/14] iio: adc: mt6370: Add Mediatek MT6370 support
Quoted 5 lines · On Tue, 31 May 2022 19:18:56 +0800 ChiaEn Wu <[email protected]> wrote:
From: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 ADC support.
Signed-off-by ChiaEn Wu <[email protected]>
Hi ChiaEn,
A few comments inline.
Thanks,
Jonathan
Quoted 12 lines
--- drivers/iio/adc/Kconfig | 9 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6370-adc.c | 257 +++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/iio/adc/mt6370-adc.cdrivers/iio/adc/Kconfig +0
-0
drivers/iio/adc/Kconfig config MEDIATEK_MT6360_ADC · line 745
Quoted 9 lines
drivers/iio/adc/Kconfig +6
-0@@ -737,6 +737,15 @@ 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 Y here to enable MT6370 ADC support. + Integrated for System Monitoring includes
The wrapping of this text needs cleaning up.
Quoted 24 lines
drivers/iio/adc/Kconfig +3
-0+ is used in smartphones and tablets and supports a 9 channel + general purpose ADC. + config MEDIATEK_MT6577_AUXADC tristate "MediaTek AUXADC driver" depends on ARCH_MEDIATEK || COMPILE_TESTdrivers/iio/adc/Makefile +1
-0@@ -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.odrivers/iio/adc/mt6370-adc.c new file +0
-0
drivers/iio/adc/mt6370-adc.c line 7
Quoted 7 lines
drivers/iio/adc/mt6370-adc.c new file +7
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <dt-bindings/iio/adc/mediatek,mt6370_adc.h> +#include <linux/bits.h> +#include <linux/bitfield.h> +#include <linux/iio/iio.h> +#include <linux/irq.h>
Not seeing any interrupt support in here.
Quoted 6 lines
drivers/iio/adc/mt6370-adc.c new file +6
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> +
drivers/iio/adc/mt6370-adc.c line 23
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+#define MT6370_REG_CHG_CTRL3 0x113/* AICR */ +#define MT6370_REG_CHG_CTRL7 0x117/* ICHG */ +#define MT6370_REG_CHG_ADC 0x121 +#define MT6370_REG_ADC_DATA_H 0x14C + +#define MT6370_ADC_START_MASK BIT(0) +#define MT6370_ADC_IN_SEL_MASK GENMASK(7, 4) +#define MT6370_AICR_ICHG_MASK GENMASK(7, 2) + +#define MT6370_ADC_CHAN_SHIFT 4
Prefer using a mask and then FIELD_PREP
drivers/iio/adc/mt6370-adc.c line 35
Quoted 12 lines
drivers/iio/adc/mt6370-adc.c new file +12
-0+ +#define MT6370_AICR_400MA 0x6 +#define MT6370_ICHG_500MA 0x4 +#define MT6370_ICHG_900MA 0x8 + +#define ADC_CONV_TIME_US 35000 +#define ADC_CONV_POLLING_TIME 1000 + +struct mt6370_adc_data { +struct device *dev; +struct regmap *regmap; +struct mutex lock;
All locks need documentation. What is the scope of the lock? Looks like it protects device state when doing setup, wait for read, read cycles.
drivers/iio/adc/mt6370-adc.c line 47
Quoted 12 lines
drivers/iio/adc/mt6370-adc.c new file +12
-0+}; + +static int mt6370_adc_read_channel (struct mt6370_adc_data *priv,int chan, +unsigned long addr,int *val) +{ +__be16 be_val; +unsigned int reg_val; +int ret; + +mutex_lock (&priv->lock); + + reg_val =MT6370_ADC_START_MASK | (addr <<MT6370_ADC_CHAN_SHIFT );
FIELD_PREP for that shift?
Quoted 32 lines
drivers/iio/adc/mt6370-adc.c new file +32
-0+ ret =regmap_write (priv->regmap,MT6370_REG_CHG_ADC , reg_val); +if (ret) + goto adc_unlock; + +msleep (ADC_CONV_TIME_US /1000 ); + + ret =regmap_read_poll_timeout (priv->regmap, +MT6370_REG_CHG_ADC , reg_val, + !(reg_val &MT6370_ADC_START_MASK ), +ADC_CONV_POLLING_TIME , +ADC_CONV_TIME_US *3 ); +if (ret) { +if (ret == -ETIMEDOUT ) +dev_err (priv->dev,"Failed to wait adc conversion\n" ); + goto adc_unlock; + } + + ret =regmap_raw_read (priv->regmap,MT6370_REG_ADC_DATA_H , + &be_val,sizeof (be_val)); +if (ret) + goto adc_unlock; + + *val =be16_to_cpu (be_val); + ret =IIO_VAL_INT ; + +adc_unlock: +mutex_unlock (&priv->lock); + +return ret; +} + +static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,
drivers/iio/adc/mt6370-adc.c line 89
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+ int chan, int *val1, int *val2) +{ + unsigned int reg_val; +int ret; + +switch (chan) { +case MT6370_CHAN_VBAT : +case MT6370_CHAN_VSYS : +case MT6370_CHAN_CHG_VDDP : + *val1 =5000 ;
This seems very large. Voltages are in millivolts as per Documentation/ABI/testing/sysfs-bus-iio and this means each step is 5 volts.
So value in mv is currently 5 * _raw
Quoted 40 lines
drivers/iio/adc/mt6370-adc.c new file +40
-0+return IIO_VAL_INT ; +case MT6370_CHAN_IBUS : + ret =regmap_read (priv->regmap,MT6370_REG_CHG_CTRL3 , ®_val); +if (ret) +return ret; + + reg_val =FIELD_GET (MT6370_AICR_ICHG_MASK , reg_val); +if (reg_val <MT6370_AICR_400MA ) + *val1 =33500 ; +else + *val1 =50000 ; + +return IIO_VAL_INT ; +case MT6370_CHAN_IBAT : + ret =regmap_read (priv->regmap,MT6370_REG_CHG_CTRL7 , ®_val); +if (ret) +return ret; + + reg_val =FIELD_GET (MT6370_AICR_ICHG_MASK , reg_val); +if (reg_val <MT6370_ICHG_500MA ) + *val1 =23750 ; +else if (reg_val >=MT6370_ICHG_500MA && + reg_val <MT6370_ICHG_900MA ) + *val1 =26800 ; +else + *val1 =50000 ; + +return IIO_VAL_INT ; +case MT6370_CHAN_VBUSDIV5 : + *val1 =25000 ; +return IIO_VAL_INT ; +case MT6370_CHAN_VBUSDIV2 : + *val1 =50000 ; +return IIO_VAL_INT ; +case MT6370_CHAN_TS_BAT : + *val1 =25 ; + *val2 =10000 ; +return IIO_VAL_FRACTIONAL ; +case MT6370_CHAN_TEMP_JC : + *val1 =2 ;
drivers/iio/adc/mt6370-adc.c line 139
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+return IIO_VAL_INT ; + } + +return -EINVAL ; +} + +static int mt6370_adc_read_offset (struct mt6370_adc_data *priv, +int chan,int *val) +{ + *val = (chan ==MT6370_CHAN_TEMP_JC ) ?-20 :0 ;
Offset default is 0, so for channels where it doesn't apply don't provide the offset attribute at all.
Quoted 13 lines
drivers/iio/adc/mt6370-adc.c new file +13
-0+return IIO_VAL_INT ; +} + +static int mt6370_adc_read_raw (struct iio_dev *iio_dev, +const struct iio_chan_spec *chan, +int *val,int *val2,long mask) +{ +struct mt6370_adc_data *priv =iio_priv (iio_dev); + +switch (mask) { +case IIO_CHAN_INFO_RAW : +return mt6370_adc_read_channel (priv, chan->channel, + chan->address, val);
drivers/iio/adc/mt6370-adc.c line 162
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+case IIO_CHAN_INFO_SCALE : +return mt6370_adc_read_scale (priv, chan->channel, val, val2); +case IIO_CHAN_INFO_OFFSET : +return mt6370_adc_read_offset (priv, chan->channel, val); + } + +return -EINVAL ; +} + +static const char *const mt6370_channel_labels[MT6370_CHAN_MAX ] = {
Perhaps define an enum with which to index this and the chan spec and hence ensure they end up matching.
[vbusdiv5] = "vbusdiv5", etc
Quoted 16 lines
drivers/iio/adc/mt6370-adc.c new file +16
-0+"vbusdiv5" ,"vbusdiv2" ,"vsys" ,"vbat" , +"ts_bat" ,"ibus" ,"ibat" ,"chg_vddp" , + "temp_jc", +}; + +static int mt6370_adc_read_label (struct iio_dev *iio_dev, +struct iio_chan_spec const *chan,char *label) +{ +return snprintf (label,PAGE_SIZE ,"%s\n" , + mt6370_channel_labels[chan->channel]); +} + +static const struct iio_info mt6370_adc_iio_info = { + .read_raw = mt6370_adc_read_raw, + .read_label = mt6370_adc_read_label, +};
drivers/iio/adc/mt6370-adc.c line 188
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+ +#define MT6370_ADC_CHAN (_idx, _type, _addr) { \ + .type = _type, \ + .channel = MT6370_CHAN_##_idx, \ + .address = _addr, \ + .scan_index = MT6370_CHAN_##_idx, \ + .indexed = 1, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_OFFSET), \
See above. Only temp_jc channel should hav an offset.
Quoted 33 lines
drivers/iio/adc/mt6370-adc.c new file +33
-0+} + +static const struct iio_chan_spec mt6370_adc_channels[] = { +MT6370_ADC_CHAN (VBUSDIV5 ,IIO_VOLTAGE ,1 ), +MT6370_ADC_CHAN (VBUSDIV2 ,IIO_VOLTAGE ,2 ), +MT6370_ADC_CHAN (VSYS ,IIO_VOLTAGE ,3 ), +MT6370_ADC_CHAN (VBAT ,IIO_VOLTAGE ,4 ), +MT6370_ADC_CHAN (TS_BAT ,IIO_VOLTAGE ,6 ), +MT6370_ADC_CHAN (IBUS ,IIO_CURRENT ,8 ), +MT6370_ADC_CHAN (IBAT ,IIO_CURRENT ,9 ), +MT6370_ADC_CHAN (CHG_VDDP ,IIO_VOLTAGE ,11 ), +MT6370_ADC_CHAN (TEMP_JC ,IIO_TEMP ,12 ), +}; + +static int mt6370_adc_probe (struct platform_device *pdev) +{ +int ret; +struct mt6370_adc_data *priv; +struct regmap *regmap; +struct iio_dev *indio_dev; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) { +dev_err (&pdev->dev,"Failed to get regmap\n" ); +return -ENODEV ; + } + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + priv->dev = &pdev->dev;
drivers/iio/adc/mt6370-adc.c line 231
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+ priv->regmap = regmap; +mutex_init (&priv->lock); + + ret =regmap_write (priv->regmap,MT6370_REG_CHG_ADC ,0 ); +if (ret) { +dev_err (&pdev->dev,"Failed to reset adc\n" ); +return ret; + } + + indio_dev->name =dev_name (&pdev->dev);
What does this end up as? It's used for userspace ABI and should correspond to the part number, "mt6370-adc" probably appropriate in this case (I think it'll end up as simply "adc.x" currently?) Normally we just hard code this in the driver for whatever devices the driver supports.
Quoted 26 lines
drivers/iio/adc/mt6370-adc.c new file +26
-0+ indio_dev->info = &mt6370_adc_iio_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = mt6370_adc_channels; + indio_dev->num_channels =ARRAY_SIZE (mt6370_adc_channels); + +return devm_iio_device_register (&pdev->dev, indio_dev); +} + +static const struct of_device_id mt6370_adc_of_id[] = { + { .compatible ="mediatek,mt6370-adc" , }, + {} +}; +MODULE_DEVICE_TABLE (of, mt6370_adc_of_id); + +static struct platform_driver mt6370_adc_driver = { + .driver = { + .name ="mt6370-adc" , + .of_match_table = mt6370_adc_of_id, + }, + .probe = mt6370_adc_probe, +}; +module_platform_driver (mt6370_adc_driver); + +MODULE_AUTHOR ("ChiaEn Wu <[email protected]>" ); +MODULE_DESCRIPTION ("MT6370 ADC Drvier" ); +MODULE_LICENSE ("GPL v2" );
Re: [RESEND 10/14] iio: adc: mt6370: Add Mediatek MT6370 support
Hi Jonathan,
Sorry for sending the same email again. I miss to reply all in the last email..
Thanks for your valuable suggestions!
Jonathan Cameron <[email protected]> 於 2022年5月31日 週二 下午9:21寫道:
Quoted 67 lines
Quoted 5 lines · On Tue, 31 May 2022 19:18:56 +0800 ChiaEn Wu <[email protected]> wrote:
From: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 ADC support.
Signed-off-by ChiaEn Wu <[email protected]>Hi ChiaEn,
A few comments inline.
Thanks,
Jonathan
Quoted 12 lines
--- drivers/iio/adc/Kconfig | 9 ++ drivers/iio/adc/Makefile | 1 + drivers/iio/adc/mt6370-adc.c | 257 +++++++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/iio/adc/mt6370-adc.cdrivers/iio/adc/Kconfig +0
-0drivers/iio/adc/Kconfig config MEDIATEK_MT6360_ADC · line 745
Quoted 9 lines
drivers/iio/adc/Kconfig +6
-0@@ -737,6 +737,15 @@ 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 Y here to enable MT6370 ADC support. + Integrated for System Monitoring includesThe wrapping of this text needs cleaning up.
Quoted 25 lines
drivers/iio/adc/Kconfig +3
-0+ is used in smartphones and tablets and supports a 9 channel + general purpose ADC. + config MEDIATEK_MT6577_AUXADC tristate "MediaTek AUXADC driver" depends on ARCH_MEDIATEK || COMPILE_TESTdrivers/iio/adc/Makefile +1
-0@@ -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.odrivers/iio/adc/mt6370-adc.c new file +1
-0@@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0
Quoted 8 lines
drivers/iio/adc/mt6370-adc.c line 7
Quoted 6 lines
drivers/iio/adc/mt6370-adc.c new file +6
-0+ +#include <dt-bindings/iio/adc/mediatek,mt6370_adc.h> +#include <linux/bits.h> +#include <linux/bitfield.h> +#include <linux/iio/iio.h> +#include <linux/irq.h> Not seeing any interrupt support in here.
Sorry for that I forgot remove this line, I'll refine it in the next patch.
Quoted 12 lines
Quoted 12 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define MT6370_REG_CHG_CTRL3 0x113/* AICR */ +#define MT6370_REG_CHG_CTRL7 0x117/* ICHG */ +#define MT6370_REG_CHG_ADC 0x121 +#define MT6370_REG_ADC_DATA_H 0x14C
Quoted 8 lines
drivers/iio/adc/mt6370-adc.c line 23
Quoted 6 lines
drivers/iio/adc/mt6370-adc.c new file +6
-0+ +#define MT6370_ADC_START_MASK BIT(0) +#define MT6370_ADC_IN_SEL_MASK GENMASK(7, 4) +#define MT6370_AICR_ICHG_MASK GENMASK(7, 2) + +#define MT6370_ADC_CHAN_SHIFT 4Prefer using a mask and then
FIELD_PREP
OK, I got it!
Quoted 17 lines
drivers/iio/adc/mt6370-adc.c line 35
Quoted 13 lines
drivers/iio/adc/mt6370-adc.c new file +12
-0+ +#define MT6370_AICR_400MA 0x6 +#define MT6370_ICHG_500MA 0x4 +#define MT6370_ICHG_900MA 0x8 + +#define ADC_CONV_TIME_US 35000 +#define ADC_CONV_POLLING_TIME 1000 + +struct mt6370_adc_data { +struct device *dev; +struct regmap *regmap; +struct mutex lock;All locks need documentation. What is the scope of the lock? Looks like it protects device state when doing setup, wait for read, read cycles.
This mutex lock is for preventing the different adc channel from being read at the same time.
So, if I just change its name to adc_chan_lock or adc_lock and add the comment for this mutex lock, does this change meet your requirement?
Quoted 15 lines
drivers/iio/adc/mt6370-adc.c line 47
Quoted 13 lines
drivers/iio/adc/mt6370-adc.c new file +12
-0+}; + +static int mt6370_adc_read_channel (struct mt6370_adc_data *priv,int chan, +unsigned long addr,int *val) +{ +__be16 be_val; +unsigned int reg_val; +int ret; + +mutex_lock (&priv->lock); + + reg_val =MT6370_ADC_START_MASK | (addr <<MT6370_ADC_CHAN_SHIFT );
FIELD_PREPfor that shift?
I got it! I'll refine it in the next patch.
Quoted 48 lines
Quoted 33 lines
drivers/iio/adc/mt6370-adc.c new file +32
-0+ ret =regmap_write (priv->regmap,MT6370_REG_CHG_ADC , reg_val); +if (ret) + goto adc_unlock; + +msleep (ADC_CONV_TIME_US /1000 ); + + ret =regmap_read_poll_timeout (priv->regmap, +MT6370_REG_CHG_ADC , reg_val, + !(reg_val &MT6370_ADC_START_MASK ), +ADC_CONV_POLLING_TIME , +ADC_CONV_TIME_US *3 ); +if (ret) { +if (ret == -ETIMEDOUT ) +dev_err (priv->dev,"Failed to wait adc conversion\n" ); + goto adc_unlock; + } + + ret =regmap_raw_read (priv->regmap,MT6370_REG_ADC_DATA_H , + &be_val,sizeof (be_val)); +if (ret) + goto adc_unlock; + + *val =be16_to_cpu (be_val); + ret =IIO_VAL_INT ; + +adc_unlock: +mutex_unlock (&priv->lock); + +return ret; +} + +static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,drivers/iio/adc/mt6370-adc.c line 89
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+ int chan, int *val1, int *val2) +{ + unsigned int reg_val; +int ret; + +switch (chan) { +case MT6370_CHAN_VBAT : +case MT6370_CHAN_VSYS : +case MT6370_CHAN_CHG_VDDP : + *val1 =5000 ;This seems very large. Voltages are in millivolts as per
Documentation/ABI/testing/sysfs-bus-iioand this means each step is 5 volts.
Quoted 2 lines
So value in mv is currently 5 *
_raw
OK, I got it. Also, I will add the ABI file in the next version. Thanks!
Quoted 47 lines
Quoted 47 lines
drivers/iio/adc/mt6370-adc.c new file +45
-0+return IIO_VAL_INT ; +case MT6370_CHAN_IBUS : + ret =regmap_read (priv->regmap,MT6370_REG_CHG_CTRL3 , ®_val); +if (ret) +return ret; + + reg_val =FIELD_GET (MT6370_AICR_ICHG_MASK , reg_val); +if (reg_val <MT6370_AICR_400MA ) + *val1 =33500 ; +else + *val1 =50000 ; + +return IIO_VAL_INT ; +case MT6370_CHAN_IBAT : + ret =regmap_read (priv->regmap,MT6370_REG_CHG_CTRL7 , ®_val); +if (ret) +return ret; + + reg_val =FIELD_GET (MT6370_AICR_ICHG_MASK , reg_val); +if (reg_val <MT6370_ICHG_500MA ) + *val1 =23750 ; +else if (reg_val >=MT6370_ICHG_500MA && + reg_val <MT6370_ICHG_900MA ) + *val1 =26800 ; +else + *val1 =50000 ; + +return IIO_VAL_INT ; +case MT6370_CHAN_VBUSDIV5 : + *val1 =25000 ; +return IIO_VAL_INT ; +case MT6370_CHAN_VBUSDIV2 : + *val1 =50000 ; +return IIO_VAL_INT ; +case MT6370_CHAN_TS_BAT : + *val1 =25 ; + *val2 =10000 ; +return IIO_VAL_FRACTIONAL ; +case MT6370_CHAN_TEMP_JC : + *val1 =2 ; +return IIO_VAL_INT ; + } + +return -EINVAL ; +}
Quoted 9 lines
drivers/iio/adc/mt6370-adc.c line 139
Quoted 5 lines
drivers/iio/adc/mt6370-adc.c new file +5
-0+ +static int mt6370_adc_read_offset (struct mt6370_adc_data *priv, +int chan,int *val) +{ + *val = (chan ==MT6370_CHAN_TEMP_JC ) ?-20 :0 ;Offset default is 0, so for channels where it doesn't apply don't provide the offset attribute at all.
OK!
Quoted 19 lines
Quoted 19 lines
drivers/iio/adc/mt6370-adc.c new file +19
-0+return IIO_VAL_INT ; +} + +static int mt6370_adc_read_raw (struct iio_dev *iio_dev, +const struct iio_chan_spec *chan, +int *val,int *val2,long mask) +{ +struct mt6370_adc_data *priv =iio_priv (iio_dev); + +switch (mask) { +case IIO_CHAN_INFO_RAW : +return mt6370_adc_read_channel (priv, chan->channel, + chan->address, val); +case IIO_CHAN_INFO_SCALE : +return mt6370_adc_read_scale (priv, chan->channel, val, val2); +case IIO_CHAN_INFO_OFFSET : +return mt6370_adc_read_offset (priv, chan->channel, val); + } +
Quoted 9 lines
drivers/iio/adc/mt6370-adc.c line 162
Quoted 4 lines
drivers/iio/adc/mt6370-adc.c new file +4
-0+return -EINVAL ; +} + +static const char *const mt6370_channel_labels[MT6370_CHAN_MAX ] = {Perhaps define an enum with which to index this and the chan spec and hence ensure they end up matching.
[vbusdiv5] = "vbusdiv5", etc
Do you mean that I can refine this const char array to the following array??
static const char * const mt6370_channel_labels[MT6370_CHAN_MAX] = {
[MT6370_CHAN_VBUSDIV5] = "vbusdiv5",
[MT6370_CHAN_VBUSDIV2] = "vbusdiv2",
...
...
[MT6370_CHAN_TEMP_JC] = "temp_jc",
};Quoted 20 lines
Quoted 20 lines
drivers/iio/adc/mt6370-adc.c new file +20
-0+"vbusdiv5" ,"vbusdiv2" ,"vsys" ,"vbat" , +"ts_bat" ,"ibus" ,"ibat" ,"chg_vddp" , + "temp_jc", +}; + +static int mt6370_adc_read_label (struct iio_dev *iio_dev, +struct iio_chan_spec const *chan,char *label) +{ +return snprintf (label,PAGE_SIZE ,"%s\n" , + mt6370_channel_labels[chan->channel]); +} + +static const struct iio_info mt6370_adc_iio_info = { + .read_raw = mt6370_adc_read_raw, + .read_label = mt6370_adc_read_label, +}; + +#define MT6370_ADC_CHAN (_idx, _type, _addr) { \ + .type = _type, \ + .channel = MT6370_CHAN_##_idx, \
Quoted 9 lines
drivers/iio/adc/mt6370-adc.c line 188
Quoted 6 lines
drivers/iio/adc/mt6370-adc.c new file +6
-0+ .address = _addr, \ + .scan_index = MT6370_CHAN_##_idx, \ + .indexed = 1, \ + .info_mask_separate =BIT (IIO_CHAN_INFO_RAW ) | \ +BIT (IIO_CHAN_INFO_SCALE ) | \ + BIT(IIO_CHAN_INFO_OFFSET), \See above. Only
temp_jcchannel should hav an offset.
OK!
Quoted 41 lines
Quoted 41 lines
drivers/iio/adc/mt6370-adc.c new file +41
-0+} + +static const struct iio_chan_spec mt6370_adc_channels[] = { +MT6370_ADC_CHAN (VBUSDIV5 ,IIO_VOLTAGE ,1 ), +MT6370_ADC_CHAN (VBUSDIV2 ,IIO_VOLTAGE ,2 ), +MT6370_ADC_CHAN (VSYS ,IIO_VOLTAGE ,3 ), +MT6370_ADC_CHAN (VBAT ,IIO_VOLTAGE ,4 ), +MT6370_ADC_CHAN (TS_BAT ,IIO_VOLTAGE ,6 ), +MT6370_ADC_CHAN (IBUS ,IIO_CURRENT ,8 ), +MT6370_ADC_CHAN (IBAT ,IIO_CURRENT ,9 ), +MT6370_ADC_CHAN (CHG_VDDP ,IIO_VOLTAGE ,11 ), +MT6370_ADC_CHAN (TEMP_JC ,IIO_TEMP ,12 ), +}; + +static int mt6370_adc_probe (struct platform_device *pdev) +{ +int ret; +struct mt6370_adc_data *priv; +struct regmap *regmap; +struct iio_dev *indio_dev; + + regmap =dev_get_regmap (pdev->dev.parent,NULL ); +if (!regmap) { +dev_err (&pdev->dev,"Failed to get regmap\n" ); +return -ENODEV ; + } + + indio_dev =devm_iio_device_alloc (&pdev->dev,sizeof (*priv)); +if (!indio_dev) +return -ENOMEM ; + + priv =iio_priv (indio_dev); + priv->dev = &pdev->dev; + priv->regmap = regmap; +mutex_init (&priv->lock); + + ret =regmap_write (priv->regmap,MT6370_REG_CHG_ADC ,0 ); +if (ret) { +dev_err (&pdev->dev,"Failed to reset adc\n" ); +return ret; + }
Quoted 8 lines
drivers/iio/adc/mt6370-adc.c line 231
Quoted 2 lines
drivers/iio/adc/mt6370-adc.c new file +2
-0+ + indio_dev->name =dev_name (&pdev->dev);What does this end up as? It's used for userspace ABI and should correspond to the part number, "mt6370-adc" probably appropriate in this case (I think it'll end up as simply "adc.x" currently?) Normally we just hard code this in the driver for whatever devices the driver supports.
I got it, I will change this name to "mt6370-adc" in the next version! Thanks!
Quoted 19 lines
Quoted 19 lines
drivers/iio/adc/mt6370-adc.c new file +18
-0+ indio_dev->info = &mt6370_adc_iio_info; + indio_dev->modes =INDIO_DIRECT_MODE ; + indio_dev->channels = mt6370_adc_channels; + indio_dev->num_channels =ARRAY_SIZE (mt6370_adc_channels); + +return devm_iio_device_register (&pdev->dev, indio_dev); +} + +static const struct of_device_id mt6370_adc_of_id[] = { + { .compatible ="mediatek,mt6370-adc" , }, + {} +}; +MODULE_DEVICE_TABLE (of, mt6370_adc_of_id); + +static struct platform_driver mt6370_adc_driver = { + .driver = { + .name ="mt6370-adc" , + .of_match_table = mt6370_adc_of_id,
Quoted 9 lines
drivers/iio/adc/mt6370-adc.c line 257
Quoted 8 lines
drivers/iio/adc/mt6370-adc.c new file +8
-0+ }, + .probe = mt6370_adc_probe, +}; +module_platform_driver (mt6370_adc_driver); + +MODULE_AUTHOR ("ChiaEn Wu <[email protected]>" ); +MODULE_DESCRIPTION ("MT6370 ADC Drvier" ); +MODULE_LICENSE ("GPL v2" );
Best regards,
ChiaEn Wu
Jonathan Cameron
maintainerRe: [RESEND 10/14] iio: adc: mt6370: Add Mediatek MT6370 support
Quoted 18 lines
Quoted 17 lines
drivers/iio/adc/mt6370-adc.c line 35
Quoted 13 lines
drivers/iio/adc/mt6370-adc.c new file +12
-0+ +#define MT6370_AICR_400MA 0x6 +#define MT6370_ICHG_500MA 0x4 +#define MT6370_ICHG_900MA 0x8 + +#define ADC_CONV_TIME_US 35000 +#define ADC_CONV_POLLING_TIME 1000 + +struct mt6370_adc_data { +struct device *dev; +struct regmap *regmap; +struct mutex lock;All locks need documentation. What is the scope of the lock? Looks like it protects device state when doing setup, wait for read, read cycles.
Quoted 4 lines
This mutex lock is for preventing the different adc channel from being read at the same time.
So, if I just change its name toadc_chan_lockoradc_lockand add the comment for this mutex lock, does this change meet your requirement
Yes
Quoted 20 lines
Quoted 20 lines
Quoted 5 lines
drivers/iio/adc/mt6370-adc.c new file +3
-0+}; + +static int mt6370_adc_read_scale(struct mt6370_adc_data *priv,drivers/iio/adc/mt6370-adc.c line 89
Quoted 10 lines
drivers/iio/adc/mt6370-adc.c new file +10
-0+ int chan, int *val1, int *val2) +{ + unsigned int reg_val; +int ret; + +switch (chan) { +case MT6370_CHAN_VBAT : +case MT6370_CHAN_VSYS : +case MT6370_CHAN_CHG_VDDP : + *val1 =5000 ;This seems very large. Voltages are in millivolts as per
Documentation/ABI/testing/sysfs-bus-iioand this means each step is 5 volts.
Quoted 4 lines
Quoted 2 lines
So value in mv is currently 5 *
_rawOK, I got it. Also, I will add the ABI file in the next version. Thanks!
Only add ABI documentation for anything non-standard.
The documentation scripts really don't like repeats!
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
+static const char * const mt6370_channel_labels[MT6370_CHAN_MAX] = {
Perhaps define an enum with which to index this and the chan spec and hence ensure they end up matching.
[vbusdiv5] = "vbusdiv5", etcDo you mean that I can refine this const char array to the following array??
Quoted 7 lines
static const char * const mt6370_channel_labels[MT6370_CHAN_MAX] = {
[MT6370_CHAN_VBUSDIV5] = "vbusdiv5",
[MT6370_CHAN_VBUSDIV2] = "vbusdiv2",
...
...
[MT6370_CHAN_TEMP_JC] = "temp_jc",
};Yes
thanks,
Jonathan
PATCH RESEND 11/14 power: supply: mt6370: Add Mediatek MT6370 charger driver
In reply to ChiaEn WuFrom: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 charger driver
--- drivers/power/supply/Kconfig | 11 + drivers/power/supply/Makefile | 1 + drivers/power/supply/mt6370-charger.c | 1132 +++++++++++++++++++++++++ 3 files changed, 1144 insertions(+) create mode 100644 drivers/power/supply/mt6370-charger.c
drivers/power/supply/Kconfig +11 -0
@@ -619,6 +619,17 @@ 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. + 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
@@ -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 +1132 -0
1,132 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH RESEND 12/14 leds: mt6370: Add Mediatek MT6370 Indicator support
In reply to ChiaEn WuFrom: Alice Chen <[email protected]>
Add Mediatek MT6370 Indicator support
--- drivers/leds/Kconfig | 11 + drivers/leds/Makefile | 1 + drivers/leds/leds-mt6370.c | 994 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1006 insertions(+) create mode 100644 drivers/leds/leds-mt6370.c
drivers/leds/Kconfig +11 -0
@@ -244,6 +244,17 @@ config LEDS_MT6323 This option enables support for on-chip LED drivers found on Mediatek MT6323 PMIC. +config LEDS_MT6370_RGB + tristate "LED Support for Mediatek MT6370 PMIC" + depends on LEDS_CLASS + depends on MFD_MT6370 + select LINEAR_RANGE + help + Support 4 channels and reg/pwm/breath mode. + Isink4 can also use as a CHG_VIN power good Indicator. + Say Y here to enable support for + MT6370_RGB_LED device. + config LEDS_S3C24XX tristate "LED Support for Samsung S3C24XX GPIO LEDs" depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
@@ -62,6 +62,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_MT6370_RGB) += leds-mt6370.o obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o obj-$(CONFIG_LEDS_NETXBIG) += leds-netxbig.o obj-$(CONFIG_LEDS_NIC78BX) += leds-nic78bx.o
drivers/leds/leds-mt6370.c new file +994 -0
994 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botRe: [RESEND 12/14] leds: mt6370: Add Mediatek MT6370 Indicator support
Thank you for the patch! Yet something to improve:
Hi ChiaEn,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on pavel-leds/for-next]
[also build test ERROR on lee-mfd/for-mfd-next lee-backlight/for-backlight-next v5.19-rc1 next-20220606] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/ChiaEn-Wu/Add-Mediatek-MT6370-PMIC-support/20220531-211432 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20220606/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/4de9e5ff11aeade155aa744bcaf9efca82b3d4ee
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review ChiaEn-Wu/Add-Mediatek-MT6370-PMIC-support/20220531-211432 git checkout 4de9e5ff11aeade155aa744bcaf9efca82b3d4ee
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=nios2 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
All errors (new ones prefixed by >>):
drivers/leds/leds-mt6370.c: In function 'mt6370_check_vendor_info':
>> drivers/leds/leds-mt6370.c:873:15: error: implicit declaration of function 'FIELD_GET'; did you mean 'FOLL_GET'? [-Werror=implicit-function-declaration]
873 | vid = FIELD_GET(MT6370_VENID_MASK, devinfo);
| ^~~~~~~~~
| FOLL_GETcc1: some warnings being treated as errors
vim +873 drivers/leds/leds-mt6370.c
863
864 static int mt6370_check_vendor_info(struct mt6370_priv *priv)
865 {
866 unsigned int devinfo, vid;
867 int ret;
868
869 ret = regmap_read(priv->regmap, MT6370_REG_DEV_INFO, &devinfo);
870 if (ret)
871 return ret;
872
> 873 vid = FIELD_GET(MT6370_VENID_MASK, devinfo);
874 if (vid == 0x9 || vid == 0xb) {
875 priv->reg_fields = mt6372_reg_fields;
876 priv->ranges = mt6372_led_ranges;
877 priv->is_mt6372 = true;
878 } else {
879 priv->reg_fields = common_reg_fields;
880 priv->ranges = common_led_ranges;
881 }
882
883 return 0;
884 }
885
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
PATCH RESEND 13/14 leds: flashlight: mt6370: Add Mediatek MT6370 flashlight support
In reply to ChiaEn WuFrom: Alice Chen <[email protected]>
Add Mediatek MT6370 flashlight support
--- drivers/leds/flash/Kconfig | 9 + drivers/leds/flash/Makefile | 1 + drivers/leds/flash/leds-mt6370-flash.c | 665 +++++++++++++++++++++++++ 3 files changed, 675 insertions(+) create mode 100644 drivers/leds/flash/leds-mt6370-flash.c
drivers/leds/flash/Kconfig +9 -0
@@ -90,4 +90,13 @@ config LEDS_SGM3140 This option enables support for the SGM3140 500mA Buck/Boost Charge Pump LED Driver. +config LEDS_MT6370_FLASHLIGHT + tristate "Flash LED Support for Mediatek MT6370 PMIC" + depends on LEDS_CLASS + depends on MFD_MT6370 + help + Support 2 channels and torch/strobe mode. + Say Y here to enable support for + MT6370_FLASH_LED device. + endif # LEDS_CLASS_FLASH
drivers/leds/flash/Makefile +1 -0
@@ -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_FLASHLIGHT) += leds-mt6370-flash.o
drivers/leds/flash/leds-mt6370-flash.c new file +665 -0
665 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botRe: [RESEND 13/14] leds: flashlight: mt6370: Add Mediatek MT6370 flashlight support
Thank you for the patch! Perhaps something to improve:
Hi ChiaEn,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on pavel-leds/for-next]
[also build test WARNING on lee-mfd/for-mfd-next lee-backlight/for-backlight-next v5.18 next-20220602] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/ChiaEn-Wu/Add-Mediatek-MT6370-PMIC-support/20220531-211432 base: git://git.kernel.org/pub/scm/linux/kernel/git/pavel/linux-leds.git for-next config: nios2-allyesconfig (https://download.01.org/0day-ci/archive/20220602/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/805a8af17c769562ec4b85e9b7d2669d004fe3a6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review ChiaEn-Wu/Add-Mediatek-MT6370-PMIC-support/20220531-211432
git checkout 805a8af17c769562ec4b85e9b7d2669d004fe3a6
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=nios2 SHELL=/bin/bash drivers/gpu/drm/v3d/ drivers/leds/ sound/core/
If you fix the issue, kindly add following tag where applicable
All warnings (new ones prefixed by >>):
In file included from include/linux/device.h:15,
from include/linux/leds.h:12,
from include/linux/led-class-flash.h:11,
from drivers/leds/flash/leds-mt6370-flash.c:8:
drivers/leds/flash/leds-mt6370-flash.c: In function 'mt6370_led_probe':
>> drivers/leds/flash/leds-mt6370-flash.c:591:17: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
591 | "No child node or node count over max led number %lu\n", count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
110 | _p_func(dev, fmt, ##__VA_ARGS__); \
| ^~~
include/linux/dev_printk.h:144:56: note: in expansion of macro 'dev_fmt'
144 | dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~
drivers/leds/flash/leds-mt6370-flash.c:590:17: note: in expansion of macro 'dev_err'
590 | dev_err(&pdev->dev,
| ^~~~~~~
drivers/leds/flash/leds-mt6370-flash.c:591:68: note: format string is defined here
591 | "No child node or node count over max led number %lu\n", count);
| ~~^
| |
| long unsigned int
| %uvim +591 drivers/leds/flash/leds-mt6370-flash.c
580
581 static int mt6370_led_probe(struct platform_device *pdev)
582 {
583 struct mt6370_priv *priv;
584 struct fwnode_handle *child;
585 size_t count;
586 int i = 0, ret;
587
588 count = device_get_child_node_count(&pdev->dev);
589 if (!count || count > MT6370_MAX_LEDS) {
590 dev_err(&pdev->dev,
> 591 "No child node or node count over max led number %lu\n", count);
592 return -EINVAL;
593 }
594
595 priv = devm_kzalloc(&pdev->dev, struct_size(priv, leds, count),
596 GFP_KERNEL);
597 if (!priv)
598 return -ENOMEM;
599
600 priv->leds_count = count;
601 priv->dev = &pdev->dev;
602 mutex_init(&priv->lock);
603
604 priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
605 if (!priv->regmap) {
606 dev_err(&pdev->dev, "Failed to get parent regmap\n");
607 return -ENODEV;
608 }
609
610 device_for_each_child_node(&pdev->dev, child) {
611 struct mt6370_led *led = priv->leds + i;
612 struct led_init_data init_data = { .fwnode = child, };
613
614 led->priv = priv;
615 ret = mt6370_init_common_properties(led, &init_data);
616 if (ret)
617 goto out_flash_release;
618
619 ret = mt6370_init_flash_properties(led, &init_data);
620
621 if (ret)
622 goto out_flash_release;
623
624 ret = mt6370_led_register(&pdev->dev, led, &init_data);
625 if (ret)
626 goto out_flash_release;
627
628 i++;
629 }
630
631 platform_set_drvdata(pdev, priv);
632 return 0;
633
634 out_flash_release:
635 mt6370_v4l2_flash_release(priv);
636 return ret;
637 }
638
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
PATCH RESEND 14/14 video: backlight: mt6370: Add Mediatek MT6370 support
In reply to ChiaEn WuFrom: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 Backlight support.
--- drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/mt6370-backlight.c | 338 +++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 drivers/video/backlight/mt6370-backlight.c
drivers/video/backlight/Kconfig +8 -0
@@ -268,6 +268,14 @@ 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 + Say Y here to enable MT6370 Backlight support. + It's commonly used to drive the display WLED. There're 4 channels + inisde, and each channel can provide up to 30mA current. + config BACKLIGHT_APPLE tristate "Apple Backlight Driver" depends on X86 && ACPI
drivers/video/backlight/Makefile +1 -0
@@ -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 +338 -0
338 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [RESEND 14/14] video: backlight: mt6370: Add Mediatek MT6370 support
Quoted 17 lines · ChiaEn Wu
From: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 Backlight support.
Signed-off-by ChiaEn Wu <[email protected]>--- drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/mt6370-backlight.c | 338 +++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 drivers/video/backlight/mt6370-backlight.cdrivers/video/backlight/Kconfig +0
-0
drivers/video/backlight/Kconfig config BACKLIGHT_MAX8925 · line 271
Quoted 4 lines
drivers/video/backlight/Kconfig +1
-0@@ -268,6 +268,14 @@ 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
Is MT6370 really the best name for this driver? In other words, you don't expect there to be any family resemblance between this backlight and the backlight in the *next* Mediatak PMIC?
Moreover,
drivers/video/backlight/Kconfig config BACKLIGHT_MAX8925 · line 277
Quoted 6 lines
drivers/video/backlight/Kconfig +6
-0+ tristate "Mediatek MT6370 Backlight Driver" + depends on MFD_MT6370 + help + Say Y here to enable MT6370 Backlight support. + It's commonly used to drive the display WLED. There're 4 channels + inisde, and each channel can provide up to 30mA current.
Nitpicking but this doesn't align well with other help texts in this file.
Quoted 53 lines
drivers/video/backlight/Kconfig +1
-0+ config BACKLIGHT_APPLE tristate "Apple Backlight Driver" depends on X86 && ACPIdrivers/video/backlight/Makefile +1
-0@@ -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.odrivers/video/backlight/mt6370-backlight.c new file +31
-0@@ -0,0 +1,338 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/backlight.h> +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/gpio/consumer.h> +#include <linux/gpio/driver.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define MT6370_REG_DEV_INFO 0x100 +#define MT6370_REG_BL_EN 0x1A0 +#define MT6370_REG_BL_BSTCTRL 0x1A1 +#define MT6370_REG_BL_PWM 0x1A2 +#define MT6370_REG_BL_DIM2 0x1A4 + +#define MT6370_VENID_MASK GENMASK(7, 4) +#define MT6370_BL_EXT_EN_MASK BIT(7) +#define MT6370_BL_EN_MASK BIT(6) +#define MT6370_BL_CONFIG_MASK BIT(0) +#define MT6370_BL_CH_MASK GENMASK(5, 2) +#define MT6370_BL_DIM2_MASK GENMASK(2, 0) +#define MT6370_BL_DUMMY_6372_MASK GENMASK(2, 0) +#define MT6370_BL_DIM2_6372_SHIFT 3 +#define MT6370_BL_PWM_EN_MASK BIT(7) +#define MT6370_BL_PWM_HYS_EN_MASK BIT(2) +#define MT6370_BL_PWM_HYS_SEL_MASK GENMASK(1, 0) +#define MT6370_BL_OVP_EN_MASK BIT(7)
drivers/video/backlight/mt6370-backlight.c line 41
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+#define MT6370_BL_OVP_SEL_MASK GENMASK(6, 5) +#define MT6370_BL_OC_EN_MASK BIT(3) +#define MT6370_BL_OC_SEL_MASK GENMASK(2, 1) + +#define MT6370_BL_MAX_BRIGHTNESS 2048 + +enum { +MT6370_VID_COMMON =0 , +MT6370_VID_6372 , +MT6370_VID_MAX ,
Unused.
drivers/video/backlight/mt6370-backlight.c line 47
Quoted 6 lines
drivers/video/backlight/mt6370-backlight.c new file +6
-0+}; + +enum mt6370_prop_type { +MT6370_PARSE_TYPE_BOOL =0 , +MT6370_PARSE_TYPE_U8 , +MT6370_PARSE_TYPE_MAX ,
Unused.
Quoted 16 lines
drivers/video/backlight/mt6370-backlight.c new file +16
-0+}; + +struct mt6370_priv { +int vid_type; +struct backlight_device *bl; +struct device *dev; +struct gpio_desc *enable_gpio; +struct regmap *regmap; +}; + +static int mt6370_bl_update_status (struct backlight_device *bl_dev) +{ +struct mt6370_priv *priv =bl_get_data (bl_dev); +int brightness =backlight_get_brightness (bl_dev); +unsigned int enable_val; +u8 brightness_val[2 ];
drivers/video/backlight/mt6370-backlight.c line 73
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+int ret; + +if (brightness) { + brightness_val[0 ] = (brightness -1 ) &MT6370_BL_DIM2_MASK ; + brightness_val[1 ] = (brightness -1 ) + >>fls (MT6370_BL_DIM2_MASK ); + +if (priv->vid_type ==MT6370_VID_6372 ) { + brightness_val[0 ] <<=MT6370_BL_DIM2_6372_SHIFT ; + brightness_val[0 ] |=MT6370_BL_DUMMY_6372_MASK ;
Comment explaining why we have to set these bits would be useful.
Quoted 16 lines
drivers/video/backlight/mt6370-backlight.c new file +16
-0+ } + + ret =regmap_raw_write (priv->regmap,MT6370_REG_BL_DIM2 , + brightness_val,sizeof (brightness_val)); +if (ret) +return ret; + } + +if (priv->enable_gpio) +gpiod_set_value (priv->enable_gpio, brightness ?1 :0 ); + + enable_val = brightness ?MT6370_BL_EN_MASK :0 ; +return regmap_update_bits (priv->regmap,MT6370_REG_BL_EN , +MT6370_BL_EN_MASK , enable_val); +} +
<snip>
drivers/video/backlight/mt6370-backlight.c line 126
Quoted 3 lines
drivers/video/backlight/mt6370-backlight.c new file +3
-0+#define MT6370_DT_PROP_DECL (_name, _type, _reg, _mask, _max, _inv) \ +{ \ + .name = "mediatek,bled-" #_name, \
I'd rather have the whole DT property in the macro (because it helps with grepability).
Quoted 63 lines
drivers/video/backlight/mt6370-backlight.c new file +63
-0+ .type = MT6370_PARSE_TYPE_##_type, \ + .reg = _reg, \ + .mask = _mask, \ + .max_val = _max, \ + .invert = _inv, \ +} + +static int mt6370_init_backlight_properties (struct mt6370_priv *priv, +struct backlight_properties *props) +{ +struct device *dev = priv->dev; +u8 prop_val; +u32 brightness; +unsigned int mask, val; +static const struct { +char *name; +enum mt6370_prop_type type; +unsigned int reg; +unsigned int mask; +u8 max_val; +bool invert; + } vendor_opt_props[] = { +MT6370_DT_PROP_DECL (pwm-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-sel,U8 ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_EN_MASK ,1 , true), +MT6370_DT_PROP_DECL (ocp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ocp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_EN_MASK ,1 , true), + }, *prop_now; +int i, ret; + +/* vendor optional properties */ +for (i =0 ; i <ARRAY_SIZE (vendor_opt_props); i++) { + prop_now = vendor_opt_props + i; + +switch (prop_now->type) { +case MT6370_PARSE_TYPE_BOOL : +if (device_property_read_bool (dev, prop_now->name)) + val =1 ; +else + val =0 ; +break ; +case MT6370_PARSE_TYPE_U8 : + ret =device_property_read_u8 (dev, prop_now->name, + &prop_val); +/* Property not exist, keep value in default */ +if (ret) +continue ; + + val =min_t (u8, prop_val, prop_now->max_val); +break ; +default : +return -EINVAL ; + } +
drivers/video/backlight/mt6370-backlight.c line 199
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+if (prop_now->invert) + val = prop_now->max_val - val; + + val <<=ffs (prop_now->mask) -1 ; + + ret =regmap_update_bits (priv->regmap, prop_now->reg, + prop_now->mask, val); +if (ret) +return ret; + }
Is it really worth all this tricky code for 7 properties?
The code would be much easier to read and maintain if it were coded directly. For example, the inverted boolean code is hard to read and can be written directly as:
val = device_property_read_bool(dev, "mediatek,bled-ovp_shutdown"); ret = regmap_update_bits(priv->regmap, MT6370_REG_BL_BST_CTRL, MT6370_BL_OVP_EN_MASK, MT6370_BL_OVP_EN_MASK * !val); if (ret) return ret;
The direct coded approach will probably also pay off if you switch the bindings over to microvolts/microamps since it becomes much more natural to call out to a lookup function to convert it into a register value.
Quoted 17 lines
drivers/video/backlight/mt6370-backlight.c new file +17
-0+ +/* common properties */ + ret =device_property_read_u32 (dev,"max-brightness" , &brightness); +if (ret) + brightness =MT6370_BL_MAX_BRIGHTNESS ; + + props->max_brightness =min_t (u32, brightness, +MT6370_BL_MAX_BRIGHTNESS ); + + ret =device_property_read_u32 (dev,"default-brightness" , &brightness); +if (ret) + brightness = props->max_brightness; + + props->brightness =min_t (u32, brightness, props->max_brightness); + + + ret = device_property_read_u8(dev, "mediatek,bled-channel-use",
drivers/video/backlight/mt6370-backlight.c line 226
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+ &prop_val); +if (ret) { +dev_err (dev,"mediatek,bled-channel-use DT property missing\n" ); +return ret; + } + +if (!prop_val) { +dev_err (dev,"No channel specified\n" ); +return -EINVAL ; + }
If we are going to validity check this property then it needs an upper bounds check to (e.g. consider if property is set to 64).
drivers/video/backlight/mt6370-backlight.c line 237
Quoted 11 lines
drivers/video/backlight/mt6370-backlight.c new file +11
-0+ + mask =MT6370_BL_EXT_EN_MASK |MT6370_BL_CH_MASK ; + val = prop_val << (ffs (MT6370_BL_CH_MASK ) -1 ); + +if (priv->enable_gpio) + val |=MT6370_BL_EXT_EN_MASK ; + +return regmap_update_bits (priv->regmap,MT6370_REG_BL_EN , mask, val); +} + +static int mt6370_check_vendor_info (struct mt6370_priv *priv)
A comment explaining what variants this function is intended to supported here would be good here.
Quoted 6 lines
drivers/video/backlight/mt6370-backlight.c new file +6
-0+{ +unsigned int dev_info, vid; +int ret; + + ret =regmap_read (priv->regmap,MT6370_REG_DEV_INFO , &dev_info); +if (ret)
drivers/video/backlight/mt6370-backlight.c line 253
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+return ret; + + vid =FIELD_GET (MT6370_VENID_MASK , dev_info); +if (vid ==0x9 || vid ==0xb ) + priv->vid_type =MT6370_VID_6372 ; +else + priv->vid_type =MT6370_VID_COMMON ; + +return 0 ; +}
No furthers comments so I trimmed the rest.
Daniel.
Re: [RESEND 14/14] video: backlight: mt6370: Add Mediatek MT6370 support
Hi Daniel,
Thanks for your valuable feedback!
Daniel Thompson <[email protected]> 於 2022年6月1日 週三 下午5:46寫道:
Quoted 22 lines · ChiaEn Wu
Quoted 20 lines
From: ChiaEn Wu <[email protected]>
Add Mediatek MT6370 Backlight support.
Signed-off-by ChiaEn Wu <[email protected]>--- drivers/video/backlight/Kconfig | 8 + drivers/video/backlight/Makefile | 1 + drivers/video/backlight/mt6370-backlight.c | 338 +++++++++++++++++++++ 3 files changed, 347 insertions(+) create mode 100644 drivers/video/backlight/mt6370-backlight.cdrivers/video/backlight/Kconfig +0
-0@@ -268,6 +268,14 @@ 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.
Quoted 7 lines
drivers/video/backlight/Kconfig config BACKLIGHT_MAX8925 · line 271
Quoted 1 line
drivers/video/backlight/Kconfig +1
-0+config BACKLIGHT_MT6370Is MT6370 really the best name for this driver? In other words, you don't expect there to be any family resemblance between this backlight and the backlight in the *next* Mediatak PMIC?
Moreover,
MT6370, MT6371, MT6372 are very similar, their hardware design and features are almost the same and this driver can be compatible with them.
But, MT6374 is not the same serials PMIC as MT6370, but the name is very similar. And It has no backlight feature, so I think MT6370 is the best name for this driver now.
Quoted 9 lines
drivers/video/backlight/Kconfig config BACKLIGHT_MAX8925 · line 277
Quoted 8 lines
drivers/video/backlight/Kconfig +6
-0+ tristate "Mediatek MT6370 Backlight Driver" + depends on MFD_MT6370 + help + Say Y here to enable MT6370 Backlight support. + It's commonly used to drive the display WLED. There're 4 channels + inisde, and each channel can provide up to 30mA current.
Quoted 3 lines
Nitpicking but this doesn't align well with other help texts in this file.
OK! I will try to align well in the next patch.
Quoted 96 lines
Quoted 54 lines
drivers/video/backlight/Kconfig +1
-0+ config BACKLIGHT_APPLE tristate "Apple Backlight Driver" depends on X86 && ACPIdrivers/video/backlight/Makefile +1
-0@@ -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.odrivers/video/backlight/mt6370-backlight.c new file +31
-0@@ -0,0 +1,338 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/backlight.h> +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/gpio/consumer.h> +#include <linux/gpio/driver.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +#define MT6370_REG_DEV_INFO 0x100 +#define MT6370_REG_BL_EN 0x1A0 +#define MT6370_REG_BL_BSTCTRL 0x1A1 +#define MT6370_REG_BL_PWM 0x1A2 +#define MT6370_REG_BL_DIM2 0x1A4 + +#define MT6370_VENID_MASK GENMASK(7, 4) +#define MT6370_BL_EXT_EN_MASK BIT(7) +#define MT6370_BL_EN_MASK BIT(6) +#define MT6370_BL_CONFIG_MASK BIT(0) +#define MT6370_BL_CH_MASK GENMASK(5, 2) +#define MT6370_BL_DIM2_MASK GENMASK(2, 0) +#define MT6370_BL_DUMMY_6372_MASK GENMASK(2, 0) +#define MT6370_BL_DIM2_6372_SHIFT 3 +#define MT6370_BL_PWM_EN_MASK BIT(7) +#define MT6370_BL_PWM_HYS_EN_MASK BIT(2) +#define MT6370_BL_PWM_HYS_SEL_MASK GENMASK(1, 0) +#define MT6370_BL_OVP_EN_MASK BIT(7)drivers/video/backlight/mt6370-backlight.c line 41
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+#define MT6370_BL_OVP_SEL_MASK GENMASK(6, 5) +#define MT6370_BL_OC_EN_MASK BIT(3) +#define MT6370_BL_OC_SEL_MASK GENMASK(2, 1) + +#define MT6370_BL_MAX_BRIGHTNESS 2048 + +enum { +MT6370_VID_COMMON =0 , +MT6370_VID_6372 , +MT6370_VID_MAX ,Unused.
drivers/video/backlight/mt6370-backlight.c line 47
Quoted 6 lines
drivers/video/backlight/mt6370-backlight.c new file +6
-0+}; + +enum mt6370_prop_type { +MT6370_PARSE_TYPE_BOOL =0 , +MT6370_PARSE_TYPE_U8 , +MT6370_PARSE_TYPE_MAX ,Unused.
Quoted 20 lines
drivers/video/backlight/mt6370-backlight.c new file +20
-0+}; + +struct mt6370_priv { +int vid_type; +struct backlight_device *bl; +struct device *dev; +struct gpio_desc *enable_gpio; +struct regmap *regmap; +}; + +static int mt6370_bl_update_status (struct backlight_device *bl_dev) +{ +struct mt6370_priv *priv =bl_get_data (bl_dev); +int brightness =backlight_get_brightness (bl_dev); +unsigned int enable_val; +u8 brightness_val[2 ]; +int ret; + +if (brightness) { + brightness_val[0 ] = (brightness -1 ) &MT6370_BL_DIM2_MASK ;
Quoted 8 lines
drivers/video/backlight/mt6370-backlight.c line 73
Quoted 6 lines
drivers/video/backlight/mt6370-backlight.c new file +6
-0+ brightness_val[1 ] = (brightness -1 ) + >>fls (MT6370_BL_DIM2_MASK ); + +if (priv->vid_type ==MT6370_VID_6372 ) { + brightness_val[0 ] <<=MT6370_BL_DIM2_6372_SHIFT ; + brightness_val[0 ] |=MT6370_BL_DUMMY_6372_MASK ;Comment explaining why we have to set these bits would be useful.
I got it, I will add the comment in the next patch.
Quoted 21 lines
Quoted 18 lines
drivers/video/backlight/mt6370-backlight.c new file +16
-0+ } + + ret =regmap_raw_write (priv->regmap,MT6370_REG_BL_DIM2 , + brightness_val,sizeof (brightness_val)); +if (ret) +return ret; + } + +if (priv->enable_gpio) +gpiod_set_value (priv->enable_gpio, brightness ?1 :0 ); + + enable_val = brightness ?MT6370_BL_EN_MASK :0 ; +return regmap_update_bits (priv->regmap,MT6370_REG_BL_EN , +MT6370_BL_EN_MASK , enable_val); +} +<snip>
Quoted 6 lines
drivers/video/backlight/mt6370-backlight.c line 126
Quoted 3 lines
drivers/video/backlight/mt6370-backlight.c new file +3
-0+#define MT6370_DT_PROP_DECL (_name, _type, _reg, _mask, _max, _inv) \ +{ \ + .name = "mediatek,bled-" #_name, \I'd rather have the whole DT property in the macro (because it helps with grepability).
Do you mean the _name parameter must be the full name of the DT property and do not use "#" to concat like following example?
// in declare
.name = _name,
// in use
MT6370_DT_PROP_DECL(mediatek,bled-pwm-enable, ......)Quoted 90 lines
Quoted 65 lines
drivers/video/backlight/mt6370-backlight.c new file +63
-0+ .type = MT6370_PARSE_TYPE_##_type, \ + .reg = _reg, \ + .mask = _mask, \ + .max_val = _max, \ + .invert = _inv, \ +} + +static int mt6370_init_backlight_properties (struct mt6370_priv *priv, +struct backlight_properties *props) +{ +struct device *dev = priv->dev; +u8 prop_val; +u32 brightness; +unsigned int mask, val; +static const struct { +char *name; +enum mt6370_prop_type type; +unsigned int reg; +unsigned int mask; +u8 max_val; +bool invert; + } vendor_opt_props[] = { +MT6370_DT_PROP_DECL (pwm-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-sel,U8 ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_EN_MASK ,1 , true), +MT6370_DT_PROP_DECL (ocp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ocp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_EN_MASK ,1 , true), + }, *prop_now; +int i, ret; + +/* vendor optional properties */ +for (i =0 ; i <ARRAY_SIZE (vendor_opt_props); i++) { + prop_now = vendor_opt_props + i; + +switch (prop_now->type) { +case MT6370_PARSE_TYPE_BOOL : +if (device_property_read_bool (dev, prop_now->name)) + val =1 ; +else + val =0 ; +break ; +case MT6370_PARSE_TYPE_U8 : + ret =device_property_read_u8 (dev, prop_now->name, + &prop_val); +/* Property not exist, keep value in default */ +if (ret) +continue ; + + val =min_t (u8, prop_val, prop_now->max_val); +break ; +default : +return -EINVAL ; + } +drivers/video/backlight/mt6370-backlight.c line 199
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+if (prop_now->invert) + val = prop_now->max_val - val; + + val <<=ffs (prop_now->mask) -1 ; + + ret =regmap_update_bits (priv->regmap, prop_now->reg, + prop_now->mask, val); +if (ret) +return ret; + }Is it really worth all this tricky code for 7 properties?
The code would be much easier to read and maintain if it were coded directly. For example, the inverted boolean code is hard to read and can be written directly as:
val = device_property_read_bool(dev, "mediatek,bled-ovp_shutdown"); ret = regmap_update_bits(priv->regmap, MT6370_REG_BL_BST_CTRL, MT6370_BL_OVP_EN_MASK, MT6370_BL_OVP_EN_MASK * !val); if (ret) return ret;
Quoted 5 lines
The direct coded approach will probably also pay off if you switch the bindings over to microvolts/microamps since it becomes much more natural to call out to a lookup function to convert it into a register value.
The purpose of my code is trying to avoid the repeat code in this function. And for loop can help to decrease the lines of code effectively, that's why I use these code to parse the DT properties.
Quoted 22 lines
Quoted 22 lines
drivers/video/backlight/mt6370-backlight.c new file +22
-0+ +/* common properties */ + ret =device_property_read_u32 (dev,"max-brightness" , &brightness); +if (ret) + brightness =MT6370_BL_MAX_BRIGHTNESS ; + + props->max_brightness =min_t (u32, brightness, +MT6370_BL_MAX_BRIGHTNESS ); + + ret =device_property_read_u32 (dev,"default-brightness" , &brightness); +if (ret) + brightness = props->max_brightness; + + props->brightness =min_t (u32, brightness, props->max_brightness); + + + ret =device_property_read_u8 (dev,"mediatek,bled-channel-use" , + &prop_val); +if (ret) { +dev_err (dev,"mediatek,bled-channel-use DT property missing\n" ); +return ret; + }
Quoted 9 lines
drivers/video/backlight/mt6370-backlight.c line 226
Quoted 5 lines
drivers/video/backlight/mt6370-backlight.c new file +5
-0+ +if (!prop_val) { +dev_err (dev,"No channel specified\n" ); +return -EINVAL ; + }If we are going to validity check this property then it needs an upper bounds check to (e.g. consider if property is set to 64).
OK, I will add the validation in the next patch.
Quoted 15 lines
drivers/video/backlight/mt6370-backlight.c line 237
Quoted 12 lines
drivers/video/backlight/mt6370-backlight.c new file +11
-0+ + mask =MT6370_BL_EXT_EN_MASK |MT6370_BL_CH_MASK ; + val = prop_val << (ffs (MT6370_BL_CH_MASK ) -1 ); + +if (priv->enable_gpio) + val |=MT6370_BL_EXT_EN_MASK ; + +return regmap_update_bits (priv->regmap,MT6370_REG_BL_EN , mask, val); +} + +static int mt6370_check_vendor_info (struct mt6370_priv *priv)A comment explaining what variants this function is intended to supported here would be good here.
Ok, I got it! I'll add the comment in the next patch.
Quoted 23 lines
Quoted 8 lines
drivers/video/backlight/mt6370-backlight.c new file +6
-0+{ +unsigned int dev_info, vid; +int ret; + + ret =regmap_read (priv->regmap,MT6370_REG_DEV_INFO , &dev_info); +if (ret)drivers/video/backlight/mt6370-backlight.c line 253
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+return ret; + + vid =FIELD_GET (MT6370_VENID_MASK , dev_info); +if (vid ==0x9 || vid ==0xb ) + priv->vid_type =MT6370_VID_6372 ; +else + priv->vid_type =MT6370_VID_COMMON ; + +return 0 ; +}No furthers comments so I trimmed the rest.
Quoted 1 line
Daniel.
Best regards,
ChiaEn Wu
Re: [RESEND 14/14] video: backlight: mt6370: Add Mediatek MT6370 support
Quoted 10 lines · ChiaEn Wu
Daniel Thompson <[email protected]> 於 2022年6月1日 週三 下午5:46寫道:
Quoted 8 lines · ChiaEn Wu
drivers/video/backlight/mt6370-backlight.c line 126
Quoted 3 lines
drivers/video/backlight/mt6370-backlight.c new file +3
-0+#define MT6370_DT_PROP_DECL (_name, _type, _reg, _mask, _max, _inv) \ +{ \ + .name = "mediatek,bled-" #_name, \I'd rather have the whole DT property in the macro (because it helps with grepability).
Quoted 7 lines
Do you mean the
_nameparameter must be the full name of the DT property and do not use "#" to concat like following example?// in declare
.name = _name, // in use MT6370_DT_PROP_DECL(mediatek,bled-pwm-enable, ......)
Yes, I would prefer this form, although, as discussed below, I don't really like MT6370_DT_PROP_DECL().
Quoted 94 lines
Quoted 88 lines
Quoted 63 lines
drivers/video/backlight/mt6370-backlight.c new file +63
-0+ .type = MT6370_PARSE_TYPE_##_type, \ + .reg = _reg, \ + .mask = _mask, \ + .max_val = _max, \ + .invert = _inv, \ +} + +static int mt6370_init_backlight_properties (struct mt6370_priv *priv, +struct backlight_properties *props) +{ +struct device *dev = priv->dev; +u8 prop_val; +u32 brightness; +unsigned int mask, val; +static const struct { +char *name; +enum mt6370_prop_type type; +unsigned int reg; +unsigned int mask; +u8 max_val; +bool invert; + } vendor_opt_props[] = { +MT6370_DT_PROP_DECL (pwm-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-enable,BOOL ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_EN_MASK ,1 , false), +MT6370_DT_PROP_DECL (pwm-hys-sel,U8 ,MT6370_REG_BL_PWM , +MT6370_BL_PWM_HYS_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ovp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OVP_EN_MASK ,1 , true), +MT6370_DT_PROP_DECL (ocp-level-sel,U8 ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_SEL_MASK ,3 , false), +MT6370_DT_PROP_DECL (ocp-shutdown,BOOL ,MT6370_REG_BL_BSTCTRL , +MT6370_BL_OC_EN_MASK ,1 , true), + }, *prop_now; +int i, ret; + +/* vendor optional properties */ +for (i =0 ; i <ARRAY_SIZE (vendor_opt_props); i++) { + prop_now = vendor_opt_props + i; + +switch (prop_now->type) { +case MT6370_PARSE_TYPE_BOOL : +if (device_property_read_bool (dev, prop_now->name)) + val =1 ; +else + val =0 ; +break ; +case MT6370_PARSE_TYPE_U8 : + ret =device_property_read_u8 (dev, prop_now->name, + &prop_val); +/* Property not exist, keep value in default */ +if (ret) +continue ; + + val =min_t (u8, prop_val, prop_now->max_val); +break ; +default : +return -EINVAL ; + } +drivers/video/backlight/mt6370-backlight.c line 199
Quoted 10 lines
drivers/video/backlight/mt6370-backlight.c new file +10
-0+if (prop_now->invert) + val = prop_now->max_val - val; + + val <<=ffs (prop_now->mask) -1 ; + + ret =regmap_update_bits (priv->regmap, prop_now->reg, + prop_now->mask, val); +if (ret) +return ret; + }Is it really worth all this tricky code for 7 properties?
The code would be much easier to read and maintain if it were coded directly. For example, the inverted boolean code is hard to read and can be written directly as:
val = device_property_read_bool(dev, "mediatek,bled-ovp_shutdown"); ret = regmap_update_bits(priv->regmap, MT6370_REG_BL_BST_CTRL, MT6370_BL_OVP_EN_MASK, MT6370_BL_OVP_EN_MASK * !val); if (ret) return ret;Quoted 5 lines
The direct coded approach will probably also pay off if you switch the bindings over to microvolts/microamps since it becomes much more natural to call out to a lookup function to convert it into a register value.
Quoted 3 lines
The purpose of my code is trying to avoid the repeat code in this function. And for loop can help to decrease the lines of code effectively, that's why I use these code to parse the DT properties.
I'm not really convinced that is uses fewer lines of code. It certainly would if there were a very large number of properties but here there is only seven.
However I guess what I'm really complaining about is how hard it is to read the for loop. We have to study the macros, keep track six different arguments per property and review the complex logic of the for loop (which for example handles inverted u8's that don't actually exist).
To be clear, it's not that loops aren't useful for reducing boilerplate code. They can be. However trying to handle booleans and integers in the *same* loop ends up needlessly hard to read.
Also, I think that if/when you adopt microamps/microvolts then the hard-to-read problem will get even worse unless you get loops to do only one thing!
Daniel.
Quoted 4 lines · ChiaEn Wu
From: ChiaEn Wu <[email protected]>
Sorry, for the patch dependency, we resend this patch series and we're sorry for any inconvenience that we may have caused.
What is the reason of resend? I just finished reviewing v1, so shall it is confusing to see a new one...
Best regards,
Krzysztof