Skip to contentSkip to conversation

ARM: support for ICP DAS LP-8x4x

PATCH Superseded Sergei Ianovich 27 participants 304 messages Dec 1, 2013 – Sep 27, 2016 1 message not in the archive Page 3 of 3

Subsystems (15)
lore
Share & tools
lore
#228 lore raw

PATCH v7 1/1 serial: support for 16550A serial ports on LP-8x4x

In reply to Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

---
CC: Alan Cox <[email protected]>
CC: Andy Shevchenko <[email protected]>
CC: Arnd Bergmann <[email protected]>

v6..v7
fix review comments by Andy Shevchenko
not applying Acked-by as the 1st change is big
* handle unsupported tty modes correctly as suggested by Alan Cox
* remove extra check of platform_get_resource() result
* propagate error code from devm_ioremap_resource()
* drop uart.port.iobase for UPIO_MEM device

v5..v6
fix review comments by Arnd Bergmann
* remove wildcards from compatible
* update doc file
* drop interrupt parent from doc file
* replace uart w/ serial in device names in doc file

fix review comments by Andy Shevchenko
* exchange labels in switch block
* replace iowrite8() with writeb()
* compact comment to one line

v4..v5
* constify struct of_device_id
* drop .owner from struct platform_driver
* rewrite set_termios() baud rate hadnling as suggested by Alan Cox

v3..v4
* move DTS bindings to a different patch (8/21) as suggested by Heikki Krogerus

v2..v3
* no changes (except number 10/16 -> 12/21)

v0..v2
* register platform driver instead of platform device
* use device tree
* use devm helpers where possible

 .../bindings/serial/icpdas-lp8841-uart.txt         |  41 +++++
 drivers/tty/serial/8250/8250_lp8841.c              | 193 +++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig                    |  14 ++
 drivers/tty/serial/8250/Makefile                   |   2 +
 4 files changed, 250 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt
 create mode 100644 drivers/tty/serial/8250/8250_lp8841.c
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +41 -0
new file mode 100644
index 0000000..d6acd22
@@ -0,0 +1,41 @@
+* UART ports on ICP DAS LP-8841
+
+LP-8441, LP-8141 and LP-8041 are fully compatible.
+
+ICP DAS LP-8841 contains three additional serial ports interfaced via
+Analog Devices ADM213EA chips in addition to 3 serial ports on PXA CPU.
+
+The chips themselves are standard, they would work with 8250_core if
+properly connected. However, they are not connected normally. Al least
+some of their config pins are wired to a different address region. So
+the driver is board-specific.
+
+Required properties:
+- compatible : should be "icpdas,uart-lp8841"
+
+- reg : should provide 16 byte man IO memory region and 1 byte region for
+	termios
+
+- interrupts : should provide interrupt
+
+Optional property:
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly or implicitly from a parent node
+
+Examples (from pxa27x-lp8x4x.dts):
+
+		serial@9050 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9050 0x10
+			       0x9030 0x02>;
+			interrupts = <13>;
+			status = "okay";
+		};
+
+		serial@9060 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9060 0x10
+			       0x9032 0x02>;
+			interrupts = <14>;
+			status = "okay";
+		};
drivers/tty/serial/8250/8250_lp8841.c new file +193 -0

193 lines not on this page · raw message

drivers/tty/serial/8250/Kconfig +14 -0
index 3b5cf9c..68640c1 100644
@@ -394,3 +394,17 @@ config SERIAL_8250_PXA
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
+
+	  If you choose M here, the module name will be 8250_pxa.
+
+config SERIAL_8250_LP8841
+	tristate "Support 16550A ports on ICP DAS LP-8841"
+	depends on SERIAL_8250 && MACH_PXA27X_DT
+	select LP8841_IRQ
+	help
+	  In addition to serial ports on PXA270 SoC, LP-8841 has 1 dual
+	  RS232/RS485 port, 1 RS485 port and 1 RS232 port.
+
+	  Say N here, unless you plan to run this kernel on a LP-8841 system.
+
+	  If you choose M here, the module name will be 8250_lp8841.
drivers/tty/serial/8250/Makefile +2 -0
index d1e2f2d..10b4bf0 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT)	+= 8250_accent.o
 obj-$(CONFIG_SERIAL_8250_BOCA)		+= 8250_boca.o
 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554)	+= 8250_exar_st16c554.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
+obj-$(CONFIG_SERIAL_8250_LP8X4X)	+= 8250_lp8x4x.o
 obj-$(CONFIG_SERIAL_8250_FSL)		+= 8250_fsl.o
 obj-$(CONFIG_SERIAL_8250_DW)		+= 8250_dw.o
 obj-$(CONFIG_SERIAL_8250_EM)		+= 8250_em.o
@@ -30,5 +31,6 @@ obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
+obj-$(CONFIG_SERIAL_8250_LP8841)	+= 8250_lp8841.o
 
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
Signature · 1 line
2.7.0
#229 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 9 lines · Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

Few more comments, mostly about style.

drivers/tty/serial/8250/8250_lp8841.c line 31

