Skip to content

Commit 2870b52

Browse files
rmsilvagregkh
authored andcommitted
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: Rui Miguel Silva <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 13fcfbb commit 2870b52

File tree

4 files changed

+1420
-0
lines changed

4 files changed

+1420
-0
lines changed

drivers/staging/greybus/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ gb-phy-y := gpbridge.o \
3030
gb-vibrator-y := vibrator.o
3131
gb-battery-y := battery.o
3232
gb-loopback-y := loopback.o
33+
gb-light-y := light.o
3334
gb-raw-y := raw.o
3435
gb-es1-y := es1.o
3536
gb-es2-y := es2.o
@@ -39,6 +40,7 @@ obj-m += gb-phy.o
3940
obj-m += gb-vibrator.o
4041
obj-m += gb-battery.o
4142
obj-m += gb-loopback.o
43+
obj-m += gb-light.o
4244
obj-m += gb-raw.o
4345
obj-m += gb-es1.o
4446
obj-m += gb-es2.o

drivers/staging/greybus/greybus_protocols.h

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,5 +1067,181 @@ struct gb_sdio_event_request {
10671067
#define GB_SDIO_WP 0x04
10681068
};
10691069

1070+
/* Lights */
1071+
1072+
#define GB_LIGHTS_VERSION_MAJOR 0x00
1073+
#define GB_LIGHTS_VERSION_MINOR 0x01
1074+
1075+
/* Greybus Lights request types */
1076+
#define GB_LIGHTS_TYPE_INVALID 0x00
1077+
#define GB_LIGHTS_TYPE_PROTOCOL_VERSION 0x01
1078+
#define GB_LIGHTS_TYPE_GET_LIGHTS 0x02
1079+
#define GB_LIGHTS_TYPE_GET_LIGHT_CONFIG 0x03
1080+
#define GB_LIGHTS_TYPE_GET_CHANNEL_CONFIG 0x04
1081+
#define GB_LIGHTS_TYPE_GET_CHANNEL_FLASH_CONFIG 0x05
1082+
#define GB_LIGHTS_TYPE_SET_BRIGHTNESS 0x06
1083+
#define GB_LIGHTS_TYPE_SET_BLINK 0x07
1084+
#define GB_LIGHTS_TYPE_SET_COLOR 0x08
1085+
#define GB_LIGHTS_TYPE_SET_FADE 0x09
1086+
#define GB_LIGHTS_TYPE_EVENT 0x0A
1087+
#define GB_LIGHTS_TYPE_SET_FLASH_INTENSITY 0x0B
1088+
#define GB_LIGHTS_TYPE_SET_FLASH_STROBE 0x0C
1089+
#define GB_LIGHTS_TYPE_SET_FLASH_TIMEOUT 0x0D
1090+
#define GB_LIGHTS_TYPE_GET_FLASH_FAULT 0x0E
1091+
1092+
/* Greybus Light modes */
1093+
1094+
/*
1095+
* if you add any specific mode below, update also the
1096+
* GB_CHANNEL_MODE_DEFINED_RANGE value accordingly
1097+
*/
1098+
#define GB_CHANNEL_MODE_NONE 0x00000000
1099+
#define GB_CHANNEL_MODE_BATTERY 0x00000001
1100+
#define GB_CHANNEL_MODE_POWER 0x00000002
1101+
#define GB_CHANNEL_MODE_WIRELESS 0x00000004
1102+
#define GB_CHANNEL_MODE_BLUETOOTH 0x00000008
1103+
#define GB_CHANNEL_MODE_KEYBOARD 0x00000010
1104+
#define GB_CHANNEL_MODE_BUTTONS 0x00000020
1105+
#define GB_CHANNEL_MODE_NOTIFICATION 0x00000040
1106+
#define GB_CHANNEL_MODE_ATTENTION 0x00000080
1107+
#define GB_CHANNEL_MODE_FLASH 0x00000100
1108+
#define GB_CHANNEL_MODE_TORCH 0x00000200
1109+
#define GB_CHANNEL_MODE_INDICATOR 0x00000400
1110+
1111+
/* Lights Mode valid bit values */
1112+
#define GB_CHANNEL_MODE_DEFINED_RANGE 0x000004FF
1113+
#define GB_CHANNEL_MODE_VENDOR_RANGE 0x00F00000
1114+
1115+
/* Greybus Light Channels Flags */
1116+
#define GB_LIGHT_CHANNEL_MULTICOLOR 0x00000001
1117+
#define GB_LIGHT_CHANNEL_FADER 0x00000002
1118+
#define GB_LIGHT_CHANNEL_BLINK 0x00000004
1119+
1120+
/* get count of lights in module */
1121+
struct gb_lights_get_lights_response {
1122+
__u8 lights_count;
1123+
};
1124+
1125+
/* light config request payload */
1126+
struct gb_lights_get_light_config_request {
1127+
__u8 id;
1128+
};
1129+
1130+
/* light config response payload */
1131+
struct gb_lights_get_light_config_response {
1132+
__u8 channel_count;
1133+
__u8 name[32];
1134+
};
1135+
1136+
/* channel config request payload */
1137+
struct gb_lights_get_channel_config_request {
1138+
__u8 light_id;
1139+
__u8 channel_id;
1140+
};
1141+
1142+
/* channel flash config request payload */
1143+
struct gb_lights_get_channel_flash_config_request {
1144+
__u8 light_id;
1145+
__u8 channel_id;
1146+
};
1147+
1148+
/* channel config response payload */
1149+
struct gb_lights_get_channel_config_response {
1150+
__u8 max_brightness;
1151+
__le32 flags;
1152+
__le32 color;
1153+
__u8 color_name[32];
1154+
__le32 mode;
1155+
__u8 mode_name[32];
1156+
} __packed;
1157+
1158+
/* channel flash config response payload */
1159+
struct gb_lights_get_channel_flash_config_response {
1160+
__le32 intensity_min_uA;
1161+
__le32 intensity_max_uA;
1162+
__le32 intensity_step_uA;
1163+
__le32 timeout_min_us;
1164+
__le32 timeout_max_us;
1165+
__le32 timeout_step_us;
1166+
};
1167+
1168+
/* blink request payload: response have no payload */
1169+
struct gb_lights_blink_request {
1170+
__u8 light_id;
1171+
__u8 channel_id;
1172+
__le16 time_on_ms;
1173+
__le16 time_off_ms;
1174+
};
1175+
1176+
/* set brightness request payload: response have no payload */
1177+
struct gb_lights_set_brightness_request {
1178+
__u8 light_id;
1179+
__u8 channel_id;
1180+
__u8 brightness;
1181+
};
1182+
1183+
/* set color request payload: response have no payload */
1184+
struct gb_lights_set_color_request {
1185+
__u8 light_id;
1186+
__u8 channel_id;
1187+
__le32 color;
1188+
} __packed;
1189+
1190+
/* set fade request payload: response have no payload */
1191+
struct gb_lights_set_fade_request {
1192+
__u8 light_id;
1193+
__u8 channel_id;
1194+
__u8 fade_in;
1195+
__u8 fade_out;
1196+
};
1197+
1198+
/* event request: generated by module */
1199+
struct gb_lights_event_request {
1200+
__u8 light_id;
1201+
__u8 event;
1202+
#define GB_LIGHTS_LIGHT_CONFIG 0x01
1203+
};
1204+
1205+
/* set flash intensity request payload: response have no payload */
1206+
struct gb_lights_set_flash_intensity_request {
1207+
__u8 light_id;
1208+
__u8 channel_id;
1209+
__le32 intensity_uA;
1210+
} __packed;
1211+
1212+
/* set flash strobe state request payload: response have no payload */
1213+
struct gb_lights_set_flash_strobe_request {
1214+
__u8 light_id;
1215+
__u8 channel_id;
1216+
__u8 state;
1217+
};
1218+
1219+
/* set flash timeout request payload: response have no payload */
1220+
struct gb_lights_set_flash_timeout_request {
1221+
__u8 light_id;
1222+
__u8 channel_id;
1223+
__le32 timeout_us;
1224+
} __packed;
1225+
1226+
/* get flash fault request payload */
1227+
struct gb_lights_get_flash_fault_request {
1228+
__u8 light_id;
1229+
__u8 channel_id;
1230+
};
1231+
1232+
/* get flash fault response payload */
1233+
struct gb_lights_get_flash_fault_response {
1234+
__le32 fault;
1235+
#define GB_LIGHTS_FLASH_FAULT_OVER_VOLTAGE 0x00000000
1236+
#define GB_LIGHTS_FLASH_FAULT_TIMEOUT 0x00000001
1237+
#define GB_LIGHTS_FLASH_FAULT_OVER_TEMPERATURE 0x00000002
1238+
#define GB_LIGHTS_FLASH_FAULT_SHORT_CIRCUIT 0x00000004
1239+
#define GB_LIGHTS_FLASH_FAULT_OVER_CURRENT 0x00000008
1240+
#define GB_LIGHTS_FLASH_FAULT_INDICATOR 0x00000010
1241+
#define GB_LIGHTS_FLASH_FAULT_UNDER_VOLTAGE 0x00000020
1242+
#define GB_LIGHTS_FLASH_FAULT_INPUT_VOLTAGE 0x00000040
1243+
#define GB_LIGHTS_FLASH_FAULT_LED_OVER_TEMPERATURE 0x00000080
1244+
};
1245+
10701246
#endif /* __GREYBUS_PROTOCOLS_H */
10711247

