Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp548022ybh; Sun, 12 Jul 2020 15:14:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnc82ZInWwNdJmN5NSimTwMC+It2x73po+iraieDWfmN5irC5u3T2a1HaxVn55Y40DDvsa X-Received: by 2002:a50:cbcd:: with SMTP id l13mr70564716edi.384.1594592051566; Sun, 12 Jul 2020 15:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594592051; cv=none; d=google.com; s=arc-20160816; b=MwjVadih8aYr8G2rs2uE2aBvYEqyfB52+hfgxlQV/rmbpu43O7p7m60rzoRBtJiV9a Hg6LArnYHCw4DgNRROVjzaS5PKYJW/+T8vodCMDyyXfd2G9esTXIt9gjA971727SAdgJ nBGD2f25aKC1KmaQzyOswkDkhvEEICVTDWPUegRGIiDTS7h0oBNWXCmRcQsMfy19XMP/ O95Xo3b2FwqkL2CVQdioSs4fZMEIhOQ68bDGIKSEtCoEbW7bLfpWctSCHVs6wPsuA0ox eM8o1PVKfn+tZByuZZC3k2yo0U/zPGAiv+KjSyh+/8HGFJyL8FgVeerAIJ/DGOODszdJ v2xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:mail-followup-to:message-id:subject:cc:to :from:date:dkim-signature; bh=FjzpdDQ+sA+h9ptoirGWiFEDGmy87ldB/4si4QGUvIY=; b=MAkI7EA2gL9OI/ljZ93CT92VjKTRHg8XaWv8CTSr2zCVDj13tjJ1oIbd0Y0GHbCq1e MDbKpfC0lFmVwtvIshHvSChGSgsNAlqcLm4mRJGhFaxIvoHfsyqR7P83euC25qidQ04r B+Z4gwh8JP9qVnwYA+5SOK/hl0weZIxvWeAkt+ln0VPC3RlKRYPfUBqZioWxOHrK5s8C dsMpmp67pDdnXxTXYTiscspNupHkeXX+RE7cHg6mgV3s2OmQ8i7BqMPIalNwBS5uBSk9 9zi6p3UICPRZPDG++sCZ0hUgSUNTEtiMQ25eWAk7LGoSjdafYPpZAvP+MGDqPKFdctOb z/CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@megous.com header.s=mail header.b=kheohcW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=megous.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b23si8221845ejb.465.2020.07.12.15.13.48; Sun, 12 Jul 2020 15:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@megous.com header.s=mail header.b=kheohcW0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=megous.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727868AbgGLWM2 (ORCPT + 99 others); Sun, 12 Jul 2020 18:12:28 -0400 Received: from vps.xff.cz ([195.181.215.36]:59712 "EHLO vps.xff.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727099AbgGLWM1 (ORCPT ); Sun, 12 Jul 2020 18:12:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megous.com; s=mail; t=1594591945; bh=p8Ou+/ReAlGiGL/G8va0szvgGl7G4nS7JBPLpKZvUPE=; h=Date:From:To:Cc:Subject:References:X-My-GPG-KeyId:From; b=kheohcW0vIIzh6Sckg9Z6N+Japwgb2QBS7EhuClXZKloJZpCXBdK41vEJrMETogfY K0KTjFC0xGon0vHFbjfCQYg5nX6/jmEj/41ZoIzSyyPB7LqOxDnq9CBrUdeYz4Mp6/ WybyvZDnqQAn4eGJQfSodbe/BO8lblAsK6griekU= Date: Mon, 13 Jul 2020 00:12:25 +0200 From: =?utf-8?Q?Ond=C5=99ej?= Jirman To: Pavel Machek Cc: linux-kernel@vger.kernel.org, Jacek Anaszewski , Dan Murphy , "open list:LED SUBSYSTEM" , marek.behun@nic.cz Subject: Re: [PATCH RFC] leds: Add support for per-LED device triggers Message-ID: <20200712221225.jkfof4edsveoidhm@core.my.home> Mail-Followup-To: =?utf-8?Q?Ond=C5=99ej?= Jirman , Pavel Machek , linux-kernel@vger.kernel.org, Jacek Anaszewski , Dan Murphy , "open list:LED SUBSYSTEM" , marek.behun@nic.cz References: <20200702144712.1994685-1-megous@megous.com> <20200711100409.GA18901@amd> <20200711210111.5ysijhexgyzyr7u7@core.my.home> <20200712072554.GC4721@duo.ucw.cz> <20200712134911.r3lig4hgyqhmslth@core.my.home> <20200712191111.GA20592@amd> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200712191111.GA20592@amd> X-My-GPG-KeyId: EBFBDDE11FB918D44D1F56C1F9F0A873BE9777ED Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Pavel, On Sun, Jul 12, 2020 at 09:11:11PM +0200, Pavel Machek wrote: > Hi! > > > > > > > Some LED controllers may come with an internal HW triggering mechanism > > > > > > for the LED and an ability to switch between user control of the LED, > > > > > > or the internal control. One such example is AXP20X PMIC, that allows > > > > > > wither for user control of the LED, or for internal control based on > > > > > > the state of the battery charger. > > > > > > > > > > > > Add support for registering per-LED device trigger. > > > > > > > > > > > > Names of private triggers need to be globally unique, but may clash > > > > > > with other private triggers. This is enforced during trigger > > > > > > registration. Developers can register private triggers just like > > > > > > the normal triggers, by setting private_led to a classdev > > > > > > of the LED the trigger is associated with. > > > > > > > > > > What about this? Should address Marek's concerns about resource use... > > > > > > > > What concerns? Marek's concerns seem to be about case where we register > > > > a trigger for (each led * self-working configuration) which I admit > > > > can be quite a lot of triggers if there are many functions. But that's > > > > not my proposal. > > > > > > > > My proposal is to only register on trigger per LED at most. So on my > > > > system that's 1 extra trigger and on Marek's system that'd be 48 new > > > > triggers. Neither seems like a meaningful problem from resource > > > > use perspective. > > > > > > So.. 48 triggers on Marek's systems means I'll not apply your patch. > > > > > > Please take a look at my version, it is as simple and avoids that > > > problem. > > > > I would, but I don't see your version linked or mentioned in this > > thread. > > Ah! Sorry about that. Here it is. (I verified it compiles in the > meantime). > > Best regards, > Pavel > > diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c > index 79e30d2cb7a5..e8333675959c 100644 > --- a/drivers/leds/led-triggers.c > +++ b/drivers/leds/led-triggers.c > @@ -27,6 +27,12 @@ LIST_HEAD(trigger_list); > > /* Used by LED Class */ > > +static inline bool > +trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig) > +{ > + return !trig->trigger_type || trig->trigger_type == led_cdev->trigger_type; > +} > + > ssize_t led_trigger_write(struct file *filp, struct kobject *kobj, > struct bin_attribute *bin_attr, char *buf, > loff_t pos, size_t count) > @@ -50,7 +56,8 @@ ssize_t led_trigger_write(struct file *filp, struct kobject *kobj, > > down_read(&triggers_list_lock); > list_for_each_entry(trig, &trigger_list, next_trig) { > - if (sysfs_streq(buf, trig->name)) { > + if (sysfs_streq(buf, trig->name) && > + trigger_relevant(led_cdev, trig)) { > down_write(&led_cdev->trigger_lock); > led_trigger_set(led_cdev, trig); > up_write(&led_cdev->trigger_lock); > @@ -96,6 +103,9 @@ static int led_trigger_format(char *buf, size_t size, > bool hit = led_cdev->trigger && > !strcmp(led_cdev->trigger->name, trig->name); > > + if (!trigger_relevant(led_cdev, trig)) > + continue; > + > len += led_trigger_snprintf(buf + len, size - len, > " %s%s%s", hit ? "[" : "", > trig->name, hit ? "]" : ""); > @@ -243,7 +253,8 @@ void led_trigger_set_default(struct led_classdev *led_cdev) > down_read(&triggers_list_lock); > down_write(&led_cdev->trigger_lock); > list_for_each_entry(trig, &trigger_list, next_trig) { > - if (!strcmp(led_cdev->default_trigger, trig->name)) { > + if (!strcmp(led_cdev->default_trigger, trig->name) && > + trigger_relevant(led_cdev, trig)) { > led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER; > led_trigger_set(led_cdev, trig); > break; > @@ -280,7 +291,8 @@ int led_trigger_register(struct led_trigger *trig) > down_write(&triggers_list_lock); > /* Make sure the trigger's name isn't already in use */ > list_for_each_entry(_trig, &trigger_list, next_trig) { > - if (!strcmp(_trig->name, trig->name)) { > + if (!strcmp(_trig->name, trig->name) && > + (!_trig->private_led || _trig->private_led == trig->private_led)) { > up_write(&triggers_list_lock); > return -EEXIST; > } This would not compile, probably some stale code. > diff --git a/include/linux/leds.h b/include/linux/leds.h > index 2451962d1ec5..cba52714558f 100644 > --- a/include/linux/leds.h > +++ b/include/linux/leds.h > @@ -57,6 +57,10 @@ struct led_init_data { > bool devname_mandatory; > }; > > +struct led_hw_trigger_type { > + int dummy; > +} > + > struct led_classdev { > const char *name; > enum led_brightness brightness; > @@ -150,6 +154,8 @@ struct led_classdev { > > /* Ensures consistent access to the LED Flash Class device */ > struct mutex led_access; > + > + struct led_hw_trigger_type *trigger_type; > }; > > /** > @@ -345,6 +351,9 @@ struct led_trigger { > int (*activate)(struct led_classdev *led_cdev); > void (*deactivate)(struct led_classdev *led_cdev); > > + /* LED-private triggers have this set. */ > + struct led_hw_trigger_type *trigger_type; > + > /* LEDs under control by this trigger (for simple triggers) */ > rwlock_t leddev_list_lock; > struct list_head led_cdevs; I like this proposal. I'll try to use it in my code. Thank you! regards, o. > -- > (english) http://www.livejournal.com/~pavelmachek > (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html