Quoted 8 lines
drivers/tty/serial/8250/8250_lp8841.c new file +8 -0
+static void lp8841_serial_set_termios(struct uart_port *port,
+		struct ktermios *termios, struct ktermios *old)
+{
+#ifdef BOTHER
+	unsigned int cbaud;
+#endif
+	unsigned int baud;
+	unsigned int len;

Since you are writing this to the register at the end maybe
 - unsigned int -> u8 (write*b* — exactly one byte)
 - len -> value (it's not only about data length)

Quoted 19 lines
drivers/tty/serial/8250/8250_lp8841.c new file +19 -0
+	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+	struct lp8841_serial_data *data = port->private_data;
+
+	/* We only support CS7 and CS8 */
+	while ((termios->c_cflag & CSIZE) != CS7 &&
+	       (termios->c_cflag & CSIZE) != CS8) {
+		termios->c_cflag &= ~CSIZE;
+		termios->c_cflag |= old_csize;
+		old_csize = CS8;
+	}
+
+	serial8250_do_set_termios(port, termios, old);
+
+	if ((termios->c_cflag & CSIZE) == CS7)
+		len = 9;
+	else
+		len = 10;
+
+	if (termios->c_cflag & CSTOPB)

drivers/tty/serial/8250/8250_lp8841.c line 59

Quoted 10 lines
drivers/tty/serial/8250/8250_lp8841.c new file +9 -0
+		len++;
 
+	if (termios->c_cflag & PARENB)
+		len++;
+	if (!(termios->c_cflag & PARODD))
+		len++;
+#ifdef CMSPAR
+	if (termios->c_cflag & CMSPAR)
+		len++;
+#endif

I don't know if someone likes it or not (up to you), but for me looks better to have ternary operators here:

value += (termios->c_cflag & CSTOPB) ? 1 : 0;
value += (termios->c_cflag & PARENB) ? 1 : 0;
value += (termios->c_cflag & PARODD) ? 0 : 1;

#ifdef CMSPAR
value += (termios->c_cflag & CMSPAR) ? 1 : 0;
#endif

drivers/tty/serial/8250/8250_lp8841.c line 61

Quoted 1 line
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+	len -= 9;

This one could be part of previous evaluation:
 value = (termios->c_cflag & CSIZE) == CS7 ? 0 : 1;

drivers/tty/serial/8250/8250_lp8841.c line 63

Quoted 2 lines
drivers/tty/serial/8250/8250_lp8841.c new file +2 -0
+	len &= 3;
+	len <<= 3;

Perhaps to define magic number (e.g. LP8841_DATA_LEN_SHIFT).

Quoted 22 lines
drivers/tty/serial/8250/8250_lp8841.c new file +13 -0
+
+	baud = tty_termios_baud_rate(termios);
+
+#ifdef BOTHER
+	/* We only support fixed rates */
+	cbaud = termios->c_cflag & CBAUD;
+
+	if (cbaud == BOTHER) {
+		termios->c_cflag &= ~BOTHER;
+
+		/* Don't rewrite B0 */
+		if (baud) {
+			tty_termios_encode_baud_rate(termios, baud,

baud);

drivers/tty/serial/8250/8250_lp8841.c new file +6 -0
+			baud = tty_termios_baud_rate(termios);
+
+			/* Set sane default speed if we get 0 */
+			if (!baud) {
+				baud = 9600;
 
+				tty_termios_encode_baud_rate(termios

,

drivers/tty/serial/8250/8250_lp8841.c line 83

Quoted 1 line
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+						baud, baud);

I think you can call this unconditionally together with case > 115200.

drivers/tty/serial/8250/8250_lp8841.c line 93

Quoted 10 lines
drivers/tty/serial/8250/8250_lp8841.c new file +10 -0
+			}
+		}
+	}
+#endif
+
+	/* We only support up to 115200 */
+	if (baud > 115200) {
+		baud = 115200;
+		tty_termios_encode_baud_rate(termios, baud, baud);
+	}

Btw, can we use uart_get_baud_rate() here?

drivers/tty/serial/8250/8250_lp8841.c line 131

Quoted 8 lines
drivers/tty/serial/8250/8250_lp8841.c new file +6 -0
+	writeb(len, data->ios_mem);
+
+}
 
 
+static int lp8841_serial_probe(struct platform_device *pdev)
+{
+	struct uart_8250_port uart = {};

{0}

drivers/tty/serial/8250/8250_lp8841.c line 137

Quoted 7 lines
drivers/tty/serial/8250/8250_lp8841.c new file +6 -0
+	struct lp8841_serial_data *data;
+	struct resource *mmres, *mires;
+	int ret;
+
+	mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
+	mires = platform_get_resource(pdev, IORESOURCE_MEM, 1);

Perhaps move it down to be closer to devm_ioremap_resource() call.

drivers/tty/serial/8250/8250_lp8841.c line 144

Quoted 7 lines
drivers/tty/serial/8250/8250_lp8841.c new file +7 -0
+	if (!mmres)
+		return -ENODEV;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+

+ mires = platform_get_resource(pdev, IORESOURCE_MEM, 1);

Quoted 3 lines
drivers/tty/serial/8250/8250_lp8841.c new file +3 -0
+	data->ios_mem = devm_ioremap_resource(&pdev->dev, mires);
+	if (IS_ERR(data->ios_mem))
+		return PTR_ERR(data->ios_mem);
Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#230 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 65 lines · Andy Shevchenko
Quoted 11 lines · Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports
on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

Few more comments, mostly about style.

drivers/tty/serial/8250/8250_lp8841.c line 31

Quoted 8 lines
drivers/tty/serial/8250/8250_lp8841.c new file +8 -0
+static void lp8841_serial_set_termios(struct uart_port *port,
+		struct ktermios *termios, struct ktermios *old)
+{
+#ifdef BOTHER
+	unsigned int cbaud;
+#endif
+	unsigned int baud;
+	unsigned int len;

Since you are writing this to the register at the end maybe
 - unsigned int -> u8 (write*b* — exactly one byte)
 - len -> value (it's not only about data length)

Quoted 19 lines
drivers/tty/serial/8250/8250_lp8841.c new file +19 -0
+	unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+	struct lp8841_serial_data *data = port->private_data;
+
+	/* We only support CS7 and CS8 */
+	while ((termios->c_cflag & CSIZE) != CS7 &&
+	       (termios->c_cflag & CSIZE) != CS8) {
+		termios->c_cflag &= ~CSIZE;
+		termios->c_cflag |= old_csize;
+		old_csize = CS8;
+	}
+
+	serial8250_do_set_termios(port, termios, old);
+
+	if ((termios->c_cflag & CSIZE) == CS7)
+		len = 9;
+	else
+		len = 10;
+
+	if (termios->c_cflag & CSTOPB)

drivers/tty/serial/8250/8250_lp8841.c line 59

Quoted 10 lines
drivers/tty/serial/8250/8250_lp8841.c new file +9 -0
+		len++;
 
+	if (termios->c_cflag & PARENB)
+		len++;
+	if (!(termios->c_cflag & PARODD))
+		len++;
+#ifdef CMSPAR
+	if (termios->c_cflag & CMSPAR)
+		len++;
+#endif

I don't know if someone likes it or not (up to you), but for me looks better to have ternary operators here:

value += (termios->c_cflag & CSTOPB) ? 1 : 0;
value += (termios->c_cflag & PARENB) ? 1 : 0;
value += (termios->c_cflag & PARODD) ? 0 : 1;

Quoted 8 lines

#ifdef CMSPAR
value += (termios->c_cflag & CMSPAR) ? 1 : 0;
#endif

drivers/tty/serial/8250/8250_lp8841.c line 61

Quoted 1 line
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+	len -= 9;

This one could be part of previous evaluation:
 value = (termios->c_cflag & CSIZE) == CS7 ? 0 : 1;

Great point.

Quoted 4 lines

drivers/tty/serial/8250/8250_lp8841.c line 63

Quoted 2 lines
drivers/tty/serial/8250/8250_lp8841.c new file +2 -0
+	len &= 3;
+	len <<= 3;

Perhaps to define magic number (e.g. LP8841_DATA_LEN_SHIFT).

OK

Quoted 21 lines
Quoted 20 lines
drivers/tty/serial/8250/8250_lp8841.c new file +13 -0
+
+	baud = tty_termios_baud_rate(termios);
+
+#ifdef BOTHER
+	/* We only support fixed rates */
+	cbaud = termios->c_cflag & CBAUD;
+
+	if (cbaud == BOTHER) {
+		termios->c_cflag &= ~BOTHER;
+
+		/* Don't rewrite B0 */
+		if (baud) {
+			tty_termios_encode_baud_rate(termios,

baud,
baud);

drivers/tty/serial/8250/8250_lp8841.c new file +5 -0
+			baud = tty_termios_baud_rate(termios);
+
+			/* Set sane default speed if we get 0 */
+			if (!baud) {
+				baud = 9600;
Quoted 7 lines

drivers/tty/serial/8250/8250_lp8841.c line 83

Quoted 4 lines
(quoted diff) +1 -0
+				tty_termios_encode_baud_rate(termi

os
,

drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+						baud, baud);

I think you can call this unconditionally together with case > 115200.

The calls are orthogonal. This one deals with the case when BOTHER is defined and set, and we have non-zero rate with BOTHER, but we have zero rate after BOTHER is cleared. So we set 9600 as a sane default speed.

Quoted 10 lines

drivers/tty/serial/8250/8250_lp8841.c line 93

Quoted 10 lines
drivers/tty/serial/8250/8250_lp8841.c new file +10 -0
+			}
+		}
+	}
+#endif
+
+	/* We only support up to 115200 */
+	if (baud > 115200) {
+		baud = 115200;
+		tty_termios_encode_baud_rate(termios, baud, baud);
+	}

This one deals with the case when the rate is over 115200. If the previous case has been triggered, this one won't be.

Quoted 1 line

Btw, can we use uart_get_baud_rate() here?

uart_get_baud_rate() has already been called
in serial8250_do_set_termios(). uart_get_baud_rate()
calls tty_termios_encode_baud_rate(). uart_get_baud_rate() won't help us if BOTHER is set. Once BOTHER is cleared, we don't need any special processing of uart_get_baud_rate().

Quoted 5 lines

drivers/tty/serial/8250/8250_lp8841.c line 131

Quoted 3 lines
drivers/tty/serial/8250/8250_lp8841.c new file +3 -0
+static int lp8841_serial_probe(struct platform_device *pdev)
+{
+     struct uart_8250_port uart = {};

{0}

---
drivers/tty/serial/8250/8250_lp8841.c: In function 'lp8841_serial_probe':
drivers/tty/serial/8250/8250_lp8841.c:124:32: warning: excess elements in struct initializer
  struct uart_8250_port uart = {0};
                                ^
drivers/tty/serial/8250/8250_lp8841.c:124:32: note: (near initialization for 'uart.port.lock.<anonymous>.rlock.raw_lock')
---

Zero triggers a warning. I'll use memset().

Quoted 9 lines
Quoted 7 lines

+     struct lp8841_serial_data *data;
+     struct resource *mmres, *mires;
+     int ret;
+
+     mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);

+     mires = platform_get_resource(pdev, IORESOURCE_MEM, 1);

Perhaps move it down to be closer to devm_ioremap_resource() call.

OK

Thanks for lightning fast reviews. I'll resubmit v8 if there is no objections to the points above.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#231 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 4 lines · Sergei Ianovich
Quoted 3 lines · Andy Shevchenko

drivers/tty/serial/8250/8250_lp8841.c line 62

Quoted 1 line · Sergei Ianovich
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+	len &= 3;

Mask as well to be defined.

Quoted 11 lines
Quoted 3 lines

drivers/tty/serial/8250/8250_lp8841.c line 63

Quoted 1 line
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+	len <<= 3;

Perhaps to define magic number (e.g. LP8841_DATA_LEN_SHIFT).

OK

(quoted diff) +1 -0
+	baud = tty_termios_baud_rate(termios);
Quoted 3 lines

drivers/tty/serial/8250/8250_lp8841.c line 68

Quoted 3 lines
drivers/tty/serial/8250/8250_lp8841.c new file +3 -0
+
+#ifdef BOTHER
+	/* We only support fixed rates */

So, but if you support only fixed rates, why do you care about BOTHER at all?

Quoted 10 lines
Quoted 3 lines
Quoted 1 line

I think you can call this unconditionally together with case > 115200.

The calls are orthogonal. This one deals with the case when BOTHER is defined and set, and we have non-zero rate with BOTHER, but we have zero rate after BOTHER is cleared. So we set 9600 as a sane default speed.

+

Quoted 9 lines
Quoted 6 lines

Review

Quoted 6 lines
drivers/tty/serial/8250/8250_lp8841.c new file +4 -0
+	/* We only support up to 115200 */
+	if (baud > 115200) {
+		baud = 115200;
+		tty_termios_encode_baud_rate(termios, baud,

baud);

(quoted diff) +1 -0
+	}

This one deals with the case when the rate is over 115200. If the previous case has been triggered, this one won't be.

Yeah, but I meant to unconditionally call it just once here every time. tty_termios_encode_baud_rate(termios, baud, baud);

Quoted 6 lines

+static int lp8841_serial_probe(struct platform_device *pdev)

Quoted 4 lines
Quoted 2 lines

+{
+     struct uart_8250_port uart = {};

{0}

Quoted 9 lines

---
drivers/tty/serial/8250/8250_lp8841.c: In function 'lp8841_serial_probe':
drivers/tty/serial/8250/8250_lp8841.c:124:32: warning: excess elements in struct initializer
  struct uart_8250_port uart = {0};
                                ^ drivers/tty/serial/8250/8250_lp8841.c:124:32: note: (near initialization for 'uart.port.lock.<anonymous>.rlock.raw_lock')

Do you have any warning verbosity enabled? I see a lot of stuff like this in the code

$ git grep -n 'struct .* = {0};' | wc -l
338
$ git grep -n 'struct .* = { \?0 \?};' | wc -l
550

( '… = { 0 };' included)

Quoted 3 lines

---

Zero triggers a warning. I'll use memset().

Either will work.

Quoted 2 lines

Thanks for lightning fast reviews. I'll resubmit v8 if there is no objections to the points above.

See above.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#232 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Sergei Ianovich
Quoted 3 lines · Andy Shevchenko

drivers/tty/serial/8250/8250_lp8841.c line 62

Quoted 1 line · Sergei Ianovich
drivers/tty/serial/8250/8250_lp8841.c new file +1 -0
+	len &= 3;

Mask as well to be defined.

Sure.

Quoted 2 lines

So, but if you support only fixed rates, why do you care about BOTHER at all?

If BOTHER is defined, tty_termios_baud_rate()
and tty_termios_encode_baud_rate() allow non-standard baud rates. I should clear it from c_cflag to indicate I don't support it.

Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
Quoted 1 line

I think you can call this unconditionally together with case > 115200.

The calls are orthogonal. This one deals with the case when BOTHER is
defined and set, and we have non-zero rate with BOTHER, but we have zero rate after BOTHER is cleared. So we set 9600 as a sane default speed.

Quoted 5 lines
Quoted 2 lines

This one deals with the case when the rate is over 115200. If the previous case has been triggered, this one won't be.

Yeah, but I meant to unconditionally call it just once here every time.

I see. It saves a few lines.

Quoted 10 lines
Quoted 9 lines

---
drivers/tty/serial/8250/8250_lp8841.c: In function 'lp8841_serial_probe':
drivers/tty/serial/8250/8250_lp8841.c:124:32: warning: excess elements in struct initializer
  struct uart_8250_port uart = {0};
                                ^ drivers/tty/serial/8250/8250_lp8841.c:124:32: note: (near initialization for 'uart.port.lock.<anonymous>.rlock.raw_lock')

Quoted 2 lines

Do you have any warning verbosity enabled? I see a lot of stuff like this in the code

Plain make.

The warning seems to be the result of initializing a spinlock with zero. Spinlocks are intentionally obfuscated, but I didn't investigate further.

Quoted 7 lines
$ git grep -n 'struct .* = {0};' | wc -l
338
$ git grep -n 'struct .* = { \?0 \?};' | wc -l
550

( '… = { 0 };' included)

The first structure member is most likely not a spinlock in those cases.

Quoted 5 lines
Quoted 3 lines

---

Zero triggers a warning. I'll use memset().

Either will work.

OK

The only remaining open point is BOTHER handling.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#233 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 5 lines · Sergei Ianovich
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sergei Ianovich
Quoted 1 line · Andy Shevchenko

On Tue, 2016-03-01 at 00:26 +0300, Sergei Ianovich wrote:

Quoted 20 lines
Quoted 3 lines

So, but if you support only fixed rates, why do you care about BOTHER
at all?

If BOTHER is defined, tty_termios_baud_rate()
and tty_termios_encode_baud_rate() allow non-standard baud rates. I should clear it from c_cflag to indicate I don't support it.

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Quoted 1 line

I think you can call this unconditionally together with case > 115200.

The calls are orthogonal. This one deals with the case when BOTHER
is
defined and set, and we have non-zero rate with BOTHER, but we have
zero rate after BOTHER is cleared. So we set 9600 as a sane default
speed.

Maybe you just set a baud rate nearest to the one from the table in case of BOTHER?

In that case perhaps you have to supply +-1 to the range. That's why I asked about uart_get_baud_rate().

Maybe this flow will work for you

if (BOTHER)
 clear BOTHER
 call uart_get_baud_rate()

?

Quoted 8 lines

The warning seems to be the result of initializing a spinlock with zero. Spinlocks are intentionally obfuscated, but I didn't investigate
further.

Quoted 3 lines
$ git grep -n 'struct .* = {0};' | wc -l
338
Quoted 7 lines
Quoted 4 lines
$ git grep -n 'struct .* = { \?0 \?};' | wc -l
550

( '… = { 0 };' included)

The first structure member is most likely not a spinlock in those cases.

Hmm... Interesting. On one hand the poison is reasonable, on the other we often do a memset() or {0} on structures, i.o.w. assign 0 as initial value until spinlock_init().

Arnd, what do you think about this (and similar) case(s)?

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#234 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 2 lines

Maybe you just set a baud rate nearest to the one from the table in case of BOTHER?

This is broken. BOTHER can be set with a perfectly valid baud rate that could equally be represented by B9600 say.

If you are stuck with limited ranges then

	switch(baud) {
	case 9600:
	case 4800:

etc

and don't worry about BOTHER, it's entirely transparent to you. The core kernel code will provide you with a baud rate number, the re-encoder will always do the right thing.

A driver should never care about BOTHER or any of the baud bits in the termios structure directly.

Alan

#235 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

In reply to Andy Shevchenko
Quoted 35 lines · Andy Shevchenko
Quoted 5 lines · Sergei Ianovich
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Sergei Ianovich
Quoted 1 line · Andy Shevchenko

On Tue, 2016-03-01 at 00:26 +0300, Sergei Ianovich wrote:

Quoted 21 lines
Quoted 3 lines

So, but if you support only fixed rates, why do you care about BOTHER
at all?

If BOTHER is defined, tty_termios_baud_rate()
and tty_termios_encode_baud_rate() allow non-standard baud rates. I should clear it from c_cflag to indicate I don't support it.

Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Quoted 1 line

I think you can call this unconditionally together with case

Quoted 1 line

115200.

The calls are orthogonal. This one deals with the case when BOTHER
is
defined and set, and we have non-zero rate with BOTHER, but we have
zero rate after BOTHER is cleared. So we set 9600 as a sane default
speed.

Maybe you just set a baud rate nearest to the one from the table in case of BOTHER?

In that case perhaps you have to supply +-1 to the range. That's why I
asked about uart_get_baud_rate().

Quoted 7 lines

Maybe this flow will work for you

if (BOTHER)
 clear BOTHER
 call uart_get_baud_rate()

?

It works well for standard rates, let it be so. If there ever is a problem, we can fix it.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#236 lore raw

Re: [PATCH v7] serial: support for 16550A serial ports on LP-8x4x

Quoted 10 lines
Quoted 7 lines

Maybe this flow will work for you

if (BOTHER)
 clear BOTHER
 call uart_get_baud_rate()

?

It works well for standard rates, let it be so. If there ever is a problem, we can fix it.

I'm NAKking the v7 PATCH because we spent ages getting all the drivers to use tty_termios_get_baud_rate() cleanly.

Get rid of everything in the ifdef BOTHER
Remove the if baud > 115200 stuff

For the default: entry in the case add

             tty_termios_encode_baud_rate(termios, 2400, 2400);

and all will be good. Anything not a standard rate will get 2400 baud and reported back to the user properly as that rate.

You could do matches for "within 10%" but really I don't think it matters and other drivers don't bother either when they have such fixed clocks.

Alan
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#237 lore raw

PATCH v8 1/1 serial: support for 16550A serial ports on LP-8x4x

In reply to Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

---
CC: Alan Cox <[email protected]>
CC: Andy Shevchenko <[email protected]>
CC: Arnd Bergmann <[email protected]>

v7..v8
* call serial8250_do_set_termios() after speed check, not before. This way clock divisor is properly inited for the new baud rate, if any
fix review comments by Andy Shevchenko
* change board variable name and type
* use ternary operators
* use #defines instead of magic numbers
* simplify speed check and use uart_get_baud_rate()
* zero-init uart structure
* re-organized probing calls

v6..v7
fix review comments by Andy Shevchenko
not applying Acked-by as the 1st change is big
* handle unsupported tty modes correctly
* remove extra check of platform_get_resource() result
* propagate error code from devm_ioremap_resource()
* drop uart.port.iobase for UPIO_MEM device

v5..v6
fix review comments by Arnd Bergmann
* remove wildcards from compatible
* update doc file
* drop interrupt parent from doc file
* replace uart w/ serial in device names in doc file

fix review comments by Andy Shevchenko
* exchange labels in switch block
* replace iowrite8() with writeb()
* compact comment to one line

v4..v5
* constify struct of_device_id
* drop .owner from struct platform_driver
* rewrite set_termios() baud rate hadnling as suggested by Alan Cox

v3..v4
* move DTS bindings to a different patch (8/21) as suggested by Heikki Krogerus

v2..v3
* no changes (except number 10/16 -> 12/21)

v0..v2
* register platform driver instead of platform device
* use device tree
* use devm helpers where possible

 .../bindings/serial/icpdas-lp8841-uart.txt         |  41 +++++
 drivers/tty/serial/8250/8250_lp8841.c              | 173 +++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig                    |  14 ++
 drivers/tty/serial/8250/Makefile                   |   2 +
 4 files changed, 230 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt
 create mode 100644 drivers/tty/serial/8250/8250_lp8841.c
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +41 -0
new file mode 100644
index 0000000..d6acd22
@@ -0,0 +1,41 @@
+* UART ports on ICP DAS LP-8841
+
+LP-8441, LP-8141 and LP-8041 are fully compatible.
+
+ICP DAS LP-8841 contains three additional serial ports interfaced via
+Analog Devices ADM213EA chips in addition to 3 serial ports on PXA CPU.
+
+The chips themselves are standard, they would work with 8250_core if
+properly connected. However, they are not connected normally. Al least
+some of their config pins are wired to a different address region. So
+the driver is board-specific.
+
+Required properties:
+- compatible : should be "icpdas,uart-lp8841"
+
+- reg : should provide 16 byte man IO memory region and 1 byte region for
+	termios
+
+- interrupts : should provide interrupt
+
+Optional property:
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly or implicitly from a parent node
+
+Examples (from pxa27x-lp8x4x.dts):
+
+		serial@9050 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9050 0x10
+			       0x9030 0x02>;
+			interrupts = <13>;
+			status = "okay";
+		};
+
+		serial@9060 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9060 0x10
+			       0x9032 0x02>;
+			interrupts = <14>;
+			status = "okay";
+		};
drivers/tty/serial/8250/8250_lp8841.c new file +173 -0

173 lines not on this page · raw message

drivers/tty/serial/8250/Kconfig +14 -0
index 3b5cf9c..68640c1 100644
@@ -394,3 +394,17 @@ config SERIAL_8250_PXA
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
+
+	  If you choose M here, the module name will be 8250_pxa.
+
+config SERIAL_8250_LP8841
+	tristate "Support 16550A ports on ICP DAS LP-8841"
+	depends on SERIAL_8250 && MACH_PXA27X_DT
+	select LP8841_IRQ
+	help
+	  In addition to serial ports on PXA270 SoC, LP-8841 has 1 dual
+	  RS232/RS485 port, 1 RS485 port and 1 RS232 port.
+
+	  Say N here, unless you plan to run this kernel on a LP-8841 system.
+
+	  If you choose M here, the module name will be 8250_lp8841.
drivers/tty/serial/8250/Makefile +2 -0
index d1e2f2d..10b4bf0 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT)	+= 8250_accent.o
 obj-$(CONFIG_SERIAL_8250_BOCA)		+= 8250_boca.o
 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554)	+= 8250_exar_st16c554.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
+obj-$(CONFIG_SERIAL_8250_LP8X4X)	+= 8250_lp8x4x.o
 obj-$(CONFIG_SERIAL_8250_FSL)		+= 8250_fsl.o
 obj-$(CONFIG_SERIAL_8250_DW)		+= 8250_dw.o
 obj-$(CONFIG_SERIAL_8250_EM)		+= 8250_em.o
@@ -30,5 +31,6 @@ obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
+obj-$(CONFIG_SERIAL_8250_LP8841)	+= 8250_lp8841.o
 
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
Signature · 1 line
2.7.0
#238 lore raw

PATCH v9 1/1 serial: support for 16550A serial ports on LP-8x4x

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

---
CC: Alan Cox <gnomes-qBU/[email protected]>
CC: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]>
CC: Arnd Bergmann <[email protected]>

v8..v9
fix review comments by Alan Cox
* further simplify speed check

v7..v8
* call serial8250_do_set_termios() after speed check, not before. This way clock divisor is properly inited for the new baud rate, if any
fix review comments by Andy Shevchenko
* change board variable name and type
* use ternary operators
* use #defines instead of magic numbers
* simplify speed check and use uart_get_baud_rate()
* zero-init uart structure
* re-organized probing calls

v6..v7
fix review comments by Andy Shevchenko
not applying Acked-by as the 1st change is big
* handle unsupported tty modes correctly
* remove extra check of platform_get_resource() result
* propagate error code from devm_ioremap_resource()
* drop uart.port.iobase for UPIO_MEM device

v5..v6
fix review comments by Arnd Bergmann
* remove wildcards from compatible
* update doc file
* drop interrupt parent from doc file
* replace uart w/ serial in device names in doc file

fix review comments by Andy Shevchenko
* exchange labels in switch block
* replace iowrite8() with writeb()
* compact comment to one line

v4..v5
* constify struct of_device_id
* drop .owner from struct platform_driver
* rewrite set_termios() baud rate hadnling as suggested by Alan Cox

v3..v4
* move DTS bindings to a different patch (8/21) as suggested by Heikki Krogerus

v2..v3
* no changes (except number 10/16 -> 12/21)

v0..v2
* register platform driver instead of platform device
* use device tree
* use devm helpers where possible

 .../bindings/serial/icpdas-lp8841-uart.txt         |  41 ++++++
 drivers/tty/serial/8250/8250_lp8841.c              | 159 +++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig                    |  14 ++
 drivers/tty/serial/8250/Makefile                   |   2 +
 4 files changed, 216 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt
 create mode 100644 drivers/tty/serial/8250/8250_lp8841.c
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +41 -0
new file mode 100644
index 0000000..d6acd22
@@ -0,0 +1,41 @@
+* UART ports on ICP DAS LP-8841
+
+LP-8441, LP-8141 and LP-8041 are fully compatible.
+
+ICP DAS LP-8841 contains three additional serial ports interfaced via
+Analog Devices ADM213EA chips in addition to 3 serial ports on PXA CPU.
+
+The chips themselves are standard, they would work with 8250_core if
+properly connected. However, they are not connected normally. Al least
+some of their config pins are wired to a different address region. So
+the driver is board-specific.
+
+Required properties:
+- compatible : should be "icpdas,uart-lp8841"
+
+- reg : should provide 16 byte man IO memory region and 1 byte region for
+	termios
+
+- interrupts : should provide interrupt
+
+Optional property:
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly or implicitly from a parent node
+
+Examples (from pxa27x-lp8x4x.dts):
+
+		serial@9050 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9050 0x10
+			       0x9030 0x02>;
+			interrupts = <13>;
+			status = "okay";
+		};
+
+		serial@9060 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9060 0x10
+			       0x9032 0x02>;
+			interrupts = <14>;
+			status = "okay";
+		};
drivers/tty/serial/8250/8250_lp8841.c new file +159 -0

