backlight: qcom-wled: Support for QCOM wled driver
Subsystems (5)
v2 cover backlight: qcom-wled: Support for QCOM wled driver
This patch series renames the pm8941-wled.c driver to qcom-wled.c to add the support for multiple PMICs supported by qualcomm. This patch series supports both PM8941 and PMI8998 WLED. The PMI8998 WLED has the support to handle the OVP (over voltage protection) and the SC (short circuit protection) interrupts. It also has the auto calibration algorithm support to configure the right strings if the user specified string configuration is in-correct. These three features are added in this series for PMI8998.
changes from v1:
Fixed the commit message for
backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
Kiran Gunda (5):
backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
backlight: qcom-wled: Add support for WLED4 peripheral
backlight: qcom-wled: Add support for short circuit handling
backlight: qcom-wled: Add support for OVP interrupt handling
backlight: qcom-wled: Add auto string detection logic
.../bindings/leds/backlight/pm8941-wled.txt | 42 - .../bindings/leds/backlight/qcom-wled.txt | 158 +++ drivers/video/backlight/Kconfig | 8 +- drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/pm8941-wled.c | 432 ------- drivers/video/backlight/qcom-wled.c | 1329 ++++++++++++++++++++ 6 files changed, 1492 insertions(+), 479 deletions(-) delete mode 100644 Documentation/devicetree/bindings/leds/backlight/pm8941-wled.txt create mode 100644 Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt delete mode 100644 drivers/video/backlight/pm8941-wled.c create mode 100644 drivers/video/backlight/qcom-wled.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 1/5 backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
pm8941-wled.c driver is supporting the WLED peripheral on pm8941. Rename it to qcom-wled.c so that it can support WLED on multiple PMICs.
---
.../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2 +-
drivers/video/backlight/Kconfig | 8 ++++----
drivers/video/backlight/Makefile | 2 +-
drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0
4 files changed, 6 insertions(+), 6 deletions(-)
rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%)
rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt renamed from Documentation/devicetree/bindings/leds/backlight/pm8941-wled.txt +1 -1
@@ -1,4 +1,4 @@ -Binding for Qualcomm PM8941 WLED driver +Binding for Qualcomm Technologies, Inc. WLED driver Required properties: - compatible: should be "qcom,pm8941-wled"
drivers/video/backlight/Kconfig +4 -4
@@ -299,12 +299,12 @@ config BACKLIGHT_TOSA If you have an Sharp SL-6000 Zaurus say Y to enable a driver for its backlight -config BACKLIGHT_PM8941_WLED - tristate "Qualcomm PM8941 WLED Driver" +config BACKLIGHT_QCOM_WLED + tristate "Qualcomm PMIC WLED Driver" select REGMAP help - If you have the Qualcomm PM8941, say Y to enable a driver for the - WLED block. + If you have the Qualcomm PMIC, say Y to enable a driver for the + WLED block. Currently it supports PM8941 and PMI8998. config BACKLIGHT_SAHARA tristate "Tabletkiosk Sahara Touch-iT Backlight Driver"
drivers/video/backlight/Makefile +1 -1
@@ -49,8 +49,8 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o -obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o +obj-$(CONFIG_BACKLIGHT_QCOM_WLED) += qcom-wled.o obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
drivers/video/backlight/qcom-wled.c renamed from drivers/video/backlight/pm8941-wled.c +0 -0
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 2/5 backlight: qcom-wled: Add support for WLED4 peripheral
In reply to Kiran GundaWLED4 peripheral is present on some PMICs like pmi8998 and pm660l. It has a different register map and also configurations are different. Add support for it.
--- .../bindings/leds/backlight/qcom-wled.txt | 172 ++++- drivers/video/backlight/qcom-wled.c | 749 +++++++++++++++------ 2 files changed, 696 insertions(+), 225 deletions(-)
Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt +144 -28
@@ -1,30 +1,129 @@ Binding for Qualcomm Technologies, Inc. WLED driver -Required properties: -- compatible: should be "qcom,pm8941-wled" -- reg: slave address - -Optional properties: -- default-brightness: brightness value on boot, value from: 0-4095 - default: 2048 -- label: The name of the backlight device -- qcom,cs-out: bool; enable current sink output -- qcom,cabc: bool; enable content adaptive backlight control -- qcom,ext-gen: bool; use externally generated modulator signal to dim -- qcom,current-limit: mA; per-string current limit; value from 0 to 25 - default: 20mA -- qcom,current-boost-limit: mA; boost current limit; one of: - 105, 385, 525, 805, 980, 1260, 1400, 1680 - default: 805mA -- qcom,switching-freq: kHz; switching frequency; one of: - 600, 640, 685, 738, 800, 872, 960, 1066, 1200, 1371, - 1600, 1920, 2400, 3200, 4800, 9600, - default: 1600kHz -- qcom,ovp: V; Over-voltage protection limit; one of: - 27, 29, 32, 35 - default: 29V -- qcom,num-strings: #; number of led strings attached; value from 1 to 3 - default: 2 +WLED (White Light Emitting Diode) driver is used for controlling display +backlight that is part of PMIC on Qualcomm Technologies, Inc. reference +platforms. The PMIC is connected to the host processor via SPMI bus. + +- compatible + Usage: required + Value type: <string> + Definition: should be "qcom,pm8941-wled" or "qcom,pmi8998-wled". + or "qcom,pm660l-wled". + +- reg + Usage: required + Value type: <prop encoded array> + Definition: Base address of the WLED modules. + +- interrupts + Usage: optional + Value type: <prop encoded array> + Definition: Interrupts associated with WLED. Interrupts can be + specified as per the encoding listed under + Documentation/devicetree/bindings/spmi/ + qcom,spmi-pmic-arb.txt. + +- interrupt-names + Usage: optional + Value type: <string> + Definition: Interrupt names associated with the interrupts. + Must be "short" and "ovp". The short circuit detection + is not supported for PM8941. + +- label + Usage: required + Value type: <string> + Definition: The name of the backlight device + +- default-brightness + Usage: optional + Value type: <u32> + Definition: brightness value on boot, value from: 0-4095 + Default: 2048 + +- qcom,current-limit + Usage: optional + Value type: <u32> + Definition: uA; per-string current limit + value: + For pm8941: from 0 to 25000 with 5000 ua step + Default 20000 uA + For pmi8998: from 0 to 30000 with 5000 ua step + Default 25000 uA. + +- qcom,current-boost-limit + Usage: optional + Value type: <u32> + Definition: mA; boost current limit. + For pm8941: one of: 105, 385, 525, 805, 980, 1260, 1400, + 1680. Default: 805 mA + For pmi8998: one of: 105, 280, 450, 620, 970, 1150, 1300, + 1500. Default: 970 mA + +- qcom,switching-freq + Usage: optional + Value type: <u32> + Definition: kHz; switching frequency; one of: 600, 640, 685, 738, + 800, 872, 960, 1066, 1200, 1371, 1600, 1920, 2400, 3200, + 4800, 9600. + Default: for pm8941: 1600 kHz + for pmi8998: 800 kHz + +- qcom,ovp + Usage: optional + Value type: <u32> + Definition: mV; Over-voltage protection limit; + For pm8941: one of 27000, 29000, 32000, 35000 + Default: 29000 mV + For pmi8998: one of 18100, 19600, 29600, 31100 + Default: 29600 mV + +- qcom,num-strings + Usage: optional + Value type: <u32> + Definition: #; number of led strings attached; + for pm8941: value 3. + for pmi8998: value 4. + +- qcom,enabled-strings + Usage: optional + Value tyoe: <u32> + Definition: Bit mask of the WLED strings. Bit 0 to 3 indicates strings + 0 to 3 respectively. Each string of leds are operated + individually. Specify the strings using the bit mask. Any + combination of led strings can be used. + for pm8941: Default value is 7 (b111). + for pmi8998: Default value is 15 (b1111). + +- qcom,cs-out + Usage: optional + Value type: <bool> + Definition: enable current sink output. + This property is supported only for PM8941. + +- qcom,cabc + Usage: optional + Value type: <bool> + Definition: enable content adaptive backlight control. + +- qcom,ext-gen + Usage: optional + Value type: <bool> + Definition: use externally generated modulator signal to dim. + This property is supported only for PM8941. + +- qcom,external-pfet + Usage: optional + Value type: <bool> + Definition: Specify if external PFET control for short circuit + protection is used. This property is supported only + for PMI8998. + +- qcom,auto-string-detection + Usage: optional + Value type: <bool> + Definition: Enables auto-detection of the WLED string configuration. + This feature is not supported for PM8941. Example:
@@ -34,9 +133,26 @@ pm8941-wled@d800 { label = "backlight"; qcom,cs-out; - qcom,current-limit = <20>; + qcom,current-limit = <20000>; + qcom,current-boost-limit = <805>; + qcom,switching-freq = <1600>; + qcom,ovp = <29000>; + qcom,num-strings = <3>; + qcom,enabled-strings = <7>; +}; + +pmi8998-wled@d800 { + compatible = "qcom,pmi8998-wled"; + reg = <0xd800 0xd900>; + label = "backlight"; + + interrupts = <3 0xd8 2 IRQ_TYPE_EDGE_RISING>, + <3 0xd8 1 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "short", "ovp"; + qcom,current-limit = <25000>; qcom,current-boost-limit = <805>; qcom,switching-freq = <1600>; - qcom,ovp = <29>; - qcom,num-strings = <2>; + qcom,ovp = <29600>; + qcom,num-strings = <4>; + qcom,enabled-strings = <15>; };
drivers/video/backlight/qcom-wled.c +552 -197
943 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 3/5 backlight: qcom-wled: Add support for short circuit handling
In reply to Kiran GundaHandle the short circuit interrupt and check if the short circuit interrupt is valid. Re-enable the module to check if it goes away. Disable the module altogether if the short circuit event persists.
--- drivers/video/backlight/qcom-wled.c | 134 ++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 4 deletions(-)
drivers/video/backlight/qcom-wled.c +130 -4
@@ -10,6 +10,9 @@* GNU General Public License for more details. */ +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/ktime.h> #include <linux/kernel.h> #include <linux/backlight.h> #include <linux/module.h>
@@ -23,7 +26,9 @@#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF -/* Control registers */ +/* WLED3 Control registers */ +#define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7)
@@ -36,7 +41,17 @@#define WLED3_CTRL_REG_ILIMIT 0x4e#define WLED3_CTRL_REG_ILIMIT_MASK GENMASK(2, 0) -/* sink registers */ +/* WLED4 control registers */ +#define WLED4_CTRL_REG_SHORT_PROTECT 0x5e +#define WLED4_CTRL_REG_SHORT_EN_MASK BIT(7) + +#define WLED4_CTRL_REG_SEC_ACCESS 0xd0 +#define WLED4_CTRL_REG_SEC_UNLOCK 0xa5 + +#define WLED4_CTRL_REG_TEST1 0xe2 +#define WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 0x09 + +/* WLED3 sink registers */ #define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_MASK GENMASK(2, 0)#define WLED4_SINK_REG_SYNC_MASK GENMASK(3, 0)
@@ -130,17 +145,23 @@ struct wled_config {bool cs_out_en;bool ext_gen;bool cabc; +bool external_pfet; };struct wled {const char *name;struct device *dev;struct regmap *regmap; +struct mutex lock;/* Lock to avoid race from ISR */ +ktime_t last_short_event;u16 ctrl_addr;u16 sink_addr;u32 brightness;u32 max_brightness; +u32 short_count;const int *version; +int short_irq; +bool force_mod_disable;struct wled_config cfg;int (*wled_set_brightness)(struct wled *wled,u16 brightness);
@@ -192,6 +213,9 @@ static int wled_module_enable(struct wled *wled, int val) {int rc; +if (wled->force_mod_disable) +return 0 ; + rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN, WLED3_CTRL_REG_MOD_EN_MASK,
@@ -248,12 +272,13 @@ static int wled_update_status(struct backlight_device *bl) bl->props.state & BL_CORE_FBBLANK) brightness =0 ; +mutex_lock (&wled->lock);if (brightness) { rc = wled->wled_set_brightness (wled, brightness);if (rc <0 ) {dev_err (wled->dev,"wled failed to set brightness rc:%d\n" , rc); -return rc; + goto unlock_mutex; } rc = wled->wled_sync_toggle (wled);
@@ -267,15 +292,60 @@ static int wled_update_status(struct backlight_device *bl) rc =wled_module_enable (wled, !!brightness);if (rc <0 ) {dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); -return rc; + goto unlock_mutex; } } wled->brightness = brightness; +unlock_mutex: +mutex_unlock (&wled->lock); +return rc; } +#define WLED_SHORT_DLY_MS 20 +#define WLED_SHORT_CNT_MAX 5 +#define WLED_SHORT_RESET_CNT_DLY_US HZ +static irqreturn_t wled_short_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +s64 elapsed_time; + + wled->short_count++; +mutex_lock (&wled->lock); + rc =wled_module_enable (wled, false); +if (rc <0 ) { +dev_err (wled->dev,"wled disable failed rc:%d\n" , rc); + goto unlock_mutex; + } + + elapsed_time =ktime_us_delta (ktime_get (), + wled->last_short_event); +if (elapsed_time >WLED_SHORT_RESET_CNT_DLY_US ) + wled->short_count =0 ; + +if (wled->short_count >WLED_SHORT_CNT_MAX ) { +dev_err (wled->dev,"Short trigged %d times, disabling WLED forever!\n" , + wled->short_count); + wled->force_mod_disable = true; + goto unlock_mutex; + } + + wled->last_short_event =ktime_get (); + +msleep (WLED_SHORT_DLY_MS ); + rc =wled_module_enable (wled, true); +if (rc <0 ) +dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); + +unlock_mutex: +mutex_unlock (&wled->lock); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled) {u16 addr;
@@ -435,6 +505,21 @@ static int wled4_setup(struct wled *wled)return rc; } +if (wled->cfg.external_pfet) { +/* Unlock the secure register access */ + rc =regmap_write (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SEC_ACCESS , +WLED4_CTRL_REG_SEC_UNLOCK ); +if (rc <0 ) +return rc; + + rc =regmap_write (wled->regmap, + wled->ctrl_addr +WLED4_CTRL_REG_TEST1 , +WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 ); +if (rc <0 ) +return rc; + } +return 0 ; }
@@ -446,6 +531,7 @@ static int wled4_setup(struct wled *wled) .switch_freq = 11, .enabled_strings = 0xf, .cabc = false, + .external_pfet = true, };static const u32 wled3_boost_i_limit_values[] = {
@@ -628,6 +714,7 @@ static int wled_configure(struct wled *wled) { "qcom,cs-out", &cfg->cs_out_en, }, { "qcom,ext-gen", &cfg->ext_gen, }, { "qcom,cabc", &cfg->cabc, }, + { "qcom,external-pfet", &cfg->external_pfet, }, }; prop_addr =of_get_address (dev->of_node,0 ,NULL ,NULL );
@@ -701,6 +788,39 @@ static int wled_configure(struct wled *wled)return 0 ; } +static int wled_configure_short_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; + +/* PM8941 doesn't have the short detection support */ +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + rc =regmap_update_bits (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SHORT_PROTECT , +WLED4_CTRL_REG_SHORT_EN_MASK , +WLED4_CTRL_REG_SHORT_EN_MASK ); +if (rc <0 ) +return rc; + + wled->short_irq =platform_get_irq_byname (pdev,"short" ); +if (wled->short_irq <0 ) { +dev_dbg (&pdev->dev,"short irq is not used\n" ); +return 0 ; + } + + rc =devm_request_threaded_irq (wled->dev, wled->short_irq, +NULL , wled_short_irq_handler, +IRQF_ONESHOT , +"wled_short_irq" , wled); +if (rc <0 ) +dev_err (wled->dev,"Unable to request short_irq (err:%d)\n" , + rc); + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };
@@ -733,6 +853,8 @@ static int wled_probe(struct platform_device *pdev)return -ENODEV ; } +mutex_init (&wled->lock); + rc =wled_configure (wled);if (rc)return rc;
@@ -752,6 +874,10 @@ static int wled_probe(struct platform_device *pdev) } } + rc =wled_configure_short_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 4/5 backlight: qcom-wled: Add support for OVP interrupt handling
In reply to Kiran GundaWLED peripheral has over voltage protection(OVP) circuitry and the OVP fault is notified through an interrupt. Though this fault condition rising is due to an incorrect hardware configuration is mitigated in the hardware, it still needs to be detected and handled. Add support for it.
When WLED module is enabled, keep OVP fault interrupt disabled for 10 ms to account for soft start delay.
--- drivers/video/backlight/qcom-wled.c | 118 +++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-)
drivers/video/backlight/qcom-wled.c +116 -2
@@ -23,14 +23,20 @@/* From DT binding */ #define WLED_DEFAULT_BRIGHTNESS 2048 - +#define WLED_SOFT_START_DLY_US 10000#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF/* WLED3 Control registers */ #define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_ILIM_FAULT_BIT BIT(0) +#define WLED3_CTRL_REG_OVP_FAULT_BIT BIT(1) +#define WLED4_CTRL_REG_SC_FAULT_BIT BIT(2) + +#define WLED3_CTRL_REG_INT_RT_STS 0x10#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7) +#define WLED3_CTRL_REG_MOD_EN_BIT BIT(7)#define WLED3_CTRL_REG_FREQ 0x4c#define WLED3_CTRL_REG_FREQ_MASK GENMASK(3, 0)
@@ -161,9 +167,12 @@ struct wled {u32 short_count;const int *version;int short_irq; +int ovp_irq;bool force_mod_disable; +bool ovp_irq_disabled;struct wled_config cfg; +struct delayed_work ovp_work;int (*wled_set_brightness)(struct wled *wled,u16 brightness);int (*wled_sync_toggle)(struct wled *wled); };
@@ -209,6 +218,32 @@ static int wled4_set_brightness(struct wled *wled, u16 brightness)return 0 ; } +static void wled_ovp_work (struct work_struct *work) +{ +u32 val; +int rc; + +struct wled *wled =container_of (work, + struct wled, ovp_work.work); + + rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , + &val); +if (rc <0 ) +return ; + +if (val &WLED3_CTRL_REG_MOD_EN_BIT ) { +if (wled->ovp_irq >0 && wled->ovp_irq_disabled) { +enable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = false; + } + }else { +if (wled->ovp_irq >0 && !wled->ovp_irq_disabled) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + } +} +static int wled_module_enable (struct wled *wled,int val) {int rc;
@@ -220,7 +255,12 @@ static int wled_module_enable(struct wled *wled, int val)WLED3_CTRL_REG_MOD_EN ,WLED3_CTRL_REG_MOD_EN_MASK , WLED3_CTRL_REG_MOD_EN_MASK); -return rc; +if (rc <0 ) +return rc; + +schedule_delayed_work (&wled->ovp_work,WLED_SOFT_START_DLY_US ); + +return 0 ; }static int wled3_sync_toggle (struct wled *wled)
@@ -346,6 +386,36 @@ static irqreturn_t wled_short_irq_handler(int irq, void *_wled)return IRQ_HANDLED ; } +static irqreturn_t wled_ovp_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +u32 int_sts, fault_sts; + + rc =regmap_read (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_INT_RT_STS , &int_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED3_INT_RT_STS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_FAULT_STATUS , &fault_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED_FAULT_STATUS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + +if (fault_sts & + (WLED3_CTRL_REG_OVP_FAULT_BIT |WLED3_CTRL_REG_ILIM_FAULT_BIT )) +dev_dbg (wled->dev,"WLED OVP fault detected, int_sts=%x fault_sts= %x\n" , + int_sts, fault_sts); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled) {u16 addr;
@@ -821,6 +891,44 @@ static int wled_configure_short_irq(struct wled *wled,return rc; } +static int wled_configure_ovp_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; +u32 val; + +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + wled->ovp_irq =platform_get_irq_byname (pdev,"ovp" ); +if (wled->ovp_irq <0 ) { +dev_dbg (&pdev->dev,"ovp irq is not used\n" ); +return 0 ; + } + + rc =devm_request_threaded_irq (wled->dev, wled->ovp_irq,NULL , + wled_ovp_irq_handler,IRQF_ONESHOT , +"wled_ovp_irq" , wled); +if (rc <0 ) { +dev_err (wled->dev,"Unable to request ovp_irq (err:%d)\n" , + rc); +return 0 ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_MOD_EN , &val); +if (rc <0 ) +return rc; + +/* Keep OVP irq disabled until module is enabled */ +if (!rc && !(val &WLED3_CTRL_REG_MOD_EN_MASK )) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };
@@ -874,10 +982,16 @@ static int wled_probe(struct platform_device *pdev) } } +INIT_DELAYED_WORK (&wled->ovp_work, wled_ovp_work); + rc =wled_configure_short_irq (wled, pdev);if (rc <0 )return rc; + rc =wled_configure_ovp_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v2 5/5 backlight: qcom-wled: Add auto string detection logic
In reply to Kiran GundaThe auto string detection algorithm checks if the current WLED sink configuration is valid. It tries enabling every sink and checks if the OVP fault is observed. Based on this information it detects and enables the valid sink configuration. Auto calibration will be triggered when the OVP fault interrupts are seen frequently thereby it tries to fix the sink configuration.
--- drivers/video/backlight/qcom-wled.c | 302 ++++++++++++++++++++++++++++++++++++ 1 file changed, 302 insertions(+)
drivers/video/backlight/qcom-wled.c +302 -0
@@ -33,11 +33,14 @@#define WLED4_CTRL_REG_SC_FAULT_BIT BIT(2)#define WLED3_CTRL_REG_INT_RT_STS 0x10 +#define WLED3_CTRL_REG_OVP_FAULT_STATUS BIT(1)#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7)#define WLED3_CTRL_REG_MOD_EN_BIT BIT(7) +#define WLED3_CTRL_REG_FEEDBACK_CONTROL 0x48 +#define WLED3_CTRL_REG_FREQ 0x4c#define WLED3_CTRL_REG_FREQ_MASK GENMASK(3, 0)
@@ -152,6 +155,7 @@ struct wled_config {bool ext_gen;bool cabc;bool external_pfet; +bool auto_detection_enabled; };struct wled {
@@ -160,8 +164,10 @@ struct wled {struct regmap *regmap;struct mutex lock;/* Lock to avoid race from ISR */ ktime_t last_short_event; +ktime_t start_ovp_fault_time;u16 ctrl_addr;u16 sink_addr; +u16 auto_detection_ovp_count;u32 brightness;u32 max_brightness;u32 short_count;
@@ -170,6 +176,7 @@ struct wled {int ovp_irq;bool force_mod_disable;bool ovp_irq_disabled; +bool auto_detection_done;struct wled_config cfg;struct delayed_work ovp_work;
@@ -386,6 +393,292 @@ static irqreturn_t wled_short_irq_handler(int irq, void *_wled)return IRQ_HANDLED ; } +#define AUTO_DETECT_BRIGHTNESS 200 +static int wled_auto_string_detection (struct wled *wled) +{ +int rc =0 , i; +u32 sink_config =0 , int_sts; +u8 sink_test =0 , sink_valid =0 , val; + +if (wled->auto_detection_done) +return 0 ; + +/* read configured sink configuration */ + rc =regmap_read (wled->regmap, wled->sink_addr + +WLED4_SINK_REG_CURR_SINK , &sink_config); +if (rc <0 ) { +pr_err ("Failed to read SINK configuration rc=%d\n" , rc); + goto failed_detect; + } + +/* disable the module before starting detection */ + rc =regmap_update_bits (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , +WLED3_CTRL_REG_MOD_EN_MASK ,0 ); +if (rc <0 ) { +pr_err ("Failed to disable WLED module rc=%d\n" , rc); + goto failed_detect; + } + +/* set low brightness across all sinks */ + rc =wled4_set_brightness (wled,AUTO_DETECT_BRIGHTNESS ); +if (rc <0 ) { +pr_err ("Failed to set brightness for auto detection rc=%d\n" , + rc); + goto failed_detect; + } + +if (wled->cfg.cabc) { +for (i =0 ; i < wled->cfg.num_strings; i++) { + rc =regmap_update_bits (wled->regmap, wled->sink_addr + +WLED4_SINK_REG_STR_CABC (i), +WLED4_SINK_REG_STR_CABC_MASK , +0 ); +if (rc <0 ) + goto failed_detect; + } + } + +/* disable all sinks */ + rc =regmap_write (wled->regmap, + wled->sink_addr +WLED4_SINK_REG_CURR_SINK ,0 ); +if (rc <0 ) { +pr_err ("Failed to disable all sinks rc=%d\n" , rc); + goto failed_detect; + } + +/* iterate through the strings one by one */ +for (i =0 ; i < wled->cfg.num_strings; i++) { + sink_test =BIT ((WLED4_SINK_REG_CURR_SINK_SHFT + i)); + +/* Enable feedback control */ + rc =regmap_write (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_FEEDBACK_CONTROL , i +1 ); +if (rc <0 ) { +pr_err ("Failed to enable feedback for SINK %d rc = %d\n" , + i +1 , rc); + goto failed_detect; + } + +/* enable the sink */ + rc =regmap_write (wled->regmap, wled->sink_addr + +WLED4_SINK_REG_CURR_SINK , sink_test); +if (rc <0 ) { +pr_err ("Failed to configure SINK %d rc=%d\n" , i +1 , + rc); + goto failed_detect; + } + +/* Enable the module */ + rc =regmap_update_bits (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_MOD_EN , +WLED3_CTRL_REG_MOD_EN_MASK , +WLED3_CTRL_REG_MOD_EN_MASK ); +if (rc <0 ) { +pr_err ("Failed to enable WLED module rc=%d\n" , rc); + goto failed_detect; + } + +usleep_range (WLED_SOFT_START_DLY_US , +WLED_SOFT_START_DLY_US +1000 ); + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_INT_RT_STS , &int_sts); +if (rc <0 ) { +pr_err ("Error in reading WLED3_CTRL_INT_RT_STS rc=%d\n" , + rc); + goto failed_detect; + } + +if (int_sts &WLED3_CTRL_REG_OVP_FAULT_STATUS ) +pr_debug ("WLED OVP fault detected with SINK %d\n" , + i +1 ); +else + sink_valid |= sink_test; + +/* Disable the module */ + rc =regmap_update_bits (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , +WLED3_CTRL_REG_MOD_EN_MASK ,0 ); +if (rc <0 ) { +pr_err ("Failed to disable WLED module rc=%d\n" , rc); + goto failed_detect; + } + } + +if (sink_valid == sink_config) { +pr_debug ("WLED auto-detection complete, default sink-config=%x OK!\n" , + sink_config); + }else { +pr_warn ("Invalid WLED default sink config=%x changing it to=%x\n" , + sink_config, sink_valid); + sink_config = sink_valid; + } + +if (!sink_config) { +pr_err ("No valid WLED sinks found\n" ); + wled->force_mod_disable = true; + goto failed_detect; + } + +/* write the new sink configuration */ + rc =regmap_write (wled->regmap, + wled->sink_addr +WLED4_SINK_REG_CURR_SINK , + sink_config); +if (rc <0 ) { +pr_err ("Failed to reconfigure the default sink rc=%d\n" , rc); + goto failed_detect; + } + +/* Enable valid sinks */ +for (i =0 ; i < wled->cfg.num_strings; i++) { +if (wled->cfg.cabc) { + rc =regmap_update_bits (wled->regmap, wled->sink_addr + +WLED4_SINK_REG_STR_CABC (i), +WLED4_SINK_REG_STR_CABC_MASK , +WLED4_SINK_REG_STR_CABC_MASK ); +if (rc <0 ) + goto failed_detect; + } + +if (sink_config &BIT (WLED4_SINK_REG_CURR_SINK_SHFT + i)) + val =WLED4_SINK_REG_STR_MOD_MASK ; +else + val =0x0 ;/* disable modulator_en for unused sink */ + + rc =regmap_write (wled->regmap, wled->sink_addr + +WLED4_SINK_REG_STR_MOD_EN (i), val); +if (rc <0 ) { +pr_err ("Failed to configure MODULATOR_EN rc=%d\n" , rc); + goto failed_detect; + } + } + +/* restore the feedback setting */ + rc =regmap_write (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_FEEDBACK_CONTROL ,0 ); +if (rc <0 ) { +pr_err ("Failed to restore feedback setting rc=%d\n" , rc); + goto failed_detect; + } + +/* restore brightness */ + rc =wled4_set_brightness (wled, wled->brightness); +if (rc <0 ) { +pr_err ("Failed to set brightness after auto detection rc=%d\n" , + rc); + goto failed_detect; + } + + rc =regmap_update_bits (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , +WLED3_CTRL_REG_MOD_EN_MASK , +WLED3_CTRL_REG_MOD_EN_MASK ); +if (rc <0 ) { +pr_err ("Failed to enable WLED module rc=%d\n" , rc); + goto failed_detect; + } + + wled->auto_detection_done = true; + +failed_detect: +return rc; +} + +#define WLED_AUTO_DETECT_OVP_COUNT 5 +#define WLED_AUTO_DETECT_CNT_DLY_US HZ/* 1 second */ +static bool wled_auto_detection_required (struct wled *wled) +{ +s64 elapsed_time_us; + +if (*wled->version ==WLED_PM8941 ) +return false; +/* +* Check if the OVP fault was an occasional one +* or if it's firing continuously, the latter qualifies +* for an auto-detection check. +*/ +if (!wled->auto_detection_ovp_count) { + wled->start_ovp_fault_time =ktime_get (); + wled->auto_detection_ovp_count++; + }else { + elapsed_time_us =ktime_us_delta (ktime_get (), + wled->start_ovp_fault_time); +if (elapsed_time_us >WLED_AUTO_DETECT_CNT_DLY_US ) + wled->auto_detection_ovp_count =0 ; +else + wled->auto_detection_ovp_count++; + +if (wled->auto_detection_ovp_count >= +WLED_AUTO_DETECT_OVP_COUNT ) { + wled->auto_detection_ovp_count =0 ; +return true; + } + } + +return false; +} + +static int wled_auto_detection_at_init (struct wled *wled) +{ +int rc; +u32 fault_status =0 , rt_status =0 ; + +if (*wled->version ==WLED_PM8941 ) +return 0 ; + +if (!wled->cfg.auto_detection_enabled) +return 0 ; + + rc =regmap_read (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_INT_RT_STS , + &rt_status); +if (rc <0 ) { +pr_err ("Failed to read RT status rc=%d\n" , rc); +return rc; + } + + rc =regmap_read (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_FAULT_STATUS , + &fault_status); +if (rc <0 ) { +pr_err ("Failed to read fault status rc=%d\n" , rc); +return rc; + } + +if ((rt_status &WLED3_CTRL_REG_OVP_FAULT_STATUS ) || + (fault_status &WLED3_CTRL_REG_OVP_FAULT_BIT )) { +mutex_lock (&wled->lock); + rc =wled_auto_string_detection (wled); +if (!rc) + wled->auto_detection_done = true; +mutex_unlock (&wled->lock); + } + +return rc; +} + +static void handle_ovp_fault (struct wled *wled) +{ +if (!wled->cfg.auto_detection_enabled) +return ; + +mutex_lock (&wled->lock); +if (wled->ovp_irq >0 && !wled->ovp_irq_disabled) { +disable_irq_nosync (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + +if (wled_auto_detection_required (wled)) +wled_auto_string_detection (wled); + +if (wled->ovp_irq >0 && wled->ovp_irq_disabled) { +enable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = false; + } +mutex_unlock (&wled->lock); +} +static irqreturn_t wled_ovp_irq_handler (int irq,void *_wled) {struct wled *wled = _wled;
@@ -413,6 +706,9 @@ static irqreturn_t wled_ovp_irq_handler(int irq, void *_wled)dev_dbg (wled->dev,"WLED OVP fault detected, int_sts=%x fault_sts= %x\n" , int_sts, fault_sts); +if (fault_sts &WLED3_CTRL_REG_OVP_FAULT_BIT ) +handle_ovp_fault (wled); +return IRQ_HANDLED ; }
@@ -575,6 +871,10 @@ static int wled4_setup(struct wled *wled)return rc; } + rc =wled_auto_detection_at_init (wled); +if (rc <0 ) +return rc; +if (wled->cfg.external_pfet) {/* Unlock the secure register access */ rc = regmap_write(wled->regmap, wled->ctrl_addr +
@@ -602,6 +902,7 @@ static int wled4_setup(struct wled *wled) .enabled_strings = 0xf, .cabc = false, .external_pfet = true, + .auto_detection_enabled = false, };static const u32 wled3_boost_i_limit_values[] = {
@@ -785,6 +1086,7 @@ static int wled_configure(struct wled *wled) { "qcom,ext-gen", &cfg->ext_gen, }, { "qcom,cabc", &cfg->cabc, }, { "qcom,external-pfet", &cfg->external_pfet, }, + { "qcom,auto-string-detection", &cfg->auto_detection_enabled, }, }; prop_addr =of_get_address (dev->of_node,0 ,NULL ,NULL );
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Jingoo Han
maintainerRe: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to Kiran GundaOn Thursday, May 3, 2018 6:12 AM, Kiran Gunda wrote:
If you really want someone to review your patch, please add more detailed explanations.
1. Please add 0th patch.
2. Please add what the difference is between V1 and V2 patches.
If you cannot understand what I am saying, just ask another person who have an experience to send patches to Linux mailing-list.
Best regards,
Jingoo Han
Quoted 9 lines
pm8941-wled.cdriver is supporting the WLED peripheral on pm8941. Rename it toqcom-wled.cso that it can support WLED on multiple PMICs.Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2 +- drivers/video/backlight/Kconfig | 8
++++----
drivers/video/backlight/Makefile obj-$(CONFIG_BACKLIGHT_OMAP1) +=
Quoted 50 lines
drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%) rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)(quoted diff) +0
-0wled.txt
b/Documentation/devicetree/bindings/leds/backlight/qcom-wled.txtsimilarity index 95%
rename fromDocumentation/devicetree/bindings/leds/backlight/pm8941-wled.txt
rename toDocumentation/devicetree/bindings/leds/backlight/qcom-wled.txtindex e5b294d..fb39e32 100644Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt renamed from Documentation/devicetree/bindings/leds/backlight/pm8941-wled.txt +1
-1@@ -1,4 +1,4 @@ -Binding for Qualcomm PM8941 WLED driver +Binding for Qualcomm Technologies, Inc. WLED driver Required properties: - compatible: should be "qcom,pm8941-wled"drivers/video/backlight/Kconfig +4
-4@@ -299,12 +299,12 @@ config BACKLIGHT_TOSA If you have an Sharp SL-6000 Zaurus say Y to enable a driver for its backlight -config BACKLIGHT_PM8941_WLED - tristate "Qualcomm PM8941 WLED Driver" +config BACKLIGHT_QCOM_WLED + tristate "Qualcomm PMIC WLED Driver" select REGMAP help - If you have the Qualcomm PM8941, say Y to enable a driver for the - WLED block. + If you have the Qualcomm PMIC, say Y to enable a driver for the + WLED block. Currently it supports PM8941 and PMI8998. config BACKLIGHT_SAHARA tristate "Tabletkiosk Sahara Touch-iT Backlight Driver"drivers/video/backlight/Makefile +0
-0@@ -49,8 +49,8 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) +=
omap1_bl.o
Quoted 15 lines
drivers/video/backlight/Makefile +1
-1obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o -obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o +obj-$(CONFIG_BACKLIGHT_QCOM_WLED) += qcom-wled.o obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.odrivers/video/backlight/qcom-wled.c renamed from drivers/video/backlight/pm8941-wled.c +0
-1--
Quoted 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
Hi Jingoo Han,
Thanks for the response.
Thanks,
Kiran
Quoted 6 lines · Jingoo Han
On Thursday, May 3, 2018 6:12 AM, Kiran Gunda wrote:
If you really want someone to review your patch, please add more detailed explanations.
1. Please add 0th patch.
I have already added the 0th patch (cover letter). Following is the subject for the same. forwarding the same to you.
[PATCH V2 0/5] backlight: qcom-wled: Support for QCOM wled driver
Quoted 2 lines
2. Please add what the difference is between V1 and V2 patches.
Already added the difference between V1 and V2 in the cover letter (0th patch). Please let me know if you are looking for any other info. Following is the difference added between v1 and v2.
Quoted 1 line
Quoted 1 line
Quoted 1 line
changes from v1:
Fixed the commit message for
backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
Quoted 87 lines
If you cannot understand what I am saying, just ask another person who have an experience to send patches to Linux mailing-list.
Best regards,
Jingoo HanQuoted 10 lines
pm8941-wled.cdriver is supporting the WLED peripheral on pm8941. Rename it toqcom-wled.cso that it can support WLED on multiple PMICs.Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2 +- drivers/video/backlight/Kconfig | 8++++----
drivers/video/backlight/Makefile obj-$(CONFIG_BACKLIGHT_OMAP1) +=
Quoted 52 lines
drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%) rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)(quoted diff) +0
-0wled.txt
b/Documentation/devicetree/bindings/leds/backlight/qcom-wled.txtsimilarity index 95%
rename fromDocumentation/devicetree/bindings/leds/backlight/pm8941-wled.txt
rename toDocumentation/devicetree/bindings/leds/backlight/qcom-wled.txtindex e5b294d..fb39e32 100644Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt renamed from Documentation/devicetree/bindings/leds/backlight/pm8941-wled.txt +1
-1@@ -1,4 +1,4 @@ -Binding for Qualcomm PM8941 WLED driver +Binding for Qualcomm Technologies, Inc. WLED driver Required properties: - compatible: should be "qcom,pm8941-wled"drivers/video/backlight/Kconfig +4
-4@@ -299,12 +299,12 @@ config BACKLIGHT_TOSA If you have an Sharp SL-6000 Zaurus say Y to enable a driver for its backlight -config BACKLIGHT_PM8941_WLED - tristate "Qualcomm PM8941 WLED Driver" +config BACKLIGHT_QCOM_WLED + tristate "Qualcomm PMIC WLED Driver" select REGMAP help - If you have the Qualcomm PM8941, say Y to enable a driver for the - WLED block. + If you have the Qualcomm PMIC, say Y to enable a driver for the + WLED block. Currently it supports PM8941 and PMI8998. config BACKLIGHT_SAHARA tristate "Tabletkiosk Sahara Touch-iT Backlight Driver"drivers/video/backlight/Makefile +0
-0@@ -49,8 +49,8 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) +=omap1_bl.o
Quoted 17 lines
drivers/video/backlight/Makefile +1
-1obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o -obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o +obj-$(CONFIG_BACKLIGHT_QCOM_WLED) += qcom-wled.o obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.odrivers/video/backlight/qcom-wled.c renamed from drivers/video/backlight/pm8941-wled.c +0
-1--The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Rob Herring
maintainerRe: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to Kiran GundaQuoted 7 lines · Kiran Gunda
pm8941-wled.cdriver is supporting the WLED peripheral on pm8941. Rename it toqcom-wled.cso that it can support WLED on multiple PMICs.Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2 +-
Please split DT bindings from driver patches.
Quoted 6 lines
drivers/video/backlight/Kconfig | 8 ++++----
drivers/video/backlight/Makefile | 2 +-
drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0
4 files changed, 6 insertions(+), 6 deletions(-)
rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%)
rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Rob Herring
maintainerRe: [PATCH V2 2/5] backlight: qcom-wled: Add support for WLED4 peripheral
In reply to Kiran GundaQuoted 7 lines · Kiran Gunda
WLED4 peripheral is present on some PMICs like pmi8998 and pm660l. It has a different register map and also configurations are different. Add support for it.
Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/qcom-wled.txt | 172 ++++-
Please split bindings to a separate patch.
This is also a whole lot of churn re-formatting. That is fine, but don't mix actual changes to the binding with re-formatting. You can do 2 patches in this case:
- move and reformat (as long as the move shows up as a move and not a remove and add)
- additions for new chips
Quoted 2 lines
drivers/video/backlight/qcom-wled.c | 749 +++++++++++++++------ 2 files changed, 696 insertions(+), 225 deletions(-)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to [email protected]Quoted 12 lines · On Mon, May 07, 2018 at 11:26:59AM +0530, [email protected] wrote:
Hi Jingoo Han,
Thanks for the response.Thanks,
KiranQuoted 6 lines · Jingoo Han
On Thursday, May 3, 2018 6:12 AM, Kiran Gunda wrote:
If you really want someone to review your patch, please add more detailed
explanations.
Quoted 5 lines
Quoted 1 line
1. Please add 0th patch.
I have already added the 0th patch (cover letter). Following is the subject for the same.
forwarding the same to you.
[PATCH V2 0/5] backlight: qcom-wled: Support for QCOM wled driver
Perhaps you should interpret Jingoo's comment as a request to improve the To: and Cc: list on the 0th patch the next time you circulate it.
Many maintainers configure their mailers to give patches where they are in the To: or Cc: list special treatment so it confusing when a series arrives with a spartan set of recipients for the 0th patch (and doubly confusing when every patch in the set targets the same driver).
Daniel.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to Kiran GundaQuoted 10 lines · Kiran Gunda
pm8941-wled.cdriver is supporting the WLED peripheral on pm8941. Rename it toqcom-wled.cso that it can support WLED on multiple PMICs.Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2 +- drivers/video/backlight/Kconfig | 8 ++++---- drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0
For me this hovers extremely close to being a gratuitous renaming especially with no effort to bridge the gap between old and new names.
On the other hand, no current defconfig enables BACKLIGHT_PM8941_WLED, it is configured by DT (so modules.conf tricks are unlikely) and any distros that already have it enables are likely to be aggressive in enabling drivers (so will probably turn on BACKLIGHT_QCOM_WLED as soon as it appears).
On that basis I can live with this... but will also listen for any complaints!
Daniel.
Quoted 60 lines
4 files changed, 6 insertions(+), 6 deletions(-) rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%) rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)Documentation/devicetree/bindings/leds/backlight/qcom-wled.txt renamed from Documentation/devicetree/bindings/leds/backlight/pm8941-wled.txt +1
-1@@ -1,4 +1,4 @@ -Binding for Qualcomm PM8941 WLED driver +Binding for Qualcomm Technologies, Inc. WLED driver Required properties: - compatible: should be "qcom,pm8941-wled"drivers/video/backlight/Kconfig +4
-4@@ -299,12 +299,12 @@ config BACKLIGHT_TOSA If you have an Sharp SL-6000 Zaurus say Y to enable a driver for its backlight -config BACKLIGHT_PM8941_WLED - tristate "Qualcomm PM8941 WLED Driver" +config BACKLIGHT_QCOM_WLED + tristate "Qualcomm PMIC WLED Driver" select REGMAP help - If you have the Qualcomm PM8941, say Y to enable a driver for the - WLED block. + If you have the Qualcomm PMIC, say Y to enable a driver for the + WLED block. Currently it supports PM8941 and PMI8998. config BACKLIGHT_SAHARA tristate "Tabletkiosk Sahara Touch-iT Backlight Driver"drivers/video/backlight/Makefile +1
-1@@ -49,8 +49,8 @@ obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o obj-$(CONFIG_BACKLIGHT_OT200) += ot200_bl.o obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o -obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o +obj-$(CONFIG_BACKLIGHT_QCOM_WLED) += qcom-wled.o obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.odrivers/video/backlight/qcom-wled.c renamed from drivers/video/backlight/pm8941-wled.c +0
-0Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to Daniel ThompsonQuoted 22 lines · Daniel Thompson
Quoted 12 lines · On Mon, May 07, 2018 at 11:26:59AM +0530, [email protected] wrote:
Hi Jingoo Han,
Thanks for the response.Thanks,
KiranQuoted 6 lines · Jingoo Han
On Thursday, May 3, 2018 6:12 AM, Kiran Gunda wrote:
If you really want someone to review your patch, please add more detailed
explanations.Quoted 5 lines
Quoted 1 line
1. Please add 0th patch.
I have already added the 0th patch (cover letter). Following is the subject for the same.
forwarding the same to you.
[PATCH V2 0/5] backlight: qcom-wled: Support for QCOM wled driverPerhaps you should interpret Jingoo's comment as a request to improve the To: and Cc: list on the 0th patch the next time you circulate it.
Quoted 7 lines
Many maintainers configure their mailers to give patches where they are in the To: or Cc: list special treatment so it confusing when a series arrives with a spartan set of recipients for the 0th patch (and doubly confusing when every patch in the set targets the same driver).
Daniel.
Ok. Got it. Not sure how the To: Cc: list on the 0th patch got shrink, while I was using the To: Cc: list same for all the patches. Anyways, will double check of it while circulating the next series.
Re: [PATCH V2 2/5] backlight: qcom-wled: Add support for WLED4 peripheral
In reply to Rob HerringQuoted 11 lines · Rob Herring
Quoted 7 lines · Kiran Gunda
WLED4 peripheral is present on some PMICs like pmi8998 and pm660l. It has a different register map and also configurations are different. Add support for it.
Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/qcom-wled.txt | 172 ++++-Please split bindings to a separate patch.
Quoted 8 lines
This is also a whole lot of churn re-formatting. That is fine, but don't mix actual changes to the binding with re-formatting. You can do 2 patches in this case:
- move and reformat (as long as the move shows up as a move and not a remove and add)
- additions for new chips
Sure. I will do it in the next series.
Quoted 3 lines
Quoted 3 lines
drivers/video/backlight/qcom-wled.c | 749 +++++++++++++++------ 2 files changed, 696 insertions(+), 225 deletions(-)
Re: [PATCH V2 1/5] backlight: qcom-wled: Rename pm8941-wled.c to qcom-wled.c
In reply to Rob HerringQuoted 5 lines · Rob Herring
Quoted 4 lines · Kiran Gunda
pm8941-wled.cdriver is supporting the WLED peripheral on pm8941. Rename it toqcom-wled.cso that it can support WLED on multiple PMICs.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Kiran Gunda <[email protected]>--- .../bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} | 2+-
Please split DT bindings from driver patches.
Sure. Will do that in the next series.
Quoted 13 lines
Quoted 9 lines
drivers/video/backlight/Kconfig | 8 ++++---- drivers/video/backlight/Makefile | 2 +- drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename Documentation/devicetree/bindings/leds/backlight/{pm8941-wled.txt => qcom-wled.txt} (95%) rename drivers/video/backlight/{pm8941-wled.c => qcom-wled.c} (100%)--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH V2 3/5] backlight: qcom-wled: Add support for short circuit handling
In reply to Kiran GundaQuoted 113 lines · Kiran Gunda
Handle the short circuit interrupt and check if the short circuit interrupt is valid. Re-enable the module to check if it goes away. Disable the module altogether if the short circuit event persists.
Signed-off-by Kiran Gunda <[email protected]>--- drivers/video/backlight/qcom-wled.c | 134 ++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 4 deletions(-)drivers/video/backlight/qcom-wled.c +29
-4@@ -10,6 +10,9 @@* GNU General Public License for more details. */ +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/ktime.h> #include <linux/kernel.h> #include <linux/backlight.h> #include <linux/module.h> @@ -23,7 +26,9 @@#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF -/* Control registers */ +/* WLED3 Control registers */ +#define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7)@@ -36,7 +41,17 @@#define WLED3_CTRL_REG_ILIMIT 0x4e#define WLED3_CTRL_REG_ILIMIT_MASK GENMASK(2, 0) -/* sink registers */ +/* WLED4 control registers */ +#define WLED4_CTRL_REG_SHORT_PROTECT 0x5e +#define WLED4_CTRL_REG_SHORT_EN_MASK BIT(7) + +#define WLED4_CTRL_REG_SEC_ACCESS 0xd0 +#define WLED4_CTRL_REG_SEC_UNLOCK 0xa5 + +#define WLED4_CTRL_REG_TEST1 0xe2 +#define WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 0x09 + +/* WLED3 sink registers */ #define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_MASK GENMASK(2, 0)#define WLED4_SINK_REG_SYNC_MASK GENMASK(3, 0)@@ -130,17 +145,23 @@ struct wled_config {bool cs_out_en;bool ext_gen;bool cabc; +bool external_pfet; };struct wled {const char *name;struct device *dev;struct regmap *regmap; +struct mutex lock;/* Lock to avoid race from ISR */ +ktime_t last_short_event;u16 ctrl_addr;u16 sink_addr;u32 brightness;u32 max_brightness; +u32 short_count;const int *version; +int short_irq; +bool force_mod_disable;struct wled_config cfg;int (*wled_set_brightness)(struct wled *wled,u16 brightness);@@ -192,6 +213,9 @@ static int wled_module_enable(struct wled *wled, int val) {int rc; +if (wled->force_mod_disable) +return 0 ; + rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN, WLED3_CTRL_REG_MOD_EN_MASK,@@ -248,12 +272,13 @@ static int wled_update_status(struct backlight_device *bl) bl->props.state & BL_CORE_FBBLANK) brightness =0 ; +mutex_lock (&wled->lock);if (brightness) { rc = wled->wled_set_brightness (wled, brightness);if (rc <0 ) {dev_err (wled->dev,"wled failed to set brightness rc:%d\n" , rc); -return rc; + goto unlock_mutex; } rc = wled->wled_sync_toggle (wled);@@ -267,15 +292,60 @@ static int wled_update_status(struct backlight_device *bl) rc =wled_module_enable (wled, !!brightness);if (rc <0 ) {dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); -return rc; + goto unlock_mutex; } } wled->brightness = brightness;
drivers/video/backlight/qcom-wled.c static int wled_update_status(struct backlight_device *bl) · line 309
Quoted 10 lines
drivers/video/backlight/qcom-wled.c +6
-0+unlock_mutex: +mutex_unlock (&wled->lock); +return rc; } +#define WLED_SHORT_DLY_MS 20 +#define WLED_SHORT_CNT_MAX 5 +#define WLED_SHORT_RESET_CNT_DLY_US HZ
So we think a short report every quarter second is harmless?
Quoted 98 lines
drivers/video/backlight/qcom-wled.c +70
-0+static irqreturn_t wled_short_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +s64 elapsed_time; + + wled->short_count++; +mutex_lock (&wled->lock); + rc =wled_module_enable (wled, false); +if (rc <0 ) { +dev_err (wled->dev,"wled disable failed rc:%d\n" , rc); + goto unlock_mutex; + } + + elapsed_time =ktime_us_delta (ktime_get (), + wled->last_short_event); +if (elapsed_time >WLED_SHORT_RESET_CNT_DLY_US ) + wled->short_count =0 ; + +if (wled->short_count >WLED_SHORT_CNT_MAX ) { +dev_err (wled->dev,"Short trigged %d times, disabling WLED forever!\n" , + wled->short_count); + wled->force_mod_disable = true; + goto unlock_mutex; + } + + wled->last_short_event =ktime_get (); + +msleep (WLED_SHORT_DLY_MS ); + rc =wled_module_enable (wled, true); +if (rc <0 ) +dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); + +unlock_mutex: +mutex_unlock (&wled->lock); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled) {u16 addr;@@ -435,6 +505,21 @@ static int wled4_setup(struct wled *wled)return rc; } +if (wled->cfg.external_pfet) { +/* Unlock the secure register access */ + rc =regmap_write (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SEC_ACCESS , +WLED4_CTRL_REG_SEC_UNLOCK ); +if (rc <0 ) +return rc; + + rc =regmap_write (wled->regmap, + wled->ctrl_addr +WLED4_CTRL_REG_TEST1 , +WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 ); +if (rc <0 ) +return rc; + } +return 0 ; }@@ -446,6 +531,7 @@ static int wled4_setup(struct wled *wled) .switch_freq = 11, .enabled_strings = 0xf, .cabc = false, + .external_pfet = true, };static const u32 wled3_boost_i_limit_values[] = {@@ -628,6 +714,7 @@ static int wled_configure(struct wled *wled) { "qcom,cs-out", &cfg->cs_out_en, }, { "qcom,ext-gen", &cfg->ext_gen, }, { "qcom,cabc", &cfg->cabc, }, + { "qcom,external-pfet", &cfg->external_pfet, }, }; prop_addr =of_get_address (dev->of_node,0 ,NULL ,NULL );@@ -701,6 +788,39 @@ static int wled_configure(struct wled *wled)return 0 ; } +static int wled_configure_short_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; + +/* PM8941 doesn't have the short detection support */ +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + rc =regmap_update_bits (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SHORT_PROTECT , +WLED4_CTRL_REG_SHORT_EN_MASK , +WLED4_CTRL_REG_SHORT_EN_MASK ); +if (rc <0 )
drivers/video/backlight/qcom-wled.c static int wled_configure(struct wled *wled) · line 814
Quoted 10 lines
drivers/video/backlight/qcom-wled.c +10
-0+return rc; + + wled->short_irq =platform_get_irq_byname (pdev,"short" ); +if (wled->short_irq <0 ) { +dev_dbg (&pdev->dev,"short irq is not used\n" ); +return 0 ; + } + + rc = devm_request_threaded_irq(wled->dev, wled->short_irq, + NULL, wled_short_irq_handler,
NULL? There's no register we can check to make sure the interrupt handler did not enter spuriously?
Quoted 36 lines
drivers/video/backlight/qcom-wled.c +15
-0+IRQF_ONESHOT , + "wled_short_irq", wled); +if (rc <0 ) +dev_err (wled->dev,"Unable to request short_irq (err:%d)\n" , + rc); + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };@@ -733,6 +853,8 @@ static int wled_probe(struct platform_device *pdev)return -ENODEV ; } +mutex_init (&wled->lock); + rc =wled_configure (wled);if (rc)return rc;@@ -752,6 +874,10 @@ static int wled_probe(struct platform_device *pdev) } } + rc =wled_configure_short_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val);Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 4/5] backlight: qcom-wled: Add support for OVP interrupt handling
In reply to Kiran GundaQuoted 4 lines · Kiran Gunda
WLED peripheral has over voltage protection(OVP) circuitry and the OVP fault is notified through an interrupt. Though this fault condition rising is due to an incorrect hardware configuration is mitigated in the hardware, it still needs to be detected and handled. Add support for it.
Why detect and handle it? The interrupt handler doesn't appear to do anything other than clear the interrupt... and it appears that the interrupt can be masked.
Quoted 197 lines
When WLED module is enabled, keep OVP fault interrupt disabled for 10 ms to account for soft start delay.
Signed-off-by Kiran Gunda <[email protected]>--- drivers/video/backlight/qcom-wled.c | 118 +++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-)drivers/video/backlight/qcom-wled.c +116
-2@@ -23,14 +23,20 @@/* From DT binding */ #define WLED_DEFAULT_BRIGHTNESS 2048 - +#define WLED_SOFT_START_DLY_US 10000#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF/* WLED3 Control registers */ #define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_ILIM_FAULT_BIT BIT(0) +#define WLED3_CTRL_REG_OVP_FAULT_BIT BIT(1) +#define WLED4_CTRL_REG_SC_FAULT_BIT BIT(2) + +#define WLED3_CTRL_REG_INT_RT_STS 0x10#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7) +#define WLED3_CTRL_REG_MOD_EN_BIT BIT(7)#define WLED3_CTRL_REG_FREQ 0x4c#define WLED3_CTRL_REG_FREQ_MASK GENMASK(3, 0)@@ -161,9 +167,12 @@ struct wled {u32 short_count;const int *version;int short_irq; +int ovp_irq;bool force_mod_disable; +bool ovp_irq_disabled;struct wled_config cfg; +struct delayed_work ovp_work;int (*wled_set_brightness)(struct wled *wled,u16 brightness);int (*wled_sync_toggle)(struct wled *wled); };@@ -209,6 +218,32 @@ static int wled4_set_brightness(struct wled *wled, u16 brightness)return 0 ; } +static void wled_ovp_work (struct work_struct *work) +{ +u32 val; +int rc; + +struct wled *wled =container_of (work, + struct wled, ovp_work.work); + + rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , + &val); +if (rc <0 ) +return ; + +if (val &WLED3_CTRL_REG_MOD_EN_BIT ) { +if (wled->ovp_irq >0 && wled->ovp_irq_disabled) { +enable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = false; + } + }else { +if (wled->ovp_irq >0 && !wled->ovp_irq_disabled) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + } +} +static int wled_module_enable (struct wled *wled,int val) {int rc;@@ -220,7 +255,12 @@ static int wled_module_enable(struct wled *wled, int val)WLED3_CTRL_REG_MOD_EN ,WLED3_CTRL_REG_MOD_EN_MASK , WLED3_CTRL_REG_MOD_EN_MASK); -return rc; +if (rc <0 ) +return rc; + +schedule_delayed_work (&wled->ovp_work,WLED_SOFT_START_DLY_US ); + +return 0 ; }static int wled3_sync_toggle (struct wled *wled)@@ -346,6 +386,36 @@ static irqreturn_t wled_short_irq_handler(int irq, void *_wled)return IRQ_HANDLED ; } +static irqreturn_t wled_ovp_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +u32 int_sts, fault_sts; + + rc =regmap_read (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_INT_RT_STS , &int_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED3_INT_RT_STS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_FAULT_STATUS , &fault_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED_FAULT_STATUS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + +if (fault_sts & + (WLED3_CTRL_REG_OVP_FAULT_BIT |WLED3_CTRL_REG_ILIM_FAULT_BIT )) +dev_dbg (wled->dev,"WLED OVP fault detected, int_sts=%x fault_sts= %x\n" , + int_sts, fault_sts); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled) {u16 addr;@@ -821,6 +891,44 @@ static int wled_configure_short_irq(struct wled *wled,return rc; } +static int wled_configure_ovp_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; +u32 val; + +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + wled->ovp_irq =platform_get_irq_byname (pdev,"ovp" ); +if (wled->ovp_irq <0 ) { +dev_dbg (&pdev->dev,"ovp irq is not used\n" ); +return 0 ; + } + + rc =devm_request_threaded_irq (wled->dev, wled->ovp_irq,NULL , + wled_ovp_irq_handler,IRQF_ONESHOT , +"wled_ovp_irq" , wled); +if (rc <0 ) { +dev_err (wled->dev,"Unable to request ovp_irq (err:%d)\n" , + rc); +return 0 ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_MOD_EN , &val); +if (rc <0 ) +return rc; + +/* Keep OVP irq disabled until module is enabled */ +if (!rc && !(val &WLED3_CTRL_REG_MOD_EN_MASK )) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };@@ -874,10 +982,16 @@ static int wled_probe(struct platform_device *pdev) } } +INIT_DELAYED_WORK (&wled->ovp_work, wled_ovp_work); + rc =wled_configure_short_irq (wled, pdev);if (rc <0 )return rc; + rc =wled_configure_ovp_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val);Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH V2 4/5] backlight: qcom-wled: Add support for OVP interrupt handling
Quoted 11 lines · Daniel Thompson
Quoted 4 lines · Kiran Gunda
WLED peripheral has over voltage protection(OVP) circuitry and the OVP fault is notified through an interrupt. Though this fault condition rising is due to an incorrect hardware configuration is mitigated in the hardware, it still needs to be detected and handled. Add support for it.
Why detect and handle it? The interrupt handler doesn't appear to do anything other than clear the interrupt... and it appears that the interrupt can be masked.
Planing to squash this patch with the auto-string-detection patch in the next series, where the OVP is used for the right string detection.
Quoted 205 lines
Quoted 205 lines
When WLED module is enabled, keep OVP fault interrupt disabled for 10 ms to account for soft start delay.
Signed-off-by Kiran Gunda <[email protected]>--- drivers/video/backlight/qcom-wled.c | 118 +++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-)drivers/video/backlight/qcom-wled.c +36
-1@@ -23,14 +23,20 @@/* From DT binding */ #define WLED_DEFAULT_BRIGHTNESS 2048 - +#define WLED_SOFT_START_DLY_US 10000#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF/* WLED3 Control registers */ #define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_ILIM_FAULT_BIT BIT(0) +#define WLED3_CTRL_REG_OVP_FAULT_BIT BIT(1) +#define WLED4_CTRL_REG_SC_FAULT_BIT BIT(2) + +#define WLED3_CTRL_REG_INT_RT_STS 0x10#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7) +#define WLED3_CTRL_REG_MOD_EN_BIT BIT(7)#define WLED3_CTRL_REG_FREQ 0x4c#define WLED3_CTRL_REG_FREQ_MASK GENMASK(3, 0)@@ -161,9 +167,12 @@ struct wled {u32 short_count;const int *version;int short_irq; +int ovp_irq;bool force_mod_disable; +bool ovp_irq_disabled;struct wled_config cfg; +struct delayed_work ovp_work;int (*wled_set_brightness)(struct wled *wled,u16 brightness);int (*wled_sync_toggle)(struct wled *wled); };@@ -209,6 +218,32 @@ static int wled4_set_brightness(struct wled *wled, u16 brightness)return 0 ; } +static void wled_ovp_work (struct work_struct *work) +{ +u32 val; +int rc; + +struct wled *wled =container_of (work, + struct wled, ovp_work.work); + + rc =regmap_read (wled->regmap, wled->ctrl_addr +WLED3_CTRL_REG_MOD_EN , + &val); +if (rc <0 ) +return ; + +if (val &WLED3_CTRL_REG_MOD_EN_BIT ) { +if (wled->ovp_irq >0 && wled->ovp_irq_disabled) { +enable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = false; + } + }else { +if (wled->ovp_irq >0 && !wled->ovp_irq_disabled) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + } +} +static int wled_module_enable (struct wled *wled,int val){
drivers/video/backlight/qcom-wled.c +6
-1int rc;@@ -220,7 +255,12 @@ static int wled_module_enable(struct wled *wled, int val)WLED3_CTRL_REG_MOD_EN ,WLED3_CTRL_REG_MOD_EN_MASK , WLED3_CTRL_REG_MOD_EN_MASK); -return rc; +if (rc <0 ) +return rc; + +schedule_delayed_work (&wled->ovp_work,WLED_SOFT_START_DLY_US ); + +return 0 ; }static int
wled3_sync_toggle(struct wled *wled)drivers/video/backlight/qcom-wled.c +30
-0@@ -346,6 +386,36 @@ static irqreturn_t wled_short_irq_handler(int irq, void *_wled)return IRQ_HANDLED ; } +static irqreturn_t wled_ovp_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +u32 int_sts, fault_sts; + + rc =regmap_read (wled->regmap, + wled->ctrl_addr +WLED3_CTRL_REG_INT_RT_STS , &int_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED3_INT_RT_STS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_FAULT_STATUS , &fault_sts); +if (rc <0 ) { +dev_err (wled->dev,"Error in reading WLED_FAULT_STATUS rc=%d\n" , + rc); +return IRQ_HANDLED ; + } + +if (fault_sts & + (WLED3_CTRL_REG_OVP_FAULT_BIT |WLED3_CTRL_REG_ILIM_FAULT_BIT )) + dev_dbg(wled->dev, "WLED OVP fault detected, int_sts=%x fault_sts= %x\n", + int_sts, fault_sts); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled){
drivers/video/backlight/qcom-wled.c +38
-0u16 addr;@@ -821,6 +891,44 @@ static int wled_configure_short_irq(struct wled *wled, return rc; } +static int wled_configure_ovp_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; +u32 val; + +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + wled->ovp_irq =platform_get_irq_byname (pdev,"ovp" ); +if (wled->ovp_irq <0 ) { +dev_dbg (&pdev->dev,"ovp irq is not used\n" ); +return 0 ; + } + + rc =devm_request_threaded_irq (wled->dev, wled->ovp_irq,NULL , + wled_ovp_irq_handler,IRQF_ONESHOT , +"wled_ovp_irq" , wled); +if (rc <0 ) { +dev_err (wled->dev,"Unable to request ovp_irq (err:%d)\n" , + rc); +return 0 ; + } + + rc =regmap_read (wled->regmap, wled->ctrl_addr + +WLED3_CTRL_REG_MOD_EN , &val); +if (rc <0 ) +return rc; + +/* Keep OVP irq disabled until module is enabled */ +if (!rc && !(val &WLED3_CTRL_REG_MOD_EN_MASK )) { +disable_irq (wled->ovp_irq); + wled->ovp_irq_disabled = true; + } + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status,};
drivers/video/backlight/qcom-wled.c +6
-1@@ -874,10 +982,16 @@ static int wled_probe(struct platform_device *pdev) } } +INIT_DELAYED_WORK (&wled->ovp_work, wled_ovp_work); + rc =wled_configure_short_irq (wled, pdev);if (rc <0 )return rc; + rc =wled_configure_ovp_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
Re: [PATCH V2 3/5] backlight: qcom-wled: Add support for short circuit handling
In reply to Daniel ThompsonQuoted 125 lines · Daniel Thompson
Quoted 124 lines · Kiran Gunda
Handle the short circuit interrupt and check if the short circuit interrupt is valid. Re-enable the module to check if it goes away. Disable the module altogether if the short circuit event persists.
Signed-off-by Kiran Gunda <[email protected]>--- drivers/video/backlight/qcom-wled.c | 134 ++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 4 deletions(-)drivers/video/backlight/qcom-wled.c +26
-2@@ -10,6 +10,9 @@* GNU General Public License for more details. */ +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/ktime.h> #include <linux/kernel.h> #include <linux/backlight.h> #include <linux/module.h> @@ -23,7 +26,9 @@#define WLED3_SINK_REG_BRIGHT_MAX 0xFFF -/* Control registers */ +/* WLED3 Control registers */ +#define WLED3_CTRL_REG_FAULT_STATUS 0x08 +#define WLED3_CTRL_REG_MOD_EN 0x46#define WLED3_CTRL_REG_MOD_EN_MASK BIT(7)@@ -36,7 +41,17 @@#define WLED3_CTRL_REG_ILIMIT 0x4e#define WLED3_CTRL_REG_ILIMIT_MASK GENMASK(2, 0) -/* sink registers */ +/* WLED4 control registers */ +#define WLED4_CTRL_REG_SHORT_PROTECT 0x5e +#define WLED4_CTRL_REG_SHORT_EN_MASK BIT(7) + +#define WLED4_CTRL_REG_SEC_ACCESS 0xd0 +#define WLED4_CTRL_REG_SEC_UNLOCK 0xa5 + +#define WLED4_CTRL_REG_TEST1 0xe2 +#define WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 0x09 + +/* WLED3 sink registers */ #define WLED3_SINK_REG_SYNC 0x47#define WLED3_SINK_REG_SYNC_MASK GENMASK(2, 0)#define WLED4_SINK_REG_SYNC_MASK GENMASK(3, 0)@@ -130,17 +145,23 @@ struct wled_config {bool cs_out_en;bool ext_gen;bool cabc; +bool external_pfet; };struct wled {const char *name;struct device *dev;struct regmap *regmap; +struct mutex lock;/* Lock to avoid race from ISR */ +ktime_t last_short_event;u16 ctrl_addr;u16 sink_addr;u32 brightness;u32 max_brightness; +u32 short_count;const int *version; +int short_irq; +bool force_mod_disable;struct wled_config cfg;int (*wled_set_brightness)(struct wled *wled,u16 brightness);@@ -192,6 +213,9 @@ static int wled_module_enable(struct wled *wled, int val) {int rc; +if (wled->force_mod_disable) +return 0 ; + rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + WLED3_CTRL_REG_MOD_EN,drivers/video/backlight/qcom-wled.c +2
-1WLED3_CTRL_REG_MOD_EN_MASK,@@ -248,12 +272,13 @@ static int wled_update_status(struct backlight_device *bl) bl->props.state & BL_CORE_FBBLANK) brightness =0 ; +mutex_lock (&wled->lock);if (brightness) { rc = wled->wled_set_brightness (wled, brightness);if (rc <0 ) {dev_err (wled->dev,"wled failed to set brightness rc:%d\n" , rc); -return rc; + goto unlock_mutex; }drivers/video/backlight/qcom-wled.c +4
-1rc = wled->wled_sync_toggle (wled);@@ -267,15 +292,60 @@ static int wled_update_status(struct backlight_device *bl) rc =wled_module_enable (wled, !!brightness);if (rc <0 ) {dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); -return rc; + goto unlock_mutex; } } wled->brightness = brightness; +unlock_mutex: +mutex_unlock (&wled->lock); +return rc; }
Quoted 7 lines
drivers/video/backlight/qcom-wled.c static int wled_update_status(struct backlight_device *bl) · line 309
Quoted 3 lines
drivers/video/backlight/qcom-wled.c +3
-0+#define WLED_SHORT_DLY_MS 20 +#define WLED_SHORT_CNT_MAX 5 +#define WLED_SHORT_RESET_CNT_DLY_US HZSo we think a short report every quarter second is harmless?
Yes. We wait for the short to report 5 times with in this time. If the short still persists, we go and disable the WLED module to avoid the damage. This is suggested by the HW team.
Quoted 104 lines
Quoted 104 lines
drivers/video/backlight/qcom-wled.c +39
-0+static irqreturn_t wled_short_irq_handler (int irq,void *_wled) +{ +struct wled *wled = _wled; +int rc; +s64 elapsed_time; + + wled->short_count++; +mutex_lock (&wled->lock); + rc =wled_module_enable (wled, false); +if (rc <0 ) { +dev_err (wled->dev,"wled disable failed rc:%d\n" , rc); + goto unlock_mutex; + } + + elapsed_time =ktime_us_delta (ktime_get (), + wled->last_short_event); +if (elapsed_time >WLED_SHORT_RESET_CNT_DLY_US ) + wled->short_count =0 ; + +if (wled->short_count >WLED_SHORT_CNT_MAX ) { +dev_err (wled->dev,"Short trigged %d times, disabling WLED forever!\n", + wled->short_count); + wled->force_mod_disable = true; + goto unlock_mutex; + } + + wled->last_short_event =ktime_get (); + +msleep (WLED_SHORT_DLY_MS ); + rc =wled_module_enable (wled, true); +if (rc <0 ) +dev_err (wled->dev,"wled enable failed rc:%d\n" , rc); + +unlock_mutex: +mutex_unlock (&wled->lock); + +return IRQ_HANDLED ; +} +static int wled3_setup (struct wled *wled){
drivers/video/backlight/qcom-wled.c +36
-0u16 addr;@@ -435,6 +505,21 @@ static int wled4_setup(struct wled *wled)return rc; } +if (wled->cfg.external_pfet) { +/* Unlock the secure register access */ + rc =regmap_write (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SEC_ACCESS , +WLED4_CTRL_REG_SEC_UNLOCK ); +if (rc <0 ) +return rc; + + rc =regmap_write (wled->regmap, + wled->ctrl_addr +WLED4_CTRL_REG_TEST1 , +WLED4_CTRL_REG_TEST1_EXT_FET_DTEST2 ); +if (rc <0 ) +return rc; + } +return 0 ; }@@ -446,6 +531,7 @@ static int wled4_setup(struct wled *wled) .switch_freq = 11, .enabled_strings = 0xf, .cabc = false, + .external_pfet = true, };static const u32 wled3_boost_i_limit_values[] = {@@ -628,6 +714,7 @@ static int wled_configure(struct wled *wled) { "qcom,cs-out", &cfg->cs_out_en, }, { "qcom,ext-gen", &cfg->ext_gen, }, { "qcom,cabc", &cfg->cabc, }, + { "qcom,external-pfet", &cfg->external_pfet, }, }; prop_addr =of_get_address (dev->of_node,0 ,NULL ,NULL );@@ -701,6 +788,39 @@ static int wled_configure(struct wled *wled)return 0 ; } +static int wled_configure_short_irq (struct wled *wled, +struct platform_device *pdev) +{ +int rc =0 ; + +/* PM8941 doesn't have the short detection support */ +if (*wled->version ==WLED_PM8941 ) +return 0 ; + + rc =regmap_update_bits (wled->regmap, wled->ctrl_addr + +WLED4_CTRL_REG_SHORT_PROTECT , +WLED4_CTRL_REG_SHORT_EN_MASK , +WLED4_CTRL_REG_SHORT_EN_MASK ); +if (rc <0 ) +return rc; + + wled->short_irq =platform_get_irq_byname (pdev,"short" ); +if (wled->short_irq <0 ) { +dev_dbg (&pdev->dev,"short irq is not used\n" );
Quoted 10 lines
drivers/video/backlight/qcom-wled.c static int wled_configure(struct wled *wled) · line 814
Quoted 5 lines
drivers/video/backlight/qcom-wled.c +5
-0+return 0 ; + } + + rc = devm_request_threaded_irq(wled->dev, wled->short_irq, + NULL, wled_short_irq_handler,NULL? There's no register we can check to make sure the interrupt handler did not enter spuriously?
There is FAULT_STATUS register. I will address it in the next series.
Quoted 38 lines
Quoted 38 lines
drivers/video/backlight/qcom-wled.c +11
-0+IRQF_ONESHOT , + "wled_short_irq", wled); +if (rc <0 ) +dev_err (wled->dev,"Unable to request short_irq (err:%d)\n" , + rc); + +return rc; +} +static const struct backlight_ops wled_ops = { .update_status = wled_update_status, };@@ -733,6 +853,8 @@ static int wled_probe(struct platform_device *pdev)return -ENODEV ; } +mutex_init (&wled->lock); + rc =wled_configure (wled);if (rc)drivers/video/backlight/qcom-wled.c +4
-1return rc;@@ -752,6 +874,10 @@ static int wled_probe(struct platform_device *pdev) } } + rc =wled_configure_short_irq (wled, pdev); +if (rc <0 ) +return rc; + val =WLED_DEFAULT_BRIGHTNESS ;of_property_read_u32 (pdev->dev.of_node,"default-brightness" , &val); --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project