Merge branch develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / media / video / rk_camsys / ext_flashled_drv / flashlight.h
1 /* include/linux/leds/flashlight.h
2  * Header of Flashlight Class Device Driver
3  *
4  * Copyright (C) 2013 Richtek Technology Corp.
5  * Patrick Chang <patrick_chang@richtek.com>
6  *
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.
10  */
11
12 #ifndef LINUX_LEDS_FLASHLIGHT_H
13 #define LINUX_LEDS_FLASHLIGHT_H
14
15 #include <linux/device.h>
16 #include <linux/mutex.h>
17
18 typedef enum flashlight_type {
19         FLASHLIGHT_TYPE_XENON = 0,
20         FLASHLIGHT_TYPE_LED,
21         FLASHLIFHT_TYPE_BULB,
22         FLASHLIGHT_TYPE_MAX,
23 } flashlight_type_t;
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,
30         FLASHLIGHT_MODE_MAX,
31 } flashlight_mode_t;
32
33 struct flashlight_device;
34
35 typedef int (*flashlight_charge_event_cb) (void *data, int remains);
36
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 *);
50 };
51
52 struct flashlight_properties {
53         /* Flashlight type */
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;
59         int torch_brightness;
60         int torch_max_brightness;
61         int strobe_brightness;
62         int strobe_max_brightness;
63         int strobe_delay;
64         int strobe_timeout;
65         const char *alias_name;
66 };
67
68 struct flashlight_device {
69         /* Flashlight properties */
70         struct flashlight_properties props;
71         const struct flashlight_ops *ops;
72         struct mutex ops_lock;
73         struct device dev;
74 };
75
76 extern struct flashlight_device *flashlight_device_register(const char *name,
77                                                         struct device *parent,
78                                                         void *devdata,
79                                                         const struct
80                                                         flashlight_ops * ops,
81                                                         const struct
82                                                         flashlight_properties
83                                                         *props);
84 extern void flashlight_device_unregister(struct flashlight_device
85                                          *flashlight_dev);
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,
91                                             int maxK);
92 extern int flashlight_set_torch_brightness(struct flashlight_device
93                                            *flashlight_dev,
94                                            int brightness_level);
95 extern int flashlight_set_strobe_brightness(struct flashlight_device
96                                             *flashlight_dev,
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,
102                                          int max_ms);
103 extern int flashlight_set_mode(struct flashlight_device *flashlight_dev,
104                                int mode);
105
106 extern int flashlight_strobe(struct flashlight_device *flashlight_dev);
107
108 /* flashlight_charge_event_cb(void *data, int remains)
109  * description :
110  *   callback function of flashlight charging progress
111  * arguments :
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
115  */
116
117 /* flashlight_strobe_chargestruct flashlight_device *flashlight_dev,
118  *                      flashlight_charge_event_cb cb, void *data, int start)
119  * description :
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
125  */
126 extern int flashlight_strobe_charge(struct flashlight_device *flashlight_dev,
127                                     flashlight_charge_event_cb cb, void *data,
128                                     int start);
129
130 #define to_flashlight_device(obj) \
131         container_of(obj, struct flashlight_device, dev)
132
133 static inline void *flashlight_get_data(struct flashlight_device
134                                         *flashlight_dev)
135 {
136         return dev_get_drvdata(&flashlight_dev->dev);
137 }
138 #endif /*LINUX_LEDS_FLASHLIGHT_H */