微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > 求助闪光灯不亮

求助闪光灯不亮

时间:10-02 整理:3721RD 点击:
如题。MT6582  kk版本,闪光灯不亮,通过log分析,下面这个函数跑的流程是default,请问遇到的同仁是什么原因导致上层传的参数不对?万分感谢!
static int constant_flashlight_ioctl(MUINT32 cmd, MUINT32 arg)
{
int i4RetValue = 0;
int ior_shift;
int iow_shift;
int iowr_shift;
ior_shift = cmd - (_IOR(FLASHLIGHT_MAGIC,0, int));
iow_shift = cmd - (_IOW(FLASHLIGHT_MAGIC,0, int));
iowr_shift = cmd - (_IOWR(FLASHLIGHT_MAGIC,0, int));
printk("swordking in 82 %s  @%d cmd = %d\n",__func__,__LINE__,cmd);
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);
    switch(cmd)
    {
  case FLASH_IOC_SET_TIME_OUT_TIME_MS:
    printk("swordking in 82 %s  %d\n",__func__,__LINE__);
   PK_DBG("FLASH_IOC_SET_TIME_OUT_TIME_MS: %d\n",arg);
   g_timeOutTimEMS=arg;
  break;
     case FLASH_IOC_SET_DUTY :
    printk("swordking in 82 %s  %d\n",__func__,__LINE__);
      PK_DBG("FLASHLIGHT_DUTY: %d\n",arg);
      FL_dim_duty(arg);
      break;
     case FLASH_IOC_SET_STEP:
    printk("swordking in 82 %s  %d\n",__func__,__LINE__);
      PK_DBG("FLASH_IOC_SET_STEP: %d\n",arg);
      break;
     case FLASH_IOC_SET_ONOFF :
    printk("swordking in 82 %s  %d\n",__func__,__LINE__);
      PK_DBG("FLASHLIGHT_ONOFF: %d\n",arg);
      if(arg==1)
      {
       printk("swordking in 82 %s  %d\n",__func__,__LINE__);
    if(g_timeOutTimeMs!=0)
             {
              ktime_t ktime;
      printk("swordking in 82 %s  %d\n",__func__,__LINE__);
     ktime = ktime_set( 0, g_timeOutTimeMs*1000000 );
     hrtimer_start( &g_timeOutTimer, ktime, HRTIMER_MODE_REL );
             }
       FL_Enable();
      }
      else
      {
       printk("swordking in 82 %s  %d\n",__func__,__LINE__);
       FL_Disable();
    hrtimer_cancel( &g_timeOutTimer );
      }
      break;
  default :
    printk("swordking in 82 %s  %d\n",__func__,__LINE__);
      PK_DBG(" No such command \n");
      i4RetValue = -EPERM;
      break;
    }

我也遇到这个问题了,您遇到这个问题已经过了将近一年了,想必早已解决了吧,可以帮忙回答我一下吗?万分感谢!

