TA的每日心情 | 郁闷 2024-9-18 16:57 |
---|
签到天数: 48 天 连续签到: 1 天 [LV.5]常住居民I
|
本帖最后由 eefocus_3828686 于 2022-8-26 19:37 编辑
在MTD-T507H开发板上调试gc5035,硬件设计见https://www.cirmall.com/bbs/thread-222755-1-1.html
1、配置驱动文件Makefile,路径为/home/myir/myd-t507h/t507h-sdk/t507/kernel/linux-4.9/drivers/media/platform/sunxi-vin/modules/sensor/Makefile,把把其余的sensor都注释掉,只留gc5035_mipi就行
- #obj-y += ov5640.o
- #obj-m += ov2775_mipi.o
- #obj-m += gc2145.o
- ##obj-m += gc0310_mipi.o
- ##obj-m += gc2355_mipi.o
- ##obj-m += gc030a_mipi.o
- ##obj-m += gc2385_mipi.o
- ##obj-m += gc5024_mipi.o
- #obj-m += imx214.o
- #obj-m += imx219.o
- #obj-m += imx274_slvds.o
- #obj-m += imx291_dvp.o
- #obj-m += imx291_mipi.o
- ##obj-m += imx317_mipi.o
- #obj-m += imx335_mipi.o
- #obj-m += imx326_mipi.o
- #obj-m += imx477_mipi.o
- #obj-m += ov2710_mipi.o
- #obj-m += ov2718_mipi.o
- #obj-m += ar0238.o
- #obj-m += imx278_mipi.o
- #obj-m += imx386_mipi.o
- #obj-m += s5k3h5xa.o
- #obj-m += ar0238_hispi.o
- #obj-m += nvp6134/
- ##obj-y += nvp6324/
- ##obj-y += nvp6158/
- ##obj-y += max9286_mipi.o
- ##obj-y += rn6854m_mipi.o
- ##obj-y += ov5640_mipi.o
- ##obj-y += ov5640_dvp.o
- #obj-m += tp9950.o
- obj-y += gc5035_mipi.o
- #obj-m += sc2232_mipi.o
复制代码 2、在路径/home/myir/myd-t507h/t507h-sdk/t507/kernel/myir-t5-kernel/drivers/media/platform/sunxi-vin/modules/sensor/添加gc5035_mipi.c文件,这里直接复制SDK里自带的gc5024_mipi.c为gc5035_mipi.c,姑且修改如下
- /*
- * A V4L2 driver for GC5035 Raw cameras.
- * 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.
- */
- #include <linux/init.h>
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <linux/i2c.h>
- #include <linux/delay.h>
- #include <linux/videodev2.h>
- #include <linux/clk.h>
- #include <media/v4l2-device.h>
- #include <media/v4l2-mediabus.h>
- #include <linux/io.h>
- #include "camera.h"
- #include "sensor_helper.h"
- #define SENSOR_DEBUG_INFO 1
- #if SENSOR_DEBUG_INFO == 1
- #define print_debug(fmt,...) \
- do{\
- printk("[DEBUG_INFO] <%s %s %d> ==> "fmt, __FILE__,__func__, __LINE__, ##__VA_ARGS__); \
- }while(0)
- #elif SENSOR_DEBUG_INFO == 0
- #define print_debug(fmt,...)
- #endif
- MODULE_AUTHOR("lwj");
- MODULE_DESCRIPTION("A low-level driver for GC5035 sensors");
- MODULE_LICENSE("GPL");
- #define MCLK (24*1000*1000)
- #define V4L2_IDENT_SENSOR 0x5035
- #define I2C_ADDR 0x6e
- #define SENSOR_NAME "gc5035_mipi"
复制代码 想看原有打印也可以打开/home/myir/myd-t507h/t507h-sdk/t507/kernel/linux-4.9/drivers/media/platform/sunxi-vin/modules/sensor/sensor_helper.h文件里的
gc5035_mipi.c里的函数改为如下,主要是PWR_ON要符合所用sensor的时序,这点很重要
- static int sensor_power(struct v4l2_subdev *sd, int on)
- {
- int ret = 0;
- print_debug("\n");
- switch (on) {
- case STBY_ON:
- sensor_dbg("STBY_ON!\n");
- if (ret < 0)
- usleep_range(10000, 12000);
- cci_lock(sd);
- vin_gpio_write(sd, PWDN, CSI_STBY_ON);
- cci_unlock(sd);
- break;
- case STBY_OFF:
- sensor_dbg("STBY_OFF!\n");
- cci_lock(sd);
- vin_set_mclk_freq(sd, MCLK);
- vin_set_mclk(sd, ON);
- usleep_range(10000, 12000);
- vin_gpio_write(sd, PWDN, CSI_STBY_OFF);
- usleep_range(10000, 12000);
- cci_unlock(sd);
- usleep_range(10000, 12000);
- break;
- case PWR_ON:
- sensor_dbg("PWR_ON!\n");
- cci_lock(sd);
- vin_gpio_write(sd, RESET, CSI_GPIO_LOW);
- vin_gpio_write(sd, PWDN, CSI_GPIO_LOW);
- usleep_range(1000, 1200);
- vin_set_mclk_freq(sd, MCLK);
- vin_set_mclk(sd, ON);
- usleep_range(10000, 12000);
- vin_set_pmu_channel(sd, CAMERAVDD, ON);
- vin_set_pmu_channel(sd, IOVDD, ON);
- vin_set_pmu_channel(sd, DVDD, ON);
- vin_set_pmu_channel(sd, AVDD, ON);
- usleep_range(5000, 6000);
- vin_gpio_write(sd, RESET, CSI_GPIO_HIGH);
- vin_gpio_write(sd, PWDN, CSI_GPIO_HIGH);
- usleep_range(1000, 1200); // >50us
- cci_unlock(sd);
- break;
- case PWR_OFF:
- sensor_dbg("PWR_OFF!\n");
- cci_lock(sd);
- vin_set_mclk(sd, OFF);
- vin_set_pmu_channel(sd, CAMERAVDD, OFF);
- vin_set_pmu_channel(sd, IOVDD, OFF);
- vin_set_pmu_channel(sd, DVDD, OFF);
- vin_set_pmu_channel(sd, AVDD, OFF);
- //vin_gpio_write(sd, RESET, CSI_GPIO_HIGH);
- //vin_gpio_write(sd, PWDN, CSI_GPIO_HIGH);
- usleep_range(1000, 1200);
- vin_set_mclk(sd, OFF);
- cci_unlock(sd);
- break;
- default:
- return -EINVAL;
- }
- return 0;
- }
复制代码 gc5035上电时序如下图
sensor_detect函数加打印,用来读取sensor ID的
- #define ID_REG_HIGH 0xf0
- #define ID_REG_LOW 0xf1
复制代码- static int sensor_detect(struct v4l2_subdev *sd)
- {
- data_type val = 0;
- print_debug("\n");
- sensor_read(sd, ID_REG_HIGH, &val);
- if (val != ID_VAL_HIGH)
- return -ENODEV;
- print_debug("ID_REG_HIGH: 0x%x\n", val);
- sensor_read(sd, ID_REG_LOW, &val);
- if (val != ID_VAL_LOW)
- return -ENODEV;
- print_debug("ID_REG_LOW : 0x%x\n", val);
- return 0;
- }
复制代码 函数sensor_init、sensor_reset、sensor_ioctl、sensor_probe都加上打印,方便看执行情况
3、设备树配置/home/myir/myd-t507h/t507h-sdk/t507/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/myir-yt507.dtsi
- sensor0:sensor@0 {
- device_type = "sensor0";
- #if 0
- sensor0_mname = "ov5640_mipi";
- sensor0_twi_cci_id = <0>;
- sensor0_twi_addr = <0x78>;
- #else
- sensor0_mname = "gc5035_mipi";// likw
- sensor0_twi_cci_id = <0>;
- sensor0_twi_addr = <0x6e>;
- #endif
- sensor0_mclk_id = <1>;
- sensor0_pos = "rear";
- sensor0_isp_used = <0>;
- sensor0_fmt = <0>;
- sensor0_stby_mode = <0>;
- sensor0_vflip = <0>;
- sensor0_hflip = <0>;
- sensor0_iovdd-supply = <®_bldo1>;
- sensor0_iovdd_vol = <1800000>;
- /*
- sensor0_avdd-supply = <®_cldo1>;
- sensor0_avdd_vol = <3300000>;
- sensor0_dvdd-supply = <®_bldo5>;
- sensor0_dvdd_vol = <1200000>;
- */
- sensor0_power_en = <&pio PC 7 1 0 1 1>;
- sensor0_reset = <&pio PC 12 1 0 1 0>;
- sensor0_pwdn = <&pio PC 2 1 0 1 1>;
- sensor0_sm_vs = <>;
- device_id = <0>;
- status = "okay";
- };
复制代码 sensor0_twi_addr = <0x6e>; 0x6e是gc5035的8位i2c地址值
4、编译烧录看现象,dmesg
可见gc5035驱动已经被运行,并且读出了sensor的ID值
dev目录下也已经生成了video节点
至此,MTD-T507H开发板和gc5035通信成功,后续再学习gc5035在MTD-T507H开发板的配置和具体调试。
|
|