title: How do I open/write/read a uart device from a kernel module?
body: <p>The device is a scanner. I know uart5 is setup in the dtsi file and in userspace it is listed under /dev/ttymxc4. From userspace, I understand that I can manipulate the device by </p>
  
  <pre><code>fd = open("/dev/ttymxc5", O_RDWR|O_NOCTTY|O_NONBLOCK);
  if (fd &lt; 0)
  {
      fprintf (stderr,"Open error on %s: %s\n", SCANNER_UART, strerror(errno));
      return nullptr;
  }
  </code></pre>
  
  <p>And use termios to set all the settings like baudrate, write data using the write call etc.</p>
  
  <p>I am wanting to abstract a lot of the commands under sysfs. I've setup a "uart driver" like this:</p>
  
  <pre><code>result = uart_register_driver(&amp;scanner_reg);
  if (result)
      return result;
  
  result = uart_add_one_port(&amp;scanner_reg, &amp;scanner_port);
  if (result)
      uart_unregister_driver(&amp;scanner_reg);
  </code></pre>
  
  <p>And I am using gpio lines to turn on the system and a few other things. However, in the schematic, I do not see the gpio lines for these things.</p>
  
  <pre><code>UART5_CTS_HOST_SCAN_3_3V
  UART5_RTS_HOST_SCAN_3_3V
  UART5_RxD_HOST_SCAN_3_3V
  UART5_TxD_HOST_SCAN_3_3V
  </code></pre>
  
  <p>I am just not sure how to open/write/read data from the device. I <em>know</em> about sys_open and similar calls, however, I know they are not the "right" way to do this; I don't want to have to go through userspace.</p>
  
  <p>So, in summary how do I </p>
  
  <ol>
  <li>"choose" the /dev/ttymxc4 device in my module and </li>
  <li>open, set baud rate, and read/write data to the device?</li>
  </ol>
  
  <p>Thanks! Please help! New to everything uart, I've dealt with i2c in the past and it seemed less complicated.</p>