Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp602707imm; Wed, 1 Aug 2018 02:04:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdSizLq8XIGpyn7kTaAuZeze5Ss5xCMeZC0z0xPHTgNmbsz54ROz3rhWybcLbpyV6gs5fNf X-Received: by 2002:a63:f953:: with SMTP id q19-v6mr23212520pgk.292.1533114271910; Wed, 01 Aug 2018 02:04:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533114271; cv=none; d=google.com; s=arc-20160816; b=cOmlHQldM2t/SJXPLsV3otOgYX6TmKBPlnVL0+s9U1by7S+lP9GCp1rCLW7t6UOU6R 3pxLIqYMuiGa7RmI23p0K7UOVHv3EELvcvUS0kjUCSydTVH74l+/hxlcuAGtNmPFy22h 5bfHJ3eqwryUa+1VnILNStBuViBKjrOaV7QWA74lUbt+8S1olf2WTsNoU7azVc06tP3N iOX5d2sYtvljssjkC+ckDs2RrDDMnBtUGQo0ZuFIAGd6tlm58x7FSwQbATGk3UaLpgt+ Umv10/A3lrgNHDd2thB+EJ1E7tYNgqBWZQOJbYNEYg5B7jleCBKOgYKdBHu2QW4YUXBa pO1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=V489fPjcWJFEgMeaZj6nA1jSnBaSIxvzoUyi5ky2k2w=; b=qE1gJlAbafnLG6pO4BgthbCjT76Tzbs2VotAjOeELEfkziTeK/rlmbnePkh1EMdJ8x LcQCUuXG86vq84xEQdyhjtqD+imXBUguj//TAHqJu8DI3ghrdO+HFZdTe5CtEaQdcQtZ 9//MQMZqOe8pbfSppbJXW8vnKyaMa2dWfZ3m9XOiZDGA419xVhsMdKuGo33K9XEjHIJr +8W9aRjqWNSCeeIcx1rglicPvKB7bqgo45Jg7DHe2kAJuXrrQwQIFiO3SGy3+5cgK/Ok YKWIT2xBlOYPdbY2aUwNU0O7tPOP36T1kFSb3dlXUI0tFs2EYuFM5MtQcVPJYRXOE6v4 OEeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Jphq42WU; 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 d5-v6si14142724plo.3.2018.08.01.02.04.17; Wed, 01 Aug 2018 02:04:31 -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=Jphq42WU; 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 S2388892AbeHAKrl (ORCPT + 99 others); Wed, 1 Aug 2018 06:47:41 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43228 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388774AbeHAKrk (ORCPT ); Wed, 1 Aug 2018 06:47:40 -0400 Received: by mail-pg1-f194.google.com with SMTP id d17-v6so6062886pgv.10 for ; Wed, 01 Aug 2018 02:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=V489fPjcWJFEgMeaZj6nA1jSnBaSIxvzoUyi5ky2k2w=; b=Jphq42WUOusIpGAfz/0kWpe2G+gHhAAXMK/TI16VPOl0ntbsGHfU1wXcm7lj6V3DL1 ZH3+xniSLMCZSHntqHMEFlDFgg2eTCwKzLSCH2P31OzhSghUOuidSDKcDgZ0aexgwbxT jHvVd+N0k8MO47C1UGkZrJsyyhh7+tyeAT7Sc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=V489fPjcWJFEgMeaZj6nA1jSnBaSIxvzoUyi5ky2k2w=; b=R0wLtMG5mMPmHHDcpmhV59GjIOqixcWbDECSrjeWKRs3hY5wp5Mmy/ywQwXFJzpX8J KbRy4h8sdeuFAdgU62NKNPcahA88efqkB2oBaTA04hI3rVQOtoIKWKJQwWoG/tgAgCiI e1tpz9nDAAf/fOyfXwOPqCOWxS5WpNHVt6Dt2dbln6JkgvXZVj/Mp2+CYxnhyA9rCV+p FKspIZWg+NGRbh45wvOvK/VeZhqEKz1YGAlPmDEFalpG9WvfTUTIIAIACIeJFX7eIVI+ yC72Yrp1+uPHriTG8YS0BYcXhMqioEw0+VWS7VEEwmgb8XM0YRuFAa/aEOMlHHFNFUZb 5Vig== X-Gm-Message-State: AOUpUlE84v92YliXgGrJ/kEufyX5BYvxkFpOl7U/UW6DZNju5JxyFmWH H0UrPLd0EBmsioeuK8ZDLOeURg== X-Received: by 2002:a63:524e:: with SMTP id s14-v6mr24143820pgl.35.1533114176752; Wed, 01 Aug 2018 02:02:56 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id f90-v6sm7215590pfh.168.2018.08.01.02.02.53 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 01 Aug 2018 02:02:56 -0700 (PDT) From: Baolin Wang To: jacek.anaszewski@gmail.com, pavel@ucw.cz Cc: rteysseyre@gmail.com, bjorn.andersson@linaro.org, david@lechnology.com, baolin.wang@linaro.org, broonie@kernel.org, linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] leds: sc27xx: Add pattern_set/clear interfaces for LED controller Date: Wed, 1 Aug 2018 17:01:43 +0800 Message-Id: <1a902eb33d1643466e77d339ff025623cdd2fda4.1533112637.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1bf9aed83d1756dd4f81590297ce7e0b9972bf85.1533112637.git.baolin.wang@linaro.org> References: <1bf9aed83d1756dd4f81590297ce7e0b9972bf85.1533112637.git.baolin.wang@linaro.org> In-Reply-To: <1bf9aed83d1756dd4f81590297ce7e0b9972bf85.1533112637.git.baolin.wang@linaro.org> References: <1bf9aed83d1756dd4f81590297ce7e0b9972bf85.1533112637.git.baolin.wang@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch implements the 'pattern_set'and 'pattern_clear' interfaces to support SC27XX LED breathing mode. Signed-off-by: Baolin Wang --- changes from v1: - Remove pattern_get interface. --- drivers/leds/leds-sc27xx-bltc.c | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/leds/leds-sc27xx-bltc.c b/drivers/leds/leds-sc27xx-bltc.c index 9d9b7aa..297dd43 100644 --- a/drivers/leds/leds-sc27xx-bltc.c +++ b/drivers/leds/leds-sc27xx-bltc.c @@ -32,8 +32,13 @@ #define SC27XX_DUTY_MASK GENMASK(15, 0) #define SC27XX_MOD_MASK GENMASK(7, 0) +#define SC27XX_CURVE_SHIFT 8 +#define SC27XX_CURVE_L_MASK GENMASK(7, 0) +#define SC27XX_CURVE_H_MASK GENMASK(15, 8) + #define SC27XX_LEDS_OFFSET 0x10 #define SC27XX_LEDS_MAX 3 +#define SC27XX_LEDS_PATTERN_CNT 4 struct sc27xx_led { char name[LED_MAX_NAME_SIZE]; @@ -122,6 +127,91 @@ static int sc27xx_led_set(struct led_classdev *ldev, enum led_brightness value) return err; } +static int sc27xx_led_pattern_clear(struct led_classdev *ldev) +{ + struct sc27xx_led *leds = to_sc27xx_led(ldev); + struct regmap *regmap = leds->priv->regmap; + u32 base = sc27xx_led_get_offset(leds); + u32 ctrl_base = leds->priv->base + SC27XX_LEDS_CTRL; + u8 ctrl_shift = SC27XX_CTRL_SHIFT * leds->line; + int err; + + mutex_lock(&leds->priv->lock); + + /* Reset the rise, high, fall and low time to zero. */ + regmap_write(regmap, base + SC27XX_LEDS_CURVE0, 0); + regmap_write(regmap, base + SC27XX_LEDS_CURVE1, 0); + + err = regmap_update_bits(regmap, ctrl_base, + (SC27XX_LED_RUN | SC27XX_LED_TYPE) << ctrl_shift, 0); + + mutex_unlock(&leds->priv->lock); + + return err; +} + +static int sc27xx_led_pattern_set(struct led_classdev *ldev, + struct led_pattern *pattern, + int len, u32 repeat) +{ + struct sc27xx_led *leds = to_sc27xx_led(ldev); + u32 base = sc27xx_led_get_offset(leds); + u32 ctrl_base = leds->priv->base + SC27XX_LEDS_CTRL; + u8 ctrl_shift = SC27XX_CTRL_SHIFT * leds->line; + struct regmap *regmap = leds->priv->regmap; + int err; + + /* + * Must contain 4 patterns to configure the rise time, high time, fall + * time and low time to enable the breathing mode. + */ + if (len != SC27XX_LEDS_PATTERN_CNT) + return -EINVAL; + + mutex_lock(&leds->priv->lock); + + err = regmap_update_bits(regmap, base + SC27XX_LEDS_CURVE0, + SC27XX_CURVE_L_MASK, pattern[0].delta_t); + if (err) + goto out; + + err = regmap_update_bits(regmap, base + SC27XX_LEDS_CURVE1, + SC27XX_CURVE_L_MASK, pattern[1].delta_t); + if (err) + goto out; + + err = regmap_update_bits(regmap, base + SC27XX_LEDS_CURVE0, + SC27XX_CURVE_H_MASK, + pattern[2].delta_t << SC27XX_CURVE_SHIFT); + if (err) + goto out; + + + err = regmap_update_bits(regmap, base + SC27XX_LEDS_CURVE1, + SC27XX_CURVE_H_MASK, + pattern[3].delta_t << SC27XX_CURVE_SHIFT); + if (err) + goto out; + + + err = regmap_update_bits(regmap, base + SC27XX_LEDS_DUTY, + SC27XX_DUTY_MASK, + (pattern[0].brightness << SC27XX_DUTY_SHIFT) | + SC27XX_MOD_MASK); + if (err) + goto out; + + /* Enable the LED breathing mode */ + err = regmap_update_bits(regmap, ctrl_base, + SC27XX_LED_RUN << ctrl_shift, + SC27XX_LED_RUN << ctrl_shift); + +out: + mutex_unlock(&leds->priv->lock); + + return err; +} + static int sc27xx_led_register(struct device *dev, struct sc27xx_led_priv *priv) { int i, err; @@ -140,6 +230,9 @@ static int sc27xx_led_register(struct device *dev, struct sc27xx_led_priv *priv) led->priv = priv; led->ldev.name = led->name; led->ldev.brightness_set_blocking = sc27xx_led_set; + led->ldev.pattern_set = sc27xx_led_pattern_set; + led->ldev.pattern_clear = sc27xx_led_pattern_clear; + led->ldev.default_trigger = "pattern"; err = devm_led_classdev_register(dev, &led->ldev); if (err) @@ -241,4 +334,5 @@ static int sc27xx_led_remove(struct platform_device *pdev) MODULE_DESCRIPTION("Spreadtrum SC27xx breathing light controller driver"); MODULE_AUTHOR("Xiaotong Lu "); +MODULE_AUTHOR("Baolin Wang "); MODULE_LICENSE("GPL v2"); -- 1.7.9.5