RK3288 控制usb摄像头补光GPIO

正常可以通过添加dts配置,再从设备树中读取gpio号,在这里为了简单,直接使用GPIO号,先通过终端测试gpio,


系统自带GPIO控制驱动:
内核已经自带了通用GPIO驱动,可以直接在用户空间操作.
路径: /sys/class/gpio
root@rk3288:/sys/class/gpio # ls
export
gpiochip0
gpiochip120
gpiochip152
gpiochip184
gpiochip216
gpiochip24
gpiochip248
gpiochip280
gpiochip56
gpiochip88
unexport

比如我要操作GPIO8_A6作为高电平输出有效, 那么有以下问题:
1. 对应的gpio number是多少呢?
2. 如何设置成输出
3. 如何输出高电平

问题1:
可以通过/sys/kernel/debug/gpio查询信息:
root@rk3288:/sys/kernel/debug # cat gpio                                       
//snip
GPIOs 184-215, platform/ff770000.pinctrl, gpio6:
 gpio-193 (?                   ) in  hi
 gpio-194 (?                   ) in  hi

GPIOs 216-247, platform/ff770000.pinctrl, gpio7:
 gpio-218 (enable              ) out hi
 gpio-219 (lcd_en              ) in  hi
 gpio-220 (lcd_cs              ) in  hi
 gpio-221 (gslX680 wake pin    ) out hi
 gpio-222 (gslX680 irq pin     ) out lo
 gpio-223 (headset_gpio        ) in  hi
 gpio-233 (?                   ) in  hi
 gpio-234 (?                   ) in  hi

GPIOs 248-279, platform/ff770000.pinctrl, gpio8:

GPIOs 280-311, platform/ff770000.pinctrl, gpio15:

可以看到gpio8是以nubmer为248开始, 那么GPIO8_A6就是 248 + 6 = 254
接下来就可以导出gpio了
root@rk3288:/sys/class/gpio # echo 254 > export                          
root@rk3288:/sys/class/gpio # ls
export
gpio254
......

问题2
root@rk3288:/sys/class/gpio/gpio254 # echo out > direction                     
root@rk3288:/sys/class/gpio/gpio254 # cat direction                            
out

问题3:
root@rk3288:/sys/class/gpio/gpio254 # echo 1 > value                           
root@rk3288:/sys/class/gpio/gpio254 # cat value                                
1

 


打开后置摄像头时打开led补光

初始化led补光GPIO口,在注册后置usb摄像头时申请gpio
/work/rk3288/firefly-rk3288_android5.1_git_20180126/kernel/drivers/media/usb/uvc/uvc_driver.c

/* carroll add led gpio start */
#define FILL_LIGHT_GPIO 233
/* carroll add led gpio end */

static int uvc_register_video(struct uvc_device *dev,
        struct uvc_streaming *stream)
{
     /* carroll add led gpio start */
    static bool led_init_flag = true;
    /* carroll add led gpio end */

    ................

    stream->vdev = vdev;
    video_set_drvdata(vdev, stream);

     /* carroll add usb deice num start */
     vdev->portnum = dev->udev->portnum;
     /* carroll add usb deice num end */

    ................

     /* carroll add led gpio start */
    if(vdev->portnum == 1 && led_init_flag == true)
    {
        printk("carroll led-camera-2 gpio init\n");
        ret = gpio_request(FILL_LIGHT_GPIO,  "led-camera-2");
        if (ret != 0) {
            printk("%s request led-camera_2_gpio error", __func__);
            return ret;
        }
        gpio_direction_output(FILL_LIGHT_GPIO, 1);
        led_init_flag = false;
    }
    /* carroll add led gpio end */

 

打开后置usb摄像头和关闭摄像头时修改gpio值
/work/rk3288/firefly-rk3288_android5.1_git_20180126/kernel/drivers/media/usb/uvc/uvc_v4l2.c

/* carroll add led gpio start */
#define FILL_LIGHT_GPIO 233
/* carroll add led gpio end */
static int uvc_v4l2_open(struct file *file)
{
    ...........
    /* carroll add led gpio start */
    if(stream->dev->udev->portnum == 1)
    {
        gpio_set_value(FILL_LIGHT_GPIO, 0);
        printk("carroll led on \n");
    }
    /* carroll add led gpio end */
    
    return 0;
}

static int uvc_v4l2_release(struct file *file)
{
    ...........
    /* carroll add led gpio start */
    if(stream->dev->udev->portnum == 1)
    {
        gpio_set_value(FILL_LIGHT_GPIO, 1);
        printk("carroll led off \n");
    }
     /* carroll add led gpio end */    

    return 0;
}

 

 

参考:

https://blog.csdn.net/kris_fei/article/details/69553422

转载于:https://www.cnblogs.com/CZM-/p/9584566.html

你可能感兴趣的:(RK3288 控制usb摄像头补光GPIO)