0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __LINUX_FLASH_LEDS_H_INCLUDED
0009 #define __LINUX_FLASH_LEDS_H_INCLUDED
0010
0011 #include <linux/leds.h>
0012
0013 struct device_node;
0014 struct led_classdev_flash;
0015
0016
0017
0018
0019
0020 #define LED_FAULT_OVER_VOLTAGE (1 << 0)
0021 #define LED_FAULT_TIMEOUT (1 << 1)
0022 #define LED_FAULT_OVER_TEMPERATURE (1 << 2)
0023 #define LED_FAULT_SHORT_CIRCUIT (1 << 3)
0024 #define LED_FAULT_OVER_CURRENT (1 << 4)
0025 #define LED_FAULT_INDICATOR (1 << 5)
0026 #define LED_FAULT_UNDER_VOLTAGE (1 << 6)
0027 #define LED_FAULT_INPUT_VOLTAGE (1 << 7)
0028 #define LED_FAULT_LED_OVER_TEMPERATURE (1 << 8)
0029 #define LED_NUM_FLASH_FAULTS 9
0030
0031 #define LED_FLASH_SYSFS_GROUPS_SIZE 5
0032
0033 struct led_flash_ops {
0034
0035 int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
0036 u32 brightness);
0037
0038 int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
0039 u32 *brightness);
0040
0041 int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
0042
0043 int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
0044
0045 int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
0046
0047 int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
0048 };
0049
0050
0051
0052
0053
0054 struct led_flash_setting {
0055
0056 u32 min;
0057
0058 u32 max;
0059
0060 u32 step;
0061
0062 u32 val;
0063 };
0064
0065 struct led_classdev_flash {
0066
0067 struct led_classdev led_cdev;
0068
0069
0070 const struct led_flash_ops *ops;
0071
0072
0073 struct led_flash_setting brightness;
0074
0075
0076 struct led_flash_setting timeout;
0077
0078
0079 const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE];
0080 };
0081
0082 static inline struct led_classdev_flash *lcdev_to_flcdev(
0083 struct led_classdev *lcdev)
0084 {
0085 return container_of(lcdev, struct led_classdev_flash, led_cdev);
0086 }
0087
0088 #if IS_ENABLED(CONFIG_LEDS_CLASS_FLASH)
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098 int led_classdev_flash_register_ext(struct device *parent,
0099 struct led_classdev_flash *fled_cdev,
0100 struct led_init_data *init_data);
0101
0102
0103
0104
0105
0106
0107
0108
0109 void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
0110
0111 int devm_led_classdev_flash_register_ext(struct device *parent,
0112 struct led_classdev_flash *fled_cdev,
0113 struct led_init_data *init_data);
0114
0115
0116 void devm_led_classdev_flash_unregister(struct device *parent,
0117 struct led_classdev_flash *fled_cdev);
0118
0119 #else
0120
0121 static inline int led_classdev_flash_register_ext(struct device *parent,
0122 struct led_classdev_flash *fled_cdev,
0123 struct led_init_data *init_data)
0124 {
0125 return 0;
0126 }
0127
0128 static inline void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev) {};
0129 static inline int devm_led_classdev_flash_register_ext(struct device *parent,
0130 struct led_classdev_flash *fled_cdev,
0131 struct led_init_data *init_data)
0132 {
0133 return 0;
0134 }
0135
0136 static inline void devm_led_classdev_flash_unregister(struct device *parent,
0137 struct led_classdev_flash *fled_cdev)
0138 {};
0139
0140 #endif
0141
0142 static inline int led_classdev_flash_register(struct device *parent,
0143 struct led_classdev_flash *fled_cdev)
0144 {
0145 return led_classdev_flash_register_ext(parent, fled_cdev, NULL);
0146 }
0147
0148 static inline int devm_led_classdev_flash_register(struct device *parent,
0149 struct led_classdev_flash *fled_cdev)
0150 {
0151 return devm_led_classdev_flash_register_ext(parent, fled_cdev, NULL);
0152 }
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163 static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
0164 bool state)
0165 {
0166 if (!fled_cdev)
0167 return -EINVAL;
0168 return fled_cdev->ops->strobe_set(fled_cdev, state);
0169 }
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
0181 bool *state)
0182 {
0183 if (!fled_cdev)
0184 return -EINVAL;
0185 if (fled_cdev->ops->strobe_get)
0186 return fled_cdev->ops->strobe_get(fled_cdev, state);
0187
0188 return -EINVAL;
0189 }
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200 int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
0201 u32 brightness);
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout);
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234 int led_get_flash_fault(struct led_classdev_flash *fled_cdev, u32 *fault);
0235
0236 #endif