mbox series

[v2,0/4] Add support for QCOM SPMI Flash LEDs

Message ID 20210126140240.1517044-1-nfraprado@protonmail.com
Headers show
Series Add support for QCOM SPMI Flash LEDs | expand

Message

Nícolas F. R. A. Prado Jan. 26, 2021, 2:03 p.m. UTC
Hi,

this patch series adds support for Qualcomm's SPMI Flash LEDs present in the
PM8941 PMIC. It is used as part of MSM8974 based devices, like the Nexus 5
(hammerhead), as a camera flash or as a lantern when in torch mode.

Patch 1 adds the dt-bindings for the driver, together with a header for the
values of some properties.

Patch 2 adds the driver, which was ported from downstream [1], and is now using
the flash LED class framework.

Patch 3 enables the driver as a module in qcom_defconfig, and also enables
CONFIG_LEDS_CLASS_FLASH since it is required by the driver.

Patch 4 adds the device tree nodes configuring the driver in the pm8941 dtsi.

After the feedback I received from the v1 RFC patch (thank you Jacek and
Bjorn!), I implemented the flash LED class framework, renamed the driver to
qcom-spmi-flash and added the dt-bindings. I also did a whole lot of cleanup.

Some caveats:
- I still didn't implement get_strobe() and get_fault() for the flash LEDs,
  because I'm still not sure how to do it. get_strobe() in particular I'm not
  even sure if is possible, since after the flash turns off automatically after
  the timeout, I don't see any change in the SPMI registers. So I'm unsure how
  one would get the current strobe state.
- I have yet to add the V4L2 flash wrapper for the flash LEDs. I still didn't do
  it because I wasn't sure if it was needed, so wanted to double check. But
  being a camera flash it seems that would be useful. Also, it would be great if
  someone could point me how I would go about testing the flash usage through
  V4L2.

Another thing worth mentioning: for v1 the dt nodes were added in hammerhead's
dts (just to simplify testing), but I have now moved them to pm8941's dtsi,
since it was like that in downstream. So if folks using devices based on
PM8941/MSM8974 other than the Nexus 5 could test it, that would be great, since
I have only tested on the Nexus 5.

v1 RFC: https://lore.kernel.org/lkml/20201106165737.1029106-1-nfraprado@protonmail.com/

[1] https://github.com/AICP/kernel_lge_hammerhead/blob/n7.1/drivers/leds/leds-qpnp.c

Nícolas F. R. A. Prado (4):
  dt-bindings: leds: Add binding for qcom-spmi-flash
  leds: Add driver for QCOM SPMI Flash LEDs
  ARM: qcom_defconfig: Enable QCOM SPMI Flash LEDs
  ARM: dts: qcom: pm8941: Add nodes for QCOM SPMI Flash LEDs

 .../bindings/leds/leds-qcom-spmi-flash.yaml   |   94 ++
 arch/arm/boot/dts/qcom-pm8941.dtsi            |   38 +
 arch/arm/configs/qcom_defconfig               |    2 +
 drivers/leds/Kconfig                          |    8 +
 drivers/leds/Makefile                         |    1 +
 drivers/leds/leds-qcom-spmi-flash.c           | 1153 +++++++++++++++++
 .../dt-bindings/leds/leds-qcom-spmi-flash.h   |   15 +
 7 files changed, 1311 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/leds-qcom-spmi-flash.yaml
 create mode 100644 drivers/leds/leds-qcom-spmi-flash.c
 create mode 100644 include/dt-bindings/leds/leds-qcom-spmi-flash.h

Comments

Bjorn Andersson Jan. 27, 2021, 2:29 p.m. UTC | #1
On Tue 26 Jan 08:06 CST 2021, N?colas F. R. A. Prado wrote:

> Enable module for the Qualcomm SPMI Flash LEDs present on the PM8941

> PMIC.

> 

> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@protonmail.com>

> ---

> Changes in v2:

> - Enabled CONFIG_LEDS_CLASS_FLASH since the driver now depends on it.

> 

>  arch/arm/configs/qcom_defconfig | 2 ++

>  1 file changed, 2 insertions(+)

> 

> diff --git a/arch/arm/configs/qcom_defconfig b/arch/arm/configs/qcom_defconfig

> index f6e9675f639c..05cacc59087e 100644

> --- a/arch/arm/configs/qcom_defconfig

> +++ b/arch/arm/configs/qcom_defconfig

> @@ -202,6 +202,7 @@ CONFIG_MMC_SDHCI_PLTFM=y

>  CONFIG_MMC_SDHCI_MSM=y

>  CONFIG_NEW_LEDS=y

>  CONFIG_LEDS_CLASS=y

> +CONFIG_LEDS_CLASS_FLASH=y


This doesn't seem critical to boot the system, can we make it =m?

Regards,
Bjorn

>  CONFIG_LEDS_GPIO=y

>  CONFIG_LEDS_PM8058=y

>  CONFIG_LEDS_TRIGGERS=y

> @@ -284,3 +285,4 @@ CONFIG_DYNAMIC_DEBUG=y

>  CONFIG_DEBUG_INFO=y

>  CONFIG_MAGIC_SYSRQ=y

>  # CONFIG_SCHED_DEBUG is not set

> +CONFIG_LEDS_QCOM_SPMI_FLASH=m

> -- 

> 2.30.0

> 

>
Jacek Anaszewski Jan. 30, 2021, 8:32 p.m. UTC | #2
Hi Nicolas,

