changeset 3915:6f2b6b4e8cd9

libdevice/uart: Move UART configuration class to valio Drop DRIVER_UART class. It is only a setter and has no real added value. Split out uart configuration structure and resource declaration to device/resource/uart.h. It is generic and available even if there is not runtime configuration of UARTs possible (device tree may still contain init resources). Add a uart_config valio subclass that can read/write/wait for UART configuration of a device. Move all implementations to this API.
author Nicolas Pouillon <nipo@ssji.net>
date Thu, 19 Apr 2018 08:57:48 +0200
parents 25c630216268
children feb8372ead09
files arch/efm32/boards/g8xxstk.c arch/efm32/boards/stk3200.c arch/efm32/boards/stk3x00_678.c arch/efm32/boards/stk6066a.c arch/efm32/boards/stk620xa.c arch/efm32/drivers/leuart/leuart_char.c arch/efm32/drivers/usart/usart_char.c arch/nrf5x/board/arduino.c arch/nrf5x/board/clock.c arch/nrf5x/board/pca10000.c arch/nrf5x/board/pca10005.c arch/nrf5x/board/pca10024.c arch/nrf5x/board/pca10028.c arch/nrf5x/board/pca10031.c arch/nrf5x/board/pca10040.c arch/nrf5x/board/pca10040_sr3.c arch/nrf5x/board/pca10056.c arch/nrf5x/board/pca20002.c arch/nrf5x/board/pca20006.c arch/nrf5x/board/smartremote3.c arch/nrf5x/board/tiny_ble.c arch/nrf5x/drivers/uart.c arch/nrf5x/drivers/uarte.c arch/psoc4/board/board.build arch/psoc4/board/procble_dev.c arch/psoc4/drivers/uart.c arch/stm32/boards/guidog.c arch/stm32/boards/nucleo_f103rb.c arch/stm32/boards/nucleo_f401re.c arch/stm32/boards/nucleo_f746g.c arch/stm32/boards/nucleo_l476rg.c arch/stm32/drivers/usart/usart.c arch/stm32/drivers/usart/usart.config examples/ble/midi/board.c libdevice/Makefile libdevice/device.config libdevice/device_uart.c libdevice/include/device/class/uart.h libdevice/include/device/driver.h libdevice/include/device/resource/uart.h libdevice/include/device/valio/uart_config.h libdevice/libdevice.mkdoc libdevice/shell.c libdevice/shell_uart.c libdevice/valio.config
diffstat 45 files changed, 363 insertions(+), 289 deletions(-) [+]
line wrap: on
line diff
--- a/arch/efm32/boards/g8xxstk.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/boards/g8xxstk.c	Thu Apr 19 08:57:48 2018 +0200
@@ -27,7 +27,7 @@
 # include <device/class/cmu.h>
 # include <device/class/dma.h>
 # include <device/class/i2c.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 #endif
 
 #include <hexo/iospace.h>
--- a/arch/efm32/boards/stk3200.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/boards/stk3200.c	Thu Apr 19 08:57:48 2018 +0200
@@ -26,7 +26,7 @@
 # include <device/class/iomux.h>
 # include <device/class/dma.h>
 # include <device/class/cmu.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 #endif
 
 #include <hexo/iospace.h>
--- a/arch/efm32/boards/stk3x00_678.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/boards/stk3x00_678.c	Thu Apr 19 08:57:48 2018 +0200
@@ -28,7 +28,7 @@
 # include <device/class/dma.h>
 # include <device/class/usbdev.h>
 # include <device/class/i2c.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 #endif
 
 #include <hexo/iospace.h>
--- a/arch/efm32/boards/stk6066a.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/boards/stk6066a.c	Thu Apr 19 08:57:48 2018 +0200
@@ -27,7 +27,7 @@
 # include <device/class/cmu.h>
 # include <device/class/timer.h>
 # include <device/class/dma.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 # include <device/class/i2c.h>
 #endif
 
--- a/arch/efm32/boards/stk620xa.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/boards/stk620xa.c	Thu Apr 19 08:57:48 2018 +0200
@@ -28,7 +28,7 @@
 # include <device/class/dma.h>
 # include <device/class/usbdev.h>
 # include <device/class/i2c.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 #endif
 
 #include <hexo/iospace.h>
--- a/arch/efm32/drivers/leuart/leuart_char.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/drivers/leuart/leuart_char.c	Thu Apr 19 08:57:48 2018 +0200
@@ -42,7 +42,7 @@
 #include <device/irq.h>
 #include <device/class/char.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/clock.h>
 
 #if CONFIG_DRIVER_EFM32_LEUART_SWFIFO > 0
--- a/arch/efm32/drivers/usart/usart_char.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/efm32/drivers/usart/usart_char.c	Thu Apr 19 08:57:48 2018 +0200
@@ -32,7 +32,7 @@
 #include <device/irq.h>
 #include <device/class/char.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/clock.h>
 
 #include <arch/efm32/usart.h>
--- a/arch/nrf5x/board/arduino.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/arduino.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/i2c.h>
--- a/arch/nrf5x/board/clock.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/clock.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #ifdef CONFIG_DEVICE
 # include <device/class/iomux.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 # include <device/class/gpio.h>
 # include <device/class/timer.h>
 # if defined(CONFIG_DRIVER_NRF5X_I2C)
--- a/arch/nrf5x/board/pca10000.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10000.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #ifdef CONFIG_DEVICE
 # include <device/class/iomux.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 # include <device/class/cmu.h>
 # include <device/resources.h>
 # include <device/irq.h>
--- a/arch/nrf5x/board/pca10005.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10005.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 #include <device/resources.h>
 #include <device/class/icu.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/cmu.h>
 #include <arch/nrf5x/ids.h>
 #endif
