20240620在飞凌OK3588-C的LINUX系统启动的时候拉高3个GPIO口141-111-120【方法二】
2024/6/20 9:05
缘起:在凌OK3588-C的LINUX R4系统启动的时候,需要拉高GPIO4_B5、GPIO3_B7和GPIO3_D0。
cat sys/kernel/debug/gpio
cat /sys/kernel/debug/pinctrl/pinctrl-rockchip-pinctrl/pinmux-pins
root@ok3588:/#
root@ok3588:/# cat sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/fd8a0000.gpio, gpio0:
gpio-0 ( |work ) out lo
gpio-4 ( |cd ) in hi ACTIVE LOW
gpio-24 ( |vbus5v0-typec0 ) out lo
gpio-27 ( |vbus5v0-typec1 ) out lo
gpiochip1: GPIOs 32-63, parent: platform/fec20000.gpio, gpio1:
gpio-38 ( |bt-wake ) out hi
gpio-44 ( |snps,reset ) out hi ACTIVE LOW
gpio-54 ( |vcc-5g ) out lo ACTIVE LOW
gpio-61 ( |hdmirx-det ) in hi ACTIVE LOW
gpiochip2: GPIOs 64-95, parent: platform/fec30000.gpio, gpio2:
gpio-84 ( |vcc3v3-sdmmc ) out hi
gpiochip3: GPIOs 96-127, parent: platform/fec40000.gpio, gpio3:
gpio-106 ( |dsi0-en ) out hi
gpio-113 ( |enable ) in lo
gpio-118 ( |dsi1-en ) out hi
gpiochip4: GPIOs 128-159, parent: platform/fec50000.gpio, gpio4:
gpio-128 ( |sbu1-dc ) out lo
gpio-129 ( |sbu1-dc ) out lo
gpio-130 ( |sbu2-dc ) out lo
gpio-136 ( |sbu2-dc ) out lo
gpio-137 ( |enable ) out hi
gpiochip5: GPIOs 509-511, parent: platform/rk806-pinctrl.1.auto, rk806-gpio, can sleep:
root@ok3588:/#
soot@ok3588:/# cat /sys/kernel/debug/pinctrl/pinctrl-rockchip-pinctrl/pinmux-pins
Pinmux settings per pin
Format: pin (name): mux_owner gpio_owner hog?
pin 0 (gpio0-0): leds gpio0:0 function leds_gpio group work-led-gpio
pin 110 (gpio3-14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 111 (gpio3-15): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 112 (gpio3-16): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 113 (gpio3-17): (MUX UNCLAIMED) gpio3:113
pin 114 (gpio3-18): fe1c0000.ethernet (GPIO UNCLAIMED) function gmac1 group gmac1-miim
pin 115 (gpio3-19): fe1c0000.ethernet (GPIO UNCLAIMED) function gmac1 group gmac1-miim
pin 116 (gpio3-20): fea70000.can (GPIO UNCLAIMED) function can2 group can2m0-pins
pin 117 (gpio3-21): fea70000.can (GPIO UNCLAIMED) function can2 group can2m0-pins
pin 118 (gpio3-22): dsi1-en gpio3:118 function lcd group mipi1-enable-gpio
pin 119 (gpio3-23): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 120 (gpio3-24): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 121 (gpio3-25): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 122 (gpio3-26): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 123 (gpio3-27): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 124 (gpio3-28): febc0000.serial (GPIO UNCLAIMED) function uart9 group uart9m2-xfer
pin 125 (gpio3-29): febc0000.serial (GPIO UNCLAIMED) function uart9 group uart9m2-xfer
pin 126 (gpio3-30): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 127 (gpio3-31): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 128 (gpio4-0): (MUX UNCLAIMED) gpio4:128
pin 129 (gpio4-1): (MUX UNCLAIMED) gpio4:129
pin 130 (gpio4-2): (MUX UNCLAIMED) gpio4:130
pin 131 (gpio4-3): fd890000.serial (GPIO UNCLAIMED) function uart0 group uart0m2-xfer
pin 132 (gpio4-4): fd890000.serial (GPIO UNCLAIMED) function uart0 group uart0m2-xfer
pin 133 (gpio4-5): feb60000.serial (GPIO UNCLAIMED) function uart3 group uart3m2-xfer
pin 134 (gpio4-6): feb60000.serial (GPIO UNCLAIMED) function uart3 group uart3m2-xfer
pin 135 (gpio4-7): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 136 (gpio4-8): (MUX UNCLAIMED) gpio4:136
pin 137 (gpio4-9): (MUX UNCLAIMED) gpio4:137
pin 138 (gpio4-10): fea60000.can (GPIO UNCLAIMED) function can1 group can1m1-pins
pin 139 (gpio4-11): fea60000.can (GPIO UNCLAIMED) function can1 group can1m1-pins
pin 140 (gpio4-12): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 141 (gpio4-13): (MUX UNCLAIMED) (GPIO UNCLAIMED)
pin 142 (gpio4-14): (MUX UNCLAIMED) (GPIO UNCLAIMED)
printk("**** wyb 2024/6/19 19:19 %s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
1D0 32*1+8*3+0=32+24=56
1D1
dmesg
[ 3.999112] **** wyb 2024/6/19 19:19 drivers/media/i2c/ov5645.c ov5645_probe 1436
[ 3.999173] Firefly GPIO Test Program Probe
[ 3.999180] firefly-gpio: -2 is invalid
比较简单粗暴的解法:
在导入头文件之后,#include <linux/of_gpio.h>
直接调用gpio_direction_output拉高这3个GPIO口!
Z:\versions\fpga_OK3588_Linux_fs\kernel\drivers\media\i2c\ov5645.c
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fwnode.h>
#include <media/v4l2-subdev.h>
#include <linux/rk-camera-module.h>
//#include <linux/clk.h>
//#include <linux/device.h>
//#include <linux/delay.h>
//#include <linux/gpio/consumer.h>
//#include <linux/i2c.h>
//#include <linux/module.h>
//#include <linux/pm_runtime.h>
//#include <linux/regulator/consumer.h>
//#include <linux/sysfs.h>
//#include <linux/slab.h>
//#include <linux/version.h>
//#include <linux/rk-camera-module.h>
//#include <media/media-entity.h>
//#include <media/v4l2-async.h>
//#include <media/v4l2-ctrls.h>
//#include <media/v4l2-subdev.h>
//#include <linux/pinctrl/consumer.h>
#include <linux/of_gpio.h>
static int ov5645_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct device_node *node = dev->of_node;
struct device_node *endpoint;
struct ov5645 *ov5645;
u8 chip_id_high, chip_id_low;
u32 xclk_freq;
int ret;
char facing[2];
int ret;
//int gpio;
//enum of_gpio_flags flag;
//struct firefly_gpio_info *gpio_info;
struct device_node *firefly_gpio_node = pdev->dev.of_node;
//struct device_node *firefly_gpio_node = dev->of_node;
printk("**** wyb 2024/6/19 19:19 %s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
ov5645 = devm_kzalloc(dev, sizeof(struct ov5645), GFP_KERNEL);
if (!ov5645)
return -ENOMEM;
ov5645->i2c_client = client;
ov5645->dev = dev;
ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
&ov5645->module_index);
ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
&ov5645->module_facing);
ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
&ov5645->module_name);
ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
&ov5645->len_name);
if (ret) {
dev_err(dev, "could not get module information!\n");
return -EINVAL;
}
endpoint = of_graph_get_next_endpoint(dev->of_node, NULL);
if (!endpoint) {
dev_err(dev, "endpoint node not found\n");
return -EINVAL;
}
ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(endpoint),
&ov5645->ep);
of_node_put(endpoint);
if (ret < 0) {
dev_err(dev, "parsing endpoint node failed\n");
return ret;
}
if (ov5645->ep.bus_type != V4L2_MBUS_CSI2_DPHY) {
dev_err(dev, "invalid bus type, must be CSI2\n");
return -EINVAL;
}
/* get system clock (xclk) */
ov5645->xclk = devm_clk_get(dev, "xclk");
if (IS_ERR(ov5645->xclk)) {
dev_err(dev, "could not get xclk");
return PTR_ERR(ov5645->xclk);
}
ret = of_property_read_u32(dev->of_node, "clock-frequency", &xclk_freq);
if (ret) {
dev_err(dev, "could not get xclk frequency\n");
return ret;
}
/* external clock must be 24MHz, allow 1% tolerance */
if (xclk_freq < 23760000 || xclk_freq > 24240000) {
dev_err(dev, "external clock frequency %u is not supported\n",
xclk_freq);
return -EINVAL;
}
ret = clk_set_rate(ov5645->xclk, xclk_freq);
if (ret) {
dev_err(dev, "could not set xclk frequency\n");
return ret;
}
/*
for (i = 0; i < OV5645_NUM_SUPPLIES; i++)
ov5645->supplies[i].supply = ov5645_supply_name[i];
ret = devm_regulator_bulk_get(dev, OV5645_NUM_SUPPLIES,
ov5645->supplies);
if (ret < 0)
return ret;
*/
// 2024/4/30 9:24
//ov5645->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
//if (IS_ERR(ov5645->enable_gpio)) {
// dev_err(dev, "cannot get enable gpio\n");
// return PTR_ERR(ov5645->enable_gpio);
//}
//
//ov5645->rst_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
//if (IS_ERR(ov5645->rst_gpio)) {
// dev_err(dev, "cannot get reset gpio\n");
// return PTR_ERR(ov5645->rst_gpio);
//}
//ov5645->enable_gpio = devm_gpiod_get(dev, "enable", GPIOD_OUT_HIGH);
//if (IS_ERR(ov5645->enable_gpio)) {
// dev_err(dev, "cannot get enable gpio\n");
// return PTR_ERR(ov5645->enable_gpio);
//}
//
//ov5645->rst_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
//if (IS_ERR(ov5645->rst_gpio)) {
// dev_err(dev, "cannot get reset gpio\n");
// return PTR_ERR(ov5645->rst_gpio);
//}
//
//ov5645->test3_gpio = devm_gpiod_get(dev, "test3", GPIOD_OUT_HIGH);
//if (IS_ERR(ov5645->test3_gpio)) {
// dev_err(dev, "cannot get test3 gpio\n");
// return PTR_ERR(ov5645->test3_gpio);
//}
// printk("Firefly GPIO Test Program Probe\n");
// //gpio_info = devm_kzalloc(&pdev->dev,sizeof(struct firefly_gpio_info *), GFP_KERNEL);
// //gpio_info = devm_kzalloc(&dev,sizeof(struct firefly_gpio_info *), GFP_KERNEL);
// gpio_info = devm_kzalloc(dev,sizeof(struct firefly_gpio_info *), GFP_KERNEL);
// if (!gpio_info) {
// return -ENOMEM;
// }
//
// printk("**** wyb 2024/6/19 19:19 %s %s %d\n", __FILE__, __FUNCTION__, __LINE__);
//
// gpio = of_get_named_gpio_flags(firefly_gpio_node, "firefly-gpio", 0, &flag);
//
// printk("**** wyb 2024/6/19 19:19 %s %s %d gpio=%d\n", __FILE__, __FUNCTION__, __LINE__, gpio);
// printk("**** wyb 2024/6/19 19:19 %s %s %d OF_GPIO_ACTIVE_LOW=%d\n", __FILE__, __FUNCTION__, __LINE__, OF_GPIO_ACTIVE_LOW);
// //if (!gpio_is_valid(gpio)) {
// // printk("firefly-gpio: %d is invalid\n", gpio); return -ENODEV;
// //}
// //if (gpio_request(gpio, "firefly-gpio")) {
// // printk("gpio %d request failed!\n", gpio);
// // gpio_free(gpio);
// // return -ENODEV;
// //}
// //gpio_info->firefly_gpio = gpio;
// //gpio_info->gpio_enable_value = (flag == OF_GPIO_ACTIVE_LOW) ? 0:1;
// //gpio_direction_output(gpio_info->firefly_gpio, gpio_info->gpio_enable_value);
// //printk("Firefly gpio putout finish \n");
//
//
LVDS12V_EN GPIO4_B5 32*4+8*1+5=141
FG_3V3_EN GPIO3_B7 32*3+8*1+7=111
FBGA_1V2_EN GPIO3_D0 32*3+8*3+0=120
//
//
// if (!gpio_is_valid(111)) {
// printk("firefly-gpio: %d is invalid\n", 111);
// return -ENODEV;
// }
// if (gpio_request(111, "firefly-gpio")) {
// printk("gpio %d request failed!\n", 111);
// gpio_free(111);
// return -ENODEV;
// }
//gpio_info->firefly_gpio = gpio;
//gpio_info->gpio_enable_value = (flag == OF_GPIO_ACTIVE_LOW) ? 0:1;
//gpio_direction_output(gpio_info->firefly_gpio, gpio_info->gpio_enable_value);
msleep(20);
gpio_direction_output(111, 1);
gpio_direction_output(120, 1);
gpio_direction_output(141, 1);
usleep_range(20000, 25000);
//printk("Firefly gpio putout finish \n");
printk("---- wyb 2024/6/20 15:26 %s %s %d Firefly gpio putout finish\n", __FILE__, __FUNCTION__, __LINE__);
mutex_init(&ov5645->power_lock);
Z:\versions\fpga_OK3588_Linux_fs\kernel\arch\arm64\boot\dts\rockchip\OK3588-C-common.dtsi
参考资料:
BING:RK3588 gpio 开机高
RK3588 gpio of_find_node_by_path
RK3588 usleep msleep
RK3588 of_get_named_gpio_flags
[ 3.997746] firefly-gpio: -2 is invalid
struct firefly_gpio_info
gpio_dev.nd = of_find_node_by_path("/mytest");
RK3588 of_get_named_gpio_flags
https://blog.csdn.net/baimingyong007/article/details/76850252
rk3288 gpio控制
//power
gpio = of_get_named_gpio(np, "3g_pwr_gpio", 0);
【ov5645.c中可选挂载双设备节点!】
led = of_get_named_gpio_flags(led_node,"led-gpios",0,&flag)
https://blog.csdn.net/u010854102/article/details/47259471
RK3288开发板PopMetal上的GPIO驱动实例
https://blog.csdn.net/qq_64516728/article/details/136837691
rk3588 pinctrl子系统的gpio控制(自用笔记)
https://blog.csdn.net/weixin_43245753/article/details/125380619?spm=1001.2014.3001.5502
https://blog.csdn.net/weixin_43245753/article/details/125380619
Rockchip RK3588 kernel dts解析之regulator-fixed
https://doc.embedfire.com/linux/rk356x/driver/zh/latest/linux_driver/subsystem_gpio.html
2. Pinctrl子系统和GPIO子系统——LED实验
【可能无效】
https://blog.csdn.net/BigGhostCell/article/details/129304365
GPIO实验(1)——基于rk3308b-cc-plus开发板
https://wiki.t-firefly.com/zh_CN/Firefly-RK3399/driver_gpio.html
Firefly-RK3399
【不能获取GPIO号码】
https://wiki.t-firefly.com/zh_CN/ROC-RK3588-PC/usage_gpio.html
ROC-RK3588-PC
4. GPIO 使用
https://blog.csdn.net/u011037593/article/details/128999649
https://blog.csdn.net/u011037593/article/details/128999649?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1-128999649-blog-132533506.235^v43^pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.2&utm_relevant_index=4
Linux GPIO模块-RK3588 GPIO驱动分析
https://blog.csdn.net/suifen_/article/details/138287050
https://blog.csdn.net/suifen_/article/details/138287050?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-4-138287050-blog-136403130.235^v43^pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.3&utm_relevant_index=7
RK3588使能UART串口设备,并生成/dev/ttySx设备节点,GPIO控制
https://blog.csdn.net/dreamliweiming/article/details/134703414
https://blog.csdn.net/dreamliweiming/article/details/134703414?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-134703414-blog-132533506.235^v43^pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.1&utm_relevant_index=3
RK3588 在uboot 和kernel下对GPIO的配置
https://blog.csdn.net/qq_59164231/article/details/136403130
https://blog.csdn.net/qq_59164231/article/details/136403130?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-136403130-blog-132533506.235%5Ev43%5Epc_blog_bottom_relevance_base4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-136403130-blog-132533506.235%5Ev43%5Epc_blog_bottom_relevance_base4&utm_relevant_index=5
RK3588控制GPIO方法
https://blog.csdn.net/weixin_43245753/article/details/125380600
https://blog.csdn.net/weixin_43245753/article/details/125380600?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-125380600-blog-132533506.235%5Ev43%5Epc_blog_bottom_relevance_base4&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-6-125380600-blog-132533506.235%5Ev43%5Epc_blog_bottom_relevance_base4&utm_relevant_index=10
Rockchip RK3588 kernel dts解析之GPIO Pinctrl
https://blog.csdn.net/nb124667390/article/details/132533506
https://blog.csdn.net/nb124667390/article/details/132533506?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-132533506-blog-47259471.235^v43^pc_blog_bottom_relevance_base4&spm=1001.2101.3001.4242.1&utm_relevant_index=1
RK3588平台驱动调试篇 [ GPIO篇 ] - RK3588-对GPIO的操作控制