mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] introduce basic rs485 support
@ 2013-09-19 13:19 Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
  2013-09-24  7:22 ` [PATCH 0/5] introduce basic rs485 support Sascha Hauer
  0 siblings, 2 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:19 UTC (permalink / raw)
  To: barebox

HI,

	this patch serie introduce the basic rs485 support

	This wil allow as example on Somfy Animeo-IP board to detect crossed
	rs485 cable that is used to start the board in special mode

The following changes since commit fe4117357f8f304a08b957eded8ede9db8dafdcf:

  Add missing dependency ENV_HANDLING for OF_BAREBOX_DRIVER option (2013-09-18 10:24:29 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/rs485

for you to fetch changes up to fdee185585717e2d2368252542083fd3516abc1a:

  Animeo IP: add rs485 crossing detection support (2013-09-19 21:15:50 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (5):
      shutdown: add board call back
      console: introduce console_get_by_dev
      console: introduce new callback set_mode
      atmel_serial: add rs485 support
      Animeo IP: add rs485 crossing detection support

 arch/arm/boards/animeo_ip/init.c     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 arch/arm/configs/animeo_ip_defconfig |  1 -
 common/console_common.c              | 13 +++++++++++++
 common/startup.c                     |  4 ++++
 drivers/serial/atmel.c               | 27 +++++++++++++++++++++++++++
 include/common.h                     |  1 +
 include/console.h                    |  8 ++++++++
 7 files changed, 136 insertions(+), 6 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] shutdown: add board call back
  2013-09-19 13:19 [PATCH 0/5] introduce basic rs485 support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-19 13:20 ` Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 2/5] console: introduce console_get_by_dev Jean-Christophe PLAGNIOL-VILLARD
                     ` (3 more replies)
  2013-09-24  7:22 ` [PATCH 0/5] introduce basic rs485 support Sascha Hauer
  1 sibling, 4 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:20 UTC (permalink / raw)
  To: barebox

so if we need to do something switch in the board we can fill this function
pointer (as example on Animeo IP shutdown some rs232 & rs485)

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/startup.c | 4 ++++
 include/common.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/common/startup.c b/common/startup.c
index 9b33a92..ece852c 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -159,6 +159,8 @@ void __noreturn hang (void)
 	for (;;);
 }
 
