linux/include/linux/leds.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Driver model for leds and led triggers
 *
 * Copyright (C) 2005 John Lenz <[email protected]>
 * Copyright (C) 2005 Richard Purdie <[email protected]>
 */
#ifndef __LINUX_LEDS_H_INCLUDED
#define __LINUX_LEDS_H_INCLUDED

#include <dt-bindings/leds/common.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/rwsem.h>
#include <linux/spinlock.h>
#include <linux/timer.h>
#include <linux/types.h>
#include <linux/workqueue.h>

struct attribute_group;
struct device_node;
struct fwnode_handle;
struct gpio_desc;
struct kernfs_node;
struct led_pattern;
struct platform_device;

/*
 * LED Core
 */

/* This is obsolete/useless. We now support variable maximum brightness. */
enum led_brightness {};

enum led_default_state {};

/**
 * 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 led_init_data {};

enum led_default_state led_init_default_state_get(struct fwnode_handle *fwnode);

struct led_hw_trigger_type {};

struct led_classdev {};

/**
 * 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
 *
 * Register a new object of LED class, with name derived from init_data.
 *
 * Returns: 0 on success or negative error value on failure
 */
int led_classdev_register_ext(struct device *parent,
				     struct led_classdev *led_cdev,
				     struct led_init_data *init_data);

/**
 * 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)
{}

int devm_led_classdev_register_ext(struct device *parent,
					  struct led_classdev *led_cdev,
					  struct led_init_data *init_data);
static inline int devm_led_classdev_register(struct device *parent,
					     struct led_classdev *led_cdev)
{}
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);

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);

extern struct led_classdev *of_led_get(struct device_node *np, int index);
extern void led_put(struct led_classdev *led_cdev);
struct led_classdev *__must_check devm_of_led_get(struct device *dev,
						  int index);
struct led_classdev *__must_check devm_of_led_get_optional(struct device *dev,
						  int index);

/**
 * 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.
 *
 * This function may sleep!
 *
 * Note that if software blinking is active, simply calling
 * led_cdev->brightness_set() will not stop the blinking,
 * use led_set_brightness() instead.
 */
void led_blink_set(struct led_classdev *led_cdev, unsigned long *delay_on,
		   unsigned long *delay_off);

/**
 * 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);

/**
 * 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.
 *
 * This function is guaranteed not to sleep.
 */
void led_blink_set_oneshot(struct led_classdev *led_cdev,
			   unsigned long *delay_on, unsigned long *delay_off,
			   int invert);
/**
 * led_set_brightness - set LED brightness
 * @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
 * hardware doesn't. This function is guaranteed not to sleep.
 */
void led_set_brightness(struct led_classdev *led_cdev, unsigned int brightness);

/**
 * led_set_brightness_sync - set LED brightness synchronously
 * @led_cdev: the LED to set
 * @value: 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
 */
int led_set_brightness_sync(struct led_classdev *led_cdev, unsigned int value);

/**
 * led_mc_set_brightness - set mc LED color intensity values and brightness
 * @led_cdev: the LED to set
 * @intensity_value: array of per color intensity values to set
 * @num_colors: amount of entries in intensity_value array
 * @brightness: the brightness to set the LED to
 *
 * Set a multi-color LED's per color intensity values and brightness.
 * If necessary, this cancels the software blink timer. This function is
 * guaranteed not to sleep.
 *
 * Calling this function on a non multi-color led_classdev or with the wrong
 * num_colors value is an error. In this case an error will be logged once
 * and the call will do nothing.
 */
void led_mc_set_brightness(struct led_classdev *led_cdev,
			   unsigned int *intensity_value, unsigned int num_colors,
			   unsigned int brightness);

/**
 * 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
 */
int led_update_brightness(struct led_classdev *led_cdev);

/**
 * 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().
 */
u32 *led_get_default_pattern(struct led_classdev *led_cdev, unsigned int *size);

/**
 * led_sysfs_disable - disable LED sysfs interface
 * @led_cdev: the LED to set
 *
 * Disable the led_cdev's sysfs interface.
 */
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.
 */
void led_sysfs_enable(struct led_classdev *led_cdev);

/**
 * led_compose_name - compose LED class device name
 * @dev: LED controller device object
 * @init_data: the LED class device initialization data
 * @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
 */
int led_compose_name(struct device *dev, struct led_init_data *init_data,
		     char *led_classdev_name);

/**
 * led_get_color_name - get string representation of color ID
 * @color_id: The LED_COLOR_ID_* constant
 *
 * Get the string name of a LED_COLOR_ID_* constant.
 *
 * Returns: A string constant or NULL on an invalid ID.
 */
const char *led_get_color_name(u8 color_id);

/**
 * 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)
{}

/*
 * LED Triggers
 */
