Commit 2870b52b authored by Rui Miguel Silva's avatar Rui Miguel Silva Committed by Greg Kroah-Hartman

greybus: lights: add lights implementation

This patch adds lights implementation for Greybus Lights class, it
allows multiplexing of lights devices using the same connection. Also
adds two sysfs entries to led class (color, fade) which are commonly
used in several existing LED devices.

It support 2 major class of devices (normal LED and flash type), for
the first it registers to led_classdev, for the latest it registers in
the led_classdev_flash and v4l2_flash, depending on the support of the
kernel version.

Each Module can have N light devices attach and each light can have
multiple channel associated:
glights
   |->light0
   |     |->channel0
   |     |->channel1
   |     | ....
   |     |->channeln
   |->...
   |->lightn
         |->channel0
         |->channel1
         | ....
         |->channeln
Signed-off-by: default avatarRui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@google.com>
parent 13fcfbb6
......@@ -30,6 +30,7 @@ gb-phy-y := gpbridge.o \
gb-vibrator-y := vibrator.o
gb-battery-y := battery.o
gb-loopback-y := loopback.o
gb-light-y := light.o
gb-raw-y := raw.o
gb-es1-y := es1.o
gb-es2-y := es2.o
......@@ -39,6 +40,7 @@ obj-m += gb-phy.o
obj-m += gb-vibrator.o
obj-m += gb-battery.o
obj-m += gb-loopback.o
obj-m += gb-light.o
obj-m += gb-raw.o
obj-m += gb-es1.o
obj-m += gb-es2.o
......
......@@ -1067,5 +1067,181 @@ struct gb_sdio_event_request {
#define GB_SDIO_WP 0x04
};
/* Lights */
#define GB_LIGHTS_VERSION_MAJOR 0x00
#define GB_LIGHTS_VERSION_MINOR 0x01
/* Greybus Lights request types */
#define GB_LIGHTS_TYPE_INVALID 0x00
#define GB_LIGHTS_TYPE_PROTOCOL_VERSION 0x01
#define GB_LIGHTS_TYPE_GET_LIGHTS 0x02
#define GB_LIGHTS_TYPE_GET_LIGHT_CONFIG 0x03
#define GB_LIGHTS_TYPE_GET_CHANNEL_CONFIG 0x04
#define GB_LIGHTS_TYPE_GET_CHANNEL_FLASH_CONFIG 0x05
#define GB_LIGHTS_TYPE_SET_BRIGHTNESS 0x06
#define GB_LIGHTS_TYPE_SET_BLINK 0x07
#define GB_LIGHTS_TYPE_SET_COLOR 0x08
#define GB_LIGHTS_TYPE_SET_FADE 0x09
#define GB_LIGHTS_TYPE_EVENT 0x0A
#define GB_LIGHTS_TYPE_SET_FLASH_INTENSITY 0x0B
#define GB_LIGHTS_TYPE_SET_FLASH_STROBE 0x0C
#define GB_LIGHTS_TYPE_SET_FLASH_TIMEOUT 0x0D
#define GB_LIGHTS_TYPE_GET_FLASH_FAULT 0x0E
/* Greybus Light modes */
/*
* if you add any specific mode below, update also the
* GB_CHANNEL_MODE_DEFINED_RANGE value accordingly
*/
#define GB_CHANNEL_MODE_NONE 0x00000000
#define GB_CHANNEL_MODE_BATTERY 0x00000001
#define GB_CHANNEL_MODE_POWER 0x00000002
#define GB_CHANNEL_MODE_WIRELESS 0x00000004
#define GB_CHANNEL_MODE_BLUETOOTH 0x00000008
#define GB_CHANNEL_MODE_KEYBOARD 0x00000010
#define GB_CHANNEL_MODE_BUTTONS 0x00000020
#define GB_CHANNEL_MODE_NOTIFICATION 0x00000040
#define GB_CHANNEL_MODE_ATTENTION 0x00000080
#define GB_CHANNEL_MODE_FLASH 0x00000100
#define GB_CHANNEL_MODE_TORCH 0x00000200
#define GB_CHANNEL_MODE_INDICATOR 0x00000400
/* Lights Mode valid bit values */
#define GB_CHANNEL_MODE_DEFINED_RANGE 0x000004FF
#define GB_CHANNEL_MODE_VENDOR_RANGE 0x00F00000
/* Greybus Light Channels Flags */
#define GB_LIGHT_CHANNEL_MULTICOLOR 0x00000001
#define GB_LIGHT_CHANNEL_FADER 0x00000002
#define GB_LIGHT_CHANNEL_BLINK 0x00000004
/* get count of lights in module */
struct gb_lights_get_lights_response {
__u8 lights_count;
};
/* light config request payload */
struct gb_lights_get_light_config_request {
__u8 id;
};
/* light config response payload */
struct gb_lights_get_light_config_response {
__u8 channel_count;
__u8 name[32];
};
/* channel config request payload */
struct gb_lights_get_channel_config_request {
__u8 light_id;
__u8 channel_id;
};
/* channel flash config request payload */
struct gb_lights_get_channel_flash_config_request {
__u8 light_id;
__u8 channel_id;
};
/* channel config response payload */
struct gb_lights_get_channel_config_response {
__u8 max_brightness;
__le32 flags;
__le32 color;
__u8 color_name[32];
__le32 mode;
__u8 mode_name[32];
} __packed;
/* channel flash config response payload */
struct gb_lights_get_channel_flash_config_response {
__le32 intensity_min_uA;
__le32 intensity_max_uA;
__le32 intensity_step_uA;
__le32 timeout_min_us;
__le32 timeout_max_us;
__le32 timeout_step_us;
};
/* blink request payload: response have no payload */
struct gb_lights_blink_request {
__u8 light_id;
__u8 channel_id;
__le16 time_on_ms;
__le16 time_off_ms;
};
/* set brightness request payload: response have no payload */
struct gb_lights_set_brightness_request {
__u8 light_id;
__u8 channel_id;
__u8 brightness;
};
/* set color request payload: response have no payload */
struct gb_lights_set_color_request {
__u8 light_id;
__u8 channel_id;
__le32 color;
} __packed;
/* set fade request payload: response have no payload */
struct gb_lights_set_fade_request {
__u8 light_id;
__u8 channel_id;
__u8 fade_in;
__u8 fade_out;
};
/* event request: generated by module */
struct gb_lights_event_request {
__u8 light_id;
__u8 event;
#define GB_LIGHTS_LIGHT_CONFIG 0x01
};
/* set flash intensity request payload: response have no payload */
struct gb_lights_set_flash_intensity_request {
__u8 light_id;
__u8 channel_id;
__le32 intensity_uA;
} __packed;
/* set flash strobe state request payload: response have no payload */
struct gb_lights_set_flash_strobe_request {
__u8 light_id;
__u8 channel_id;
__u8 state;
};
/* set flash timeout request payload: response have no payload */
struct gb_lights_set_flash_timeout_request {
__u8 light_id;
__u8 channel_id;
__le32 timeout_us;
} __packed;
/* get flash fault request payload */
struct gb_lights_get_flash_fault_request {
__u8 light_id;
__u8 channel_id;
};
/* get flash fault response payload */
struct gb_lights_get_flash_fault_response {
__le32 fault;
#define GB_LIGHTS_FLASH_FAULT_OVER_VOLTAGE 0x00000000
#define GB_LIGHTS_FLASH_FAULT_TIMEOUT 0x00000001
#define GB_LIGHTS_FLASH_FAULT_OVER_TEMPERATURE 0x00000002
#define GB_LIGHTS_FLASH_FAULT_SHORT_CIRCUIT 0x00000004
#define GB_LIGHTS_FLASH_FAULT_OVER_CURRENT 0x00000008
#define GB_LIGHTS_FLASH_FAULT_INDICATOR 0x00000010
#define GB_LIGHTS_FLASH_FAULT_UNDER_VOLTAGE 0x00000020
#define GB_LIGHTS_FLASH_FAULT_INPUT_VOLTAGE 0x00000040
#define GB_LIGHTS_FLASH_FAULT_LED_OVER_TEMPERATURE 0x00000080
};
#endif /* __GREYBUS_PROTOCOLS_H */
......@@ -248,4 +248,45 @@ static inline size_t sg_pcopy_from_buffer(struct scatterlist *sgl,
list_entry((ptr)->prev, type, member)
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
/*
* Before this version the led classdev did not support groups
*/
#define LED_HAVE_GROUPS
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
/*
* At this time the internal API for the set brightness was changed to the async
* version, and one sync API was added to handle cases that need immediate
* effect. Also, the led class flash and lock for sysfs access was introduced.
*/
#define LED_HAVE_SET_SYNC
#define LED_HAVE_FLASH
#define LED_HAVE_LOCK
#include <linux/led-class-flash.h>
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
/*
* From this version upper it was introduced the possibility to disable led
* sysfs entries to handle control of the led device to v4l2, which was
* implemented later. So, before that this should return false.
*/
#include <linux/leds.h>
static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
{
return false;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
/*
* New helper functions for registering/unregistering flash led devices as v4l2
* subdevices were added.
*/
#define V4L2_HAVE_FLASH
#include <media/v4l2-flash-led-class.h>
#endif
#endif /* __GREYBUS_KERNEL_VER_H */
This diff is collapsed.
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