平台:MTK6765
android版本:9.0
内核版本:4.9
读写GPIO节点:/sys/devices/platform/1000b000.pinctrl/mt_gpio
public void writeGpio(String value) {
Log.d(TAG, "wjz debug writeGpio: value is " + value);
if (value.isEmpty()) {
return;
}
FileWriter fileWriter;
try {
fileWriter = new FileWriter(MTK_GPIO_PATH);
fileWriter.write(value);
fileWriter.close();
} catch (IOException e) {
Log.e(TAG, "wjz debug writeGpio: error is " + e.getMessage());
e.printStackTrace();
}
}
public String readGpio(String gpioNumber) {
StringBuilder content = new StringBuilder();
File file = new File(MTK_GPIO_PATH);
if (!file.exists() || TextUtils.isEmpty(gpioNumber)) {
return "";
}
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new FileReader(file));
String line;
while ((line = bufferedReader.readLine()) != null) {
content.append(line);
}
bufferedReader.close();
} catch (IOException e) {
Log.e(TAG, "wjz debug readGpio: error is " + e.getMessage());
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
Log.e(TAG, "wjz debug readGpio: close bufferedReader error is " + e.getMessage());
e.printStackTrace();
}
}
}
return content.toString();
}
//调用举例:
writeGpio("mode 112 0");//设置gpio 112为普通模式
writeGpio("dir 112 1");//设置gpio 112为输出模式
writeGpio("out 112 1");//拉高gpio 112
writeGpio("out 112 0");//拉低gpio 112
相关调试源码路径:
gpio驱动:kernel-4.9/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
方法:mtk_gpio_set,可以通过pr_info增加打印信息,dump_stack()打印内核调用栈。
--- a/kernel-4.9/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
+++ b/kernel-4.9/drivers/pinctrl/mediatek/pinctrl-mtk-common.c
@@ -50,6 +50,7 @@ static unsigned long Gpio_num_status;
#define MAX_GPIO_MODE_PER_REG 5
#define GPIO_MODE_BITS 3
#define GPIO_MODE_PREFIX "GPIO"
+#define GPIO_DEBUG 1
static const char * const mtk_gpio_functions[] = {
@@ -350,6 +351,12 @@ static void mtk_gpio_set(struct gpio_chip *chip,
unsigned int bit;
struct mtk_pinctrl *pctl = gpiochip_get_data(chip);
+ //wjz
+ if (offset == 111) {
+ pr_info("===============wjz==================\n");
+ dump_stack();//使用dump_stack来显示内核调用栈
+ }
+
#if defined(CONFIG_PINCTRL_MTK_NO_UPSTREAM)
if (pctl->devdata->pin_dout_grps) {
/* Just Used by smartphone projects */