159 lines not on this page · raw message

drivers/tty/serial/8250/Kconfig +14 -0
index 3b5cf9c..68640c1 100644
@@ -394,3 +394,17 @@ config SERIAL_8250_PXA
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
+
+	  If you choose M here, the module name will be 8250_pxa.
+
+config SERIAL_8250_LP8841
+	tristate "Support 16550A ports on ICP DAS LP-8841"
+	depends on SERIAL_8250 && MACH_PXA27X_DT
+	select LP8841_IRQ
+	help
+	  In addition to serial ports on PXA270 SoC, LP-8841 has 1 dual
+	  RS232/RS485 port, 1 RS485 port and 1 RS232 port.
+
+	  Say N here, unless you plan to run this kernel on a LP-8841 system.
+
+	  If you choose M here, the module name will be 8250_lp8841.
drivers/tty/serial/8250/Makefile +2 -0
index d1e2f2d..10b4bf0 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT)	+= 8250_accent.o
 obj-$(CONFIG_SERIAL_8250_BOCA)		+= 8250_boca.o
 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554)	+= 8250_exar_st16c554.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
+obj-$(CONFIG_SERIAL_8250_LP8X4X)	+= 8250_lp8x4x.o
 obj-$(CONFIG_SERIAL_8250_FSL)		+= 8250_fsl.o
 obj-$(CONFIG_SERIAL_8250_DW)		+= 8250_dw.o
 obj-$(CONFIG_SERIAL_8250_EM)		+= 8250_em.o
