Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* LED Multicolor class interface
0003  * Copyright (C) 2019-20 Texas Instruments Incorporated - http://www.ti.com/
0004  */
0005 
0006 #ifndef _LINUX_MULTICOLOR_LEDS_H_INCLUDED
0007 #define _LINUX_MULTICOLOR_LEDS_H_INCLUDED
0008 
0009 #include <linux/leds.h>
0010 #include <dt-bindings/leds/common.h>
0011 
0012 struct mc_subled {
0013     unsigned int color_index;
0014     unsigned int brightness;
0015     unsigned int intensity;
0016     unsigned int channel;
0017 };
0018 
0019 struct led_classdev_mc {
0020     /* led class device */
0021     struct led_classdev led_cdev;
0022     unsigned int num_colors;
0023 
0024     struct mc_subled *subled_info;
0025 };
0026 
0027 static inline struct led_classdev_mc *lcdev_to_mccdev(
0028                         struct led_classdev *led_cdev)
0029 {
0030     return container_of(led_cdev, struct led_classdev_mc, led_cdev);
0031 }
0032 
0033 #if IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR)
0034 /**
0035  * led_classdev_multicolor_register_ext - register a new object of led_classdev
0036  *                    class with support for multicolor LEDs
0037  * @parent: the multicolor LED to register
0038  * @mcled_cdev: the led_classdev_mc structure for this device
0039  * @init_data: the LED class multicolor device initialization data
0040  *
0041  * Returns: 0 on success or negative error value on failure
0042  */
0043 int led_classdev_multicolor_register_ext(struct device *parent,
0044                         struct led_classdev_mc *mcled_cdev,
0045                         struct led_init_data *init_data);
0046 
0047 /**
0048  * led_classdev_multicolor_unregister - unregisters an object of led_classdev
0049  *                  class with support for multicolor LEDs
0050  * @mcled_cdev: the multicolor LED to unregister
0051  *
0052  * Unregister a previously registered via led_classdev_multicolor_register
0053  * object
0054  */
0055 void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev);
0056 
0057 /* Calculate brightness for the monochrome LED cluster */
0058 int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
0059                  enum led_brightness brightness);
0060 
0061 int devm_led_classdev_multicolor_register_ext(struct device *parent,
0062                       struct led_classdev_mc *mcled_cdev,
0063                       struct led_init_data *init_data);
0064 
0065 void devm_led_classdev_multicolor_unregister(struct device *parent,
0066                         struct led_classdev_mc *mcled_cdev);
0067 #else
0068 
0069 static inline int led_classdev_multicolor_register_ext(struct device *parent,
0070                         struct led_classdev_mc *mcled_cdev,
0071                         struct led_init_data *init_data)
0072 {
0073     return 0;
0074 }
0075 
0076 static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {};
0077 static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
0078                            enum led_brightness brightness)
0079 {
0080     return 0;
0081 }
0082 
0083 static inline int devm_led_classdev_multicolor_register_ext(struct device *parent,
0084                       struct led_classdev_mc *mcled_cdev,
0085                       struct led_init_data *init_data)
0086 {
0087     return 0;
0088 }
0089 
0090 static inline void devm_led_classdev_multicolor_unregister(struct device *parent,
0091                         struct led_classdev_mc *mcled_cdev)
0092 {};
0093 
0094 #endif  /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */
0095 
0096 static inline int led_classdev_multicolor_register(struct device *parent,
0097                         struct led_classdev_mc *mcled_cdev)
0098 {
0099     return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL);
0100 }
0101 
0102 static inline int devm_led_classdev_multicolor_register(struct device *parent,
0103                          struct led_classdev_mc *mcled_cdev)
0104 {
0105     return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev,
0106                              NULL);
0107 }
0108 
0109 #endif  /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */