Merge tag 'mfd-next-5.9-1' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
[linux-2.6-microblaze.git] / include / linux / led-class-multicolor.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* LED Multicolor class interface
3  * Copyright (C) 2019-20 Texas Instruments Incorporated - http://www.ti.com/
4  */
5
6 #ifndef _LINUX_MULTICOLOR_LEDS_H_INCLUDED
7 #define _LINUX_MULTICOLOR_LEDS_H_INCLUDED
8
9 #include <linux/leds.h>
10 #include <dt-bindings/leds/common.h>
11
12 struct mc_subled {
13         unsigned int color_index;
14         unsigned int brightness;
15         unsigned int intensity;
16         unsigned int channel;
17 };
18
19 struct led_classdev_mc {
20         /* led class device */
21         struct led_classdev led_cdev;
22         unsigned int num_colors;
23
24         struct mc_subled *subled_info;
25 };
26
27 static inline struct led_classdev_mc *lcdev_to_mccdev(
28                                                 struct led_classdev *led_cdev)
29 {
30         return container_of(led_cdev, struct led_classdev_mc, led_cdev);
31 }
32
33 #if IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR)
34 /**
35  * led_classdev_multicolor_register_ext - register a new object of led_classdev
36  *                                    class with support for multicolor LEDs
37  * @parent: the multicolor LED to register
38  * @mcled_cdev: the led_classdev_mc structure for this device
39  * @init_data: the LED class multicolor device initialization data
40  *
41  * Returns: 0 on success or negative error value on failure
42  */
43 int led_classdev_multicolor_register_ext(struct device *parent,
44                                             struct led_classdev_mc *mcled_cdev,
45                                             struct led_init_data *init_data);
46
47 static inline int led_classdev_multicolor_register(struct device *parent,
48                                             struct led_classdev_mc *mcled_cdev)
49 {
50         return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL);
51 }
52
53 /**
54  * led_classdev_multicolor_unregister - unregisters an object of led_classdev
55  *                                      class with support for multicolor LEDs
56  * @mcled_cdev: the multicolor LED to unregister
57  *
58  * Unregister a previously registered via led_classdev_multicolor_register
59  * object
60  */
61 void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev);
62
63 /* Calculate brightness for the monochrome LED cluster */
64 int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
65                                  enum led_brightness brightness);
66
67 int devm_led_classdev_multicolor_register_ext(struct device *parent,
68                                           struct led_classdev_mc *mcled_cdev,
69                                           struct led_init_data *init_data);
70
71 static inline int devm_led_classdev_multicolor_register(struct device *parent,
72                                      struct led_classdev_mc *mcled_cdev)
73 {
74         return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev,
75                                                          NULL);
76 }
77
78 void devm_led_classdev_multicolor_unregister(struct device *parent,
79                                             struct led_classdev_mc *mcled_cdev);
80 #else
81
82 static inline int led_classdev_multicolor_register_ext(struct device *parent,
83                                             struct led_classdev_mc *mcled_cdev,
84                                             struct led_init_data *init_data)
85 {
86         return -EINVAL;
87 }
88
89 static inline int led_classdev_multicolor_register(struct device *parent,
90                                             struct led_classdev_mc *mcled_cdev)
91 {
92         return led_classdev_multicolor_register_ext(parent, mcled_cdev, NULL);
93 }
94
95 static inline void led_classdev_multicolor_unregister(struct led_classdev_mc *mcled_cdev) {};
96 static inline int led_mc_calc_color_components(struct led_classdev_mc *mcled_cdev,
97                                                enum led_brightness brightness)
98 {
99         return -EINVAL;
100 }
101
102 static inline int devm_led_classdev_multicolor_register_ext(struct device *parent,
103                                           struct led_classdev_mc *mcled_cdev,
104                                           struct led_init_data *init_data)
105 {
106         return -EINVAL;
107 }
108
109 static inline int devm_led_classdev_multicolor_register(struct device *parent,
110                                              struct led_classdev_mc *mcled_cdev)
111 {
112         return devm_led_classdev_multicolor_register_ext(parent, mcled_cdev,
113                                                          NULL);
114 }
115
116 static inline void devm_led_classdev_multicolor_unregister(struct device *parent,
117                                             struct led_classdev_mc *mcled_cdev)
118 {};
119
120 #endif  /* IS_ENABLED(CONFIG_LEDS_CLASS_MULTICOLOR) */
121 #endif  /* _LINUX_MULTICOLOR_LEDS_H_INCLUDED */