+void (*board_shutdown)(void);
+
 /* Everything needed to cleanly shutdown barebox.
  * Should be called before starting an OS to get
  * the devices into a clean state
@@ -169,4 +171,6 @@ void shutdown_barebox(void)
 #ifdef ARCH_SHUTDOWN
 	arch_shutdown();
 #endif
+	if (board_shutdown)
+		board_shutdown();
 }
diff --git a/include/common.h b/include/common.h
index 066827f..0f0ba08 100644
--- a/include/common.h
+++ b/include/common.h
@@ -152,6 +152,7 @@ extern int (*barebox_main)(void);
 
 void __noreturn start_barebox(void);
 void shutdown_barebox(void);
+extern void (*board_shutdown)(void);
 
 /*
  * architectures which have special calling conventions for
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] console: introduce console_get_by_dev
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-19 13:20   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 3/5] console: introduce new callback set_mode Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:20 UTC (permalink / raw)
  To: barebox

so we can get console by it's device

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/console_common.c | 13 +++++++++++++
 include/console.h       |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/common/console_common.c b/common/console_common.c
index d139d1a..24aa63e 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -108,3 +108,16 @@ int fputc(int fd, char c)
 	return 0;
 }
 EXPORT_SYMBOL(fputc);
+
+struct console_device *console_get_by_dev(struct device_d *dev)
+{
+	struct console_device *cdev;
+
+	for_each_console(cdev) {
+		if (cdev->dev == dev)
+			return cdev;
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(console_get_by_dev);
diff --git a/include/console.h b/include/console.h
index 72cf99f..355e259 100644
--- a/include/console.h
+++ b/include/console.h
@@ -49,6 +49,8 @@ struct console_device {
 int console_register(struct console_device *cdev);
 int console_unregister(struct console_device *cdev);
 
+struct console_device *console_get_by_dev(struct device_d *dev);
+
 extern struct list_head console_list;
 #define for_each_console(console) list_for_each_entry(console, &console_list, list)
 
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] console: introduce new callback set_mode
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 2/5] console: introduce console_get_by_dev Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-19 13:20   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 4/5] atmel_serial: add rs485 support Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 5/5] Animeo IP: add rs485 crossing detection support Jean-Christophe PLAGNIOL-VILLARD
  3 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:20 UTC (permalink / raw)
  To: barebox

so we can set the port in rs485 mode

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/console.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/console.h b/include/console.h
index 355e259..ef6e193 100644
--- a/include/console.h
+++ b/include/console.h
@@ -28,6 +28,11 @@
 #define CONSOLE_STDOUT          (1 << 1)
 #define CONSOLE_STDERR          (1 << 2)
 
+enum console_mode {
+	CONSOLE_MODE_NORMAL,
+	CONSOLE_MODE_RS485,
+};
+
 struct console_device {
 	struct device_d *dev;
 	struct device_d class_dev;
@@ -37,6 +42,7 @@ struct console_device {
 	int  (*getc)(struct console_device *cdev);
 	int (*setbrg)(struct console_device *cdev, int baudrate);
 	void (*flush)(struct console_device *cdev);
+	int (*set_mode)(struct console_device *cdev, enum console_mode mode);
 
 	struct list_head list;
 
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] atmel_serial: add rs485 support
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 2/5] console: introduce console_get_by_dev Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 3/5] console: introduce new callback set_mode Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-19 13:20   ` Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20   ` [PATCH 5/5] Animeo IP: add rs485 crossing detection support Jean-Christophe PLAGNIOL-VILLARD
  3 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:20 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/serial/atmel.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/serial/atmel.c b/drivers/serial/atmel.c
index 89c141e..40945c9 100644
--- a/drivers/serial/atmel.c
+++ b/drivers/serial/atmel.c
@@ -362,6 +362,32 @@ static int atmel_serial_setbaudrate(struct console_device *cdev, int baudrate)
 	return 0;
 }
 
+static int atmel_serial_set_mode(struct console_device *cdev, enum console_mode mode)
+{
+	struct atmel_uart_port *uart = to_atmel_uart_port(cdev);
+	u32 mr;
+	u8 m;
+
+	mr = readl(uart->base + USART3_MR);
+	mr &= ~0xf;
+
+	switch (mode) {
+	case CONSOLE_MODE_NORMAL:
+		m = USART3_USART_MODE_NORMAL;
+		break;
+	case CONSOLE_MODE_RS485:
+		m = USART3_USART_MODE_RS485;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	mr |= USART3_BF(USART_MODE, m);
+	writel(mr, uart->base + USART3_MR);
+
+	return 0;
+}
+
 /*
  * Initialise the serial port with the given baudrate. The settings
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
@@ -404,6 +430,7 @@ static int atmel_serial_probe(struct device_d *dev)
 	cdev->putc = atmel_serial_putc;
 	cdev->getc = atmel_serial_getc;
 	cdev->setbrg = atmel_serial_setbaudrate;
+	cdev->set_mode = atmel_serial_set_mode;
 
 	atmel_serial_init_port(cdev);
 
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] Animeo IP: add rs485 crossing detection support
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
                     ` (2 preceding siblings ...)
  2013-09-19 13:20   ` [PATCH 4/5] atmel_serial: add rs485 support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-19 13:20   ` Jean-Christophe PLAGNIOL-VILLARD
  3 siblings, 0 replies; 7+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-09-19 13:20 UTC (permalink / raw)
  To: barebox

this will be used to force the update or the start test mode

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/animeo_ip/init.c     | 88 ++++++++++++++++++++++++++++++++++--
 arch/arm/configs/animeo_ip_defconfig |  1 -
 2 files changed, 83 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/animeo_ip/init.c b/arch/arm/boards/animeo_ip/init.c
index 56b8df2..d46f645 100644
--- a/arch/arm/boards/animeo_ip/init.c
+++ b/arch/arm/boards/animeo_ip/init.c
@@ -239,20 +239,37 @@ static int animeo_ip_devices_init(void)
 
 device_initcall(animeo_ip_devices_init);
 
-static int animeo_ip_console_init(void)
+static struct device_d *usart0, *usart1;
+
+static void animeo_ip_shutdown_uart(void *base)
+{
+#define ATMEL_US_BRGR	0x0020
+	writel(0, base + ATMEL_US_BRGR);
+}
+
+static void animeo_ip_shutdown(void)
 {
 	/*
-	 * disable the dbgu enable by the bootstrap
+	 * disable the dbgu and others enable by the bootstrap
 	 * so linux can detect that we only enable the uart2
 	 * and use it for decompress
 	 */
-#define ATMEL_US_BRGR	0x0020
-	at91_sys_write(AT91_DBGU + ATMEL_US_BRGR, 0);
+	animeo_ip_shutdown_uart(IOMEM(AT91_DBGU + AT91_BASE_SYS));
+	animeo_ip_shutdown_uart(IOMEM(AT91SAM9260_BASE_US0));
+	animeo_ip_shutdown_uart(IOMEM(AT91SAM9260_BASE_US1));
+}
+
+static int animeo_ip_console_init(void)
+{
+	at91_register_uart(3, 0);
+
+	usart0 = at91_register_uart(1, ATMEL_UART_RTS);
+	usart1 = at91_register_uart(2, ATMEL_UART_RTS);
+	board_shutdown = animeo_ip_shutdown;
 
 	barebox_set_model("Somfy Animeo IP");
 	barebox_set_hostname("animeoip");
 
-	at91_register_uart(3, 0);
 	return 0;
 }
 console_initcall(animeo_ip_console_init);
@@ -263,3 +280,64 @@ static int animeo_ip_main_clock(void)
 	return 0;
 }
 pure_initcall(animeo_ip_main_clock);
+
+static unsigned int get_char_timeout(struct console_device *cs, int timeout)
+{
+	uint64_t start = get_time_ns();
+
+	do {
+		if (!cs->tstc(cs))
+			continue;
+		return cs->getc(cs);
+	} while (!is_timeout(start, timeout));
+
+	return -1;
+}
+
+static int animeo_ip_cross_detect_init(void)
+{
+	struct console_device *cs0, *cs1;
+	int i;
+	char *s = "loop";
+	int crossed = 0;
+
+	cs0 = console_get_by_dev(usart0);
+	if (!cs0)
+		return -EINVAL;
+	cs1 = console_get_by_dev(usart1);
+	if (!cs1)
+		return -EINVAL;
+
+	at91_set_gpio_input(AT91_PIN_PC16, 0);
+	cs0->set_mode(cs0, CONSOLE_MODE_RS485);
+	cs0->setbrg(cs0, 38400);
+	cs1->set_mode(cs1, CONSOLE_MODE_RS485);
+	cs1->setbrg(cs1, 38400);
+
+	/* empty the bus */
+	while (cs1->tstc(cs1))
+		cs1->getc(cs1);
+
+	for (i = 0; i < strlen(s); i++) {
+		unsigned int ch = s[i];
+		unsigned int c;
+
+resend:
+		cs0->putc(cs0, ch);
+		c = get_char_timeout(cs1, 10 * MSECOND);
+		if (c == 0)
+			goto resend;
+		else if (c != ch)
+			goto err;
+	}
+
+	crossed = 1;
+
+err:
+	export_env_ull("rs485_crossed", crossed);
+
+	pr_info("rs485 ports %scrossed\n", crossed ? "" : "not ");
+
+	return 0;
+}
+late_initcall(animeo_ip_cross_detect_init);
diff --git a/arch/arm/configs/animeo_ip_defconfig b/arch/arm/configs/animeo_ip_defconfig
index 23e7278..b2d7340 100644
--- a/arch/arm/configs/animeo_ip_defconfig
+++ b/arch/arm/configs/animeo_ip_defconfig
@@ -16,7 +16,6 @@ CONFIG_PROMPT_HUSH_PS2="y"
 CONFIG_HUSH_FANCY_PROMPT=y
 CONFIG_CMDLINE_EDITING=y
 CONFIG_AUTO_COMPLETE=y