@@ -30,5 +31,6 @@ obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
+obj-$(CONFIG_SERIAL_8250_LP8841)	+= 8250_lp8841.o
 
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
Signature · 6 lines
2.7.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v9 1/1
#239 lore raw

Re: [PATCH v9] serial: support for 16550A serial ports on LP-8x4x

Quoted 9 lines · Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

Sorry, but still few nitpicks and then

drivers/tty/serial/8250/8250_lp8841.c line 25

Quoted 2 lines
drivers/tty/serial/8250/8250_lp8841.c new file +2 -0
+#define LP8841_DATA_LEN_MASK           0x3
+#define LP8841_DATA_LEN_SHIFT_OFFSET   3

No need to have _OFFSET suffix.

drivers/tty/serial/8250/8250_lp8841.c line 33

Quoted 9 lines
drivers/tty/serial/8250/8250_lp8841.c new file +8 -0
+
+static void lp8841_serial_set_termios(struct uart_port *port,
+               struct ktermios *termios, struct ktermios *old)
+{
+       unsigned int baud;
+       u8 value;
 
+       unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
+       struct lp8841_serial_data *data = port->private_data;

I would rearrange to have assignments first in the definition block.

Code duplication (no idea if it worth to fix):

+ case 2400:
+ value |= 1;
+ break;
+ default:

+               value |= 1;
+               tty_termios_encode_baud_rate(termios, 2400, 2400);
+               break;

drivers/tty/serial/8250/8250_lp8841.c line 96

Quoted 3 lines
drivers/tty/serial/8250/8250_lp8841.c new file +3 -0
+static int lp8841_serial_probe(struct platform_device *pdev)
+{
+       struct uart_8250_port uart = {};

No need {} since memset().

drivers/tty/serial/8250/8250_lp8841.c line 101

Quoted 5 lines
drivers/tty/serial/8250/8250_lp8841.c new file +5 -0
+       struct lp8841_serial_data *data;
+       struct resource *mmres, *mires;
+       int ret;
+
+       memset(&uart, 0, sizeof(uart));

Move this closer to the first assignment of a field.

Quoted 4 lines
drivers/tty/serial/8250/8250_lp8841.c new file +4 -0
+
+       mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!mmres)
+               return -ENODEV;

drivers/tty/serial/8250/8250_lp8841.c line 115

Quoted 10 lines
drivers/tty/serial/8250/8250_lp8841.c new file +10 -0
+
+       data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       mires = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+       data->ios_mem = devm_ioremap_resource(&pdev->dev, mires);
+       if (IS_ERR(data->ios_mem))
+               return PTR_ERR(data->ios_mem);
+

+ memset(&uart, 0, sizeof(uart));

Quoted 9 lines
drivers/tty/serial/8250/8250_lp8841.c new file +9 -0
+       uart.port.iotype = UPIO_MEM;
+       uart.port.mapbase = mmres->start;
+       uart.port.regshift = 1;
+       uart.port.irq = platform_get_irq(pdev, 0);
+       uart.port.flags = UPF_IOREMAP;
+       uart.port.dev = &pdev->dev;
+       uart.port.uartclk = 14745600;
+       uart.port.set_termios = lp8841_serial_set_termios;
+       uart.port.private_data = data;
Signature · 6 lines
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#240 lore raw

PATCH v10 1/1 serial: support for 16550A serial ports on LP-8x4x

In reply to Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

---
CC: Alan Cox <[email protected]>
CC: Arnd Bergmann <[email protected]>

v9..v10
fix review comments by Andy Shevchenko
* fix code styling

v8..v9
fix review comments by Alan Cox
* further simplify speed check

v7..v8
* call serial8250_do_set_termios() after speed check, not before. This way clock divisor is properly inited for the new baud rate, if any
fix review comments by Andy Shevchenko
* change board variable name and type
* use ternary operators
* use #defines instead of magic numbers
* simplify speed check and use uart_get_baud_rate()
* zero-init uart structure
* re-organized probing calls

v6..v7
fix review comments by Andy Shevchenko
not applying Acked-by as the 1st change is big
* handle unsupported tty modes correctly
* remove extra check of platform_get_resource() result
* propagate error code from devm_ioremap_resource()
* drop uart.port.iobase for UPIO_MEM device

v5..v6
fix review comments by Arnd Bergmann
* remove wildcards from compatible
* update doc file
* drop interrupt parent from doc file
* replace uart w/ serial in device names in doc file

fix review comments by Andy Shevchenko
* exchange labels in switch block
* replace iowrite8() with writeb()
* compact comment to one line

v4..v5
* constify struct of_device_id
* drop .owner from struct platform_driver
* rewrite set_termios() baud rate hadnling as suggested by Alan Cox

v3..v4
* move DTS bindings to a different patch (8/21) as suggested by Heikki Krogerus

v2..v3
* no changes (except number 10/16 -> 12/21)

v0..v2
* register platform driver instead of platform device
* use device tree
* use devm helpers where possible

 .../bindings/serial/icpdas-lp8841-uart.txt         |  41 ++++++
 drivers/tty/serial/8250/8250_lp8841.c              | 156 +++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig                    |  14 ++
 drivers/tty/serial/8250/Makefile                   |   2 +
 4 files changed, 213 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt
 create mode 100644 drivers/tty/serial/8250/8250_lp8841.c
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +41 -0
new file mode 100644
index 0000000..d6acd22
@@ -0,0 +1,41 @@
+* UART ports on ICP DAS LP-8841
+
+LP-8441, LP-8141 and LP-8041 are fully compatible.
+
+ICP DAS LP-8841 contains three additional serial ports interfaced via
+Analog Devices ADM213EA chips in addition to 3 serial ports on PXA CPU.
+
+The chips themselves are standard, they would work with 8250_core if
+properly connected. However, they are not connected normally. Al least
+some of their config pins are wired to a different address region. So
+the driver is board-specific.
+
+Required properties:
+- compatible : should be "icpdas,uart-lp8841"
+
+- reg : should provide 16 byte man IO memory region and 1 byte region for
+	termios
+
+- interrupts : should provide interrupt
+
+Optional property:
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly or implicitly from a parent node
+
+Examples (from pxa27x-lp8x4x.dts):
+
+		serial@9050 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9050 0x10
+			       0x9030 0x02>;
+			interrupts = <13>;
+			status = "okay";
+		};
+
+		serial@9060 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9060 0x10
+			       0x9032 0x02>;
+			interrupts = <14>;
+			status = "okay";
+		};
drivers/tty/serial/8250/8250_lp8841.c new file +156 -0

