目录
一、MTK平台的GPIO配置
1. MTK平台GPIO驱动程序提供了两个接口:
2.配置dws文件
3.配置dts文件
二、MTK平台camera模块的GPIO配置
(1)内核空间:所提供的GPIO驱动程序,驱动程序可以调用其他函数,比如mt_set_gpio_dir、mt_set_gpio_mode等;
(2)用户空间:用户空间的程序可以通过发送IOCTL给/dev/ mtgpio的操作GPIO,如open、ioctl、write、read和close等函数。
在搭载MTK平台的机器中查看本机的GPIO配置,可以使用如下命令
adb shell
cat /proc/kmsg
cat /sys/devices/platform/pinctrl/mt_gpio
(以具体的mt_gpio路径为准,可以先使用find sys/ -name "mt_gpio"进行查找)
一般来说,GPIO引脚功能复用每个GPIO引脚支持四种模式,可作为EINT、GPIO、或I2C、SPI等,通过GPIO_MODE进行选择。每个GPIO可以配置的模式可以参考这个头文件kernel-4.X/arch/arm64/boot/dts/mediatek/mtXXXX-pinfunc.h。
GPIO_DIR:GPIO模式下,可配置为控制输入输出方向,置0是input,置1是output。在MTK平台的GPIO表的mode中,会看到有B(for both,既可设为输入也可设为输出),O(for output only),I0(for input only,作为输入且为低电平),I1(作为输入且为高电平)。
GPIO_DIN:通过访问寄存器可以得知输入的是高电平还是低电平
GPIO_DOUT:在引脚被配置为output后,控制输出高低电平
GPIO_PULLEN:是否支持上下拉,GPIO作为输入模式时生效。
mtk的文档给的框图中没有标全,还有设置上下拉,SMT等属性。不过,在cat mt_gpio的时候会打印全相关配置。
PULL_SEL:GPIO_PULLEN只设置了是否使能上拉或下拉,而这个属性设置是上拉还是下拉。0=下拉;1=上拉。上拉是一个电阻接到一个电压,其实就是增强了IO的驱动能力;下拉是一个电阻接到地,保证IO口是低电平;
IES:输入使能,控制输入是否有效。
SMT:是否使能斯密特触发器
DRIVE:驱动能力,一般可取值0~7
([R1] [R0]):当前GPIO pin的上下拉并联电阻的使能状态;
1 0表示enable R1,disable R0
0 1表示disable R1,enable R0
1 1表示enable R1,enable R0
没有打印表示当前GPIO pin不支持PUPD,即只有一个上拉电阻、一个下拉电阻。
使用vendor\mediatek\proprietary\scripts\dct中的DrvGen.exe,打开vendor\mediatek\ proprietary\bootable\bootloader\lk\target\{$project}\dct\dct下的codegen.dws进行GPIO等配置。
依次来看下GPIO的配置项:
EintMode:中断模式
Def.Mode:默认的模式,根据后面勾选的VarName1~3中选择默认模式
InPull En:是否支持上下拉
InPull Sel High:选择上拉还是下拉,勾选表示上拉
Def.Dir:input还是output
OutHigh:输出为高电平还是低电平
SMT#:SMT group
SMT:是否支持SMT(schmitt trigger)功能,波形过滤,输出方波或者脉冲波,延迟滞后具有消噪的功能,一般不用勾选。
IES:输入使能,控制输入是否有效,一般全选。
配置完成后点击保存会自动更新codegen.dws文件。
在kernel-4.*\arch\arm64\boot\dts\mediatek目录下的dts文件中设置pinctrl。
&device{
......
pinctrl-names = "aaa","bbb","ccc";
pinctrl-0 = <&xxx>;
pinctrl-1 = <&yyy>;
pinctrl-2 = <&zzz>;
......
};
&pio {
xxx: config0 {
pins_cmd_dat {
pins = ;
//设置GPIO mode,在boot/dts/中mtxxxx-pinfunc.h里有定义
slew-rate = <0>;
//设置GPIO dir,0为input,1为output
bias-pull-down = <11>;
//设置pull enable,下拉,后面的11并无影响,写00也可以
input-schmitt-enable = <0>;
//设置SMT enable
};
};
yyy: config1 {
pins_cmd_dat {
pins = ;
slew-rate = <1>;
bias-pull-up = <11>;
output-low; //设置低电平输出,只有在slew-rate设为1时才有效
//output-high就是设置为高电平输出
input-schmitt-enable = <0>;
};
};
zzz: config2 {
pins_cmd_dat {
pins = ;
slew-rate = <1>;
bias-disable;
//无上下拉设置,不能与bias-pull-down/up共存
output-low;
input-schmitt-enable = <0>;
};
};
};
这边以在MT8766_Q0平台配置为例。在确认codegen.dws与所在平台的GPIO配置一致后,还要注意各引脚在上电文件及dtsi中的配置是否正确。下面以添加一个新的regulator电源为例,当要配置一个GPIO电源时步骤大致相同,只是忽略5、6、7这三条操作,并将添加的语句中的regulator字眼都替换为gpio。
该平台在kernel-4.*/drivers/misc/mediatek/imgsensor/src/mt6***/camera_hw/regulator/ regulator.c中默认写了三组regulator的pin
struct REGULATOR_CTRL regulator_control[REGULATOR_TYPE_MAX_NUM] = {
{"vcama"},
{"vcamd"},
{"vcamio"},
};
假设需要添加一个regulator电源,需要在以下文件中做如下工作:
1.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\gpio\gpio.c
2.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\gpio\gpio.h
3.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\imgsensor_cfg_table.c
4.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\imgsensor_cfg_table.h
5.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\regulator\regulator.c
6.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\regulator\regulator.h
7.8.kernel-4.*\arch\arm64\boot\dts\mediatek\cust_mt6XXX_camera.dtsi
要注意所有文件中添加的相对位置要保持一致
1. kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\gpio\gpio.c
struct GPIO_PINCTRL gpio_pinctrl_list_cam[
GPIO_CTRL_STATE_MAX_NUM_CAM] = {
/* Main */
{"pnd1"},
{"pnd0"},
{"rst1"},
{"rst0"},
{"ldo_vcama_1"},
{"ldo_vcama_0"},
+{"ldo_vcamio_1p8_1"}, //add
+{"ldo_vcamio_1p8_0"}, //add
{"ldo_vcamd_1"},
{"ldo_vcamd_0"},
{"ldo_vcamio_1"},
{"ldo_vcamio_0"},
};
2. kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\gpio\gpio.h
enum GPIO_CTRL_STATE_CAM {
/* Main */
GPIO_CTRL_STATE_PDN_H,
GPIO_CTRL_STATE_PDN_L,
GPIO_CTRL_STATE_RST_H,
GPIO_CTRL_STATE_RST_L,
GPIO_CTRL_STATE_LDO_VCAMA_H,
GPIO_CTRL_STATE_LDO_VCAMA_L,
+ GPIO_CTRL_STATE_LDO_VCAMIO_1P8_H, //add
+ GPIO_CTRL_STATE_LDO_VCAMIO_1P8_L, //add
GPIO_CTRL_STATE_LDO_VCAMD_H,
GPIO_CTRL_STATE_LDO_VCAMD_L,
GPIO_CTRL_STATE_LDO_VCAMIO_H,
GPIO_CTRL_STATE_LDO_VCAMIO_L,
GPIO_CTRL_STATE_MAX_NUM_CAM,
};
3. kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\imgsensor_cfg_table.c
struct IMGSENSOR_HW_CFG imgsensor_custom_config[] = {
{
IMGSENSOR_SENSOR_IDX_MAIN,
IMGSENSOR_I2C_DEV_0,
{
{IMGSENSOR_HW_PIN_MCLK, IMGSENSOR_HW_ID_MCLK},
{IMGSENSOR_HW_PIN_AVDD, IMGSENSOR_HW_ID_GPIO},
+ {IMGSENSOR_HW_PIN_DOVDD_1P8, IMGSENSOR_HW_ID_REGULATOR}, //add
{IMGSENSOR_HW_PIN_DOVDD, IMGSENSOR_HW_ID_REGULATOR},
{IMGSENSOR_HW_PIN_DVDD, IMGSENSOR_HW_ID_GPIO},
{IMGSENSOR_HW_PIN_PDN, IMGSENSOR_HW_ID_GPIO},
{IMGSENSOR_HW_PIN_RST, IMGSENSOR_HW_ID_GPIO},
{IMGSENSOR_HW_PIN_NONE, IMGSENSOR_HW_ID_NONE},
},
},
...
};
//上电时序中
#if defined(*****_MIPI_RAW)
{
SENSOR_DRVNAME_*****_MIPI_RAW,
{
{RST, Vol_Low, 1},
{AVDD, Vol_2800, 0},
{DVDD, Vol_1200, 0},
+ {DOVDD_1P8, Vol_1800, 1}, //add
{SensorMCLK, Vol_High, 1},
{RST, Vol_High, 1}
},
},
4.kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\imgsensor_cfg_table.h
enum IMGSENSOR_HW_PIN {
IMGSENSOR_HW_PIN_NONE = 0,
IMGSENSOR_HW_PIN_PDN,
IMGSENSOR_HW_PIN_RST,
IMGSENSOR_HW_PIN_AVDD,
+IMGSENSOR_HW_PIN_DOVDD_1P8, //add
IMGSENSOR_HW_PIN_DVDD,
IMGSENSOR_HW_PIN_DOVDD,
#ifdef MIPI_SWITCH
IMGSENSOR_HW_PIN_MIPI_SWITCH_EN,
IMGSENSOR_HW_PIN_MIPI_SWITCH_SEL,
#endif
IMGSENSOR_HW_PIN_MCLK,
IMGSENSOR_HW_PIN_MAX_NUM,
IMGSENSOR_HW_PIN_UNDEF = -1
};
5. kernel-4.*\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\regulator\regulator.c
struct REGULATOR_CTRL regulator_control[REGULATOR_TYPE_MAX_NUM] = {
{"vcama"},
+{"vcamio_1p8"}, //add
{"vcamd"},
{"vcamio"},
};
若添加的位置在最后,regulator_set中,高亮位置记得做相应修改
static enum IMGSENSOR_RETURN regulator_set( void *pinstance, enum IMGSENSOR_SENSOR_IDX sensor_idx, enum IMGSENSOR_HW_PIN pin, enum IMGSENSOR_HW_PIN_STATE pin_state) { struct regulator *pregulator; struct REGULATOR *preg = (struct REGULATOR *)pinstance; int reg_type_offset; atomic_t *enable_cnt; if (pin > IMGSENSOR_HW_PIN_AFVDD || pin < IMGSENSOR_HW_PIN_AVDD || pin_state < IMGSENSOR_HW_PIN_STATE_LEVEL_0 || pin_state >= IMGSENSOR_HW_PIN_STATE_LEVEL_HIGH || sensor_idx < 0) return IMGSENSOR_RETURN_ERROR; ...... |
6.kernel-4.**\drivers\misc\mediatek\imgsensor\src\mt6***\camera_hw\regulator\regulator.h
enum REGULATOR_TYPE {
REGULATOR_TYPE_VCAMA,
+REGULATOR_TYPE_VCAMIO_1P8, //add
REGULATOR_TYPE_VCAMD,
REGULATOR_TYPE_VCAMIO,
REGULATOR_TYPE_MAX_NUM
};
7.kernel-4.14\arch\arm64\boot\dts\mediatek\cust_mt6XXX_camera.dtsi
cam0_vcama-supply = <&mt_pmic_vcama_ldo_reg>;
+cam0_vcamio_1p8-supply = <&mt_pmic_vcamio_ldo_reg>; //add
cam0_vcamd-supply = <&mt_pmic_vcamd_ldo_reg>;
cam0_vcamio-supply = <&mt_pmic_vcamio_ldo_reg>;
如果是GPIO口,这里需去掉相应代码,并在上方的pinctrl中添加相应代码。
8.同时,要确保项目所在的.dts文件中
&pio {
...
}
及&kd_camera_hw1里面没有该电源的配置。该配置中,只配置作为GPIO使用的引脚。也就是当添加一个GPIO电源时,要记得往里面添加一组配置。