diff options
Diffstat (limited to 'include/linux/leds')
| -rw-r--r-- | include/linux/leds/flashlight.h | 134 | ||||
| -rw-r--r-- | include/linux/leds/rt5033_fled.h | 79 | ||||
| -rw-r--r-- | include/linux/leds/rtfled.h | 127 |
3 files changed, 340 insertions, 0 deletions
diff --git a/include/linux/leds/flashlight.h b/include/linux/leds/flashlight.h new file mode 100644 index 00000000..34fedd48 --- /dev/null +++ b/include/linux/leds/flashlight.h @@ -0,0 +1,134 @@ +/* include/linux/leds/flashlight.h + * Header of Flashlight Class Device Driver + * + * Copyright (C) 2013 Richtek Technology Corp. + * Patrick Chang <patrick_chang@richtek.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef LINUX_LEDS_FLASHLIGHT_H +#define LINUX_LEDS_FLASHLIGHT_H + +#include <linux/device.h> +#include <linux/mutex.h> + + +typedef enum flashlight_type { + FLASHLIGHT_TYPE_XENON = 0, + FLASHLIGHT_TYPE_LED, + FLASHLIFHT_TYPE_BULB, + FLASHLIGHT_TYPE_MAX, +} flashlight_type_t; +typedef enum flashlight_mode { + FLASHLIGHT_MODE_OFF = 0, + FLASHLIGHT_MODE_TORCH, + FLASHLIGHT_MODE_FLASH, + /* MIXED mode means TORCH + FLASH */ + FLASHLIGHT_MODE_MIXED, + FLASHLIGHT_MODE_MAX, +} flashlight_mode_t; + +struct flashlight_device; + +typedef int (*flashlight_charge_event_cb)(void *data, int remains); + +struct flashlight_ops { + int (*set_torch_brightness)(struct flashlight_device *, int); + int (*set_strobe_brightness)(struct flashlight_device *, int); + int (*set_strobe_timeout)(struct flashlight_device *, int); + int (*list_strobe_timeout)(struct flashlight_device *, int); + int (*set_mode)(struct flashlight_device *, int); + int (*set_color_temperature)(struct flashlight_device *, int); + int (*list_color_temperature)(struct flashlight_device *, int); + int (*strobe_charge)(struct flashlight_device *, + flashlight_charge_event_cb, void *, int); + int (*strobe)(struct flashlight_device *); + int (*suspend)(struct flashlight_device *, pm_message_t); + int (*resume)(struct flashlight_device *); +}; + +struct flashlight_properties { + /* Flashlight type */ + enum flashlight_type type; + /* Xenon type flashlight doesn't support torch mode */ + enum flashlight_mode mode; + /* Color temperature, unit: K, 0 means unknown */ + int color_temperature; + int torch_brightness; + int torch_max_brightness; + int strobe_brightness; + int strobe_max_brightness; + int strobe_delay; + int strobe_timeout; + const char *alias_name; +}; + +struct flashlight_device { + /* Flashlight properties */ + struct flashlight_properties props; + const struct flashlight_ops *ops; + struct mutex ops_lock; + struct device dev; +}; + + +extern struct flashlight_device *flashlight_device_register(const char *name, + struct device *parent, void *devdata, const struct flashlight_ops *ops, + const struct flashlight_properties *props); +extern void flashlight_device_unregister(struct flashlight_device *flashlight_dev); +extern struct flashlight_device *find_flashlight_by_name(char *name); +extern int flashlight_list_color_temperature( + struct flashlight_device *flashlight_dev, + int selector); +extern int flashlight_set_color_temperature( + struct flashlight_device *flashlight_dev, + int minK, int maxK); +extern int flashlight_set_torch_brightness( + struct flashlight_device *flashlight_dev, + int brightness_level); +extern int flashlight_set_strobe_brightness( + struct flashlight_device *flashlight_dev, + int brightness_level); +extern int flashlight_list_strobe_timeout( + struct flashlight_device *flashlight_dev, + int selector); +extern int flashlight_set_strobe_timeout( + struct flashlight_device *flashlight_dev, + int min_ms, int max_ms); +extern int flashlight_set_mode(struct flashlight_device *flashlight_dev, + int mode); + +extern int flashlight_strobe(struct flashlight_device *flashlight_dev); + +/* flashlight_charge_event_cb(void *data, int remains) + * description : + * callback function of flashlight charging progress + * arguments : + * @data : data pass by flashlight_strobe_charge() + * @remains : remained time to full chargerd, unit : ms ; 0 means ready + * return : 0 means succeess, otherwise see definitions in errno.h + */ + +/* flashlight_strobe_chargestruct flashlight_device *flashlight_dev, + * flashlight_charge_event_cb cb, void *data, int start) + * description : + * flashlight start / stop charging + * @flashlight_dev : flashlight devices + * @flashlight_charge_event_cb : callback function to report progress + * @data : bypass to callback function + * @start : 1 means start; 0 means stop + */ +extern int flashlight_strobe_charge(struct flashlight_device *flashlight_dev, + flashlight_charge_event_cb cb, void *data, int start); + +#define to_flashlight_device(obj) container_of(obj, struct flashlight_device, dev) + +static inline void * flashlight_get_data( + struct flashlight_device *flashlight_dev) +{ + return dev_get_drvdata(&flashlight_dev->dev); +} +#endif /*LINUX_LEDS_FLASHLIGHT_H*/ diff --git a/include/linux/leds/rt5033_fled.h b/include/linux/leds/rt5033_fled.h new file mode 100644 index 00000000..eb34440e --- /dev/null +++ b/include/linux/leds/rt5033_fled.h @@ -0,0 +1,79 @@ +/* include/linux/leds/rt5033_fled.h + * Header of Richtek RT5033 Flash LED Driver + * + * Copyright (C) 2013 Richtek Technology Corp. + * Author: Patrick Chang <patrick_chang@richtek.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + */ + +#ifndef LINUX_LEDS_RT5033_FLED_H +#define LINUX_LEDS_RT5033_FLED_H +#include <linux/kernel.h> +#include "rtfled.h" + + +#define RT5033_STROBE_CURRENT(mA) (((mA - 50) / 25) & 0x1f) +#define RT5033_TIMEOUT_LEVEL(mA) (((mA - 50) / 25) & 0x07) +#define RT5033_STROBE_TIMEOUT(ms) (((ms - 64) / 32) & 0x3f) +#define RT5033_TORCH_CURRENT(mA) (((mA * 10 - 125) / 125) & 0x0f) +#define RT5033_LV_PROTECTION(mV) (((mV - 3000) / 100) & 0x07) +#define RT5033_MID_REGULATION_LEVEL(mV) (((mV - 3625) / 25) & 0x3f) + +typedef struct rt5033_fled_platform_data { + unsigned int fled1_en : 1; + unsigned int fled2_en : 1; + unsigned int fled_mid_track_alive : 1; + unsigned int fled_mid_auto_track_en : 1; + unsigned int fled_timeout_current_level; + unsigned int fled_strobe_current; + unsigned int fled_strobe_timeout; + unsigned int fled_torch_current; + unsigned int fled_lv_protection; + unsigned int fled_mid_level; +} rt5033_fled_platform_data_t; + +#define RT5033_FLED_RESET 0x21 + +#define RT5033_FLED_FUNCTION1 0x21 +#define RT5033_FLED_FUNCTION2 0x22 +#define RT5033_FLED_STROBE_CONTROL1 0x23 +#define RT5033_FLED_STROBE_CONTROL2 0x24 +#define RT5033_FLED_CONTROL1 0x25 +#define RT5033_FLED_CONTROL2 0x26 +#define RT5033_FLED_CONTROL3 0x27 +#define RT5033_FLED_CONTROL4 0x28 +#define RT5033_FLED_CONTROL5 0x29 + +#define RT5033_CHG_FLED_CTRL 0x67 + +extern int32_t rt5033_charger_notification(struct rt_fled_info *info, int32_t attach); +extern int32_t rt5033_boost_notification(struct rt_fled_info *info, int32_t on); +extern void rt5033_fled_lock(struct rt_fled_info *fled_info); +extern void rt5033_fled_unlock(struct rt_fled_info *fled_info); + +#ifdef CONFIG_FLED_RT5033_EXT_GPIO +/* If you are using external GPIO to control torch and flash led, + * you must call rt5033_fled_srobe_critial_section_lock() for camera shot, + * and call rt5033_fled_srobe_critial_section_unlock() after camera mode. + * example code : + * struct camera_chip* chip; + * if (chip->fled_info == NULL) + * chip->fled_info = rt_fled_get_info_by_name(NULL); + * if (chip->fled_info) + * rt5033_fled_srobe_critial_section_lock(chip->fled_info); + * ... + * ... camera opertion + * ... + * ... when finished camera operation + * if (chip->fled_info) + * rt5033_fled_srobe_critial_section_unlock(chip->fled_info); + */ +extern void rt5033_fled_strobe_critial_section_lock(struct rt_fled_info *fled_info); +extern void rt5033_fled_strobe_critial_section_unlock(struct rt_fled_info *fled_info);
extern int32_t rt5033_fled_enable(struct rt_fled_info *fled_info, int enable); +#endif /* CONFIG_FLED_RT5033_EXT_GPIO */ + +#endif /* LINUX_LEDS_RT5033_FLED_H */ diff --git a/include/linux/leds/rtfled.h b/include/linux/leds/rtfled.h new file mode 100644 index 00000000..aae1c7e9 --- /dev/null +++ b/include/linux/leds/rtfled.h @@ -0,0 +1,127 @@ +/* include/linux/leds/rtfled.h + * Header of Richtek Flash LED Driver + * + * Copyright (C) 2013 Richtek Technology Corp. + * Author: Patrick Chang <patrick_chang@richtek.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + */ + +#ifndef LINUX_LEDS_RTFLED_H +#define LINUX_LEDS_RTFLED_H +#include <linux/leds/flashlight.h> + +struct rt_fled_info; +typedef int (*rt_hal_fled_init)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_suspend)(struct rt_fled_info *info, pm_message_t state); +typedef int (*rt_hal_fled_resume)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_set_mode)(struct rt_fled_info *info, flashlight_mode_t mode); +typedef int (*rt_hal_fled_get_mode)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_strobe)(struct rt_fled_info *info); + +/* Return value : -EINVAL => selector parameter is out of range, otherwise current in uA*/ +typedef int (*rt_hal_fled_torch_current_list)(struct rt_fled_info *info, int selector); +typedef int (*rt_hal_fled_strobe_current_list)(struct rt_fled_info *info, int selector); +typedef int (*rt_hal_fled_timeout_level_list)(struct rt_fled_info *info, int selector); +/* Return value : -EINVAL => selector parameter is out of range, otherwise voltage in mV*/ +typedef int (*rt_hal_fled_lv_protection_list)(struct rt_fled_info *info, int selector); +/* Return value : -EINVAL => selector parameter is out of range, otherwise time in ms*/ +typedef int (*rt_hal_fled_strobe_timeout_list)(struct rt_fled_info *info, int selector); +typedef int (*rt_hal_fled_set_torch_current)(struct rt_fled_info *info, + int min_uA, int max_uA, int *selector); +typedef int (*rt_hal_fled_set_strobe_current)(struct rt_fled_info *info, + int min_uA, int max_uA, int *selector); +typedef int (*rt_hal_fled_set_timeout_level)(struct rt_fled_info *info, + int min_uA, int max_uA, int *selector); +typedef int (*rt_hal_fled_set_lv_protection)(struct rt_fled_info *info, + int min_mV, int max_mV, int *selector); +typedef int (*rt_hal_fled_set_strobe_timeout)(struct rt_fled_info *info, + int min_ms, int max_ms, int *selector); +typedef int (*rt_hal_fled_set_torch_current_sel)(struct rt_fled_info *info, + int selector); +typedef int (*rt_hal_fled_set_strobe_current_sel)(struct rt_fled_info *info, + int selector); +typedef int (*rt_hal_fled_set_timeout_level_sel)(struct rt_fled_info *info, + int selector); +typedef int (*rt_hal_fled_set_lv_protection_sel)(struct rt_fled_info *info, + int selector); +typedef int (*rt_hal_fled_set_strobe_timeout_sel)(struct rt_fled_info *info, + int selector); +typedef int (*rt_hal_fled_get_torch_current_sel)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_strobe_current_sel)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_timeout_level_sel)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_lv_protection_sel)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_strobe_timeout_sel)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_torch_current)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_strobe_current)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_timeout_level)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_lv_protection)(struct rt_fled_info *info); +typedef int (*rt_hal_fled_get_strobe_timeout)(struct rt_fled_info *info); +typedef void (*rt_hal_fled_shutdown)(struct rt_fled_info *info); + +struct rt_fled_hal { + rt_hal_fled_init fled_init; + rt_hal_fled_suspend fled_suspend; + rt_hal_fled_resume fled_resume; + rt_hal_fled_set_mode fled_set_mode; + rt_hal_fled_get_mode fled_get_mode; + rt_hal_fled_strobe fled_strobe; + rt_hal_fled_torch_current_list fled_troch_current_list; + rt_hal_fled_strobe_current_list fled_strobe_current_list; + rt_hal_fled_timeout_level_list fled_timeout_level_list; + rt_hal_fled_lv_protection_list fled_lv_protection_list; + rt_hal_fled_strobe_timeout_list fled_strobe_timeout_list; + /* method to set */ + rt_hal_fled_set_torch_current_sel fled_set_torch_current_sel; + rt_hal_fled_set_strobe_current_sel fled_set_strobe_current_sel; + rt_hal_fled_set_timeout_level_sel fled_set_timeout_level_sel; + rt_hal_fled_set_lv_protection_sel fled_set_lv_protection_sel; + rt_hal_fled_set_strobe_timeout_sel fled_set_strobe_timeout_sel; + /* method to set, optional */ + rt_hal_fled_set_torch_current fled_set_torch_current; + rt_hal_fled_set_strobe_current fled_set_strobe_current; + rt_hal_fled_set_timeout_level fled_set_timeout_level; + rt_hal_fled_set_lv_protection fled_set_lv_protection; + rt_hal_fled_set_strobe_timeout fled_set_strobe_timeout; + /* method to get */ + rt_hal_fled_get_torch_current_sel fled_get_torch_current_sel; + rt_hal_fled_get_strobe_current_sel fled_get_strobe_current_sel; + rt_hal_fled_get_timeout_level_sel fled_get_timeout_level_sel; + rt_hal_fled_get_lv_protection_sel fled_get_lv_protection_sel; + rt_hal_fled_get_strobe_timeout_sel fled_get_strobe_timeout_sel; + /* method to get, optional*/ + rt_hal_fled_get_torch_current fled_get_torch_current; + rt_hal_fled_get_strobe_current fled_get_strobe_current; + rt_hal_fled_get_timeout_level fled_get_timeout_level; + rt_hal_fled_get_lv_protection fled_get_lv_protection; + rt_hal_fled_get_strobe_timeout fled_get_strobe_timeout; + /* PM shutdown, optional */ + rt_hal_fled_shutdown fled_shutdown; +}; + +typedef struct rt_fled_info { + struct rt_fled_hal *hal; + struct flashlight_device *flashlight_dev; + const struct flashlight_properties *init_props; + char *name; + char *chip_name; +} rt_fled_info_t; + + +/* Public funtions + * argument + * @name : Flash LED's name;pass NULL menas "rt-flash-led" + */ + +rt_fled_info_t *rt_fled_get_info_by_name(char *name); + +/* Usage : + * fled_info = rt_fled_get_info_by_name("FlashLED1"); + * fled_info->hal->fled_set_strobe_current(fled_info, + * 150, 200); + */ + +#endif /*LINUX_LEDS_RTFLED_H*/ |