156 lines not on this page · raw message

drivers/tty/serial/8250/Kconfig +14 -0
index 3b5cf9c..68640c1 100644
@@ -394,3 +394,17 @@ config SERIAL_8250_PXA
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
+
+	  If you choose M here, the module name will be 8250_pxa.
+
+config SERIAL_8250_LP8841
+	tristate "Support 16550A ports on ICP DAS LP-8841"
+	depends on SERIAL_8250 && MACH_PXA27X_DT
+	select LP8841_IRQ
+	help
+	  In addition to serial ports on PXA270 SoC, LP-8841 has 1 dual
+	  RS232/RS485 port, 1 RS485 port and 1 RS232 port.
+
+	  Say N here, unless you plan to run this kernel on a LP-8841 system.
+
+	  If you choose M here, the module name will be 8250_lp8841.
drivers/tty/serial/8250/Makefile +2 -0
index d1e2f2d..10b4bf0 100644
@@ -18,6 +18,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT)	+= 8250_accent.o
 obj-$(CONFIG_SERIAL_8250_BOCA)		+= 8250_boca.o
 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554)	+= 8250_exar_st16c554.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
+obj-$(CONFIG_SERIAL_8250_LP8X4X)	+= 8250_lp8x4x.o
 obj-$(CONFIG_SERIAL_8250_FSL)		+= 8250_fsl.o
 obj-$(CONFIG_SERIAL_8250_DW)		+= 8250_dw.o
 obj-$(CONFIG_SERIAL_8250_EM)		+= 8250_em.o
@@ -30,5 +31,6 @@ obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
+obj-$(CONFIG_SERIAL_8250_LP8841)	+= 8250_lp8841.o
 
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
Signature · 1 line
2.7.0
maintainer
#194 lore raw

Re: [PATCH v6] arm: pxa: support ICP DAS LP-8x4x FPGA irq

In reply to Sergei Ianovich
Quoted 76 lines · Sergei Ianovich

ICP DAS LP-8x4x contains FPGA chip. The chip functions as an interrupt source providing 16 additional interrupts among other things. The interrupt lines are muxed to a GPIO pin of a 2nd level PXA-GPIO interrupt controller. GPIO pins of the 2nd level controller are in turn muxed to a CPU interrupt line.

Until pxa is completely converted to device tree, it is impossible to use IRQCHIP_DECLARE() and the irqdomain needs to added manually. Drivers for the on-CPU IRQs and GPIO-IRQs are loaded using postcore_initcall(). We need to have all irq domain drivers loaded prior to DT parsing in order to allow normal initialization of IRQ resources with DT.

v5..v6
fixes according to Rob Herring review comments:
* drop wildcards in binding and file names
* rename alias 'fpga'->'fpga_irq'

fixes according to Marc Zyngier review comments:
* use writeb/readb not iowrite8/ioread8
* redefine 2nd mask using inversion on 1st
* add comments

v4..v5
* constify struct of_device_id
* drop irq number from handler signature

v3.2..v4
* move DTS binding to a different patch (8/21)

v3.1..v3.2
fixes to apply Linus Walleij's "Reviewed-by":
* add kerneldoc comment for state container struct
* rename irq -> hwirq for clarity
* drop overzealous error checks from the hotpaths

v3..v3.1
fixes according to Linus Walleij review comments:
* update commit message
* use state container instead of global variables
* get hardware irq nums from irq_data, don't calculate them
* use BIT() macro
* add defines for system irq register masks
* replace cycle control variable with break
* use better names for resource variables
* add a linear domain instead of a legacy one
* use irq_create_mapping() instead of irq_alloc_desc()

v2..v3
* no changes (except number 09/16 -> 11/21)

v0..v2
* extract irqchip and move to drivers/irqchip/
* use device tree
* use devm helpers where possible

---
 .../interrupt-controller/icpdas-lp8x4x-irq.txt     |  49 ++++
 drivers/irqchip/Kconfig                            |   5 +
 drivers/irqchip/Makefile                           |   1 +
 drivers/irqchip/irq-lp8841.c                       | 246 +++++++++++++++++++++
 4 files changed, 301 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt
 create mode 100644 drivers/irqchip/irq-lp8841.c
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +0 -0
new file mode 100644
index 0000000..a72109b

Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +7 -0
@@ -0,0 +1,49 @@
+ICP DAS LP-8841 FPGA Interrupt Controller
+
+ICP DAS LP-8841 contains FPGA chip. The chip functions as a interrupt
+source providing 16 additional interrupts among other things.
+
+Required properties:
+- compatible : should be "icpdas,lp8x4x-irq"

You've still got wildcards here. Seems to be an oversight as the example and code have "icpdas,lp8841-irq".

Quoted 8 lines
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +8 -0
+
+- reg: physical base address of the controller and length of memory mapped
+  region.
+
+- interrupt-controller : identifies the node as an interrupt controller
+
+- #interrupt-cells : should be 1
+

Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +10 -0
+- interrupts : should provide interrupt
+
+Optional properties:
+
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly and implicitly from a parent node
+
+Example:
+
+fpgairq: irq@9006 {

Still not right... interrupt-controller@9006

Quoted 14 lines
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +14 -0
+	compatible = "icpdas,lp8841-irq";
+	reg = <0x9006 0x16>;
+	interrupt-parent = <&gpio>;
+	interrupts = <3 IRQ_TYPE_EDGE_FALLING>;
+	#interrupt-cells = <1>;
+	interrupt-controller;
+	status = "okay";
+};
+
+serial@9050 {
+	compatible = "icpdas,lp8841-uart";
+	reg =  <0x9050 0x10
+		0x9030 0x02>;
+	interrupts = <13>;

Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt line 49

Quoted 10 lines
Documentation/devicetree/bindings/interrupt-controller/icpdas-lp8x4x-irq.txt new file +10 -0
+	status = "okay";
+};
+
+serial@9060 {
+	compatible = "icpdas,lp8841-uart";
+	reg =  <0x9060 0x10
+		0x9032 0x02>;
+	interrupts = <14>;
+	status = "okay";
+};

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#241 lore raw

Re: [PATCH v10] serial: support for 16550A serial ports on LP-8x4x

In reply to Sergei Ianovich
Quoted 6 lines · Sergei Ianovich

The patch adds support for 3 additional LP-8x4x built-in serial ports.

The device can also host up to 8 extension cards with 4 serial ports on each card for a total of 35 ports. However, I don't have the hardware to test extension cards, so they are not supported, yet.

That's a lot of serial ports...

[...]

Quoted 6 lines
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +0 -0
new file mode 100644
index 0000000..d6acd22

Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +8 -0
@@ -0,0 +1,41 @@
+* UART ports on ICP DAS LP-8841
+
+LP-8441, LP-8141 and LP-8041 are fully compatible.
+
+ICP DAS LP-8841 contains three additional serial ports interfaced via
+Analog Devices ADM213EA chips in addition to 3 serial ports on PXA CPU.
+
+The chips themselves are standard, they would work with 8250_core if

Describe in h/w terms how they are different, not what Linux driver won't work.

Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt line 9

Quoted 1 line
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +1 -0
+properly connected. However, they are not connected normally. Al least

