tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / include / linux / leds / 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
19 typedef enum flashlight_type {
20         FLASHLIGHT_TYPE_XENON = 0,
21         FLASHLIGHT_TYPE_LED,
22         FLASHLIFHT_TYPE_BULB,
23         FLASHLIGHT_TYPE_MAX,
24 } flashlight_type_t;
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,
31         FLASHLIGHT_MODE_MAX,
32 } flashlight_mode_t;
33
34 struct flashlight_device;
35
36 typedef int (*flashlight_charge_event_cb)(void *data, int remains);
37
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 *);
51 };
52
53 struct flashlight_properties {
54         /* Flashlight type */
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;
60         int torch_brightness;
61         int torch_max_brightness;
62         int strobe_brightness;
63         int strobe_max_brightness;
64         int strobe_delay;
65         int strobe_timeout;
66         const char *alias_name;
67 };
68
69 struct flashlight_device {
70         /* Flashlight properties */
71         struct flashlight_properties props;
72         const struct flashlight_ops *ops;
73         struct mutex ops_lock;
74         struct device dev;
75 };
76
77
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,
85                 int selector);
86 extern int flashlight_set_color_temperature(
87                 struct flashlight_device *flashlight_dev,
88                 int minK, int maxK);
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,
97                 int selector);
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,
102                 int mode);
103
104 extern int flashlight_strobe(struct flashlight_device *flashlight_dev);
105
106 /* flashlight_charge_event_cb(void *data, int remains)
107  * description :
108  *   callback function of flashlight charging progress
109  * arguments :
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
113  */
114
115 /* flashlight_strobe_chargestruct flashlight_device *flashlight_dev,
116  *                      flashlight_charge_event_cb cb, void *data, int start)
117  * description :
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
123  */
124 extern int flashlight_strobe_charge(struct flashlight_device *flashlight_dev,
125                 flashlight_charge_event_cb cb, void *data, int start);
126
127 #define to_flashlight_device(obj) container_of(obj, struct flashlight_device, dev)
128
129 static inline void * flashlight_get_data(
130                 struct flashlight_device *flashlight_dev)
131 {
132         return dev_get_drvdata(&flashlight_dev->dev);
133 }
134 #endif /*LINUX_LEDS_FLASHLIGHT_H*/