]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: serial: Replace setparity by setconfig
authorPatrice Chotard <patrice.chotard@st.com>
Fri, 3 Aug 2018 13:07:38 +0000 (15:07 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 11 Sep 2018 00:20:38 +0000 (20:20 -0400)
Replace setparity by more generic setconfig ops
to allow uart parity, bits word length and stop bits
number change.

Adds SERIAL_GET_PARITY/BITS/STOP macros.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/serial/serial-uclass.c
include/serial.h

index 4121a37aa80c661bbdcf46da8794e376206843f0..ffdcae0931869e8e7b8b488613aa79015c38229d 100644 (file)
@@ -290,6 +290,20 @@ void serial_setbrg(void)
                ops->setbrg(gd->cur_serial_dev, gd->baudrate);
 }
 
+int serial_setconfig(uint config)
+{
+       struct dm_serial_ops *ops;
+
+       if (!gd->cur_serial_dev)
+               return 0;
+
+       ops = serial_get_ops(gd->cur_serial_dev);
+       if (ops->setconfig)
+               return ops->setconfig(gd->cur_serial_dev, config);
+
+       return 0;
+}
+
 void serial_stdio_init(void)
 {
 }
@@ -401,6 +415,8 @@ static int serial_post_probe(struct udevice *dev)
                ops->pending += gd->reloc_off;
        if (ops->clear)
                ops->clear += gd->reloc_off;
+       if (ops->setconfig)
+               ops->setconfig += gd->reloc_off;
 #if CONFIG_POST & CONFIG_SYS_POST_UART
        if (ops->loop)
                ops->loop += gd->reloc_off
index 9cd6f107032c02f1c9421d090f1cbb823b02ed2d..8b00f38280ff98d8cdfe664c9028f238211f5876 100644 (file)
@@ -73,6 +73,39 @@ enum serial_par {
        SERIAL_PAR_EVEN
 };
 
+#define SERIAL_PAR_SHIFT       0
+#define SERIAL_PAR_MASK                (0x03 << SERIAL_PAR_SHIFT)
+#define SERIAL_GET_PARITY(config) \
+       ((config & SERIAL_PAR_MASK) >> SERIAL_PAR_SHIFT)
+
+enum serial_bits {
+       SERIAL_5_BITS,
+       SERIAL_6_BITS,
+       SERIAL_7_BITS,
+       SERIAL_8_BITS
+};
+
+#define SERIAL_BITS_SHIFT      2
+#define SERIAL_BITS_MASK       (0x3 << SERIAL_BITS_SHIFT)
+#define SERIAL_GET_BITS(config) \
+       ((config & SERIAL_BITS_MASK) >> SERIAL_BITS_SHIFT)
+
+enum serial_stop {
+       SERIAL_HALF_STOP,       /* 0.5 stop bit */
+       SERIAL_ONE_STOP,        /*   1 stop bit */
+       SERIAL_ONE_HALF_STOP,   /* 1.5 stop bit */
+       SERIAL_TWO_STOP         /*   2 stop bit */
+};
+
+#define SERIAL_STOP_SHIFT      4
+#define SERIAL_STOP_MASK       (0x3 << SERIAL_STOP_SHIFT)
+#define SERIAL_GET_STOP(config) \
+       ((config & SERIAL_STOP_MASK) >> SERIAL_STOP_SHIFT)
+
+#define SERIAL_DEFAULT_CONFIG  SERIAL_PAR_NONE << SERIAL_PAR_SHIFT | \
+                               SERIAL_8_BITS << SERIAL_BITS_SHIFT | \
+                               SERIAL_ONE_STOP << SERIAL_STOP_SHIFT
+
 /**
  * struct struct dm_serial_ops - Driver model serial operations
  *
@@ -159,6 +192,20 @@ struct dm_serial_ops {
         * @return 0 if OK, -ve on error
         */
        int (*setparity)(struct udevice *dev, enum serial_par parity);
+
+       /**
+        * setconfig() - Set up the uart configuration
+        * (parity, 5/6/7/8 bits word length, stop bits)
+        *
+        * Set up a new config for this device.
+        *
+        * @dev: Device pointer
+        * @parity: parity to use
+        * @bits: bits number to use
+        * @stop: stop bits number to use
+        * @return 0 if OK, -ve on error
+        */
+       int (*setconfig)(struct udevice *dev, uint serial_config);
 };
 
 /**