Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2938761imm; Fri, 20 Jul 2018 07:29:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcCoPdLNP8bRjOlmo1yTrPwGk1ajIPfWEdgpWW6KiuiXmWsH1Yt9SivwYNb+pvexREBWr3J X-Received: by 2002:a63:571d:: with SMTP id l29-v6mr2258290pgb.296.1532096985678; Fri, 20 Jul 2018 07:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532096985; cv=none; d=google.com; s=arc-20160816; b=XbgDE8ws+mDO02IiT9fWMdj0+PfJtAGMBbYs2DB0hJMWY0H0HtY3lIKC9aKpQAA1WH ZElJcEWTHMOaOfaacflaHJ6QaZuy6UMpP3zqzJvQk0Hi6v8d4EBmdT6ObwEh4ueSr3B7 0hjJvc5IuWsnzNx/ZVlIILqWyojIJxMFzd1T/8VcRVFcBjXpMZPqQZ7gjMEhzK/FZPVY goVkuV3q2sSPp/myf5oeeax+RaLk4zvYE7WYvkcJAbhmoZY4yk6WxX473FiBFxsGPVCm 4/vhD+qv3/a4PpjNOoyKT7rZqcQO7g+WV9QI67FsWwEgL95Y/YIGQGbXAQkC3WcuvKu5 e8Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=3aBH3Auw0nDb/jP2lXlkT5e9tLD44GenlLCmj5VqHQw=; b=CVmHYe+B8hHbBIaX9MVwgQKkBonfYFshCAFjxte+r1dkPZRB4iXkrwDoHDUQcUa6FI ZxHXrPVD7/6FpWhTX4wejtWeckSUgRuJUz8au4DQzqZQhcdkkrQUl+mkok22OUwuQax2 XPiFOs68CI6US3rcMPbCaZaAs599my7B2dtm0ErRhXpSF+U81aRJIc8JOrRw71zJz8ar m5HiT4e+zZAAhx/Cb3lLp3/fwXBBk7xhOtENjKxuB53pC00lbvuXmGgePeXDSbwPUE18 Br1/ygKyrkawu/1mkAdnclq7EpMv5GcGVjfRtBf6qzWQNZf1bH9lNYR7WSwXAAnKwKZl Y5qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jQdy7/ki"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e185-v6si1852640pgc.318.2018.07.20.07.29.28; Fri, 20 Jul 2018 07:29:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jQdy7/ki"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731642AbeGTOzt (ORCPT + 99 others); Fri, 20 Jul 2018 10:55:49 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:35965 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731000AbeGTOzt (ORCPT ); Fri, 20 Jul 2018 10:55:49 -0400 Received: by mail-wr1-f68.google.com with SMTP id h9-v6so11483992wro.3 for ; Fri, 20 Jul 2018 07:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=3aBH3Auw0nDb/jP2lXlkT5e9tLD44GenlLCmj5VqHQw=; b=jQdy7/kiGqbnV93zCW3Yf+Y8GbMt5ozKJWV7Kjx0qG5gMzOrxBhsOTU4M0ryG01JoV Cavr14LGnusNqsZonp8s9PnFvHzTupAmKVBmL21pRAhlgI74juO6J05dj9yHGoJc35B9 1qiQGvhAo62ssMle1vDiKxvFv7bs0Hw7OyDBU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=3aBH3Auw0nDb/jP2lXlkT5e9tLD44GenlLCmj5VqHQw=; b=rutnBISG6Fwk5Dkjk9tBAbJ9x9FskhryHC/Vs31hagxfdjWwIOov65VhVFjnUmLiZH MZE2aV55g92u3yNpZ7mCBuMEl73GqCJcE2uAK7jjir0T1TKXJtBW3qBMhAPF1jVEPkJb xoIOCMnOe5R2zhVblelqOGJzbhCSh2BibPUTS958WmUfvRc1tBf5J/SPxgLD+jr70CgT LI3TgTgXmekcLQjElegPh1DUDofo6Dgf/EagAg4qgNh0xPgE3YSyR4wTBanIqqaCYkdk 2vdtkiPRLfs03a1JxC6REVUXQzQu8rZtFnFOYjyx4/Ef8zX8sI4fBUW6nulHHV2YTmwH tSYA== X-Gm-Message-State: AOUpUlE0OehqOqPRvNXyL5T/9lT/CSFCmcbPSJsL/szon3P3sdYcIc6H cmiLqcetBjtRe77SSCDrsnaPNw== X-Received: by 2002:a5d:4643:: with SMTP id j3-v6mr1592938wrs.52.1532095639973; Fri, 20 Jul 2018 07:07:19 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.googlemail.com with ESMTPSA id o8-v6sm2050255wro.68.2018.07.20.07.07.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jul 2018 07:07:18 -0700 (PDT) Subject: Re: [PATCH V4 7/8] backlight: qcom-wled: add support for short circuit handling To: Kiran Gunda , bjorn.andersson@linaro.org, jingoohan1@gmail.com, lee.jones@linaro.org, b.zolnierkie@samsung.com, dri-devel@lists.freedesktop.org, jacek.anaszewski@gmail.com, pavel@ucw.cz, robh+dt@kernel.org, mark.rutland@arm.com, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fbdev@vger.kernel.org Cc: linux-arm-msm@vger.kernel.org References: <1531131741-19971-1-git-send-email-kgunda@codeaurora.org> <1531131741-19971-8-git-send-email-kgunda@codeaurora.org> From: Daniel Thompson Message-ID: <1a708fea-0759-fcd0-d169-a36e21c31c28@linaro.org> Date: Fri, 20 Jul 2018 15:07:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1531131741-19971-8-git-send-email-kgunda@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/07/18 11:22, Kiran Gunda wrote: > 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 > Reviewed-by: Bjorn Andersson > --- > Changes from V3: > - Added Reviewed by tag. > - Addressed minor comments from Vinod > > drivers/video/backlight/qcom-wled.c | 132 ++++++++++++++++++++++++++++++++++-- > 1 file changed, 128 insertions(+), 4 deletions(-) > > diff --git a/drivers/video/backlight/qcom-wled.c b/drivers/video/backlight/qcom-wled.c > index 362d254..a14f1a6 100644 > --- a/drivers/video/backlight/qcom-wled.c > +++ b/drivers/video/backlight/qcom-wled.c > @@ -10,6 +10,9 @@ > * GNU General Public License for more details. > */ > > +#include > +#include > +#include > #include > #include > #include > @@ -64,6 +67,16 @@ > #define WLED3_SINK_REG_STR_CABC(n) (0x66 + (n * 0x10)) > #define WLED3_SINK_REG_STR_CABC_MASK BIT(7) > > +/* WLED4 specific 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 > + > /* WLED4 specific sink registers */ > #define WLED4_SINK_REG_CURR_SINK 0x46 > #define WLED4_SINK_REG_CURR_SINK_MASK GENMASK(7, 4) > @@ -113,17 +126,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 thread irq handler */ > + ktime_t last_short_event; > u16 ctrl_addr; > u16 sink_addr; > u16 max_string_count; > u32 brightness; > u32 max_brightness; > + u32 short_count; > + bool disabled_by_short; > + bool has_short_detect; > > struct wled_config cfg; > int (*wled_set_brightness)(struct wled *wled, u16 brightness); > @@ -174,6 +193,9 @@ static int wled_module_enable(struct wled *wled, int val) > { > int rc; > > + if (wled->disabled_by_short) > + return -EFAULT; EFAULT means bad address (memory fault). Perhaps EIO or maybe even something more exotic like ENXIO might be more appropriate? > + > rc = regmap_update_bits(wled->regmap, wled->ctrl_addr + > WLED_CTRL_REG_MOD_EN, > WLED_CTRL_REG_MOD_EN_MASK, > @@ -210,18 +232,19 @@ 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_sync_toggle(wled); > if (rc < 0) { > dev_err(wled->dev, "wled sync failed rc:%d\n", rc); > - return rc; > + goto unlock_mutex; > } > } > > @@ -229,15 +252,61 @@ 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 USEC_PER_SEC > + > +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; Shouldn't this reset to 1 (e.g. we have just seen a short). Daniel.