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>
19 typedef enum flashlight_type {
20 FLASHLIGHT_TYPE_XENON = 0,
25 typedef enum flashlight_mode {
26 FLASHLIGHT_MODE_OFF = 0,
27 FLASHLIGHT_MODE_TORCH,
28 FLASHLIGHT_MODE_FLASH,
29 /* MIXED mode means TORCH + FLASH */
30 FLASHLIGHT_MODE_MIXED,
34 struct flashlight_device;
36 typedef int (*flashlight_charge_event_cb)(void *data, int remains);
38 struct flashlight_ops {
39 int (*set_torch_brightness)(struct flashlight_device *, int);
40 int (*set_strobe_brightness)(struct flashlight_device *, int);
41 int (*set_strobe_timeout)(struct flashlight_device *, int);
42 int (*list_strobe_timeout)(struct flashlight_device *, int);
43 int (*set_mode)(struct flashlight_device *, int);
44 int (*set_color_temperature)(struct flashlight_device *, int);
45 int (*list_color_temperature)(struct flashlight_device *, int);
46 int (*strobe_charge)(struct flashlight_device *,
47 flashlight_charge_event_cb, void *, int);
48 int (*strobe)(struct flashlight_device *);
49 int (*suspend)(struct flashlight_device *, pm_message_t);
50 int (*resume)(struct flashlight_device *);
53 struct flashlight_properties {
55 enum flashlight_type type;
56 /* Xenon type flashlight doesn't support torch mode */
57 enum flashlight_mode mode;
58 /* Color temperature, unit: K, 0 means unknown */
59 int color_temperature;
61 int torch_max_brightness;
62 int strobe_brightness;
63 int strobe_max_brightness;
66 const char *alias_name;
69 struct flashlight_device {
70 /* Flashlight properties */
71 struct flashlight_properties props;
72 const struct flashlight_ops *ops;
73 struct mutex ops_lock;
78 extern struct flashlight_device *flashlight_device_register(const char *name,
79 struct device *parent, void *devdata, const struct flashlight_ops *ops,
80 const struct flashlight_properties *props);
81 extern void flashlight_device_unregister(struct flashlight_device *flashlight_dev);
82 extern struct flashlight_device *find_flashlight_by_name(char *name);
83 extern int flashlight_list_color_temperature(
84 struct flashlight_device *flashlight_dev,
86 extern int flashlight_set_color_temperature(
87 struct flashlight_device *flashlight_dev,
89 extern int flashlight_set_torch_brightness(
90 struct flashlight_device *flashlight_dev,
91 int brightness_level);
92 extern int flashlight_set_strobe_brightness(
93 struct flashlight_device *flashlight_dev,
94 int brightness_level);
95 extern int flashlight_list_strobe_timeout(
96 struct flashlight_device *flashlight_dev,
98 extern int flashlight_set_strobe_timeout(
99 struct flashlight_device *flashlight_dev,
100 int min_ms, int max_ms);
101 extern int flashlight_set_mode(struct flashlight_device *flashlight_dev,
104 extern int flashlight_strobe(struct flashlight_device *flashlight_dev);
106 /* flashlight_charge_event_cb(void *data, int remains)
108 * callback function of flashlight charging progress
110 * @data : data pass by flashlight_strobe_charge()
111 * @remains : remained time to full chargerd, unit : ms ; 0 means ready
112 * return : 0 means succeess, otherwise see definitions in errno.h
115 /* flashlight_strobe_chargestruct flashlight_device *flashlight_dev,
116 * flashlight_charge_event_cb cb, void *data, int start)
118 * flashlight start / stop charging
119 * @flashlight_dev : flashlight devices
120 * @flashlight_charge_event_cb : callback function to report progress
121 * @data : bypass to callback function
122 * @start : 1 means start; 0 means stop
124 extern int flashlight_strobe_charge(struct flashlight_device *flashlight_dev,
125 flashlight_charge_event_cb cb, void *data, int start);
127 #define to_flashlight_device(obj) container_of(obj, struct flashlight_device, dev)
129 static inline void * flashlight_get_data(
130 struct flashlight_device *flashlight_dev)
132 return dev_get_drvdata(&flashlight_dev->dev);
134 #endif /*LINUX_LEDS_FLASHLIGHT_H*/