mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 20:35:17 +07:00
d2912cb15b
Based on 2 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation # extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 4122 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Enrico Weigelt <info@metux.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
141 lines
3.3 KiB
C
141 lines
3.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* LED Kernel Timer Trigger
|
|
*
|
|
* Copyright 2005-2006 Openedhand Ltd.
|
|
*
|
|
* Author: Richard Purdie <rpurdie@openedhand.com>
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/device.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/leds.h>
|
|
|
|
static ssize_t led_delay_on_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct led_classdev *led_cdev = led_trigger_get_led(dev);
|
|
|
|
return sprintf(buf, "%lu\n", led_cdev->blink_delay_on);
|
|
}
|
|
|
|
static ssize_t led_delay_on_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
|
{
|
|
struct led_classdev *led_cdev = led_trigger_get_led(dev);
|
|
unsigned long state;
|
|
ssize_t ret = -EINVAL;
|
|
|
|
ret = kstrtoul(buf, 10, &state);
|
|
if (ret)
|
|
return ret;
|
|
|
|
led_blink_set(led_cdev, &state, &led_cdev->blink_delay_off);
|
|
led_cdev->blink_delay_on = state;
|
|
|
|
return size;
|
|
}
|
|
|
|
static ssize_t led_delay_off_show(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct led_classdev *led_cdev = led_trigger_get_led(dev);
|
|
|
|
return sprintf(buf, "%lu\n", led_cdev->blink_delay_off);
|
|
}
|
|
|
|
static ssize_t led_delay_off_store(struct device *dev,
|
|
struct device_attribute *attr, const char *buf, size_t size)
|
|
{
|
|
struct led_classdev *led_cdev = led_trigger_get_led(dev);
|
|
unsigned long state;
|
|
ssize_t ret = -EINVAL;
|
|
|
|
ret = kstrtoul(buf, 10, &state);
|
|
if (ret)
|
|
return ret;
|
|
|
|
led_blink_set(led_cdev, &led_cdev->blink_delay_on, &state);
|
|
led_cdev->blink_delay_off = state;
|
|
|
|
return size;
|
|
}
|
|
|
|
static DEVICE_ATTR(delay_on, 0644, led_delay_on_show, led_delay_on_store);
|
|
static DEVICE_ATTR(delay_off, 0644, led_delay_off_show, led_delay_off_store);
|
|
|
|
static struct attribute *timer_trig_attrs[] = {
|
|
&dev_attr_delay_on.attr,
|
|
&dev_attr_delay_off.attr,
|
|
NULL
|
|
};
|
|
ATTRIBUTE_GROUPS(timer_trig);
|
|
|
|
static void pattern_init(struct led_classdev *led_cdev)
|
|
{
|
|
u32 *pattern;
|
|
unsigned int size = 0;
|
|
|
|
pattern = led_get_default_pattern(led_cdev, &size);
|
|
if (!pattern)
|
|
return;
|
|
|
|
if (size != 2) {
|
|
dev_warn(led_cdev->dev,
|
|
"Expected 2 but got %u values for delays pattern\n",
|
|
size);
|
|
goto out;
|
|
}
|
|
|
|
led_cdev->blink_delay_on = pattern[0];
|
|
led_cdev->blink_delay_off = pattern[1];
|
|
/* led_blink_set() called by caller */
|
|
|
|
out:
|
|
kfree(pattern);
|
|
}
|
|
|
|
static int timer_trig_activate(struct led_classdev *led_cdev)
|
|
{
|
|
if (led_cdev->flags & LED_INIT_DEFAULT_TRIGGER) {
|
|
pattern_init(led_cdev);
|
|
/*
|
|
* Mark as initialized even on pattern_init() error because
|
|
* any consecutive call to it would produce the same error.
|
|
*/
|
|
led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER;
|
|
}
|
|
|
|
/*
|
|
* If "set brightness to 0" is pending in workqueue, we don't
|
|
* want that to be reordered after blink_set()
|
|
*/
|
|
flush_work(&led_cdev->set_brightness_work);
|
|
led_blink_set(led_cdev, &led_cdev->blink_delay_on,
|
|
&led_cdev->blink_delay_off);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void timer_trig_deactivate(struct led_classdev *led_cdev)
|
|
{
|
|
/* Stop blinking */
|
|
led_set_brightness(led_cdev, LED_OFF);
|
|
}
|
|
|
|
static struct led_trigger timer_led_trigger = {
|
|
.name = "timer",
|
|
.activate = timer_trig_activate,
|
|
.deactivate = timer_trig_deactivate,
|
|
.groups = timer_trig_groups,
|
|
};
|
|
module_led_trigger(timer_led_trigger);
|
|
|
|
MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
|
|
MODULE_DESCRIPTION("Timer LED trigger");
|
|
MODULE_LICENSE("GPL v2");
|