1 /* include/linux/leds/flashlight.h
2 * Header of Flashlight Class Device Driver
4 * Copyright (C) 2013 Richtek Technology Corp.
5 * Patrick Chang <patrick_chang@richtek.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #ifndef LINUX_LEDS_FLASHLIGHT_H
13 #define LINUX_LEDS_FLASHLIGHT_H
15 #include <linux/device.h>
16 #include <linux/mutex.h>
18 typedef enum flashlight_type {
19 FLASHLIGHT_TYPE_XENON = 0,
24 typedef enum flashlight_mode {
25 FLASHLIGHT_MODE_OFF = 0,
26 FLASHLIGHT_MODE_TORCH,
27 FLASHLIGHT_MODE_FLASH,
28 /* MIXED mode means TORCH + FLASH */
29 FLASHLIGHT_MODE_MIXED,
33 struct flashlight_device;
35 typedef int (*flashlight_charge_event_cb) (void *data, int remains);
37 struct flashlight_ops {
38 int (*set_torch_brightness)(struct flashlight_device *, int);
39 int (*set_strobe_brightness)(struct flashlight_device *, int);
40 int (*set_strobe_timeout)(struct flashlight_device *, int);
41 int (*list_strobe_timeout)(struct flashlight_device *, int);
42 int (*set_mode)(struct flashlight_device *, int);
43 int (*set_color_temperature)(struct flashlight_device *, int);
44 int (*list_color_temperature)(struct flashlight_device *, int);
45 int (*strobe_charge)(struct flashlight_device *,
46 flashlight_charge_event_cb, void *, int);
47 int (*strobe)(struct flashlight_device *);
48 int (*suspend)(struct flashlight_device *, pm_message_t);
49 int (*resume)(struct flashlight_device *);
52 struct flashlight_properties {
54 enum flashlight_type type;
55 /* Xenon type flashlight doesn't support torch mode */
56 enum flashlight_mode mode;
57 /* Color temperature, unit: K, 0 means unknown */
58 int color_temperature;
60 int torch_max_brightness;
61 int strobe_brightness;
62 int strobe_max_brightness;
65 const char *alias_name;
68 struct flashlight_device {
69 /* Flashlight properties */
70 struct flashlight_properties props;
71 const struct flashlight_ops *ops;
72 struct mutex ops_lock;
76 extern struct flashlight_device *flashlight_device_register(const char *name,
77 struct device *parent,
84 extern void flashlight_device_unregister(struct flashlight_device
86 extern struct flashlight_device *find_flashlight_by_name(char *name);
87 extern int flashlight_list_color_temperature(struct flashlight_device
88 *flashlight_dev, int selector);
89 extern int flashlight_set_color_temperature(struct flashlight_device
90 *flashlight_dev, int minK,
92 extern int flashlight_set_torch_brightness(struct flashlight_device
94 int brightness_level);
95 extern int flashlight_set_strobe_brightness(struct flashlight_device
97 int brightness_level);
98 extern int flashlight_list_strobe_timeout(struct flashlight_device
99 *flashlight_dev, int selector);
100 extern int flashlight_set_strobe_timeout(struct flashlight_device
101 *flashlight_dev, int min_ms,
103 extern int flashlight_set_mode(struct flashlight_device *flashlight_dev,
106 extern int flashlight_strobe(struct flashlight_device *flashlight_dev);
108 /* flashlight_charge_event_cb(void *data, int remains)
110 * callback function of flashlight charging progress
112 * @data : data pass by flashlight_strobe_charge()
113 * @remains : remained time to full chargerd, unit : ms ; 0 means ready
114 * return : 0 means succeess, otherwise see definitions in errno.h
117 /* flashlight_strobe_chargestruct flashlight_device *flashlight_dev,
118 * flashlight_charge_event_cb cb, void *data, int start)
120 * flashlight start / stop charging
121 * @flashlight_dev : flashlight devices
122 * @flashlight_charge_event_cb : callback function to report progress
123 * @data : bypass to callback function
124 * @start : 1 means start; 0 means stop
126 extern int flashlight_strobe_charge(struct flashlight_device *flashlight_dev,
127 flashlight_charge_event_cb cb, void *data,
130 #define to_flashlight_device(obj) \
131 container_of(obj, struct flashlight_device, dev)
133 static inline void *flashlight_get_data(struct flashlight_device
136 return dev_get_drvdata(&flashlight_dev->dev);
138 #endif /*LINUX_LEDS_FLASHLIGHT_H */