On 1/26/21 3:04 PM, Nícolas F. R. A. Prado wrote:
> Add devicetree binding for QCOM SPMI Flash LEDs, which are part of
> PM8941, and are used both as lantern and camera flash.
> 
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@protonmail.com>
> ---
> Changes in v2:
> - Add this commit
> 
>   .../bindings/leds/leds-qcom-spmi-flash.yaml   | 94 +++++++++++++++++++
>   .../dt-bindings/leds/leds-qcom-spmi-flash.h   | 15 +++
>   2 files changed, 109 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/leds/leds-qcom-spmi-flash.yaml
>   create mode 100644 include/dt-bindings/leds/leds-qcom-spmi-flash.h
> 
> diff --git a/Documentation/devicetree/bindings/leds/leds-qcom-spmi-flash.yaml b/Documentation/devicetree/bindings/leds/leds-qcom-spmi-flash.yaml
> new file mode 100644
> index 000000000000..169716e14f67
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/leds/leds-qcom-spmi-flash.yaml
> @@ -0,0 +1,94 @@
> +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/leds/leds-qcom-spmi-flash.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Qualcomm SPMI Flash LEDs
> +
> +maintainers:
> +  - Nícolas F. R. A. Prado <nfraprado@protonmail.com>
> +
> +description: |
> +  The Qualcomm SPMI Flash LEDs are part of Qualcomm PMICs and are used primarily
> +  as a camera or video flash. They can also be used as a lantern when on torch
> +  mode.
> +  The PMIC is connected to Host processor via SPMI bus.
> +
> +properties:
> +  compatible:
> +    const: qcom,spmi-flash
> +
> +  reg:
> +    maxItems: 1
> +
> +  flash-boost-supply:
> +    description: SMBB regulator for LED flash mode
> +
> +  torch-boost-supply:
> +    description: SMBB regulator for LED torch mode
> +
> +patternProperties:
> +  "^led[0-1]$":
> +    type: object
> +    $ref: common.yaml#
> +
> +    properties:
> +      qcom,clamp-curr:
> +        description: current to clamp at, in uA

You're already using led-max-microamp and flash-max-microamp,
so I'm not sure how this is related to those.

> +        $ref: /schemas/types.yaml#definitions/uint32
> +
> +      qcom,headroom:
> +        description: |
> +          headroom to use. Use one of QCOM_SPMI_FLASH_HEADROOM_* defined in
> +          include/dt-bindings/leds/leds-qcom-spmi-flash.h

More information would be welcome here on how it impacts device
operation.

> +        $ref: /schemas/types.yaml#definitions/uint32
> +        minimum: 0
> +        maximum: 3
> +
> +      qcom,startup-dly:
> +        description: |
> +          delay before flashing. Use one of QCOM_SPMI_FLASH_STARTUP_DLY_*
> +          defined in include/dt-bindings/leds/leds-qcom-spmi-flash.h

I don't see much gain in having this exposed.
We don't have related constructs in the API to handle that, so I propose
to always set it to 0 and not expose this setting at all.

> +        $ref: /schemas/types.yaml#definitions/uint32
> +        minimum: 0
> +        maximum: 3
> +
> +      qcom,safety-timer:
> +        description: include for safety timer use, otherwise watchdog timer will be used
> +        type: boolean

What's the difference between watchdog timer and safety timer?
Either way, I propose to choose the option best fitting for handling
flash timeout setting and hide this inside the driver.

> +required:
> +  - compatible
> +  - reg
> +  - flash-boost-supply
> +  - torch-boost-supply
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/leds/common.h>
> +    #include <dt-bindings/leds/leds-qcom-spmi-flash.h>
> +
> +    qcom,leds@d300 {
> +        compatible = "qcom,spmi-flash";
> +        reg = <0xd300 0x100>;
> +        flash-boost-supply = <&pm8941_5vs1>;
> +        torch-boost-supply = <&pm8941_5v>;
> +
> +        led0 {
> +            led-sources = <0>;

Please use reg property for this purpose instead.

> +            function = LED_FUNCTION_FLASH;
> +            color = <LED_COLOR_ID_WHITE>;
> +            led-max-microamp = <200000>;
> +            flash-max-microamp = <1000000>;
> +            flash-max-timeout-us = <1280000>;

You should mention this properties above and provide constraints
(min, max, step).

> +            default-state = "off";

There's no point in having this in the example.

> +            qcom,clamp-curr = <200000>; > +            qcom,headroom = <QCOM_SPMI_FLASH_HEADROOM_500MV>;
> +            qcom,startup-dly = <QCOM_SPMI_FLASH_STARTUP_DLY_128US>;
> +            qcom,safety-timer;
> +        };
> +    };
> +...
> diff --git a/include/dt-bindings/leds/leds-qcom-spmi-flash.h b/include/dt-bindings/leds/leds-qcom-spmi-flash.h
> new file mode 100644
> index 000000000000..8bd54a8e831d
> --- /dev/null
> +++ b/include/dt-bindings/leds/leds-qcom-spmi-flash.h
> @@ -0,0 +1,15 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef _DT_BINDINGS_LEDS_QCOM_SPMI_FLASH_H
> +#define _DT_BINDINGS_LEDS_QCOM_SPMI_FLASH_H
> +
> +#define QCOM_SPMI_FLASH_HEADROOM_250MV	0
> +#define QCOM_SPMI_FLASH_HEADROOM_300MV	1
> +#define QCOM_SPMI_FLASH_HEADROOM_400MV	2
> +#define QCOM_SPMI_FLASH_HEADROOM_500MV	3
> +
> +#define QCOM_SPMI_FLASH_STARTUP_DLY_10US	0
> +#define QCOM_SPMI_FLASH_STARTUP_DLY_32US	1
> +#define QCOM_SPMI_FLASH_STARTUP_DLY_64US	2
> +#define QCOM_SPMI_FLASH_STARTUP_DLY_128US	3
> +
> +#endif
>