s/Al/At/

Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt line 16

Quoted 7 lines
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +7 -0
+some of their config pins are wired to a different address region. So
+the driver is board-specific.
+
+Required properties:
+- compatible : should be "icpdas,uart-lp8841"
+
+- reg : should provide 16 byte man IO memory region and 1 byte region for

What is "man IO"?

Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt line 17

Quoted 1 line
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +1 -0
+	termios

termios is a Linux term.

Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt line 19

Quoted 2 lines
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +2 -0
+
+- interrupts : should provide interrupt

Perhaps you should include other properties standard for 8250 such as access size or shift. Possibly if the non-standard bits are already configured, the UART could be used for earlycon?

Quoted 22 lines
Documentation/devicetree/bindings/serial/icpdas-lp8841-uart.txt new file +22 -0
+
+Optional property:
+- interrupt-parent : should provide a link to interrupt controller either
+		     explicitly or implicitly from a parent node
+
+Examples (from pxa27x-lp8x4x.dts):
+
+		serial@9050 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9050 0x10
+			       0x9030 0x02>;
+			interrupts = <13>;
+			status = "okay";
+		};
+
+		serial@9060 {
+			compatible = "icpdas,uart-lp8841";
+			reg = <0x9060 0x10
+			       0x9032 0x02>;
+			interrupts = <14>;
+			status = "okay";
+		};

[...]

Quoted 5 lines
drivers/tty/serial/8250/Kconfig +0 -0
index 3b5cf9c..68640c1 100644

drivers/tty/serial/8250/Kconfig config SERIAL_8250_PXA · line 403

Quoted 10 lines
drivers/tty/serial/8250/Kconfig +7 -0
@@ -394,3 +394,17 @@ config SERIAL_8250_PXA
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
+
+	  If you choose M here, the module name will be 8250_pxa.
+
+config SERIAL_8250_LP8841
+	tristate "Support 16550A ports on ICP DAS LP-8841"
+	depends on SERIAL_8250 && MACH_PXA27X_DT
+	select LP8841_IRQ

Generally, drivers don't select their interrupt controller.

Quoted 13 lines
drivers/tty/serial/8250/Kconfig +7 -0
+	help
+	  In addition to serial ports on PXA270 SoC, LP-8841 has 1 dual
+	  RS232/RS485 port, 1 RS485 port and 1 RS232 port.
+
+	  Say N here, unless you plan to run this kernel on a LP-8841 system.
+
+	  If you choose M here, the module name will be 8250_lp8841.
drivers/tty/serial/8250/Makefile +0 -0
index d1e2f2d..10b4bf0 100644

drivers/tty/serial/8250/Makefile obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o · line 22

Quoted 5 lines
drivers/tty/serial/8250/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_SERIAL_8250_ACCENT)	+= 8250_accent.o
 
 obj-$(CONFIG_SERIAL_8250_BOCA)		+= 8250_boca.o
 obj-$(CONFIG_SERIAL_8250_EXAR_ST16C554)	+= 8250_exar_st16c554.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
+obj-$(CONFIG_SERIAL_8250_LP8X4X)	+= 8250_lp8x4x.o

This should be dropped.

drivers/tty/serial/8250/Makefile obj-$(CONFIG_SERIAL_8250_INGENIC) += 8250_ingenic.o · line 34

Quoted 8 lines
drivers/tty/serial/8250/Makefile +0 -0
 obj-$(CONFIG_SERIAL_8250_FSL)		+= 8250_fsl.o
 obj-$(CONFIG_SERIAL_8250_DW)		+= 8250_dw.o

obj-$(CONFIG_SERIAL_8250_EM) += 8250_em.o

drivers/tty/serial/8250/Makefile +1 -0
@@ -30,5 +31,6 @@ obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
+obj-$(CONFIG_SERIAL_8250_LP8841)	+= 8250_lp8841.o

This should be in alphabetical order. OF_PLATFORM is not for legacy reasons I think.

Quoted 5 lines
drivers/tty/serial/8250/Makefile +0 -0
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
Signature · 1 line
2.7.0
#184 lore raw

Re: [PATCH v6] mtd: support BB SRAM on ICP DAS LP-8x4x

In reply to Sergei Ianovich

Hi Sergei,

A few more issues...

Quoted 241 lines · Sergei Ianovich

This provides an MTD device driver for 512kB of battery backed up SRAM on ICPDAS LP-8X4X programmable automation controllers.

SRAM chip is connected via FPGA and is not accessible without a driver, unlike flash memory which is wired to CPU MMU.

This SRAM becomes an excellent persisent storage of volatile process data like counter values and sensor statuses. Storing those data in flash or mmc card is not a viable solution.

v5..v6
* replace wildcards in compatible and module name
* drop obsolete mtd_part_parser_data.of_node

v4..v5
* remove .owner from struct platform_driver
* constify struct of_device_id
for further Brian Norris comments:
* drop unused property from doc file
* move defconfig update to a different file
* drop extra match w/ of_match_device()

v3..v4 for Brian Norris 'Reviewed-by'
* add doc file for DT binding
* move DTS binding to a different patch (8/21)
* drop unused include directive
* drop safely unused callback
* drop non-default partion probe types
* drop duplicate error checks
* drop duplicate error reporting
* fixed error message on MTD registeration
* fixed module removal routine

v2..v3
* no changes (except number 08/16 -> 10/21)

v0..v2
* use device tree
* use devm helpers where possible

---
 .../devicetree/bindings/mtd/icpdas-lp8841-sram.txt |  23 +++
 drivers/mtd/devices/Kconfig                        |  14 ++
 drivers/mtd/devices/Makefile                       |   1 +
 drivers/mtd/devices/sram_lp8841.c                  | 198 +++++++++++++++++++++
 4 files changed, 236 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/icpdas-lp8841-sram.txt
 create mode 100644 drivers/mtd/devices/sram_lp8841.c
Documentation/devicetree/bindings/mtd/icpdas-lp8841-sram.txt new file +23 -0
new file mode 100644
index 0000000..3c1007a
@@ -0,0 +1,23 @@
+512kB battery backed up SRAM on ICP DAS LP-8841 industrial computers
+
+LP-8441, LP-8141, and LP-8041 differ from LP-8841 only in expansion
+slot count.
+
+Required properties:
+- compatible : should be "icpdas,lp8841-sram"
+
+- reg: physical base addresses and region lengths of
+       * IO memory range
+       * SRAM page selector
+
+SRAM chip is connected via FPGA and is not accessible without a driver,
+unlike flash memory which is wired to CPU MMU. Driver is essentially
+an address translation routine.
+
+Example:
+
+	sram@a000 {
+		compatible = "icpdas,lp8841-sram";
+		reg = <0xa000 0x1000
+		       0x901e 0x1>;
+	};
drivers/mtd/devices/Kconfig +14 -0
index f73c416..ecf5733 100644
@@ -233,4 +233,18 @@ config BCH_CONST_T
 	default 4
 endif
 
+config MTD_SRAM_LP8841
+	tristate "SRAM on ICP DAS LP-8841"
+	depends on OF && ARCH_PXA
+       ---help---
+	 This provides an MTD device driver for 512kiB of battery backed up SRAM
+	 on ICPDAS LP-8X41 programmable automation controllers.
+
+	 SRAM chip is connected via FPGA and is not accessible without a driver,
+	 unlike flash memory which is wired to CPU MMU.
+
+	 Say N, unless you plan to run this kernel on LP-8X41.
+
+	 If you say M, the module will be called sram_lp8841.
+
 endmenu
drivers/mtd/devices/Makefile +1 -0
index 7912d3a..46df5d6 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_MTD_SST25L)	+= sst25l.o
 obj-$(CONFIG_MTD_BCM47XXSFLASH)	+= bcm47xxsflash.o
 obj-$(CONFIG_MTD_ST_SPI_FSM)    += st_spi_fsm.o
 obj-$(CONFIG_MTD_POWERNV_FLASH)	+= powernv_flash.o
+obj-$(CONFIG_MTD_SRAM_LP8841)	+= sram_lp8841.o
 
 
 CFLAGS_docg3.o			+= -I$(src)
