// SPDX-License-Identifier: GPL-2.0-only /* * ledtrig-cpu.c - LED trigger based on CPU activity * * This LED trigger will be registered for first 8 CPUs and named * as cpu0..cpu7. There's additional trigger called cpu that * is on when any CPU is active. * * If you want support for arbitrary number of CPUs, make it one trigger, * with additional sysfs file selecting which CPU to watch. * * It can be bound to any LED just like other triggers using either a * board file or via sysfs interface. * * An API named ledtrig_cpu is exported for any user, who want to add CPU * activity indication in their code. * * Copyright 2011 Linus Walleij <[email protected]> * Copyright 2011 - 2012 Bryan Wu <[email protected]> */ #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/percpu.h> #include <linux/syscore_ops.h> #include <linux/rwsem.h> #include <linux/cpu.h> #include "../leds.h" #define MAX_NAME_LEN … struct led_trigger_cpu { … }; static DEFINE_PER_CPU(struct led_trigger_cpu, cpu_trig); static struct led_trigger *trig_cpu_all; static atomic_t num_active_cpus = …; /** * ledtrig_cpu - emit a CPU event as a trigger * @ledevt: CPU event to be emitted * * Emit a CPU event on a CPU core, which will trigger a * bound LED to turn on or turn off. */ void ledtrig_cpu(enum cpu_led_event ledevt) { … } EXPORT_SYMBOL(…); static int ledtrig_cpu_syscore_suspend(void) { … } static void ledtrig_cpu_syscore_resume(void) { … } static void ledtrig_cpu_syscore_shutdown(void) { … } static struct syscore_ops ledtrig_cpu_syscore_ops = …; static int ledtrig_online_cpu(unsigned int cpu) { … } static int ledtrig_prepare_down_cpu(unsigned int cpu) { … } static int __init ledtrig_cpu_init(void) { … } device_initcall(ledtrig_cpu_init);