Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp315087imj; Sat, 16 Feb 2019 00:45:13 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib/x773SAYt3icVPVm51IhVUNv1b/tn4FSh5uqYSENMw3pJsLSFvuJI8aTb06cZIjc75fFK X-Received: by 2002:a62:6204:: with SMTP id w4mr14049706pfb.5.1550306713761; Sat, 16 Feb 2019 00:45:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550306713; cv=none; d=google.com; s=arc-20160816; b=nVsk3D9idBGvWSabcLvk8kDo63aGjwMJOdybgxu87jpaFV6Sv+1mRUwiCFj/+mYIMr aesMyBSVVpQuQcZ8NJoXfjNnZydtvowwqhERG2FDhI0+g7io7zuuPkjiRWVmCihNc8gr DmS9Zw1dk4p6An5buUfS+3f4y5Pp51KS5QQ+F2zyRqhlPd/RdoSMqNr96xm37DvG9bIY MWqblRY6d3z7ZbX4VLkPta9jmLU8u5aDNQj/S+GEX95fiY/4hcIc86beJL2UcrPFMexR Fp8lIOOoEjjLZRrIo2I5toLuJ/gzTpu4k0GwtH5Cbcms+67e9LH+Kq+GqT92xtKHMXPl qx0A== 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; bh=lTOqihQXBEziRBp8qsuh70LNMirjYV0K2k2qJv8vPgE=; b=LOFfRZhalZZZGVW9CmhCezCLaYPmq5rp6BtYBXGc5rKPIg7hH+tv7YwopWBTAGuMvX vS0KsvJclLNVPRrUYIQuXqdAhb3ne8BUJ/oLw9hR7rvGVTlbmONeRviCp6eTyrITH4BW bx2l1YzZt53KdoS8o0jnfLzJMnIhbL6iKzQjr+tdyiEq6BiMw37Qu7f3K+QXAQL5UpSZ JZ/wuVZeDUIfsUxaf0pxtjplPpChE/RdLIvO8vc7GLv07uknwX8OtxQHdKwrKdSKTH+a Evfe8BNxXBEb6BA74NzTVbvy8jNaYoE6AdLmLN2F4LTVJR1EDOavrfwwrv6WAvbuxcNQ DIKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jIyDakSk; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 91si3402828plb.265.2019.02.16.00.44.57; Sat, 16 Feb 2019 00:45:13 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=jIyDakSk; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391105AbfBOWbc (ORCPT + 99 others); Fri, 15 Feb 2019 17:31:32 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45974 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390603AbfBOWbb (ORCPT ); Fri, 15 Feb 2019 17:31:31 -0500 Received: by mail-lj1-f193.google.com with SMTP id s5-v6so9630642ljd.12; Fri, 15 Feb 2019 14:31:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=lTOqihQXBEziRBp8qsuh70LNMirjYV0K2k2qJv8vPgE=; b=jIyDakSkd/qXiz/CbUj7bXzIc8+gQ2d+pM0vzHNXnlhMMLtI+rsFL/OQGeRRoPTsEi AYikHr7243ocp4sZxfbgZe9Ro/dNU/B0Or5XJGg8bLe13L7B9Mkv6tEQRCa8ddFlyFkB pyREJZReXUqZ20ONk+nqrD5VaNyMHAfa/cLemeCnDhM3oGxfxzwdv67GIRNP+Jvh8TO0 nrKlgNYA2TDzMnp1xxg2fqbz/MizifzIj33PY7YZDuqYLFwHgNPYPUdmn0Vq6rC0Vl+C 4DbSI5c+tOnpNdNGvTewdu1WrugDqD5EdMb0depqZSRq5qz2AoFSV06idx2/em0Ktx7Y +pGw== 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=lTOqihQXBEziRBp8qsuh70LNMirjYV0K2k2qJv8vPgE=; b=jr471AENKztyw14CVzE+Q7k6ofCRuG2lQ3jTEkYaI3/bgzyh+4miIyZ19bSPIXx9ge X8DRVdEcdvTIeqTdyqC72eRzosNIQr5B+cOTWLiBVZzYdGl1rCiUVycwwfHVI6d6SF0u omDf5fBZJ6/e1o09POcpfKJbAeCfceIC7vnVnisA0DSswmANfFgwiLlDudzF2l0wmS7X kJAg6i7ZeWI1FYOltwqslYG9BqBRkqnW0y1eBEkn8Pyk4lNOpKetosfLFz3nZ/KXAwSQ X+tK3HYnEFT3PWwYHATFYgwQSPeFcvhOOObgZyUhJInmq/VpNVWbRwtJgAGHLo3MCI36 fGMA== X-Gm-Message-State: AHQUAuaWXk1rcmFuxls53BzvH/vTmsWrAxxwTjj7GHDdr1NAvUXMkmmo D5kaeL3NQoR9jWJNtGThCGjWRwgf X-Received: by 2002:a2e:5854:: with SMTP id x20-v6mr6936887ljd.31.1550269888327; Fri, 15 Feb 2019 14:31:28 -0800 (PST) Received: from [192.168.1.18] (bkp179.neoplus.adsl.tpnet.pl. [83.28.183.179]) by smtp.gmail.com with ESMTPSA id l72sm1681532lfg.75.2019.02.15.14.31.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Feb 2019 14:31:27 -0800 (PST) Subject: Re: [PATCH v2 1/2] leds: Add Intel Cherry Trail Whiskey Cove PMIC LEDs To: Hans de Goede , Pavel Machek Cc: Yauhen Kharuzhy , linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org References: <20190212205901.13037-1-jekhor@gmail.com> <20190212205901.13037-2-jekhor@gmail.com> <1df39a63-533f-bb68-a056-a0241f148be9@redhat.com> <20190213230731.GA8557@amd> <42078a81-e32e-81b7-528f-d1adb60d31c3@redhat.com> <20190213233806.GA11867@amd> <562e2acd-a60a-2aea-4050-6d9414d23a4e@redhat.com> <20190214111423.GE6132@amd> <92cf09b8-726d-4f1b-94ba-368a66af2246@redhat.com> <2b6faaa5-b21e-a512-de7d-ca21be5045fc@gmail.com> <20190214230307.GA17358@amd> <2a5e2002-e5f1-6da3-8a43-317801b69657@redhat.com> <3d5407a7-9458-f071-a1d5-511b09678e20@gmail.com> <87a21c4e-8e5e-c180-2ff3-eb8170746e71@redhat.com> From: Jacek Anaszewski Message-ID: <80971bc3-1193-83ed-913a-12f6217016c8@gmail.com> Date: Fri, 15 Feb 2019 23:31:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <87a21c4e-8e5e-c180-2ff3-eb8170746e71@redhat.com> Content-Type: text/plain; charset=windows-1252; 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 2/15/19 11:26 PM, Hans de Goede wrote: > Hi, > > On 2/15/19 10:42 PM, Jacek Anaszewski wrote: >> Hi all, >> >> On 2/15/19 12:27 PM, Hans de Goede wrote: >>> Hi, >>> >>> On 15-02-19 00:03, Pavel Machek wrote: >>>> Hi! >>>> >>>>>>>> I suggest that we deal with this special case by adding 3 custom >>>>>>>> sysfs attributes: >>>>>>>> >>>>>>>> 1) "mode" which when read, prints, e.g. : >>>>>>>> manual [on-when-charging] >>>>>>> >>>>>>> While this allows _user on console_ to control everything using >>>>>>> echo, >>>>>>> it is not suitable for applications trying to control LEDs. >>>>>>> >>>>>>> As there's nothing special about the case here, I believe we should >>>>>>> have generic solution here. >>>>>>> >>>>>>> My preffered solution would be "hardware" trigger that leaves the >>>>>>> LED >>>>>>> in hardware control. >>>>>> >>>>>> As you explained in the parts which I snipped, there are many >>>>>> devices which have a similar choice for a LED being under hw or >>>>>> user control. I can see how this looks like a trigger and how we >>>>>> could use the trigger API for this. >>>>>> >>>>>> I believe though, that if we implement a "virtual" (for lack of >>>>>> a better word) trigger for this, that this should be done in the >>>>>> LED core. I can envision this working like this: >>>>>> >>>>>> 1) Add a: >>>>>> >>>>>> hw_control_set(struct led_classdev *led_cdev, bool >>>>>> enable_hw_control); >>>>> >>>>> Please note that we have support for hw patterns in the pattern >>>>> trigger. >>>>> (see how drivers/leds/leds-sc27xx-bltc.c makes use of it for its >>>>> breathing pattern). >>>>> We have also support for hw blinking in timer trigger via blink_set >>>>> op. >>>>> >>>>> In addition to that there is brightness_hw_changed sysfs attribute >>>>> with led_classdev_notify_brightness_hw_changed() LED API. >>>>> >>>>> Couldn't they be used in concert to support the specific features >>>>> of the device in question? >>>> >>>> I believe main issue here is this: >>>> >>>> Hardware can automatically control the LED according to the charging >>>> status, or it can be used as normal software-controlled LED. >>>> >>>> I believe we should use trigger to select if hardware controls it or >>>> not (and then add driver-specific files to describe the >>>> details). Other proposal is in the mail thread, too. >>> >>> Right, so there are really 2 orthogonal issues here: >>> >>> 1) With this hardware the LED is either turned on/off automatically >>> by the PMIC based on charging state; or it is under user control. >>> >>> This is different from the led_classdev_notify_brightness_hw_changed >>> case, where the hardware may update the state underneath the driver, >>> but the driver can still always update the state itself. In this case >>> if the LED is in hw-control mode then the driver cannot turn it on/off. >>> >>> Pavel suggested modeling this with a new "hardware' trigger, where >>> setting the trigger to this trigger will enable the hw-controlled >>> mode and setting any other trigger will switch thing to the >>> user-controlled >>> mode. >> >> We already do have hw_pattern file exposed by pattern trigger. >> It can be used to set hw breathing mode using some device specific >> syntax semantics, documented in dedicated ABI documentation. >> It was introduced for similar case, see >> Documentation/ABI/testing/sysfs-class-led-driver-sc27xx. > > Ah I see, yes that could be used, the pattern would just be a single > integer specifying the cycle time in milliseconds, as nothing > else is configurable. I depends on how the pattern looks like. If it is breathing then we'd need more than one value. > I think that should work fine, which means that we can use the timer and > pattern trigger support for the blinking and breathing modes. > > That still leaves the switching between user and hw-control modes, > as discussed the hw-controlled mode could be modelled as a new "hardware" > trigger, but then we cannot choose between on/blink/breathing when > in hw-controlled mode. As Pavel mentioned, that would require some > sort of composed trigger, where we have both the hardware and > timer triggers active for example. > > I think it might be easier to just allow turning on/off the hardware > control mode through a special "hardware_control" sysfs attribute and > then use the existing timer and pattern triggers for blinking / breathing. Pattern trigger exposes pattern file by default and hw_pattern if pattern_set/get ops are provided. Writing them enables software and hardware pattern respectively. -- Best regards, Jacek Anaszewski