title: Change pin mode at runtime in kernel module on beaglebone black
body: <p>I am trying to write a kernel module that takes control of the UART1 RX&amp;TX pins a runtime, changes their mode to GPIO, sends some commands (using bitbanging) and changes their mode back to UART.</p>
  
  <p>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.</p>
  
  <pre><code>#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]);
  </code></pre>
  
  <p>the corresponding dmesg output looks like this:</p>
  
  <pre><code>[22637.953610] UARTbitbangModule: mode GPIO1_17: 0
  [22637.960000] UARTbitbangModule: mode GPIO3_19: 0
  </code></pre>
  
  <p>I also thought about using the pinctrl subsystem directly (see <a href="https://www.kernel.org/doc/Documentation/pinctrl.txt" rel="nofollow">https://www.kernel.org/doc/Documentation/pinctrl.txt</a>), but I cannot make sense of how to interact with it.</p>
  
  <p>Any ideas on how to change pin modes on the bone at runtime or gain write access to the control module?</p>
  
  <p>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</p>