2019-06-04 08:11:33 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2006-03-31 10:31:04 +00:00
|
|
|
/*
|
|
|
|
* Driver model for leds and led triggers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
|
|
|
|
* Copyright (C) 2005 Richard Purdie <rpurdie@openedhand.com>
|
|
|
|
*/
|
|
|
|
#ifndef __LINUX_LEDS_H_INCLUDED
|
|
|
|
#define __LINUX_LEDS_H_INCLUDED
|
|
|
|
|
2019-06-09 18:19:04 +00:00
|
|
|
#include <dt-bindings/leds/common.h>
|
2015-04-28 07:18:41 +00:00
|
|
|
#include <linux/device.h>
|
2014-09-22 15:21:04 +00:00
|
|
|
#include <linux/mutex.h>
|
2007-11-10 13:29:04 +00:00
|
|
|
#include <linux/rwsem.h>
|
2014-08-07 12:10:22 +00:00
|
|
|
#include <linux/spinlock.h>
|
Revert "leds: convert blink timer to workqueue"
This reverts commit 8b37e1bef5a6b60e949e28a4db3006e4b00bd758.
It's broken as it changes led_blink_set() in a way that it can now sleep
(while synchronously waiting for workqueue to be cancelled). That's a
problem, because it's possible that this function gets called from atomic
context (tpt_trig_timer() takes a readlock and thus disables preemption).
This has been brought up 3 weeks ago already [1] but no proper fix has
materialized, and I keep seeing the problem since 3.17-rc1.
[1] https://lkml.org/lkml/2014/8/16/128
BUG: sleeping function called from invalid context at kernel/workqueue.c:2650
in_atomic(): 1, irqs_disabled(): 0, pid: 2335, name: wpa_supplicant
5 locks held by wpa_supplicant/2335:
#0: (rtnl_mutex){+.+.+.}, at: [<ffffffff814c7c92>] rtnl_lock+0x12/0x20
#1: (&wdev->mtx){+.+.+.}, at: [<ffffffffc06e649c>] cfg80211_mgd_wext_siwessid+0x5c/0x180 [cfg80211]
#2: (&local->mtx){+.+.+.}, at: [<ffffffffc0817dea>] ieee80211_prep_connection+0x17a/0x9a0 [mac80211]
#3: (&local->chanctx_mtx){+.+.+.}, at: [<ffffffffc08081ed>] ieee80211_vif_use_channel+0x5d/0x2a0 [mac80211]
#4: (&trig->leddev_list_lock){.+.+..}, at: [<ffffffffc081e68c>] tpt_trig_timer+0xec/0x170 [mac80211]
CPU: 0 PID: 2335 Comm: wpa_supplicant Not tainted 3.17.0-rc3 #1
Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
ffff8800360b5a50 ffff8800751f76d8 ffffffff8159e97f ffff8800360b5a30
ffff8800751f76e8 ffffffff810739a5 ffff8800751f77b0 ffffffff8106862f
ffffffff810685d0 0aa2209200000000 ffff880000000004 ffff8800361c59d0
Call Trace:
[<ffffffff8159e97f>] dump_stack+0x4d/0x66
[<ffffffff810739a5>] __might_sleep+0xe5/0x120
[<ffffffff8106862f>] flush_work+0x5f/0x270
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffff810945ca>] ? mark_held_locks+0x6a/0x90
[<ffffffff81068a5f>] ? __cancel_work_timer+0x6f/0x100
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffffc081ecdd>] ieee80211_mod_tpt_led_trig+0x9d/0x160 [mac80211]
[<ffffffffc07e4278>] __ieee80211_recalc_idle+0x98/0x140 [mac80211]
[<ffffffffc07e59ce>] ieee80211_idle_off+0xe/0x10 [mac80211]
[<ffffffffc0804e5b>] ieee80211_add_chanctx+0x3b/0x220 [mac80211]
[<ffffffffc08062e4>] ieee80211_new_chanctx+0x44/0xf0 [mac80211]
[<ffffffffc080838a>] ieee80211_vif_use_channel+0x1fa/0x2a0 [mac80211]
[<ffffffffc0817df8>] ieee80211_prep_connection+0x188/0x9a0 [mac80211]
[<ffffffffc081c246>] ieee80211_mgd_auth+0x256/0x2e0 [mac80211]
[<ffffffffc07eab33>] ieee80211_auth+0x13/0x20 [mac80211]
[<ffffffffc06cb006>] cfg80211_mlme_auth+0x106/0x270 [cfg80211]
[<ffffffffc06ce085>] cfg80211_conn_do_work+0x155/0x3b0 [cfg80211]
[<ffffffffc06cf670>] cfg80211_connect+0x3f0/0x540 [cfg80211]
[<ffffffffc06e6148>] cfg80211_mgd_wext_connect+0x158/0x1f0 [cfg80211]
[<ffffffffc06e651e>] cfg80211_mgd_wext_siwessid+0xde/0x180 [cfg80211]
[<ffffffffc06e36c0>] ? cfg80211_wext_giwessid+0x50/0x50 [cfg80211]
[<ffffffffc06e36dd>] cfg80211_wext_siwessid+0x1d/0x40 [cfg80211]
[<ffffffff81584d0c>] ioctl_standard_iw_point+0x14c/0x3e0
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff8158502a>] ioctl_standard_call+0x8a/0xd0
[<ffffffff81584fa0>] ? ioctl_standard_iw_point+0x3e0/0x3e0
[<ffffffff81584b76>] wireless_process_ioctl.constprop.10+0xb6/0x100
[<ffffffff8158521d>] wext_handle_ioctl+0x5d/0xb0
[<ffffffff814cfb29>] dev_ioctl+0x329/0x620
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff8149c7f2>] sock_ioctl+0x142/0x2e0
[<ffffffff811b0140>] do_vfs_ioctl+0x300/0x520
[<ffffffff815a67fb>] ? sysret_check+0x1b/0x56
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff811b03e1>] SyS_ioctl+0x81/0xa0
[<ffffffff815a67d6>] system_call_fastpath+0x1a/0x1f
wlan0: send auth to 00:0b:6b:3c:8c:e4 (try 1/3)
wlan0: authenticated
wlan0: associate with 00:0b:6b:3c:8c:e4 (try 1/3)
wlan0: RX AssocResp from 00:0b:6b:3c:8c:e4 (capab=0x431 status=0 aid=2)
wlan0: associated
IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
cfg80211: Calling CRDA for country: NA
wlan0: Limiting TX power to 27 (27 - 0) dBm as advertised by 00:0b:6b:3c:8c:e4
=================================
[ INFO: inconsistent lock state ]
3.17.0-rc3 #1 Not tainted
---------------------------------
inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
swapper/0/0 [HC0[0]:SC1[1]:HE1:SE0] takes:
((&(&led_cdev->blink_work)->work)){+.?...}, at: [<ffffffff810685d0>] flush_work+0x0/0x270
{SOFTIRQ-ON-W} state was registered at:
[<ffffffff81094dbe>] __lock_acquire+0x30e/0x1a30
[<ffffffff81096c81>] lock_acquire+0x91/0x110
[<ffffffff81068608>] flush_work+0x38/0x270
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffffc081ecdd>] ieee80211_mod_tpt_led_trig+0x9d/0x160 [mac80211]
[<ffffffffc07e4278>] __ieee80211_recalc_idle+0x98/0x140 [mac80211]
[<ffffffffc07e59ce>] ieee80211_idle_off+0xe/0x10 [mac80211]
[<ffffffffc0804e5b>] ieee80211_add_chanctx+0x3b/0x220 [mac80211]
[<ffffffffc08062e4>] ieee80211_new_chanctx+0x44/0xf0 [mac80211]
[<ffffffffc080838a>] ieee80211_vif_use_channel+0x1fa/0x2a0 [mac80211]
[<ffffffffc0817df8>] ieee80211_prep_connection+0x188/0x9a0 [mac80211]
[<ffffffffc081c246>] ieee80211_mgd_auth+0x256/0x2e0 [mac80211]
[<ffffffffc07eab33>] ieee80211_auth+0x13/0x20 [mac80211]
[<ffffffffc06cb006>] cfg80211_mlme_auth+0x106/0x270 [cfg80211]
[<ffffffffc06ce085>] cfg80211_conn_do_work+0x155/0x3b0 [cfg80211]
[<ffffffffc06cf670>] cfg80211_connect+0x3f0/0x540 [cfg80211]
[<ffffffffc06e6148>] cfg80211_mgd_wext_connect+0x158/0x1f0 [cfg80211]
[<ffffffffc06e651e>] cfg80211_mgd_wext_siwessid+0xde/0x180 [cfg80211]
[<ffffffffc06e36dd>] cfg80211_wext_siwessid+0x1d/0x40 [cfg80211]
[<ffffffff81584d0c>] ioctl_standard_iw_point+0x14c/0x3e0
[<ffffffff8158502a>] ioctl_standard_call+0x8a/0xd0
[<ffffffff81584b76>] wireless_process_ioctl.constprop.10+0xb6/0x100
[<ffffffff8158521d>] wext_handle_ioctl+0x5d/0xb0
[<ffffffff814cfb29>] dev_ioctl+0x329/0x620
[<ffffffff8149c7f2>] sock_ioctl+0x142/0x2e0
[<ffffffff811b0140>] do_vfs_ioctl+0x300/0x520
[<ffffffff811b03e1>] SyS_ioctl+0x81/0xa0
[<ffffffff815a67d6>] system_call_fastpath+0x1a/0x1f
irq event stamp: 493416
hardirqs last enabled at (493416): [<ffffffff81068a5f>] __cancel_work_timer+0x6f/0x100
hardirqs last disabled at (493415): [<ffffffff81067e9f>] try_to_grab_pending+0x1f/0x160
softirqs last enabled at (493408): [<ffffffff81053ced>] _local_bh_enable+0x1d/0x50
softirqs last disabled at (493409): [<ffffffff81054c75>] irq_exit+0xa5/0xb0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock((&(&led_cdev->blink_work)->work));
<Interrupt>
lock((&(&led_cdev->blink_work)->work));
*** DEADLOCK ***
2 locks held by swapper/0/0:
#0: (((&tpt_trig->timer))){+.-...}, at: [<ffffffff810b4c50>] call_timer_fn+0x0/0x180
#1: (&trig->leddev_list_lock){.+.?..}, at: [<ffffffffc081e68c>] tpt_trig_timer+0xec/0x170 [mac80211]
stack backtrace:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.17.0-rc3 #1
Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
ffffffff8246eb30 ffff88007c203b00 ffffffff8159e97f ffffffff81a194c0
ffff88007c203b50 ffffffff81599c29 0000000000000001 ffffffff00000001
ffff880000000000 0000000000000006 ffffffff81a194c0 ffffffff81093ad0
Call Trace:
<IRQ> [<ffffffff8159e97f>] dump_stack+0x4d/0x66
[<ffffffff81599c29>] print_usage_bug+0x1f4/0x205
[<ffffffff81093ad0>] ? check_usage_backwards+0x140/0x140
[<ffffffff810944d3>] mark_lock+0x223/0x2b0
[<ffffffff81094d60>] __lock_acquire+0x2b0/0x1a30
[<ffffffff81096c81>] lock_acquire+0x91/0x110
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff81068608>] flush_work+0x38/0x270
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffff810945ca>] ? mark_held_locks+0x6a/0x90
[<ffffffff81068a5f>] ? __cancel_work_timer+0x6f/0x100
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff8109469d>] ? trace_hardirqs_on_caller+0xad/0x1c0
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffff810b4cc5>] call_timer_fn+0x75/0x180
[<ffffffff810b4c50>] ? process_timeout+0x10/0x10
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff810b50ac>] run_timer_softirq+0x1fc/0x2f0
[<ffffffff81054805>] __do_softirq+0x115/0x2e0
[<ffffffff81054c75>] irq_exit+0xa5/0xb0
[<ffffffff810049b3>] do_IRQ+0x53/0xf0
[<ffffffff815a74af>] common_interrupt+0x6f/0x6f
<EOI> [<ffffffff8147b56e>] ? cpuidle_enter_state+0x6e/0x180
[<ffffffff8147b732>] cpuidle_enter+0x12/0x20
[<ffffffff8108bba0>] cpu_startup_entry+0x330/0x360
[<ffffffff8158fb51>] rest_init+0xc1/0xd0
[<ffffffff8158fa90>] ? csum_partial_copy_generic+0x170/0x170
[<ffffffff81af3ff2>] start_kernel+0x44f/0x45a
[<ffffffff81af399c>] ? set_init_arg+0x53/0x53
[<ffffffff81af35ad>] x86_64_start_reservations+0x2a/0x2c
[<ffffffff81af36a0>] x86_64_start_kernel+0xf1/0xf4
Cc: Vincent Donnefort <vdonnefort@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
2014-09-02 09:03:12 +00:00
|
|
|
#include <linux/timer.h>
|
2023-01-03 13:12:46 +00:00
|
|
|
#include <linux/types.h>
|
2012-08-15 13:44:34 +00:00
|
|
|
#include <linux/workqueue.h>
|
2006-09-29 09:00:14 +00:00
|
|
|
|
2023-01-03 13:12:46 +00:00
|
|
|
struct attribute_group;
|
2019-10-03 08:28:09 +00:00
|
|
|
struct device_node;
|
2023-01-03 13:12:46 +00:00
|
|
|
struct fwnode_handle;
|
|
|
|
struct gpio_desc;
|
|
|
|
struct kernfs_node;
|
|
|
|
struct led_pattern;
|
|
|
|
struct platform_device;
|
|
|
|
|
2006-03-31 10:31:04 +00:00
|
|
|
/*
|
|
|
|
* LED Core
|
|
|
|
*/
|
|
|
|
|
2020-03-21 16:01:53 +00:00
|
|
|
/* This is obsolete/useless. We now support variable maximum brightness. */
|
2006-03-31 10:31:04 +00:00
|
|
|
enum led_brightness {
|
2006-04-11 05:54:02 +00:00
|
|
|
LED_OFF = 0,
|
2017-01-05 02:34:12 +00:00
|
|
|
LED_ON = 1,
|
2006-04-11 05:54:02 +00:00
|
|
|
LED_HALF = 127,
|
|
|
|
LED_FULL = 255,
|
2006-03-31 10:31:04 +00:00
|
|
|
};
|
|
|
|
|
2021-06-08 06:35:53 +00:00
|
|
|
enum led_default_state {
|
|
|
|
LEDS_DEFSTATE_OFF = 0,
|
|
|
|
LEDS_DEFSTATE_ON = 1,
|
|
|
|
LEDS_DEFSTATE_KEEP = 2,
|
|
|
|
};
|
|
|
|
|
2023-01-20 11:45:17 +00:00
|
|
|
/**
|
|
|
|
* struct led_lookup_data - represents a single LED lookup entry
|
|
|
|
*
|
|
|
|
* @list: internal list of all LED lookup entries
|
|
|
|
* @provider: name of led_classdev providing the LED
|
|
|
|
* @dev_id: name of the device associated with this LED
|
|
|
|
* @con_id: name of the LED from the device's point of view
|
|
|
|
*/
|
|
|
|
struct led_lookup_data {
|
|
|
|
struct list_head list;
|
|
|
|
const char *provider;
|
|
|
|
const char *dev_id;
|
|
|
|
const char *con_id;
|
|
|
|
};
|
|
|
|
|
2019-06-09 18:19:03 +00:00
|
|
|
struct led_init_data {
|
|
|
|
/* device fwnode handle */
|
|
|
|
struct fwnode_handle *fwnode;
|
2019-06-09 18:19:04 +00:00
|
|
|
/*
|
|
|
|
* default <color:function> tuple, for backward compatibility
|
|
|
|
* with in-driver hard-coded LED names used as a fallback when
|
|
|
|
* DT "label" property is absent; it should be set to NULL
|
|
|
|
* in new LED class drivers.
|
|
|
|
*/
|
|
|
|
const char *default_label;
|
|
|
|
/*
|
|
|
|
* string to be used for devicename section of LED class device
|
|
|
|
* either for label based LED name composition path or for fwnode
|
|
|
|
* based when devname_mandatory is true
|
|
|
|
*/
|
|
|
|
const char *devicename;
|
|
|
|
/*
|
|
|
|
* indicates if LED name should always comprise devicename section;
|
|
|
|
* only LEDs exposed by drivers of hot-pluggable devices should
|
|
|
|
* set it to true
|
|
|
|
*/
|
|
|
|
bool devname_mandatory;
|
2019-06-09 18:19:03 +00:00
|
|
|
};
|
|
|
|
|
2023-04-17 15:17:26 +00:00
|
|
|
#if IS_ENABLED(CONFIG_NEW_LEDS)
|
2023-01-03 13:12:47 +00:00
|
|
|
enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode);
|
2023-04-17 15:17:26 +00:00
|
|
|
#else
|
|
|
|
static inline enum led_default_state
|
|
|
|
led_init_default_state_get(struct fwnode_handle *fwnode)
|
|
|
|
{
|
|
|
|
return LEDS_DEFSTATE_OFF;
|
|
|
|
}
|
|
|
|
#endif
|
2023-01-03 13:12:47 +00:00
|
|
|
|
2020-07-16 17:17:28 +00:00
|
|
|
struct led_hw_trigger_type {
|
|
|
|
int dummy;
|
|
|
|
};
|
|
|
|
|
2006-03-31 10:31:04 +00:00
|
|
|
struct led_classdev {
|
2006-04-11 05:54:02 +00:00
|
|
|
const char *name;
|
2020-12-11 20:42:08 +00:00
|
|
|
unsigned int brightness;
|
|
|
|
unsigned int max_brightness;
|
2023-07-28 15:37:29 +00:00
|
|
|
unsigned int color;
|
2006-04-11 05:54:02 +00:00
|
|
|
int flags;
|
2006-03-31 10:31:04 +00:00
|
|
|
|
2009-01-08 17:55:03 +00:00
|
|
|
/* Lower 16 bits reflect status */
|
2017-09-13 17:53:58 +00:00
|
|
|
#define LED_SUSPENDED BIT(0)
|
|
|
|
#define LED_UNREGISTERING BIT(1)
|
2009-01-08 17:55:03 +00:00
|
|
|
/* Upper 16 bits reflect control information */
|
2017-09-13 17:53:58 +00:00
|
|
|
#define LED_CORE_SUSPENDRESUME BIT(16)
|
|
|
|
#define LED_SYSFS_DISABLE BIT(17)
|
|
|
|
#define LED_DEV_CAP_FLASH BIT(18)
|
|
|
|
#define LED_HW_PLUGGABLE BIT(19)
|
|
|
|
#define LED_PANIC_INDICATOR BIT(20)
|
|
|
|
#define LED_BRIGHT_HW_CHANGED BIT(21)
|
|
|
|
#define LED_RETAIN_AT_SHUTDOWN BIT(22)
|
2018-12-10 09:29:58 +00:00
|
|
|
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
|
2016-11-08 13:38:46 +00:00
|
|
|
|
|
|
|
/* set_brightness_work / blink_timer flags, atomic, private. */
|
|
|
|
unsigned long work_flags;
|
|
|
|
|
|
|
|
#define LED_BLINK_SW 0
|
|
|
|
#define LED_BLINK_ONESHOT 1
|
|
|
|
#define LED_BLINK_ONESHOT_STOP 2
|
|
|
|
#define LED_BLINK_INVERT 3
|
|
|
|
#define LED_BLINK_BRIGHTNESS_CHANGE 4
|
|
|
|
#define LED_BLINK_DISABLE 5
|
2023-05-10 16:22:32 +00:00
|
|
|
/* Brightness off also disables hw-blinking so it is a separate action */
|
|
|
|
#define LED_SET_BRIGHTNESS_OFF 6
|
|
|
|
#define LED_SET_BRIGHTNESS 7
|
2023-05-10 16:22:33 +00:00
|
|
|
#define LED_SET_BLINK 8
|
2006-03-31 10:31:04 +00:00
|
|
|
|
2016-01-21 22:11:25 +00:00
|
|
|
/* Set LED brightness level
|
|
|
|
* Must not sleep. Use brightness_set_blocking for drivers
|
|
|
|
* that can sleep while setting brightness.
|
|
|
|
*/
|
2006-04-11 05:54:02 +00:00
|
|
|
void (*brightness_set)(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness brightness);
|
2014-11-14 10:50:18 +00:00
|
|
|
/*
|
|
|
|
* Set LED brightness level immediately - it can block the caller for
|
|
|
|
* the time required for accessing a LED device register.
|
|
|
|
*/
|
2015-10-07 09:10:40 +00:00
|
|
|
int (*brightness_set_blocking)(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness brightness);
|
2008-03-18 09:47:48 +00:00
|
|
|
/* Get LED brightness level */
|
|
|
|
enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
|
2006-04-11 05:54:02 +00:00
|
|
|
|
2010-11-11 22:05:21 +00:00
|
|
|
/*
|
|
|
|
* Activate hardware accelerated blink, delays are in milliseconds
|
|
|
|
* and if both are zero then a sensible default should be chosen.
|
|
|
|
* The call should adjust the timings in that case and if it can't
|
|
|
|
* match the values specified exactly.
|
leds: core: Fix brightness setting upon hardware blinking enabled
Commit 76931edd54f8 ("leds: fix brightness changing when software blinking
is active") changed the semantics of led_set_brightness() which according
to the documentation should disable blinking upon any brightness setting.
Moreover it made it different for soft blink case, where it was possible
to change blink brightness, and for hardware blink case, where setting
any brightness greater than 0 was ignored.
While the change itself is against the documentation claims, it was driven
also by the fact that timer trigger remained active after turning blinking
off. Fixing that would have required major refactoring in the led-core,
led-class, and led-triggers because of cyclic dependencies.
Finally, it has been decided that allowing for brightness change during
blinking is beneficial as it can be accomplished without disturbing
blink rhythm.
The change in brightness setting semantics will not affect existing
LED class drivers that implement blink_set op thanks to the LED_BLINK_SW
flag introduced by this patch. The flag state will be from now on checked
in led_set_brightness() which will allow to distinguish between software
and hardware blink mode. In the latter case the control will be passed
directly to the drivers which apply their semantics on brightness set,
which is disable the blinking in case of most such drivers. New drivers
will apply new semantics and just change the brightness while hardware
blinking is on, if possible.
The issue was smuggled by subsequent LED core improvements, which modified
the code that originally introduced the problem.
Fixes: f1e80c07416a ("leds: core: Add two new LED_BLINK_ flags")
Signed-off-by: Tony Makkiel <tony.makkiel@daqri.com>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
2016-05-18 16:22:45 +00:00
|
|
|
* Deactivate blinking again when the brightness is set to LED_OFF
|
|
|
|
* via the brightness_set() callback.
|
2023-05-10 16:22:33 +00:00
|
|
|
* For led_blink_set_nosleep() the LED core assumes that blink_set
|
|
|
|
* implementations, of drivers which do not use brightness_set_blocking,
|
|
|
|
* will not sleep. Therefor if brightness_set_blocking is not set
|
|
|
|
* this function must not sleep!
|
2010-11-11 22:05:21 +00:00
|
|
|
*/
|
2007-10-31 14:07:12 +00:00
|
|
|
int (*blink_set)(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
|
|
|
|
2018-10-11 04:07:14 +00:00
|
|
|
int (*pattern_set)(struct led_classdev *led_cdev,
|
|
|
|
struct led_pattern *pattern, u32 len, int repeat);
|
|
|
|
int (*pattern_clear)(struct led_classdev *led_cdev);
|
|
|
|
|
2007-07-08 22:19:31 +00:00
|
|
|
struct device *dev;
|
2014-06-25 17:08:44 +00:00
|
|
|
const struct attribute_group **groups;
|
|
|
|
|
2006-04-11 05:54:02 +00:00
|
|
|
struct list_head node; /* LED Device list */
|
2008-05-31 14:23:19 +00:00
|
|
|
const char *default_trigger; /* Trigger to use */
|
2006-03-31 10:31:04 +00:00
|
|
|
|
2010-11-11 22:05:21 +00:00
|
|
|
unsigned long blink_delay_on, blink_delay_off;
|
Revert "leds: convert blink timer to workqueue"
This reverts commit 8b37e1bef5a6b60e949e28a4db3006e4b00bd758.
It's broken as it changes led_blink_set() in a way that it can now sleep
(while synchronously waiting for workqueue to be cancelled). That's a
problem, because it's possible that this function gets called from atomic
context (tpt_trig_timer() takes a readlock and thus disables preemption).
This has been brought up 3 weeks ago already [1] but no proper fix has
materialized, and I keep seeing the problem since 3.17-rc1.
[1] https://lkml.org/lkml/2014/8/16/128
BUG: sleeping function called from invalid context at kernel/workqueue.c:2650
in_atomic(): 1, irqs_disabled(): 0, pid: 2335, name: wpa_supplicant
5 locks held by wpa_supplicant/2335:
#0: (rtnl_mutex){+.+.+.}, at: [<ffffffff814c7c92>] rtnl_lock+0x12/0x20
#1: (&wdev->mtx){+.+.+.}, at: [<ffffffffc06e649c>] cfg80211_mgd_wext_siwessid+0x5c/0x180 [cfg80211]
#2: (&local->mtx){+.+.+.}, at: [<ffffffffc0817dea>] ieee80211_prep_connection+0x17a/0x9a0 [mac80211]
#3: (&local->chanctx_mtx){+.+.+.}, at: [<ffffffffc08081ed>] ieee80211_vif_use_channel+0x5d/0x2a0 [mac80211]
#4: (&trig->leddev_list_lock){.+.+..}, at: [<ffffffffc081e68c>] tpt_trig_timer+0xec/0x170 [mac80211]
CPU: 0 PID: 2335 Comm: wpa_supplicant Not tainted 3.17.0-rc3 #1
Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
ffff8800360b5a50 ffff8800751f76d8 ffffffff8159e97f ffff8800360b5a30
ffff8800751f76e8 ffffffff810739a5 ffff8800751f77b0 ffffffff8106862f
ffffffff810685d0 0aa2209200000000 ffff880000000004 ffff8800361c59d0
Call Trace:
[<ffffffff8159e97f>] dump_stack+0x4d/0x66
[<ffffffff810739a5>] __might_sleep+0xe5/0x120
[<ffffffff8106862f>] flush_work+0x5f/0x270
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffff810945ca>] ? mark_held_locks+0x6a/0x90
[<ffffffff81068a5f>] ? __cancel_work_timer+0x6f/0x100
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffffc081ecdd>] ieee80211_mod_tpt_led_trig+0x9d/0x160 [mac80211]
[<ffffffffc07e4278>] __ieee80211_recalc_idle+0x98/0x140 [mac80211]
[<ffffffffc07e59ce>] ieee80211_idle_off+0xe/0x10 [mac80211]
[<ffffffffc0804e5b>] ieee80211_add_chanctx+0x3b/0x220 [mac80211]
[<ffffffffc08062e4>] ieee80211_new_chanctx+0x44/0xf0 [mac80211]
[<ffffffffc080838a>] ieee80211_vif_use_channel+0x1fa/0x2a0 [mac80211]
[<ffffffffc0817df8>] ieee80211_prep_connection+0x188/0x9a0 [mac80211]
[<ffffffffc081c246>] ieee80211_mgd_auth+0x256/0x2e0 [mac80211]
[<ffffffffc07eab33>] ieee80211_auth+0x13/0x20 [mac80211]
[<ffffffffc06cb006>] cfg80211_mlme_auth+0x106/0x270 [cfg80211]
[<ffffffffc06ce085>] cfg80211_conn_do_work+0x155/0x3b0 [cfg80211]
[<ffffffffc06cf670>] cfg80211_connect+0x3f0/0x540 [cfg80211]
[<ffffffffc06e6148>] cfg80211_mgd_wext_connect+0x158/0x1f0 [cfg80211]
[<ffffffffc06e651e>] cfg80211_mgd_wext_siwessid+0xde/0x180 [cfg80211]
[<ffffffffc06e36c0>] ? cfg80211_wext_giwessid+0x50/0x50 [cfg80211]
[<ffffffffc06e36dd>] cfg80211_wext_siwessid+0x1d/0x40 [cfg80211]
[<ffffffff81584d0c>] ioctl_standard_iw_point+0x14c/0x3e0
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff8158502a>] ioctl_standard_call+0x8a/0xd0
[<ffffffff81584fa0>] ? ioctl_standard_iw_point+0x3e0/0x3e0
[<ffffffff81584b76>] wireless_process_ioctl.constprop.10+0xb6/0x100
[<ffffffff8158521d>] wext_handle_ioctl+0x5d/0xb0
[<ffffffff814cfb29>] dev_ioctl+0x329/0x620
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff8149c7f2>] sock_ioctl+0x142/0x2e0
[<ffffffff811b0140>] do_vfs_ioctl+0x300/0x520
[<ffffffff815a67fb>] ? sysret_check+0x1b/0x56
[<ffffffff810946ed>] ? trace_hardirqs_on_caller+0xfd/0x1c0
[<ffffffff811b03e1>] SyS_ioctl+0x81/0xa0
[<ffffffff815a67d6>] system_call_fastpath+0x1a/0x1f
wlan0: send auth to 00:0b:6b:3c:8c:e4 (try 1/3)
wlan0: authenticated
wlan0: associate with 00:0b:6b:3c:8c:e4 (try 1/3)
wlan0: RX AssocResp from 00:0b:6b:3c:8c:e4 (capab=0x431 status=0 aid=2)
wlan0: associated
IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
cfg80211: Calling CRDA for country: NA
wlan0: Limiting TX power to 27 (27 - 0) dBm as advertised by 00:0b:6b:3c:8c:e4
=================================
[ INFO: inconsistent lock state ]
3.17.0-rc3 #1 Not tainted
---------------------------------
inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
swapper/0/0 [HC0[0]:SC1[1]:HE1:SE0] takes:
((&(&led_cdev->blink_work)->work)){+.?...}, at: [<ffffffff810685d0>] flush_work+0x0/0x270
{SOFTIRQ-ON-W} state was registered at:
[<ffffffff81094dbe>] __lock_acquire+0x30e/0x1a30
[<ffffffff81096c81>] lock_acquire+0x91/0x110
[<ffffffff81068608>] flush_work+0x38/0x270
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffffc081ecdd>] ieee80211_mod_tpt_led_trig+0x9d/0x160 [mac80211]
[<ffffffffc07e4278>] __ieee80211_recalc_idle+0x98/0x140 [mac80211]
[<ffffffffc07e59ce>] ieee80211_idle_off+0xe/0x10 [mac80211]
[<ffffffffc0804e5b>] ieee80211_add_chanctx+0x3b/0x220 [mac80211]
[<ffffffffc08062e4>] ieee80211_new_chanctx+0x44/0xf0 [mac80211]
[<ffffffffc080838a>] ieee80211_vif_use_channel+0x1fa/0x2a0 [mac80211]
[<ffffffffc0817df8>] ieee80211_prep_connection+0x188/0x9a0 [mac80211]
[<ffffffffc081c246>] ieee80211_mgd_auth+0x256/0x2e0 [mac80211]
[<ffffffffc07eab33>] ieee80211_auth+0x13/0x20 [mac80211]
[<ffffffffc06cb006>] cfg80211_mlme_auth+0x106/0x270 [cfg80211]
[<ffffffffc06ce085>] cfg80211_conn_do_work+0x155/0x3b0 [cfg80211]
[<ffffffffc06cf670>] cfg80211_connect+0x3f0/0x540 [cfg80211]
[<ffffffffc06e6148>] cfg80211_mgd_wext_connect+0x158/0x1f0 [cfg80211]
[<ffffffffc06e651e>] cfg80211_mgd_wext_siwessid+0xde/0x180 [cfg80211]
[<ffffffffc06e36dd>] cfg80211_wext_siwessid+0x1d/0x40 [cfg80211]
[<ffffffff81584d0c>] ioctl_standard_iw_point+0x14c/0x3e0
[<ffffffff8158502a>] ioctl_standard_call+0x8a/0xd0
[<ffffffff81584b76>] wireless_process_ioctl.constprop.10+0xb6/0x100
[<ffffffff8158521d>] wext_handle_ioctl+0x5d/0xb0
[<ffffffff814cfb29>] dev_ioctl+0x329/0x620
[<ffffffff8149c7f2>] sock_ioctl+0x142/0x2e0
[<ffffffff811b0140>] do_vfs_ioctl+0x300/0x520
[<ffffffff811b03e1>] SyS_ioctl+0x81/0xa0
[<ffffffff815a67d6>] system_call_fastpath+0x1a/0x1f
irq event stamp: 493416
hardirqs last enabled at (493416): [<ffffffff81068a5f>] __cancel_work_timer+0x6f/0x100
hardirqs last disabled at (493415): [<ffffffff81067e9f>] try_to_grab_pending+0x1f/0x160
softirqs last enabled at (493408): [<ffffffff81053ced>] _local_bh_enable+0x1d/0x50
softirqs last disabled at (493409): [<ffffffff81054c75>] irq_exit+0xa5/0xb0
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock((&(&led_cdev->blink_work)->work));
<Interrupt>
lock((&(&led_cdev->blink_work)->work));
*** DEADLOCK ***
2 locks held by swapper/0/0:
#0: (((&tpt_trig->timer))){+.-...}, at: [<ffffffff810b4c50>] call_timer_fn+0x0/0x180
#1: (&trig->leddev_list_lock){.+.?..}, at: [<ffffffffc081e68c>] tpt_trig_timer+0xec/0x170 [mac80211]
stack backtrace:
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.17.0-rc3 #1
Hardware name: LENOVO 7470BN2/7470BN2, BIOS 6DET38WW (2.02 ) 12/19/2008
ffffffff8246eb30 ffff88007c203b00 ffffffff8159e97f ffffffff81a194c0
ffff88007c203b50 ffffffff81599c29 0000000000000001 ffffffff00000001
ffff880000000000 0000000000000006 ffffffff81a194c0 ffffffff81093ad0
Call Trace:
<IRQ> [<ffffffff8159e97f>] dump_stack+0x4d/0x66
[<ffffffff81599c29>] print_usage_bug+0x1f4/0x205
[<ffffffff81093ad0>] ? check_usage_backwards+0x140/0x140
[<ffffffff810944d3>] mark_lock+0x223/0x2b0
[<ffffffff81094d60>] __lock_acquire+0x2b0/0x1a30
[<ffffffff81096c81>] lock_acquire+0x91/0x110
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff81068608>] flush_work+0x38/0x270
[<ffffffff810685d0>] ? mod_delayed_work_on+0x80/0x80
[<ffffffff810945ca>] ? mark_held_locks+0x6a/0x90
[<ffffffff81068a5f>] ? __cancel_work_timer+0x6f/0x100
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff8109469d>] ? trace_hardirqs_on_caller+0xad/0x1c0
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff81068a6b>] __cancel_work_timer+0x7b/0x100
[<ffffffff81068b0e>] cancel_delayed_work_sync+0xe/0x10
[<ffffffff8147cf3b>] led_blink_set+0x1b/0x40
[<ffffffffc081e6b0>] tpt_trig_timer+0x110/0x170 [mac80211]
[<ffffffff810b4cc5>] call_timer_fn+0x75/0x180
[<ffffffff810b4c50>] ? process_timeout+0x10/0x10
[<ffffffffc081e5a0>] ? __ieee80211_get_rx_led_name+0x10/0x10 [mac80211]
[<ffffffff810b50ac>] run_timer_softirq+0x1fc/0x2f0
[<ffffffff81054805>] __do_softirq+0x115/0x2e0
[<ffffffff81054c75>] irq_exit+0xa5/0xb0
[<ffffffff810049b3>] do_IRQ+0x53/0xf0
[<ffffffff815a74af>] common_interrupt+0x6f/0x6f
<EOI> [<ffffffff8147b56e>] ? cpuidle_enter_state+0x6e/0x180
[<ffffffff8147b732>] cpuidle_enter+0x12/0x20
[<ffffffff8108bba0>] cpu_startup_entry+0x330/0x360
[<ffffffff8158fb51>] rest_init+0xc1/0xd0
[<ffffffff8158fa90>] ? csum_partial_copy_generic+0x170/0x170
[<ffffffff81af3ff2>] start_kernel+0x44f/0x45a
[<ffffffff81af399c>] ? set_init_arg+0x53/0x53
[<ffffffff81af35ad>] x86_64_start_reservations+0x2a/0x2c
[<ffffffff81af36a0>] x86_64_start_kernel+0xf1/0xf4
Cc: Vincent Donnefort <vdonnefort@gmail.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
2014-09-02 09:03:12 +00:00
|
|
|
struct timer_list blink_timer;
|
2010-11-11 22:05:21 +00:00
|
|
|
int blink_brightness;
|
2016-10-23 19:47:26 +00:00
|
|
|
int new_blink_brightness;
|
2015-01-09 15:22:51 +00:00
|
|
|
void (*flash_resume)(struct led_classdev *led_cdev);
|
2010-11-11 22:05:21 +00:00
|
|
|
|
2012-08-15 13:44:34 +00:00
|
|
|
struct work_struct set_brightness_work;
|
|
|
|
int delayed_set_value;
|
2023-05-10 16:22:33 +00:00
|
|
|
unsigned long delayed_delay_on;
|
|
|
|
unsigned long delayed_delay_off;
|
2012-08-15 13:44:34 +00:00
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGERS
|
|
|
|
/* Protects the trigger data below */
|
2007-11-10 13:29:04 +00:00
|
|
|
struct rw_semaphore trigger_lock;
|
2006-03-31 10:31:05 +00:00
|
|
|
|
2006-04-11 05:54:02 +00:00
|
|
|
struct led_trigger *trigger;
|
|
|
|
struct list_head trig_list;
|
|
|
|
void *trigger_data;
|
2012-05-29 22:07:27 +00:00
|
|
|
/* true if activated - deactivate routine uses it to do cleanup */
|
|
|
|
bool activated;
|
2020-07-16 17:17:28 +00:00
|
|
|
|
|
|
|
/* LEDs that have private triggers have this set */
|
|
|
|
struct led_hw_trigger_type *trigger_type;
|
2023-05-29 16:32:31 +00:00
|
|
|
|
|
|
|
/* Unique trigger name supported by LED set in hw control mode */
|
|
|
|
const char *hw_control_trigger;
|
|
|
|
/*
|
|
|
|
* Check if the LED driver supports the requested mode provided by the
|
|
|
|
* defined supported trigger to setup the LED to hw control mode.
|
|
|
|
*
|
|
|
|
* Return 0 on success. Return -EOPNOTSUPP when the passed flags are not
|
|
|
|
* supported and software fallback needs to be used.
|
|
|
|
* Return a negative error number on any other case for check fail due
|
|
|
|
* to various reason like device not ready or timeouts.
|
|
|
|
*/
|
|
|
|
int (*hw_control_is_supported)(struct led_classdev *led_cdev,
|
|
|
|
unsigned long flags);
|
|
|
|
/*
|
|
|
|
* Activate hardware control, LED driver will use the provided flags
|
|
|
|
* from the supported trigger and setup the LED to be driven by hardware
|
|
|
|
* following the requested mode from the trigger flags.
|
|
|
|
* Deactivate hardware blink control by setting brightness to LED_OFF via
|
|
|
|
* the brightness_set() callback.
|
|
|
|
*
|
|
|
|
* Return 0 on success, a negative error number on flags apply fail.
|
|
|
|
*/
|
|
|
|
int (*hw_control_set)(struct led_classdev *led_cdev,
|
|
|
|
unsigned long flags);
|
|
|
|
/*
|
|
|
|
* Get from the LED driver the current mode that the LED is set in hw
|
|
|
|
* control mode and put them in flags.
|
|
|
|
* Trigger can use this to get the initial state of a LED already set in
|
|
|
|
* hardware blink control.
|
|
|
|
*
|
|
|
|
* Return 0 on success, a negative error number on failing parsing the
|
|
|
|
* initial mode. Error from this function is NOT FATAL as the device
|
|
|
|
* may be in a not supported initial state by the attached LED trigger.
|
|
|
|
*/
|
|
|
|
int (*hw_control_get)(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *flags);
|
2023-05-29 16:32:32 +00:00
|
|
|
/*
|
|
|
|
* Get the device this LED blinks in response to.
|
|
|
|
* e.g. for a PHY LED, it is the network device. If the LED is
|
|
|
|
* not yet associated to a device, return NULL.
|
|
|
|
*/
|
|
|
|
struct device *(*hw_control_get_device)(struct led_classdev *led_cdev);
|
2006-03-31 10:31:05 +00:00
|
|
|
#endif
|
2014-09-22 15:21:04 +00:00
|
|
|
|
2017-01-29 13:42:52 +00:00
|
|
|
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
|
|
|
|
int brightness_hw_changed;
|
|
|
|
struct kernfs_node *brightness_hw_changed_kn;
|
|
|
|
#endif
|
|
|
|
|
2014-09-22 15:21:04 +00:00
|
|
|
/* Ensures consistent access to the LED Flash Class device */
|
|
|
|
struct mutex led_access;
|
2006-03-31 10:31:04 +00:00
|
|
|
};
|
|
|
|
|
2019-06-09 18:19:03 +00:00
|
|
|
/**
|
|
|
|
* led_classdev_register_ext - register a new object of LED class with
|
|
|
|
* init data
|
|
|
|
* @parent: LED controller device this LED is driven by
|
|
|
|
* @led_cdev: the led_classdev structure for this device
|
|
|
|
* @init_data: the LED class device initialization data
|
|
|
|
*
|
2019-08-26 20:34:42 +00:00
|
|
|
* Register a new object of LED class, with name derived from init_data.
|
|
|
|
*
|
2019-06-09 18:19:03 +00:00
|
|
|
* Returns: 0 on success or negative error value on failure
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
int led_classdev_register_ext(struct device *parent,
|
2019-06-09 18:19:03 +00:00
|
|
|
struct led_classdev *led_cdev,
|
|
|
|
struct led_init_data *init_data);
|
2019-08-26 20:34:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_classdev_register - register a new object of LED class
|
|
|
|
* @parent: LED controller device this LED is driven by
|
|
|
|
* @led_cdev: the led_classdev structure for this device
|
|
|
|
*
|
|
|
|
* Register a new object of LED class, with name derived from the name property
|
|
|
|
* of passed led_cdev argument.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success or negative error value on failure
|
|
|
|
*/
|
|
|
|
static inline int led_classdev_register(struct device *parent,
|
|
|
|
struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return led_classdev_register_ext(parent, led_cdev, NULL);
|
|
|
|
}
|
|
|
|
|
2023-04-17 15:17:26 +00:00
|
|
|
#if IS_ENABLED(CONFIG_LEDS_CLASS)
|
2019-10-02 12:40:40 +00:00
|
|
|
int devm_led_classdev_register_ext(struct device *parent,
|
2019-06-09 18:19:03 +00:00
|
|
|
struct led_classdev *led_cdev,
|
|
|
|
struct led_init_data *init_data);
|
2023-04-17 15:17:26 +00:00
|
|
|
#else
|
|
|
|
static inline int
|
|
|
|
devm_led_classdev_register_ext(struct device *parent,
|
|
|
|
struct led_classdev *led_cdev,
|
|
|
|
struct led_init_data *init_data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2019-08-26 20:34:42 +00:00
|
|
|
|
|
|
|
static inline int devm_led_classdev_register(struct device *parent,
|
|
|
|
struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return devm_led_classdev_register_ext(parent, led_cdev, NULL);
|
|
|
|
}
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_classdev_unregister(struct led_classdev *led_cdev);
|
|
|
|
void devm_led_classdev_unregister(struct device *parent,
|
|
|
|
struct led_classdev *led_cdev);
|
|
|
|
void led_classdev_suspend(struct led_classdev *led_cdev);
|
|
|
|
void led_classdev_resume(struct led_classdev *led_cdev);
|
2006-03-31 10:31:04 +00:00
|
|
|
|
2023-01-20 11:45:17 +00:00
|
|
|
void led_add_lookup(struct led_lookup_data *led_lookup);
|
|
|
|
void led_remove_lookup(struct led_lookup_data *led_lookup);
|
|
|
|
|
|
|
|
struct led_classdev *__must_check led_get(struct device *dev, char *con_id);
|
|
|
|
struct led_classdev *__must_check devm_led_get(struct device *dev, char *con_id);
|
|
|
|
|
2019-10-03 08:28:09 +00:00
|
|
|
extern struct led_classdev *of_led_get(struct device_node *np, int index);
|
|
|
|
extern void led_put(struct led_classdev *led_cdev);
|
2019-10-03 08:28:10 +00:00
|
|
|
struct led_classdev *__must_check devm_of_led_get(struct device *dev,
|
|
|
|
int index);
|
2023-07-28 15:37:28 +00:00
|
|
|
struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev,
|
|
|
|
int index);
|
2019-10-03 08:28:09 +00:00
|
|
|
|
2010-11-11 22:05:21 +00:00
|
|
|
/**
|
|
|
|
* led_blink_set - set blinking with software fallback
|
|
|
|
* @led_cdev: the LED to start blinking
|
|
|
|
* @delay_on: the time it should be on (in ms)
|
|
|
|
* @delay_off: the time it should ble off (in ms)
|
|
|
|
*
|
|
|
|
* This function makes the LED blink, attempting to use the
|
|
|
|
* hardware acceleration if possible, but falling back to
|
|
|
|
* software blinking if there is no hardware blinking or if
|
|
|
|
* the LED refuses the passed values.
|
|
|
|
*
|
2023-05-10 16:22:33 +00:00
|
|
|
* This function may sleep!
|
|
|
|
*
|
2010-11-11 22:05:21 +00:00
|
|
|
* Note that if software blinking is active, simply calling
|
|
|
|
* led_cdev->brightness_set() will not stop the blinking,
|
2023-02-18 17:21:21 +00:00
|
|
|
* use led_set_brightness() instead.
|
2010-11-11 22:05:21 +00:00
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
2023-05-10 16:22:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_blink_set_nosleep - set blinking, guaranteed to not sleep
|
|
|
|
* @led_cdev: the LED to start blinking
|
|
|
|
* @delay_on: the time it should be on (in ms)
|
|
|
|
* @delay_off: the time it should ble off (in ms)
|
|
|
|
*
|
|
|
|
* This function makes the LED blink and is guaranteed to not sleep. Otherwise
|
|
|
|
* this is the same as led_blink_set(), see led_blink_set() for details.
|
|
|
|
*/
|
|
|
|
void led_blink_set_nosleep(struct led_classdev *led_cdev, unsigned long delay_on,
|
|
|
|
unsigned long delay_off);
|
|
|
|
|
2012-05-26 23:19:22 +00:00
|
|
|
/**
|
|
|
|
* led_blink_set_oneshot - do a oneshot software blink
|
|
|
|
* @led_cdev: the LED to start blinking
|
|
|
|
* @delay_on: the time it should be on (in ms)
|
|
|
|
* @delay_off: the time it should ble off (in ms)
|
|
|
|
* @invert: blink off, then on, leaving the led on
|
|
|
|
*
|
|
|
|
* This function makes the LED blink one time for delay_on +
|
|
|
|
* delay_off time, ignoring the request if another one-shot
|
|
|
|
* blink is already in progress.
|
|
|
|
*
|
|
|
|
* If invert is set, led blinks for delay_off first, then for
|
|
|
|
* delay_on and leave the led on after the on-off cycle.
|
2023-05-10 16:22:33 +00:00
|
|
|
*
|
|
|
|
* This function is guaranteed not to sleep.
|
2012-05-26 23:19:22 +00:00
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_blink_set_oneshot(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *delay_on, unsigned long *delay_off,
|
|
|
|
int invert);
|
2010-11-11 22:05:21 +00:00
|
|
|
/**
|
2012-06-13 20:34:30 +00:00
|
|
|
* led_set_brightness - set LED brightness
|
2010-11-11 22:05:21 +00:00
|
|
|
* @led_cdev: the LED to set
|
|
|
|
* @brightness: the brightness to set it to
|
|
|
|
*
|
|
|
|
* Set an LED's brightness, and, if necessary, cancel the
|
|
|
|
* software blink timer that implements blinking when the
|
2015-10-19 07:04:01 +00:00
|
|
|
* hardware doesn't. This function is guaranteed not to sleep.
|
2010-11-11 22:05:21 +00:00
|
|
|
*/
|
2020-12-11 20:42:08 +00:00
|
|
|
void led_set_brightness(struct led_classdev *led_cdev, unsigned int brightness);
|
2015-10-07 09:10:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_set_brightness_sync - set LED brightness synchronously
|
|
|
|
* @led_cdev: the LED to set
|
2019-10-02 12:40:42 +00:00
|
|
|
* @value: the brightness to set it to
|
2015-10-07 09:10:43 +00:00
|
|
|
*
|
|
|
|
* Set an LED's brightness immediately. This function will block
|
|
|
|
* the caller for the time required for accessing device registers,
|
|
|
|
* and it can sleep.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success or negative error value on failure
|
|
|
|
*/
|
2020-12-11 20:42:08 +00:00
|
|
|
int led_set_brightness_sync(struct led_classdev *led_cdev, unsigned int value);
|
2015-10-07 09:10:43 +00:00
|
|
|
|
2014-08-20 13:41:55 +00:00
|
|
|
/**
|
|
|
|
* led_update_brightness - update LED brightness
|
|
|
|
* @led_cdev: the LED to query
|
|
|
|
*
|
|
|
|
* Get an LED's current brightness and update led_cdev->brightness
|
|
|
|
* member with the obtained value.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success or negative error value on failure
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
int led_update_brightness(struct led_classdev *led_cdev);
|
2010-11-11 22:05:21 +00:00
|
|
|
|
2019-01-09 14:44:46 +00:00
|
|
|
/**
|
|
|
|
* led_get_default_pattern - return default pattern
|
|
|
|
*
|
|
|
|
* @led_cdev: the LED to get default pattern for
|
|
|
|
* @size: pointer for storing the number of elements in returned array,
|
|
|
|
* modified only if return != NULL
|
|
|
|
*
|
|
|
|
* Return: Allocated array of integers with default pattern from device tree
|
|
|
|
* or NULL. Caller is responsible for kfree().
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
u32 *led_get_default_pattern(struct led_classdev *led_cdev, unsigned int *size);
|
2019-01-09 14:44:46 +00:00
|
|
|
|
2014-09-22 15:21:04 +00:00
|
|
|
/**
|
|
|
|
* led_sysfs_disable - disable LED sysfs interface
|
|
|
|
* @led_cdev: the LED to set
|
|
|
|
*
|
|
|
|
* Disable the led_cdev's sysfs interface.
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_sysfs_disable(struct led_classdev *led_cdev);
|
2014-09-22 15:21:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_sysfs_enable - enable LED sysfs interface
|
|
|
|
* @led_cdev: the LED to set
|
|
|
|
*
|
|
|
|
* Enable the led_cdev's sysfs interface.
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_sysfs_enable(struct led_classdev *led_cdev);
|
2014-09-22 15:21:04 +00:00
|
|
|
|
2019-06-09 18:19:04 +00:00
|
|
|
/**
|
|
|
|
* led_compose_name - compose LED class device name
|
|
|
|
* @dev: LED controller device object
|
2019-10-02 12:40:42 +00:00
|
|
|
* @init_data: the LED class device initialization data
|
2019-06-09 18:19:04 +00:00
|
|
|
* @led_classdev_name: composed LED class device name
|
|
|
|
*
|
|
|
|
* Create LED class device name basing on the provided init_data argument.
|
|
|
|
* The name can have <devicename:color:function> or <color:function>.
|
|
|
|
* form, depending on the init_data configuration.
|
|
|
|
*
|
|
|
|
* Returns: 0 on success or negative error value on failure
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
int led_compose_name(struct device *dev, struct led_init_data *init_data,
|
|
|
|
char *led_classdev_name);
|
2019-06-09 18:19:04 +00:00
|
|
|
|
2014-09-22 15:21:04 +00:00
|
|
|
/**
|
|
|
|
* led_sysfs_is_disabled - check if LED sysfs interface is disabled
|
|
|
|
* @led_cdev: the LED to query
|
|
|
|
*
|
|
|
|
* Returns: true if the led_cdev's sysfs interface is disabled.
|
|
|
|
*/
|
|
|
|
static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return led_cdev->flags & LED_SYSFS_DISABLE;
|
|
|
|
}
|
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
/*
|
|
|
|
* LED Triggers
|
|
|
|
*/
|
2013-03-14 11:29:19 +00:00
|
|
|
/* Registration functions for simple triggers */
|
|
|
|
#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x;
|
|
|
|
#define DEFINE_LED_TRIGGER_GLOBAL(x) struct led_trigger *x;
|
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGERS
|
|
|
|
|
|
|
|
#define TRIG_NAME_MAX 50
|
|
|
|
|
|
|
|
struct led_trigger {
|
|
|
|
/* Trigger Properties */
|
2006-04-11 05:54:02 +00:00
|
|
|
const char *name;
|
2018-07-02 20:05:21 +00:00
|
|
|
int (*activate)(struct led_classdev *led_cdev);
|
2006-04-11 05:54:02 +00:00
|
|
|
void (*deactivate)(struct led_classdev *led_cdev);
|
2006-03-31 10:31:05 +00:00
|
|
|
|
2020-07-16 17:17:28 +00:00
|
|
|
/* LED-private triggers have this set */
|
|
|
|
struct led_hw_trigger_type *trigger_type;
|
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
/* LEDs under control by this trigger (for simple triggers) */
|
leds: trigger: use RCU to protect the led_cdevs list
Even with the previous commit 27af8e2c90fb
("leds: trigger: fix potential deadlock with libata")
to this file, we still get lockdep unhappy, and Boqun
explained the report here:
https://lore.kernel.org/r/YNA+d1X4UkoQ7g8a@boqun-archlinux
Effectively, this means that the read_lock_irqsave() isn't
enough here because another CPU might be trying to do a
write lock, and thus block the readers.
This is all pretty messy, but it doesn't seem right that
the LEDs framework imposes some locking requirements on
users, in particular we'd have to make the spinlock in the
iwlwifi driver always disable IRQs, even if we don't need
that for any other reason, just to avoid this deadlock.
Since writes to the led_cdevs list are rare (and are done
by userspace), just switch the list to RCU. This costs a
synchronize_rcu() at removal time so we can ensure things
are correct, but that seems like a small price to pay for
getting lock-free iterations and no deadlocks (nor any
locking requirements imposed on users.)
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
2021-09-15 16:16:01 +00:00
|
|
|
spinlock_t leddev_list_lock;
|
2006-04-11 05:54:02 +00:00
|
|
|
struct list_head led_cdevs;
|
2006-03-31 10:31:05 +00:00
|
|
|
|
|
|
|
/* Link to next registered trigger */
|
2006-04-11 05:54:02 +00:00
|
|
|
struct list_head next_trig;
|
2018-07-02 20:05:22 +00:00
|
|
|
|
|
|
|
const struct attribute_group **groups;
|
2006-03-31 10:31:05 +00:00
|
|
|
};
|
|
|
|
|
2018-07-02 20:05:22 +00:00
|
|
|
/*
|
|
|
|
* Currently the attributes in struct led_trigger::groups are added directly to
|
|
|
|
* the LED device. As this might change in the future, the following
|
|
|
|
* macros abstract getting the LED device and its trigger_data from the dev
|
|
|
|
* parameter passed to the attribute accessor functions.
|
|
|
|
*/
|
|
|
|
#define led_trigger_get_led(dev) ((struct led_classdev *)dev_get_drvdata((dev)))
|
|
|
|
#define led_trigger_get_drvdata(dev) (led_get_trigger_data(led_trigger_get_led(dev)))
|
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
/* Registration functions for complex triggers */
|
2019-10-02 12:40:40 +00:00
|
|
|
int led_trigger_register(struct led_trigger *trigger);
|
|
|
|
void led_trigger_unregister(struct led_trigger *trigger);
|
|
|
|
int devm_led_trigger_register(struct device *dev,
|
2016-01-02 00:36:41 +00:00
|
|
|
struct led_trigger *trigger);
|
2006-03-31 10:31:05 +00:00
|
|
|
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_trigger_register_simple(const char *name,
|
2006-03-31 10:31:05 +00:00
|
|
|
struct led_trigger **trigger);
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_trigger_unregister_simple(struct led_trigger *trigger);
|
|
|
|
void led_trigger_event(struct led_trigger *trigger, enum led_brightness event);
|
2023-05-10 16:22:31 +00:00
|
|
|
void led_trigger_blink(struct led_trigger *trigger, unsigned long delay_on,
|
|
|
|
unsigned long delay_off);
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_trigger_blink_oneshot(struct led_trigger *trigger,
|
2023-05-10 16:22:31 +00:00
|
|
|
unsigned long delay_on,
|
|
|
|
unsigned long delay_off,
|
2019-10-02 12:40:40 +00:00
|
|
|
int invert);
|
|
|
|
void led_trigger_set_default(struct led_classdev *led_cdev);
|
|
|
|
int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trigger);
|
|
|
|
void led_trigger_remove(struct led_classdev *led_cdev);
|
2015-04-28 07:18:41 +00:00
|
|
|
|
2018-07-02 20:05:25 +00:00
|
|
|
static inline void led_set_trigger_data(struct led_classdev *led_cdev,
|
|
|
|
void *trigger_data)
|
|
|
|
{
|
|
|
|
led_cdev->trigger_data = trigger_data;
|
|
|
|
}
|
|
|
|
|
2015-04-28 07:18:41 +00:00
|
|
|
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return led_cdev->trigger_data;
|
|
|
|
}
|
|
|
|
|
2012-11-19 05:35:55 +00:00
|
|
|
/**
|
|
|
|
* led_trigger_rename_static - rename a trigger
|
|
|
|
* @name: the new trigger name
|
|
|
|
* @trig: the LED trigger to rename
|
|
|
|
*
|
|
|
|
* Change a LED trigger name by copying the string passed in
|
|
|
|
* name into current trigger name, which MUST be large
|
|
|
|
* enough for the new string.
|
|
|
|
*
|
|
|
|
* Note that name must NOT point to the same string used
|
|
|
|
* during LED registration, as that could lead to races.
|
|
|
|
*
|
|
|
|
* This is meant to be used on triggers with statically
|
|
|
|
* allocated name.
|
|
|
|
*/
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_trigger_rename_static(const char *name, struct led_trigger *trig);
|
2006-03-31 10:31:05 +00:00
|
|
|
|
2018-07-02 20:05:24 +00:00
|
|
|
#define module_led_trigger(__led_trigger) \
|
|
|
|
module_driver(__led_trigger, led_trigger_register, \
|
|
|
|
led_trigger_unregister)
|
|
|
|
|
2006-03-31 10:31:05 +00:00
|
|
|
#else
|
|
|
|
|
2013-03-14 11:29:19 +00:00
|
|
|
/* Trigger has no members */
|
|
|
|
struct led_trigger {};
|
2006-03-31 10:31:05 +00:00
|
|
|
|
2013-03-14 11:29:19 +00:00
|
|
|
/* Trigger inline empty functions */
|
|
|
|
static inline void led_trigger_register_simple(const char *name,
|
|
|
|
struct led_trigger **trigger) {}
|
|
|
|
static inline void led_trigger_unregister_simple(struct led_trigger *trigger) {}
|
|
|
|
static inline void led_trigger_event(struct led_trigger *trigger,
|
|
|
|
enum led_brightness event) {}
|
2014-09-17 22:12:50 +00:00
|
|
|
static inline void led_trigger_blink(struct led_trigger *trigger,
|
2023-05-10 16:22:31 +00:00
|
|
|
unsigned long delay_on,
|
|
|
|
unsigned long delay_off) {}
|
2014-09-17 22:12:50 +00:00
|
|
|
static inline void led_trigger_blink_oneshot(struct led_trigger *trigger,
|
2023-05-10 16:22:31 +00:00
|
|
|
unsigned long delay_on,
|
|
|
|
unsigned long delay_off,
|
2014-09-17 22:12:50 +00:00
|
|
|
int invert) {}
|
2015-04-28 07:18:41 +00:00
|
|
|
static inline void led_trigger_set_default(struct led_classdev *led_cdev) {}
|
2018-07-02 20:05:21 +00:00
|
|
|
static inline int led_trigger_set(struct led_classdev *led_cdev,
|
|
|
|
struct led_trigger *trigger)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 07:18:41 +00:00
|
|
|
static inline void led_trigger_remove(struct led_classdev *led_cdev) {}
|
2018-07-02 20:05:25 +00:00
|
|
|
static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}
|
2015-04-28 07:18:41 +00:00
|
|
|
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-14 11:29:19 +00:00
|
|
|
#endif /* CONFIG_LEDS_TRIGGERS */
|
2006-03-31 10:31:16 +00:00
|
|
|
|
2023-05-29 16:32:41 +00:00
|
|
|
/* Trigger specific enum */
|
|
|
|
enum led_trigger_netdev_modes {
|
|
|
|
TRIGGER_NETDEV_LINK = 0,
|
2023-06-19 20:46:58 +00:00
|
|
|
TRIGGER_NETDEV_LINK_10,
|
|
|
|
TRIGGER_NETDEV_LINK_100,
|
|
|
|
TRIGGER_NETDEV_LINK_1000,
|
2023-06-19 20:46:59 +00:00
|
|
|
TRIGGER_NETDEV_HALF_DUPLEX,
|
|
|
|
TRIGGER_NETDEV_FULL_DUPLEX,
|
2023-05-29 16:32:41 +00:00
|
|
|
TRIGGER_NETDEV_TX,
|
|
|
|
TRIGGER_NETDEV_RX,
|
|
|
|
|
|
|
|
/* Keep last */
|
|
|
|
__TRIGGER_NETDEV_MAX,
|
|
|
|
};
|
|
|
|
|
2006-03-31 10:31:16 +00:00
|
|
|
/* Trigger specific functions */
|
2016-06-10 05:59:56 +00:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGER_DISK
|
2019-10-02 12:40:40 +00:00
|
|
|
void ledtrig_disk_activity(bool write);
|
2006-03-31 10:31:16 +00:00
|
|
|
#else
|
2018-02-24 22:45:56 +00:00
|
|
|
static inline void ledtrig_disk_activity(bool write) {}
|
2006-03-31 10:31:16 +00:00
|
|
|
#endif
|
|
|
|
|
2016-04-12 20:46:40 +00:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGER_MTD
|
2019-10-02 12:40:40 +00:00
|
|
|
void ledtrig_mtd_activity(void);
|
2016-04-12 20:46:40 +00:00
|
|
|
#else
|
|
|
|
static inline void ledtrig_mtd_activity(void) {}
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 11:29:24 +00:00
|
|
|
#if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
|
2019-10-02 12:40:40 +00:00
|
|
|
void ledtrig_flash_ctrl(bool on);
|
|
|
|
void ledtrig_torch_ctrl(bool on);
|
2013-03-14 11:29:24 +00:00
|
|
|
#else
|
|
|
|
static inline void ledtrig_flash_ctrl(bool on) {}
|
|
|
|
static inline void ledtrig_torch_ctrl(bool on) {}
|
|
|
|
#endif
|
|
|
|
|
2008-07-16 21:49:55 +00:00
|
|
|
/*
|
|
|
|
* Generic LED platform data for describing LED names and default triggers.
|
|
|
|
*/
|
|
|
|
struct led_info {
|
|
|
|
const char *name;
|
2008-10-13 09:13:01 +00:00
|
|
|
const char *default_trigger;
|
2008-07-16 21:49:55 +00:00
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct led_platform_data {
|
|
|
|
int num_leds;
|
|
|
|
struct led_info *leds;
|
|
|
|
};
|
|
|
|
|
2019-06-09 18:19:04 +00:00
|
|
|
struct led_properties {
|
|
|
|
u32 color;
|
|
|
|
bool color_present;
|
|
|
|
const char *function;
|
|
|
|
u32 func_enum;
|
|
|
|
bool func_enum_present;
|
|
|
|
const char *label;
|
|
|
|
};
|
|
|
|
|
2016-09-14 18:54:12 +00:00
|
|
|
typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
|
|
|
|
2007-02-27 19:49:53 +00:00
|
|
|
/* For the leds-gpio driver */
|
|
|
|
struct gpio_led {
|
|
|
|
const char *name;
|
2008-10-13 09:13:01 +00:00
|
|
|
const char *default_trigger;
|
2007-02-27 19:49:53 +00:00
|
|
|
unsigned gpio;
|
leds: Add options to have GPIO LEDs start on or keep their state
There already is a "default-on" trigger but there are problems with it.
For one, it's a inefficient way to do it and requires led trigger support
to be compiled in.
But the real reason is that is produces a glitch on the LED. The GPIO is
allocate with the LED *off*, then *later* when the trigger runs it is
turned back on. If the LED was already on via the GPIO's reset default or
action of the firmware, this produces a glitch where the LED goes from on
to off to on. While normally this is fast enough that it wouldn't be
noticeable to a human observer, there are still serious problems.
One is that there may be something else on the GPIO line, like a hardware
alarm or watchdog, that is fast enough to notice the glitch.
Another is that the kernel may panic before the LED is turned back on, thus
hanging with the LED in the wrong state. This is not just speculation, but
actually happened to me with an embedded system that has an LED which
should turn off when the kernel finishes booting, which was left in the
incorrect state due to a bug in the OF LED binding code.
We also let GPIO LEDs get their initial value from whatever the current
state of the GPIO line is. On some systems the LEDs are put into some
state by the firmware or hardware before Linux boots, and it is desired to
have them keep this state which is otherwise unknown to Linux.
This requires that the underlying GPIO driver support reading the value of
output GPIOs. Some drivers support this and some do not.
The platform device binding gains a field in the platform data
"default_state" that controls this. There are three constants defined to
select from on, off, or keeping the current state. The OpenFirmware
binding uses a property named "default-state" that can be set to "on",
"off", or "keep". The default if the property isn't present is off.
Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: Sean MacLennan <smaclennan@pikatech.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
2009-05-12 22:33:12 +00:00
|
|
|
unsigned active_low : 1;
|
|
|
|
unsigned retain_state_suspended : 1;
|
2016-04-28 22:03:40 +00:00
|
|
|
unsigned panic_indicator : 1;
|
leds: Add options to have GPIO LEDs start on or keep their state
There already is a "default-on" trigger but there are problems with it.
For one, it's a inefficient way to do it and requires led trigger support
to be compiled in.
But the real reason is that is produces a glitch on the LED. The GPIO is
allocate with the LED *off*, then *later* when the trigger runs it is
turned back on. If the LED was already on via the GPIO's reset default or
action of the firmware, this produces a glitch where the LED goes from on
to off to on. While normally this is fast enough that it wouldn't be
noticeable to a human observer, there are still serious problems.
One is that there may be something else on the GPIO line, like a hardware
alarm or watchdog, that is fast enough to notice the glitch.
Another is that the kernel may panic before the LED is turned back on, thus
hanging with the LED in the wrong state. This is not just speculation, but
actually happened to me with an embedded system that has an LED which
should turn off when the kernel finishes booting, which was left in the
incorrect state due to a bug in the OF LED binding code.
We also let GPIO LEDs get their initial value from whatever the current
state of the GPIO line is. On some systems the LEDs are put into some
state by the firmware or hardware before Linux boots, and it is desired to
have them keep this state which is otherwise unknown to Linux.
This requires that the underlying GPIO driver support reading the value of
output GPIOs. Some drivers support this and some do not.
The platform device binding gains a field in the platform data
"default_state" that controls this. There are three constants defined to
select from on, off, or keeping the current state. The OpenFirmware
binding uses a property named "default-state" that can be set to "on",
"off", or "keep". The default if the property isn't present is off.
Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: Sean MacLennan <smaclennan@pikatech.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
2009-05-12 22:33:12 +00:00
|
|
|
unsigned default_state : 2;
|
2017-08-28 00:17:11 +00:00
|
|
|
unsigned retain_state_shutdown : 1;
|
leds: Add options to have GPIO LEDs start on or keep their state
There already is a "default-on" trigger but there are problems with it.
For one, it's a inefficient way to do it and requires led trigger support
to be compiled in.
But the real reason is that is produces a glitch on the LED. The GPIO is
allocate with the LED *off*, then *later* when the trigger runs it is
turned back on. If the LED was already on via the GPIO's reset default or
action of the firmware, this produces a glitch where the LED goes from on
to off to on. While normally this is fast enough that it wouldn't be
noticeable to a human observer, there are still serious problems.
One is that there may be something else on the GPIO line, like a hardware
alarm or watchdog, that is fast enough to notice the glitch.
Another is that the kernel may panic before the LED is turned back on, thus
hanging with the LED in the wrong state. This is not just speculation, but
actually happened to me with an embedded system that has an LED which
should turn off when the kernel finishes booting, which was left in the
incorrect state due to a bug in the OF LED binding code.
We also let GPIO LEDs get their initial value from whatever the current
state of the GPIO line is. On some systems the LEDs are put into some
state by the firmware or hardware before Linux boots, and it is desired to
have them keep this state which is otherwise unknown to Linux.
This requires that the underlying GPIO driver support reading the value of
output GPIOs. Some drivers support this and some do not.
The platform device binding gains a field in the platform data
"default_state" that controls this. There are three constants defined to
select from on, off, or keeping the current state. The OpenFirmware
binding uses a property named "default-state" that can be set to "on",
"off", or "keep". The default if the property isn't present is off.
Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Acked-by: Grant Likely <grant.likely@secretlab.ca>
Acked-by: Wolfram Sang <w.sang@pengutronix.de>
Acked-by: Sean MacLennan <smaclennan@pikatech.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
2009-05-12 22:33:12 +00:00
|
|
|
/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
|
2014-10-27 22:29:32 +00:00
|
|
|
struct gpio_desc *gpiod;
|
2007-02-27 19:49:53 +00:00
|
|
|
};
|
2021-06-08 06:35:53 +00:00
|
|
|
#define LEDS_GPIO_DEFSTATE_OFF LEDS_DEFSTATE_OFF
|
|
|
|
#define LEDS_GPIO_DEFSTATE_ON LEDS_DEFSTATE_ON
|
|
|
|
#define LEDS_GPIO_DEFSTATE_KEEP LEDS_DEFSTATE_KEEP
|
2007-02-27 19:49:53 +00:00
|
|
|
|
|
|
|
struct gpio_led_platform_data {
|
|
|
|
int num_leds;
|
2011-03-22 23:30:17 +00:00
|
|
|
const struct gpio_led *leds;
|
2010-05-22 10:54:55 +00:00
|
|
|
|
|
|
|
#define GPIO_LED_NO_BLINK_LOW 0 /* No blink GPIO state low */
|
|
|
|
#define GPIO_LED_NO_BLINK_HIGH 1 /* No blink GPIO state high */
|
2011-03-22 23:30:17 +00:00
|
|
|
#define GPIO_LED_BLINK 2 /* Please, blink */
|
2016-09-14 18:54:12 +00:00
|
|
|
gpio_blink_set_t gpio_blink_set;
|
2007-02-27 19:49:53 +00:00
|
|
|
};
|
|
|
|
|
2016-06-21 12:40:11 +00:00
|
|
|
#ifdef CONFIG_NEW_LEDS
|
2011-05-25 00:13:29 +00:00
|
|
|
struct platform_device *gpio_led_register_device(
|
|
|
|
int id, const struct gpio_led_platform_data *pdata);
|
2016-06-21 12:40:11 +00:00
|
|
|
#else
|
|
|
|
static inline struct platform_device *gpio_led_register_device(
|
|
|
|
int id, const struct gpio_led_platform_data *pdata)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-27 19:49:53 +00:00
|
|
|
|
2011-06-25 10:33:50 +00:00
|
|
|
enum cpu_led_event {
|
|
|
|
CPU_LED_IDLE_START, /* CPU enters idle */
|
|
|
|
CPU_LED_IDLE_END, /* CPU idle ends */
|
|
|
|
CPU_LED_START, /* Machine starts, especially resume */
|
|
|
|
CPU_LED_STOP, /* Machine stops, especially suspend */
|
|
|
|
CPU_LED_HALTED, /* Machine shutdown */
|
|
|
|
};
|
|
|
|
#ifdef CONFIG_LEDS_TRIGGER_CPU
|
2019-10-02 12:40:40 +00:00
|
|
|
void ledtrig_cpu(enum cpu_led_event evt);
|
2011-06-25 10:33:50 +00:00
|
|
|
#else
|
|
|
|
static inline void ledtrig_cpu(enum cpu_led_event evt)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-29 13:42:52 +00:00
|
|
|
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
|
2019-10-02 12:40:40 +00:00
|
|
|
void led_classdev_notify_brightness_hw_changed(
|
2020-12-11 20:42:08 +00:00
|
|
|
struct led_classdev *led_cdev, unsigned int brightness);
|
2017-01-29 13:42:52 +00:00
|
|
|
#else
|
|
|
|
static inline void led_classdev_notify_brightness_hw_changed(
|
|
|
|
struct led_classdev *led_cdev, enum led_brightness brightness) { }
|
|
|
|
#endif
|
|
|
|
|
2018-10-11 04:07:14 +00:00
|
|
|
/**
|
|
|
|
* struct led_pattern - pattern interval settings
|
|
|
|
* @delta_t: pattern interval delay, in milliseconds
|
|
|
|
* @brightness: pattern interval brightness
|
|
|
|
*/
|
|
|
|
struct led_pattern {
|
|
|
|
u32 delta_t;
|
|
|
|
int brightness;
|
|
|
|
};
|
|
|
|
|
2018-11-26 16:47:44 +00:00
|
|
|
enum led_audio {
|
|
|
|
LED_AUDIO_MUTE, /* master mute LED */
|
|
|
|
LED_AUDIO_MICMUTE, /* mic mute LED */
|
|
|
|
NUM_AUDIO_LEDS
|
|
|
|
};
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_LEDS_TRIGGER_AUDIO)
|
|
|
|
enum led_brightness ledtrig_audio_get(enum led_audio type);
|
|
|
|
void ledtrig_audio_set(enum led_audio type, enum led_brightness state);
|
|
|
|
#else
|
|
|
|
static inline enum led_brightness ledtrig_audio_get(enum led_audio type)
|
|
|
|
{
|
|
|
|
return LED_OFF;
|
|
|
|
}
|
|
|
|
static inline void ledtrig_audio_set(enum led_audio type,
|
|
|
|
enum led_brightness state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-03-31 10:31:04 +00:00
|
|
|
#endif /* __LINUX_LEDS_H_INCLUDED */
|