+/* Circular Buffer */
+
+/*
+ * edge_buf_alloc
+ *
+ * Allocate a circular buffer and all associated memory.
+ */
+
+static struct edge_buf *edge_buf_alloc(unsigned int size)
+{
+ struct edge_buf *eb;
+
+
+ if (size == 0)
+ return NULL;
+
+ eb = kmalloc(sizeof(struct edge_buf), GFP_KERNEL);
+ if (eb == NULL)
+ return NULL;
+
+ eb->buf_buf = kmalloc(size, GFP_KERNEL);
+ if (eb->buf_buf == NULL) {
+ kfree(eb);
+ return NULL;
+ }
+
+ eb->buf_size = size;
+ eb->buf_get = eb->buf_put = eb->buf_buf;
+
+ return eb;
+}
+
+
+/*
+ * edge_buf_free
+ *
+ * Free the buffer and all associated memory.
+ */
+
+static void edge_buf_free(struct edge_buf *eb)
+{
+ if (eb) {
+ kfree(eb->buf_buf);
+ kfree(eb);
+ }
+}
+
+
+/*
+ * edge_buf_clear
+ *
+ * Clear out all data in the circular buffer.
+ */
+
+static void edge_buf_clear(struct edge_buf *eb)
+{
+ if (eb != NULL)
+ eb->buf_get = eb->buf_put;
+ /* equivalent to a get of all data available */
+}
+
+
+/*
+ * edge_buf_data_avail
+ *
+ * Return the number of bytes of data available in the circular
+ * buffer.
+ */
+
+static unsigned int edge_buf_data_avail(struct edge_buf *eb)
+{
+ if (eb != NULL)
+ return ((eb->buf_size + eb->buf_put - eb->buf_get) % eb->buf_size);
+ else
+ return 0;
+}
+
+
+/*
+ * edge_buf_space_avail
+ *
+ * Return the number of bytes of space available in the circular
+ * buffer.
+ */
+
+static unsigned int edge_buf_space_avail(struct edge_buf *eb)
+{
+ if (eb != NULL)
+ return ((eb->buf_size + eb->buf_get - eb->buf_put - 1) % eb->buf_size);
+ else
+ return 0;
+}
+
+
+/*
+ * edge_buf_put
+ *
+ * Copy data data from a user buffer and put it into the circular buffer.
+ * Restrict to the amount of space available.
+ *
+ * Return the number of bytes copied.
+ */
+
+static unsigned int edge_buf_put(struct edge_buf *eb, const char *buf,
+ unsigned int count)
+{
+ unsigned int len;
+
+
+ if (eb == NULL)
+ return 0;
+
+ len = edge_buf_space_avail(eb);
+ if (count > len)
+ count = len;
+
+ if (count == 0)
+ return 0;
+
+ len = eb->buf_buf + eb->buf_size - eb->buf_put;
+ if (count > len) {
+ memcpy(eb->buf_put, buf, len);
+ memcpy(eb->buf_buf, buf+len, count - len);
+ eb->buf_put = eb->buf_buf + count - len;
+ } else {
+ memcpy(eb->buf_put, buf, count);
+ if (count < len)
+ eb->buf_put += count;
+ else /* count == len */
+ eb->buf_put = eb->buf_buf;
+ }
+
+ return count;
+}
+
+
+/*
+ * edge_buf_get
+ *
+ * Get data from the circular buffer and copy to the given buffer.
+ * Restrict to the amount of data available.
+ *
+ * Return the number of bytes copied.
+ */
+
+static unsigned int edge_buf_get(struct edge_buf *eb, char *buf,
+ unsigned int count)
+{
+ unsigned int len;
+
+
+ if (eb == NULL)
+ return 0;
+
+ len = edge_buf_data_avail(eb);
+ if (count > len)
+ count = len;
+
+ if (count == 0)
+ return 0;
+
+ len = eb->buf_buf + eb->buf_size - eb->buf_get;
+ if (count > len) {
+ memcpy(buf, eb->buf_get, len);
+ memcpy(buf+len, eb->buf_buf, count - len);
+ eb->buf_get = eb->buf_buf + count - len;
+ } else {
+ memcpy(buf, eb->buf_get, count);
+ if (count < len)
+ eb->buf_get += count;
+ else /* count == len */
+ eb->buf_get = eb->buf_buf;
+ }
+
+ return count;
+}
+
+
+static struct usb_serial_driver edgeport_1port_device = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "edgeport_ti_1",
+ },
+ .description = "Edgeport TI 1 port adapter",