Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1204940ybt; Sat, 11 Jul 2020 03:05:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKEKMQH1/IWlpETuvNJEoRFnu+6bhW41JqYQHRKbN2vsKoyy+HtndDfCkXAVI2nUpRkpyi X-Received: by 2002:a17:906:e25a:: with SMTP id gq26mr63490607ejb.152.1594461911388; Sat, 11 Jul 2020 03:05:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594461911; cv=none; d=google.com; s=arc-20160816; b=wkhGa96tsBLnHEzQpWaHyDC0FRBGttydQcUPVk+N8iK4prodwqfGXULgWMbUpeGxEJ 5ZKd1qtEBrNYZDfyD6hnBCSzpJXi4gwFJLQYPKJtu9V5dVUkYiGzXyUvb4ui/9iuKTl4 zZlZ9LOYvQ8XeODiOrOvOSFhqiDrxRT1p2gcf93Vz2TAV+k0Fcw6NeFZLTgIf6opi/Ij y71qYTLkHcvoFSFvoLfX0/d6nBnkPXLLxYwjCFPw+u2DLJ/B4ODp0xOSrboZnh/pcDp9 7nXdKn5XYa19ldXnpPFX/pgqcIFUJvM2bfoVleZZLq8uiabOuPBjYCpyhwYu1Jwklaqe 1TUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=exlvr55dkYlNwuGRtoKHnx5tGmgC3WMT6De97FVwdpo=; b=hK/KoLuVUU7sAw3cC7Kl/G7iqvD+gQl0SHH4BN3PTmvRQlDqHYgpEpiDF6KiCmOAHm ErjfyJeOjanv9Rckrp18xNqz1Eo1o2G/Blny6P8Cws0Asy5ckjWrBAp+DpWFm90Tt6zP oWQ/nSrbzrF+Hx4XEvFu1ifnIeozdz2GKcEFwjJSJXlgGR8QZQARDpFdnRTxxkjwTu3k 5jEFqvsrIlnnZjcemGaEHJOAKDiXn2xRw4hXPSZaf1PptbOEhm7LfBfFa2rjAS+m8pEx Ow2U4QU0mZuHwsbN5MFEkvdTYW5USpoNUVrDPNXwe41c8ICTRoyg6q719M43rykouaos vU1A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bj4si5507693ejb.540.2020.07.11.03.04.48; Sat, 11 Jul 2020 03:05: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbgGKKEN (ORCPT + 99 others); Sat, 11 Jul 2020 06:04:13 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:41318 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726208AbgGKKEM (ORCPT ); Sat, 11 Jul 2020 06:04:12 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 268B91C0BD4; Sat, 11 Jul 2020 12:04:10 +0200 (CEST) Date: Sat, 11 Jul 2020 12:04:09 +0200 From: Pavel Machek To: Ondrej Jirman Cc: linux-kernel@vger.kernel.org, Jacek Anaszewski , Dan Murphy , "open list:LED SUBSYSTEM" Subject: Re: [PATCH RFC] leds: Add support for per-LED device triggers Message-ID: <20200711100409.GA18901@amd> References: <20200702144712.1994685-1-megous@megous.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AqsLC8rIMeq19msA" Content-Disposition: inline In-Reply-To: <20200702144712.1994685-1-megous@megous.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --AqsLC8rIMeq19msA Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > Add support for registering per-LED device trigger. >=20 > 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... 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); =20 /* Used by LED Class */ =20 +static inline bool +trigger_relevant(struct led_classdev *led_cdev, struct led_trigger *trig) +{ + return !trig->trigger_type || trig->trigger_type =3D=3D 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 kobje= ct *kobj, =20 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 =3D led_cdev->trigger && !strcmp(led_cdev->trigger->name, trig->name); =20 + if (!trigger_relevant(led_cdev, trig)) + continue; + len +=3D 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_c= dev) 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 |=3D 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 =3D=3D trig->private_led)= ) { up_write(&triggers_list_lock); return -EEXIST; } 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; }; =20 +struct led_hw_trigger_type { + int dummy; +} + struct led_classdev { const char *name; enum led_brightness brightness; @@ -150,6 +154,8 @@ struct led_classdev { =20 /* Ensures consistent access to the LED Flash Class device */ struct mutex led_access; + + struct led_hw_trigger_type *trigger_type; }; =20 /** @@ -345,6 +351,9 @@ struct led_trigger { int (*activate)(struct led_classdev *led_cdev); void (*deactivate)(struct led_classdev *led_cdev); =20 + /* 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; --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --AqsLC8rIMeq19msA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl8JjpkACgkQMOfwapXb+vI52ACeLHJpdGMej5WODWgmjQ7mQlUZ 6IsAn35tSb81OiY7moAPB/0LzvoXEMb1 =vVwO -----END PGP SIGNATURE----- --AqsLC8rIMeq19msA--