Commit 7aea8389 authored by Jacek Anaszewski's avatar Jacek Anaszewski Committed by Bryan Wu

leds: Add LED Flash class extension to the LED subsystem

Some LED devices support two operation modes - torch and flash.
This patch provides support for flash LED devices in the LED subsystem
by introducing new sysfs attributes and kernel internal interface.
The attributes being introduced are: flash_brightness, flash_strobe,
flash_timeout, max_flash_timeout, max_flash_brightness, flash_fault,
flash_sync_strobe and available_sync_leds. All the flash related
features are placed in a separate module.

The modifications aim to be compatible with V4L2 framework requirements
related to the flash devices management. The design assumes that V4L2
sub-device can take of the LED class device control and communicate
with it through the kernel internal interface. When V4L2 Flash sub-device
file is opened, the LED class device sysfs interface is made
unavailable.
Signed-off-by: default avatarJacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: default avatarKyungmin Park <kyungmin.park@samsung.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarBryan Wu <cooloney@gmail.com>
parent 452bc149
......@@ -22,6 +22,16 @@ config LEDS_CLASS
This option enables the led sysfs class in /sys/class/leds. You'll
need this to do anything useful with LEDs. If unsure, say N.
config LEDS_CLASS_FLASH
tristate "LED Flash Class Support"
depends on LEDS_CLASS
help
This option enables the flash led sysfs class in /sys/class/leds.
It wrapps LED Class and adds flash LEDs specific sysfs attributes
and kernel internal API to it. You'll need this to provide support
for the flash related features of a LED device. It can be built
as a module.
comment "LED drivers"
config LEDS_88PM860X
......
......@@ -2,6 +2,7 @@
# LED Core
obj-$(CONFIG_NEW_LEDS) += led-core.o
obj-$(CONFIG_LEDS_CLASS) += led-class.o
obj-$(CONFIG_LEDS_CLASS_FLASH) += led-class-flash.o
obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o
# LED Platform Drivers
......
This diff is collapsed.
......@@ -179,6 +179,10 @@ EXPORT_SYMBOL_GPL(led_classdev_suspend);
void led_classdev_resume(struct led_classdev *led_cdev)
{
led_cdev->brightness_set(led_cdev, led_cdev->brightness);
if (led_cdev->flash_resume)
led_cdev->flash_resume(led_cdev);
led_cdev->flags &= ~LED_SUSPENDED;
}
EXPORT_SYMBOL_GPL(led_classdev_resume);
......
/*
* LED Flash class interface
*
* Copyright (C) 2015 Samsung Electronics Co., Ltd.
* Author: Jacek Anaszewski <j.anaszewski@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
#ifndef __LINUX_FLASH_LEDS_H_INCLUDED
#define __LINUX_FLASH_LEDS_H_INCLUDED
#include <linux/leds.h>
#include <uapi/linux/v4l2-controls.h>
struct device_node;
struct led_classdev_flash;
/*
* Supported led fault bits - must be kept in synch
* with V4L2_FLASH_FAULT bits.
*/
#define LED_FAULT_OVER_VOLTAGE (1 << 0)
#define LED_FAULT_TIMEOUT (1 << 1)
#define LED_FAULT_OVER_TEMPERATURE (1 << 2)
#define LED_FAULT_SHORT_CIRCUIT (1 << 3)
#define LED_FAULT_OVER_CURRENT (1 << 4)
#define LED_FAULT_INDICATOR (1 << 5)
#define LED_FAULT_UNDER_VOLTAGE (1 << 6)
#define LED_FAULT_INPUT_VOLTAGE (1 << 7)
#define LED_FAULT_LED_OVER_TEMPERATURE (1 << 8)
#define LED_NUM_FLASH_FAULTS 9
#define LED_FLASH_MAX_SYSFS_GROUPS 7
struct led_flash_ops {
/* set flash brightness */
int (*flash_brightness_set)(struct led_classdev_flash *fled_cdev,
u32 brightness);
/* get flash brightness */
int (*flash_brightness_get)(struct led_classdev_flash *fled_cdev,
u32 *brightness);
/* set flash strobe state */
int (*strobe_set)(struct led_classdev_flash *fled_cdev, bool state);
/* get flash strobe state */
int (*strobe_get)(struct led_classdev_flash *fled_cdev, bool *state);
/* set flash timeout */
int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout);
/* get the flash LED fault */
int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault);
};
/*
* Current value of a flash setting along
* with its constraints.
*/
struct led_flash_setting {
/* maximum allowed value */
u32 min;
/* maximum allowed value */
u32 max;
/* step value */
u32 step;
/* current value */
u32 val;
};
struct led_classdev_flash {
/* led class device */
struct led_classdev led_cdev;
/* flash led specific ops */
const struct led_flash_ops *ops;
/* flash brightness value in microamperes along with its constraints */
struct led_flash_setting brightness;
/* flash timeout value in microseconds along with its constraints */
struct led_flash_setting timeout;
/* LED Flash class sysfs groups */
const struct attribute_group *sysfs_groups[LED_FLASH_MAX_SYSFS_GROUPS];
/* LEDs available for flash strobe synchronization */
struct led_classdev_flash **sync_leds;
/* Number of LEDs available for flash strobe synchronization */
int num_sync_leds;
/*
* The identifier of the sub-led to synchronize the flash strobe with.
* Identifiers start from 1, which reflects the first element from the
* sync_leds array. 0 means that the flash strobe should not be
* synchronized.
*/
u32 sync_led_id;
};
static inline struct led_classdev_flash *lcdev_to_flcdev(
struct led_classdev *lcdev)
{
return container_of(lcdev, struct led_classdev_flash, led_cdev);
}
/**
* led_classdev_flash_register - register a new object of led_classdev class
* with support for flash LEDs
* @parent: the flash LED to register
* @fled_cdev: the led_classdev_flash structure for this device
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_classdev_flash_register(struct device *parent,
struct led_classdev_flash *fled_cdev);
/**
* led_classdev_flash_unregister - unregisters an object of led_classdev class
* with support for flash LEDs
* @fled_cdev: the flash LED to unregister
*
* Unregister a previously registered via led_classdev_flash_register object
*/
extern void led_classdev_flash_unregister(struct led_classdev_flash *fled_cdev);
/**
* led_set_flash_strobe - setup flash strobe
* @fled_cdev: the flash LED to set strobe on
* @state: 1 - strobe flash, 0 - stop flash strobe
*
* Strobe the flash LED.
*
* Returns: 0 on success or negative error value on failure
*/
static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev,
bool state)
{
return fled_cdev->ops->strobe_set(fled_cdev, state);
}
/**
* led_get_flash_strobe - get flash strobe status
* @fled_cdev: the flash LED to query
* @state: 1 - flash is strobing, 0 - flash is off
*
* Check whether the flash is strobing at the moment.
*
* Returns: 0 on success or negative error value on failure
*/
static inline int led_get_flash_strobe(struct led_classdev_flash *fled_cdev,
bool *state)
{
if (fled_cdev->ops->strobe_get)
return fled_cdev->ops->strobe_get(fled_cdev, state);
return -EINVAL;
}
/**
* led_set_flash_brightness - set flash LED brightness
* @fled_cdev: the flash LED to set
* @brightness: the brightness to set it to
*
* Set a flash LED's brightness.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_set_flash_brightness(struct led_classdev_flash *fled_cdev,
u32 brightness);
/**
* led_update_flash_brightness - update flash LED brightness
* @fled_cdev: the flash LED to query
*
* Get a flash LED's current brightness and update led_flash->brightness
* member with the obtained value.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_update_flash_brightness(struct led_classdev_flash *fled_cdev);
/**
* led_set_flash_timeout - set flash LED timeout
* @fled_cdev: the flash LED to set
* @timeout: the flash timeout to set it to
*
* Set the flash strobe duration.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_set_flash_timeout(struct led_classdev_flash *fled_cdev,
u32 timeout);
/**
* led_get_flash_fault - get the flash LED fault
* @fled_cdev: the flash LED to query
* @fault: bitmask containing flash faults
*
* Get the flash LED fault.
*
* Returns: 0 on success or negative error value on failure
*/
extern int led_get_flash_fault(struct led_classdev_flash *fled_cdev,
u32 *fault);
#endif /* __LINUX_FLASH_LEDS_H_INCLUDED */
......@@ -46,6 +46,8 @@ struct led_classdev {
#define LED_SYSFS_DISABLE (1 << 20)
#define SET_BRIGHTNESS_ASYNC (1 << 21)
#define SET_BRIGHTNESS_SYNC (1 << 22)
#define LED_DEV_CAP_FLASH (1 << 23)
#define LED_DEV_CAP_SYNC_STROBE (1 << 24)
/* Set LED brightness level */
/* Must not sleep, use a workqueue if needed */
......@@ -81,6 +83,7 @@ struct led_classdev {
unsigned long blink_delay_on, blink_delay_off;
struct timer_list blink_timer;
int blink_brightness;
void (*flash_resume)(struct led_classdev *led_cdev);
struct work_struct set_brightness_work;
int delayed_set_value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment