sealevel-950-9-bit.patch

For instructions on installing this patch to your kernel source, see
the seacom/patches/INSTALL text file.

This patchset adds support for native 9-bit asynchronous communications
to the standard Linux 8250 serial driver.  The patch adds three ioctl
calls to the standard driver TIOC9BITGET, TIOC9BITSET, and TIOC9BITCLR.
In addition, the patch modifies the method in which data is formatted
in the buffers of read and write calls.  A simple application that makes
use of the new features added by this patch can be found in the
seacom/examples/sample-ninebit directory.

To make use of the following ioctls, a C header file has been added to
the seacom/includes/ninebit directory.  This file contains the ioctl
codes necessary to access the additional features added by this patchset.



**********************
*** Receiving Data ***
**********************
The standard read() function call is used to acquire serial data from
the serial port.  The only difference is that the return size will always
be an even value.  This is due to the size limitations of the byte data
type.  Since 9-bit communications require an extra bit, two data bytes
must be used for every asynchronous frame of data.  The first byte of
every two byte pair (frame) will use the LSB to indicate the state of
the ADDR bit.  The second byte in the pair will contain the data portion
of the frame.

   int i;                         // index
   int fd;                        // open file descriptor
   char buf[256];                 // buffer for received data
   int rc;                        // read() return value

   rc = read(fd, buf, sizeof(buf));
   if (rc < 0) {
      // process error
   } else {
      // process rc bytes of data
      for (i = 0; i < rc; i += 2) {
          buf[i] & 0x01;   // ADDR bit
          buf[i+1];        // Data bits
      }
   }


********************
*** Sending Data ***
********************
The standard write() function call is used to send serial data from the
serial port.  The only difference is that the data size should always
be a multiple of two.  Similar to the read() function, each 9-bit
transmission corresponds to a two byte pair in the transmit buffer.
The first byte contains the ADDR bit in the LSB of the byte.  The second
byte contains the data bits of the transmission.

   int fd;                        // open file descriptor
   char buf[2];                   // buffer is multiple of 2
   int rc;                        // write() return value

   // initialize buf with send data
   // initialize size with count of send data bytes
   buf[0] = 0x01;  // ADDR bit (0x01 or 0x00)
   buf[1] = 0xFF;  // Data bits

   rc = write(fd, buf, sizeof(buf));
   if (rc < 0) {
      // process error
   } else {
      // rc bytes of data successfully sent
   }


*********************
*** ioctl() codes ***
*********************
TIOC9BITGET - Get the current status of 9-bit mode (ON/OFF)
----------------------------
This ioctl requires a pointer to an int as an argument.

   int ninebit;
   rc = ioctl(fd, TIOC9BITGET, &ninebit);
   if (ninebit)
       printf("9-bit mode is currently enabled\n");
   else
       printf("9-bit mode is currently disabled\n");


TIOC9BITSET - Enable 9-bit communications
---------------------------------------
This ioctl will only work correctly on OX16c950 type UARTS.  All
other types of UART will return a -ENOTTY error.

   rc = ioctl(fd, TIOC9BITSET);
   if (rc == -ENOTTY)
       printf("this UART type does not support native 9-bit mode\n");


TIOC9BITCLR - Disable 9-bit communications
---------------------------------------
This ioctl will only work correctly on OX16c950 type UARTS.  All
other types of UART will return a -ENOTTY error.

   rc = ioctl(fd, TIOC9BITCLR);
   if (rc == -ENOTTY)
       printf("this UART type does not support native 9-bit mode\n");