drivers/staging/greybus/kernel_ver.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,45 @@ static inline size_t sg_pcopy_from_buffer(struct scatterlist *sgl,
248248
list_entry((ptr)->prev, type, member)
249249
#endif
250250

251+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
252+
/*
253+
* Before this version the led classdev did not support groups
254+
*/
255+
#define LED_HAVE_GROUPS
256+
#endif
257+
258+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
259+
/*
260+
* At this time the internal API for the set brightness was changed to the async
261+
* version, and one sync API was added to handle cases that need immediate
262+
* effect. Also, the led class flash and lock for sysfs access was introduced.
263+
*/
264+
#define LED_HAVE_SET_SYNC
265+
#define LED_HAVE_FLASH
266+
#define LED_HAVE_LOCK
267+
#include <linux/led-class-flash.h>
268+
#endif
269+
270+
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0)
271+
/*
272+
* From this version upper it was introduced the possibility to disable led
273+
* sysfs entries to handle control of the led device to v4l2, which was
274+
* implemented later. So, before that this should return false.
275+
*/
276+
#include <linux/leds.h>
277+
static inline bool led_sysfs_is_disabled(struct led_classdev *led_cdev)
278+
{
279+
return false;
280+
}
281+
#endif
282+
283+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
284+
/*
285+
* New helper functions for registering/unregistering flash led devices as v4l2
286+
* subdevices were added.
287+
*/
288+
#define V4L2_HAVE_FLASH
289+
#include <media/v4l2-flash-led-class.h>
290+
#endif
291+
251292
#endif /* __GREYBUS_KERNEL_VER_H */

0 commit comments

Comments
 (0)