1

I am trying to write a kernel module that takes control of the UART1 RX&TX pins a runtime, changes their mode to GPIO, sends some commands (using bitbanging) and changes their mode back to UART.

Now, is there a way to change pin modes at runtime in a kernel module on the beaglebone black? I tried accessing the CONTROL_MODULE directly, which did not return an error, however, nothing seems to be written out.

#define CONTROL_MODULE_START    0x44E10000      // CONTROL_MODULE starting address in memory
#define CONTROL_MODULE_END      0x44E11FFF      // CONTROL_MODULE end address in memory
#define CONTROL_MODULE_SIZE (CONTROL_MODULE_END - CONTROL_MODULE_START)
#define GPIO1_17_OFFSET         0x844           // control offset for GPIO1_17
#define GPIO3_19_OFFSET         0x9a4           // control offset for GPIO3_19

.
.
.

if (!(control_module = ioremap(CONTROL_MODULE_START, CONTROL_MODULE_SIZE))) {
    printk(KERN_ERR "UARTbitbangModule: unable to map control module\n");
    return -1;
}

// set both GPIOs to mode 7, input enabled
value = 0x7;

iowrite32(value, control_module + GPIO1_17_OFFSET);
iowrite32(value, control_module + GPIO3_19_OFFSET);

printk(KERN_INFO "UARTbitbangModule: mode GPIO1_17: %d\n", control_module[GPIO1_17_OFFSET]);
printk(KERN_INFO "UARTbitbangModule: mode GPIO3_19: %d\n", control_module[GPIO3_19_OFFSET]);

the corresponding dmesg output looks like this:

[22637.953610] UARTbitbangModule: mode GPIO1_17: 0
[22637.960000] UARTbitbangModule: mode GPIO3_19: 0

I also thought about using the pinctrl subsystem directly (see https://www.kernel.org/doc/Documentation/pinctrl.txt), but I cannot make sense of how to interact with it.

Any ideas on how to change pin modes on the bone at runtime or gain write access to the control module?

Edit: I am using a slightly tweaked (better rt performance) 4.1.15-bone-rt-r17 kernel with a BeagleBoard.org Debian Image 2015-03-01

bananahead
  • 11
  • 4
  • useful http://stackoverflow.com/questions/16872763/configuring-pins-mode-beaglebone – Punit Vara Dec 21 '15 at 19:26
  • pinctrl has a special (non stable nevertheless) interface in debugfs (*/sys/kernel/debug*). So, I would recommend to use it. – 0andriy Dec 23 '15 at 14:18

1 Answers1

0

You can use "linux/gpio.h" header file. An example code from Derek Molloy is here. This code is simple and gpio_request and gpio_direction_input or gpio_direction_output commands do what you need and you can change pin direction without directly changing CONTROL_MODULE register.

Regards

Community
  • 1
  • 1