serial: msm_geni_serial_console : Add Earlycon support
PATCH v2 1/1 serial: msm_geni_serial_console : Add Earlycon support
From: Mukesh Kumar Savaliya <[email protected]>
This change enables earlyconsole support as static driver for geni based UART. Kernel space UART console driver will be generic for console and other usecases of UART.
---
-Use correct CONFIG string to compile the driver.
drivers/tty/serial/Kconfig | 15 + drivers/tty/serial/Makefile | 1 + drivers/tty/serial/msm_geni_serial_console.c | 500 +++++++++++++++++++ 3 files changed, 516 insertions(+) create mode 100644 drivers/tty/serial/msm_geni_serial_console.c
drivers/tty/serial/Kconfig +15 -0
@@ -956,6 +956,21 @@ config SERIAL_MSM_CONSOLE select SERIAL_CORE_CONSOLE select SERIAL_EARLYCON +config SERIAL_MSM_GENI_HALF_SAMPLING + bool "Changes clock divider which impacts sampling rate for QUP HW ver greater than 2.5.0" + help + Clock divider value should be doubled for QUP hardware version + greater than 2.5.0. + As earlycon can't have HW version awareness, decision is taken + based on the configuration. + +config SERIAL_MSM_GENI_EARLY_CONSOLE + bool "MSM on-chip GENI HW based early console support" + select SERIAL_MSM_GENI_HALF_SAMPLING + help + Serial early console driver for Qualcomm Technologies Inc's GENI + based QUP hardware. + config SERIAL_QCOM_GENI tristate "QCOM on-chip GENI based serial port support" depends on ARCH_QCOM || COMPILE_TEST
drivers/tty/serial/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_SERIAL_VR41XX) += vr41xx_siu.o obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o obj-$(CONFIG_SERIAL_MSM) += msm_serial.o +obj-$(CONFIG_SERIAL_MSM_GENI_EARLY_CONSOLE) += msm_geni_serial_console.o obj-$(CONFIG_SERIAL_QCOM_GENI) += qcom_geni_serial.o obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o obj-$(CONFIG_SERIAL_ALTERA_UART) += altera_uart.o
drivers/tty/serial/msm_geni_serial_console.c new file +500 -0
500 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Greg KH
maintainerdrivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();
Can't you just write the above two lines as:
writel(ch, uport->membase+SE_GENI_TX_FIFOn);
?
Why put a mb() after a _relaxed() call?
Will, I know I asked you about this on irc a while ago, is the above really correct?
This happens other places in the driver.
Also, Savaliya, please use checkpatch on your patch, you need some whitespace fixes in this code before I could accept it at the very least.
thanks,
greg k-h
Quoted 11 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();Can't you just write the above two lines as:
Quoted 4 lines
writel(ch, uport->membase+SE_GENI_TX_FIFOn);?
Why put a
mb()after a_relaxed()call?
writel() usually puts the barrier /before/ the I/O write, since it's normally used to signal the readiness of a DMA buffer, e.g.:
ptr = dma_map(...); ptr->data = tx_data; writel(dev->ctrl_reg, SEND_DATA); // Device must see tx_data
but this driver looks like it only cares about PIO rather than DMA, in which case there's no need for mb() or writel(); writel_relaxed() should do the trick because we just need to ensure ordering of the writes hitting the device. From memory-barriers.txt:
... they [relaxed accesses] are still guaranteed to be ordered with respect to other accesses from the same CPU thread to the same peripheral when operating on __iomem pointers mapped with the default I/O attributes.
Will
Greg KH
maintainerQuoted 29 lines · Will Deacon
Quoted 11 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();Can't you just write the above two lines as:
Quoted 4 lines
writel(ch, uport->membase+SE_GENI_TX_FIFOn);?
Why put a
mb()after a_relaxed()call?
writel()usually puts the barrier /before/ the I/O write, since it's normally used to signal the readiness of a DMA buffer, e.g.:ptr = dma_map(...); ptr->data = tx_data; writel(dev->ctrl_reg, SEND_DATA); // Device must see tx_databut this driver looks like it only cares about PIO rather than DMA, in which case there's no need for
mb()orwritel();writel_relaxed()should do the trick because we just need to ensure ordering of the writes hitting the device. From memory-barriers.txt:
Quoted 4 lines
... they [relaxed accesses] are still guaranteed to be ordered with respect to other accesses from the same CPU thread to the same peripheral when operating on
__iomempointers mapped with the default I/O attributes.
Ok, that makes more sense, many thanks.
So, as writes are ordered here, Savaliya, I think all of the calls to mb() can be dropped from this driver, right?
thanks,
greg k-h
Quoted 28 lines · Greg KH
Quoted 27 lines · Will Deacon
Quoted 10 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();Can't you just write the above two lines as:
Quoted 4 lines
writel(ch, uport->membase+SE_GENI_TX_FIFOn);?
Why put a
mb()after a_relaxed()call?
writel()usually puts the barrier /before/ the I/O write, since it's normally used to signal the readiness of a DMA buffer, e.g.:ptr = dma_map(...); ptr->data = tx_data; writel(dev->ctrl_reg, SEND_DATA); // Device must see tx_databut this driver looks like it only cares about PIO rather than DMA, in which case there's no need for
mb()orwritel();writel_relaxed()should do the trick because we just need to ensure ordering of the writes hitting the device. From memory-barriers.txt:
Quoted 8 lines
Quoted 4 lines
... they [relaxed accesses] are still guaranteed to be ordered with respect to other accesses from the same CPU thread to the same peripheral when operating on
__iomempointers mapped with the default I/O attributes.Ok, that makes more sense, many thanks.
So, as writes are ordered here, Savaliya, I think all of the calls to
mb()can be dropped from this driver, right?
yes, makes sense. I have removed it, kept *_relaxed() calls and uploaded the patch.
Quoted 4 lines
thanks,
greg k-h
Quoted 11 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();Can't you just write the above two lines as:
writel(ch, uport->membase+SE_GENI_TX_FIFOn);
Quoted 8 lines
?
Why put a
mb()after a_relaxed()call?Will, I know I asked you about this on irc a while ago, is the above really correct?
This happens other places in the driver.
Removed mb() calls due to _relaxed() APIs taking care of the same.
Quoted 4 lines
Also, Savaliya, please use checkpatch on your patch, you need some whitespace fixes in this code before I could accept it at the very least.
I ran the script now also on same patch, didn't any warning/error. Do you see the error ? Below is the output:
./scripts/checkpatch.pl 0001-serial-msm_geni_serial_console-Add-Earlycon-support.patch
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #58:
new file mode 100644
total: 0 errors, 1 warnings, 511 lines checked
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 30 lines · Savaliya
Quoted 11 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 276
Quoted 8 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +8
-0+static void msm_geni_serial_wr_char (struct uart_port *uport,int ch) +{ +writel_relaxed (ch, uport->membase+SE_GENI_TX_FIFOn); +/* +* Ensure FIFO write clear goes through before +* next iteration. +*/ +mb ();Can't you just write the above two lines as:
writel(ch, uport->membase+SE_GENI_TX_FIFOn);Quoted 8 lines
?
Why put a
mb()after a_relaxed()call?Will, I know I asked you about this on irc a while ago, is the above really correct?
This happens other places in the driver.
Removed
mb()calls due to_relaxed()APIs taking care of the same.Quoted 4 lines
Also, Savaliya, please use checkpatch on your patch, you need some whitespace fixes in this code before I could accept it at the very least.
I ran the script now also on same patch, didn't any warning/error. Do you see the error ? Below is the output:
Quoted 7 lines
./scripts/checkpatch.pl0001-serial-msm_geni_serial_console-Add-Earlycon-support.patch
WARNING: added, moved or deleted file(s), doesMAINTAINERSneed updating? #58:
new file mode 100644total: 0 errors, 1 warnings, 511 lines checked
You need ' ' around the '+' characters. Odd that it didn't catch that.
Also, you added a file with no MAINTAINERS entry, please add your name to it so we know who to bother over time :)
thanks,
greg k-h
Greg KH
maintainerdrivers/tty/serial/msm_geni_serial_console.c line 381
Quoted 9 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +9
-0+/* +* If the WM bit never set, then the Tx state machine is not +* in a valid state, so break, cancel/abort any existing +* command. Unfortunately the current data being written is +* lost. +*/ +while (!msm_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , +M_TX_FIFO_WATERMARK_EN , true)) +break ;
Am I reading this correctly in that if the bit is set properly, you will just loop for forever?
That feels wrong, are you sure this is correct?
drivers/tty/serial/msm_geni_serial_console.c line 391
Quoted 10 lines
drivers/tty/serial/msm_geni_serial_console.c new file +10
-0+ chars_to_write =min ((unsigned int )(count - i), + avail_fifo_bytes); +if ((chars_to_write <<1 ) > avail_fifo_bytes) + chars_to_write = (avail_fifo_bytes >>1 ); +uart_console_write (uport, (s + i), chars_to_write, + msm_geni_serial_wr_char); +writel_relaxed (M_TX_FIFO_WATERMARK_EN , + uport->membase+SE_GENI_M_IRQ_CLEAR ); +/* Ensure this goes through before polling for WM IRQ again.*/ +mb ();
Again, writel() on its own should be fine here, and elsewhere.
thanks,
greg k-h
Quoted 13 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 381
Quoted 9 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +9
-0+/* +* If the WM bit never set, then the Tx state machine is not +* in a valid state, so break, cancel/abort any existing +* command. Unfortunately the current data being written is +* lost. +*/ +while (!msm_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , +M_TX_FIFO_WATERMARK_EN , true)) +break ;Am I reading this correctly in that if the bit is set properly, you will just loop for forever?
Quoted 1 line
That feels wrong, are you sure this is correct?
It seems correct to me. The API returns true if function sees the BIT is set else returns false.
Mostly it's true and returns true, hence it shouldn't loop.
Quoted 12 lines
drivers/tty/serial/msm_geni_serial_console.c line 391
Quoted 11 lines
drivers/tty/serial/msm_geni_serial_console.c new file +10
-0+ chars_to_write =min ((unsigned int )(count - i), + avail_fifo_bytes); +if ((chars_to_write <<1 ) > avail_fifo_bytes) + chars_to_write = (avail_fifo_bytes >>1 ); +uart_console_write (uport, (s + i), chars_to_write, + msm_geni_serial_wr_char); +writel_relaxed (M_TX_FIFO_WATERMARK_EN , + uport->membase+SE_GENI_M_IRQ_CLEAR ); +/* Ensure this goes through before polling for WM IRQ again.*/ +mb ();Again,
writel()on its own should be fine here, and elsewhere.
Removed mb() from whole file as _relaxed takes care of it.
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 15 lines · Savaliya
Quoted 13 lines · Greg KH
drivers/tty/serial/msm_geni_serial_console.c line 381
Quoted 9 lines · Savaliya
drivers/tty/serial/msm_geni_serial_console.c new file +9
-0+/* +* If the WM bit never set, then the Tx state machine is not +* in a valid state, so break, cancel/abort any existing +* command. Unfortunately the current data being written is +* lost. +*/ +while (!msm_geni_serial_poll_bit (uport,SE_GENI_M_IRQ_STATUS , +M_TX_FIFO_WATERMARK_EN , true)) +break ;Am I reading this correctly in that if the bit is set properly, you will just loop for forever?
Quoted 6 lines
Quoted 1 line
That feels wrong, are you sure this is correct?
It seems correct to me. The API returns true if function sees the BIT is set else returns false.
Mostly it's true and returns true, hence it shouldn't loop.
What if it always is false, the loop is now stuck and can never break out of this. You need some sort of "timeout" for when the hardware breaks :)
thanks,
greg k-h