Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * LED Flash class interface
0004  *
0005  * Copyright (C) 2015 Samsung Electronics Co., Ltd.
0006  * Author: Jacek Anaszewski <j.anaszewski@samsung.com>
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  * Supported led fault bits - must be kept in synch
0018  * with V4L2_FLASH_FAULT bits.
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     /* set flash brightness */
0035     int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
0036                     u32 brightness);
0037     /* get flash brightness */
0038     int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
0039                     u32 *brightness);
0040     /* set flash strobe state */
0041     int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
0042     /* get flash strobe state */
0043     int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
0044     /* set flash timeout */
0045     int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
0046     /* get the flash LED fault */
0047     int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
0048 };
0049 
0050 /*
0051  * Current value of a flash setting along
0052  * with its constraints.
0053  */
0054 struct led_flash_setting {
0055     /* maximum allowed value */
0056     u32 min;
0057     /* maximum allowed value */
0058     u32 max;
0059     /* step value */
0060     u32 step;
0061     /* current value */
0062     u32 val;
0063 };
0064 
0065 struct led_classdev_flash {
0066     /* led class device */
0067     struct led_classdev led_cdev;
0068 
0069     /* flash led specific ops */
0070     const struct led_flash_ops *ops;
0071 
0072     /* flash brightness value in microamperes along with its constraints */
0073     struct led_flash_setting brightness;
0074 
0075     /* flash timeout value in microseconds along with its constraints */
0076     struct led_flash_setting timeout;
0077 
0078     /* LED Flash class sysfs groups */
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  * led_classdev_flash_register_ext - register a new object of LED class with
0091  *                   init data and with support for flash LEDs
0092  * @parent: LED flash controller device this flash LED is driven by
0093  * @fled_cdev: the led_classdev_flash structure for this device
0094  * @init_data: the LED class flash device initialization data
0095  *
0096  * Returns: 0 on success or negative error value on failure
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  * led_classdev_flash_unregister - unregisters an object of led_classdev class
0104  *                 with support for flash LEDs
0105  * @fled_cdev: the flash LED to unregister
0106  *
0107  * Unregister a previously registered via led_classdev_flash_register object
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  /* IS_ENABLED(CONFIG_LEDS_CLASS_FLASH) */
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  * led_set_flash_strobe - setup flash strobe
0156  * @fled_cdev: the flash LED to set strobe on
0157  * @state: 1 - strobe flash, 0 - stop flash strobe
0158  *
0159  * Strobe the flash LED.
0160  *
0161  * Returns: 0 on success or negative error value on failure
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  * led_get_flash_strobe - get flash strobe status
0173  * @fled_cdev: the flash LED to query
0174  * @state: 1 - flash is strobing, 0 - flash is off
0175  *
0176  * Check whether the flash is strobing at the moment.
0177  *
0178  * Returns: 0 on success or negative error value on failure
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  * led_set_flash_brightness - set flash LED brightness
0193  * @fled_cdev: the flash LED to set
0194  * @brightness: the brightness to set it to
0195  *
0196  * Set a flash LED's brightness.
0197  *
0198  * Returns: 0 on success or negative error value on failure
0199  */
0200 int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
0201                  u32 brightness);
0202 
0203 /**
0204  * led_update_flash_brightness - update flash LED brightness
0205  * @fled_cdev: the flash LED to query
0206  *
0207  * Get a flash LED's current brightness and update led_flash->brightness
0208  * member with the obtained value.
0209  *
0210  * Returns: 0 on success or negative error value on failure
0211  */
0212 int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
0213 
0214 /**
0215  * led_set_flash_timeout - set flash LED timeout
0216  * @fled_cdev: the flash LED to set
0217  * @timeout: the flash timeout to set it to
0218  *
0219  * Set the flash strobe duration.
0220  *
0221  * Returns: 0 on success or negative error value on failure
0222  */
0223 int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout);
0224 
0225 /**
0226  * led_get_flash_fault - get the flash LED fault
0227  * @fled_cdev: the flash LED to query
0228  * @fault: bitmask containing flash faults
0229  *
0230  * Get the flash LED fault.
0231  *
0232  * Returns: 0 on success or negative error value on failure
0233  */
0234 int led_get_flash_fault(struct led_classdev_flash *fled_cdev, u32 *fault);
0235 
0236 #endif  /* __LINUX_FLASH_LEDS_H_INCLUDED */