Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp4696166imm; Mon, 25 Jun 2018 22:09:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKYEsuaYpR51CLOHlChJ8rGC/XDKWNbcXmQX2zdQf3vGxlkq07ciVOuqqntXcxTWQRVzuXT X-Received: by 2002:a65:62cd:: with SMTP id m13-v6mr12107pgv.280.1529989759466; Mon, 25 Jun 2018 22:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529989759; cv=none; d=google.com; s=arc-20160816; b=cJl/fBVNnwti8SFomavWAmtroUcSt/b75IKkmZQMzlpJ0Yc8yr/LjXezK29ewcwu6P A4wiqJYHPV9sCpe5EHRKgrwBRIuGBQxQb9a5LwFxej9wqq5I0SC4Ywy4EiUY35zyy7vM Zynj/7vvikeuW/Jn3EDpY9OhINsDXAp+sbWQGvaq7W7DG2BFjYLab5moWwu4+ruKDrDH 1ezqWpg7GmunpQJGgQtTQSU4CIG6tTA9utB40yMcGuh7PXMT7vV6Rei7UiCc08ce9T7V JxvJe8Jm/haM4XZQs9oq/rtxh5nIJlQgTnZUVSTgCq5XfAezIG8BbZdFmFsIrJs538p1 Pw9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=8uIr3Oh/NSxGyYB+8z2Pu8rXkyWRCewAveDkujPCgFY=; b=zg4auQWwRPIkTj1pQFAI03N0KKuRHiI2xTYC0qfIpDOzfs3qzzKs+RW7D5lc7h8CcB kmBzK6ULkKTgJrqbfS/J3iwqSe3WU5RDDWFVUFgGPrpTXGIAj7H/08E+14eNLcHGd4y2 FOnk15r1D1UsLWcDZSykG+AsDol6+sq1oXd00KB5gzFMUlINbpqcEG1CdktLXAoci6hv 3fT8ZyBiiafj7Re29JcDDKL41bINEiejMqBOVhjwyg24RCqIJuUhNbcVfuJH6hrBsgMv ACNjx4eUHc4+Ml2x5OurdYnWpPf9+fqCmX8GU2Dj/XReBAx4+4McYCqVcXQJn7/JIOZs TMog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AwoG22tz; 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 x68-v6si762168pfc.239.2018.06.25.22.09.05; Mon, 25 Jun 2018 22:09:19 -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=AwoG22tz; 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 S1751469AbeFZFIG (ORCPT + 99 others); Tue, 26 Jun 2018 01:08:06 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:39900 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751176AbeFZFIE (ORCPT ); Tue, 26 Jun 2018 01:08:04 -0400 Received: by mail-oi0-f68.google.com with SMTP id 18-v6so5264143oiq.6 for ; Mon, 25 Jun 2018 22:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8uIr3Oh/NSxGyYB+8z2Pu8rXkyWRCewAveDkujPCgFY=; b=AwoG22tzUsKxEw/NIyfsHzRoGS8kN6mRrQDtb7wmpkiBhjdF5rkdW8KCVD/fKioNNE 6i7JQpbP1RpBqOlE/6hcYarQwO7YABDaXtu8bpET9i6MFWdZXgSvWaO2CemXVoGkG7OX noU5EAQaXPUiE2Zv+hGY3BPDRSAKbSguWX0cw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8uIr3Oh/NSxGyYB+8z2Pu8rXkyWRCewAveDkujPCgFY=; b=tkAA+6kL1aZkyQH8AidDK3JynnvuqkF6T4vlEPu8klvQNGxHscl2mmTsg9jNWewPa8 qa+iIzsnPc3YFG3m3B9MyLGmEJerPFFeyxfrEfBe5DFVxpy5d4wgpCFPC1eziYKK1/jp j67C3jLy7XGa8EUCF3ygvZ4Y9t1y3gOA+0IsAhXhiws11WZQNlWe8TGSkmpXmT/7Z4cQ axQRvwEeAVfeBTsAdAx2kSGGC5iac9+tsZ88imoacd4pCULgu6a7teQtzD/LT9Sob/76 xD2T+6Zg45VcQNn7gPY4YhIzvdKSJfc2HSyz4oBlfEF13/oWiEAm3EUbHh7OTezQbvbj V7KQ== X-Gm-Message-State: APt69E1O9kDnDJ2zjzwFYKSZl45iVRCdyBFXPT3DEqpbLBujc3ZMijyp q4/EjMu0PpqPNFC7RwBNLIC+UlmXSYwqvdvla2Bo2Q== X-Received: by 2002:aca:686:: with SMTP id 128-v6mr8830725oig.31.1529989683958; Mon, 25 Jun 2018 22:08:03 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:237a:0:0:0:0:0 with HTTP; Mon, 25 Jun 2018 22:08:03 -0700 (PDT) In-Reply-To: <20180625121845.GA32505@amd> References: <046c0cf717cbdfd55dcdc2bb7463642734e2ca4c.1529902636.git.baolin.wang@linaro.org> <20180625121845.GA32505@amd> From: Baolin Wang Date: Tue, 26 Jun 2018 13:08:03 +0800 Message-ID: Subject: Re: [PATCH 1/2] leds: core: Introduce generic pattern interface To: Pavel Machek Cc: Jacek Anaszewski , Bjorn Andersson , Mark Brown , linux-leds@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pavel, On 25 June 2018 at 20:18, Pavel Machek wrote: > On Mon 2018-06-25 13:03:19, Baolin Wang wrote: >> From: Bjorn Andersson >> >> Some LED controllers have support for autonomously controlling >> brightness over time, according to some preprogrammed pattern or >> function. >> >> This adds a new optional operator that LED class drivers can implement >> if they support such functionality as well as a new device attribute to >> configure the pattern for a given LED. > > Thanks for doing this! > >> index 5f67f7a..fe90a12 100644 >> --- a/Documentation/ABI/testing/sysfs-class-led >> +++ b/Documentation/ABI/testing/sysfs-class-led >> @@ -61,3 +61,19 @@ Description: >> gpio and backlight triggers. In case of the backlight trigger, >> it is useful when driving a LED which is intended to indicate >> a device in a standby like state. >> + >> +What: /sys/class/leds//pattern >> +Date: June 2018 >> +KernelVersion: 4.18 >> +Description: >> + Specify a pattern for the LED, for LED hardware that support >> + altering the brightness as a function of time. >> + >> + The pattern is given by a series of tuples, of brightness and >> + duration (ms). The LED is expected to traverse the series and >> + each brightness value for the specified duration. >> + >> + As LED hardware might have different capabilities and precision >> + the requested pattern might be slighly adjusted by the driver >> + and the resulting pattern of such operation should be returned >> + when this file is read. > > I'd add "Duration of 0 means brightness should immediately change to > new value." Sure. > >> + struct led_classdev *led_cdev = dev_get_drvdata(dev); >> + struct led_pattern *pattern = NULL; >> + unsigned long val; >> + char *sbegin; >> + char *elem; >> + char *s; >> + int ret, len = 0; >> + bool odd = true; >> + >> + s = sbegin = kstrndup(buf, size, GFP_KERNEL); >> + if (!s) >> + return -ENOMEM; >> + >> + /* Trim trailing newline */ >> + s[strcspn(s, "\n")] = '\0'; > > Is substring function best to use here? Will it do the right thing > when \n is not present? We always have a '\n' to present the end of the string passed from userspace. Or anything I missed here? > >> + /* If the remaining string is empty, clear the pattern */ >> + if (!s[0]) { >> + ret = led_cdev->pattern_clear(led_cdev); >> + goto out; >> + } >> + >> + pattern = kcalloc(size, sizeof(*pattern), GFP_KERNEL); >> + if (!pattern) { >> + ret = -ENOMEM; >> + goto out; >> + } >> + >> + /* Parse out the brightness & delta_t touples and check for repeat */ >> + while ((elem = strsep(&s, " ")) != NULL) { >> + ret = kstrtoul(elem, 10, &val); >> + if (ret) >> + goto out; >> + >> + if (odd) { >> + pattern[len].brightness = val; >> + } else { >> + /* Ensure we don't have any delta_t == 0 */ >> + if (!val) { >> + ret = -EINVAL; >> + goto out; >> + } > > I believe we should support delta_t of 0 for "change immediately". OK. Thanks for your comments. -- Baolin Wang Best Regards