--- a/arch/nrf5x/board/pca10024.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10024.c	Thu Apr 19 08:57:48 2018 +0200
@@ -20,7 +20,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/cmu.h>
 #include <arch/nrf5x/ids.h>
 
--- a/arch/nrf5x/board/pca10028.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10028.c	Thu Apr 19 08:57:48 2018 +0200
@@ -20,7 +20,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/i2c.h>
--- a/arch/nrf5x/board/pca10031.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10031.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #ifdef CONFIG_DEVICE
 # include <device/class/iomux.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 # include <device/class/cmu.h>
 # include <device/class/icu.h>
 # include <device/resources.h>
--- a/arch/nrf5x/board/pca10040.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10040.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/i2c.h>
--- a/arch/nrf5x/board/pca10040_sr3.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10040_sr3.c	Thu Apr 19 08:57:48 2018 +0200
@@ -20,7 +20,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/i2c.h>
--- a/arch/nrf5x/board/pca10056.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca10056.c	Thu Apr 19 08:57:48 2018 +0200
@@ -20,7 +20,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <arch/nrf5x/ids.h>
--- a/arch/nrf5x/board/pca20002.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca20002.c	Thu Apr 19 08:57:48 2018 +0200
@@ -21,7 +21,7 @@
 #include <device/resources.h>
 #include <device/class/iomux.h>
 #include <device/class/i2c.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/icu.h>
--- a/arch/nrf5x/board/pca20006.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/pca20006.c	Thu Apr 19 08:57:48 2018 +0200
@@ -21,7 +21,7 @@
 #include <device/resources.h>
 #include <device/irq.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/cmu.h>
 #include <device/class/icu.h>
 #include <arch/nrf5x/ids.h>
--- a/arch/nrf5x/board/smartremote3.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/smartremote3.c	Thu Apr 19 08:57:48 2018 +0200
@@ -20,7 +20,7 @@
 
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <device/class/gpio.h>
 #include <device/class/cmu.h>
 #include <device/class/i2c.h>
--- a/arch/nrf5x/board/tiny_ble.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/board/tiny_ble.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 
 #ifdef CONFIG_DEVICE
 # include <device/class/iomux.h>
-# include <device/class/uart.h>
+# include <device/resource/uart.h>
 # include <device/class/gpio.h>
 # include <device/class/timer.h>
 # include <device/class/i2c.h>
--- a/arch/nrf5x/drivers/uart.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/drivers/uart.c	Thu Apr 19 08:57:48 2018 +0200
@@ -34,7 +34,11 @@
 #include <device/driver.h>
 #include <device/irq.h>
 #include <device/class/char.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+# include <device/class/valio.h>
+# include <device/valio/uart_config.h>
+#endif
 #include <device/class/iomux.h>
 #include <device/clock.h>
 
@@ -388,18 +392,26 @@
     return 0;
 }
 
-#if defined(CONFIG_DEVICE_UART)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
 
-static DEV_UART_CONFIG(nrf5x_uart_uart_config)
+static DEV_VALIO_REQUEST(nrf5x_uart_valio_request)
 {
-    struct device_s *dev = accessor->dev;
-    struct nrf5x_uart_priv *pv = dev->drv_pv;
+  struct device_s *dev = accessor->dev;
+  struct nrf5x_uart_priv *pv = dev->drv_pv;
 
-    error_t err = nrf5x_uart_config(pv, cfg);
+  if (req->type != DEVICE_VALIO_WRITE
+      || req->attribute != VALIO_UART_CONFIG) {
+    req->error = -ENOTSUP;
+  } else {
+    LOCK_SPIN_IRQ_SCOPED(&dev->lock);
 
-    return err;
+    req->error = nrf5x_uart_config(pv, req->data);
+  }
+
+  kroutine_exec(&req->base.kr);
 }
 
+#define nrf5x_uart_valio_cancel (dev_valio_cancel_t*)dev_driver_notsup_fcn
 #endif
 
 
@@ -475,9 +487,8 @@
 
     uintptr_t addr;
     if (device_res_get_uint(dev, DEV_RES_MEM, 0, &addr, NULL))
-        goto free_pv;
+        return -ENOENT;
 
-#if defined(CONFIG_DEVICE_UART)
     /* If there is a config resource, apply it. */
     struct dev_resource_s *r = device_res_get(dev, DEV_RES_UART, 0);
 
@@ -494,7 +505,6 @@
           logk_warning("uart config overrides printk baudrate");
 # endif
     }
-#endif
 
     pv = mem_alloc(sizeof(*pv), mem_scope_sys);
     if (!pv)
@@ -633,12 +643,12 @@
 }
 
 DRIVER_DECLARE(nrf5x_uart_drv, 0, "nRF5x Serial"
-#if defined(CONFIG_DEVICE_UART)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
                ",UART"
 #endif
                , nrf5x_uart_char,
-#if defined(CONFIG_DEVICE_UART)
-               DRIVER_UART_METHODS(nrf5x_uart_uart),
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+               DRIVER_VALIO_METHODS(nrf5x_uart_valio),
 #endif
                DRIVER_CHAR_METHODS(nrf5x_uart));
 
--- a/arch/nrf5x/drivers/uarte.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/nrf5x/drivers/uarte.c	Thu Apr 19 08:57:48 2018 +0200
@@ -33,7 +33,11 @@
 #include <device/driver.h>
 #include <device/irq.h>
 #include <device/class/char.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
+#ifdef CONFIG_DEVICE_VALIO_UART_CONFIG
+# include <device/class/valio.h>
+# include <device/valio/uart_config.h>
+#endif
 #include <device/class/iomux.h>
 
 #include <arch/nrf5x/uarte.h>
@@ -67,7 +71,7 @@
                                        struct dev_char_rq_s *rq,
                                        size_t count)
 {
-  struct nrf5x_uarte_priv *pv = dev->drv_pv;
+  __unused__ struct nrf5x_uarte_priv *pv = dev->drv_pv;
 
   rq->size -= count;
   rq->data += count;
@@ -404,18 +408,26 @@
   return 0;
 }
 
-#if defined(CONFIG_DEVICE_UART)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
 
-static DEV_UART_CONFIG(nrf5x_uarte_uart_config)
+static DEV_VALIO_REQUEST(nrf5x_uarte_valio_request)
 {
   struct device_s *dev = accessor->dev;
   struct nrf5x_uarte_priv *pv = dev->drv_pv;
 
-  LOCK_SPIN_IRQ_SCOPED(&dev->lock);
+  if (req->type != DEVICE_VALIO_WRITE
+      || req->attribute != VALIO_UART_CONFIG) {
+    req->error = -ENOTSUP;
+  } else {
+    LOCK_SPIN_IRQ_SCOPED(&dev->lock);
 
-  return nrf5x_uarte_config(pv, cfg);
+    req->error = nrf5x_uarte_config(pv, req->data);
+  }
+
+  kroutine_exec(&req->base.kr);
 }
 
+#define nrf5x_uarte_valio_cancel (dev_valio_cancel_t*)dev_driver_notsup_fcn
 #endif
 
 #define nrf5x_uarte_char_use dev_use_generic
@@ -493,7 +505,6 @@
   if (device_irq_source_link(dev, &pv->irq_ep, 1, -1))
     goto free_queue;
 
-#if defined(CONFIG_DEVICE_UART)
   struct dev_resource_s *r = device_res_get(dev, DEV_RES_UART, 0);
 
   if (r) {
@@ -503,7 +514,6 @@
     config.parity      = r->u.uart.parity;
     config.flow_ctrl   = r->u.uart.flow_ctrl;
   }
-#endif
 
   nrf5x_uarte_config(pv, &config);
 
@@ -551,12 +561,12 @@
 }
 
 DRIVER_DECLARE(nrf5x_uarte_drv, 0, "nRF52 Serial dma"
-#if defined(CONFIG_DEVICE_UART)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
                ",UART"
 #endif
                , nrf5x_uarte_char,
-#if defined(CONFIG_DEVICE_UART)
-               DRIVER_UART_METHODS(nrf5x_uarte_uart),
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+               DRIVER_VALIO_METHODS(nrf5x_uarte_valio),
 #endif
                DRIVER_CHAR_METHODS(nrf5x_uarte));
 
--- a/arch/psoc4/board/board.build	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/psoc4/board/board.build	Thu Apr 19 08:57:48 2018 +0200
@@ -36,5 +36,6 @@
 #  CONFIG_DRIVER_PSOC4_UART
 #  CONFIG_DRIVER_PSOC4_CLOCK
   CONFIG_DRIVER_PSOC4_GPIO
-#  CONFIG_DEVICE_UART
+#  CONFIG_DEVICE_VALIO
+#  CONFIG_DEVICE_VALIO_UART_CONFIG
 #  CONFIG_DRIVER_PSOC4_RTC
--- a/arch/psoc4/board/procble_dev.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/psoc4/board/procble_dev.c	Thu Apr 19 08:57:48 2018 +0200
@@ -22,7 +22,7 @@
 #include <device/irq.h>
 #include <device/class/iomux.h>
 #include <device/clock.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <arch/psoc4/variant.h>
 
 #ifdef CONFIG_DRIVER_PSOC4_UART
--- a/arch/psoc4/drivers/uart.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/psoc4/drivers/uart.c	Thu Apr 19 08:57:48 2018 +0200
@@ -31,7 +31,11 @@
 #include <device/driver.h>
 #include <device/irq.h>
 #include <device/class/char.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
+#ifdef CONFIG_DEVICE_VALIO_UART_CONFIG
+# include <device/class/valio.h>
+# include <device/valio/uart_config.h>
+#endif
 #include <device/class/iomux.h>
 #include <device/clock.h>
 
@@ -574,18 +578,24 @@
   return 0;
 }
 
-#if defined(CONFIG_DEVICE_UART)
-static DEV_UART_CONFIG(psoc4_uart_uart_config)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+static DEV_VALIO_REQUEST(psoc4_uart_valio_request)
 {
   struct device_s *dev = accessor->dev;
-  error_t err;
 
-  LOCK_SPIN_IRQ(&dev->lock);
-  err = psoc4_uart_config(dev, cfg);
-  LOCK_RELEASE_IRQ(&dev->lock);
+  if (req->type != DEVICE_VALIO_WRITE
+      || req->attribute != VALIO_UART_CONFIG) {
+    req->error = -ENOTSUP;
+  } else {
+    LOCK_SPIN_IRQ_SCOPED(&dev->lock);
 
-  return err;
+    req->error = psoc4_uart_config(dev, req->data);
+  }
+
+  kroutine_exec(&req->base.kr);
 }
+
+#define psoc4_uart_valio_cancel (dev_valio_cancel_t*)dev_driver_notsup_fcn
 #endif
 
 static DEV_USE(psoc4_uart_char_use)
@@ -725,7 +735,6 @@
   uart_fifo_init(&pv->rx_fifo);
   uart_fifo_init(&pv->tx_fifo);
 
-#if defined(CONFIG_DEVICE_UART)
   /* If there is a config resource, apply it. */
   struct dev_resource_s *r = device_res_get(dev, DEV_RES_UART, 0);
 
@@ -735,9 +744,7 @@
     config.stop_bits   = r->u.uart.stop_bits;
     config.parity      = r->u.uart.parity;
     config.flow_ctrl   = r->u.uart.flow_ctrl && pv->has_ctsrts;
-    config.half_duplex = r->u.uart.half_duplex;
   }
-#endif
 
   psoc4_uart_scb_init(dev);
 
@@ -792,12 +799,12 @@
 }
 
 DRIVER_DECLARE(psoc4_uart_drv, 0, "SCB Serial"
-#if defined(CONFIG_DEVICE_UART)
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
                "+UART"
 #endif
                , psoc4_uart_char,
-#if defined(CONFIG_DEVICE_UART)
-               DRIVER_UART_METHODS(psoc4_uart_uart),
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
+               DRIVER_VALIO_METHODS(psoc4_uart_valio),
 #endif
                DRIVER_CHAR_METHODS(psoc4_uart));
 
--- a/arch/stm32/boards/guidog.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/boards/guidog.c	Thu Apr 19 08:57:48 2018 +0200
@@ -46,7 +46,7 @@
 
 #if defined(CONFIG_DRIVER_STM32_USART)
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 
 DEV_DECLARE_STATIC(usart1_dev, "uart1", 0, stm32_usart_drv,
                    DEV_STATIC_RES_MEM(STM32_USART1_ADDR, STM32_USART1_ADDR + STM32_USART1_SIZE),
--- a/arch/stm32/boards/nucleo_f103rb.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/boards/nucleo_f103rb.c	Thu Apr 19 08:57:48 2018 +0200
@@ -47,7 +47,7 @@
 
 #if defined(CONFIG_DRIVER_STM32_USART)
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 
 /* USART1. */
 DEV_DECLARE_STATIC(usart1_dev, "uart1", 0, stm32_usart_drv,
--- a/arch/stm32/boards/nucleo_f401re.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/boards/nucleo_f401re.c	Thu Apr 19 08:57:48 2018 +0200
@@ -47,7 +47,7 @@
 
 #if defined(CONFIG_DRIVER_STM32_USART)
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 
 /* USART1. */
 DEV_DECLARE_STATIC(usart1_dev, "uart1", 0, stm32_usart_drv,
--- a/arch/stm32/boards/nucleo_f746g.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/boards/nucleo_f746g.c	Thu Apr 19 08:57:48 2018 +0200
@@ -43,7 +43,7 @@
 
 #if defined(CONFIG_DRIVER_STM32_USART)
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 
 /* USART1. */
 DEV_DECLARE_STATIC(usart1_dev, "uart1", 0, stm32_usart_drv,
--- a/arch/stm32/boards/nucleo_l476rg.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/boards/nucleo_l476rg.c	Thu Apr 19 08:57:48 2018 +0200
@@ -43,7 +43,7 @@
 
 #if defined(CONFIG_DRIVER_STM32_USART)
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 
 /* USART1. */
 DEV_DECLARE_STATIC(usart2_dev, "uart1", 0, stm32_usart_drv,
--- a/arch/stm32/drivers/usart/usart.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/drivers/usart/usart.c	Thu Apr 19 08:57:48 2018 +0200
@@ -35,7 +35,9 @@
 #include <device/irq.h>
 #include <device/class/char.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
+#include <device/class/valio.h>
+#include <device/resource/uart.h>
 
 #include <arch/stm32/usart.h>
 
@@ -486,10 +488,18 @@
 }
 
 static
-DEV_UART_CONFIG(stm32_usart_config)
+DEV_VALIO_REQUEST(stm32_usart_valio_request)
 {
-  struct device_s              *dev = accessor->dev;
-  struct stm32_usart_context_s *pv  = dev->drv_pv;
+  struct device_s *dev = accessor->dev;
+  struct stm32_usart_context_s *pv = dev->drv_pv;
+
+  if (req->type != DEVICE_VALIO_WRITE
+      || req->attribute != VALIO_UART_CONFIG) {
+    req->error = -ENOTSUP;
+    kroutine_exec(&req->base.kr);
+  }
+
+  struct dev_uart_config_s *cfg = req->data;
 
   /* disable the usart. */
   uint32_t a = pv->addr + STM32_USART_CR1_ADDR;
@@ -499,10 +509,10 @@
   STM32_USART_CR1_UE_SET(x, 0);
   cpu_mem_write_32(a, endian_le32(x));
 
-  error_t err = stm32_usart_config_simple(pv, cfg);
+  req->error = stm32_usart_config_simple(pv, cfg);
 
   /* (re-)enable the usart. */
-  if (!err && enabled)
+  if (!req->error && enabled)
     {
       x = endian_le32(cpu_mem_read_32(a));
       STM32_USART_CR1_UE_SET(x, 1);
@@ -510,13 +520,15 @@
     }
 
 #if defined(CONFIG_DEBUG)
-  if (err && enabled)
+  if (req->error && enabled)
     printk("uart: configuration left unchanged.\n");
 #endif
 
-  return err;
+  kroutine_exec(&req->base.kr);
 }
 
+#define stm32_usart_valio_cancel (dev_valio_cancel_t*)dev_driver_notsup_fcn
+
 
 #define stm32_usart_use dev_use_generic
 
@@ -659,7 +671,7 @@
 
 DRIVER_DECLARE(stm32_usart_drv, 0, "STM32 USART", stm32_usart,
                DRIVER_CHAR_METHODS(stm32_usart),
-               DRIVER_UART_METHODS(stm32_usart));
+               DRIVER_VALIO_METHODS(stm32_usart_valio));
 
 DRIVER_REGISTER(stm32_usart_drv);
 
--- a/arch/stm32/drivers/usart/usart.config	Thu Apr 19 07:39:38 2018 +0200
+++ b/arch/stm32/drivers/usart/usart.config	Thu Apr 19 08:57:48 2018 +0200
@@ -4,7 +4,7 @@
   parent CONFIG_ARCH_STM32
   depend CONFIG_DEVICE_CHAR
   depend CONFIG_DEVICE_IOMUX
-  depend CONFIG_DEVICE_UART
+  depend CONFIG_DEVICE_VALIO_UART_CONFIG
   suggest CONFIG_DEVICE_IRQ
   provide CONFIG_DEVICE_START_LOG2INC=2
 %config end
--- a/examples/ble/midi/board.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/examples/ble/midi/board.c	Thu Apr 19 08:57:48 2018 +0200
@@ -1,6 +1,5 @@
 #include <device/resources.h>
 #include <device/class/iomux.h>
-#include <device/class/uart.h>
 #include <device/class/i2c.h>
 #include <device/class/gpio.h>
 #include <arch/nrf5x/ids.h>
--- a/libdevice/Makefile	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/Makefile	Thu Apr 19 08:57:48 2018 +0200
@@ -9,8 +9,8 @@
                include/device/class/crypto.h \
                include/device/class/timer.h \
                include/device/class/rfpacket.h \
-               include/device/class/uart.h \
                include/device/class/spi.h \
+               include/device/resource/uart.h \
                include/device/valio/hwclock.h
 
 objs = driver.o device.o resources.o init.o request.o
@@ -82,17 +82,18 @@
 objs-$(CONFIG_DEVICE_SHELL_CRYPTO) += shell_crypto.o
 endif
 
-ifeq ($(CONFIG_DEVICE_UART), defined)
-objs += device_uart.o
-objs-$(CONFIG_DEVICE_SHELL_UART) += shell_uart.o
-endif
-
 objs-$(CONFIG_DEVICE_USBDEV) += device_usbdev.o device_usbdev_helpers.o
 
 ifeq ($(CONFIG_DEVICE_VALIO), defined)
 objs += device_valio.o
 endif
 
+objs += device_uart.o
+
+ifeq ($(CONFIG_DEVICE_VALIO_UART_CONFIG), defined)
+objs-$(CONFIG_DEVICE_SHELL) += shell_uart.o
+endif
+
 ifeq ($(CONFIG_DEVICE_VALIO_HWCLOCK), defined)
 objs += device_hwclock.o
 objs-$(CONFIG_DEVICE_SHELL) += shell_hwclock.o
--- a/libdevice/device.config	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/device.config	Thu Apr 19 08:57:48 2018 +0200
@@ -462,12 +462,6 @@
   default 12
 %config end
 
-%config CONFIG_DEVICE_UART
-  parent CONFIG_DEVICE
-  flags auto
-  desc Enable UART device support
-%config end
-
 %config CONFIG_DEVICE_I2C
   parent CONFIG_DEVICE
   flags auto
@@ -675,10 +669,3 @@
   default defined
   desc Enable cryto commands in shell
 %config end
-
-%config CONFIG_DEVICE_SHELL_UART
-  parent CONFIG_DEVICE_SHELL
-  depend CONFIG_DEVICE_UART
-  default defined
-  desc Enable usart commands in shell
-%config end
--- a/libdevice/device_uart.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/device_uart.c	Thu Apr 19 08:57:48 2018 +0200
@@ -18,7 +18,7 @@
   Copyright (c) Nicolas Pouillon <nipo@ssji.net>, 2016
 */
 
-#include <device/class/uart.h>
+#include <device/resource/uart.h>
 #include <hexo/enum.h>
 
 const char dev_uart_parity_e[] = ENUM_DESC_DEV_UART_PARITY_E;
--- a/libdevice/include/device/class/uart.h	Thu Apr 19 07:39:38 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-/*
-    This file is part of MutekH.
-
-    MutekH is free software; you can redistribute it and/or modify it
-    under the terms of the GNU Lesser General Public License as
-    published by the Free Software Foundation; version 2.1 of the
-    License.
-
-    MutekH is distributed in the hope that it will be useful, but
-    WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-    Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with MutekH; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301 USA.
-
-    Copyright Julien Peeters <contact@julienpeeters.net> (c) 2014
-
-*/
-
-/**
-   @file
-   @module {Core::Devices support library}
-   @short UART configuration driver API
-   @index {UART configuration} {Device classes}
-   @csee DRIVER_CLASS_UART
-
-   UART class only defines configuration parameters for UART devices.
-   Data path of UART devices goes through the Character device class.
-
-   Parameters addresed by this class are:
-   @list
-   @item Baud rate,
-   @item Character bit size,
-   @item Character framing (Start, stop bits, parity),
-   @item Line control (flow control)
-   @end list
- */
-
-#ifndef __DEVICE_UART_H__
-#define __DEVICE_UART_H__
-
-#include <hexo/types.h>
-#include <hexo/error.h>
-
-#include <device/device.h>
-#include <device/driver.h>
-#include <device/resources.h>
-
-ENUM_DESCRIPTOR(dev_uart_parity_e, strip:DEV_UART_PARITY_, upper);
-
-/** UART parity. */
-enum dev_uart_parity_e
-{
-  DEV_UART_PARITY_NONE,
-  DEV_UART_PARITY_ODD,
-  DEV_UART_PARITY_EVEN,
-};
-
-/** @This structure describes the configuration of a UART device. */
-struct dev_uart_config_s
-{
-  /** baud rate in bps. */
-  uint32_t BITFIELD(baudrate,22);
-
-  /** data bits. */
-  uint32_t BITFIELD(data_bits,5);
-
-  /** stop bits. */
-  uint32_t BITFIELD(stop_bits,2);
-
-  /** flow control. */
-  uint32_t BITFIELD(flow_ctrl,1);
-
-  /** parity. */
-  enum dev_uart_parity_e BITFIELD(parity,2);
-};
-
-
-/* forward declarations. */
-struct device_uart_s;
-
-/** @see dev_uart_config_t */
-#define DEV_UART_CONFIG(n) error_t (n)(struct device_uart_s     *accessor, \
-                                      struct dev_uart_config_s *cfg)
-
-/** @This configures the uart device with the given configuration. */
-typedef DEV_UART_CONFIG(dev_uart_config_t);
-
-DRIVER_CLASS_TYPES(DRIVER_CLASS_UART, uart,
-                   dev_uart_config_t *f_config;
-                  );
-
-/** @see driver_uart_s */
-#define DRIVER_UART_METHODS(prefix)                            \
-  ((const struct driver_class_s*)&(const struct driver_uart_s){ \
-    .class_ = DRIVER_CLASS_UART,                               \
-    .f_config = prefix ## _config,                             \
-  })
-
-
-/** @This is a wrapper for the @ref dev_uart_config_t function */
-ALWAYS_INLINE
-error_t dev_uart_config(struct device_uart_s     *accessor,
-                        struct dev_uart_config_s *cfg)
-{
-  return DEVICE_OP(accessor, config, cfg);
-}
-
-
-/** @This appends a UART resource entry to the device tree.
-    @csee DEV_RES_UART */
-config_depend_and2_alwaysinline(CONFIG_DEVICE_UART, CONFIG_DEVICE_RESOURCE_ALLOC,
-error_t device_res_add_uart(struct device_s           *dev,
-                            const struct dev_uart_config_s *cfg),
-{
-  struct dev_resource_s *r;
-
-  error_t err = device_res_alloc(dev, &r, DEV_RES_UART);
-  if (err)
-    return err;
-
-  r->u.uart.baudrate    = cfg->baudrate;
-  r->u.uart.data_bits   = cfg->data_bits;
-  r->u.uart.stop_bits   = cfg->stop_bits;
-  r->u.uart.parity      = cfg->parity;
-  r->u.uart.flow_ctrl   = cfg->flow_ctrl;
-
-  return 0;
-})
-
-ALWAYS_INLINE error_t device_get_res_uart(const struct device_s *dev,
-                                          struct dev_uart_config_s *cfg)
-{
-  struct dev_resource_s *r;
-
-  r = device_res_get(dev, DEV_RES_UART, 0);
-  if (r == NULL)
-    return -ENOENT;
-
-  cfg->baudrate  = r->u.uart.baudrate;
-  cfg->data_bits = r->u.uart.data_bits;
-  cfg->stop_bits = r->u.uart.stop_bits;
-  cfg->parity    = r->u.uart.parity;
-  cfg->flow_ctrl = r->u.uart.flow_ctrl;
-
-  return 0;
-}
-
-/** @This specifies an UART configuration resource entry in a static
-    device resources table declaration. @csee DEV_RES_UART
-    @see #DEV_DECLARE_STATIC */
-# define DEV_STATIC_RES_UART(                               \
-    __baudrate, __data, __parity, __stop, __flow)           \
-  {                                                         \
-    .type = DEV_RES_UART,                                   \
-    .u    = { .uart = {                                     \
-      .baudrate  = (__baudrate),                            \
-      .data_bits = (__data),                                \
-      .stop_bits = (__stop),                                \
-      .parity    = (__parity),                              \
-      .flow_ctrl = (__flow)                                 \
-    } }                                                     \
-  }
-
-#endif
-
--- a/libdevice/include/device/driver.h	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/include/device/driver.h	Thu Apr 19 08:57:48 2018 +0200
@@ -59,7 +59,6 @@
   DRIVER_CLASS_CMU,
   DRIVER_CLASS_GPIO,
   DRIVER_CLASS_IOMUX,
-  DRIVER_CLASS_UART,
   DRIVER_CLASS_I2C_CTRL,
   DRIVER_CLASS_I2C_SLAVE,
   DRIVER_CLASS_MEM,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libdevice/include/device/resource/uart.h	Thu Apr 19 08:57:48 2018 +0200
@@ -0,0 +1,113 @@
+/*
+    This file is part of MutekH.
+
+    MutekH is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as
+    published by the Free Software Foundation; version 2.1 of the
+    License.
+
+    MutekH is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this program.  If not, see
+    <http://www.gnu.org/licenses/>.
+
+    Copyright Nicolas Pouillon <nipo@ssji.net> (c) 2018
+    Copyright Julien Peeters <contact@julienpeeters.net> (c) 2014
+*/
+
+#ifndef __DEVICE_RESOURCE_UART_H__
+#define __DEVICE_RESOURCE_UART_H__
+
+#include <hexo/types.h>
+#include <device/device.h>
+#include <device/resources.h>
+
+ENUM_DESCRIPTOR(dev_uart_parity_e, strip:DEV_UART_PARITY_, upper);
+
+/** UART parity. */
+enum dev_uart_parity_e
+{
+  DEV_UART_PARITY_NONE,
+  DEV_UART_PARITY_ODD,
+  DEV_UART_PARITY_EVEN,
+};
+
+/** @This structure describes the configuration of a UART device. */
+struct dev_uart_config_s
+{
+  /** baud rate in bps. */
+  uint32_t BITFIELD(baudrate,22);
+
+  /** data bits. */
+  uint32_t BITFIELD(data_bits,5);
+
+  /** stop bits. */
+  uint32_t BITFIELD(stop_bits,2);
+
+  /** flow control. */
+  uint32_t BITFIELD(flow_ctrl,1);
+
+  /** parity. */
+  enum dev_uart_parity_e BITFIELD(parity,2);
+};
+
+/** @This appends a UART resource entry to the device tree.
+    @csee DEV_RES_UART */
+config_depend_alwaysinline(CONFIG_DEVICE_RESOURCE_ALLOC,
+error_t device_res_add_uart(struct device_s           *dev,
+                            const struct dev_uart_config_s *cfg),
+{
+  struct dev_resource_s *r;
+
+  error_t err = device_res_alloc(dev, &r, DEV_RES_UART);
+  if (err)
+    return err;
+
+  r->u.uart.baudrate    = cfg->baudrate;
+  r->u.uart.data_bits   = cfg->data_bits;
+  r->u.uart.stop_bits   = cfg->stop_bits;
+  r->u.uart.parity      = cfg->parity;
+  r->u.uart.flow_ctrl   = cfg->flow_ctrl;
+
+  return 0;
+})
+
+ALWAYS_INLINE error_t device_get_res_uart(const struct device_s *dev,
+                                          struct dev_uart_config_s *cfg)
+{
+  struct dev_resource_s *r;
+
+  r = device_res_get(dev, DEV_RES_UART, 0);
+  if (r == NULL)
+    return -ENOENT;
+
+  cfg->baudrate  = r->u.uart.baudrate;
+  cfg->data_bits = r->u.uart.data_bits;
+  cfg->stop_bits = r->u.uart.stop_bits;
+  cfg->parity    = r->u.uart.parity;
+  cfg->flow_ctrl = r->u.uart.flow_ctrl;
+
+  return 0;
+}
+
+/** @This specifies an UART configuration resource entry in a static
+    device resources table declaration. @csee DEV_RES_UART
+    @see #DEV_DECLARE_STATIC */
+# define DEV_STATIC_RES_UART(                               \
+    __baudrate, __data, __parity, __stop, __flow)           \
+  {                                                         \
+    .type = DEV_RES_UART,                                   \
+    .u    = { .uart = {                                     \
+      .baudrate  = (__baudrate),                            \
+      .data_bits = (__data),                                \
+      .stop_bits = (__stop),                                \
+      .parity    = (__parity),                              \
+      .flow_ctrl = (__flow)                                 \
+    } }                                                     \
+  }
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libdevice/include/device/valio/uart_config.h	Thu Apr 19 08:57:48 2018 +0200
@@ -0,0 +1,65 @@
+/*
+    This file is part of MutekH.
+
+    MutekH is free software; you can redistribute it and/or modify it
+    under the terms of the GNU Lesser General Public License as
+    published by the Free Software Foundation; version 2.1 of the
+    License.
+
+    MutekH is distributed in the hope that it will be useful, but
+    WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this program.  If not, see
+    <http://www.gnu.org/licenses/>.
+
+    Copyright Nicolas Pouillon <nipo@ssji.net> (c) 2018
+    Copyright Julien Peeters <contact@julienpeeters.net> (c) 2014
+*/
+
+/**
+   @file
+   @module {Core::Devices support library::Valio device attributes}
+   @short UART configuration driver API
+   @index {UART configuration} {Device classes}
+   @csee DRIVER_CLASS_CHAR
+
+   UART valio subclass only defines configuration parameters for UART
+   devices.  Data path of UART devices goes through the Character
+   device class.
+
+   Parameters addresed by this class are:
+   @list
+   @item Baud rate,
+   @item Character bit size,
+   @item Character framing (Start, stop bits, parity),
+   @item Line control (flow control)
+   @end list
+
+   Depending on character device, device may be configuring the
+   hardware (like for actual serial port), or receiving external
+   instructions (like for CDC-ACM devices).  Using valio allows the
+   application to wait for changes on parameters for the latter.
+ */
+
+#ifndef __DEVICE_VALIO_UART_H__
+#define __DEVICE_VALIO_UART_H__
+
+#include <hexo/types.h>
+#include <hexo/error.h>
+
+#include <device/device.h>
+#include <device/resources.h>
+
+#include <device/resource/uart.h>
+
+#include <device/class/valio.h>
+
+enum valio_uart_config_att {
+    /** A struct valio_uart_config_s */
+    VALIO_UART_CONFIG = CONFIG_DEVICE_VALIO_UART_CONFIG_ATTRIBUTE_FIRST,
+};
+
+#endif
--- a/libdevice/libdevice.mkdoc	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/libdevice.mkdoc	Thu Apr 19 08:57:48 2018 +0200
@@ -417,9 +417,9 @@
 device/class/smi.h
 device/class/pcm.h
 device/class/rfpacket.h
-device/class/uart.h
 device/class/valio.h
 device/class/usbdev.h
+device/resource/uart.h
 
 device/valio/adc.h
 device/valio/button.h
@@ -429,6 +429,7 @@
 device/valio/motion.h
 device/valio/motion_sensor.h
 device/valio/touchpad.h
+device/valio/uart_config.h
 
 device/usb/usb.h
 }
--- a/libdevice/shell.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/shell.c	Thu Apr 19 08:57:48 2018 +0200
@@ -492,7 +492,6 @@
           break;
         }
 #endif
-#ifdef CONFIG_DEVICE_UART
         case DEV_RES_UART: {
           static const char uart_parity[] = "NOE";
           termui_con_printf(con,
@@ -506,7 +505,6 @@
           );
           break;
         }
-#endif
         case DEV_RES_ID:
           termui_con_printf(con, "  Numerical identifier %x %x\n", r->u.id.major, r->u.id.minor);
           break;
@@ -879,7 +877,7 @@
 #ifdef CONFIG_DEVICE_ENUM
   TERMUI_CON_GROUP_ENTRY(dev_shell_enum_group, "enum")
 #endif
-#ifdef CONFIG_DEVICE_SHELL_UART
+#if defined(CONFIG_DEVICE_VALIO_UART_CONFIG)
   TERMUI_CON_GROUP_ENTRY(dev_shell_uart_group, "uart")
 #endif
 #if defined(CONFIG_DEVICE_VALIO_HWCLOCK)
--- a/libdevice/shell_uart.c	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/shell_uart.c	Thu Apr 19 08:57:48 2018 +0200
@@ -18,12 +18,18 @@
   Copyright (c) Nicolas Pouillon <nipo@ssji.net>, 2016
 */
 
+#include <device/class/char.h>
+#include <device/driver.h>
+#include <device/resources.h>
 #include <device/shell.h>
-#include <device/device.h>
-#include <device/driver.h>
-#include <inttypes.h>
 
-#include <device/class/uart.h>
+#include <mutek/console.h>
+#include <mutek/shell.h>
+#include <mutek/mem_alloc.h>
+#include <hexo/enum.h>
+
+#include <device/class/valio.h>
+#include <device/valio/uart_config.h>
 
 enum mem_opts_e
 {
@@ -37,7 +43,7 @@
 
 struct termui_optctx_dev_uart_opts
 {
-  struct device_uart_s uart;
+  struct device_valio_s device;
   uint32_t baudrate;
   uint32_t bits;
   enum dev_uart_parity_e parity;
@@ -48,28 +54,47 @@
 {
   struct termui_optctx_dev_uart_opts *c = ctx;
 
-  if (device_check_accessor(&c->uart.base))
-      device_put_accessor(&c->uart.base);
+  if (device_check_accessor(&c->device.base))
+      device_put_accessor(&c->device.base);
 }
 
 static TERMUI_CON_COMMAND_PROTOTYPE(dev_shell_uart_config)
 {
   struct termui_optctx_dev_uart_opts *c = ctx;
-  struct dev_uart_config_s config = {
-    .baudrate = c->baudrate,
-    .data_bits = used & UART_OPT_BITS ? c->bits : 8,
-    .stop_bits = used & UART_OPT_STOP ? c->stop : 1,
-    .flow_ctrl = !!(used & UART_OPT_FLOW),
-    .parity = used & UART_OPT_PARITY ? c->parity : DEV_UART_PARITY_NONE,
-  };
+  struct dev_uart_config_s config;
 
-  return dev_uart_config(&c->uart, &config);
+  if (used & (UART_OPT_BAUDRATE
+              | UART_OPT_FLOW | UART_OPT_BITS
+              | UART_OPT_STOP | UART_OPT_PARITY)) {
+    config.baudrate = c->baudrate;
+    config.data_bits = used & UART_OPT_BITS ? c->bits : 8;
+    config.stop_bits = used & UART_OPT_STOP ? c->stop : 1;
+    config.flow_ctrl = !!(used & UART_OPT_FLOW);
+    config.parity = used & UART_OPT_PARITY ? c->parity : DEV_UART_PARITY_NONE;
+
+    return dev_valio_wait_write(&c->device, VALIO_UART_CONFIG, &config);
+  } else {
+    error_t err = dev_valio_wait_read(&c->device, VALIO_UART_CONFIG, &config);
+
+    if (err) {
+      termui_con_printf(con, "Error %d\n", err);
+      return err;
+    }
+
+    termui_con_printf(con, "Baud rate: %d\n", config.baudrate);
+    termui_con_printf(con, "Data bits: %d\n", config.data_bits);
+    termui_con_printf(con, "Stop bits: %d\n", config.stop_bits);
+    termui_con_printf(con, "Flow ctrl: %s\n", config.flow_ctrl ? "on" : "off");
+    termui_con_printf(con, "Parity   : %c\n", "NOE"[config.parity]);
+  }
+
+  return 0;
 }
 
 static TERMUI_CON_OPT_DECL(dev_uart_opts) =
 {
   TERMUI_CON_OPT_DEV_ACCESSOR_ENTRY("-d", "--uart", UART_OPT_DEV,
-                                    struct termui_optctx_dev_uart_opts, uart, DRIVER_CLASS_UART,
+                                    struct termui_optctx_dev_uart_opts, device, DRIVER_CLASS_VALIO,
                                     TERMUI_CON_OPT_CONSTRAINTS(UART_OPT_DEV, 0)
                                     )
 
@@ -105,8 +130,9 @@
 {
   TERMUI_CON_ENTRY(dev_shell_uart_config, "config",
 		   TERMUI_CON_OPTS_CTX(dev_uart_opts,
-                                       UART_OPT_DEV | UART_OPT_BAUDRATE,
-                                       UART_OPT_FLOW | UART_OPT_BITS
+                                       UART_OPT_DEV,
+                                       UART_OPT_BAUDRATE
+                                       | UART_OPT_FLOW | UART_OPT_BITS
                                        | UART_OPT_STOP | UART_OPT_PARITY,
                                        uart_opts_cleanup)
                    )
--- a/libdevice/valio.config	Thu Apr 19 07:39:38 2018 +0200
+++ b/libdevice/valio.config	Thu Apr 19 08:57:48 2018 +0200
@@ -117,6 +117,20 @@
   default 2
 %config end
 
+%config CONFIG_DEVICE_VALIO_UART_CONFIG
+  desc Valio UART config class enable
+  parent CONFIG_DEVICE_VALIO
+  flags auto
+%config end
+
+%config CONFIG_DEVICE_VALIO_UART_CONFIG_ATTRIBUTE_COUNT
+  desc Valio UART config class attribute count
+  parent CONFIG_DEVICE_VALIO_UART_CONFIG
+  flags value
+  provide CONFIG_DEVICE_VALIO_ATTRIBUTE_ENUM
+  default 1
+%config end
+
 %config CONFIG_DEVICE_VALIO_HUMIDITY
   desc Valio Humidity Sensor class enable
   parent CONFIG_DEVICE_VALIO