drivers/mtd/devices/sram_lp8841.c new file +119 -0
new file mode 100644
index 0000000..5d5d942
@@ -0,0 +1,198 @@
+/*
+ *  linux/drivers/mtd/devices/sram_lp8841.c
+ *
+ *  MTD Driver for SRAM on ICP DAS LP-8841
+ *  Copyright (C) 2013 Sergei Ianovich <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation or any later version.
+ */
+
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mtd/map.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/platform_device.h>
+#include <linux/of_device.h>
+#include <linux/slab.h>
+#include <linux/string_helpers.h>
+#include <linux/types.h>
+
+struct lp8841_sram_info {
+	void __iomem	*bank;
+	void __iomem	*virt;
+	struct mutex	lock;
+	unsigned	active_bank;
+	struct mtd_info	mtd;
+};
+
+static int
+lp8841_sram_erase(struct mtd_info *mtd, struct erase_info *instr)
+{
+	struct lp8841_sram_info *info = mtd->priv;
+	unsigned bank = instr->addr >> 11;
+	unsigned offset = (instr->addr & 0x7ff) << 1;
+	loff_t i;
+
+	mutex_lock(&info->lock);
+	if (unlikely(bank != info->active_bank)) {
+		info->active_bank = bank;
+		iowrite8(bank, info->bank);
+	}
+	for (i = 0; i < instr->len; i++) {
+		iowrite8(0xff, info->virt + offset);
+		offset += 2;
+		if (unlikely(offset == 0)) {
+			info->active_bank++;
+			iowrite8(info->active_bank, info->bank);
+		}
+	}
+	mutex_unlock(&info->lock);
+	instr->state = MTD_ERASE_DONE;
+	mtd_erase_callback(instr);
+
+	return 0;
+}
+
+static int
+lp8841_sram_write(struct mtd_info *mtd, loff_t to, size_t len,
+		size_t *retlen, const u_char *b)
+{
+	struct lp8841_sram_info *info = mtd->priv;
+	unsigned bank = to >> 11;
+	unsigned offset = (to & 0x7ff) << 1;
+	loff_t i;
+
+	mutex_lock(&info->lock);
+	if (unlikely(bank != info->active_bank)) {
+		info->active_bank = bank;
+		iowrite8(bank, info->bank);
+	}
+	for (i = 0; i < len; i++) {
+		iowrite8(b[i], info->virt + offset);
+		offset += 2;
+		if (unlikely(offset == 0)) {
+			info->active_bank++;
+			iowrite8(info->active_bank, info->bank);
+		}
+	}
+	mutex_unlock(&info->lock);
+	*retlen = len;
+	return 0;
+}
+
+static int
+lp8841_sram_read(struct mtd_info *mtd, loff_t from, size_t len,
+		size_t *retlen, u_char *b)
+{
+	struct lp8841_sram_info *info = mtd->priv;
+	unsigned bank = from >> 11;
+	unsigned offset = (from & 0x7ff) << 1;
+	loff_t i;
+
+	mutex_lock(&info->lock);
+	if (unlikely(bank != info->active_bank)) {
+		info->active_bank = bank;
+		iowrite8(bank, info->bank);
+	}
+	for (i = 0; i < len; i++) {
+		b[i] = ioread8(info->virt + offset);
+		offset += 2;
+		if (unlikely(offset == 0)) {
+			info->active_bank++;
+			iowrite8(info->active_bank, info->bank);
+		}
+	}
+	mutex_unlock(&info->lock);
+	*retlen = len;
+	return 0;
+}
+
+static const struct of_device_id of_flash_match[] = {
+	{
+		.compatible	= "icpdas,lp8841-sram",
+	},
+	{ },

drivers/mtd/devices/sram_lp8841.c line 129

Quoted 10 lines
drivers/mtd/devices/sram_lp8841.c new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, of_flash_match);
+
+static int
+lp8841_sram_probe(struct platform_device *pdev)
+{
+	struct lp8841_sram_info *info;
+	struct resource *res_virt, *res_bank;
+	char sz_str[16];
+	struct mtd_part_parser_data ppdata;

You don't need this struct any more.

Quoted 13 lines
drivers/mtd/devices/sram_lp8841.c new file +13 -0
+	int err = 0;
+
+	info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
+	if (!info)
+		return -ENOMEM;
+
+	res_virt = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	info->virt =  devm_ioremap_resource(&pdev->dev, res_virt);
+	if (IS_ERR(info->virt))
+		return PTR_ERR(info->virt);
+
+	res_bank = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+	info->bank = devm_ioremap_resource(&pdev->dev, res_bank);

drivers/mtd/devices/sram_lp8841.c line 152

Quoted 10 lines
drivers/mtd/devices/sram_lp8841.c new file +10 -0
+	if (IS_ERR(info->bank))
+		return PTR_ERR(info->bank);
+
+	info->mtd.priv = info;
+	info->mtd.name = "SRAM";
+	info->mtd.type = MTD_RAM;
+	info->mtd.flags = MTD_CAP_RAM;
+	info->mtd.size = resource_size(res_virt) << 7;
+	info->mtd.erasesize = 512;
+	info->mtd.writesize = 4;

Can you please set mtd.writebufsize to an appropriate value too? Maybe it's just the same as writesize.

drivers/mtd/devices/sram_lp8841.c line 156

Quoted 4 lines
drivers/mtd/devices/sram_lp8841.c new file +4 -0
+	info->mtd._erase = lp8841_sram_erase;
+	info->mtd._write = lp8841_sram_write;
+	info->mtd._read = lp8841_sram_read;
+	info->mtd.owner = THIS_MODULE;

If you set info->mtd.dev.parent (please do), you don't need the above line.

drivers/mtd/devices/sram_lp8841.c line 163

Quoted 7 lines
drivers/mtd/devices/sram_lp8841.c new file +7 -0
+
+	mutex_init(&info->lock);
+	iowrite8(info->active_bank, info->bank);
+	platform_set_drvdata(pdev, info);
+
+	err = mtd_device_parse_register(&info->mtd, NULL, &ppdata,
+			NULL, 0);

This can just be:

	err = mtd_device_register(&info->mtd, NULL, 0);
Quoted 25 lines
drivers/mtd/devices/sram_lp8841.c new file +25 -0
+
+	if (err < 0) {
+		dev_err(&pdev->dev, "failed to register MTD\n");
+		return err;
+	}
+
+	string_get_size(info->mtd.size, 1, STRING_UNITS_2, sz_str,
+			sizeof(sz_str));
+	dev_info(&pdev->dev, "using %s SRAM on LP-8X4X as %s\n", sz_str,
+			dev_name(&info->mtd.dev));
+	return 0;
+}
+
+static int
+lp8841_sram_remove(struct platform_device *dev)
+{
+	struct lp8841_sram_info *info = platform_get_drvdata(dev);
+
+	return mtd_device_unregister(&info->mtd);
+}
+
+static struct platform_driver lp8841_sram_driver = {
+	.driver = {
+		.name		= "sram-lp8841",
+		.of_match_table = of_flash_match,

drivers/mtd/devices/sram_lp8841.c line 198

Quoted 10 lines
drivers/mtd/devices/sram_lp8841.c new file +10 -0
+	},
+	.probe		= lp8841_sram_probe,
+	.remove		= lp8841_sram_remove,
+};
+
+module_platform_driver(lp8841_sram_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Sergei Ianovich");
+MODULE_DESCRIPTION("MTD driver for SRAM on ICPDAS LP-8841");

Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer Reviewed-by Heikki Krogerus Tested-by
#266 lore raw

Re: [PATCH v6] serial: rewrite pxa2xx-uart to use 8250_core

In reply to Robert Jarzmik
Quoted 11 lines · Robert Jarzmik
Quoted 2 lines
Quoted 2 lines

If so, great, get the platform maintainer to sign off on this please and then resend it.

If you're talking about the PXA maintainer, then :

I'm happy with the patch, all pxa board maintainers have been warned, and there exists a fallback solution.

So let's go forward, and if people complain, let them complain and forward them to me.

Hi Greg,

I rebased and retested the patch (both devicetree and legacy boards, multiple pxa variants, early console and standard console), and it does work. The fallback on the old driver works as well.

I also signed it as the pxa maintainer, and I'm pushing it now, in [2].

If you want context, it's archived in [1].

If you're overburdened and feel there won't be a merge conflict in your serial tree, I can take it through pxa tree provided you ack it, or you can take it, just let me know.

Cheers.

Signature · 7 lines
Robert

[1] Original discussion
    https://patchwork.kernel.org/patch/7918421/

[2] The patch
---8>---
Quoted 1 line

From 6d9bd0c05c9c7bf42ee1655f3a50dcff959bc87d Mon Sep 17 00:00:00 2001

From: Sergey Yanovich <[email protected]>
Date: Thu, 24 Dec 2015 18:15:14 +0300
Subject: [PATCH] serial: rewrite pxa2xx-uart to use 8250_core

pxa2xx-uart was a separate uart platform driver. It was declaring the same device names and numbers as 8250 driver. As a result, it was impossible to use 8250 driver on PXA SoCs.

Upon closer examination pxa2xx-uart turned out to be a clone of 8250_core driver.

Workaround for Erratum #19 according to Marvel(R) PXA270M Processor Specification Update (April 19, 2010) is dropped. 8250_core reads from FIFO immediately after checking DR bit in LSR.

The patch leaves the original SERIAL_PXA driver around. The original driver is just marked DEPRECATED in Kconfig and C source. When the original driver is considered safe to remove, no changes to SERIAL_8250 will be necessary.

Compiling SERIAL_8250_CONSOLE and SERIAL_PXA_CONSOLE even without SERIAL_8250_PXA breaks console for SERIAL_PXA. For this reasons, the new and the original drivers are made mutually exclusive.

CC Heikki Krogerus <[email protected]>
CC James Cameron <[email protected]>
CC Greg Kroah-Hartman <[email protected]>
CC Robert Jarzmik <[email protected]>
CC Russell King <[email protected]>
[rebased on v4.8]
---
 drivers/tty/serial/8250/8250_pxa.c | 177 +++++++++++++++++++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig    |  10 +++
 drivers/tty/serial/8250/Makefile   |   1 +
 drivers/tty/serial/Kconfig         |  17 +++-
 drivers/tty/serial/Makefile        |   2 +-
 drivers/tty/serial/pxa.c           |   4 +-
 6 files changed, 207 insertions(+), 4 deletions(-)
 create mode 100644 drivers/tty/serial/8250/8250_pxa.c
drivers/tty/serial/8250/8250_pxa.c new file +177 -0
new file mode 100644
index 000000000000..6a14df013754
@@ -0,0 +1,177 @@
+/*
+ *  drivers/tty/serial/8250/8250_pxa.c -- driver for PXA on-board UARTS
+ *  Copyright:	(C) 2013 Sergei Ianovich <[email protected]>
+ *
+ *  replaces drivers/serial/pxa.c by Nicolas Pitre
+ *  Created:	Feb 20, 2003
+ *  Copyright:	(C) 2003 Monta Vista Software, Inc.
+ *
+ *  Based on drivers/serial/8250.c by Russell King.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/serial_8250.h>
+#include <linux/serial_core.h>
+#include <linux/serial_reg.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/pm_runtime.h>
+
+#include "8250.h"
+
+struct pxa8250_data {
+	int			line;
+	struct clk		*clk;
+};
+
+#ifdef CONFIG_PM
+static int serial_pxa_suspend(struct device *dev)
+{
+	struct pxa8250_data *data = dev_get_drvdata(dev);
+
+	serial8250_suspend_port(data->line);
+
+	return 0;
+}
+
+static int serial_pxa_resume(struct device *dev)
+{
+	struct pxa8250_data *data = dev_get_drvdata(dev);
+
+	serial8250_resume_port(data->line);
+
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops serial_pxa_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(serial_pxa_suspend, serial_pxa_resume)
+};
+
+static const struct of_device_id serial_pxa_dt_ids[] = {
+	{ .compatible = "mrvl,pxa-uart", },
+	{ .compatible = "mrvl,mmp-uart", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids);
+
+/* Uart divisor latch write */
+static void serial_pxa_dl_write(struct uart_8250_port *up, int value)
+{
+	unsigned int dll;
+
+	serial_out(up, UART_DLL, value & 0xff);
+	/*
+	 * work around Erratum #74 according to Marvel(R) PXA270M Processor
+	 * Specification Update (April 19, 2010)
+	 */
+	dll = serial_in(up, UART_DLL);
+	WARN_ON(dll != (value & 0xff));
+
+	serial_out(up, UART_DLM, value >> 8 & 0xff);
+}
+
+
+static void serial_pxa_pm(struct uart_port *port, unsigned int state,
+	      unsigned int oldstate)
+{
+	struct pxa8250_data *data = port->private_data;
+
+	if (!state)
+		clk_prepare_enable(data->clk);
+	else
+		clk_disable_unprepare(data->clk);
+}
+
+static int serial_pxa_probe(struct platform_device *pdev)
+{
+	struct uart_8250_port uart = {};
+	struct pxa8250_data *data;
+	struct resource *mmres, *irqres;
+	int ret;
+
+	mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+	if (!mmres || !irqres)
+		return -ENODEV;
+
+	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(data->clk))
+		return PTR_ERR(data->clk);
+
+	ret = clk_prepare(data->clk);
+	if (ret)
+		return ret;
+
+	uart.port.type = PORT_XSCALE;
+	uart.port.iotype = UPIO_MEM32;
+	uart.port.mapbase = mmres->start;
+	uart.port.regshift = 2;
+	uart.port.irq = irqres->start;
+	uart.port.fifosize = 64;
+	uart.port.flags = UPF_IOREMAP | UPF_SKIP_TEST;
+	uart.port.dev = &pdev->dev;
+	uart.port.uartclk = clk_get_rate(data->clk);
+	uart.port.pm = serial_pxa_pm;
+	uart.port.private_data = data;
+	uart.dl_write = serial_pxa_dl_write;
+
+	ret = serial8250_register_8250_port(&uart);
+	if (ret < 0)
+		goto err_clk;
+
+	data->line = ret;
+
+	platform_set_drvdata(pdev, data);
+
+	return 0;
+
+ err_clk:
+	clk_unprepare(data->clk);
+	return ret;
+}
+
+static int serial_pxa_remove(struct platform_device *pdev)
+{
+	struct pxa8250_data *data = platform_get_drvdata(pdev);
+
+	serial8250_unregister_port(data->line);
+
+	clk_unprepare(data->clk);
+
+	return 0;
+}
+
+static struct platform_driver serial_pxa_driver = {
+	.probe          = serial_pxa_probe,
+	.remove         = serial_pxa_remove,
+
+	.driver		= {
+		.name	= "pxa2xx-uart",
+		.pm	= &serial_pxa_pm_ops,
+		.of_match_table = serial_pxa_dt_ids,
+	},
+};
+
+module_platform_driver(serial_pxa_driver);
+
+MODULE_AUTHOR("Sergei Ianovich");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:pxa2xx-uart");
drivers/tty/serial/8250/Kconfig +10 -0
index c9ec839a5ddf..a294e858e16b 100644
@@ -426,6 +426,16 @@ config SERIAL_8250_MOXA
 	  This driver can also be built as a module. The module will be called
 	  8250_moxa. If you want to do that, say M here.
 