驱动发给我看下

  1. #include <linux/kernel.h>
  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>
  7. #include <linux/fs.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"
  18. #include <asm/io.h>
  19. #include <asm/uaccess.h>
  20. #include "kd_camera_hw.h"
  21. #include <linux/hrtimer.h>
  22. #include <linux/ktime.h>
  23. #include <linux/xlog.h>
  24. #include <mach/upmu_common.h>

  25. #include <mach/mt_gpio.h>                // For gpio control

  26. /******************************************************************************
  27. * Debug configuration
  28. ******************************************************************************/
  29. // availible parameter
  30. // ANDROID_LOG_ASSERT
  31. // ANDROID_LOG_ERROR
  32. // ANDROID_LOG_WARNING
  33. // ANDROID_LOG_INFO
  34. // ANDROID_LOG_DEBUG
  35. // ANDROID_LOG_VERBOSE
  36. #define TAG_NAME "leds_strobe.c"
  37. #define PK_DBG_NONE(fmt, arg...)    do {} while (0)
  38. #define PK_DBG_FUNC(fmt, arg...)    xlog_printk(ANDROID_LOG_DEBUG  , TAG_NAME, KERN_INFO  "%s: " fmt, __FUNCTION__ ,##arg)
  39. #define PK_WARN(fmt, arg...)        xlog_printk(ANDROID_LOG_WARNING, TAG_NAME, KERN_WARNING  "%s: " fmt, __FUNCTION__ ,##arg)
  40. #define PK_NOTICE(fmt, arg...)      xlog_printk(ANDROID_LOG_DEBUG  , TAG_NAME, KERN_NOTICE  "%s: " fmt, __FUNCTION__ ,##arg)
  41. #define PK_INFO(fmt, arg...)        xlog_printk(ANDROID_LOG_INFO   , TAG_NAME, KERN_INFO  "%s: " fmt, __FUNCTION__ ,##arg)
  42. #define PK_TRC_FUNC(f)              xlog_printk(ANDROID_LOG_DEBUG  , TAG_NAME,  "<%s>\n", __FUNCTION__);
  43. #define PK_TRC_VERBOSE(fmt, arg...) xlog_printk(ANDROID_LOG_VERBOSE, TAG_NAME,  fmt, ##arg)
  44. #define PK_ERROR(fmt, arg...)       xlog_printk(ANDROID_LOG_ERROR  , TAG_NAME, KERN_ERR "%s: " fmt, __FUNCTION__ ,##arg)


  45. #define DEBUG_LEDS_STROBE
  46. #ifdef  DEBUG_LEDS_STROBE
  47.         #define PK_DBG PK_DBG_FUNC
  48.         #define PK_VER PK_TRC_VERBOSE
  49.         #define PK_ERR PK_ERROR
  50. #else
  51.         #define PK_DBG(a,...)
  52.         #define PK_VER(a,...)
  53.         #define PK_ERR(a,...)
  54. #endif

  55. /******************************************************************************
  56. * local variables
  57. ******************************************************************************/
  58. static DEFINE_SPINLOCK(g_strobeSMPLock);
  59. static u32 strobe_Res = 0;
  60. static BOOL g_strobe_On = 0;
  61. static int g_duty=-1;
  62. static int g_step=-1;
  63. static int g_timeOutTimeMs=0;

  64. static struct work_struct workTimeOut;
  65. /*****************************************************************************
  66. Functions
  67. *****************************************************************************/
  68. static void work_timeOutFunc(struct work_struct *data);

  69. #define LEDS_TORCH_MODE                 0
  70. #define LEDS_FLASH_MODE                 1
  71. #define LEDS_CUSTOM_MODE_THRES         20

  72. #ifndef GPIO_CAMERA_FLASH_EN_PIN
  73. #define GPIO_CAMERA_FLASH_EN_PIN GPIO24
  74. #endif

  75. #ifndef GPIO_CAMERA_FLASH_EN_PIN_M_GPIO
  76. #define GPIO_CAMERA_FLASH_EN_PIN_M_GPIO GPIO_MODE_00
  77. #endif

  78. #ifndef GPIO_CAMERA_FLASH_MODE_PIN
  79. #define GPIO_CAMERA_FLASH_MODE_PIN GPIO25
  80. #endif

  81. #ifndef GPIO_CAMERA_FLASH_MODE_PIN_M_GPIO
  82. #define GPIO_CAMERA_FLASH_MODE_PIN_M_GPIO GPIO_MODE_00
  83. #endif

  84. int FL_enable(void)
  85. {
  86.         PK_DBG("FL_enable");
  87.         mt_set_gpio_out(GPIO_CAMERA_FLASH_EN_PIN, 1);

  88. //        upmu_set_rg_bst_drv_1m_ck_pdn(0);
  89. //        upmu_set_flash_en(1);
  90.     return 0;
  91. }

  92. int FL_disable(void)
  93. {
  94.         PK_DBG("FL_disable");
  95.         mt_set_gpio_out(GPIO_CAMERA_FLASH_EN_PIN, 0);
  96. //        upmu_set_flash_en(0);
  97.         //upmu_set_rg_bst_drv_1m_ck_pdn(1);
  98.     return 0;
  99. }

  100. int FL_dim_duty(kal_uint32 duty)
  101. {
  102.         PK_DBG("FL_dim_duty %d, thres %d", duty, LEDS_CUSTOM_MODE_THRES);

  103.         if(duty < LEDS_CUSTOM_MODE_THRES)
  104.                 mt_set_gpio_out(GPIO_CAMERA_FLASH_MODE_PIN, LEDS_TORCH_MODE);
  105.         else
  106.                 mt_set_gpio_out(GPIO_CAMERA_FLASH_MODE_PIN, LEDS_FLASH_MODE);

  107.         if((g_timeOutTimeMs == 0) && (duty > LEDS_CUSTOM_MODE_THRES))
  108.         {
  109.                 PK_ERR("FL_dim_duty %d > thres %d, FLASH mode but timeout %d", duty, LEDS_CUSTOM_MODE_THRES, g_timeOutTimeMs);
  110.                 mt_set_gpio_out(GPIO_CAMERA_FLASH_MODE_PIN, LEDS_TORCH_MODE);
  111.         }
  112. //        upmu_set_flash_dim_duty(duty);
  113.     return 0;
  114. }

  115. int FL_step(kal_uint32 step)
  116. {
  117.         //int sTab[8]={0,2,4,6,9,11,13,15};
  118.         PK_DBG("FL_step");
  119. //        upmu_set_flash_sel(sTab[step]);
  120.     return 0;
  121. }

  122. int FL_init(void)
  123. {
  124. //        upmu_set_flash_dim_duty(0);
  125. //        upmu_set_flash_sel(0);
  126.         PK_DBG("FL_init");

  127.         mt_set_gpio_mode(GPIO_CAMERA_FLASH_EN_PIN, GPIO_CAMERA_FLASH_EN_PIN_M_GPIO);
  128.         mt_set_gpio_mode(GPIO_CAMERA_FLASH_MODE_PIN, GPIO_CAMERA_FLASH_MODE_PIN_M_GPIO);

  129.         //FL_disable();
  130.         FL_enable();
  131.         INIT_WORK(&workTimeOut, work_timeOutFunc);
  132.     return 0;
  133. }

  134. int FL_uninit(void)
  135. {
  136.         PK_DBG("FL_uninit");

  137.         FL_disable();
  138.     return 0;
  139. }

  140. /*****************************************************************************
  141. User interface
  142. *****************************************************************************/
  143. static void work_timeOutFunc(struct work_struct *data)
  144. {
  145.         FL_disable();
  146.     PK_DBG("ledTimeOut_callback\n");
  147.     //printk(KERN_ALERT "work handler function./n");
  148. }
  149. enum hrtimer_restart ledTimeOutCallback(struct hrtimer *timer)
  150. {
  151.         PK_DBG("ledTimeOut_callback\n");
  152.         schedule_work(&workTimeOut);

  153.     return HRTIMER_NORESTART;
  154. }
  155. static struct hrtimer g_timeOutTimer;
  156. void timerInit(void)
  157. {
  158.         g_timeOutTimeMs=1000; //1s
  159.         hrtimer_init( &g_timeOutTimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL );
  160.         g_timeOutTimer.function=ledTimeOutCallback;

  161. }

  162. static int constant_flashlight_ioctl(MUINT32 cmd, MUINT32 arg)
  163. {
  164.         int i4RetValue = 0;
  165.         int iFlashType = (int)FLASHLIGHT_NONE;
  166.         int ior;
  167.         int iow;
  168.         int iowr;
  169.         ior = _IOR(FLASHLIGHT_MAGIC,0, int);
  170.         iow = _IOW(FLASHLIGHT_MAGIC,0, int);
  171.         iowr = _IOWR(FLASHLIGHT_MAGIC,0, int);
  172.         PK_DBG("constant_flashlight_ioctl() line=%x cmd=%x, ior=%x, iow=%x iowr=%x arg=%x\n",__LINE__, cmd, ior, iow, iowr, arg);
  173.         //PK_DBG("constant_flashlight_ioctl() line=%x cmd-ior=%x, cmd-iow=%x cmd-iowr=%x arg=%x\n",__LINE__, cmd-ior, cmd-iow, cmd-iowr, arg);
  174.         PK_DBG("constant_flashlight_ioctl() line=%d cmd=%d, ior=%d, iow=%d iowr=%d arg=%d\n",__LINE__, cmd, ior, iow, iowr, arg);
  175.         PK_DBG("constant_flashlight_ioctl() line=%d cmd-ior=%d, cmd-iow=%d cmd-iowr=%d arg=%d\n",__LINE__, cmd-ior, cmd-iow, cmd-iowr, arg);
  176.         PK_DBG("constant_flashlight_ioctl() FLASH_IOC_SET_TIME_OUT_TIME_MS=%x FLASH_IOC_SET_DUTY=%x, FLASH_IOC_SET_STEP=%x, FLASH_IOC_SET_ONOFF=%x FLASHLIGHTIOC_G_FLASHTYPE=%x arg=%x\n",FLASH_IOC_SET_TIME_OUT_TIME_MS, FLASH_IOC_SET_DUTY, FLASH_IOC_SET_STEP, FLASH_IOC_SET_ONOFF, FLASHLIGHTIOC_G_FLASHTYPE, arg);
  177.        
  178.     switch(cmd)
  179.     {

  180.                 case FLASH_IOC_SET_TIME_OUT_TIME_MS:
  181.                         PK_DBG("FLASH_IOC_SET_TIME_OUT_TIME_MS: %d\n",arg);
  182.                         g_timeOutTimeMs=arg;
  183.                         break;

  184.             case FLASH_IOC_SET_DUTY :
  185.                     PK_DBG("FLASHLIGHT_DUTY: %d\n",arg);
  186.                     g_duty=arg;
  187.                     FL_dim_duty(arg);
  188.                     break;

  189.             case FLASH_IOC_SET_STEP:
  190.                     PK_DBG("FLASH_IOC_SET_STEP: %d\n",arg);
  191.                     g_step=arg;
  192.                     FL_step(arg);
  193.                     break;

  194.             case FLASH_IOC_SET_ONOFF :
  195.                     PK_DBG("FLASHLIGHT_ONOFF: %d\n",arg);
  196.                     if(arg==1)
  197.                     {
  198.                                 if(g_timeOutTimeMs!=0)
  199.                     {
  200.                             ktime_t ktime;
  201.                                         ktime = ktime_set( 0, g_timeOutTimeMs*1000000 );
  202.                                         hrtimer_start( &g_timeOutTimer, ktime, HRTIMER_MODE_REL );
  203.                     }
  204.                             FL_enable();
  205.                             g_strobe_On=1;
  206.                     }
  207.                     else
  208.                     {
  209.                             FL_disable();
  210.                                 hrtimer_cancel( &g_timeOutTimer );
  211.                                 g_strobe_On=0;
  212.                     }
  213.                     break;
  214.         case FLASHLIGHTIOC_G_FLASHTYPE:
  215.             iFlashType = FLASHLIGHT_LED_CONSTANT;
  216.             if(copy_to_user((void __user *) arg , (void*)&iFlashType , _IOC_SIZE(cmd)))
  217.             {
  218.                 PK_DBG("[strobe_ioctl] ioctl copy to user failed\n");
  219.                 return -EFAULT;
  220.             }
  221.             break;
  222.                 default :
  223.                     PK_DBG(" No such command \n");
  224.                     i4RetValue = -EPERM;
  225.                     break;
  226.     }
  227.     return i4RetValue;
  228. }

  229. static int constant_flashlight_open(void *pArg)
  230. {
  231.     int i4RetValue = 0;
  232.     PK_DBG("constant_flashlight_open line=%d\n", __LINE__);

  233.         if (0 == strobe_Res)
  234.         {
  235.             FL_init();
  236.                 timerInit();
  237.         }
  238.         spin_lock_irq(&g_strobeSMPLock);

  239.     if(strobe_Res)
  240.     {
  241.         PK_ERR(" busy!\n");
  242.         i4RetValue = -EBUSY;
  243.     }
  244.     else
  245.     {
  246.         strobe_Res += 1;
  247.     }

  248.     spin_unlock_irq(&g_strobeSMPLock);

  249.     return i4RetValue;

  250. }

  251. static int constant_flashlight_release(void *pArg)
  252. {
  253.     PK_DBG(" constant_flashlight_release\n");

  254.     if (strobe_Res)
  255.     {
  256.         spin_lock_irq(&g_strobeSMPLock);

  257.         strobe_Res = 0;

  258.         /* LED On Status */
  259.         g_strobe_On = FALSE;

  260.         spin_unlock_irq(&g_strobeSMPLock);

  261.             FL_uninit();
  262.     }

  263.     PK_DBG(" Done\n");

  264.     return 0;

  265. }

  266. FLASHLIGHT_FUNCTION_STRUCT        constantFlashlightFunc=
  267. {
  268.         constant_flashlight_open,
  269.         constant_flashlight_release,
  270.         constant_flashlight_ioctl
  271. };

  272. MUINT32 constantFlashlightInit(PFLASHLIGHT_FUNCTION_STRUCT *pfFunc)
  273. {
  274.     if (pfFunc != NULL)
  275.     {
  276.         *pfFunc = &constantFlashlightFunc;
  277.     }
  278.     return 0;
  279. }

  280. /* LED flash control for high current capture mode*/
  281. ssize_t strobe_VDIrq(void)
  282. {

  283.     return 0;
  284. }

  285. EXPORT_SYMBOL(strobe_VDIrq);

复制代码

case FLASHLIGHTIOC_G_FLASHTYPE
1、ioctl的这个case跑到没?
2、需要确认闪光灯是不是好的?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top