[PATCH RESEND] max3100 driver

2007-12-29 Thread chripell
This patch adds support for the MAX3100 SPI UART.

Generated on  20071229  against v2.6.23

Signed-off-by: Christian Pellegrin <[EMAIL PROTECTED]>
---
 drivers/serial/Kconfig |7 +
 drivers/serial/Makefile|1 +
 drivers/serial/max3100.c   | 1003 
 include/linux/serial_max3100.h |   28 ++
 4 files changed, 1039 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 81b52b7..4e7111b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -461,6 +461,13 @@ config SERIAL_S3C2410_CONSOLE
  your boot loader about how to pass options to the kernel at
  boot time.)
 
+config SERIAL_MAX3100
+tristate "MAX3100 support"
+depends on SPI
+help
+  MAX3100 chip support
+
+
 config SERIAL_DZ
bool "DECstation DZ serial driver"
depends on MACH_DECSTATION && 32BIT
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index af6377d..9f67e52 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
+obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
 obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
diff --git a/drivers/serial/max3100.c b/drivers/serial/max3100.c
new file mode 100644
index 000..9b6a08c
--- /dev/null
+++ b/drivers/serial/max3100.c
@@ -0,0 +1,1003 @@
+
+/*
+ *
+ *  Copyright (C) 2007 Christian Pellegrin <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ *
+ * Notes: the MAX3100 doesn't provide an interrupt on CTS so we have
+ * to use polling for flow control. TX empty IRQ is unusable, since
+ * writing conf clears FIFO buffer and we cannot have this interrupt
+ * always asking us for attention.
+ *
+ * Example platform data:
+
+static struct plat_max3100 max3100_plat_data = {
+   .loopback = 0,
+   .crystal = 0,
+   .only_edge_irq = 0,
+};
+
+static struct spi_board_info spi_board_info[] = {
+   {
+   .modalias   = "max3100",
+   .platform_data  = _plat_data,
+   .irq= IRQ_EINT12,
+   .max_speed_hz   = 5*1000*1000,
+   .chip_select= 0,
+   },
+};
+
+ * The initial minor number is 128 to prevent clashes with ttyS:
+ * mknod /dev/ttyMAX0 c 4 128
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#define MAX3100_C(1<<14)
+#define MAX3100_D(0<<14)
+#define MAX3100_W(1<<15)
+#define MAX3100_RX   (0<<15)
+
+#define MAX3100_WC   (MAX3100_W  | MAX3100_C)
+#define MAX3100_RC   (MAX3100_RX | MAX3100_C)
+#define MAX3100_WD   (MAX3100_W  | MAX3100_D)
+#define MAX3100_RD   (MAX3100_RX | MAX3100_D)
+#define MAX3100_CMD  (3 << 14)
+
+#define MAX3100_T(1<<14)
+#define MAX3100_R(1<<15)
+
+#define MAX3100_FEN  (1<<13)
+#define MAX3100_SHDN (1<<12)
+#define MAX3100_TM   (1<<11)
+#define MAX3100_RM   (1<<10)
+#define MAX3100_PM   (1<<9)
+#define MAX3100_RAM  (1<<8)
+#define MAX3100_IR   (1<<7)
+#define MAX3100_ST   (1<<6)
+#define MAX3100_PE   (1<<5)
+#define MAX3100_L(1<<4)
+#define MAX3100_BAUD (0xf)
+
+#define MAX3100_TE   (1<<10)
+#define MAX3100_RAFE (1<<10)
+#define MAX3100_RTS  (1<<9)
+#define MAX3100_CTS  (1<<9)
+#define MAX3100_PT   (1<<8)
+#define MAX3100_DATA (0xff)
+
+#define MAX3100_RT   (MAX3100_R | MAX3100_T)
+#define MAX3100_RTC  (MAX3100_RT | MAX3100_CTS | MAX3100_RAFE)
+
+struct max3100_port_s {
+   struct uart_port port;
+   struct spi_device *spi;
+   struct tty_struct   *tty;
+
+   struct mutex   spi_txrx;/* protects access to the hw */
+
+   int rts:1;  /* rts status */
+   int conf;   /* configuration for the MAX31000
+* (bits 0-7, bits 8-11 are irqs) */
+   int last_cts_rx;/* last CTS received for flow ctrl */
+
+   unsigned int tx_buf_cur;/* current char to tx */
+   /* current number of chars in tx buf */
+   unsigned int tx_buf_tot;
+   unsigned char *tx_buf;
+   /* shared tx buffer spinlock (no sem since write may sleep) */
+   spinlock_t tx_buf_lock;
+
+   int tx_stopped:1;   /* when we should not send chars */
+   int parity:3;   /* keeps track if we 

[PATCH RESEND] max3100 driver

2007-12-29 Thread chripell
This patch adds support for the MAX3100 SPI UART.

Generated on  20071229  against v2.6.23

Signed-off-by: Christian Pellegrin [EMAIL PROTECTED]
---
 drivers/serial/Kconfig |7 +
 drivers/serial/Makefile|1 +
 drivers/serial/max3100.c   | 1003 
 include/linux/serial_max3100.h |   28 ++
 4 files changed, 1039 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 81b52b7..4e7111b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -461,6 +461,13 @@ config SERIAL_S3C2410_CONSOLE
  your boot loader about how to pass options to the kernel at
  boot time.)
 
+config SERIAL_MAX3100
+tristate MAX3100 support
+depends on SPI
+help
+  MAX3100 chip support
+
+
 config SERIAL_DZ
bool DECstation DZ serial driver
depends on MACH_DECSTATION  32BIT
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index af6377d..9f67e52 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
+obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
 obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
diff --git a/drivers/serial/max3100.c b/drivers/serial/max3100.c
new file mode 100644
index 000..9b6a08c
--- /dev/null
+++ b/drivers/serial/max3100.c
@@ -0,0 +1,1003 @@
+
+/*
+ *
+ *  Copyright (C) 2007 Christian Pellegrin [EMAIL PROTECTED]
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ *
+ * Notes: the MAX3100 doesn't provide an interrupt on CTS so we have
+ * to use polling for flow control. TX empty IRQ is unusable, since
+ * writing conf clears FIFO buffer and we cannot have this interrupt
+ * always asking us for attention.
+ *
+ * Example platform data:
+
+static struct plat_max3100 max3100_plat_data = {
+   .loopback = 0,
+   .crystal = 0,
+   .only_edge_irq = 0,
+};
+
+static struct spi_board_info spi_board_info[] = {
+   {
+   .modalias   = max3100,
+   .platform_data  = max3100_plat_data,
+   .irq= IRQ_EINT12,
+   .max_speed_hz   = 5*1000*1000,
+   .chip_select= 0,
+   },
+};
+
+ * The initial minor number is 128 to prevent clashes with ttyS:
+ * mknod /dev/ttyMAX0 c 4 128
+ */
+
+#include linux/bitops.h
+#include linux/console.h
+#include linux/delay.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/fcntl.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/irq.h
+#include linux/kernel.h
+#include linux/keyboard.h
+#include linux/major.h
+#include linux/mm.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/pm.h
+#include linux/reboot.h
+#include linux/sched.h
+#include linux/serial_core.h
+#include linux/signal.h
+#include linux/spi/spi.h
+#include linux/string.h
+#include linux/timer.h
+#include linux/tty.h
+#include linux/tty_flip.h
+#include linux/uaccess.h
+#include linux/workqueue.h
+
+#include asm/system.h
+
+#include linux/serial_max3100.h
+
+#define MAX3100_C(114)
+#define MAX3100_D(014)
+#define MAX3100_W(115)
+#define MAX3100_RX   (015)
+
+#define MAX3100_WC   (MAX3100_W  | MAX3100_C)
+#define MAX3100_RC   (MAX3100_RX | MAX3100_C)
+#define MAX3100_WD   (MAX3100_W  | MAX3100_D)
+#define MAX3100_RD   (MAX3100_RX | MAX3100_D)
+#define MAX3100_CMD  (3  14)
+
+#define MAX3100_T(114)
+#define MAX3100_R(115)
+
+#define MAX3100_FEN  (113)
+#define MAX3100_SHDN (112)
+#define MAX3100_TM   (111)
+#define MAX3100_RM   (110)
+#define MAX3100_PM   (19)
+#define MAX3100_RAM  (18)
+#define MAX3100_IR   (17)
+#define MAX3100_ST   (16)
+#define MAX3100_PE   (15)
+#define MAX3100_L(14)
+#define MAX3100_BAUD (0xf)
+
+#define MAX3100_TE   (110)
+#define MAX3100_RAFE (110)
+#define MAX3100_RTS  (19)
+#define MAX3100_CTS  (19)
+#define MAX3100_PT   (18)
+#define MAX3100_DATA (0xff)
+
+#define MAX3100_RT   (MAX3100_R | MAX3100_T)
+#define MAX3100_RTC  (MAX3100_RT | MAX3100_CTS | MAX3100_RAFE)
+
+struct max3100_port_s {
+   struct uart_port port;
+   struct spi_device *spi;
+   struct tty_struct   *tty;
+
+   struct mutex   spi_txrx;/* protects access to the hw */
+
+   int rts:1;  /* rts status */
+   int conf;   /* configuration for the MAX31000
+* (bits 0-7, bits 8-11 are irqs) */
+   int last_cts_rx;/* last CTS received for flow ctrl */
+
+   unsigned int tx_buf_cur;  

Re: [PATCH RESEND] max3100 driver

2007-12-28 Thread chri
Hi,

On Dec 29, 2007 2:38 AM, Jan Engelhardt <[EMAIL PROTECTED]> wrote:
>
> [4:128] is taken by ttyS64. Please look into Documentation/devices.txt.
>

I did it but I think it's better to reuse a minor from ttyS than
allocating a new major (64 serial ports is a lot). I saw that other
drivers take a similar approach, just tend to stay away from low
numbers that are used by 8250 and its child (that can be connected
more or less everywhere).  Perhaps in these udev times the serial
minor number should be allocated dinamicaly. Do you think this makes
sense?

>
> I notice a steep increase in serial drivers. Everyone got their
> new chips for xmas, eh? :)
>
>