+config SERIAL_8250_PXA
+	tristate "PXA serial port support"
+	depends on SERIAL_8250
+	depends on ARCH_PXA || ARCH_MMP
+	help
+	  If you have a machine based on an Intel XScale PXA2xx CPU you can
+	  enable its onboard serial ports by enabling this option. The option is
+	  applicable to both devicetree and legacy boards, and early console is
+	  part of its support.
+
 config SERIAL_OF_PLATFORM
 	tristate "Devicetree based probing for 8250 ports"
 	depends on SERIAL_8250 && OF
drivers/tty/serial/8250/Makefile +1 -0
index 367d403d28d5..30745c94ae45 100644
@@ -30,6 +30,7 @@ obj-$(CONFIG_SERIAL_8250_UNIPHIER)	+= 8250_uniphier.o
 obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_MID)		+= 8250_mid.o
 obj-$(CONFIG_SERIAL_8250_MOXA)		+= 8250_moxa.o
+obj-$(CONFIG_SERIAL_8250_PXA)		+= 8250_pxa.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM)	+= 8250_of.o
 
 CFLAGS_8250_ingenic.o += -I$(srctree)/scripts/dtc/libfdt
drivers/tty/serial/Kconfig +15 -2
index 518db24a5b36..543cdd58232d 100644
@@ -438,17 +438,27 @@ config SERIAL_MPSC_CONSOLE
 	  Say Y here if you want to support a serial console on a Marvell MPSC.
 
 config SERIAL_PXA
-	bool "PXA serial port support"
+	bool "PXA serial port support (DEPRECATED)"
 	depends on ARCH_PXA || ARCH_MMP
 	select SERIAL_CORE
+	select SERIAL_8250_PXA if SERIAL_8250=y
+	select SERIAL_PXA_NON8250 if !SERIAL_8250=y
 	help
 	  If you have a machine based on an Intel XScale PXA2xx CPU you
 	  can enable its onboard serial ports by enabling this option.
 
+	  Unless you have a specific need, you should use SERIAL_8250_PXA
+	  instead of this.
+
+config SERIAL_PXA_NON8250
+	bool
+	depends on !SERIAL_8250
+
 config SERIAL_PXA_CONSOLE
-	bool "Console on PXA serial port"
+	bool "Console on PXA serial port (DEPRECATED)"
 	depends on SERIAL_PXA
 	select SERIAL_CORE_CONSOLE
+	select SERIAL_8250_CONSOLE if SERIAL_8250=y
 	help
 	  If you have enabled the serial port on the Intel XScale PXA
 	  CPU you can make it the console by answering Y to this option.
@@ -460,6 +470,9 @@ config SERIAL_PXA_CONSOLE
 	  your boot loader (lilo or loadlin) about how to pass options to the
 	  kernel at boot time.)
 
+	  Unless you have a specific need, you should use SERIAL_8250_PXA
+	  and SERIAL_8250_CONSOLE instead of this.
+
 config SERIAL_SA1100
 	bool "SA1100 serial port support"
 	depends on ARCH_SA1100
drivers/tty/serial/Makefile +1 -1
index 1278d376da50..1fa21ec616bd 100644
@@ -23,7 +23,7 @@ obj-$(CONFIG_SERIAL_8250) += 8250/
 obj-$(CONFIG_SERIAL_AMBA_PL010) += amba-pl010.o
 obj-$(CONFIG_SERIAL_AMBA_PL011) += amba-pl011.o
 obj-$(CONFIG_SERIAL_CLPS711X) += clps711x.o
-obj-$(CONFIG_SERIAL_PXA) += pxa.o
+obj-$(CONFIG_SERIAL_PXA_NON8250) += pxa.o
 obj-$(CONFIG_SERIAL_PNX8XXX) += pnx8xxx_uart.o
 obj-$(CONFIG_SERIAL_SA1100) += sa1100.o
 obj-$(CONFIG_SERIAL_BCM63XX) += bcm63xx_uart.o
drivers/tty/serial/pxa.c +3 -1
index cd9d9e878475..b9dd787cb561 100644
@@ -925,7 +925,9 @@ static struct platform_driver serial_pxa_driver = {
 	},
 };
 
-static int __init serial_pxa_init(void)
+
+/* 8250 driver for PXA serial ports should be used */
+static int __deprecated __init serial_pxa_init(void)
 {
 	int ret;
 
Signature · 1 line
2.1.4
#267 lore raw

Re: [PATCH v6] serial: rewrite pxa2xx-uart to use 8250_core

Quoted 20 lines · Robert Jarzmik
Quoted 11 lines · Robert Jarzmik
Quoted 2 lines
Quoted 2 lines

If so, great, get the platform maintainer to sign off on this please and then resend it.

If you're talking about the PXA maintainer, then :

I'm happy with the patch, all pxa board maintainers have been warned, and there exists a fallback solution.

So let's go forward, and if people complain, let them complain and forward them to me.

Hi Greg,

I rebased and retested the patch (both devicetree and legacy boards, multiple pxa variants, early console and standard console), and it does work. The fallback on the old driver works as well.

Quoted 7 lines

I also signed it as the pxa maintainer, and I'm pushing it now, in [2].

If you want context, it's archived in [1].

If you're overburdened and feel there won't be a merge conflict in your serial tree, I can take it through pxa tree provided you ack it, or you can take it, just let me know.

I'll be glad to take it, can you send it in a proper format?

thanks,

greg k-h

maintainer
#268 lore raw

Re: [PATCH v6] serial: rewrite pxa2xx-uart to use 8250_core

Quoted 6 lines · Greg Kroah-Hartman
Quoted 3 lines · Robert Jarzmik

If you're overburdened and feel there won't be a merge conflict in your serial tree, I can take it through pxa tree provided you ack it, or you can take it, just let me know.

I'll be glad to take it, can you send it in a proper format?

Most certainly.

Done with the title "[PATCH v6 RESEND] serial: rewrite pxa2xx-uart to use 8250_core".

Thanks.

Signature · 1 line
Robert