1 #include <linux/kernel.h> //constant xx
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/types.h>
5 #include <linux/wait.h>
6 #include <linux/slab.h>
8 #include <linux/sched.h>
9 #include <linux/poll.h>
10 #include <linux/device.h>
11 #include <linux/interrupt.h>
12 #include <linux/delay.h>
13 #include <linux/platform_device.h>
14 #include <linux/cdev.h>
15 #include <linux/errno.h>
16 #include <linux/time.h>
17 #include "kd_flashlight.h"
19 #include <asm/uaccess.h>
20 #include "kd_camera_hw.h"
21 #include <cust_gpio_usage.h>
22 #include <linux/hrtimer.h>
23 #include <linux/ktime.h>
24 #include <linux/xlog.h>
25 #include <linux/version.h>
27 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
28 #include <linux/mutex.h>
30 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
31 #include <linux/semaphore.h>
33 #include <asm/semaphore.h>
39 /******************************************************************************
41 ******************************************************************************/
42 // availible parameter
45 // ANDROID_LOG_WARNING
48 // ANDROID_LOG_VERBOSE
49 #define TAG_NAME "leds_strobe.c"
50 #define PK_DBG_NONE(fmt, arg...) do {} while (0)
51 #define PK_DBG_FUNC(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG , TAG_NAME, KERN_INFO "%s: " fmt, __FUNCTION__ ,##arg)
52 #define PK_WARN(fmt, arg...) xlog_printk(ANDROID_LOG_WARNING, TAG_NAME, KERN_WARNING "%s: " fmt, __FUNCTION__ ,##arg)
53 #define PK_NOTICE(fmt, arg...) xlog_printk(ANDROID_LOG_DEBUG , TAG_NAME, KERN_NOTICE "%s: " fmt, __FUNCTION__ ,##arg)
54 #define PK_INFO(fmt, arg...) xlog_printk(ANDROID_LOG_INFO , TAG_NAME, KERN_INFO "%s: " fmt, __FUNCTION__ ,##arg)
55 #define PK_TRC_FUNC(f) xlog_printk(ANDROID_LOG_DEBUG , TAG_NAME, "<%s>\n", __FUNCTION__);
56 #define PK_TRC_VERBOSE(fmt, arg...) xlog_printk(ANDROID_LOG_VERBOSE, TAG_NAME, fmt, ##arg)
57 #define PK_ERROR(fmt, arg...) xlog_printk(ANDROID_LOG_ERROR , TAG_NAME, KERN_ERR "%s: " fmt, __FUNCTION__ ,##arg)
60 #define DEBUG_LEDS_STROBE
61 #ifdef DEBUG_LEDS_STROBE
62 #define PK_DBG PK_DBG_FUNC
63 #define PK_VER PK_TRC_VERBOSE
64 #define PK_ERR PK_ERROR
71 /******************************************************************************
73 ******************************************************************************/
75 static DEFINE_SPINLOCK(g_strobeSMPLock
); /* cotta-- SMP proection */
78 static u32 strobe_Res
= 0;
79 static u32 strobe_Timeus
= 0;
80 static BOOL g_strobe_On
= 0;
83 static int g_timeOutTimeMs
=0;
85 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
86 static DEFINE_MUTEX(g_strobeSem
);
88 static DECLARE_MUTEX(g_strobeSem
);
92 #define STROBE_DEVICE_ID 0x60
95 static struct work_struct workTimeOut
;
97 /*****************************************************************************
99 *****************************************************************************/
100 #ifdef GPIO_CAMERA_FLASH_EN_PIN
101 #define GPIO_ENF GPIO_CAMERA_FLASH_EN_PIN
103 #define GPIO_ENF 0xFF
106 #ifdef GPIO_CAMERA_FLASH_MODE_PIN
107 #define GPIO_ENT GPIO_CAMERA_FLASH_MODE_PIN
108 #define GPIO_ENT_IS_AVALIABLE 1
110 #define GPIO_ENT 0xFF
111 #define GPIO_ENT_IS_AVALIABLE 0
117 extern int iWriteRegI2C(u8
*a_pSendData
, u16 a_sizeSendData
, u16 i2cId
);
118 extern int iReadRegI2C(u8
*a_pSendData
, u16 a_sizeSendData
, u8
* a_pRecvData
, u16 a_sizeRecvData
, u16 i2cId
);
119 static void work_timeOutFunc(struct work_struct
*data
);
139 mt_set_gpio_out(GPIO_ENT
,GPIO_OUT_ONE
);
140 mt_set_gpio_out(GPIO_ENF
,GPIO_OUT_ZERO
);
142 #if GPIO_ENT_IS_AVALIABLE
143 mt_set_gpio_out(GPIO_ENT
,GPIO_OUT_ZERO
);
145 mt_set_gpio_out(GPIO_ENF
,GPIO_OUT_ONE
);
147 PK_DBG(" FL_Enable line=%d\n",__LINE__
);
151 #if GPIO_ENT_IS_AVALIABLE
152 mt_set_gpio_out(GPIO_ENT
,GPIO_OUT_ZERO
);
154 mt_set_gpio_out(GPIO_ENF
,GPIO_OUT_ONE
);
155 PK_DBG(" FL_Enable line=%d\n",__LINE__
);
163 #if GPIO_ENT_IS_AVALIABLE
164 mt_set_gpio_out(GPIO_ENT
,GPIO_OUT_ZERO
);
166 mt_set_gpio_out(GPIO_ENF
,GPIO_OUT_ZERO
);
167 PK_DBG(" FL_Disable line=%d\n",__LINE__
);
171 int FL_dim_duty(kal_uint32 duty
)
174 PK_DBG(" FL_dim_duty line=%d\n",__LINE__
);
182 PK_DBG(" FL_Init - start line=%d\n",__LINE__
);
183 PK_DBG(" GPIO_ENF=0x%x, GPIO_MODE_00=0x%x \n",GPIO_ENF
,GPIO_MODE_00
);
185 if (mt_set_gpio_mode(GPIO_ENF
,GPIO_MODE_00
))
187 PK_DBG("[constant_flashlight] set gpio mode failed!! \n");
189 if (mt_set_gpio_dir(GPIO_ENF
,GPIO_DIR_OUT
))
191 PK_DBG("[constant_flashlight] set gpio dir failed!! \n");
193 if (mt_set_gpio_out(GPIO_ENF
,GPIO_OUT_ZERO
))
195 PK_DBG("[constant_flashlight] set gpio failed!! \n");
199 #if GPIO_ENT_IS_AVALIABLE
200 PK_DBG(" FL_Init - start line=%d\n",__LINE__
);
201 if (mt_set_gpio_mode(GPIO_ENT
,GPIO_MODE_00
))
203 PK_DBG("[constant_flashlight] set gpio mode failed!! \n");
205 if (mt_set_gpio_dir(GPIO_ENT
,GPIO_DIR_OUT
))
207 PK_DBG("[constant_flashlight] set gpio dir failed!! \n");
209 if (mt_set_gpio_out(GPIO_ENT
,GPIO_OUT_ZERO
))
211 PK_DBG("[constant_flashlight] set gpio failed!! \n");
214 INIT_WORK(&workTimeOut
, work_timeOutFunc
);
215 PK_DBG(" FL_Init - end line=%d\n",__LINE__
);
226 /*****************************************************************************
228 *****************************************************************************/
230 static void work_timeOutFunc(struct work_struct
*data
)
233 PK_DBG("ledTimeOut_callback\n");
234 //printk(KERN_ALERT "work handler function./n");
239 enum hrtimer_restart
ledTimeOutCallback(struct hrtimer
*timer
)
241 schedule_work(&workTimeOut
);
242 return HRTIMER_NORESTART
;
244 static struct hrtimer g_timeOutTimer
;
247 g_timeOutTimeMs
=1000; //1s
248 hrtimer_init( &g_timeOutTimer
, CLOCK_MONOTONIC
, HRTIMER_MODE_REL
);
249 g_timeOutTimer
.function
=ledTimeOutCallback
;
255 static int constant_flashlight_ioctl(MUINT32 cmd
, MUINT32 arg
)
261 ior_shift
= cmd
- (_IOR(FLASHLIGHT_MAGIC
,0, int));
262 iow_shift
= cmd
- (_IOW(FLASHLIGHT_MAGIC
,0, int));
263 iowr_shift
= cmd
- (_IOWR(FLASHLIGHT_MAGIC
,0, int));
264 PK_DBG("constant_flashlight_ioctl() line=%d ior_shift=%d, iow_shift=%d iowr_shift=%d arg=%d\n",__LINE__
, ior_shift
, iow_shift
, iowr_shift
, arg
);
268 case FLASH_IOC_SET_TIME_OUT_TIME_MS
:
269 PK_DBG("FLASH_IOC_SET_TIME_OUT_TIME_MS: %d\n",arg
);
274 case FLASH_IOC_SET_DUTY
:
275 PK_DBG("FLASHLIGHT_DUTY: %d\n",arg
);
280 case FLASH_IOC_SET_STEP
:
281 PK_DBG("FLASH_IOC_SET_STEP: %d\n",arg
);
285 case FLASH_IOC_SET_ONOFF
:
286 PK_DBG("FLASHLIGHT_ONOFF: %d\n",arg
);
289 if (g_timeOutTimeMs
!=0)
292 ktime
= ktime_set( 0, g_timeOutTimeMs
*1000000 );
293 hrtimer_start( &g_timeOutTimer
, ktime
, HRTIMER_MODE_REL
);
300 hrtimer_cancel( &g_timeOutTimer
);
304 PK_DBG(" No such command \n");
314 static int constant_flashlight_open(void *pArg
)
317 PK_DBG("constant_flashlight_open line=%d\n", __LINE__
);
324 PK_DBG("constant_flashlight_open line=%d\n", __LINE__
);
325 spin_lock_irq(&g_strobeSMPLock
);
339 spin_unlock_irq(&g_strobeSMPLock
);
340 PK_DBG("constant_flashlight_open line=%d\n", __LINE__
);
347 static int constant_flashlight_release(void *pArg
)
349 PK_DBG(" constant_flashlight_release\n");
353 spin_lock_irq(&g_strobeSMPLock
);
361 spin_unlock_irq(&g_strobeSMPLock
);
373 FLASHLIGHT_FUNCTION_STRUCT constantFlashlightFunc
=
375 constant_flashlight_open
,
376 constant_flashlight_release
,
377 constant_flashlight_ioctl
381 MUINT32
constantFlashlightInit(PFLASHLIGHT_FUNCTION_STRUCT
*pfFunc
)
385 *pfFunc
= &constantFlashlightFunc
;
392 /* LED flash control for high current capture mode*/
393 ssize_t
strobe_VDIrq(void)
399 EXPORT_SYMBOL(strobe_VDIrq
);