-CONFIG_CONSOLE_ACTIVATE_ALL=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC=y
 CONFIG_DEFAULT_ENVIRONMENT_PATH="arch/arm/boards/animeo_ip/env"
 CONFIG_CMD_EDIT=y
-- 
1.8.4.rc1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] introduce basic rs485 support
  2013-09-19 13:19 [PATCH 0/5] introduce basic rs485 support Jean-Christophe PLAGNIOL-VILLARD
  2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
@ 2013-09-24  7:22 ` Sascha Hauer
  1 sibling, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-09-24  7:22 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Thu, Sep 19, 2013 at 03:19:29PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> HI,
> 
> 	this patch serie introduce the basic rs485 support
> 
> 	This wil allow as example on Somfy Animeo-IP board to detect crossed
> 	rs485 cable that is used to start the board in special mode
> 
> The following changes since commit fe4117357f8f304a08b957eded8ede9db8dafdcf:
> 
>   Add missing dependency ENV_HANDLING for OF_BAREBOX_DRIVER option (2013-09-18 10:24:29 +0200)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git delivery/rs485
> 
> for you to fetch changes up to fdee185585717e2d2368252542083fd3516abc1a:
> 
>   Animeo IP: add rs485 crossing detection support (2013-09-19 21:15:50 +0800)
>

Applied, thanks

Sascha
 
> ----------------------------------------------------------------
> Jean-Christophe PLAGNIOL-VILLARD (5):
>       shutdown: add board call back
>       console: introduce console_get_by_dev
>       console: introduce new callback set_mode
>       atmel_serial: add rs485 support
>       Animeo IP: add rs485 crossing detection support
> 
>  arch/arm/boards/animeo_ip/init.c     | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  arch/arm/configs/animeo_ip_defconfig |  1 -
>  common/console_common.c              | 13 +++++++++++++
>  common/startup.c                     |  4 ++++
>  drivers/serial/atmel.c               | 27 +++++++++++++++++++++++++++
>  include/common.h                     |  1 +
>  include/console.h                    |  8 ++++++++
>  7 files changed, 136 insertions(+), 6 deletions(-)
> 
> Best Regards,
> J.
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-24  7:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-19 13:19 [PATCH 0/5] introduce basic rs485 support Jean-Christophe PLAGNIOL-VILLARD
2013-09-19 13:20 ` [PATCH 1/5] shutdown: add board call back Jean-Christophe PLAGNIOL-VILLARD
2013-09-19 13:20   ` [PATCH 2/5] console: introduce console_get_by_dev Jean-Christophe PLAGNIOL-VILLARD
2013-09-19 13:20   ` [PATCH 3/5] console: introduce new callback set_mode Jean-Christophe PLAGNIOL-VILLARD
2013-09-19 13:20   ` [PATCH 4/5] atmel_serial: add rs485 support Jean-Christophe PLAGNIOL-VILLARD
2013-09-19 13:20   ` [PATCH 5/5] Animeo IP: add rs485 crossing detection support Jean-Christophe PLAGNIOL-VILLARD
2013-09-24  7:22 ` [PATCH 0/5] introduce basic rs485 support Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox