2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2006-03-31 18:31:04 +08: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
|
|
|
|
|
2015-04-28 15:18:41 +08:00
|
|
|
#include <linux/device.h>
|
2017-01-29 21:42:52 +08:00
|
|
|
#include <linux/kernfs.h>
|
2006-09-29 17:00:14 +08:00
|
|
|
#include <linux/list.h>
|
2014-09-22 23:21:04 +08:00
|
|
|
#include <linux/mutex.h>
|
2007-11-10 21:29:04 +08:00
|
|
|
#include <linux/rwsem.h>
|
2014-08-07 20:10:22 +08: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 17:03:12 +08:00
|
|
|
#include <linux/timer.h>
|
2012-08-15 21:44:34 +08:00
|
|
|
#include <linux/workqueue.h>
|
2006-09-29 17:00:14 +08:00
|
|
|
|
2006-03-31 18:31:04 +08:00
|
|
|
struct device;
|
2018-10-11 12:07:14 +08:00
|
|
|
struct led_pattern;
|
2006-03-31 18:31:04 +08:00
|
|
|
/*
|
|
|
|
* LED Core
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum led_brightness {
|
2006-04-11 13:54:02 +08:00
|
|
|
LED_OFF = 0,
|
2017-01-05 10:34:12 +08:00
|
|
|
LED_ON = 1,
|
2006-04-11 13:54:02 +08:00
|
|
|
LED_HALF = 127,
|
|
|
|
LED_FULL = 255,
|
2006-03-31 18:31:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct led_classdev {
|
2006-04-11 13:54:02 +08:00
|
|
|
const char *name;
|
2014-08-07 20:10:23 +08:00
|
|
|
enum led_brightness brightness;
|
|
|
|
enum led_brightness max_brightness;
|
2006-04-11 13:54:02 +08:00
|
|
|
int flags;
|
2006-03-31 18:31:04 +08:00
|
|
|
|
2009-01-09 01:55:03 +08:00
|
|
|
/* Lower 16 bits reflect status */
|
2017-09-14 01:53:58 +08:00
|
|
|
#define LED_SUSPENDED BIT(0)
|
|
|
|
#define LED_UNREGISTERING BIT(1)
|
2009-01-09 01:55:03 +08:00
|
|
|
/* Upper 16 bits reflect control information */
|
2017-09-14 01:53:58 +08: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 17:29:58 +08:00
|
|
|
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
|
2016-11-08 21:38:46 +08: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
|
2006-03-31 18:31:04 +08:00
|
|
|
|
2016-01-22 06:11:25 +08:00
|
|
|
/* Set LED brightness level
|
|
|
|
* Must not sleep. Use brightness_set_blocking for drivers
|
|
|
|
* that can sleep while setting brightness.
|
|
|
|
*/
|
2006-04-11 13:54:02 +08:00
|
|
|
void (*brightness_set)(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness brightness);
|
2014-11-14 18:50:18 +08:00
|
|
|
/*
|
|
|
|
* Set LED brightness level immediately - it can block the caller for
|
|
|
|
* the time required for accessing a LED device register.
|
|
|
|
*/
|
2015-10-07 17:10:40 +08:00
|
|
|
int (*brightness_set_blocking)(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness brightness);
|
2008-03-18 17:47:48 +08:00
|
|
|
/* Get LED brightness level */
|
|
|
|
enum led_brightness (*brightness_get)(struct led_classdev *led_cdev);
|
2006-04-11 13:54:02 +08:00
|
|
|
|
2010-11-12 06:05:21 +08: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-19 00:22:45 +08:00
|
|
|
* Deactivate blinking again when the brightness is set to LED_OFF
|
|
|
|
* via the brightness_set() callback.
|
2010-11-12 06:05:21 +08:00
|
|
|
*/
|
2007-10-31 22:07:12 +08:00
|
|
|
int (*blink_set)(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
|
|
|
|
2018-10-11 12:07:14 +08: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-09 06:19:31 +08:00
|
|
|
struct device *dev;
|
2014-06-26 01:08:44 +08:00
|
|
|
const struct attribute_group **groups;
|
|
|
|
|
2006-04-11 13:54:02 +08:00
|
|
|
struct list_head node; /* LED Device list */
|
2008-05-31 22:23:19 +08:00
|
|
|
const char *default_trigger; /* Trigger to use */
|
2006-03-31 18:31:04 +08:00
|
|
|
|
2010-11-12 06:05:21 +08: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 17:03:12 +08:00
|
|
|
struct timer_list blink_timer;
|
2010-11-12 06:05:21 +08:00
|
|
|
int blink_brightness;
|
2016-10-24 03:47:26 +08:00
|
|
|
int new_blink_brightness;
|
2015-01-09 23:22:51 +08:00
|
|
|
void (*flash_resume)(struct led_classdev *led_cdev);
|
2010-11-12 06:05:21 +08:00
|
|
|
|
2012-08-15 21:44:34 +08:00
|
|
|
struct work_struct set_brightness_work;
|
|
|
|
int delayed_set_value;
|
|
|
|
|
2006-03-31 18:31:05 +08:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGERS
|
|
|
|
/* Protects the trigger data below */
|
2007-11-10 21:29:04 +08:00
|
|
|
struct rw_semaphore trigger_lock;
|
2006-03-31 18:31:05 +08:00
|
|
|
|
2006-04-11 13:54:02 +08:00
|
|
|
struct led_trigger *trigger;
|
|
|
|
struct list_head trig_list;
|
|
|
|
void *trigger_data;
|
2012-05-30 06:07:27 +08:00
|
|
|
/* true if activated - deactivate routine uses it to do cleanup */
|
|
|
|
bool activated;
|
2006-03-31 18:31:05 +08:00
|
|
|
#endif
|
2014-09-22 23:21:04 +08:00
|
|
|
|
2017-01-29 21:42:52 +08:00
|
|
|
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
|
|
|
|
int brightness_hw_changed;
|
|
|
|
struct kernfs_node *brightness_hw_changed_kn;
|
|
|
|
#endif
|
|
|
|
|
2014-09-22 23:21:04 +08:00
|
|
|
/* Ensures consistent access to the LED Flash Class device */
|
|
|
|
struct mutex led_access;
|
2006-03-31 18:31:04 +08:00
|
|
|
};
|
|
|
|
|
2017-03-06 13:19:44 +08:00
|
|
|
extern int of_led_classdev_register(struct device *parent,
|
|
|
|
struct device_node *np,
|
|
|
|
struct led_classdev *led_cdev);
|
|
|
|
#define led_classdev_register(parent, led_cdev) \
|
|
|
|
of_led_classdev_register(parent, NULL, led_cdev)
|
|
|
|
extern int devm_of_led_classdev_register(struct device *parent,
|
|
|
|
struct device_node *np,
|
|
|
|
struct led_classdev *led_cdev);
|
|
|
|
#define devm_led_classdev_register(parent, led_cdev) \
|
|
|
|
devm_of_led_classdev_register(parent, NULL, led_cdev)
|
2008-11-17 22:35:44 +08:00
|
|
|
extern void led_classdev_unregister(struct led_classdev *led_cdev);
|
2015-02-24 08:11:41 +08:00
|
|
|
extern void devm_led_classdev_unregister(struct device *parent,
|
|
|
|
struct led_classdev *led_cdev);
|
2006-03-31 18:31:04 +08:00
|
|
|
extern void led_classdev_suspend(struct led_classdev *led_cdev);
|
|
|
|
extern void led_classdev_resume(struct led_classdev *led_cdev);
|
|
|
|
|
2010-11-12 06:05:21 +08: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.
|
|
|
|
*
|
|
|
|
* Note that if software blinking is active, simply calling
|
|
|
|
* led_cdev->brightness_set() will not stop the blinking,
|
|
|
|
* use led_classdev_brightness_set() instead.
|
|
|
|
*/
|
|
|
|
extern void led_blink_set(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
2012-05-27 07:19:22 +08: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.
|
|
|
|
*/
|
|
|
|
extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off,
|
|
|
|
int invert);
|
2010-11-12 06:05:21 +08:00
|
|
|
/**
|
2012-06-14 04:34:30 +08:00
|
|
|
* led_set_brightness - set LED brightness
|
2010-11-12 06:05:21 +08: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 15:04:01 +08:00
|
|
|
* hardware doesn't. This function is guaranteed not to sleep.
|
2010-11-12 06:05:21 +08:00
|
|
|
*/
|
2012-06-14 04:34:30 +08:00
|
|
|
extern void led_set_brightness(struct led_classdev *led_cdev,
|
2010-11-12 06:05:21 +08:00
|
|
|
enum led_brightness brightness);
|
2015-10-07 17:10:43 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* led_set_brightness_sync - set LED brightness synchronously
|
|
|
|
* @led_cdev: the LED to set
|
|
|
|
* @brightness: the brightness to set it to
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
extern int led_set_brightness_sync(struct led_classdev *led_cdev,
|
|
|
|
enum led_brightness value);
|
|
|
|
|
2014-08-20 21:41:55 +08: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
|
|
|
|
*/
|
|
|
|
extern int led_update_brightness(struct led_classdev *led_cdev);
|
2010-11-12 06:05:21 +08:00
|
|
|
|
2019-01-09 22:44:46 +08: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().
|
|
|
|
*/
|
|
|
|
extern u32 *led_get_default_pattern(struct led_classdev *led_cdev,
|
|
|
|
unsigned int *size);
|
|
|
|
|
2014-09-22 23:21:04 +08:00
|
|
|
/**
|
|
|
|
* led_sysfs_disable - disable LED sysfs interface
|
|
|
|
* @led_cdev: the LED to set
|
|
|
|
*
|
|
|
|
* Disable the led_cdev's sysfs interface.
|
|
|
|
*/
|
|
|
|
extern void led_sysfs_disable(struct led_classdev *led_cdev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* led_sysfs_enable - enable LED sysfs interface
|
|
|
|
* @led_cdev: the LED to set
|
|
|
|
*
|
|
|
|
* Enable the led_cdev's sysfs interface.
|
|
|
|
*/
|
|
|
|
extern void led_sysfs_enable(struct led_classdev *led_cdev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 18:31:05 +08:00
|
|
|
/*
|
|
|
|
* LED Triggers
|
|
|
|
*/
|
2013-03-14 19:29:19 +08: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 18:31:05 +08:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGERS
|
|
|
|
|
|
|
|
#define TRIG_NAME_MAX 50
|
|
|
|
|
|
|
|
struct led_trigger {
|
|
|
|
/* Trigger Properties */
|
2006-04-11 13:54:02 +08:00
|
|
|
const char *name;
|
2018-07-03 04:05:21 +08:00
|
|
|
int (*activate)(struct led_classdev *led_cdev);
|
2006-04-11 13:54:02 +08:00
|
|
|
void (*deactivate)(struct led_classdev *led_cdev);
|
2006-03-31 18:31:05 +08:00
|
|
|
|
|
|
|
/* LEDs under control by this trigger (for simple triggers) */
|
2006-04-11 13:54:02 +08:00
|
|
|
rwlock_t leddev_list_lock;
|
|
|
|
struct list_head led_cdevs;
|
2006-03-31 18:31:05 +08:00
|
|
|
|
|
|
|
/* Link to next registered trigger */
|
2006-04-11 13:54:02 +08:00
|
|
|
struct list_head next_trig;
|
2018-07-03 04:05:22 +08:00
|
|
|
|
|
|
|
const struct attribute_group **groups;
|
2006-03-31 18:31:05 +08:00
|
|
|
};
|
|
|
|
|
2018-07-03 04:05:22 +08: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)))
|
|
|
|
|
2015-04-28 15:18:41 +08:00
|
|
|
ssize_t led_trigger_store(struct device *dev, struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count);
|
|
|
|
ssize_t led_trigger_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf);
|
|
|
|
|
2006-03-31 18:31:05 +08:00
|
|
|
/* Registration functions for complex triggers */
|
|
|
|
extern int led_trigger_register(struct led_trigger *trigger);
|
|
|
|
extern void led_trigger_unregister(struct led_trigger *trigger);
|
2016-01-02 08:36:41 +08:00
|
|
|
extern int devm_led_trigger_register(struct device *dev,
|
|
|
|
struct led_trigger *trigger);
|
2006-03-31 18:31:05 +08:00
|
|
|
|
|
|
|
extern void led_trigger_register_simple(const char *name,
|
|
|
|
struct led_trigger **trigger);
|
|
|
|
extern void led_trigger_unregister_simple(struct led_trigger *trigger);
|
|
|
|
extern void led_trigger_event(struct led_trigger *trigger,
|
|
|
|
enum led_brightness event);
|
2011-01-08 00:28:16 +08:00
|
|
|
extern void led_trigger_blink(struct led_trigger *trigger,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
2012-05-27 07:19:22 +08:00
|
|
|
extern void led_trigger_blink_oneshot(struct led_trigger *trigger,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off,
|
|
|
|
int invert);
|
2015-04-28 15:18:41 +08:00
|
|
|
extern void led_trigger_set_default(struct led_classdev *led_cdev);
|
2018-07-03 04:05:21 +08:00
|
|
|
extern int led_trigger_set(struct led_classdev *led_cdev,
|
|
|
|
struct led_trigger *trigger);
|
2015-04-28 15:18:41 +08:00
|
|
|
extern void led_trigger_remove(struct led_classdev *led_cdev);
|
|
|
|
|
2018-07-03 04:05:25 +08: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 15:18:41 +08:00
|
|
|
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return led_cdev->trigger_data;
|
|
|
|
}
|
|
|
|
|
2012-11-19 13:35:55 +08: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.
|
|
|
|
*/
|
|
|
|
extern void led_trigger_rename_static(const char *name,
|
|
|
|
struct led_trigger *trig);
|
2006-03-31 18:31:05 +08:00
|
|
|
|
2018-07-03 04:05:24 +08:00
|
|
|
#define module_led_trigger(__led_trigger) \
|
|
|
|
module_driver(__led_trigger, led_trigger_register, \
|
|
|
|
led_trigger_unregister)
|
|
|
|
|
2006-03-31 18:31:05 +08:00
|
|
|
#else
|
|
|
|
|
2013-03-14 19:29:19 +08:00
|
|
|
/* Trigger has no members */
|
|
|
|
struct led_trigger {};
|
2006-03-31 18:31:05 +08:00
|
|
|
|
2013-03-14 19:29:19 +08: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-18 06:12:50 +08:00
|
|
|
static inline void led_trigger_blink(struct led_trigger *trigger,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off) {}
|
|
|
|
static inline void led_trigger_blink_oneshot(struct led_trigger *trigger,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off,
|
|
|
|
int invert) {}
|
2015-04-28 15:18:41 +08:00
|
|
|
static inline void led_trigger_set_default(struct led_classdev *led_cdev) {}
|
2018-07-03 04:05:21 +08:00
|
|
|
static inline int led_trigger_set(struct led_classdev *led_cdev,
|
|
|
|
struct led_trigger *trigger)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 15:18:41 +08:00
|
|
|
static inline void led_trigger_remove(struct led_classdev *led_cdev) {}
|
2018-07-03 04:05:25 +08:00
|
|
|
static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}
|
2015-04-28 15:18:41 +08:00
|
|
|
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-14 19:29:19 +08:00
|
|
|
#endif /* CONFIG_LEDS_TRIGGERS */
|
2006-03-31 18:31:16 +08:00
|
|
|
|
|
|
|
/* Trigger specific functions */
|
2016-06-10 13:59:56 +08:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGER_DISK
|
2018-02-25 06:45:56 +08:00
|
|
|
extern void ledtrig_disk_activity(bool write);
|
2006-03-31 18:31:16 +08:00
|
|
|
#else
|
2018-02-25 06:45:56 +08:00
|
|
|
static inline void ledtrig_disk_activity(bool write) {}
|
2006-03-31 18:31:16 +08:00
|
|
|
#endif
|
|
|
|
|
2016-04-13 04:46:40 +08:00
|
|
|
#ifdef CONFIG_LEDS_TRIGGER_MTD
|
|
|
|
extern void ledtrig_mtd_activity(void);
|
|
|
|
#else
|
|
|
|
static inline void ledtrig_mtd_activity(void) {}
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 19:29:24 +08:00
|
|
|
#if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
|
|
|
|
extern void ledtrig_flash_ctrl(bool on);
|
|
|
|
extern void ledtrig_torch_ctrl(bool on);
|
|
|
|
#else
|
|
|
|
static inline void ledtrig_flash_ctrl(bool on) {}
|
|
|
|
static inline void ledtrig_torch_ctrl(bool on) {}
|
|
|
|
#endif
|
|
|
|
|
2008-07-17 05:49:55 +08:00
|
|
|
/*
|
|
|
|
* Generic LED platform data for describing LED names and default triggers.
|
|
|
|
*/
|
|
|
|
struct led_info {
|
|
|
|
const char *name;
|
2008-10-13 17:13:01 +08:00
|
|
|
const char *default_trigger;
|
2008-07-17 05:49:55 +08:00
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct led_platform_data {
|
|
|
|
int num_leds;
|
|
|
|
struct led_info *leds;
|
|
|
|
};
|
|
|
|
|
2016-09-15 02:54:12 +08:00
|
|
|
struct gpio_desc;
|
|
|
|
typedef int (*gpio_blink_set_t)(struct gpio_desc *desc, int state,
|
|
|
|
unsigned long *delay_on,
|
|
|
|
unsigned long *delay_off);
|
|
|
|
|
2007-02-28 03:49:53 +08:00
|
|
|
/* For the leds-gpio driver */
|
|
|
|
struct gpio_led {
|
|
|
|
const char *name;
|
2008-10-13 17:13:01 +08:00
|
|
|
const char *default_trigger;
|
2007-02-28 03:49:53 +08: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-13 06:33:12 +08:00
|
|
|
unsigned active_low : 1;
|
|
|
|
unsigned retain_state_suspended : 1;
|
2016-04-29 06:03:40 +08: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-13 06:33:12 +08:00
|
|
|
unsigned default_state : 2;
|
2017-08-28 08:17:11 +08: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-13 06:33:12 +08:00
|
|
|
/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
|
2014-10-28 06:29:32 +08:00
|
|
|
struct gpio_desc *gpiod;
|
2007-02-28 03:49:53 +08:00
|
|
|
};
|
2010-05-22 18:54:55 +08:00
|
|
|
#define LEDS_GPIO_DEFSTATE_OFF 0
|
|
|
|
#define LEDS_GPIO_DEFSTATE_ON 1
|
|
|
|
#define LEDS_GPIO_DEFSTATE_KEEP 2
|
2007-02-28 03:49:53 +08:00
|
|
|
|
|
|
|
struct gpio_led_platform_data {
|
|
|
|
int num_leds;
|
2011-03-23 07:30:17 +08:00
|
|
|
const struct gpio_led *leds;
|
2010-05-22 18:54:55 +08: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-23 07:30:17 +08:00
|
|
|
#define GPIO_LED_BLINK 2 /* Please, blink */
|
2016-09-15 02:54:12 +08:00
|
|
|
gpio_blink_set_t gpio_blink_set;
|
2007-02-28 03:49:53 +08:00
|
|
|
};
|
|
|
|
|
2016-06-21 20:40:11 +08:00
|
|
|
#ifdef CONFIG_NEW_LEDS
|
2011-05-25 08:13:29 +08:00
|
|
|
struct platform_device *gpio_led_register_device(
|
|
|
|
int id, const struct gpio_led_platform_data *pdata);
|
2016-06-21 20:40:11 +08: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-28 03:49:53 +08:00
|
|
|
|
2011-06-25 18:33:50 +08: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
|
|
|
|
extern void ledtrig_cpu(enum cpu_led_event evt);
|
|
|
|
#else
|
|
|
|
static inline void ledtrig_cpu(enum cpu_led_event evt)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-29 21:42:52 +08:00
|
|
|
#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
|
|
|
|
extern void led_classdev_notify_brightness_hw_changed(
|
|
|
|
struct led_classdev *led_cdev, enum led_brightness brightness);
|
|
|
|
#else
|
|
|
|
static inline void led_classdev_notify_brightness_hw_changed(
|
|
|
|
struct led_classdev *led_cdev, enum led_brightness brightness) { }
|
|
|
|
#endif
|
|
|
|
|
2018-10-11 12:07:14 +08: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-27 00:47:44 +08: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 18:31:04 +08:00
|
|
|
#endif /* __LINUX_LEDS_H_INCLUDED */
|