Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1533484ybt; Thu, 2 Jul 2020 07:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy83rwBO6vPe3sL68bdHp0YSS7RSpcILjIiTq7qqMMTvB9CrHKTKyQbV0j6ymV5o1GKMZk4 X-Received: by 2002:aa7:d2d2:: with SMTP id k18mr34189993edr.16.1593701338649; Thu, 02 Jul 2020 07:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593701338; cv=none; d=google.com; s=arc-20160816; b=UoMm05dAmcpc0aLw13CkrxYuQlqbP4W29EqoHsFJytpPRxJoz65woNNBcafyXDZnMF betHisOvRca/nHJlCBclNsZtmCRxfiF+5JwFUYWYqlfFxzQWCmhwpBsvvB2EwZBQfKpy X6jPfW/K84ybHy8Cvt+SU+HuXbCFeiirCdfdXvdqduzD++WLF1XN0AkdBYKMHY1YaEv0 n7uSNjQcKQQ7aC6LDEmQk0sEbFYvzqfZTV0v2UPSukZY1w6O5s5sdsLLpkxa1Wh69d7x ONSAG9S+xuGfA4JdZtvcOVL6d9Q2DkFr2M5ZTTOiM7Ksd20c+NQoIP3Kk/bvAqkieNX4 SFAg== 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:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wgWtCqNRb//Ku5V7/TdC0HBSMc9Nn4cbFhGbH7pzgnk=; b=ZPXLncT+QDvD8KEBZ9GBNO8tKcOVp417foBsZTLcwnW+3tYlYD8yvxSZbsp/rKx4QI u2+bEa5dtiauTCTyALDcv6H8+EZiC9rDv+2wy+14nrmlK6YmRqWqml88W/YCPFy4/XB5 XfTZhunXr/oqaLmaqkeC05B7KVa4aQ3Hmf2gBWv3qMb0WpSS/60rQPUSPVI+9oz3ptb0 mMdtiM0EmhKva7u5XUi6iThuDa+8mFeeBQdYrBf35YXrCsWtso6ErS/36MFFZOGTRteH czfFFmLvkUK8I1FCF0menSQFLsC/e2n8uzjL/auYDULhcUAb/cUFoL44shdj06eWRxE7 7aOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@megous.com header.s=mail header.b=sBmrw1y3; 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 c25si5900419edv.335.2020.07.02.07.48.35; Thu, 02 Jul 2020 07:48:58 -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=sBmrw1y3; 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 S1730174AbgGBOrk (ORCPT + 99 others); Thu, 2 Jul 2020 10:47:40 -0400 Received: from vps.xff.cz ([195.181.215.36]:46886 "EHLO vps.xff.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730171AbgGBOri (ORCPT ); Thu, 2 Jul 2020 10:47:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megous.com; s=mail; t=1593701256; bh=uDf9d/uRJiCtCt1AKubcJLejRj1GRrlsMFGfiGhHhXQ=; h=From:To:Cc:Subject:Date:From; b=sBmrw1y3Ge453s/b6duoEIXe2POYkrOzZJaYL8FeCWY463xCsUurnLS8sONz2cBlT TSBlhuShDIyYHOYS0GSD76SQCtKKzw8SP3rbDuWRBcA2wk1tM0SLTISlAGO3FT7xHi EuL4TmVsgJGT2xKBpvFq6vxbOMZnYfHTTL8Sp7I8= From: Ondrej Jirman To: linux-kernel@vger.kernel.org Cc: Ondrej Jirman , Jacek Anaszewski , Pavel Machek , Dan Murphy , linux-leds@vger.kernel.org (open list:LED SUBSYSTEM) Subject: [PATCH RFC] leds: Add support for per-LED device triggers Date: Thu, 2 Jul 2020 16:47:11 +0200 Message-Id: <20200702144712.1994685-1-megous@megous.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Ondrej Jirman --- drivers/leds/led-triggers.c | 12 +++++++++--- include/linux/leds.h | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 79e30d2cb7a5..3011e2658404 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c @@ -50,7 +50,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) && + (!trig->private_led || trig->private_led == led_cdev)) { down_write(&led_cdev->trigger_lock); led_trigger_set(led_cdev, trig); up_write(&led_cdev->trigger_lock); @@ -96,6 +97,9 @@ static int led_trigger_format(char *buf, size_t size, bool hit = led_cdev->trigger && !strcmp(led_cdev->trigger->name, trig->name); + if (trig->private_led && trig->private_led != led_cdev) + continue; + len += led_trigger_snprintf(buf + len, size - len, " %s%s%s", hit ? "[" : "", trig->name, hit ? "]" : ""); @@ -243,7 +247,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) && + (!trig->private_led || trig->private_led == led_cdev)) { led_cdev->flags |= LED_INIT_DEFAULT_TRIGGER; led_trigger_set(led_cdev, trig); break; @@ -280,7 +285,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; } diff --git a/include/linux/leds.h b/include/linux/leds.h index 2451962d1ec5..0d7577c752ad 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -345,6 +345,9 @@ struct led_trigger { int (*activate)(struct led_classdev *led_cdev); void (*deactivate)(struct led_classdev *led_cdev); + /* LED-private triggers have the LED device set here. */ + struct led_classdev *private_led; + /* LEDs under control by this trigger (for simple triggers) */ rwlock_t leddev_list_lock; struct list_head led_cdevs; -- 2.27.0