This year I was a bad boy so Santa brought me just a cheap uart. For
next Xmas I hope in a WLAN chip or something like that. ;-)


-- 
Christian Pellegrin, see http://www.evolware.org/chri/
"Real Programmers don't play tennis, or any other sport which requires
you to change clothes. Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RESEND] max3100 driver

2007-12-28 Thread Jan Engelhardt

On Dec 28 2007 14:01, [EMAIL PROTECTED] wrote:
>+
>+ * The initial minor number is 128 to prevent clashes with ttyS:
>+ * mknod /dev/ttyMAX0 c 4 128
>+ */

[4:128] is taken by ttyS64. Please look into Documentation/devices.txt.

>+struct max3100_port_s {
>+  struct uart_port port;
>+  struct spi_device *spi;
>+  struct tty_struct   *tty;
>+
>+  struct mutex   spi_txrx;/* protects access to the hw */
>+
>+  int rts;/* rts status, can be MAX3100_RTS or 0 */

possibly be bool then, if it only takes on two values?

>+  int conf;   /* configuration for the MAX31000
>+   * (bits 0-7, bits 8-11 are irqs) */
>+  int last_cts_rx;/* last CTS received for flow ctrl */
>+
>+  int tx_buf_cur; /* current char to tx */
>+  int tx_buf_tot; /* current number of chars in tx buf */

Probably unsigned?

>+static int max3100_do_parity(struct max3100_port_s *s, u16 c)
>+{
>+  int parity;
>+  int i, n;
>+
>+  if (s->parity & MAX3100_PARITY_ODD)
>+  parity = 0;
>+  else
>+  parity = 1;

Or
parity = !!(s->parity & MAX3100_PARITY_ODD);
n = (s->parity & MAX3100_7BIT) ? 7 : 8;
(up to you)

>+  for (i = 0; i < n; i++)
>+  parity = parity ^ ((c>>i) & 1);

parity ^= (c >> i) & 1;

>+  return parity;
>+}
>+
>+  if (s->loopback) {
>+  if ((tx & MAX3100_CMD) == MAX3100_RC)
>+  tx |= 1;
>+  }

if (s->loopback && (tx & MAX3100_CMD) == MAX3100_RC)
tx |= 1;

>+MODULE_DESCRIPTION("MAX3100 driver");
>+MODULE_LICENSE("GPL");

I notice a steep increase in serial drivers. Everyone got their
new chips for xmas, eh? :)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RESEND] max3100 driver