/* Registration functions for simple triggers */
#define DEFINE_LED_TRIGGER(x)
#define DEFINE_LED_TRIGGER_GLOBAL(x)

#ifdef CONFIG_LEDS_TRIGGERS

#define TRIG_NAME_MAX

struct led_trigger {};

/*
 * 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)
#define led_trigger_get_drvdata(dev)

/* Registration functions for complex triggers */
int led_trigger_register(struct led_trigger *trigger);
void led_trigger_unregister(struct led_trigger *trigger);
int devm_led_trigger_register(struct device *dev,
				     struct led_trigger *trigger);

void led_trigger_register_simple(const char *name,
				struct led_trigger **trigger);
void led_trigger_unregister_simple(struct led_trigger *trigger);
void led_trigger_event(struct led_trigger *trigger,  enum led_brightness event);
void led_mc_trigger_event(struct led_trigger *trig,
			  unsigned int *intensity_value, unsigned int num_colors,
			  enum led_brightness brightness);
void led_trigger_blink(struct led_trigger *trigger, unsigned long delay_on,
		       unsigned long delay_off);
void led_trigger_blink_oneshot(struct led_trigger *trigger,
			       unsigned long delay_on,
			       unsigned long delay_off,
			       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);

static inline void led_set_trigger_data(struct led_classdev *led_cdev,
					void *trigger_data)
{}

static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
{}

static inline enum led_brightness
led_trigger_get_brightness(const struct led_trigger *trigger)
{}

#define module_led_trigger(__led_trigger)

#else

/* Trigger has no members */
struct led_trigger {};

/* 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) {}
static inline void led_mc_trigger_event(struct led_trigger *trig,
				unsigned int *intensity_value, unsigned int num_colors,
				enum led_brightness brightness) {}
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) {}
static inline void led_trigger_set_default(struct led_classdev *led_cdev) {}
static inline int led_trigger_set(struct led_classdev *led_cdev,
				  struct led_trigger *trigger)
{
	return 0;
}

static inline void led_trigger_remove(struct led_classdev *led_cdev) {}
static inline void led_set_trigger_data(struct led_classdev *led_cdev) {}
static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
{
	return NULL;
}

static inline enum led_brightness
led_trigger_get_brightness(const struct led_trigger *trigger)
{
	return LED_OFF;
}

#endif /* CONFIG_LEDS_TRIGGERS */

/* Trigger specific enum */
enum led_trigger_netdev_modes {};

/* Trigger specific functions */
#ifdef CONFIG_LEDS_TRIGGER_DISK
void ledtrig_disk_activity(bool write);
#else
static inline void ledtrig_disk_activity(bool write) {}
#endif

#ifdef CONFIG_LEDS_TRIGGER_MTD
void ledtrig_mtd_activity(void);
#else
static inline void ledtrig_mtd_activity(void) {}
#endif

#if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
void ledtrig_flash_ctrl(bool on);
void ledtrig_torch_ctrl(bool on);
#else
static inline void ledtrig_flash_ctrl(bool on) {}
static inline void ledtrig_torch_ctrl(bool on) {}
#endif

/*
 * Generic LED platform data for describing LED names and default triggers.
 */
struct led_info {};

struct led_platform_data {};

struct led_properties {};

gpio_blink_set_t;

/* For the leds-gpio driver */
struct gpio_led {};
#define LEDS_GPIO_DEFSTATE_OFF
#define LEDS_GPIO_DEFSTATE_ON
#define LEDS_GPIO_DEFSTATE_KEEP

struct gpio_led_platform_data {};

#ifdef CONFIG_LEDS_GPIO_REGISTER
struct platform_device *gpio_led_register_device(
		int id, const struct gpio_led_platform_data *pdata);
#else
static inline struct platform_device *gpio_led_register_device(
		int id, const struct gpio_led_platform_data *pdata)
{}
#endif

enum cpu_led_event {};
#ifdef CONFIG_LEDS_TRIGGER_CPU
void ledtrig_cpu(enum cpu_led_event evt);
#else
static inline void ledtrig_cpu(enum cpu_led_event evt)
{
	return;
}
#endif

#ifdef CONFIG_LEDS_BRIGHTNESS_HW_CHANGED
void led_classdev_notify_brightness_hw_changed(
	struct led_classdev *led_cdev, unsigned int brightness);
#else
static inline void led_classdev_notify_brightness_hw_changed(
	struct led_classdev *led_cdev, enum led_brightness brightness) { }
#endif

/**
 * struct led_pattern - pattern interval settings
 * @delta_t: pattern interval delay, in milliseconds
 * @brightness: pattern interval brightness
 */
struct led_pattern {};

enum led_audio {};

#endif		/* __LINUX_LEDS_H_INCLUDED */