2007-12-28 Thread chripell
This patch adds support for the MAX3100 SPI UART.

Generated on  20071228  against v2.6.23

Signed-off-by: Christian Pellegrin <[EMAIL PROTECTED]>
---
 drivers/serial/Kconfig |7 +
 drivers/serial/Makefile|1 +
 drivers/serial/max3100.c   |  987 
 include/linux/serial_max3100.h |   28 ++
 4 files changed, 1023 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 81b52b7..4e7111b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -461,6 +461,13 @@ config SERIAL_S3C2410_CONSOLE
  your boot loader about how to pass options to the kernel at
  boot time.)
 
+config SERIAL_MAX3100
+tristate "MAX3100 support"
+depends on SPI
+help
+  MAX3100 chip support
+
+
 config SERIAL_DZ
bool "DECstation DZ serial driver"
depends on MACH_DECSTATION && 32BIT
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index af6377d..9f67e52 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
+obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
 obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
diff --git a/drivers/serial/max3100.c b/drivers/serial/max3100.c
new file mode 100644
index 000..7f2c371
--- /dev/null
+++ b/drivers/serial/max3100.c
@@ -0,0 +1,987 @@
+
+/*
+ *
+ *  Copyright (C) 2007 Christian Pellegrin <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ *
+ * Notes: the MAX3100 doesn't provide an interrupt on CTS so we have
+ * to use polling for flow control. TX empty IRQ is unusable, since
+ * writing conf clears FIFO buffer and we cannot have this interrupt
+ * always asking us for attention.
+ *
+ * Example platform data:
+
+static struct plat_max3100 max3100_plat_data = {
+   .loopback = 0,
+   .crystal = 0,
+   .only_edge_irq = 0,
+};
+
+static struct spi_board_info spi_board_info[] = {
+   {
+   .modalias   = "max3100",
+   .platform_data  = _plat_data,
+   .irq= IRQ_EINT12,
+   .max_speed_hz   = 5*1000*1000,
+   .chip_select= 0,
+   },
+};
+
+ * The initial minor number is 128 to prevent clashes with ttyS:
+ * mknod /dev/ttyMAX0 c 4 128
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#define MAX3100_C(1<<14)
+#define MAX3100_D(0<<14)
+#define MAX3100_W(1<<15)
+#define MAX3100_RX   (0<<15)
+
+#define MAX3100_WC   (MAX3100_W  | MAX3100_C)
+#define MAX3100_RC   (MAX3100_RX | MAX3100_C)
+#define MAX3100_WD   (MAX3100_W  | MAX3100_D)
+#define MAX3100_RD   (MAX3100_RX | MAX3100_D)
+#define MAX3100_CMD  (3 << 14)
+
+#define MAX3100_T(1<<14)
+#define MAX3100_R(1<<15)
+
+#define MAX3100_FEN  (1<<13)
+#define MAX3100_SHDN (1<<12)
+#define MAX3100_TM   (1<<11)
+#define MAX3100_RM   (1<<10)
+#define MAX3100_PM   (1<<9)
+#define MAX3100_RAM  (1<<8)
+#define MAX3100_IR   (1<<7)
+#define MAX3100_ST   (1<<6)
+#define MAX3100_PE   (1<<5)
+#define MAX3100_L(1<<4)
+#define MAX3100_BAUD (0xf)
+
+#define MAX3100_TE   (1<<10)
+#define MAX3100_RAFE (1<<10)
+#define MAX3100_RTS  (1<<9)
+#define MAX3100_CTS  (1<<9)
+#define MAX3100_PT   (1<<8)
+#define MAX3100_DATA (0xff)
+
+#define MAX3100_RT   (MAX3100_R | MAX3100_T)
+#define MAX3100_RTC  (MAX3100_RT | MAX3100_CTS | MAX3100_RAFE)
+
+struct max3100_port_s {
+   struct uart_port port;
+   struct spi_device *spi;
+   struct tty_struct   *tty;
+
+   struct mutex   spi_txrx;/* protects access to the hw */
+
+   int rts;/* rts status, can be MAX3100_RTS or 0 */
+   int conf;   /* configuration for the MAX31000
+* (bits 0-7, bits 8-11 are irqs) */
+   int last_cts_rx;/* last CTS received for flow ctrl */
+
+   int tx_buf_cur; /* current char to tx */
+   int tx_buf_tot; /* current number of chars in tx buf */
+   unsigned char *tx_buf;
+   /* shared tx buffer spinlock (no sem
+* since write may sleep) */
+   spinlock_t tx_buf_lock;
+
+   int tx_stopped:1;   /* when we should not send chars */
+   int parity:3;   /* keeps 

[PATCH RESEND] max3100 driver

2007-12-28 Thread chripell
This patch adds support for the MAX3100 SPI UART.

Generated on  20071228  against v2.6.23

Signed-off-by: Christian Pellegrin [EMAIL PROTECTED]
---
 drivers/serial/Kconfig |7 +
 drivers/serial/Makefile|1 +
 drivers/serial/max3100.c   |  987 
 include/linux/serial_max3100.h |   28 ++
 4 files changed, 1023 insertions(+), 0 deletions(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 81b52b7..4e7111b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -461,6 +461,13 @@ config SERIAL_S3C2410_CONSOLE
  your boot loader about how to pass options to the kernel at
  boot time.)
 
+config SERIAL_MAX3100
+tristate MAX3100 support
+depends on SPI
+help
+  MAX3100 chip support
+
+
 config SERIAL_DZ
bool DECstation DZ serial driver
depends on MACH_DECSTATION  32BIT
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index af6377d..9f67e52 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BFIN) += bfin_5xx.o
 obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
+obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
 obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
 obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
 obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
diff --git a/drivers/serial/max3100.c b/drivers/serial/max3100.c
new file mode 100644
index 000..7f2c371
--- /dev/null
+++ b/drivers/serial/max3100.c
@@ -0,0 +1,987 @@
+
+/*
+ *
+ *  Copyright (C) 2007 Christian Pellegrin [EMAIL PROTECTED]
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ *
+ * Notes: the MAX3100 doesn't provide an interrupt on CTS so we have
+ * to use polling for flow control. TX empty IRQ is unusable, since
+ * writing conf clears FIFO buffer and we cannot have this interrupt
+ * always asking us for attention.
+ *
+ * Example platform data:
+
+static struct plat_max3100 max3100_plat_data = {
+   .loopback = 0,
+   .crystal = 0,
+   .only_edge_irq = 0,
+};
+
+static struct spi_board_info spi_board_info[] = {
+   {
+   .modalias   = max3100,
+   .platform_data  = max3100_plat_data,
+   .irq= IRQ_EINT12,
+   .max_speed_hz   = 5*1000*1000,
+   .chip_select= 0,
+   },
+};
+
+ * The initial minor number is 128 to prevent clashes with ttyS:
+ * mknod /dev/ttyMAX0 c 4 128
+ */
+
+#include linux/bitops.h
+#include linux/console.h
+#include linux/delay.h
+#include linux/device.h
+#include linux/errno.h
+#include linux/fcntl.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/irq.h
+#include linux/kernel.h
+#include linux/keyboard.h
+#include linux/major.h
+#include linux/mm.h
+#include linux/module.h
+#include linux/mutex.h
+#include linux/pm.h
+#include linux/reboot.h
+#include linux/sched.h
+#include linux/serial_core.h
+#include linux/signal.h
+#include linux/spi/spi.h
+#include linux/string.h
+#include linux/timer.h
+#include linux/tty.h
+#include linux/tty_flip.h
+#include linux/uaccess.h
+#include linux/workqueue.h
+
+#include asm/system.h
+
+#include linux/serial_max3100.h
+
+#define MAX3100_C(114)
+#define MAX3100_D(014)
+#define MAX3100_W(115)
+#define MAX3100_RX   (015)
+
+#define MAX3100_WC   (MAX3100_W  | MAX3100_C)
+#define MAX3100_RC   (MAX3100_RX | MAX3100_C)
+#define MAX3100_WD   (MAX3100_W  | MAX3100_D)
+#define MAX3100_RD   (MAX3100_RX | MAX3100_D)
+#define MAX3100_CMD  (3  14)
+
+#define MAX3100_T(114)
+#define MAX3100_R(115)
+
+#define MAX3100_FEN  (113)
+#define MAX3100_SHDN (112)
+#define MAX3100_TM   (111)
+#define MAX3100_RM   (110)
+#define MAX3100_PM   (19)
+#define MAX3100_RAM  (18)
+#define MAX3100_IR   (17)
+#define MAX3100_ST   (16)
+#define MAX3100_PE   (15)
+#define MAX3100_L(14)
+#define MAX3100_BAUD (0xf)
+
+#define MAX3100_TE   (110)
+#define MAX3100_RAFE (110)
+#define MAX3100_RTS  (19)
+#define MAX3100_CTS  (19)
+#define MAX3100_PT   (18)
+#define MAX3100_DATA (0xff)
+
+#define MAX3100_RT   (MAX3100_R | MAX3100_T)
+#define MAX3100_RTC  (MAX3100_RT | MAX3100_CTS | MAX3100_RAFE)
+
+struct max3100_port_s {
+   struct uart_port port;
+   struct spi_device *spi;
+   struct tty_struct   *tty;
+
+   struct mutex   spi_txrx;/* protects access to the hw */
+
+   int rts;/* rts status, can be MAX3100_RTS or 0 */
+   int conf;   /* configuration for the MAX31000
+* (bits 0-7, bits 8-11 are irqs) */
+   int last_cts_rx;/* last CTS received for flow ctrl */
+
+   int 

Re: [PATCH RESEND] max3100 driver

2007-12-28 Thread Jan Engelhardt

On Dec 28 2007 14:01, [EMAIL PROTECTED] wrote:
+
+ * The initial minor number is 128 to prevent clashes with ttyS:
+ * mknod /dev/ttyMAX0 c 4 128
+ */

[4:128] is taken by ttyS64. Please look into Documentation/devices.txt.

+struct max3100_port_s {
+  struct uart_port port;
+  struct spi_device *spi;
+  struct tty_struct   *tty;
+
+  struct mutex   spi_txrx;/* protects access to the hw */
+
+  int rts;/* rts status, can be MAX3100_RTS or 0 */

possibly be bool then, if it only takes on two values?

+  int conf;   /* configuration for the MAX31000
+   * (bits 0-7, bits 8-11 are irqs) */
+  int last_cts_rx;/* last CTS received for flow ctrl */
+
+  int tx_buf_cur; /* current char to tx */
+  int tx_buf_tot; /* current number of chars in tx buf */

Probably unsigned?

+static int max3100_do_parity(struct max3100_port_s *s, u16 c)
+{
+  int parity;
+  int i, n;
+
+  if (s-parity  MAX3100_PARITY_ODD)
+  parity = 0;
+  else
+  parity = 1;

Or
parity = !!(s-parity  MAX3100_PARITY_ODD);
n = (s-parity  MAX3100_7BIT) ? 7 : 8;
(up to you)

+  for (i = 0; i  n; i++)
+  parity = parity ^ ((ci)  1);

parity ^= (c  i)  1;

+  return parity;
+}
+
+  if (s-loopback) {
+  if ((tx  MAX3100_CMD) == MAX3100_RC)
+  tx |= 1;
+  }

if (s-loopback  (tx  MAX3100_CMD) == MAX3100_RC)
tx |= 1;

+MODULE_DESCRIPTION(MAX3100 driver);
+MODULE_LICENSE(GPL);

I notice a steep increase in serial drivers. Everyone got their
new chips for xmas, eh? :)

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RESEND] max3100 driver

2007-12-28 Thread chri
Hi,

On Dec 29, 2007 2:38 AM, Jan Engelhardt [EMAIL PROTECTED] wrote:

 [4:128] is taken by ttyS64. Please look into Documentation/devices.txt.


I did it but I think it's better to reuse a minor from ttyS than
allocating a new major (64 serial ports is a lot). I saw that other
drivers take a similar approach, just tend to stay away from low
numbers that are used by 8250 and its child (that can be connected
more or less everywhere).  Perhaps in these udev times the serial
minor number should be allocated dinamicaly. Do you think this makes
sense?


 I notice a steep increase in serial drivers. Everyone got their
 new chips for xmas, eh? :)



This year I was a bad boy so Santa brought me just a cheap uart. For
next Xmas I hope in a WLAN chip or something like that. ;-)


-- 
Christian Pellegrin, see http://www.evolware.org/chri/
Real Programmers don't play tennis, or any other sport which requires
you to change clothes. Mountain climbing is OK, and Real Programmers
wear their climbing boots to work in case a mountain should suddenly
spring up in the middle of the computer room.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/