Skip to contentSkip to conversation

Introduce GENI SE Controller Driver

PATCH Superseded Karthikeyan Ramasubramanian 12 participants 42 messages Jan 13, 2018 – Feb 27, 2018 5 messages not in the archive Page 1 of 2

Subsystems (7)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce GENI SE Controller Driver

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a next generation programmable module for supporting a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial Interfaces using its internal Serial Engines (SE). The protocol supported by each interface is determined by the firmware loaded to the Serial Engine.

This patch series introduces GENI SE Driver to manage the GENI based QUP Wrapper and the common aspects of all SEs inside the QUP Wrapper. This patch series also introduces the UART and I2C Controller drivers to drive the SEs that are programmed with the respective protocols.

[v2]
* Updated device tree bindings to describe the hardware
* Updated SE DT node as child node of QUP Wrapper DT node
* Moved common AHB clocks to QUP Wrapper DT node
* Use the standard "clock-frequency" I2C property
* Update compatible field in UART Controller to reflect hardware manual
* Addressed other device tree binding specific comments from Rob Herring

Karthikeyan Ramasubramanian (7):
qcom-geni-se: Add QCOM GENI SE Driver summary
dt-bindings: soc: qcom: Add device tree binding for GENI SE
soc: qcom: Add GENI based QUP Wrapper driver
dt-bindings: i2c: Add device tree bindings for GENI I2C Controller
i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C
controller
dt-bindings: serial: Add bindings for GENI based UART Controller
tty: serial: msm_geni_serial: Add serial driver support for GENI based
QUP

 .../devicetree/bindings/i2c/i2c-qcom-geni.txt      |   35 +
 .../devicetree/bindings/serial/qcom,geni-uart.txt  |   29 +
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  |   66 +
 Documentation/qcom-geni-se.txt                     |   56 +
 drivers/i2c/busses/Kconfig                         |   10 +
 drivers/i2c/busses/Makefile                        |    1 +
 drivers/i2c/busses/i2c-qcom-geni.c                 |  656 +++++++++
 drivers/soc/qcom/Kconfig                           |    8 +
 drivers/soc/qcom/Makefile                          |    1 +
 drivers/soc/qcom/qcom-geni-se.c                    | 1016 ++++++++++++++
 drivers/tty/serial/Kconfig                         |   10 +
 drivers/tty/serial/Makefile                        |    1 +
 drivers/tty/serial/qcom_geni_serial.c              | 1414 ++++++++++++++++++++
 include/linux/qcom-geni-se.h                       |  807 +++++++++++
 14 files changed, 4110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
 create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
 create mode 100644 Documentation/qcom-geni-se.txt
 create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
 create mode 100644 include/linux/qcom-geni-se.h
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH v2 1/7 qcom-geni-se: Add QCOM GENI SE Driver summary

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a programmable module that is composed of multiple Serial Engines (SE) and can support various Serial Interfaces like UART, SPI, I2C, I3C, etc. This document provides a high level overview of the GENI based QUP Wrapper.

---
 Documentation/qcom-geni-se.txt | 56 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 Documentation/qcom-geni-se.txt
Documentation/qcom-geni-se.txt new file +56 -0
new file mode 100644
index 0000000..dc517ef
@@ -0,0 +1,56 @@
+Introduction
+============
+
+Generic Interface (GENI) Serial Engine (SE) Wrapper driver is introduced
+to manage GENI firmware based Qualcomm Universal Peripheral (QUP) Wrapper
+controller. QUP Wrapper is designed to support various serial bus protocols
+like UART, SPI, I2C, I3C, etc.
+
+Hardware description
+====================
+
+GENI based QUP is a highly-flexible and programmable module for supporting
+a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. A single
+QUP module can provide upto 8 Serial Interfaces, using its internal
+Serial Engines. The actual configuration is determined by the target
+platform configuration. The protocol supported by each interface is
+determined by the firmware loaded to the Serial Engine. Each SE consists
+of a DMA Engine and GENI sub modules which enable Serial Engines to
+support FIFO and DMA modes of operation.
+
+::
+
+                      +-----------------------------------------+
+                      |QUP Wrapper                              |
+                      |         +----------------------------+  |
+   --QUP & SE Clocks-->         | Serial Engine N            |  +-IO------>
+                      |         | ...                        |  | Interface
+   <---Clock Perf.----+    +----+-----------------------+    |  |
+     State Interface  |    | Serial Engine 1            |    |  |
+                      |    |                            |    |  |
+                      |    |                            |    |  |
+   <--------AHB------->    |                            |    |  |
+                      |    |                            +----+  |
+                      |    |                            |       |
+                      |    |                            |       |
+   <------SE IRQ------+    +----------------------------+       |
+                      |                                         |
+                      +-----------------------------------------+
+
+                         Figure 1: GENI based QUP Wrapper
+
+Software description
+====================
+
+GENI SE Wrapper driver is structured into 2 parts:
+
+geni_se_device represents QUP Wrapper controller. This part of the driver
+manages QUP Wrapper information such as hardware version, clock
+performance table that is common to all the internal Serial Engines.
+
+geni_se_rsc represents Serial Engine. This part of the driver manages
+Serial Engine information such as clocks, pinctrl states, containing QUP
+Wrapper. This part of driver also supports operations(eg. initialize the
+concerned Serial Engine, select between FIFO and DMA mode of operation etc.)
+that are common to all the Serial Engines and are independent of Serial
+Interfaces.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

PATCH v2 2/7 dt-bindings: soc: qcom: Add device tree binding for GENI SE

In reply to Karthikeyan Ramasubramanian

Add device tree binding support for the QCOM GENI SE driver.

---
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +34 -0
new file mode 100644
index 0000000..66f8a16
@@ -0,0 +1,34 @@
+Qualcomm Technologies, Inc. GENI Serial Engine QUP Wrapper Controller
+
+Generic Interface (GENI) based Qualcomm Universal Peripheral (QUP) wrapper
+is a programmable module for supporting a wide range of serial interfaces
+like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial
+Interfaces, using its internal Serial Engines. The GENI Serial Engine QUP
+Wrapper controller is modeled as a node with zero or more child nodes each
+representing a serial engine.
+
+Required properties:
+- compatible:		Must be "qcom,geni-se-qup".
+- reg:			Must contain QUP register address and length.
+- clock-names:		Must contain "m-ahb" and "s-ahb".
+- clocks:		AHB clocks needed by the device.
+
+Required properties if child node exists:
+- #address-cells: Must be 1
+- #size-cells: Must be 1
+- ranges: Must be present
+
+Properties for children:
+
+A GENI based QUP wrapper controller node can contain 0 or more child nodes
+representing serial devices.  These serial devices can be a QCOM UART, I2C
+controller, spi controller, or some combination of aforementioned devices.
+
+Example:
+	qup0: qcom,geniqup0@8c0000 {
+		compatible = "qcom,geni-se-qup";
+		reg = <0x8c0000 0x6000>;
+		clock-names = "m-ahb", "s-ahb";
+		clocks = <&clock_gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
+			<&clock_gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
+	}
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#9 lore raw

PATCH v2 3/7 soc: qcom: Add GENI based QUP Wrapper driver

In reply to a message not in the archive

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

---
 drivers/soc/qcom/Kconfig        |    8 +
 drivers/soc/qcom/Makefile       |    1 +
 drivers/soc/qcom/qcom-geni-se.c | 1016 +++++++++++++++++++++++++++++++++++++++
 include/linux/qcom-geni-se.h    |  807 +++++++++++++++++++++++++++++++
 4 files changed, 1832 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 include/linux/qcom-geni-se.h
drivers/soc/qcom/Kconfig +8 -0
index b81374b..b306d51 100644
@@ -3,6 +3,14 @@
 #
 menu "Qualcomm SoC drivers"
 
+config QCOM_GENI_SE
+	tristate "QCOM GENI Serial Engine Driver"
+	help
+	  This module is used to manage Generic Interface (GENI) firmware based
+	  Qualcomm Technologies, Inc. Universal Peripheral (QUP) Wrapper. This
+	  module is also used to manage the common aspects of multiple Serial
+	  Engines present in the QUP.
+
 config QCOM_GLINK_SSR
 	tristate "Qualcomm Glink SSR driver"
 	depends on RPMSG
drivers/soc/qcom/Makefile +1 -0
index 40c56f6..74d5db8 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_QCOM_GENI_SE) +=	qcom-geni-se.o
 obj-$(CONFIG_QCOM_GLINK_SSR) +=	glink_ssr.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
drivers/soc/qcom/qcom-geni-se.c new file +1016 -0

1,016 lines not on this page · raw message

include/linux/qcom-geni-se.h new file +807 -0

807 lines not on this page · raw message

Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--
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
#31 lore raw

PATCH v2 4/7 dt-bindings: i2c: Add device tree bindings for GENI I2C Controller

In reply to Karthikeyan Ramasubramanian

Add device tree binding support for I2C Controller in GENI based QUP Wrapper.

---
 .../devicetree/bindings/i2c/i2c-qcom-geni.txt      | 35 ++++++++++++++++++++++
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 19 ++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +35 -0
new file mode 100644
index 0000000..ea84be7
@@ -0,0 +1,35 @@
+Qualcomm Technologies Inc. GENI Serial Engine based I2C Controller
+
+Required properties:
+ - compatible: Should be:
+   * "qcom,i2c-geni.
+ - reg: Should contain QUP register address and length.
+ - interrupts: Should contain I2C interrupt.
+ - clock-names: Should contain "se-clk".
+ - clocks: Serial engine core clock needed by the device.
+ - pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+   should be "active" and "sleep" for the pin confuguration when core is active
+   or when entering sleep state.
+ - #address-cells: Should be <1> Address cells for i2c device address
+ - #size-cells: Should be <0> as i2c addresses have no size component
+
+Optional property:
+ - clock-frequency : Desired I2C bus clock frequency in Hz.
+   When missing default to 400000Hz.
+
+Child nodes should conform to i2c bus binding.
+
+Example:
+
+i2c0: i2c@a94000 {
+	compatible = "qcom,i2c-geni";
+	reg = <0xa94000 0x4000>;
+	interrupts = <GIC_SPI 358 0>;
+	clock-names = "se-clk";
+	clocks = <&clock_gcc GCC_QUPV3_WRAP0_S5_CLK>;
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&qup_1_i2c_5_active>;
+	pinctrl-1 = <&qup_1_i2c_5_sleep>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+};
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt +19 -0
index 66f8a16..2ffbb3e 100644
@@ -24,6 +24,9 @@ A GENI based QUP wrapper controller node can contain 0 or more child nodes
 representing serial devices.  These serial devices can be a QCOM UART, I2C
 controller, spi controller, or some combination of aforementioned devices.
 
+See the following documentation for child node definitions:
+Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
+
 Example:
 	qup0: qcom,geniqup0@8c0000 {
 		compatible = "qcom,geni-se-qup";
@@ -31,4 +34,20 @@ Example:
 		clock-names = "m-ahb", "s-ahb";
 		clocks = <&clock_gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
 			<&clock_gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		i2c0: i2c@a94000 {
+			compatible = "qcom,i2c-geni";
+			reg = <0xa94000 0x4000>;
+			interrupts = <GIC_SPI 358 0>;
+			clock-names = "se-clk";
+			clocks = <&clock_gcc GCC_QUPV3_WRAP0_S5_CLK>;
+			pinctrl-names = "default", "sleep";
+			pinctrl-0 = <&qup_1_i2c_5_active>;
+			pinctrl-1 = <&qup_1_i2c_5_sleep>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+		};
 	}
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#24 lore raw

PATCH v2 5/7 i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller

In reply to a message not in the archive

This bus driver supports the GENI based i2c hardware controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including I2C. The driver supports FIFO mode and DMA mode of transfer and switches modes dynamically depending on the size of the transfer.

---
 drivers/i2c/busses/Kconfig         |  10 +
 drivers/i2c/busses/Makefile        |   1 +
 drivers/i2c/busses/i2c-qcom-geni.c | 656 +++++++++++++++++++++++++++++++++++++
 3 files changed, 667 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c
drivers/i2c/busses/Kconfig +10 -0
index 009345d..caef309 100644
@@ -838,6 +838,16 @@ config I2C_PXA_SLAVE
 	  is necessary for systems where the PXA may be a target on the
 	  I2C bus.
 
+config I2C_QCOM_GENI
+	tristate "Qualcomm Technologies Inc.'s GENI based I2C controller"
+	depends on ARCH_QCOM
+	help
+	  If you say yes to this option, support will be included for the
+	  built-in I2C interface on the Qualcomm Technologies Inc.'s SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-qcom-geni.
+
 config I2C_QUP
 	tristate "Qualcomm QUP based I2C controller"
 	depends on ARCH_QCOM
drivers/i2c/busses/Makefile +1 -0
index 2ce8576..201fce1 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_I2C_PNX)		+= i2c-pnx.o
 obj-$(CONFIG_I2C_PUV3)		+= i2c-puv3.o
 obj-$(CONFIG_I2C_PXA)		+= i2c-pxa.o
 obj-$(CONFIG_I2C_PXA_PCI)	+= i2c-pxa-pci.o
+obj-$(CONFIG_I2C_QCOM_GENI)	+= i2c-qcom-geni.o
 obj-$(CONFIG_I2C_QUP)		+= i2c-qup.o
 obj-$(CONFIG_I2C_RIIC)		+= i2c-riic.o
 obj-$(CONFIG_I2C_RK3X)		+= i2c-rk3x.o
drivers/i2c/busses/i2c-qcom-geni.c new file +656 -0

656 lines not on this page · raw message

Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--
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
#35 lore raw

PATCH v2 6/7 dt-bindings: serial: Add bindings for GENI based UART Controller

In reply to Karthikeyan Ramasubramanian

Add device tree binding support for GENI based UART Controller in the QUP Wrapper.

---
 .../devicetree/bindings/serial/qcom,geni-uart.txt  | 29 ++++++++++++++++++++++
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 13 ++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +29 -0
new file mode 100644
index 0000000..e7b9e24
@@ -0,0 +1,29 @@
+Qualcomm Technologies Inc. GENI Serial Engine based UART Controller
+
+The Generic Interface (GENI) Serial Engine based UART controller supports
+console use-cases and is supported only by GENI based Qualcomm Universal
+Peripheral (QUP) cores.
+
+Required properties:
+- compatible: should contain "qcom,geni-debug-uart".
+- reg: Should contain UART register location and length.
+- reg-names: Should contain "se-phys".
+- interrupts: Should contain UART core interrupts.
+- clock-names: Should contain "se-clk".
+- clocks: clocks needed for UART, includes the core clock.
+- pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+  Should be "active" and "sleep" for the pin confuguration when core is active
+  or when entering sleep state.
+
+Example:
+uart0: qcom,serial@a88000 {
+	compatible = "qcom,geni-debug-uart";
+	reg = <0xa88000 0x7000>;
+	reg-names = "se-phys";
+	interrupts = <0 355 0>;
+	clock-names = "se-clk";
+	clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>;
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&qup_1_uart_3_active>;
+	pinctrl-1 = <&qup_1_uart_3_sleep>;
+};
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt +13 -0
index 2ffbb3e..c307788 100644
@@ -26,6 +26,7 @@ controller, spi controller, or some combination of aforementioned devices.
 
 See the following documentation for child node definitions:
 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
+Documentation/devicetree/bindings/serial/qcom,geni-uart.txt
 
 Example:
 	qup0: qcom,geniqup0@8c0000 {
@@ -50,4 +51,16 @@ Example:
 			#address-cells = <1>;
 			#size-cells = <0>;
 		};
+
+		uart0: qcom,serial@a88000 {
+			compatible = "qcom,geni-debug-uart";
+			reg = <0xa88000 0x7000>;
+			reg-names = "se-phys";
+			interrupts = <0 355 0>;
+			clock-names = "se-clk";
+			clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>;
+			pinctrl-names = "default", "sleep";
+			pinctrl-0 = <&qup_1_uart_3_active>;
+			pinctrl-1 = <&qup_1_uart_3_sleep>;
+		};
 	}
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#38 lore raw

PATCH v2 7/7 tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
drivers/tty/serial/Kconfig +10 -0
index b788fee..1be30e5 100644
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
 	select SERIAL_CORE_CONSOLE
 	select SERIAL_EARLYCON
 
+config SERIAL_QCOM_GENI
+	tristate "QCOM on-chip GENI based serial port support"
+	depends on ARCH_QCOM
+	select SERIAL_CORE
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Serial driver for Qualcomm Technologies Inc's GENI based QUP
+	  hardware.
+
 config SERIAL_VT8500
 	bool "VIA VT8500 on-chip serial port support"
 	depends on ARCH_VT8500
drivers/tty/serial/Makefile +1 -0
index 842d185..64a8d82 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_serial.o
 obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_MSM) += msm_serial.o
+obj-$(CONFIG_SERIAL_QCOM_GENI) += qcom_geni_serial.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
 obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
drivers/tty/serial/qcom_geni_serial.c new file +1414 -0

1,414 lines not on this page · raw message

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw

Re: [PATCH v2 1/7] qcom-geni-se: Add QCOM GENI SE Driver summary

In reply to Karthikeyan Ramasubramanian
Quoted 7 lines · Karthikeyan Ramasubramanian

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a programmable module that is composed of multiple Serial Engines (SE) and can support various Serial Interfaces like UART, SPI, I2C, I3C, etc. This document provides a high level overview of the GENI based QUP Wrapper.

Rather than adding a disconnected chunk of documentation move this into the driver(s), using the format described in
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html?highlight=kernel%20doc#overview-documentation-comments

Regards,
Bjorn

#10 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Karthikeyan Ramasubramanian
Quoted 7 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

Quoted 7 lines
---
 drivers/soc/qcom/Kconfig        |    8 +
 drivers/soc/qcom/Makefile       |    1 +
 drivers/soc/qcom/qcom-geni-se.c | 1016 +++++++++++++++++++++++++++++++++++++++

I'm not aware of any non-serial-engine "geni" at Qualcomm, so can we drop the "se" throughout this driver?

Quoted 10 lines
 include/linux/qcom-geni-se.h    |  807 +++++++++++++++++++++++++++++++
 4 files changed, 1832 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 include/linux/qcom-geni-se.h
drivers/soc/qcom/Kconfig +0 -0
index b81374b..b306d51 100644

drivers/soc/qcom/Kconfig line 7

Quoted 5 lines
drivers/soc/qcom/Kconfig +2 -0
@@ -3,6 +3,14 @@
 #
 menu "Qualcomm SoC drivers"
 
+config QCOM_GENI_SE
+	tristate "QCOM GENI Serial Engine Driver"

Options in drivers/soc/qcom/Kconfig should have "depends on ARCH_QCOM", as the makefile in this directory won't be processed when !ARCH_QCOM.

Quoted 28 lines
drivers/soc/qcom/Kconfig +6 -0
+	help
+	  This module is used to manage Generic Interface (GENI) firmware based
+	  Qualcomm Technologies, Inc. Universal Peripheral (QUP) Wrapper. This
+	  module is also used to manage the common aspects of multiple Serial
+	  Engines present in the QUP.
+
 config QCOM_GLINK_SSR
 	tristate "Qualcomm Glink SSR driver"
 	depends on RPMSG
drivers/soc/qcom/Makefile +1 -0
index 40c56f6..74d5db8 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_QCOM_GENI_SE) +=	qcom-geni-se.o
 obj-$(CONFIG_QCOM_GLINK_SSR) +=	glink_ssr.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

drivers/soc/qcom/qcom-geni-se.c line 19

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+#include <linux/clk.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/list.h>

This isn't used.

drivers/soc/qcom/qcom-geni-se.c line 23

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/pm_runtime.h>

Is this used?

drivers/soc/qcom/qcom-geni-se.c line 25

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+#include <linux/qcom-geni-se.h>
+#include <linux/spinlock.h>

Is this used?

drivers/soc/qcom/qcom-geni-se.c line 30

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+#define MAX_CLK_PERF_LEVEL 32
+
+/**
+ * @struct geni_se_device - Data structure to represent the QUP Wrapper Core

Make this name indicate that this is the wrapper; e.g. struct geni_wrapper

drivers/soc/qcom/qcom-geni-se.c line 43

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+ * @dev:		Device pointer of the QUP wrapper core.
+ * @base:		Base address of this instance of QUP wrapper core.
+ * @m_ahb_clk:		Handle to the primary AHB clock.
+ * @s_ahb_clk:		Handle to the secondary AHB clock.
+ * @geni_dev_lock:	Lock to protect the device elements.
+ * @num_clk_levels:	Number of valid clock levels in clk_perf_tbl.
+ * @clk_perf_tbl:	Table of clock frequency input to Serial Engine clock.
+ */
+struct geni_se_device {
+	struct device *dev;
+	void __iomem *base;
+	struct clk *m_ahb_clk;
+	struct clk *s_ahb_clk;

As these two clocks always seems to be operated in tandem use clk_bulk_data to keep track of them and use the clk_bulk*() operations to simplify your prepare/unprepare sites.

drivers/soc/qcom/qcom-geni-se.c line 44

Quoted 1 line
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	struct mutex geni_dev_lock;

There's only one lock and it should be obvious from context that it's the lock of the geni_se_device, so naming this "lock" should be sufficient.

drivers/soc/qcom/qcom-geni-se.c line 50

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+	unsigned int num_clk_levels;
+	unsigned long *clk_perf_tbl;
+};
+
+/* Offset of QUP Hardware Version Register */
+#define QUP_HW_VER (0x4)

Drop the parenthesis. It would be nice if this define indicated that this is a register and not a value. E.g. call it QUP_HW_VER_REG.

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+#define HW_VER_MAJOR_MASK GENMASK(31, 28)
+#define HW_VER_MAJOR_SHFT 28
+#define HW_VER_MINOR_MASK GENMASK(27, 16)
+#define HW_VER_MINOR_SHFT 16

drivers/soc/qcom/qcom-geni-se.c line 65

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+#define HW_VER_STEP_MASK GENMASK(15, 0)
+
+/**
+ * geni_read_reg_nolog() - Helper function to read from a GENI register
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.
+ */
+unsigned int geni_read_reg_nolog(void __iomem *base, int offset)

Remove this function.

drivers/soc/qcom/qcom-geni-se.c line 77

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+{
+	return readl_relaxed(base + offset);
+}
+EXPORT_SYMBOL(geni_read_reg_nolog);
+
+/**
+ * geni_write_reg_nolog() - Helper function to write into a GENI register
+ * @value:	Value to be written into the register.
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ */
+void geni_write_reg_nolog(unsigned int value, void __iomem *base, int offset)

Ditto

drivers/soc/qcom/qcom-geni-se.c line 88

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+{
+	return writel_relaxed(value, (base + offset));
+}
+EXPORT_SYMBOL(geni_write_reg_nolog);
+
+/**
+ * geni_read_reg() - Helper function to read from a GENI register
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.

Drop the extra spaces after "Return:" in all your kerneldoc.

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+ */
+unsigned int geni_read_reg(void __iomem *base, int offset)
+{
+	return readl_relaxed(base + offset);
+}
+EXPORT_SYMBOL(geni_read_reg);

drivers/soc/qcom/qcom-geni-se.c line 104

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+/**
+ * geni_write_reg() - Helper function to write into a GENI register
+ * @value:	Value to be written into the register.
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ */
+void geni_write_reg(unsigned int value, void __iomem *base, int offset)
+{
+	return writel_relaxed(value, (base + offset));

As written, this function adds no value and I find it quite confusing that this is used both for read/writes on the wrapper as well as the individual functions.

Compare:

	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);

with just inlining:

	writel(common_geni_m_irq_en, base + SE_GENI_M_IRQ_EN);
Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+}
+EXPORT_SYMBOL(geni_write_reg);
+
+/**
+ * geni_get_qup_hw_version() - Read the QUP wrapper Hardware version
+ * @wrapper_dev:	Pointer to the corresponding QUP wrapper core.
+ * @major:		Buffer for Major Version field.
+ * @minor:		Buffer for Minor Version field.
+ * @step:		Buffer for Step Version field.
+ *

drivers/soc/qcom/qcom-geni-se.c line 124

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */
+int geni_get_qup_hw_version(struct device *wrapper_dev, unsigned int *major,
+			    unsigned int *minor, unsigned int *step)
+{
+	unsigned int version;
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !major || !minor || !step)
+		return -EINVAL;

This would only happen during development, as the engineer calls the function incorrectly. Consider it a contract that these has to be valid and skip the checks.

drivers/soc/qcom/qcom-geni-se.c line 128

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -ENODEV;

Make the children acquire the geni_se_dev handle (keep the type opaque) and pass that instead of wrapper_dev. Then you can just drop this chunk.

drivers/soc/qcom/qcom-geni-se.c line 134

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	version = geni_read_reg(geni_se_dev->base, QUP_HW_VER);
+	*major = (version & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT;
+	*minor = (version & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT;
+	*step = version & HW_VER_STEP_MASK;
+	return 0;

If you implement these two changes there's no way this function can fail, so you don't have to return a value here.

drivers/soc/qcom/qcom-geni-se.c line 144

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+}
+EXPORT_SYMBOL(geni_get_qup_hw_version);
+
+/**
+ * geni_se_get_proto() - Read the protocol configured for a serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * Return:	Protocol value as configured in the serial engine.
+ */
+int geni_se_get_proto(void __iomem *base)

I keep reading this as "geni set get proto", you should be fine just dropping _se_ from these function names. And if you want to denote that it's the Qualcomm GENI then make it qcom_geni_*.

But more importantly, it is not obvious when reading this driver that the typeless "base" being passed is that of the individual functional block, and not the wrapper.

If you want to do this in an "object oriented" fashion create a struct that's common for all geni instances, include it in the context of the individual function devices and pass it into these functions.

drivers/soc/qcom/qcom-geni-se.c line 149

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+{
+	int proto;
+
+	proto = ((geni_read_reg(base, GENI_FW_REVISION_RO)
+			& FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT);

Don't do everything in one go, as you can't fit it on one line anyways. Writing it like this instead makes it easier to read:

	u32 val;

	val = readl(base + GENI_FW_S_REVISION_RO);

	return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;

drivers/soc/qcom/qcom-geni-se.c line 157

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	return proto;
+}
+EXPORT_SYMBOL(geni_se_get_proto);
+
+static int geni_se_irq_en(void __iomem *base)
+{
+	unsigned int common_geni_m_irq_en;
+	unsigned int common_geni_s_irq_en;

The size of these values isn't unsigned int, it's u32. And if you give them a shorter name the function becomes easier to read.

Further more, as you don't care about ordering you don't need two of them either. So you should be able to just do:

	u32 val;

	val = readl(base + SE_GENI_M_IRQ_EN);
	val |= M_COMMON_GENI_M_IRQ_EN;
	writel(val, base + SE_GENI_M_IRQ_EN);

	val = readl(base + SE_GENI_S_IRQ_EN);
	val |= S_COMMON_GENI_S_IRQ_EN;
	writel(val, base + SE_GENI_S_IRQ_EN);

drivers/soc/qcom/qcom-geni-se.c line 167

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	common_geni_m_irq_en = geni_read_reg(base, SE_GENI_M_IRQ_EN);
+	common_geni_s_irq_en = geni_read_reg(base, SE_GENI_S_IRQ_EN);
+	/* Common to all modes */
+	common_geni_m_irq_en |= M_COMMON_GENI_M_IRQ_EN;
+	common_geni_s_irq_en |= S_COMMON_GENI_S_IRQ_EN;
+
+	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);
+	geni_write_reg(common_geni_s_irq_en, base, SE_GENI_S_IRQ_EN);
+	return 0;

And as this can't fail there's no reason to have a return value.

Quoted 16 lines
drivers/soc/qcom/qcom-geni-se.c new file +16 -0
+}
+
+
+static void geni_se_set_rx_rfr_wm(void __iomem *base, unsigned int rx_wm,
+				  unsigned int rx_rfr)
+{
+	geni_write_reg(rx_wm, base, SE_GENI_RX_WATERMARK_REG);
+	geni_write_reg(rx_rfr, base, SE_GENI_RX_RFR_WATERMARK_REG);
+}
+
+static int geni_se_io_set_mode(void __iomem *base)
+{
+	unsigned int io_mode;
+	unsigned int geni_dma_mode;
+
+	io_mode = geni_read_reg(base, SE_IRQ_EN);

drivers/soc/qcom/qcom-geni-se.c line 193

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+
+	io_mode |= (GENI_M_IRQ_EN | GENI_S_IRQ_EN);
+	io_mode |= (DMA_TX_IRQ_EN | DMA_RX_IRQ_EN);
+	geni_dma_mode &= ~GENI_DMA_MODE_EN;
+
+	geni_write_reg(io_mode, base, SE_IRQ_EN);
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	return 0;

As this function can't fail, don't return a value.

drivers/soc/qcom/qcom-geni-se.c line 200

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+}
+
+static void geni_se_io_init(void __iomem *base)
+{
+	unsigned int io_op_ctrl;
+	unsigned int geni_cgc_ctrl;
+	unsigned int dma_general_cfg;

These are all u32, be explicit.

drivers/soc/qcom/qcom-geni-se.c line 206

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	geni_cgc_ctrl = geni_read_reg(base, GENI_CGC_CTRL);
+	dma_general_cfg = geni_read_reg(base, SE_DMA_GENERAL_CFG);
+	geni_cgc_ctrl |= DEFAULT_CGC_EN;
+	dma_general_cfg |= (AHB_SEC_SLV_CLK_CGC_ON | DMA_AHB_SLV_CFG_ON |
+			DMA_TX_CLK_CGC_ON | DMA_RX_CLK_CGC_ON);

Drop the parenthesis and there's no harm in making multiple assignments in favour of splitting the line.

drivers/soc/qcom/qcom-geni-se.c line 209

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	io_op_ctrl = DEFAULT_IO_OUTPUT_CTRL_MSK;
+	geni_write_reg(geni_cgc_ctrl, base, GENI_CGC_CTRL);
+	geni_write_reg(dma_general_cfg, base, SE_DMA_GENERAL_CFG);

Is there a reason why this chunk of code is a mix of 3 independent register updates?

drivers/soc/qcom/qcom-geni-se.c line 219

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	geni_write_reg(io_op_ctrl, base, GENI_OUTPUT_CTRL);
+	geni_write_reg(FORCE_DEFAULT, base, GENI_FORCE_DEFAULT_REG);
+}
+
+/**
+ * geni_se_init() - Initialize the GENI Serial Engine
+ * @base:	Base address of the serial engine's register block.
+ * @rx_wm:	Receive watermark to be configured.
+ * @rx_rfr_wm:	Ready-for-receive watermark to be configured.

What's the unit for these?

drivers/soc/qcom/qcom-geni-se.c line 224

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+ *
+ * This function is used to initialize the GENI serial engine, configure
+ * receive watermark and ready-for-receive watermarks.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.

As neither geni_se_io_set_mode() nor geni_se_irq_en() can fail there's no way geni_se_init() can fail and as such you don't need a return value of this function.

drivers/soc/qcom/qcom-geni-se.c line 236

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+ */
+int geni_se_init(void __iomem *base, unsigned int rx_wm, unsigned int rx_rfr)
+{
+	int ret;
+
+	geni_se_io_init(base);
+	ret = geni_se_io_set_mode(base);
+	if (ret)
+		return ret;
+
+	geni_se_set_rx_rfr_wm(base, rx_wm, rx_rfr);
+	ret = geni_se_irq_en(base);

Just inline these two functions here.

drivers/soc/qcom/qcom-geni-se.c line 239

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_init);

This is an excellent candidate for initializing a common "geni function"-struct shared among the children, i.e. make this:

void geni_init_port(struct geni_port *port, struct device *dev,

		    size_t rx_wm, rfr_wm);

And have this do the ioremap of the memory of dev and initialize some common "geni_port" struct, then you can pass this to some set of geni_port_*() helper functions.

drivers/soc/qcom/qcom-geni-se.c line 246

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+static int geni_se_select_fifo_mode(void __iomem *base)
+{
+	int proto = geni_se_get_proto(base);
+	unsigned int common_geni_m_irq_en;
+	unsigned int common_geni_s_irq_en;
+	unsigned int geni_dma_mode;

These are of type u32.

If you use more succinct names the function will be easier to read; what about master, slave and mode? (Or m_en, s_en and mode)

drivers/soc/qcom/qcom-geni-se.c line 253

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_TX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_RX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_IRQ_EN);

Use lowercase for the hex constants.

drivers/soc/qcom/qcom-geni-se.c line 261

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+
+	common_geni_m_irq_en = geni_read_reg(base, SE_GENI_M_IRQ_EN);
+	common_geni_s_irq_en = geni_read_reg(base, SE_GENI_S_IRQ_EN);
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+	if (proto != UART) {
+		common_geni_m_irq_en |=
+			(M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN |
+			M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);

Drop the parenthesis, split the assignment in multiple to make things not span 3 lines.

drivers/soc/qcom/qcom-geni-se.c line 264

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		common_geni_s_irq_en |= S_CMD_DONE_EN;
+	}
+	geni_dma_mode &= ~GENI_DMA_MODE_EN;

Please group things that are related.

The compiler doesn't care if you stretch the life time of your local variables through your functions, but the brain does.

drivers/soc/qcom/qcom-geni-se.c line 193

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);
+	geni_write_reg(common_geni_s_irq_en, base, SE_GENI_S_IRQ_EN);
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	return 0;

This can't fail, and you ignore the returned value in geni_se_select_mode().

drivers/soc/qcom/qcom-geni-se.c line 274

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+}
+
+static int geni_se_select_dma_mode(void __iomem *base)
+{
+	unsigned int geni_dma_mode = 0;

This is u32, can be shorten to "mode" and it's first use is an assignment - so you don't have to initialize it here.

drivers/soc/qcom/qcom-geni-se.c line 253

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_TX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_RX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_IRQ_EN);

Please lower case your hex constants.

drivers/soc/qcom/qcom-geni-se.c line 286

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+	geni_dma_mode |= GENI_DMA_MODE_EN;
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	return 0;

Can't fail.

drivers/soc/qcom/qcom-geni-se.c line 298

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+}
+
+/**
+ * geni_se_select_mode() - Select the serial engine transfer mode
+ * @base:	Base address of the serial engine's register block.
+ * @mode:	Transfer mode to be selected.
+ *
+ * Return:	0 on success, standard Linux error codes on failure.
+ */
+int geni_se_select_mode(void __iomem *base, int mode)
+{
+	int ret = 0;

Drop the return value and "ret", if you want to help the developer of child devices you can start off by a WARN_ON(mode != FIFO_MODE && mode != SE_DMA);

Quoted 21 lines
drivers/soc/qcom/qcom-geni-se.c new file +21 -0
+
+	switch (mode) {
+	case FIFO_MODE:
+		geni_se_select_fifo_mode(base);
+		break;
+	case SE_DMA:
+		geni_se_select_dma_mode(base);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_select_mode);
+
+/**
+ * geni_se_setup_m_cmd() - Setup the primary sequencer
+ * @base:	Base address of the serial engine's register block.
+ * @cmd:	Command/Operation to setup in the primary sequencer.

drivers/soc/qcom/qcom-geni-se.c line 329

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @params:	Parameter for the sequencer command.
+ *
+ * This function is used to configure the primary sequencer with the
+ * command and its assoicated parameters.
+ */
+void geni_se_setup_m_cmd(void __iomem *base, u32 cmd, u32 params)
+{
+	u32 m_cmd = (cmd << M_OPCODE_SHFT);
+
+	m_cmd |= (params & M_PARAMS_MSK);

Rather than initializing the variable during declaration and then amending the value it's cleaner if you do:

	val = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	geni_write_reg(m_cmd, base, SE_GENI_M_CMD0);
+}
+EXPORT_SYMBOL(geni_se_setup_m_cmd);
+

[..]

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+/**
+ * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the depth i.e. number of elements in the

drivers/soc/qcom/qcom-geni-se.c line 423

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * TX fifo of the serial engine.
+ *
+ * Return:	TX fifo depth in units of FIFO words.
+ */
+int geni_se_get_tx_fifo_depth(void __iomem *base)
+{
+	int tx_fifo_depth;
+
+	tx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_0)
+			& TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT);

It easier to read this way:

	u32 val;

	val = readl(base, SE_HW_PARAM_0);

	return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;
Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	return tx_fifo_depth;
+}
+EXPORT_SYMBOL(geni_se_get_tx_fifo_depth);
+
+/**
+ * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the width i.e. word size per element in the
+ * TX fifo of the serial engine.

drivers/soc/qcom/qcom-geni-se.c line 443

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ *
+ * Return:	TX fifo width in bits
+ */
+int geni_se_get_tx_fifo_width(void __iomem *base)
+{
+	int tx_fifo_width;
+
+	tx_fifo_width = ((geni_read_reg(base, SE_HW_PARAM_0)
+			& TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT);
+	return tx_fifo_width;

Ditto.

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +9 -0
+}
+EXPORT_SYMBOL(geni_se_get_tx_fifo_width);
+
+/**
+ * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the depth i.e. number of elements in the
+ * RX fifo of the serial engine.

drivers/soc/qcom/qcom-geni-se.c line 462

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ *
+ * Return:	RX fifo depth in units of FIFO words
+ */
+int geni_se_get_rx_fifo_depth(void __iomem *base)
+{
+	int rx_fifo_depth;
+
+	rx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_1)
+			& RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT);
+	return rx_fifo_depth;

Ditto.

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+}
+EXPORT_SYMBOL(geni_se_get_rx_fifo_depth);
+
+/**
+ * geni_se_get_packing_config() - Get the packing configuration based on input
+ * @bpw:	Bits of data per transfer word.

drivers/soc/qcom/qcom-geni-se.c line 478

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @pack_words:	Number of words per fifo element.
+ * @msb_to_lsb:	Transfer from MSB to LSB or vice-versa.
+ * @cfg0:	Output buffer to hold the first half of configuration.
+ * @cfg1:	Output buffer to hold the second half of configuration.
+ *
+ * This function is used to calculate the packing configuration based on
+ * the input packing requirement and the configuration logic.
+ */
+void geni_se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
+				unsigned long *cfg0, unsigned long *cfg1)

This function is used only from geni_se_config_packing() which writes the new config to the associated registers and from the serial driver that does the same - but here pack_words differ for rx and tx.

If you improve geni_se_config_packing() to take rx and tx fifo sizes independently you don't have to expose this function to the client drivers and you don't need to return cfg0 and cfg1 like you do here.

drivers/soc/qcom/qcom-geni-se.c line 491

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+{
+	u32 cfg[4] = {0};
+	int len;
+	int temp_bpw = bpw;
+	int idx_start = (msb_to_lsb ? (bpw - 1) : 0);
+	int idx = idx_start;
+	int idx_delta = (msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE);
+	int ceil_bpw = ((bpw & (BITS_PER_BYTE - 1)) ?
+			((bpw & ~(BITS_PER_BYTE - 1)) + BITS_PER_BYTE) : bpw);
+	int iter = (ceil_bpw * pack_words) >> 3;
+	int i;
+
+	if (unlikely(iter <= 0 || iter > 4)) {

Don't use unlikely(), this function is not called one per port, there's no need to clutter the code to "optimize" it.

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+		*cfg0 = 0;
+		*cfg1 = 0;
+		return;
+	}

drivers/soc/qcom/qcom-geni-se.c line 505

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	for (i = 0; i < iter; i++) {
+		len = (temp_bpw < BITS_PER_BYTE) ?
+				(temp_bpw - 1) : BITS_PER_BYTE - 1;
+		cfg[i] = ((idx << 5) | (msb_to_lsb << 4) | (len << 1));
+		idx = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+				((i + 1) * BITS_PER_BYTE) + idx_start :
+				idx + idx_delta;
+		temp_bpw = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+				bpw : (temp_bpw - BITS_PER_BYTE);

Each operation in this loop depend on temp_bpw being smaller or larger than BITS_PER_BYTE, please rewrite it with a single if/else based on this.

drivers/soc/qcom/qcom-geni-se.c

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+	}
+	cfg[iter - 1] |= 1;

The 1 you're writing here looks like an "EOF". It would be nice with a comment describing the format of these 4 registers and the meaning of BIT(0).

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +9 -0
+	*cfg0 = cfg[0] | (cfg[1] << 10);
+	*cfg1 = cfg[2] | (cfg[3] << 10);
+}
+EXPORT_SYMBOL(geni_se_get_packing_config);
+
+/**
+ * geni_se_config_packing() - Packing configuration of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ * @bpw:	Bits of data per transfer word.

drivers/soc/qcom/qcom-geni-se.c line 526

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @pack_words:	Number of words per fifo element.
+ * @msb_to_lsb:	Transfer from MSB to LSB or vice-versa.
+ *
+ * This function is used to configure the packing rules for the current
+ * transfer.
+ */
+void geni_se_config_packing(void __iomem *base, int bpw,
+			    int pack_words, bool msb_to_lsb)
+{
+	unsigned long cfg0, cfg1;

These are u32.

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	geni_se_get_packing_config(bpw, pack_words, msb_to_lsb, &cfg0, &cfg1);
+	geni_write_reg(cfg0, base, SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg(cfg1, base, SE_GENI_TX_PACKING_CFG1);
+	geni_write_reg(cfg0, base, SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg(cfg1, base, SE_GENI_RX_PACKING_CFG1);

drivers/soc/qcom/qcom-geni-se.c line 542

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	if (pack_words || bpw == 32)
+		geni_write_reg((bpw >> 4), base, SE_GENI_BYTE_GRAN);
+}
+EXPORT_SYMBOL(geni_se_config_packing);
+
+static void geni_se_clks_off(struct geni_se_rsc *rsc)
+{
+	struct geni_se_device *geni_se_dev;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))

Drop the unlikely(). Why would you be passed a rsc with wrapper_dev NULL?

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+		return;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return;
+
+	clk_disable_unprepare(rsc->se_clk);
+	clk_disable_unprepare(geni_se_dev->s_ahb_clk);
+	clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+}
+

drivers/soc/qcom/qcom-geni-se.c line 563

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+/**
+ * geni_se_resources_off() - Turn off resources associated with the serial
+ *                           engine
+ * @rsc:	Handle to resources associated with the serial engine.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */
+int geni_se_resources_off(struct geni_se_rsc *rsc)
+{
+	int ret = 0;

No need to initialize ret.

drivers/soc/qcom/qcom-geni-se.c line 570

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+	struct geni_se_device *geni_se_dev;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))

Only child devices would call this, so it's unlikely that this is a probe defer.

Also the returned value is not used.

And drop the unlikely()

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+		return -ENODEV;
+
+	ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_sleep);
+	if (ret)
+		return ret;

drivers/soc/qcom/qcom-geni-se.c line 585

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	geni_se_clks_off(rsc);
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_resources_off);
+
+static int geni_se_clks_on(struct geni_se_rsc *rsc)
+{
+	int ret;
+	struct geni_se_device *geni_se_dev;

If you name this "geni" instead, or "wrapper" the rest will be cleaner.

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -EPROBE_DEFER;

drivers/soc/qcom/qcom-geni-se.c line 602

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	ret = clk_prepare_enable(geni_se_dev->m_ahb_clk);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(geni_se_dev->s_ahb_clk);
+	if (ret) {
+		clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+		return ret;
+	}

These two could be dealt with in a single clk_bulk_prepare_enable().

Quoted 16 lines
drivers/soc/qcom/qcom-geni-se.c new file +16 -0
+
+	ret = clk_prepare_enable(rsc->se_clk);
+	if (ret) {
+		clk_disable_unprepare(geni_se_dev->s_ahb_clk);
+		clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+	}
+	return ret;
+}
+
+/**
+ * geni_se_resources_on() - Turn on resources associated with the serial
+ *                          engine
+ * @rsc:	Handle to resources associated with the serial engine.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */

drivers/soc/qcom/qcom-geni-se.c line 628

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+int geni_se_resources_on(struct geni_se_rsc *rsc)
+{
+	int ret = 0;
+	struct geni_se_device *geni_se_dev;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))

As with geni_se_resources_off()

drivers/soc/qcom/qcom-geni-se.c line 635

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+		return -EPROBE_DEFER;
+
+	ret = geni_se_clks_on(rsc);
+	if (ret)
+		return ret;
+
+	ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_active);

pinctrl_pm_select_default_state(rsc->dev);

So you need the dev associated with the rsc.

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	if (ret)
+		geni_se_clks_off(rsc);
+
+	return ret;

drivers/soc/qcom/qcom-geni-se.c line 649

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+}
+EXPORT_SYMBOL(geni_se_resources_on);
+
+/**
+ * geni_se_clk_tbl_get() - Get the clock table to program DFS
+ * @rsc:	Resource for which the clock table is requested.
+ * @tbl:	Table in which the output is returned.
+ *
+ * This function is called by the protocol drivers to determine the different
+ * clock frequencies supported by Serail Engine Core Clock. The protocol

s/Serail/Serial/

Quoted 6 lines

+ * drivers use the output to determine the clock frequency index to be
+ * programmed into DFS.
+ *
+ * Return: number of valid performance levels in the table on success,
+ * standard Linux error codes on failure.
+ */

drivers/soc/qcom/qcom-geni-se.c line 663

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+int geni_se_clk_tbl_get(struct geni_se_rsc *rsc, unsigned long **tbl)
+{
+	struct geni_se_device *geni_se_dev;
+	int i;
+	unsigned long prev_freq = 0;
+	int ret = 0;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev || !rsc->se_clk || !tbl))

Drop the "unlikely", you're only calling this once.

drivers/soc/qcom/qcom-geni-se.c line 666

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		return -EINVAL;
+
+	*tbl = NULL;

Don't touch tbl on error.

drivers/soc/qcom/qcom-geni-se.c line 592

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -EPROBE_DEFER;

How would this even be possible? This function should only be called by child devices, which per definition means that this device been probed.

drivers/soc/qcom/qcom-geni-se.c line 676

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	mutex_lock(&geni_se_dev->geni_dev_lock);
+	if (geni_se_dev->clk_perf_tbl) {
+		*tbl = geni_se_dev->clk_perf_tbl;
+		ret = geni_se_dev->num_clk_levels;
+		goto exit_se_clk_tbl_get;
+	}

You're never freeing clk_perf_tbl, and the only reason you have geni_dev_lock is to protect the "cached" array in geni_se_dev.

Move the allocation and generation of clk_perf_tbl to geni_se_probe() and store the value, then make this function just return that array. That way you can drop the lock and the code becomes cleaner.

drivers/soc/qcom/qcom-geni-se.c line 679

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	geni_se_dev->clk_perf_tbl = kzalloc(sizeof(*geni_se_dev->clk_perf_tbl) *
+						MAX_CLK_PERF_LEVEL, GFP_KERNEL);

Use kcalloc()

drivers/soc/qcom/qcom-geni-se.c line 689

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	if (!geni_se_dev->clk_perf_tbl) {
+		ret = -ENOMEM;
+		goto exit_se_clk_tbl_get;
+	}
+
+	for (i = 0; i < MAX_CLK_PERF_LEVEL; i++) {
+		geni_se_dev->clk_perf_tbl[i] = clk_round_rate(rsc->se_clk,
+								prev_freq + 1);
+		if (geni_se_dev->clk_perf_tbl[i] == prev_freq) {
+			geni_se_dev->clk_perf_tbl[i] = 0;

Use a local variable to keep the return value of clk_round_rate(), that way you don't have to revert the value here (not that it matters...) and you don't need to line wrap the assignment above.

drivers/soc/qcom/qcom-geni-se.c line 692

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+			break;
+		}
+		prev_freq = geni_se_dev->clk_perf_tbl[i];

...and then you don't need a separate local variable to keep track of the last value...

drivers/soc/qcom/qcom-geni-se.c line 697

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+	}
+	geni_se_dev->num_clk_levels = i;
+	*tbl = geni_se_dev->clk_perf_tbl;
+	ret = geni_se_dev->num_clk_levels;
+exit_se_clk_tbl_get:

Name your labels based on what action they perform, e.g. "out_unlock" (not err_unlock here because it's the successful path as well)

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	mutex_unlock(&geni_se_dev->geni_dev_lock);
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_clk_tbl_get);
+
+/**
+ * geni_se_clk_freq_match() - Get the matching or closest SE clock frequency
+ * @rsc:	Resource for which the clock frequency is requested.

drivers/soc/qcom/qcom-geni-se.c line 715

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @req_freq:	Requested clock frequency.
+ * @index:	Index of the resultant frequency in the table.
+ * @res_freq:	Resultant frequency which matches or is closer to the
+ *		requested frequency.
+ * @exact:	Flag to indicate exact multiple requirement of the requested
+ *		frequency .
+ *
+ * This function is called by the protocol drivers to determine the matching
+ * or closest frequency of the Serial Engine clock to be selected in order
+ * to meet the performance requirements.

What's the benefit compared to calling clk_round_rate()?

Given that the function can return a rate that is a fraction of the requested frequency even though "exact" is set, this description isn't explaining the entire picture.

Quoted 2 lines

+ *
+ * Return: 0 on success, standard Linux error codes on failure.

Returning the new clockrate would make more sense.

Quoted 11 lines

+ */

drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+int geni_se_clk_freq_match(struct geni_se_rsc *rsc, unsigned long req_freq,
+			   unsigned int *index, unsigned long *res_freq,
+			   bool exact)
+{
+	unsigned long *tbl;
+	int num_clk_levels;
+	int i;
+
+	num_clk_levels = geni_se_clk_tbl_get(rsc, &tbl);
+	if (num_clk_levels < 0)

drivers/soc/qcom/qcom-geni-se.c line 738

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+		return num_clk_levels;
+
+	if (num_clk_levels == 0)
+		return -EFAULT;
+
+	*res_freq = 0;
+	for (i = 0; i < num_clk_levels; i++) {
+		if (!(tbl[i] % req_freq)) {
+			*index = i;
+			*res_freq = tbl[i];

So this will return a frequency that divides the requested frequency without a remainder, will index be used to calculate a multiplier from this?

drivers/soc/qcom/qcom-geni-se.c line 745

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+			return 0;
+		}
+
+		if (!(*res_freq) || ((tbl[i] > *res_freq) &&
+				     (tbl[i] < req_freq))) {
+			*index = i;
+			*res_freq = tbl[i];

What if there's a previous value in tbl that given some multiplier has a smaller difference to the requested frequency?

drivers/soc/qcom/qcom-geni-se.c line 749

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+		}
+	}
+
+	if (exact || !(*res_freq))

*res_freq can't be 0, because in the case that num_clk_levels is 0 you already returned -EFAULT above, in all other cases you will assign it at least once.

drivers/soc/qcom/qcom-geni-se.c line 752

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		return -ENOKEY;
+
+	return 0;

Why not use the return value for the calculated frequency?

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+}
+EXPORT_SYMBOL(geni_se_clk_freq_match);
+
+/**
+ * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the TX buffer is mapped.
+ * @base:		Base address of the SE register block.

drivers/soc/qcom/qcom-geni-se.c line 769

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @tx_buf:		Pointer to the TX buffer.
+ * @tx_len:		Length of the TX buffer.
+ * @tx_dma:		Pointer to store the mapped DMA address.
+ *
+ * This function is used to prepare the buffers for DMA TX.
+ *
+ * Return:	0 on success, standard Linux error codes on error/failure.
+ */
+int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
+			void *tx_buf, int tx_len, dma_addr_t *tx_dma)

All child devices will have a "base", so if you move that into what you today call a geni_se_rsc and you pass that to all these functions operating on behalf of the child device you have the first two parameters passed in the same object.

A "tx_len" is typically of type size_t.

Also note that there are no other buf than tx_buf, no other len than tx_len and no other dma address than tx_dma in this function, so you can drop "tx_" without loosing any information - but improving code cleanliness.

drivers/soc/qcom/qcom-geni-se.c line 774

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+{
+	int ret;
+
+	if (unlikely(!wrapper_dev || !base || !tx_buf || !tx_len || !tx_dma))
+		return -EINVAL;

Reduce the error checking here.

drivers/soc/qcom/qcom-geni-se.c line 777

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	ret = geni_se_map_buf(wrapper_dev, tx_dma, tx_buf, tx_len,
+				    DMA_TO_DEVICE);

I think you should pass the wrapper itself to geni_se_tx_dma_prep() and if you name this "wrapper" (instead of wrapper_dev) you're under 80 chars and don't need the line break.

drivers/soc/qcom/qcom-geni-se.c line 781

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	if (ret)
+		return ret;
+
+	geni_write_reg(7, base, SE_DMA_TX_IRQ_EN_SET);

So that's DMA_RX_IRQ_EN | DMA_TX_IRQ_EN | GENI_M_IRQ_EN?

drivers/soc/qcom/qcom-geni-se.c line 783

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+	geni_write_reg((u32)(*tx_dma), base, SE_DMA_TX_PTR_L);
+	geni_write_reg((u32)((*tx_dma) >> 32), base, SE_DMA_TX_PTR_H);

If you return the dma_addr_t from this function you will have the happy side effect of being able to use tx_dma directly instead of *tx_dma and you can remove some craziness from these calls.

drivers/soc/qcom/qcom-geni-se.c line 784

Quoted 1 line
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	geni_write_reg(1, base, SE_DMA_TX_ATTR);

This "1" would be nice to have some clarification on.

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+	geni_write_reg(tx_len, base, SE_DMA_TX_LEN);
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_tx_dma_prep);
+
+/**

drivers/soc/qcom/qcom-geni-se.c line 800

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * geni_se_rx_dma_prep() - Prepare the Serial Engine for RX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @base:		Base address of the SE register block.
+ * @rx_buf:		Pointer to the RX buffer.
+ * @rx_len:		Length of the RX buffer.
+ * @rx_dma:		Pointer to store the mapped DMA address.
+ *
+ * This function is used to prepare the buffers for DMA RX.
+ *
+ * Return:	0 on success, standard Linux error codes on error/failure.

The only real error that can come out of this is dma_mapping_error(), so just return the dma_addr_t.

drivers/soc/qcom/qcom-geni-se.c line 803

Quoted 3 lines

+ */

drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+int geni_se_rx_dma_prep(struct device *wrapper_dev, void __iomem *base,
+			void *rx_buf, int rx_len, dma_addr_t *rx_dma)

As with tx, drop all the "rx_". And pass that geni_se_rsc object instead.

drivers/soc/qcom/qcom-geni-se.c line 815

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+{
+	int ret;
+
+	if (unlikely(!wrapper_dev || !base || !rx_buf || !rx_len || !rx_dma))
+		return -EINVAL;
+
+	ret = geni_se_map_buf(wrapper_dev, rx_dma, rx_buf, rx_len,
+				    DMA_FROM_DEVICE);
+	if (ret)
+		return ret;
+
+	geni_write_reg(7, base, SE_DMA_RX_IRQ_EN_SET);

We enable same interrupts for rx as tx? Why enable TX interrupt here?

drivers/soc/qcom/qcom-geni-se.c line 818

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	geni_write_reg((u32)(*rx_dma), base, SE_DMA_RX_PTR_L);
+	geni_write_reg((u32)((*rx_dma) >> 32), base, SE_DMA_RX_PTR_H);
+	/* RX does not have EOT bit */

Okay? How does this relate to the 0 being written into RX_ATTR?

Quoted 32 lines
drivers/soc/qcom/qcom-geni-se.c new file +32 -0
+	geni_write_reg(0, base, SE_DMA_RX_ATTR);
+	geni_write_reg(rx_len, base, SE_DMA_RX_LEN);
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_rx_dma_prep);
+
+/**
+ * geni_se_tx_dma_unprep() - Unprepare the Serial Engine after TX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @tx_dma:		DMA address of the TX buffer.
+ * @tx_len:		Length of the TX buffer.
+ *
+ * This function is used to unprepare the DMA buffers after DMA TX.
+ */
+void geni_se_tx_dma_unprep(struct device *wrapper_dev,
+			   dma_addr_t tx_dma, int tx_len)
+{
+	if (tx_dma)
+		geni_se_unmap_buf(wrapper_dev, &tx_dma, tx_len,
+						DMA_TO_DEVICE);
+}
+EXPORT_SYMBOL(geni_se_tx_dma_unprep);
+
+/**
+ * geni_se_rx_dma_unprep() - Unprepare the Serial Engine after RX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @rx_dma:		DMA address of the RX buffer.
+ * @rx_len:		Length of the RX buffer.
+ *
+ * This function is used to unprepare the DMA buffers after DMA RX.
+ */
+void geni_se_rx_dma_unprep(struct device *wrapper_dev,

drivers/soc/qcom/qcom-geni-se.c line 860

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+			   dma_addr_t rx_dma, int rx_len)
+{
+	if (rx_dma)
+		geni_se_unmap_buf(wrapper_dev, &rx_dma, rx_len,
+						DMA_FROM_DEVICE);
+}
+EXPORT_SYMBOL(geni_se_rx_dma_unprep);
+
+/**
+ * geni_se_map_buf() - Map a single buffer into QUP wrapper device

I find the mixture of prepare and map in the API (where prepare also maps) confusing, but no-one calls genbi_se_map_buf() can it be made internal?

Quoted 11 lines

+ * @wrapper_dev: Pointer to the corresponding QUP wrapper core.
+ * @iova: Pointer in which the mapped virtual address is stored.
+ * @buf: Address of the buffer that needs to be mapped.
+ * @size: Size of the buffer.
+ * @dir: Direction of the DMA transfer.
+ *
+ * This function is used to map an already allocated buffer into the
+ * QUP device space.
+ *
+ * Return: 0 on success, standard Linux error codes on failure/error.
+ */

drivers/soc/qcom/qcom-geni-se.c line 879

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+int geni_se_map_buf(struct device *wrapper_dev, dma_addr_t *iova,
+		    void *buf, size_t size, enum dma_data_direction dir)
+{
+	struct device *dev_p;
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !iova || !buf || !size)
+		return -EINVAL;

No need to check that the programmer of the intermediate function checked that the programmer of the client filled all these out correctly.

drivers/soc/qcom/qcom-geni-se.c line 883

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (!geni_se_dev || !geni_se_dev->dev)
+		return -ENODEV;

Pass the geni_se_device from the child driver, to remove the need for this.

drivers/soc/qcom/qcom-geni-se.c

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+
+	dev_p = geni_se_dev->dev;

Name your variables more succinct and you don't need this local alias.

drivers/soc/qcom/qcom-geni-se.c line 887

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+
+	*iova = dma_map_single(dev_p, buf, size, dir);

Just inline dma_map_single() in the functions calling this.

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	if (dma_mapping_error(dev_p, *iova))
+		return -EIO;
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_map_buf);
+
+/**
+ * geni_se_unmap_buf() - Unmap a single buffer from QUP wrapper device
+ * @wrapper_dev:	Pointer to the corresponding QUP wrapper core.
+ * @iova:		Pointer in which the mapped virtual address is stored.

drivers/soc/qcom/qcom-geni-se.c line 907

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @size:		Size of the buffer.
+ * @dir:		Direction of the DMA transfer.
+ *
+ * This function is used to unmap an already mapped buffer from the
+ * QUP device space.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */
+int geni_se_unmap_buf(struct device *wrapper_dev, dma_addr_t *iova,
+		      size_t size, enum dma_data_direction dir)

There's no reason for iova to be a pointer. Just pass the dma_addr_t as is.

Should this function really be exposed to the clients?

drivers/soc/qcom/qcom-geni-se.c line 913

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+{
+	struct device *dev_p;
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !iova || !size)
+		return -EINVAL;

Reduce the error checking.

drivers/soc/qcom/qcom-geni-se.c line 883

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (!geni_se_dev || !geni_se_dev->dev)
+		return -ENODEV;

And pass the geni_se_rsc to this function for symmetry purposes, which would give you the wrapper by just following the pointer and then the device from there.

drivers/soc/qcom/qcom-geni-se.c line 920

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	dev_p = geni_se_dev->dev;
+	dma_unmap_single(dev_p, *iova, size, dir);

Just inline dma_unmap_single() in the calling functions.

drivers/soc/qcom/qcom-geni-se.c line 928

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_unmap_buf);
+
+static const struct of_device_id geni_se_dt_match[] = {
+	{ .compatible = "qcom,geni-se-qup", },
+	{}
+};

Move this next to the geni_se_driver below and don't forget the MODULE_DEVICE_TABLE()

drivers/soc/qcom/qcom-geni-se.c line 934

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+static int geni_se_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct geni_se_device *geni_se_dev;

Just name this "geni".

drivers/soc/qcom/qcom-geni-se.c

Quoted 1 line
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	int ret = 0;

No need to initialize ret, it's only ever used after assignment.

drivers/soc/qcom/qcom-geni-se.c line 947

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+
+	geni_se_dev = devm_kzalloc(dev, sizeof(*geni_se_dev), GFP_KERNEL);
+	if (!geni_se_dev)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "%s: Mandatory resource info not found\n",
+			__func__);
+		devm_kfree(dev, geni_se_dev);
+		return -EINVAL;
+	}

It's idiomatic to not check for errors of platform_get_resource() as devm_ioremap_resource() will fail gracefully if this happens.

drivers/soc/qcom/qcom-geni-se.c line 950

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	geni_se_dev->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR_OR_NULL(geni_se_dev->base)) {

This should be IS_ERR() only.

drivers/soc/qcom/qcom-geni-se.c line 961

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+		dev_err(dev, "%s: Error mapping the resource\n", __func__);
+		devm_kfree(dev, geni_se_dev);
+		return -EFAULT;
+	}
+
+	geni_se_dev->m_ahb_clk = devm_clk_get(dev, "m-ahb");
+	if (IS_ERR(geni_se_dev->m_ahb_clk)) {
+		ret = PTR_ERR(geni_se_dev->m_ahb_clk);
+		dev_err(dev, "Err getting M AHB clk %d\n", ret);
+		devm_iounmap(dev, geni_se_dev->base);
+		devm_kfree(dev, geni_se_dev);

The reason we use the devm_ versions of these is so that we don't have to release our resources explicitly.

drivers/soc/qcom/qcom-geni-se.c line 973

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+		return ret;
+	}
+
+	geni_se_dev->s_ahb_clk = devm_clk_get(dev, "s-ahb");
+	if (IS_ERR(geni_se_dev->s_ahb_clk)) {
+		ret = PTR_ERR(geni_se_dev->s_ahb_clk);
+		dev_err(dev, "Err getting S AHB clk %d\n", ret);
+		devm_clk_put(dev, geni_se_dev->m_ahb_clk);
+		devm_iounmap(dev, geni_se_dev->base);
+		devm_kfree(dev, geni_se_dev);
+		return ret;
+	}

Use devm_clk_bulk_get().

drivers/soc/qcom/qcom-geni-se.c line 979

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	geni_se_dev->dev = dev;
+	mutex_init(&geni_se_dev->geni_dev_lock);
+	dev_set_drvdata(dev, geni_se_dev);
+	dev_dbg(dev, "GENI SE Driver probed\n");
+	return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);

You're not depopulating these devices when the wrapper goes away. Use devm_of_platform_populate() here instead to make that happen.

drivers/soc/qcom/qcom-geni-se.c line 990

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+}
+
+static int geni_se_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct geni_se_device *geni_se_dev = dev_get_drvdata(dev);
+
+	devm_clk_put(dev, geni_se_dev->s_ahb_clk);
+	devm_clk_put(dev, geni_se_dev->m_ahb_clk);
+	devm_iounmap(dev, geni_se_dev->base);
+	devm_kfree(dev, geni_se_dev);

Again, the reason to use devm_* is so that you don't have to free things...so if this is what you have here you don't even need a remove function.

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+	return 0;
+}
+
+static struct platform_driver geni_se_driver = {
+	.driver = {
+		.name = "geni_se_qup",
+		.of_match_table = geni_se_dt_match,
+	},
+	.probe = geni_se_probe,
+	.remove = geni_se_remove,
+};
+
+static int __init geni_se_driver_init(void)

drivers/soc/qcom/qcom-geni-se.c line 1013

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+{
+	return platform_driver_register(&geni_se_driver);
+}
+arch_initcall(geni_se_driver_init);
+
+static void __exit geni_se_driver_exit(void)
+{
+	platform_driver_unregister(&geni_se_driver);
+}
+module_exit(geni_se_driver_exit);

Should be fine to just use module_platform_driver(), you need separate support for earlycon regardless.

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+MODULE_DESCRIPTION("GENI Serial Engine Driver");
+MODULE_LICENSE("GPL v2");
include/linux/qcom-geni-se.h new file +2 -0
new file mode 100644
index 0000000..5695da9
@@ -0,0 +1,807 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.

[..]

Quoted 2 lines

+ */
+

Use SPDX header as above.

include/linux/qcom-geni-se.h line 20

Quoted 6 lines
include/linux/qcom-geni-se.h new file +6 -0
+#ifndef _LINUX_QCOM_GENI_SE
+#define _LINUX_QCOM_GENI_SE
+#include <linux/clk.h>
+#include <linux/dma-direction.h>
+#include <linux/io.h>
+#include <linux/list.h>

I don't think there's a need for io.h or list.h here.

include/linux/qcom-geni-se.h line 26

Quoted 6 lines
include/linux/qcom-geni-se.h new file +6 -0
+
+/* Transfer mode supported by GENI Serial Engines */
+enum geni_se_xfer_mode {
+	INVALID,
+	FIFO_MODE,
+	SE_DMA,

These are quite bad names for things in a header file.

include/linux/qcom-geni-se.h line 35

Quoted 9 lines
include/linux/qcom-geni-se.h new file +9 -0
+};
+
+/* Protocols supported by GENI Serial Engines */
+enum geni_se_protocol_types {
+	NONE,
+	SPI,
+	UART,
+	I2C,
+	I3C

Ditto

include/linux/qcom-geni-se.h line 46

Quoted 11 lines
include/linux/qcom-geni-se.h new file +11 -0
+};
+
+/**
+ * struct geni_se_rsc - GENI Serial Engine Resource
+ * @wrapper_dev:	Pointer to the parent QUP Wrapper core.
+ * @se_clk:		Handle to the core serial engine clock.
+ * @geni_pinctrl:	Handle to the pinctrl configuration.
+ * @geni_gpio_active:	Handle to the default/active pinctrl state.
+ * @geni_gpi_sleep:	Handle to the sleep pinctrl state.
+ */
+struct geni_se_rsc {

This looks like the common geni_port or geni_device I requested above.

include/linux/qcom-geni-se.h line 48

Quoted 2 lines
include/linux/qcom-geni-se.h new file +2 -0
+	struct device *wrapper_dev;
+	struct clk *se_clk;

The one and only clock can be named "clk".

include/linux/qcom-geni-se.h line 51

Quoted 3 lines
include/linux/qcom-geni-se.h new file +3 -0
+	struct pinctrl *geni_pinctrl;
+	struct pinctrl_state *geni_gpio_active;
+	struct pinctrl_state *geni_gpio_sleep;

The associated struct device already has init, default, idle and sleep pinctrl states associated through the device->pins struct. Typically this means that if you provide a "default" and "sleep" state, the default will be selected when the device probes.

In order to select between the states call pinctrl_pm_select_{default,sleep,idle}_state(dev);

include/linux/qcom-geni-se.h line 57

Quoted 6 lines
include/linux/qcom-geni-se.h new file +6 -0
+};
+
+#define PINCTRL_DEFAULT	"default"
+#define PINCTRL_SLEEP	"sleep"
+
+/* Common SE registers */

The purpose of the helper functions in the wrapper driver is to hide the common details from the individual function drivers, so move these defines into the c-file as they shouldn't be needed in the individual drivers.

Quoted 1 line

+#define GENI_INIT_CFG_REVISION (0x0)

Drop the parenthesis.

[..]

include/linux/qcom-geni-se.h line 319

Quoted 8 lines
include/linux/qcom-geni-se.h new file +8 -0
+#ifdef CONFIG_QCOM_GENI_SE
+/**
+ * geni_read_reg_nolog() - Helper function to read from a GENI register
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.
+ */

The kerneldoc goes in the implementation, not the header file. And you already have a copy there, so remove it from here.

Quoted 1 line

+unsigned int geni_read_reg_nolog(void __iomem *base, int offset);

[..]

Quoted 1 line

+#else

I see no point in providing dummy functions for these, just make the individual drivers either depend or select the core helpers.

include/linux/qcom-geni-se.h line 649

Quoted 4 lines
include/linux/qcom-geni-se.h new file +4 -0
+static inline unsigned int geni_read_reg_nolog(void __iomem *base, int offset)
+{
+	return 0;
+}

Regards,
Bjorn

#5 lore raw

Re: [PATCH v2 2/7] dt-bindings: soc: qcom: Add device tree binding for GENI SE

In reply to Karthikeyan Ramasubramanian
Quoted 3 lines · Karthikeyan Ramasubramanian

Add device tree binding support for the QCOM GENI SE driver.

Better describe the entire GENI, with it's functions in the same binding.

Quoted 19 lines
---
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +8 -0
new file mode 100644
index 0000000..66f8a16
@@ -0,0 +1,34 @@
+Qualcomm Technologies, Inc. GENI Serial Engine QUP Wrapper Controller
+
+Generic Interface (GENI) based Qualcomm Universal Peripheral (QUP) wrapper
+is a programmable module for supporting a wide range of serial interfaces
+like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial
+Interfaces, using its internal Serial Engines. The GENI Serial Engine QUP
+Wrapper controller is modeled as a node with zero or more child nodes each
+representing a serial engine.

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 18

Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +10 -0
+
+Required properties:
+- compatible:		Must be "qcom,geni-se-qup".
+- reg:			Must contain QUP register address and length.
+- clock-names:		Must contain "m-ahb" and "s-ahb".
+- clocks:		AHB clocks needed by the device.
+
+Required properties if child node exists:
+- #address-cells: Must be 1
+- #size-cells: Must be 1

But on a 64-bit system, shouldn't these be 2?

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 28

Quoted 10 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +10 -0
+- ranges: Must be present
+
+Properties for children:
+
+A GENI based QUP wrapper controller node can contain 0 or more child nodes
+representing serial devices.  These serial devices can be a QCOM UART, I2C
+controller, spi controller, or some combination of aforementioned devices.
+
+Example:
+	qup0: qcom,geniqup0@8c0000 {

I don't see a reason for this to be referenced, so skip the label. And don't use qcom, in the node name; "geni" would be perfectly fine?

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 34

Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +6 -0
+		compatible = "qcom,geni-se-qup";
+		reg = <0x8c0000 0x6000>;
+		clock-names = "m-ahb", "s-ahb";
+		clocks = <&clock_gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
+			<&clock_gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
+	}

Regards,
Bjorn

#33 lore raw

Re: [PATCH v2 4/7] dt-bindings: i2c: Add device tree bindings for GENI I2C Controller

In reply to a message not in the archive
Quoted 17 lines · Karthikeyan Ramasubramanian

Add device tree binding support for I2C Controller in GENI based QUP Wrapper.

---
 .../devicetree/bindings/i2c/i2c-qcom-geni.txt      | 35 ++++++++++++++++++++++
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 19 ++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +0 -0
new file mode 100644
index 0000000..ea84be7

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 5

Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +5 -0
@@ -0,0 +1,35 @@
+Qualcomm Technologies Inc. GENI Serial Engine based I2C Controller
+
+Required properties:
+ - compatible: Should be:
+   * "qcom,i2c-geni.

As this is a subset of geni it would look better with qcom,geni-i2c imho.

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 8

Quoted 3 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +3 -0
+ - reg: Should contain QUP register address and length.
+ - interrupts: Should contain I2C interrupt.
+ - clock-names: Should contain "se-clk".

Omit "clk" from the clock names.

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 12

Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +4 -0
+ - clocks: Serial engine core clock needed by the device.
+ - pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+   should be "active" and "sleep" for the pin confuguration when core is active
+   or when entering sleep state.

No need to describe pinctrl properties - and your description here doesn't match the code.

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 20

Quoted 8 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +8 -0
+ - #address-cells: Should be <1> Address cells for i2c device address
+ - #size-cells: Should be <0> as i2c addresses have no size component
+
+Optional property:
+ - clock-frequency : Desired I2C bus clock frequency in Hz.
+   When missing default to 400000Hz.
+
+Child nodes should conform to i2c bus binding.

..."as described in i2c.txt"

Regards,
Bjorn
--
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

#36 lore raw

Re: [PATCH v2 6/7] dt-bindings: serial: Add bindings for GENI based UART Controller

In reply to Karthikeyan Ramasubramanian
Quoted 17 lines · Karthikeyan Ramasubramanian

Add device tree binding support for GENI based UART Controller in the QUP Wrapper.

---
 .../devicetree/bindings/serial/qcom,geni-uart.txt  | 29 ++++++++++++++++++++++
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 13 ++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +0 -0
new file mode 100644
index 0000000..e7b9e24

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 8

Quoted 8 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +8 -0
@@ -0,0 +1,29 @@
+Qualcomm Technologies Inc. GENI Serial Engine based UART Controller
+
+The Generic Interface (GENI) Serial Engine based UART controller supports
+console use-cases and is supported only by GENI based Qualcomm Universal
+Peripheral (QUP) cores.
+
+Required properties:
+- compatible: should contain "qcom,geni-debug-uart".

Why is this uart a _debug_ uart? Is there a separate binding for the geni-uart?

I like that your naming here matches my suggestion with qcom,geni-i2c.

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 10

Quoted 2 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +2 -0
+- reg: Should contain UART register location and length.
+- reg-names: Should contain "se-phys".

No need to specify reg-names for a single reg.

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 12

Quoted 2 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +2 -0
+- interrupts: Should contain UART core interrupts.
+- clock-names: Should contain "se-clk".

Omit the "clk"

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 13

Quoted 1 line
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +1 -0
+- clocks: clocks needed for UART, includes the core clock.

Be more specific.

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 16

Quoted 3 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +3 -0
+- pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+  Should be "active" and "sleep" for the pin confuguration when core is active
+  or when entering sleep state.

Omit pinctrl information.

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 19

Quoted 3 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +3 -0
+
+Example:
+uart0: qcom,serial@a88000 {

Don't use qcom, in node name. This should be named "serial".

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 23

Quoted 4 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +4 -0
+	compatible = "qcom,geni-debug-uart";
+	reg = <0xa88000 0x7000>;
+	reg-names = "se-phys";
+	interrupts = <0 355 0>;

<GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 29

Quoted 6 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +6 -0
+	clock-names = "se-clk";
+	clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>;
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&qup_1_uart_3_active>;
+	pinctrl-1 = <&qup_1_uart_3_sleep>;
+};

Regards,
Bjorn

#26 lore raw

Re: [PATCH v2 5/7] i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller

In reply to a message not in the archive
Quoted 21 lines · Karthikeyan Ramasubramanian

This bus driver supports the GENI based i2c hardware controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including I2C. The driver supports FIFO mode and DMA mode of transfer and switches modes dynamically depending on the size of the transfer.

---
 drivers/i2c/busses/Kconfig         |  10 +
 drivers/i2c/busses/Makefile        |   1 +
 drivers/i2c/busses/i2c-qcom-geni.c | 656 +++++++++++++++++++++++++++++++++++++
 3 files changed, 667 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c
drivers/i2c/busses/Kconfig +0 -0
index 009345d..caef309 100644

drivers/i2c/busses/Kconfig config I2C_PXA_SLAVE · line 843

Quoted 6 lines
drivers/i2c/busses/Kconfig +3 -0
@@ -838,6 +838,16 @@ config I2C_PXA_SLAVE
 	  is necessary for systems where the PXA may be a target on the
 	  I2C bus.
 
+config I2C_QCOM_GENI
+	tristate "Qualcomm Technologies Inc.'s GENI based I2C controller"
+	depends on ARCH_QCOM

Just depend on the GENI wrapper as well.

Quoted 31 lines
drivers/i2c/busses/Kconfig +7 -0
+	help
+	  If you say yes to this option, support will be included for the
+	  built-in I2C interface on the Qualcomm Technologies Inc.'s SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-qcom-geni.
+
 config I2C_QUP
 	tristate "Qualcomm QUP based I2C controller"
 	depends on ARCH_QCOM
drivers/i2c/busses/Makefile +1 -0
index 2ce8576..201fce1 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_I2C_PNX)		+= i2c-pnx.o
 obj-$(CONFIG_I2C_PUV3)		+= i2c-puv3.o
 obj-$(CONFIG_I2C_PXA)		+= i2c-pxa.o
 obj-$(CONFIG_I2C_PXA_PCI)	+= i2c-pxa-pci.o
+obj-$(CONFIG_I2C_QCOM_GENI)	+= i2c-qcom-geni.o
 obj-$(CONFIG_I2C_QUP)		+= i2c-qup.o
 obj-$(CONFIG_I2C_RIIC)		+= i2c-riic.o
 obj-$(CONFIG_I2C_RK3X)		+= i2c-rk3x.o
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
new file mode 100644
index 0000000..59ad4da
@@ -0,0 +1,656 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/i2c/busses/i2c-qcom-geni.c line 13

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Use SPDX license header.

drivers/i2c/busses/i2c-qcom-geni.c line 16

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+#include <linux/clk.h>
+#include <linux/delay.h>

Unused?

drivers/i2c/busses/i2c-qcom-geni.c line 29

Quoted 13 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +13 -0
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/dma-mapping.h>
+#include <linux/qcom-geni-se.h>
+
+#define SE_I2C_TX_TRANS_LEN		(0x26C)

Drop the parenthesis, when not needed.

Quoted 45 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +45 -0
+#define SE_I2C_RX_TRANS_LEN		(0x270)
+#define SE_I2C_SCL_COUNTERS		(0x278)
+#define SE_GENI_IOS			(0x908)
+
+#define SE_I2C_ERR  (M_CMD_OVERRUN_EN | M_ILLEGAL_CMD_EN | M_CMD_FAILURE_EN |\
+			M_GP_IRQ_1_EN | M_GP_IRQ_3_EN | M_GP_IRQ_4_EN)
+#define SE_I2C_ABORT (1U << 1)
+/* M_CMD OP codes for I2C */
+#define I2C_WRITE		(0x1)
+#define I2C_READ		(0x2)
+#define I2C_WRITE_READ		(0x3)
+#define I2C_ADDR_ONLY		(0x4)
+#define I2C_BUS_CLEAR		(0x6)
+#define I2C_STOP_ON_BUS		(0x7)
+/* M_CMD params for I2C */
+#define PRE_CMD_DELAY		(BIT(0))
+#define TIMESTAMP_BEFORE	(BIT(1))
+#define STOP_STRETCH		(BIT(2))
+#define TIMESTAMP_AFTER		(BIT(3))
+#define POST_COMMAND_DELAY	(BIT(4))
+#define IGNORE_ADD_NACK		(BIT(6))
+#define READ_FINISHED_WITH_ACK	(BIT(7))
+#define BYPASS_ADDR_PHASE	(BIT(8))
+#define SLV_ADDR_MSK		(GENMASK(15, 9))
+#define SLV_ADDR_SHFT		(9)
+
+#define I2C_CORE2X_VOTE		(10000)
+#define GP_IRQ0			0
+#define GP_IRQ1			1
+#define GP_IRQ2			2
+#define GP_IRQ3			3
+#define GP_IRQ4			4
+#define GP_IRQ5			5
+#define GENI_OVERRUN		6
+#define GENI_ILLEGAL_CMD	7
+#define GENI_ABORT_DONE		8
+#define GENI_TIMEOUT		9
+
+#define I2C_NACK		GP_IRQ1
+#define I2C_BUS_PROTO		GP_IRQ3
+#define I2C_ARB_LOST		GP_IRQ4
+#define DM_I2C_CB_ERR		((BIT(GP_IRQ1) | BIT(GP_IRQ3) | BIT(GP_IRQ4)) \
+									<< 5)
+
+#define I2C_AUTO_SUSPEND_DELAY	250

drivers/i2c/busses/i2c-qcom-geni.c line 84

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+#define KHz(freq)		(1000 * freq)
+
+struct geni_i2c_dev {
+	struct device *dev;
+	void __iomem *base;
+	unsigned int tx_wm;
+	int irq;
+	int err;
+	struct i2c_adapter adap;
+	struct completion xfer;

How about naming this "done" or something like that, gi2c->xfer doesn't really give the sense of being a "we're done with the operation"-event.

drivers/i2c/busses/i2c-qcom-geni.c line 89

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	struct i2c_msg *cur;
+	struct geni_se_rsc i2c_rsc;
+	int cur_wr;
+	int cur_rd;
+	struct device *wrapper_dev;

This is already availabe in i2c_rsc, and in particular if you pass the i2c_rsc down to the wrapper in the 2 cases you use the wrapper_dev you don't need this duplication.

drivers/i2c/busses/i2c-qcom-geni.c line 91

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+	u32 clk_freq_out;
+	int clk_fld_idx;

Keep track of the const struct geni_i2c_clk_fld * here instead.

drivers/i2c/busses/i2c-qcom-geni.c line 102

Quoted 11 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+};
+
+struct geni_i2c_err_log {
+	int err;
+	const char *msg;
+};
+
+static struct geni_i2c_err_log gi2c_log[] = {
+	[GP_IRQ0] = {-EINVAL, "Unknown I2C err GP_IRQ0"},
+	[I2C_NACK] = {-ENOTCONN,
+			"NACK: slv unresponsive, check its power/reset-ln"},

Break the 80-char rule, to improve readability.

Quoted 12 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +12 -0
+	[GP_IRQ2] = {-EINVAL, "Unknown I2C err GP IRQ2"},
+	[I2C_BUS_PROTO] = {-EPROTO,
+				"Bus proto err, noisy/unepxected start/stop"},
+	[I2C_ARB_LOST] = {-EBUSY,
+				"Bus arbitration lost, clock line undriveable"},
+	[GP_IRQ5] = {-EINVAL, "Unknown I2C err GP IRQ5"},
+	[GENI_OVERRUN] = {-EIO, "Cmd overrun, check GENI cmd-state machine"},
+	[GENI_ILLEGAL_CMD] = {-EILSEQ,
+				"Illegal cmd, check GENI cmd-state machine"},
+	[GENI_ABORT_DONE] = {-ETIMEDOUT, "Abort after timeout successful"},
+	[GENI_TIMEOUT] = {-ETIMEDOUT, "I2C TXN timed out"},
+};

drivers/i2c/busses/i2c-qcom-geni.c line 124

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+
+struct geni_i2c_clk_fld {
+	u32	clk_freq_out;
+	u8	clk_div;
+	u8	t_high;
+	u8	t_low;
+	u8	t_cycle;
+};
+
+static struct geni_i2c_clk_fld geni_i2c_clk_map[] = {

const

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+	{KHz(100), 7, 10, 11, 26},
+	{KHz(400), 2,  5, 12, 24},
+	{KHz(1000), 1, 3,  9, 18},
+};
+
+static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c)

drivers/i2c/busses/i2c-qcom-geni.c line 140

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+{
+	int i;
+	int ret = 0;
+	bool clk_map_present = false;
+	struct geni_i2c_clk_fld *itr = geni_i2c_clk_map;
+
+	for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map); i++, itr++) {
+		if (itr->clk_freq_out == gi2c->clk_freq_out) {
+			clk_map_present = true;
+			break;

Make this:

			gi2c->clk_fld = geni_i2c_clk_map + i;
			return 0;

drivers/i2c/busses/i2c-qcom-geni.c line 143

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+		}
+	}
+

...then you can drop ret and clk_map_present and just return -EINVAL here.

drivers/i2c/busses/i2c-qcom-geni.c line 152

Quoted 9 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +9 -0
+	if (clk_map_present)
+		gi2c->clk_fld_idx = i;
+	else
+		ret = -EINVAL;
+
+	return ret;
+}
+
+static inline void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c, int dfs)

Drop the "inline", if it makes sense the compiler will inline it, if not it knows better than we do.

dfs is always 0, so drop this parameter and hard code the value below.

drivers/i2c/busses/i2c-qcom-geni.c line 162

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+{
+	struct geni_i2c_clk_fld *itr = geni_i2c_clk_map + gi2c->clk_fld_idx;
+
+	geni_write_reg(dfs, gi2c->base, SE_GENI_CLK_SEL);
+
+	geni_write_reg((itr->clk_div << 4) | 1, gi2c->base, GENI_SER_M_CLK_CFG);
+	geni_write_reg(((itr->t_high << 20) | (itr->t_low << 10) |
+			itr->t_cycle), gi2c->base, SE_I2C_SCL_COUNTERS);
+
+	/* Ensure Clk config completes before return */

That's not what "mb" does, it ensures that later memory operations aren't reordered beyond the barrier.

drivers/i2c/busses/i2c-qcom-geni.c line 166

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+	mb();
+}
+
+static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)

Looking at the code in this function it's just a bunch of logic to print various debug messages...except for the last line that uses the gi2c_log lookup table to convert the error to a errno. Sneaky...and not very nice.

drivers/i2c/busses/i2c-qcom-geni.c line 168

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+{
+	u32 m_cmd = readl_relaxed(gi2c->base + SE_GENI_M_CMD0);

Unless you have a really good reason, just use readl/writel in favour of their _relaxed versions.

Quoted 55 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +55 -0
+	u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
+	u32 geni_s = readl_relaxed(gi2c->base + SE_GENI_STATUS);
+	u32 geni_ios = readl_relaxed(gi2c->base + SE_GENI_IOS);
+	u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
+	u32 rx_st, tx_st;
+
+	if (gi2c->cur)
+		dev_dbg(gi2c->dev, "len:%d, slv-addr:0x%x, RD/WR:%d\n",
+			gi2c->cur->len, gi2c->cur->addr, gi2c->cur->flags);
+
+	if (err == I2C_NACK || err == GENI_ABORT_DONE) {
+		dev_dbg(gi2c->dev, "%s\n", gi2c_log[err].msg);
+		goto err_ret;
+	} else {
+		dev_err(gi2c->dev, "%s\n", gi2c_log[err].msg);
+	}
+
+	if (dma) {
+		rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
+		tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
+	} else {
+		rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
+		tx_st = readl_relaxed(gi2c->base + SE_GENI_TX_FIFO_STATUS);
+	}
+	dev_dbg(gi2c->dev, "DMA:%d tx_stat:0x%x, rx_stat:0x%x, irq-stat:0x%x\n",
+		dma, tx_st, rx_st, m_stat);
+	dev_dbg(gi2c->dev, "m_cmd:0x%x, geni_status:0x%x, geni_ios:0x%x\n",
+		m_cmd, geni_s, geni_ios);
+err_ret:
+	gi2c->err = gi2c_log[err].err;
+}
+
+static irqreturn_t geni_i2c_irq(int irq, void *dev)
+{
+	struct geni_i2c_dev *gi2c = dev;
+	int i, j;
+	u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
+	u32 rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
+	u32 dm_tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
+	u32 dm_rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
+	u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
+	struct i2c_msg *cur = gi2c->cur;
+
+	if (!cur || (m_stat & M_CMD_FAILURE_EN) ||
+		    (dm_rx_st & (DM_I2C_CB_ERR)) ||
+		    (m_stat & M_CMD_ABORT_EN)) {
+
+		if (m_stat & M_GP_IRQ_1_EN)
+			geni_i2c_err(gi2c, I2C_NACK);
+		if (m_stat & M_GP_IRQ_3_EN)
+			geni_i2c_err(gi2c, I2C_BUS_PROTO);
+		if (m_stat & M_GP_IRQ_4_EN)
+			geni_i2c_err(gi2c, I2C_ARB_LOST);
+		if (m_stat & M_CMD_OVERRUN_EN)
+			geni_i2c_err(gi2c, GENI_OVERRUN);

drivers/i2c/busses/i2c-qcom-geni.c line 233

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+		if (m_stat & M_ILLEGAL_CMD_EN)
+			geni_i2c_err(gi2c, GENI_ILLEGAL_CMD);
+		if (m_stat & M_CMD_ABORT_EN)
+			geni_i2c_err(gi2c, GENI_ABORT_DONE);
+		if (m_stat & M_GP_IRQ_0_EN)
+			geni_i2c_err(gi2c, GP_IRQ0);
+
+		if (!dma)
+			writel_relaxed(0, (gi2c->base +
+					   SE_GENI_TX_WATERMARK_REG));

Drop the extra parenthesis. And using writel() instead keeps you under 80 chars.

drivers/i2c/busses/i2c-qcom-geni.c line 244

Quoted 11 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+		goto irqret;
+	}
+
+	if (dma) {
+		dev_dbg(gi2c->dev, "i2c dma tx:0x%x, dma rx:0x%x\n", dm_tx_st,
+			dm_rx_st);
+		goto irqret;
+	}
+
+	if (((m_stat & M_RX_FIFO_WATERMARK_EN) ||
+		(m_stat & M_RX_FIFO_LAST_EN)) && (cur->flags & I2C_M_RD)) {

Some of these parenthesis are unnecessary, but more importantly the way you wrap this line is misleading; the wrapping indicates that the two latter conditionals are related, but the parenthesis says the first two are.

The most significant part of this conditional is "is this a read operation", so put this first.

drivers/i2c/busses/i2c-qcom-geni.c line 255

Quoted 11 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+		u32 rxcnt = rx_st & RX_FIFO_WC_MSK;
+
+		for (j = 0; j < rxcnt; j++) {
+			u32 temp;
+			int p;
+
+			temp = readl_relaxed(gi2c->base + SE_GENI_RX_FIFOn);
+			for (i = gi2c->cur_rd, p = 0; (i < cur->len && p < 4);
+				i++, p++)
+				cur->buf[i] = (u8) ((temp >> (p * 8)) & 0xff);
+			gi2c->cur_rd = i;

The two-range for loop with a line wrap isn't very clean and the wrap calls for a set of braces - which will look ugly.

How about something like this instead?

			p = 0;
			while (p < 4 && gi2c->cur_rd < cur->len) {
				cur->buf[gi2c->cur_rd++] = temp & 0xff;
				temp >>= 8;
				p++;
			}

drivers/i2c/busses/i2c-qcom-geni.c line 258

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+			if (gi2c->cur_rd == cur->len) {
+				dev_dbg(gi2c->dev, "FIFO i:%d,read 0x%x\n",
+					i, temp);

Who's the consumer of this debug line?

drivers/i2c/busses/i2c-qcom-geni.c line 271

Quoted 13 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +13 -0
+				break;
+			}
+		}
+	} else if ((m_stat & M_TX_FIFO_WATERMARK_EN) &&
+					!(cur->flags & I2C_M_RD)) {
+		for (j = 0; j < gi2c->tx_wm; j++) {
+			u32 temp = 0;
+			int p;
+
+			for (i = gi2c->cur_wr, p = 0; (i < cur->len && p < 4);
+				i++, p++)
+				temp |= (((u32)(cur->buf[i]) << (p * 8)));
+			writel_relaxed(temp, gi2c->base + SE_GENI_TX_FIFOn);

Same concern as above.

drivers/i2c/busses/i2c-qcom-geni.c line 277

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+			gi2c->cur_wr = i;
+			dev_dbg(gi2c->dev, "FIFO i:%d,wrote 0x%x\n", i, temp);
+			if (gi2c->cur_wr == cur->len) {
+				dev_dbg(gi2c->dev, "FIFO i2c bytes done writing\n");
+				writel_relaxed(0,
+				(gi2c->base + SE_GENI_TX_WATERMARK_REG));

The line break here is bad. checkpatch.pl --strict will help you find these.

Also using writel() and dropping the parenthesis keeps you below 80 chars.

drivers/i2c/busses/i2c-qcom-geni.c line 284

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +7 -0
+				break;
+			}
+		}
+	}
+irqret:
+	if (m_stat)
+		writel_relaxed(m_stat, gi2c->base + SE_GENI_M_IRQ_CLEAR);

Is it okay for this to be re-ordered wrt above writes?

drivers/i2c/busses/i2c-qcom-geni.c line 289

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+
+	if (dma) {
+		if (dm_tx_st)
+			writel_relaxed(dm_tx_st, gi2c->base +
+				       SE_DMA_TX_IRQ_CLR);

Use writel() and you don't have to wrap the line.

drivers/i2c/busses/i2c-qcom-geni.c line 293

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+		if (dm_rx_st)
+			writel_relaxed(dm_rx_st, gi2c->base +
+				       SE_DMA_RX_IRQ_CLR);
+		/* Ensure all writes are done before returning from ISR. */

That's not what wmb does.

drivers/i2c/busses/i2c-qcom-geni.c line 296

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+		wmb();
+	}
+	/* if this is err with done-bit not set, handle that thr' timeout. */

Is "thr'" should for "through"?

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+	if (m_stat & M_CMD_DONE_EN)
+		complete(&gi2c->xfer);
+	else if ((dm_tx_st & TX_DMA_DONE) || (dm_rx_st & RX_DMA_DONE))
+		complete(&gi2c->xfer);

drivers/i2c/busses/i2c-qcom-geni.c line 310

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+
+	return IRQ_HANDLED;
+}
+
+static int geni_i2c_xfer(struct i2c_adapter *adap,
+			 struct i2c_msg msgs[],
+			 int num)
+{
+	struct geni_i2c_dev *gi2c = i2c_get_adapdata(adap);
+	int i, ret = 0, timeout = 0;

No need to initialize these, first use is an assignment.

drivers/i2c/busses/i2c-qcom-geni.c line 313

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+	gi2c->err = 0;
+	gi2c->cur = &msgs[0];

You're assigning cur in each iteration of the loop below, why do you need to do it here as well?

drivers/i2c/busses/i2c-qcom-geni.c line 321

Quoted 8 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +8 -0
+	reinit_completion(&gi2c->xfer);
+	ret = pm_runtime_get_sync(gi2c->dev);
+	if (ret < 0) {
+		dev_err(gi2c->dev, "error turning SE resources:%d\n", ret);
+		pm_runtime_put_noidle(gi2c->dev);
+		/* Set device in suspended since resume failed */
+		pm_runtime_set_suspended(gi2c->dev);
+		return ret;

With the questionable assignment above you're leaving the function with gi2c->cur pointing to an object that will soon be invalid.

drivers/i2c/busses/i2c-qcom-geni.c line 326

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	}
+
+	qcom_geni_i2c_conf(gi2c, 0);
+	dev_dbg(gi2c->dev, "i2c xfer:num:%d, msgs:len:%d,flg:%d\n",
+				num, msgs[0].len, msgs[0].flags);

Use dynamic function tracing instead of debug prints for this.

drivers/i2c/busses/i2c-qcom-geni.c line 327

Quoted 1 line
drivers/i2c/busses/i2c-qcom-geni.c new file +1 -0
+	for (i = 0; i < num; i++) {

I suggest that you split out two functions here, one for rx-one-message and one for tx-one-message. There are some duplication between the two, but not too bad.

drivers/i2c/busses/i2c-qcom-geni.c line 333

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+		int stretch = (i < (num - 1));
+		u32 m_param = 0;
+		u32 m_cmd = 0;
+		dma_addr_t tx_dma = 0;
+		dma_addr_t rx_dma = 0;
+		enum geni_se_xfer_mode mode = FIFO_MODE;

No need to initialize mode, as the first use is an assignment.

drivers/i2c/busses/i2c-qcom-geni.c line 336

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+		m_param |= (stretch ? STOP_STRETCH : 0);
+		m_param |= ((msgs[i].addr & 0x7F) << SLV_ADDR_SHFT);

Drop some parenthesis.

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +7 -0
+
+		gi2c->cur = &msgs[i];
+		mode = msgs[i].len > 32 ? SE_DMA : FIFO_MODE;
+		ret = geni_se_select_mode(gi2c->base, mode);
+		if (ret) {
+			dev_err(gi2c->dev, "%s: Error mode init %d:%d:%d\n",
+				__func__, mode, i, msgs[i].len);

drivers/i2c/busses/i2c-qcom-geni.c line 353

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+			break;
+		}
+		if (msgs[i].flags & I2C_M_RD) {
+			dev_dbg(gi2c->dev,
+				"READ,n:%d,i:%d len:%d, stretch:%d\n",
+					num, i, msgs[i].len, stretch);
+			geni_write_reg(msgs[i].len,
+				       gi2c->base, SE_I2C_RX_TRANS_LEN);
+			m_cmd = I2C_READ;
+			geni_se_setup_m_cmd(gi2c->base, m_cmd, m_param);

Drop m_cmd and just write I2C_READ in the function call.

Quoted 23 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +23 -0
+			if (mode == SE_DMA) {
+				ret = geni_se_rx_dma_prep(gi2c->wrapper_dev,
+							gi2c->base, msgs[i].buf,
+							msgs[i].len, &rx_dma);
+				if (ret) {
+					mode = FIFO_MODE;
+					ret = geni_se_select_mode(gi2c->base,
+								  mode);
+				}
+			}
+		} else {
+			dev_dbg(gi2c->dev,
+				"WRITE:n:%d,i:%d len:%d, stretch:%d, m_param:0x%x\n",
+					num, i, msgs[i].len, stretch, m_param);
+			geni_write_reg(msgs[i].len, gi2c->base,
+						SE_I2C_TX_TRANS_LEN);
+			m_cmd = I2C_WRITE;
+			geni_se_setup_m_cmd(gi2c->base, m_cmd, m_param);
+			if (mode == SE_DMA) {
+				ret = geni_se_tx_dma_prep(gi2c->wrapper_dev,
+							gi2c->base, msgs[i].buf,
+							msgs[i].len, &tx_dma);
+				if (ret) {

drivers/i2c/busses/i2c-qcom-geni.c line 386

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+					mode = FIFO_MODE;
+					ret = geni_se_select_mode(gi2c->base,
+								  mode);
+				}
+			}
+			if (mode == FIFO_MODE) /* Get FIFO IRQ */
+				geni_write_reg(1, gi2c->base,
+						SE_GENI_TX_WATERMARK_REG);
+		}
+		/* Ensure FIFO write go through before waiting for Done evet */

That's not what mb does, drop it.

drivers/i2c/busses/i2c-qcom-geni.c line 388

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+		mb();
+		timeout = wait_for_completion_timeout(&gi2c->xfer, HZ);

As written you should just use "ret", but the return value of wait_for_completion_timeout() is unsigned long, so change the type of timeout instead.

drivers/i2c/busses/i2c-qcom-geni.c line 393

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+		if (!timeout) {
+			geni_i2c_err(gi2c, GENI_TIMEOUT);
+			gi2c->cur = NULL;
+			geni_se_abort_m_cmd(gi2c->base);
+			timeout = wait_for_completion_timeout(&gi2c->xfer, HZ);

What if it takes a fraction above HZ time to complete the previous operation, then you might end up here with the completion completed, but from the wrong operation.

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+		}
+		gi2c->cur_wr = 0;
+		gi2c->cur_rd = 0;
+		if (mode == SE_DMA) {
+			if (gi2c->err) {

drivers/i2c/busses/i2c-qcom-geni.c line 408

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+				if (msgs[i].flags != I2C_M_RD)
+					writel_relaxed(1, gi2c->base +
+							SE_DMA_TX_FSM_RST);
+				else
+					writel_relaxed(1, gi2c->base +
+							SE_DMA_RX_FSM_RST);
+				wait_for_completion_timeout(&gi2c->xfer, HZ);
+			}
+			geni_se_rx_dma_unprep(gi2c->wrapper_dev, rx_dma,
+					      msgs[i].len);

Reduce the length of gi2c->wrapper_dev here by using a local variable, so that you get below (or close to) 80 chars.

Also, in either rx or tx cases above I see only that you prep one of thse, and then you're unprepping both.

Quoted 19 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +19 -0
+			geni_se_tx_dma_unprep(gi2c->wrapper_dev, tx_dma,
+					      msgs[i].len);
+		}
+		ret = gi2c->err;
+		if (gi2c->err) {
+			dev_err(gi2c->dev, "i2c error :%d\n", gi2c->err);
+			break;
+		}
+	}
+	if (ret == 0)
+		ret = num;
+
+	pm_runtime_mark_last_busy(gi2c->dev);
+	pm_runtime_put_autosuspend(gi2c->dev);
+	gi2c->cur = NULL;
+	gi2c->err = 0;
+	dev_dbg(gi2c->dev, "i2c txn ret:%d\n", ret);
+	return ret;
+}

[..]

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+static int geni_i2c_probe(struct platform_device *pdev)
+{
+	struct geni_i2c_dev *gi2c;
+	struct resource *res;
+	int ret;

drivers/i2c/busses/i2c-qcom-geni.c line 453

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+
+	gi2c = devm_kzalloc(&pdev->dev, sizeof(*gi2c), GFP_KERNEL);
+	if (!gi2c)
+		return -ENOMEM;
+
+	gi2c->dev = &pdev->dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;

Put this right before devm_ioremap_resource() and drop the error check.

drivers/i2c/busses/i2c-qcom-geni.c line 456

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+	gi2c->wrapper_dev = pdev->dev.parent;
+	gi2c->i2c_rsc.wrapper_dev = pdev->dev.parent;

As suggested in the other patch, if you have an helper function in the wrapper driver that initializes the i2c_rsc then this could fill out the actual wrapper, instead of just the device.

drivers/i2c/busses/i2c-qcom-geni.c line 468

Quoted 12 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +12 -0
+	gi2c->i2c_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(gi2c->i2c_rsc.se_clk)) {
+		ret = PTR_ERR(gi2c->i2c_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		return ret;
+	}
+
+	gi2c->base = devm_ioremap_resource(gi2c->dev, res);
+	if (IS_ERR(gi2c->base))
+		return PTR_ERR(gi2c->base);
+
+	gi2c->i2c_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);

Drop all the pinctrl stuff. You might still want to call pinctrl_pm_select_{idle,default,sleep}_state(), in the various stages of PM state though.

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	if (IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified\n");
+		ret = PTR_ERR(gi2c->i2c_rsc.geni_pinctrl);
+		return ret;
+	}

[..]

drivers/i2c/busses/i2c-qcom-geni.c line 572

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+static int geni_i2c_runtime_resume(struct device *dev)
+{
+	int ret;
+	struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
+
+	ret = geni_se_resources_on(&gi2c->i2c_rsc);
+	if (ret)
+		return ret;
+
+	if (!unlikely(gi2c->tx_wm)) {

Drop the unlikely()

drivers/i2c/busses/i2c-qcom-geni.c line 576

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+		int proto = geni_se_get_proto(gi2c->base);
+		int gi2c_tx_depth = geni_se_get_tx_fifo_depth(gi2c->base);
+
+		if (unlikely(proto != I2C)) {

Has this changes since probe? Can't we verify that the proto is correct during probe and then just trust that the hardware doesn't change function?

Quoted 15 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +15 -0
+			dev_err(gi2c->dev, "Invalid proto %d\n", proto);
+			geni_se_resources_off(&gi2c->i2c_rsc);
+			return -ENXIO;
+		}
+
+		gi2c->tx_wm = gi2c_tx_depth - 1;
+		geni_se_init(gi2c->base, gi2c->tx_wm, gi2c_tx_depth);
+		geni_se_config_packing(gi2c->base, 8, 4, true);
+		dev_dbg(gi2c->dev, "i2c fifo/se-dma mode. fifo depth:%d\n",
+			gi2c_tx_depth);
+	}
+	enable_irq(gi2c->irq);
+
+	return 0;
+}

[..]

drivers/i2c/busses/i2c-qcom-geni.c line 656

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:i2c_geni");

What will reference the kernel module by this alias?

Quoted 8 lines
Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

--
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

#11 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Bjorn Andersson

[]..

Quoted 22 lines
Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

Quoted 4 lines

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

Looks like Mark Brown commented elsewhere [1] that we should use the C++ commenting style even for the Linux Foundation copyright?

[1] https://marc.info/?l=linux-clk&m=151497978626135&w=2

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#12 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

Quoted 29 lines · Rajendra Nayak

[]..

Quoted 22 lines
Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

Quoted 4 lines

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

Quoted 5 lines

Looks like Mark Brown commented elsewhere [1] that we should use the C++ commenting style even for the Linux Foundation copyright?

[1] https://marc.info/?l=linux-clk&m=151497978626135&w=2

While I can agree with Mark on the ugliness of the mixed commenting style, this is the style that I found communicated and is what you find in other files.

Regards,
Bjorn

#39 lore raw

Re: [PATCH v2 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian
Quoted 20 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
drivers/tty/serial/Kconfig +0 -0
index b788fee..1be30e5 100644

drivers/tty/serial/Kconfig config SERIAL_MSM_CONSOLE · line 1103

Quoted 6 lines
drivers/tty/serial/Kconfig +3 -0
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
 	select SERIAL_CORE_CONSOLE
 	select SERIAL_EARLYCON
 
+config SERIAL_QCOM_GENI
+	tristate "QCOM on-chip GENI based serial port support"
+	depends on ARCH_QCOM

depend on the GENI wrapper as well.

Quoted 30 lines
drivers/tty/serial/Kconfig +7 -0
+	select SERIAL_CORE
+	select SERIAL_CORE_CONSOLE
+	select SERIAL_EARLYCON
+	help
+	  Serial driver for Qualcomm Technologies Inc's GENI based QUP
+	  hardware.
+
 config SERIAL_VT8500
 	bool "VIA VT8500 on-chip serial port support"
 	depends on ARCH_VT8500
drivers/tty/serial/Makefile +1 -0
index 842d185..64a8d82 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_serial.o
 obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_MSM) += msm_serial.o
+obj-$(CONFIG_SERIAL_QCOM_GENI) += qcom_geni_serial.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
 obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
new file mode 100644
index 0000000..0dbd329
@@ -0,0 +1,1414 @@
+/*
+ * Copyright (c) 2017-2018, The Linux foundation. All rights reserved.

drivers/tty/serial/qcom_geni_serial.c line 12

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ */

SPDX license header.

drivers/tty/serial/qcom_geni_serial.c line 14

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+
+#include <linux/bitmap.h>

Unused

drivers/tty/serial/qcom_geni_serial.c line 15

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+#include <linux/bitops.h>

Unused?

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+#include <linux/delay.h>
+#include <linux/console.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>

drivers/tty/serial/qcom_geni_serial.c line 31

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/qcom-geni-se.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+
+/* UART specific GENI registers */
+#define SE_UART_TX_TRANS_CFG		(0x25C)

Drop the parenthesis

Quoted 55 lines
drivers/tty/serial/qcom_geni_serial.c new file +55 -0
+#define SE_UART_TX_WORD_LEN		(0x268)
+#define SE_UART_TX_STOP_BIT_LEN		(0x26C)
+#define SE_UART_TX_TRANS_LEN		(0x270)
+#define SE_UART_RX_TRANS_CFG		(0x280)
+#define SE_UART_RX_WORD_LEN		(0x28C)
+#define SE_UART_RX_STALE_CNT		(0x294)
+#define SE_UART_TX_PARITY_CFG		(0x2A4)
+#define SE_UART_RX_PARITY_CFG		(0x2A8)
+
+/* SE_UART_TRANS_CFG */
+#define UART_TX_PAR_EN		(BIT(0))
+#define UART_CTS_MASK		(BIT(1))
+
+/* SE_UART_TX_WORD_LEN */
+#define TX_WORD_LEN_MSK		(GENMASK(9, 0))
+
+/* SE_UART_TX_STOP_BIT_LEN */
+#define TX_STOP_BIT_LEN_MSK	(GENMASK(23, 0))
+#define TX_STOP_BIT_LEN_1	(0)
+#define TX_STOP_BIT_LEN_1_5	(1)
+#define TX_STOP_BIT_LEN_2	(2)
+
+/* SE_UART_TX_TRANS_LEN */
+#define TX_TRANS_LEN_MSK	(GENMASK(23, 0))
+
+/* SE_UART_RX_TRANS_CFG */
+#define UART_RX_INS_STATUS_BIT	(BIT(2))
+#define UART_RX_PAR_EN		(BIT(3))
+
+/* SE_UART_RX_WORD_LEN */
+#define RX_WORD_LEN_MASK	(GENMASK(9, 0))
+
+/* SE_UART_RX_STALE_CNT */
+#define RX_STALE_CNT		(GENMASK(23, 0))
+
+/* SE_UART_TX_PARITY_CFG/RX_PARITY_CFG */
+#define PAR_CALC_EN		(BIT(0))
+#define PAR_MODE_MSK		(GENMASK(2, 1))
+#define PAR_MODE_SHFT		(1)
+#define PAR_EVEN		(0x00)
+#define PAR_ODD			(0x01)
+#define PAR_SPACE		(0x10)
+#define PAR_MARK		(0x11)
+
+/* UART M_CMD OP codes */
+#define UART_START_TX		(0x1)
+#define UART_START_BREAK	(0x4)
+#define UART_STOP_BREAK		(0x5)
+/* UART S_CMD OP codes */
+#define UART_START_READ		(0x1)
+#define UART_PARAM		(0x1)
+
+#define UART_OVERSAMPLING	(32)
+#define STALE_TIMEOUT		(16)
+#define DEFAULT_BITS_PER_CHAR	(10)

drivers/tty/serial/qcom_geni_serial.c line 96

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+#define GENI_UART_NR_PORTS	(15)
+#define GENI_UART_CONS_PORTS	(1)
+#define DEF_FIFO_DEPTH_WORDS	(16)
+#define DEF_TX_WM		(2)
+#define DEF_FIFO_WIDTH_BITS	(32)
+#define UART_CORE2X_VOTE	(10000)
+#define UART_CONSOLE_RX_WM	(2)
+
+static int owr;
+module_param(owr, int, 0644);

What's this?

drivers/tty/serial/qcom_geni_serial.c line 101

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+
+struct qcom_geni_serial_port {
+	struct uart_port uport;
+	char name[20];
+	unsigned int tx_fifo_depth;

size_t is a good type for keeping track of sizes.

drivers/tty/serial/qcom_geni_serial.c line 106

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	unsigned int tx_fifo_width;
+	unsigned int rx_fifo_depth;
+	unsigned int tx_wm;
+	unsigned int rx_wm;
+	unsigned int rx_rfr;

size_t for sizes.

drivers/tty/serial/qcom_geni_serial.c line 109

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+	int xfer_mode;
+	bool port_setup;
+	unsigned int *rx_fifo;

The fifo is typeless, so it should be void *. It is however only ever used as a local variable in handle_rx_console() so drop this.

drivers/tty/serial/qcom_geni_serial.c line 117

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	int (*handle_rx)(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+	struct device *wrapper_dev;
+	struct geni_se_rsc serial_rsc;
+	unsigned int xmit_size;

size_t for sizes.

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	void *rx_buf;
+	unsigned int cur_baud;
+};
+
+static const struct uart_ops qcom_geni_serial_pops;
+static struct uart_driver qcom_geni_console_driver;
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,

drivers/tty/serial/qcom_geni_serial.c line 137

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+			bool drop_rx);
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port);
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set);
+static void qcom_geni_serial_stop_rx(struct uart_port *uport);
+
+static atomic_t uart_line_id = ATOMIC_INIT(0);
+
+#define GET_DEV_PORT(uport) \
+	container_of(uport, struct qcom_geni_serial_port, uport)

The idiomatic name for this macro would be something like "to_dev_port".

The use of "uport" as macro parameter makes this only work if the parameter is "uport", otherwise the macro will replace the last part of the container_of as well.

Quoted 20 lines
drivers/tty/serial/qcom_geni_serial.c new file +20 -0
+
+static struct qcom_geni_serial_port qcom_geni_console_port;
+
+static void qcom_geni_serial_config_port(struct uart_port *uport, int cfg_flags)
+{
+	if (cfg_flags & UART_CONFIG_TYPE)
+		uport->type = PORT_MSM;
+}
+
+static unsigned int qcom_geni_cons_get_mctrl(struct uart_port *uport)
+{
+	return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS;
+}
+
+static void qcom_geni_cons_set_mctrl(struct uart_port *uport,
+							unsigned int mctrl)
+{
+}
+
+static const char *qcom_geni_serial_get_type(struct uart_port *uport)

drivers/tty/serial/qcom_geni_serial.c line 167

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+{
+	return "MSM";
+}
+
+static struct qcom_geni_serial_port *get_port_from_line(int line)
+{
+	struct qcom_geni_serial_port *port = NULL;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		port = ERR_PTR(-ENXIO);

You need to return here as well...

drivers/tty/serial/qcom_geni_serial.c line 169

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	port = &qcom_geni_console_port;
+	return port;

Drop the "port" and just return ERR_PTR(-ENXIO) in the error case and return &qcom_geni_serial_port otherwise.

drivers/tty/serial/qcom_geni_serial.c line 173

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+}
+
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set)

This function is returning "yes" or "no", so make it return "bool"

drivers/tty/serial/qcom_geni_serial.c line 182

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+{
+	int iter = 0;
+	unsigned int reg;
+	bool met = false;
+	struct qcom_geni_serial_port *port = NULL;
+	bool cond = false;
+	unsigned int baud = 115200;
+	unsigned int fifo_bits = DEF_FIFO_DEPTH_WORDS * DEF_FIFO_WIDTH_BITS;
+	unsigned long total_iter = 2000;

Don't initialize things that will be assigned directly again.

Quoted 14 lines
drivers/tty/serial/qcom_geni_serial.c new file +14 -0
+
+
+	if (uport->private_data) {
+		port = GET_DEV_PORT(uport);
+		baud = (port->cur_baud ? port->cur_baud : 115200);
+		fifo_bits = port->tx_fifo_depth * port->tx_fifo_width;
+		/*
+		 * Total polling iterations based on FIFO worth of bytes to be
+		 * sent at current baud .Add a little fluff to the wait.
+		 */
+		total_iter = ((fifo_bits * USEC_PER_SEC) / baud) / 10;
+		total_iter += 50;
+	}
+

drivers/tty/serial/qcom_geni_serial.c line 206

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	while (iter < total_iter) {
+		reg = geni_read_reg_nolog(uport->membase, offset);
+		cond = reg & bit_field;
+		if (cond == set) {
+			met = true;
+			break;
+		}
+		udelay(10);
+		iter++;
+	}

Use readl_poll_timeout() instead of all this.

drivers/tty/serial/qcom_geni_serial.c line 213

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	return met;
+}
+
+static void qcom_geni_serial_setup_tx(struct uart_port *uport,
+				unsigned int xmit_size)
+{
+	u32 m_cmd = 0;

Don't initialize this.

drivers/tty/serial/qcom_geni_serial.c line 216

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+	geni_write_reg_nolog(xmit_size, uport->membase, SE_UART_TX_TRANS_LEN);
+	m_cmd |= (UART_START_TX << M_OPCODE_SHFT);

Why OR this into 0?

drivers/tty/serial/qcom_geni_serial.c line 225

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	geni_write_reg_nolog(m_cmd, uport->membase, SE_GENI_M_CMD0);
+	/*
+	 * Writes to enable the primary sequencer should go through before
+	 * exiting this function.
+	 */
+	mb();
+}
+
+static void qcom_geni_serial_poll_cancel_tx(struct uart_port *uport)

This function polls for command done and if that doesn't happen in time it aborts the command. It then clear any interrupts. The function name however indicates that we're polling for "cancel of tx".

drivers/tty/serial/qcom_geni_serial.c line 229

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+{
+	int done = 0;
+	unsigned int irq_clear = M_CMD_DONE_EN;
+	unsigned int geni_status = 0;

Don't initialize done and geni_status.

drivers/tty/serial/qcom_geni_serial.c line 236

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_DONE_EN, true);
+	if (!done) {
+		geni_write_reg_nolog(M_GENI_CMD_ABORT, uport->membase,
+					SE_GENI_M_CMD_CTRL_REG);
+		owr++;

What's owr?

Quoted 21 lines
drivers/tty/serial/qcom_geni_serial.c new file +21 -0
+		irq_clear |= M_CMD_ABORT_EN;
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+							M_CMD_ABORT_EN, true);
+	}
+	geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+	if (geni_status & M_GENI_CMD_ACTIVE)
+		owr++;
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_abort_rx(struct uart_port *uport)
+{
+	unsigned int irq_clear = S_CMD_DONE_EN;
+
+	geni_se_abort_s_cmd(uport->membase);
+	/* Ensure this goes through before polling. */
+	mb();
+	irq_clear |= S_CMD_ABORT_EN;
+	qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_ABORT, false);

drivers/tty/serial/qcom_geni_serial.c line 267

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(FORCE_DEFAULT, uport->membase, GENI_FORCE_DEFAULT_REG);
+}
+
+#ifdef CONFIG_CONSOLE_POLL
+static int qcom_geni_serial_get_char(struct uart_port *uport)
+{
+	unsigned int rx_fifo;
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;

These are u32 and the variable names would benefit from being shorter.

drivers/tty/serial/qcom_geni_serial.c line 270

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+			M_SEC_IRQ_EN, true)))

Drop one parenthesis.

drivers/tty/serial/qcom_geni_serial.c line 274

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+		return -ENXIO;
+
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);

Drop the _nolog and rename the variable to reduce the length of this line.

drivers/tty/serial/qcom_geni_serial.c line 280

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	geni_write_reg_nolog(m_irq_status, uport->membase,
+						SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase,
+						SE_GENI_S_IRQ_CLEAR);

Is it necessary to do this interlaced? Or can you just clear M and then clear S? I.e. have a single variable named "status".

drivers/tty/serial/qcom_geni_serial.c line 292

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_RX_FIFO_STATUS,
+			RX_FIFO_WC_MSK, true)))
+		return -ENXIO;
+
+	/*
+	 * Read the Rx FIFO only after clearing the interrupt registers and
+	 * getting valid RX fifo status.
+	 */
+	mb();
+	rx_fifo = geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+	rx_fifo &= 0xFF;

return rx_fifo & 0xff; instead of the extra step

drivers/tty/serial/qcom_geni_serial.c line 299

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	return rx_fifo;
+}
+
+static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
+					unsigned char c)
+{
+	int b = (int) c;

Why create this alias?

drivers/tty/serial/qcom_geni_serial.c line 307

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_write_reg_nolog(port->tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, 1);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+				M_TX_FIFO_WATERMARK_EN, true))
+		WARN_ON(1);
	WARN_ON(!qcom_geni_serial_poll_bit(...));

drivers/tty/serial/qcom_geni_serial.c line 313

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	geni_write_reg_nolog(b, uport->membase, SE_GENI_TX_FIFOn);
+	geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	/*
+	 * Ensure FIFO write goes through before polling for status but.
+	 */

/* This fits in a one-line comment */

But if this is necessary that means that every time you call serial_poll() you need to have this comment and a rmb(). Better move it into the poll function then - or just stop using _relaxed()

drivers/tty/serial/qcom_geni_serial.c line 325

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+	mb();
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
+static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
+{
+	geni_write_reg_nolog(ch, uport->membase, SE_GENI_TX_FIFOn);
+	/*
+	 * Ensure FIFO write clear goes through before
+	 * next iteration.

This comment is accurate, but unnecessarily line wrapped.

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	 */
+	mb();
+
+}
+
+static void
+__qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
+				unsigned int count)
+{

drivers/tty/serial/qcom_geni_serial.c line 344

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	int new_line = 0;
+	int i;
+	int bytes_to_send = count;
+	int fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	int tx_wm = DEF_TX_WM;
+
+	for (i = 0; i < count; i++) {
+		if (s[i] == '\n')
+			new_line++;
+	}

Why do we need to deal with this?

drivers/tty/serial/qcom_geni_serial.c line 353

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+
+	bytes_to_send += new_line;
+	geni_write_reg_nolog(tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, bytes_to_send);
+	i = 0;
+	while (i < count) {
+		u32 chars_to_write = 0;
+		u32 avail_fifo_bytes = (fifo_depth - tx_wm);

Use size_t for these.

drivers/tty/serial/qcom_geni_serial.c line 366

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -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 (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_TX_FIFO_WATERMARK_EN, true))
+			break;
+		chars_to_write = min((unsigned int)(count - i),
+							avail_fifo_bytes);
+		if ((chars_to_write << 1) > avail_fifo_bytes)

Write chars_to_write * 2, the compiler will be cleaver for you.

drivers/tty/serial/qcom_geni_serial.c line 373

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+			chars_to_write = (avail_fifo_bytes >> 1);
+		uart_console_write(uport, (s + i), chars_to_write,
+						qcom_geni_serial_wr_char);
+		geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+		/* Ensure this goes through before polling for WM IRQ again.*/
+		mb();

Again, if this is necessary move it into the poll function instead of sprinkling it throughout the driver.

drivers/tty/serial/qcom_geni_serial.c line 384

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+		i += chars_to_write;
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+
+static void qcom_geni_serial_console_write(struct console *co, const char *s,
+			      unsigned int count)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *port;
+	int locked = 1;

Use bool for booleans

drivers/tty/serial/qcom_geni_serial.c line 390

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	unsigned long flags;
+
+	WARN_ON(co->index < 0 || co->index >= GENI_UART_NR_PORTS);
+
+	port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(port))

port can't be NULL.

Quoted 21 lines
drivers/tty/serial/qcom_geni_serial.c new file +21 -0
+		return;
+
+	uport = &port->uport;
+	if (oops_in_progress)
+		locked = spin_trylock_irqsave(&uport->lock, flags);
+	else
+		spin_lock_irqsave(&uport->lock, flags);
+
+	if (locked) {
+		__qcom_geni_serial_console_write(uport, s, count);
+		spin_unlock_irqrestore(&uport->lock, flags);
+	}
+}
+
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx)
+{
+	int i, c;

drivers/tty/serial/qcom_geni_serial.c line 421

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	unsigned char *rx_char;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	for (i = 0; i < rx_fifo_wc; i++) {
+		int bytes = 4;
+
+		*(qcom_port->rx_fifo) =
+			geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);

Just store this value in a local variable, as the only consumer is 3 lines down.

drivers/tty/serial/qcom_geni_serial.c line 431

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		if (drop_rx)
+			continue;
+		rx_char = (unsigned char *)qcom_port->rx_fifo;
+
+		if (i == (rx_fifo_wc - 1)) {
+			if (rx_last && rx_last_byte_valid)
+				bytes = rx_last_byte_valid;
+		}
+		for (c = 0; c < bytes; c++) {
+			char flag = TTY_NORMAL;

No need for a local variable here.

Quoted 17 lines
drivers/tty/serial/qcom_geni_serial.c new file +17 -0
+			int sysrq;
+
+			uport->icount.rx++;
+			sysrq = uart_handle_sysrq_char(uport, rx_char[c]);
+			if (!sysrq)
+				tty_insert_flip_char(tport, rx_char[c], flag);
+		}
+	}
+	if (!drop_rx)
+		tty_flip_buffer_push(tport);
+	return 0;
+}
+#else
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,

drivers/tty/serial/qcom_geni_serial.c line 458

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+			bool drop_rx)
+{
+	return -EPERM;
+}
+
+#endif /* (CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)) */
+
+static void qcom_geni_serial_start_tx(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;

This is a u32, name it "irq_en"

drivers/tty/serial/qcom_geni_serial.c line 460

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned int geni_status;

geni_status should be of type u32 and there's no lack of descriptiveness naming it "status".

drivers/tty/serial/qcom_geni_serial.c line 466

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+
+	if (qcom_port->xfer_mode == FIFO_MODE) {
+		geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+		if (geni_status & M_GENI_CMD_ACTIVE)
+			goto exit_start_tx;

Just return

drivers/tty/serial/qcom_geni_serial.c line 469

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+		if (!qcom_geni_serial_tx_empty(uport))
+			goto exit_start_tx;

Ditto

drivers/tty/serial/qcom_geni_serial.c line 479

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+						    SE_GENI_M_IRQ_EN);
+		geni_m_irq_en |= (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN);
+
+		geni_write_reg_nolog(qcom_port->tx_wm, uport->membase,
+						SE_GENI_TX_WATERMARK_REG);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+		/* Geni command setup should complete before returning.*/

If that's the case then verify that it's actually done.

drivers/tty/serial/qcom_geni_serial.c line 489

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		mb();
+	}
+exit_start_tx:
+	return;
+}
+
+static void stop_tx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;

These are u32 and can be given more succinct names.

drivers/tty/serial/qcom_geni_serial.c line 492

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);

Drop the _nolog from all of these to make code easier to read.

Quoted 51 lines
drivers/tty/serial/qcom_geni_serial.c new file +51 -0
+	geni_m_irq_en &= ~M_CMD_DONE_EN;
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_m_irq_en &= ~M_TX_FIFO_WATERMARK_EN;
+		geni_write_reg_nolog(0, uport->membase,
+				     SE_GENI_TX_WATERMARK_REG);
+	}
+	port->xmit_size = 0;
+	geni_write_reg_nolog(geni_m_irq_en, uport->membase, SE_GENI_M_IRQ_EN);
+	geni_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_STATUS);
+	/* Possible stop tx is called multiple times. */
+	if (!(geni_status & M_GENI_CMD_ACTIVE))
+		return;
+
+	geni_se_cancel_m_cmd(uport->membase);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_CANCEL_EN, true)) {
+		geni_se_abort_m_cmd(uport->membase);
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_ABORT_EN, true);
+		geni_write_reg_nolog(M_CMD_ABORT_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	}
+	geni_write_reg_nolog(M_CMD_CANCEL_EN, uport, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_stop_tx(struct uart_port *uport)
+{
+	stop_tx_sequencer(uport);
+}
+
+static void start_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	if (geni_status & S_GENI_CMD_ACTIVE)
+		qcom_geni_serial_stop_rx(uport);
+
+	geni_se_setup_s_cmd(uport->membase, UART_START_READ, 0);
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+
+		geni_s_irq_en |= S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN;

drivers/tty/serial/qcom_geni_serial.c line 553

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		geni_m_irq_en |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+	/*
+	 * Ensure the writes to the secondary sequencer and interrupt enables
+	 * go through.

This is not what mb() does.

Quoted 44 lines
drivers/tty/serial/qcom_geni_serial.c new file +44 -0
+	 */
+	mb();
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+}
+
+static void qcom_geni_serial_start_rx(struct uart_port *uport)
+{
+	start_rx_sequencer(uport);
+}
+
+static void stop_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	u32 irq_clear = S_CMD_DONE_EN;
+	bool done;
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+		geni_s_irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);
+		geni_m_irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	/* Possible stop rx is called multiple times. */
+	if (!(geni_status & S_GENI_CMD_ACTIVE))
+		return;
+	geni_se_cancel_s_cmd(uport->membase);
+	/*
+	 * Ensure that the cancel goes through before polling for the
+	 * cancel control bit.
+	 */
+	mb();
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,

drivers/tty/serial/qcom_geni_serial.c line 607

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+					S_GENI_CMD_CANCEL, false);
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	if ((geni_status & S_GENI_CMD_ACTIVE))
+		qcom_geni_serial_abort_rx(uport);
+}
+
+static void qcom_geni_serial_stop_rx(struct uart_port *uport)
+{
+	stop_rx_sequencer(uport);

Just inline the function here.

drivers/tty/serial/qcom_geni_serial.c line 616

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+}
+
+static int qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop_rx)
+{
+	int ret = 0;
+	unsigned int rx_fifo_status;
+	unsigned int rx_fifo_wc = 0;
+	unsigned int rx_last_byte_valid = 0;
+	unsigned int rx_last = 0;

The context of this function gives that we're dealing with rx and rx_fifo, so no need to specify that in each local variable.

Also, they should all be u32 and there's no need to initialize them.

drivers/tty/serial/qcom_geni_serial.c line 629

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	rx_fifo_status = geni_read_reg_nolog(uport->membase,
+				SE_GENI_RX_FIFO_STATUS);
+	rx_fifo_wc = rx_fifo_status & RX_FIFO_WC_MSK;
+	rx_last_byte_valid = ((rx_fifo_status & RX_LAST_BYTE_VALID_MSK) >>
+						RX_LAST_BYTE_VALID_SHFT);
+	rx_last = rx_fifo_status & RX_LAST;
+	if (rx_fifo_wc)
+		port->handle_rx(uport, rx_fifo_wc, rx_last_byte_valid,
+							rx_last, drop_rx);

You're ignoring the return value of handle_rx.

drivers/tty/serial/qcom_geni_serial.c line 630

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	return ret;

You don't care about the return value in the caller and you always return 0 anyways, so make the function void.

drivers/tty/serial/qcom_geni_serial.c line 638

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+}
+
+static int qcom_geni_serial_handle_tx(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	struct circ_buf *xmit = &uport->state->xmit;
+	unsigned int avail_fifo_bytes = 0;

Naming avail_fifo_bytes just "avail" is carrying the same information but is shorter.

drivers/tty/serial/qcom_geni_serial.c line 643

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	unsigned int bytes_remaining = 0;
+	int i = 0;
+	unsigned int tx_fifo_status;
+	unsigned int xmit_size;
+	unsigned int fifo_width_bytes = 1;

If this really is constantly 1 you can remove the variable and remove a bit of the complexity in this function.

drivers/tty/serial/qcom_geni_serial.c line 644

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	int temp_tail = 0;

Use size_t for sizes.

drivers/tty/serial/qcom_geni_serial.c line 650

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+
+	xmit_size = uart_circ_chars_pending(xmit);
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+					SE_GENI_TX_FIFO_STATUS);
+	/* Both FIFO and framework buffer are drained */
+	if ((xmit_size == qcom_port->xmit_size) && !tx_fifo_status) {

Drop the parenthesis.

Quoted 21 lines
drivers/tty/serial/qcom_geni_serial.c new file +18 -0
+		qcom_port->xmit_size = 0;
+		uart_circ_clear(xmit);
+		qcom_geni_serial_stop_tx(uport);
+		goto exit_handle_tx;
+	}
+	xmit_size -= qcom_port->xmit_size;
+
+	avail_fifo_bytes = (qcom_port->tx_fifo_depth - qcom_port->tx_wm) *
+							fifo_width_bytes;
+	temp_tail = (xmit->tail + qcom_port->xmit_size) & (UART_XMIT_SIZE - 1);
+	if (xmit_size > (UART_XMIT_SIZE - temp_tail))
+		xmit_size = (UART_XMIT_SIZE - temp_tail);
+	if (xmit_size > avail_fifo_bytes)
+		xmit_size = avail_fifo_bytes;
 
 
 
+
+	if (!xmit_size)
+		goto exit_handle_tx;
+

drivers/tty/serial/qcom_geni_serial.c line 678

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	qcom_geni_serial_setup_tx(uport, xmit_size);
+
+	bytes_remaining = xmit_size;
+	while (i < xmit_size) {
+		unsigned int tx_bytes;
+		unsigned int buf = 0;
+		int c;
+
+		tx_bytes = ((bytes_remaining < fifo_width_bytes) ?
+					bytes_remaining : fifo_width_bytes);
		tx_bytes = min(remaining, fifo_width);
Quoted 176 lines
drivers/tty/serial/qcom_geni_serial.c new file +176 -0
+
+		for (c = 0; c < tx_bytes ; c++)
+			buf |= (xmit->buf[temp_tail + c] << (c * 8));
+		geni_write_reg_nolog(buf, uport->membase, SE_GENI_TX_FIFOn);
+		i += tx_bytes;
+		temp_tail = (temp_tail + tx_bytes) & (UART_XMIT_SIZE - 1);
+		uport->icount.tx += tx_bytes;
+		bytes_remaining -= tx_bytes;
+		/* Ensure FIFO write goes through */
+		wmb();
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+	qcom_port->xmit_size += xmit_size;
+exit_handle_tx:
+	uart_write_wakeup(uport);
+	return ret;
+}
+
+static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
+{
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;
+	struct uart_port *uport = dev;
+	unsigned long flags;
+	unsigned int m_irq_en;
+	bool drop_rx = false;
+	struct tty_port *tport = &uport->state->port;
+
+	spin_lock_irqsave(&uport->lock, flags);
+	if (uport->suspended)
+		goto exit_geni_serial_isr;
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_write_reg_nolog(m_irq_status, uport->membase, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase, SE_GENI_S_IRQ_CLEAR);
+
+	if ((m_irq_status & M_ILLEGAL_CMD_EN)) {
+		WARN_ON(1);
+		goto exit_geni_serial_isr;
+	}
+
+	if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
+		uport->icount.overrun++;
+		tty_insert_flip_char(tport, 0, TTY_OVERRUN);
+	}
+
+	if ((m_irq_status & m_irq_en) &
+	    (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN))
+		qcom_geni_serial_handle_tx(uport);
+
+	if ((s_irq_status & S_GP_IRQ_0_EN) || (s_irq_status & S_GP_IRQ_1_EN)) {
+		if (s_irq_status & S_GP_IRQ_0_EN)
+			uport->icount.parity++;
+		drop_rx = true;
+	} else if ((s_irq_status & S_GP_IRQ_2_EN) ||
+		(s_irq_status & S_GP_IRQ_3_EN)) {
+		uport->icount.brk++;
+	}
+
+	if ((s_irq_status & S_RX_FIFO_WATERMARK_EN) ||
+		(s_irq_status & S_RX_FIFO_LAST_EN))
+		qcom_geni_serial_handle_rx(uport, drop_rx);
+
+exit_geni_serial_isr:
+	spin_unlock_irqrestore(&uport->lock, flags);
+	return IRQ_HANDLED;
+}
+
+static int get_tx_fifo_size(struct qcom_geni_serial_port *port)
+{
+	struct uart_port *uport;
+
+	if (!port)
+		return -ENODEV;
+
+	uport = &port->uport;
+	port->tx_fifo_depth = geni_se_get_tx_fifo_depth(uport->membase);
+	if (!port->tx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->tx_fifo_width = geni_se_get_tx_fifo_width(uport->membase);
+	if (!port->tx_fifo_width) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO width read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->rx_fifo_depth = geni_se_get_rx_fifo_depth(uport->membase);
+	if (!port->rx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid RX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	uport->fifosize =
+		((port->tx_fifo_depth * port->tx_fifo_width) >> 3);
+	return 0;
+}
+
+static void set_rfr_wm(struct qcom_geni_serial_port *port)
+{
+	/*
+	 * Set RFR (Flow off) to FIFO_DEPTH - 2.
+	 * RX WM level at 10% RX_FIFO_DEPTH.
+	 * TX WM level at 10% TX_FIFO_DEPTH.
+	 */
+	port->rx_rfr = port->rx_fifo_depth - 2;
+	port->rx_wm = UART_CONSOLE_RX_WM;
+	port->tx_wm = 2;
+}
+
+static void qcom_geni_serial_shutdown(struct uart_port *uport)
+{
+	unsigned long flags;
+
+	/* Stop the console before stopping the current tx */
+	console_stop(uport->cons);
+
+	disable_irq(uport->irq);
+	free_irq(uport->irq, uport);
+	spin_lock_irqsave(&uport->lock, flags);
+	qcom_geni_serial_stop_tx(uport);
+	qcom_geni_serial_stop_rx(uport);
+	spin_unlock_irqrestore(&uport->lock, flags);
+}
+
+static int qcom_geni_serial_port_setup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned long cfg0, cfg1;
+	unsigned int rxstale = DEFAULT_BITS_PER_CHAR * STALE_TIMEOUT;
+
+	set_rfr_wm(qcom_port);
+	geni_write_reg_nolog(rxstale, uport->membase, SE_UART_RX_STALE_CNT);
+	/*
+	 * Make an unconditional cancel on the main sequencer to reset
+	 * it else we could end up in data loss scenarios.
+	 */
+	qcom_port->xfer_mode = FIFO_MODE;
+	qcom_geni_serial_poll_cancel_tx(uport);
+	geni_se_get_packing_config(8, 1, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_TX_PACKING_CFG1);
+	geni_se_get_packing_config(8, 4, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_RX_PACKING_CFG1);
+	ret = geni_se_init(uport->membase, qcom_port->rx_wm, qcom_port->rx_rfr);
+	if (ret) {
+		dev_err(uport->dev, "%s: Fail\n", __func__);
+		goto exit_portsetup;
+	}
+
+	ret = geni_se_select_mode(uport->membase, qcom_port->xfer_mode);
+	if (ret)
+		goto exit_portsetup;
+
+	qcom_port->port_setup = true;
+	/*
+	 * Ensure Port setup related IO completes before returning to
+	 * framework.
+	 */
+	mb();
+exit_portsetup:
+	return ret;
+}

drivers/tty/serial/qcom_geni_serial.c line 864

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+static int qcom_geni_serial_startup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	scnprintf(qcom_port->name, sizeof(qcom_port->name),
+		  "qcom_serial_geni%d",	uport->line);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {

Drop the unlikely(), in favour of readable code.

drivers/tty/serial/qcom_geni_serial.c line 866

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+		dev_err(uport->dev, "%s: Invalid FW %d loaded.\n",
+				 __func__, geni_se_get_proto(uport->membase));

Drop the __func__, the message should describe the issue in itself.

drivers/tty/serial/qcom_geni_serial.c

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+		ret = -ENXIO;
+		goto exit_startup;

We haven't done anything, so just return here.

drivers/tty/serial/qcom_geni_serial.c line 879

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+	}
+
+	get_tx_fifo_size(qcom_port);
+	if (!qcom_port->port_setup) {
+		if (qcom_geni_serial_port_setup(uport))
+			goto exit_startup;
+	}
+
+	/*
+	 * Ensure that all the port configuration writes complete
+	 * before returning to the framework.

That's not what mb() does.

drivers/tty/serial/qcom_geni_serial.c line 886

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	 */
+	mb();
+	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
+			qcom_port->name, uport);
+	if (unlikely(ret)) {
+		dev_err(uport->dev, "%s: Failed to get IRQ ret %d\n",
+							__func__, ret);

Drop the __func__

Quoted 86 lines
drivers/tty/serial/qcom_geni_serial.c new file +86 -0
+		goto exit_startup;
+	}
+
+exit_startup:
+	return ret;
+}
+
+static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
+{
+	unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
+		32000000, 48000000, 64000000, 80000000, 96000000, 100000000};
+	int i;
+	int match = -1;
+
+	for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
+		if (clk_freq > root_freq[i])
+			continue;
+
+		if (!(root_freq[i] % clk_freq)) {
+			match = i;
+			break;
+		}
+	}
+	if (match != -1)
+		*ser_clk = root_freq[match];
+	else
+		pr_err("clk_freq %ld\n", clk_freq);
+	return match;
+}
+
+static void geni_serial_write_term_regs(struct uart_port *uport,
+		u32 tx_trans_cfg, u32 tx_parity_cfg, u32 rx_trans_cfg,
+		u32 rx_parity_cfg, u32 bits_per_char, u32 stop_bit_len,
+		u32 s_clk_cfg)
+{
+	geni_write_reg_nolog(tx_trans_cfg, uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	geni_write_reg_nolog(tx_parity_cfg, uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	geni_write_reg_nolog(rx_trans_cfg, uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	geni_write_reg_nolog(rx_parity_cfg, uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_TX_WORD_LEN);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_RX_WORD_LEN);
+	geni_write_reg_nolog(stop_bit_len, uport->membase,
+						SE_UART_TX_STOP_BIT_LEN);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_M_CLK_CFG);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_S_CLK_CFG);
+}
+
+static int get_clk_div_rate(unsigned int baud, unsigned long *desired_clk_rate)
+{
+	unsigned long ser_clk;
+	int dfs_index;
+	int clk_div = 0;
+
+	*desired_clk_rate = baud * UART_OVERSAMPLING;
+	dfs_index = get_clk_cfg(*desired_clk_rate, &ser_clk);
+	if (dfs_index < 0) {
+		pr_err("%s: Can't find matching DFS entry for baud %d\n",
+								__func__, baud);
+		clk_div = -EINVAL;
+		goto exit_get_clk_div_rate;
+	}
+
+	clk_div = ser_clk / *desired_clk_rate;
+	*desired_clk_rate = ser_clk;
+exit_get_clk_div_rate:
+	return clk_div;
+}
+
+static void qcom_geni_serial_set_termios(struct uart_port *uport,
+				struct ktermios *termios, struct ktermios *old)
+{
+	unsigned int baud;
+	unsigned int bits_per_char = 0;
+	unsigned int tx_trans_cfg;
+	unsigned int tx_parity_cfg;
+	unsigned int rx_trans_cfg;
+	unsigned int rx_parity_cfg;
+	unsigned int stop_bit_len;
+	unsigned int clk_div;
+	unsigned long ser_clk_cfg = 0;

drivers/tty/serial/qcom_geni_serial.c line 982

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	unsigned long clk_rate;
+
+	qcom_geni_serial_stop_rx(uport);
+	/* baud rate */
+	baud = uart_get_baud_rate(uport, termios, old, 300, 4000000);
+	port->cur_baud = baud;
+	clk_div = get_clk_div_rate(baud, &clk_rate);
+	if (clk_div <= 0)
+		goto exit_set_termios;

Name your labels based on their actions; if you name it "out_restart_rx" you don't even have to look below to know what will happen when you jump.

drivers/tty/serial/qcom_geni_serial.c line 990

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+
+	uport->uartclk = clk_rate;
+	clk_set_rate(port->serial_rsc.se_clk, clk_rate);
+	ser_clk_cfg |= SER_CLK_EN;
+	ser_clk_cfg |= (clk_div << CLK_DIV_SHFT);
+
+	/* parity */
+	tx_trans_cfg = geni_read_reg_nolog(uport->membase,

Drop the _nolog and you don't need to line wrap

Quoted 67 lines
drivers/tty/serial/qcom_geni_serial.c new file +67 -0
+							SE_UART_TX_TRANS_CFG);
+	tx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	rx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	rx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	if (termios->c_cflag & PARENB) {
+		tx_trans_cfg |= UART_TX_PAR_EN;
+		rx_trans_cfg |= UART_RX_PAR_EN;
+		tx_parity_cfg |= PAR_CALC_EN;
+		rx_parity_cfg |= PAR_CALC_EN;
+		if (termios->c_cflag & PARODD) {
+			tx_parity_cfg |= PAR_ODD;
+			rx_parity_cfg |= PAR_ODD;
+		} else if (termios->c_cflag & CMSPAR) {
+			tx_parity_cfg |= PAR_SPACE;
+			rx_parity_cfg |= PAR_SPACE;
+		} else {
+			tx_parity_cfg |= PAR_EVEN;
+			rx_parity_cfg |= PAR_EVEN;
+		}
+	} else {
+		tx_trans_cfg &= ~UART_TX_PAR_EN;
+		rx_trans_cfg &= ~UART_RX_PAR_EN;
+		tx_parity_cfg &= ~PAR_CALC_EN;
+		rx_parity_cfg &= ~PAR_CALC_EN;
+	}
+
+	/* bits per char */
+	switch (termios->c_cflag & CSIZE) {
+	case CS5:
+		bits_per_char = 5;
+		break;
+	case CS6:
+		bits_per_char = 6;
+		break;
+	case CS7:
+		bits_per_char = 7;
+		break;
+	case CS8:
+	default:
+		bits_per_char = 8;
+		break;
+	}
+
+	/* stop bits */
+	if (termios->c_cflag & CSTOPB)
+		stop_bit_len = TX_STOP_BIT_LEN_2;
+	else
+		stop_bit_len = TX_STOP_BIT_LEN_1;
+
+	/* flow control, clear the CTS_MASK bit if using flow control. */
+	if (termios->c_cflag & CRTSCTS)
+		tx_trans_cfg &= ~UART_CTS_MASK;
+	else
+		tx_trans_cfg |= UART_CTS_MASK;
+
+	if (likely(baud))
+		uart_update_timeout(uport, termios->c_cflag, baud);
+
+	geni_serial_write_term_regs(uport, tx_trans_cfg, tx_parity_cfg,
+		rx_trans_cfg, rx_parity_cfg, bits_per_char, stop_bit_len,
+								ser_clk_cfg);
+exit_set_termios:
+	qcom_geni_serial_start_rx(uport);
+	return;

drivers/tty/serial/qcom_geni_serial.c line 1067

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+}
+
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
+{
+	unsigned int tx_fifo_status;
+	unsigned int is_tx_empty = 1;
+
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_TX_FIFO_STATUS);

Drop the "_nolog" and naming the result "status" would be just as expressive, but keep you below 80 chars.

drivers/tty/serial/qcom_geni_serial.c line 1071

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	if (tx_fifo_status)
+		is_tx_empty = 0;
+
+	return is_tx_empty;

Instead of what you're doing with is_tx_empty, just do:

	return !readl(membase + FIFO_STATUS);

drivers/tty/serial/qcom_geni_serial.c line 1083

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+}
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
+static int __init qcom_geni_console_setup(struct console *co, char *options)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *dev_port;
+	int baud = 115200;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+	int ret = 0;

Drop initialization of all these variables.

drivers/tty/serial/qcom_geni_serial.c line 1085

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+
+	if (unlikely(co->index >= GENI_UART_NR_PORTS  || co->index < 0))

Drop the unlikely.

Quoted 97 lines
drivers/tty/serial/qcom_geni_serial.c new file +97 -0
+		return -ENXIO;
+
+	dev_port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		pr_err("Invalid line %d(%d)\n", co->index, ret);
+		return ret;
+	}
+
+	uport = &dev_port->uport;
+
+	if (unlikely(!uport->membase))
+		return -ENXIO;
+
+	if (geni_se_resources_on(&dev_port->serial_rsc))
+		WARN_ON(1);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		geni_se_resources_off(&dev_port->serial_rsc);
+		return -ENXIO;
+	}
+
+	if (!dev_port->port_setup) {
+		qcom_geni_serial_stop_rx(uport);
+		qcom_geni_serial_port_setup(uport);
+	}
+
+	if (options)
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+	return uart_set_options(uport, co, baud, parity, bits, flow);
+}
+
+static int console_register(struct uart_driver *drv)
+{
+	return uart_register_driver(drv);
+}
+static void console_unregister(struct uart_driver *drv)
+{
+	uart_unregister_driver(drv);
+}
+
+static struct console cons_ops = {
+	.name = "ttyMSM",
+	.write = qcom_geni_serial_console_write,
+	.device = uart_console_device,
+	.setup = qcom_geni_console_setup,
+	.flags = CON_PRINTBUFFER,
+	.index = -1,
+	.data = &qcom_geni_console_driver,
+};
+
+static struct uart_driver qcom_geni_console_driver = {
+	.owner = THIS_MODULE,
+	.driver_name = "qcom_geni_console",
+	.dev_name = "ttyMSM",
+	.nr =  GENI_UART_NR_PORTS,
+	.cons = &cons_ops,
+};
+#else
+static int console_register(struct uart_driver *drv)
+{
+	return 0;
+}
+
+static void console_unregister(struct uart_driver *drv)
+{
+}
+#endif /* defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) */
+
+static void qcom_geni_serial_cons_pm(struct uart_port *uport,
+		unsigned int new_state, unsigned int old_state)
+{
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	if (unlikely(!uart_console(uport)))
+		return;
+
+	if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
+		geni_se_resources_on(&qcom_port->serial_rsc);
+	else if (new_state == UART_PM_STATE_OFF &&
+			old_state == UART_PM_STATE_ON)
+		geni_se_resources_off(&qcom_port->serial_rsc);
+}
+
+static const struct uart_ops qcom_geni_console_pops = {
+	.tx_empty = qcom_geni_serial_tx_empty,
+	.stop_tx = qcom_geni_serial_stop_tx,
+	.start_tx = qcom_geni_serial_start_tx,
+	.stop_rx = qcom_geni_serial_stop_rx,
+	.set_termios = qcom_geni_serial_set_termios,
+	.startup = qcom_geni_serial_startup,
+	.config_port = qcom_geni_serial_config_port,
+	.shutdown = qcom_geni_serial_shutdown,
+	.type = qcom_geni_serial_get_type,
+	.set_mctrl = qcom_geni_cons_set_mctrl,
+	.get_mctrl = qcom_geni_cons_get_mctrl,

drivers/tty/serial/qcom_geni_serial.c line 1192

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+#ifdef CONFIG_CONSOLE_POLL
+	.poll_get_char	= qcom_geni_serial_get_char,
+	.poll_put_char	= qcom_geni_serial_poll_put_char,
+#endif
+	.pm = qcom_geni_serial_cons_pm,
+};
+
+static const struct of_device_id qcom_geni_serial_match_table[] = {
+	{ .compatible = "qcom,geni-debug-uart",
+			.data = (void *)&qcom_geni_console_driver},

Shouldn't need this typecast.

drivers/tty/serial/qcom_geni_serial.c line 1205

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+};
+
+static int qcom_geni_serial_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	int line = -1;
+	struct qcom_geni_serial_port *dev_port;
+	struct uart_port *uport;
+	struct resource *res;
+	struct uart_driver *drv;
+	const struct of_device_id *id;
+
+	id = of_match_device(qcom_geni_serial_match_table, &pdev->dev);

Use of_device_get_match_data()

Quoted 37 lines
drivers/tty/serial/qcom_geni_serial.c new file +37 -0
+	if (id) {
+		dev_dbg(&pdev->dev, "%s: %s\n", __func__, id->compatible);
+		drv = (struct uart_driver *)id->data;
+	} else {
+		dev_err(&pdev->dev, "%s: No matching device found", __func__);
+		return -ENODEV;
+	}
+
+	if (pdev->dev.of_node) {
+		if (drv->cons)
+			line = of_alias_get_id(pdev->dev.of_node, "serial");
+	} else {
+		line = pdev->id;
+	}
+
+	if (line < 0)
+		line = atomic_inc_return(&uart_line_id) - 1;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		return -ENXIO;
+	dev_port = get_port_from_line(line);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		dev_err(&pdev->dev, "Invalid line %d(%d)\n",
+					line, ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport = &dev_port->uport;
+
+	/* Don't allow 2 drivers to access the same port */
+	if (uport->private_data) {
+		ret = -ENODEV;
+		goto exit_geni_serial_probe;
+	}
+
+	uport->dev = &pdev->dev;

drivers/tty/serial/qcom_geni_serial.c line 1252

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	dev_port->wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(dev_port->serial_rsc.se_clk)) {
+		ret = PTR_ERR(dev_port->serial_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "se-phys");

Don't grab this by name, just pick the first one.

drivers/tty/serial/qcom_geni_serial.c line 1257

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	if (!res) {
+		ret = -ENXIO;
+		dev_err(&pdev->dev, "Err getting IO region\n");
+		goto exit_geni_serial_probe;
+	}

Drop the error handling here.

drivers/tty/serial/qcom_geni_serial.c line 1259

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	uport->mapbase = res->start;

No

drivers/tty/serial/qcom_geni_serial.c line 1268

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	uport->membase = devm_ioremap(&pdev->dev, res->start,
+						resource_size(res));
+	if (!uport->membase) {
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "Err IO mapping serial iomem");
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);

Drop all of the pinctrl stuff.

Quoted 29 lines
drivers/tty/serial/qcom_geni_serial.c new file +29 -0
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_pinctrl);
+		goto exit_geni_serial_probe;
+	}
+	dev_port->serial_rsc.geni_gpio_active =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_DEFAULT);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_active)) {
+		dev_err(&pdev->dev, "No default config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_active);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_gpio_sleep =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_SLEEP);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_sleep)) {
+		dev_err(&pdev->dev, "No sleep config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_sleep);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->tx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
+	uport->fifosize =
+		((dev_port->tx_fifo_depth * dev_port->tx_fifo_width) >> 3);
+

drivers/tty/serial/qcom_geni_serial.c line 1307

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	uport->irq = platform_get_irq(pdev, 0);
+	if (uport->irq < 0) {
+		ret = uport->irq;
+		dev_err(&pdev->dev, "Failed to get IRQ %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport->private_data = (void *)drv;
+	platform_set_drvdata(pdev, dev_port);
+	dev_port->handle_rx = handle_rx_console;

Why have a function pointer when you're only referencing a fixed function.

drivers/tty/serial/qcom_geni_serial.c line 1309

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	dev_port->rx_fifo = devm_kzalloc(uport->dev, sizeof(u32),
+								GFP_KERNEL);

It takes 8 bytes to store a pointer and the allocation will have some overhead...just to provide storage space for 4 bytes. And you don't have any error handling...

Quoted 113 lines
drivers/tty/serial/qcom_geni_serial.c new file +105 -0
+	dev_port->port_setup = false;
+	return uart_add_one_port(drv, uport);
+
+exit_geni_serial_probe:
+	return ret;
+}
+
+static int qcom_geni_serial_remove(struct platform_device *pdev)
+{
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_driver *drv =
+			(struct uart_driver *)port->uport.private_data;
+
+	uart_remove_one_port(drv, &port->uport);
+	return 0;
+}
+
+
+#ifdef CONFIG_PM
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	uart_suspend_port((struct uart_driver *)uport->private_data,
+				uport);
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	if (console_suspend_enabled && uport->suspended) {
+		uart_resume_port((struct uart_driver *)uport->private_data,
+									uport);
+		disable_irq(uport->irq);
+	}
+	return 0;
+}
+#else
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
+	.suspend_noirq = qcom_geni_serial_sys_suspend_noirq,
+	.resume_noirq = qcom_geni_serial_sys_resume_noirq,
+};
+
+static struct platform_driver qcom_geni_serial_platform_driver = {
+	.remove = qcom_geni_serial_remove,
+	.probe = qcom_geni_serial_probe,
+	.driver = {
+		.name = "qcom_geni_serial",
+		.of_match_table = qcom_geni_serial_match_table,
+		.pm = &qcom_geni_serial_pm_ops,
+	},
+};
+
+static int __init qcom_geni_serial_init(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < GENI_UART_CONS_PORTS; i++) {
+		qcom_geni_console_port.uport.iotype = UPIO_MEM;
+		qcom_geni_console_port.uport.ops = &qcom_geni_console_pops;
+		qcom_geni_console_port.uport.flags = UPF_BOOT_AUTOCONF;
+		qcom_geni_console_port.uport.line = i;
+	}
+
+	ret = console_register(&qcom_geni_console_driver);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&qcom_geni_serial_platform_driver);
+	if (ret) {
+		console_unregister(&qcom_geni_console_driver);
+		return ret;
+	}
+	return ret;
+}
+module_init(qcom_geni_serial_init);
+
+static void __exit qcom_geni_serial_exit(void)
+{
+	platform_driver_unregister(&qcom_geni_serial_platform_driver);
+	console_unregister(&qcom_geni_console_driver);
+}
+module_exit(qcom_geni_serial_exit);
+
+MODULE_DESCRIPTION("Serial driver for GENI based QUP cores");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("tty:qcom_geni_serial");
Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

Re: [PATCH v2 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian
Quoted 8 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

Please disregard my previous answer to this patch, I hit the wrong key combo while stashing my reply.

Quoted 12 lines
---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
drivers/tty/serial/Kconfig +0 -0
index b788fee..1be30e5 100644

drivers/tty/serial/Kconfig config SERIAL_MSM_CONSOLE · line 1103

Quoted 6 lines
drivers/tty/serial/Kconfig +3 -0
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
 	select SERIAL_CORE_CONSOLE
 	select SERIAL_EARLYCON
 
+config SERIAL_QCOM_GENI
+	tristate "QCOM on-chip GENI based serial port support"
+	depends on ARCH_QCOM

depend on the GENI wrapper as well.

[..]

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
new file mode 100644
index 0000000..0dbd329
@@ -0,0 +1,1414 @@
+/*
+ * Copyright (c) 2017-2018, The Linux foundation. All rights reserved.

drivers/tty/serial/qcom_geni_serial.c line 12

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ */

SPDX license header.

drivers/tty/serial/qcom_geni_serial.c line 14

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+
+#include <linux/bitmap.h>

Unused

drivers/tty/serial/qcom_geni_serial.c line 15

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+#include <linux/bitops.h>

Unused?

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+#include <linux/delay.h>
+#include <linux/console.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>

drivers/tty/serial/qcom_geni_serial.c line 31

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/qcom-geni-se.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+
+/* UART specific GENI registers */
+#define SE_UART_TX_TRANS_CFG		(0x25C)

Drop the parenthesis

[..]

drivers/tty/serial/qcom_geni_serial.c line 96

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+static int owr;
+module_param(owr, int, 0644);

What's this?

drivers/tty/serial/qcom_geni_serial.c line 101

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+
+struct qcom_geni_serial_port {
+	struct uart_port uport;
+	char name[20];
+	unsigned int tx_fifo_depth;

size_t is a good type for keeping track of sizes.

drivers/tty/serial/qcom_geni_serial.c line 106

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	unsigned int tx_fifo_width;
+	unsigned int rx_fifo_depth;
+	unsigned int tx_wm;
+	unsigned int rx_wm;
+	unsigned int rx_rfr;

size_t for sizes.

drivers/tty/serial/qcom_geni_serial.c line 109

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+	int xfer_mode;
+	bool port_setup;
+	unsigned int *rx_fifo;

The fifo is typeless, so it should be void *. It is however only ever used as a local variable in handle_rx_console() so drop this.

drivers/tty/serial/qcom_geni_serial.c line 117

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	int (*handle_rx)(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+	struct device *wrapper_dev;
+	struct geni_se_rsc serial_rsc;
+	unsigned int xmit_size;

In other drivers we read bytes of the xmit buffer at xmit->tail, write to hardware FIFO and update xmit->tail. Why do you keep a going delta between the tail and our real tail?

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	void *rx_buf;
+	unsigned int cur_baud;
+};
+

[..]

drivers/tty/serial/qcom_geni_serial.c line 137

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+#define GET_DEV_PORT(uport) \
+	container_of(uport, struct qcom_geni_serial_port, uport)

The idiomatic name for this macro would be something like "to_dev_port".

The use of "uport" as macro parameter makes this only work if the parameter is "uport", otherwise the macro will replace the last part of the container_of as well.

[..]

drivers/tty/serial/qcom_geni_serial.c line 167

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+static struct qcom_geni_serial_port *get_port_from_line(int line)
+{
+	struct qcom_geni_serial_port *port = NULL;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		port = ERR_PTR(-ENXIO);

You need to return here as well...

drivers/tty/serial/qcom_geni_serial.c line 169

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	port = &qcom_geni_console_port;
+	return port;

Drop the "port" and just return ERR_PTR(-ENXIO) in the error case and return &qcom_geni_serial_port otherwise.

drivers/tty/serial/qcom_geni_serial.c line 173

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+}
+
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set)

This function is returning "yes" or "no", so make it return "bool"

drivers/tty/serial/qcom_geni_serial.c line 182

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+{
+	int iter = 0;
+	unsigned int reg;
+	bool met = false;
+	struct qcom_geni_serial_port *port = NULL;
+	bool cond = false;
+	unsigned int baud = 115200;
+	unsigned int fifo_bits = DEF_FIFO_DEPTH_WORDS * DEF_FIFO_WIDTH_BITS;
+	unsigned long total_iter = 2000;

Don't initialize things that will be assigned directly again.

drivers/tty/serial/qcom_geni_serial.c line 185

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+
+	if (uport->private_data) {

When is this function being called on a non-initialized uport?

drivers/tty/serial/qcom_geni_serial.c line 187

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+		port = GET_DEV_PORT(uport);
+		baud = (port->cur_baud ? port->cur_baud : 115200);

Drop the parenthesis, and consider initializing baud = port->cur_baud and then give it 115200 if it's zero separately.

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+		fifo_bits = port->tx_fifo_depth * port->tx_fifo_width;
+		/*
+		 * Total polling iterations based on FIFO worth of bytes to be
+		 * sent at current baud .Add a little fluff to the wait.
+		 */
+		total_iter = ((fifo_bits * USEC_PER_SEC) / baud) / 10;
+		total_iter += 50;
+	}
+

drivers/tty/serial/qcom_geni_serial.c line 206

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	while (iter < total_iter) {
+		reg = geni_read_reg_nolog(uport->membase, offset);
+		cond = reg & bit_field;
+		if (cond == set) {
+			met = true;
+			break;
+		}
+		udelay(10);
+		iter++;
+	}

Use readl_poll_timeout() instead of all this.

drivers/tty/serial/qcom_geni_serial.c line 213

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	return met;
+}
+
+static void qcom_geni_serial_setup_tx(struct uart_port *uport,
+				unsigned int xmit_size)
+{
+	u32 m_cmd = 0;

Don't initialize this.

drivers/tty/serial/qcom_geni_serial.c line 216

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+	geni_write_reg_nolog(xmit_size, uport->membase, SE_UART_TX_TRANS_LEN);
+	m_cmd |= (UART_START_TX << M_OPCODE_SHFT);

Why OR this into 0?

drivers/tty/serial/qcom_geni_serial.c line 225

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	geni_write_reg_nolog(m_cmd, uport->membase, SE_GENI_M_CMD0);
+	/*
+	 * Writes to enable the primary sequencer should go through before
+	 * exiting this function.
+	 */
+	mb();
+}
+
+static void qcom_geni_serial_poll_cancel_tx(struct uart_port *uport)

This function polls for command done and if that doesn't happen in time it aborts the command. It then clear any interrupts. The function name however indicates that we're polling for "cancel of tx".

drivers/tty/serial/qcom_geni_serial.c line 229

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+{
+	int done = 0;
+	unsigned int irq_clear = M_CMD_DONE_EN;
+	unsigned int geni_status = 0;

Don't initialize done and geni_status.

drivers/tty/serial/qcom_geni_serial.c line 236

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_DONE_EN, true);
+	if (!done) {
+		geni_write_reg_nolog(M_GENI_CMD_ABORT, uport->membase,
+					SE_GENI_M_CMD_CTRL_REG);
+		owr++;

What's owr?

drivers/tty/serial/qcom_geni_serial.c line 242

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		irq_clear |= M_CMD_ABORT_EN;
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+							M_CMD_ABORT_EN, true);
+	}
+	geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);

Why is this line wrapped?

drivers/tty/serial/qcom_geni_serial.c line 253

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+	if (geni_status & M_GENI_CMD_ACTIVE)
+		owr++;
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_abort_rx(struct uart_port *uport)
+{
+	unsigned int irq_clear = S_CMD_DONE_EN;
+
+	geni_se_abort_s_cmd(uport->membase);
+	/* Ensure this goes through before polling. */

Move the mb() to the qcom_geni_serial_poll_bit()

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	mb();
+	irq_clear |= S_CMD_ABORT_EN;
+	qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_ABORT, false);

drivers/tty/serial/qcom_geni_serial.c line 267

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(FORCE_DEFAULT, uport->membase, GENI_FORCE_DEFAULT_REG);
+}
+
+#ifdef CONFIG_CONSOLE_POLL
+static int qcom_geni_serial_get_char(struct uart_port *uport)
+{
+	unsigned int rx_fifo;
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;

These are u32 and the variable names would benefit from being shorter.

drivers/tty/serial/qcom_geni_serial.c line 270

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+			M_SEC_IRQ_EN, true)))

Drop one parenthesis.

drivers/tty/serial/qcom_geni_serial.c line 274

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+		return -ENXIO;
+
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);

Drop the _nolog and rename the variable to reduce the length of this line.

drivers/tty/serial/qcom_geni_serial.c line 280

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	geni_write_reg_nolog(m_irq_status, uport->membase,
+						SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase,
+						SE_GENI_S_IRQ_CLEAR);

Is it necessary to do this interlaced? Or can you just clear M and then clear S? I.e. have a single variable named "status".

drivers/tty/serial/qcom_geni_serial.c line 288

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_RX_FIFO_STATUS,
+			RX_FIFO_WC_MSK, true)))
+		return -ENXIO;
+
+	/*
+	 * Read the Rx FIFO only after clearing the interrupt registers and
+	 * getting valid RX fifo status.

Use non-_relaxed readl and you wouldn't have to do this explicitly.

drivers/tty/serial/qcom_geni_serial.c line 292

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	 */
+	mb();
+	rx_fifo = geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+	rx_fifo &= 0xFF;

return rx_fifo & 0xff; instead of the extra step

drivers/tty/serial/qcom_geni_serial.c line 299

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	return rx_fifo;
+}
+
+static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
+					unsigned char c)
+{
+	int b = (int) c;

Why create this alias?

drivers/tty/serial/qcom_geni_serial.c line 307

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_write_reg_nolog(port->tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, 1);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+				M_TX_FIFO_WATERMARK_EN, true))
+		WARN_ON(1);
	WARN_ON(!qcom_geni_serial_poll_bit(...));

drivers/tty/serial/qcom_geni_serial.c line 313

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	geni_write_reg_nolog(b, uport->membase, SE_GENI_TX_FIFOn);
+	geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	/*
+	 * Ensure FIFO write goes through before polling for status but.
+	 */

/* This fits in a one-line comment */

But if this is necessary that means that every time you call serial_poll() you need to have this comment and a rmb(). Better move it into the poll function then - or just stop using _relaxed()

drivers/tty/serial/qcom_geni_serial.c line 319

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	mb();
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)

The Kconfig specifies that we depend on CONFIG_SERIAL_CORE_CONSOLE, so no need to check that.

drivers/tty/serial/qcom_geni_serial.c line 325

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
+{
+	geni_write_reg_nolog(ch, uport->membase, SE_GENI_TX_FIFOn);
+	/*
+	 * Ensure FIFO write clear goes through before
+	 * next iteration.

This comment is accurate, but unnecessarily line wrapped.

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	 */
+	mb();
+
+}
+
+static void
+__qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
+				unsigned int count)
+{

drivers/tty/serial/qcom_geni_serial.c line 344

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	int new_line = 0;
+	int i;
+	int bytes_to_send = count;
+	int fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	int tx_wm = DEF_TX_WM;
+
+	for (i = 0; i < count; i++) {
+		if (s[i] == '\n')
+			new_line++;
+	}

Why do we need to deal with this?

drivers/tty/serial/qcom_geni_serial.c line 353

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+
+	bytes_to_send += new_line;
+	geni_write_reg_nolog(tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, bytes_to_send);
+	i = 0;
+	while (i < count) {
+		u32 chars_to_write = 0;
+		u32 avail_fifo_bytes = (fifo_depth - tx_wm);

Use size_t for these.

drivers/tty/serial/qcom_geni_serial.c line 366

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -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 (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_TX_FIFO_WATERMARK_EN, true))
+			break;
+		chars_to_write = min((unsigned int)(count - i),
+							avail_fifo_bytes);
+		if ((chars_to_write << 1) > avail_fifo_bytes)

Write chars_to_write * 2, the compiler will be cleaver for you.

drivers/tty/serial/qcom_geni_serial.c line 373

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+			chars_to_write = (avail_fifo_bytes >> 1);
+		uart_console_write(uport, (s + i), chars_to_write,
+						qcom_geni_serial_wr_char);
+		geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+		/* Ensure this goes through before polling for WM IRQ again.*/
+		mb();

Again, if this is necessary move it into the poll function instead of sprinkling it throughout the driver.

drivers/tty/serial/qcom_geni_serial.c line 384

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+		i += chars_to_write;
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+
+static void qcom_geni_serial_console_write(struct console *co, const char *s,
+			      unsigned int count)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *port;
+	int locked = 1;

Use bool for booleans

drivers/tty/serial/qcom_geni_serial.c line 390

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+	unsigned long flags;
+
+	WARN_ON(co->index < 0 || co->index >= GENI_UART_NR_PORTS);
+
+	port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(port))

port can't be NULL.

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+		return;
+
+	uport = &port->uport;
+	if (oops_in_progress)
+		locked = spin_trylock_irqsave(&uport->lock, flags);
+	else
+		spin_lock_irqsave(&uport->lock, flags);
+

drivers/tty/serial/qcom_geni_serial.c line 408

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	if (locked) {
+		__qcom_geni_serial_console_write(uport, s, count);
+		spin_unlock_irqrestore(&uport->lock, flags);
+	}
+}
+
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,

You should be able to have a single parameter with a better name stating that "this is the last chunk and it's only N bytes", rather than encoding this in a bool and a count with obscure names.

drivers/tty/serial/qcom_geni_serial.c line 421

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+			bool drop_rx)
+{
+	int i, c;
+	unsigned char *rx_char;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	for (i = 0; i < rx_fifo_wc; i++) {
+		int bytes = 4;
+
+		*(qcom_port->rx_fifo) =
+			geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);

Just store this value in a local variable, as the only consumer is 3 lines down.

drivers/tty/serial/qcom_geni_serial.c line 427

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		if (drop_rx)
+			continue;
+		rx_char = (unsigned char *)qcom_port->rx_fifo;
+
+		if (i == (rx_fifo_wc - 1)) {
+			if (rx_last && rx_last_byte_valid)

Also, shouldn't rx_last be redundant to the check against rx_fifo_wc?

drivers/tty/serial/qcom_geni_serial.c line 431

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+				bytes = rx_last_byte_valid;
+		}
+		for (c = 0; c < bytes; c++) {
+			char flag = TTY_NORMAL;

No need for a local variable here.

Quoted 17 lines
drivers/tty/serial/qcom_geni_serial.c new file +17 -0
+			int sysrq;
+
+			uport->icount.rx++;
+			sysrq = uart_handle_sysrq_char(uport, rx_char[c]);
+			if (!sysrq)
+				tty_insert_flip_char(tport, rx_char[c], flag);
+		}
+	}
+	if (!drop_rx)
+		tty_flip_buffer_push(tport);
+	return 0;
+}
+#else
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,

drivers/tty/serial/qcom_geni_serial.c line 458

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+			bool drop_rx)
+{
+	return -EPERM;
+}
+
+#endif /* (CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)) */
+
+static void qcom_geni_serial_start_tx(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;

This is a u32, name it "irq_en"

drivers/tty/serial/qcom_geni_serial.c

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned int geni_status;

geni_status should be of type u32 and there's no lack of descriptiveness naming it "status".

drivers/tty/serial/qcom_geni_serial.c line 466

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+
+	if (qcom_port->xfer_mode == FIFO_MODE) {
+		geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+		if (geni_status & M_GENI_CMD_ACTIVE)
+			goto exit_start_tx;

Just return

drivers/tty/serial/qcom_geni_serial.c line 469

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+		if (!qcom_geni_serial_tx_empty(uport))
+			goto exit_start_tx;

Ditto

drivers/tty/serial/qcom_geni_serial.c line 479

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+						    SE_GENI_M_IRQ_EN);
+		geni_m_irq_en |= (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN);
+
+		geni_write_reg_nolog(qcom_port->tx_wm, uport->membase,
+						SE_GENI_TX_WATERMARK_REG);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+		/* Geni command setup should complete before returning.*/

If that's the case then verify that it's actually done.

drivers/tty/serial/qcom_geni_serial.c line 489

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		mb();
+	}
+exit_start_tx:
+	return;
+}
+
+static void stop_tx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;

These are u32 and can be given more succinct names.

drivers/tty/serial/qcom_geni_serial.c line 492

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);

Drop the _nolog from all of these to make code easier to read.

Quoted 19 lines
drivers/tty/serial/qcom_geni_serial.c new file +19 -0
+	geni_m_irq_en &= ~M_CMD_DONE_EN;
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_m_irq_en &= ~M_TX_FIFO_WATERMARK_EN;
+		geni_write_reg_nolog(0, uport->membase,
+				     SE_GENI_TX_WATERMARK_REG);
+	}
+	port->xmit_size = 0;
+	geni_write_reg_nolog(geni_m_irq_en, uport->membase, SE_GENI_M_IRQ_EN);
+	geni_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_STATUS);
+	/* Possible stop tx is called multiple times. */
+	if (!(geni_status & M_GENI_CMD_ACTIVE))
+		return;
+
+	geni_se_cancel_m_cmd(uport->membase);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_CANCEL_EN, true)) {
+		geni_se_abort_m_cmd(uport->membase);
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,

drivers/tty/serial/qcom_geni_serial.c line 521

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+						M_CMD_ABORT_EN, true);
+		geni_write_reg_nolog(M_CMD_ABORT_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	}
+	geni_write_reg_nolog(M_CMD_CANCEL_EN, uport, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_stop_tx(struct uart_port *uport)
+{
+	stop_tx_sequencer(uport);

Inline stop_tx_sequencer here...

Quoted 18 lines
drivers/tty/serial/qcom_geni_serial.c new file +18 -0
+}
+
+static void start_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	if (geni_status & S_GENI_CMD_ACTIVE)
+		qcom_geni_serial_stop_rx(uport);
+
+	geni_se_setup_s_cmd(uport->membase, UART_START_READ, 0);
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);

drivers/tty/serial/qcom_geni_serial.c line 549

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+
+		geni_s_irq_en |= S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN;
+		geni_m_irq_en |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);

Do you need to do have these two operations interlaced? Can't you take care of M and then S using a single variable?

drivers/tty/serial/qcom_geni_serial.c line 553

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	}
+	/*
+	 * Ensure the writes to the secondary sequencer and interrupt enables
+	 * go through.

This is not what mb() does.

drivers/tty/serial/qcom_geni_serial.c line 561

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	 */
+	mb();
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+}
+
+static void qcom_geni_serial_start_rx(struct uart_port *uport)
+{
+	start_rx_sequencer(uport);

Inline start_rx_sequencer

Quoted 17 lines
drivers/tty/serial/qcom_geni_serial.c new file +17 -0
+}
+
+static void stop_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	u32 irq_clear = S_CMD_DONE_EN;
+	bool done;
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+		geni_s_irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);

drivers/tty/serial/qcom_geni_serial.c line 588

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		geni_m_irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	/* Possible stop rx is called multiple times. */

Shouldn't this be checked before above writes?

drivers/tty/serial/qcom_geni_serial.c line 601

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+	if (!(geni_status & S_GENI_CMD_ACTIVE))
+		return;
+	geni_se_cancel_s_cmd(uport->membase);
+	/*
+	 * Ensure that the cancel goes through before polling for the
+	 * cancel control bit.
+	 */
+	mb();
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_CANCEL, false);
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	if ((geni_status & S_GENI_CMD_ACTIVE))

Drop the extra parenthesis. Is this checking if we're still active after the cancel, or is this redundant?

drivers/tty/serial/qcom_geni_serial.c line 607

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		qcom_geni_serial_abort_rx(uport);
+}
+
+static void qcom_geni_serial_stop_rx(struct uart_port *uport)
+{
+	stop_rx_sequencer(uport);

Just inline the function here.

drivers/tty/serial/qcom_geni_serial.c line 616

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+}
+
+static int qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop_rx)
+{
+	int ret = 0;
+	unsigned int rx_fifo_status;
+	unsigned int rx_fifo_wc = 0;
+	unsigned int rx_last_byte_valid = 0;
+	unsigned int rx_last = 0;

The context of this function gives that we're dealing with rx and rx_fifo, so no need to specify that in each local variable.

Also, they should all be u32 and there's no need to initialize them.

drivers/tty/serial/qcom_geni_serial.c line 629

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	rx_fifo_status = geni_read_reg_nolog(uport->membase,
+				SE_GENI_RX_FIFO_STATUS);
+	rx_fifo_wc = rx_fifo_status & RX_FIFO_WC_MSK;
+	rx_last_byte_valid = ((rx_fifo_status & RX_LAST_BYTE_VALID_MSK) >>
+						RX_LAST_BYTE_VALID_SHFT);
+	rx_last = rx_fifo_status & RX_LAST;
+	if (rx_fifo_wc)
+		port->handle_rx(uport, rx_fifo_wc, rx_last_byte_valid,
+							rx_last, drop_rx);

You're ignoring the return value of handle_rx.

drivers/tty/serial/qcom_geni_serial.c

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	return ret;

You don't care about the return value in the caller and you always return 0 anyways, so make the function void.

drivers/tty/serial/qcom_geni_serial.c line 637

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+}
+
+static int qcom_geni_serial_handle_tx(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	struct circ_buf *xmit = &uport->state->xmit;

Use size_t for sizes.

drivers/tty/serial/qcom_geni_serial.c line 638

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	unsigned int avail_fifo_bytes = 0;

Naming avail_fifo_bytes just "avail" is carrying the same information but is shorter.

drivers/tty/serial/qcom_geni_serial.c line 642

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	unsigned int bytes_remaining = 0;
+	int i = 0;
+	unsigned int tx_fifo_status;
+	unsigned int xmit_size;

This is "the number of bytes we're going to take from the uart xmit buffer and push to the hardware FIFO. Call it "chunk" or something, because it's not the size of the xmit.

drivers/tty/serial/qcom_geni_serial.c line 643

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	unsigned int fifo_width_bytes = 1;

If this really is constantly 1 you can remove the variable and remove a bit of the complexity in this function.

drivers/tty/serial/qcom_geni_serial.c line 644

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	int temp_tail = 0;

Local variables are temporary in nature, so no need to name the variable temp_tail, it is the "tail" we operate on here.

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+	xmit_size = uart_circ_chars_pending(xmit);
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+					SE_GENI_TX_FIFO_STATUS);
+	/* Both FIFO and framework buffer are drained */
+	if ((xmit_size == qcom_port->xmit_size) && !tx_fifo_status) {
+		qcom_port->xmit_size = 0;
+		uart_circ_clear(xmit);
+		qcom_geni_serial_stop_tx(uport);
+		goto exit_handle_tx;

drivers/tty/serial/qcom_geni_serial.c line 664

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	}
+	xmit_size -= qcom_port->xmit_size;
+
+	avail_fifo_bytes = (qcom_port->tx_fifo_depth - qcom_port->tx_wm) *
+							fifo_width_bytes;
+	temp_tail = (xmit->tail + qcom_port->xmit_size) & (UART_XMIT_SIZE - 1);
+	if (xmit_size > (UART_XMIT_SIZE - temp_tail))
+		xmit_size = (UART_XMIT_SIZE - temp_tail);
+	if (xmit_size > avail_fifo_bytes)
+		xmit_size = avail_fifo_bytes;

This section is confusing me, in other drivers we update xmit->tail and the uart_circ_chars_pending() returns the number of bytes left to be written. But in your driver we maintain qcom_port->xmit_size as a delta between the tail and the next byte in the ring buffer to consume.

I find no place were you're actually updating the tail, so I'm wondering how setting qcom_port->xmit_size to zero above will actually work, as it doesn't consider that xmit->head might be elsewhere.

The math that you need to come up with is "how much data is there to be written" and "how much FIFO space do I have" and then take the min() of those. The prior should be the return value of uart_circ_chars_pending() straight off.

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+
+	if (!xmit_size)
+		goto exit_handle_tx;
+

drivers/tty/serial/qcom_geni_serial.c line 678

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	qcom_geni_serial_setup_tx(uport, xmit_size);
+
+	bytes_remaining = xmit_size;
+	while (i < xmit_size) {
+		unsigned int tx_bytes;
+		unsigned int buf = 0;
+		int c;
+
+		tx_bytes = ((bytes_remaining < fifo_width_bytes) ?
+					bytes_remaining : fifo_width_bytes);
		tx_bytes = min(remaining, fifo_width);

But fifo_width_bytes is 1, so this can be simplified.

drivers/tty/serial/qcom_geni_serial.c line 681

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+
+		for (c = 0; c < tx_bytes ; c++)
+			buf |= (xmit->buf[temp_tail + c] << (c * 8));

As bytes_remaining shouldn't be able to reach 0, tx_bytes should always be 1 and as such this is just a matter of writing xmit->buf[xmit->tail++] to SE_GENI_TX_FIFOn.

drivers/tty/serial/qcom_geni_serial.c line 687

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		geni_write_reg_nolog(buf, uport->membase, SE_GENI_TX_FIFOn);
+		i += tx_bytes;
+		temp_tail = (temp_tail + tx_bytes) & (UART_XMIT_SIZE - 1);
+		uport->icount.tx += tx_bytes;
+		bytes_remaining -= tx_bytes;
+		/* Ensure FIFO write goes through */

Writes to the same register isn't expected to be reordered, so you shouldn't need this wmb(). Perhaps it's the same barrier that's needed for other polls?

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+		wmb();
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+	qcom_port->xmit_size += xmit_size;
+exit_handle_tx:
+	uart_write_wakeup(uport);
+	return ret;
+}
+
+static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
+{
+	unsigned int m_irq_status;

drivers/tty/serial/qcom_geni_serial.c line 709

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	unsigned int s_irq_status;
+	struct uart_port *uport = dev;
+	unsigned long flags;
+	unsigned int m_irq_en;
+	bool drop_rx = false;
+	struct tty_port *tport = &uport->state->port;
+
+	spin_lock_irqsave(&uport->lock, flags);
+	if (uport->suspended)
+		goto exit_geni_serial_isr;

Do you need to check this within the spinlock?

Name your labels based on their action, not the function they are in. So a better name would be "out_unlock". But if this can be done outside the lock just returning would be better.

drivers/tty/serial/qcom_geni_serial.c line 718

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_write_reg_nolog(m_irq_status, uport->membase, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase, SE_GENI_S_IRQ_CLEAR);
+
+	if ((m_irq_status & M_ILLEGAL_CMD_EN)) {

Extra parenthesis, and you can better write this:

	if (WARN_ON(m_irq_status & M_ILLEGAL_CMD_EN))
		goto out_unlock;

drivers/tty/serial/qcom_geni_serial.c line 728

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+		WARN_ON(1);
+		goto exit_geni_serial_isr;
+	}
+
+	if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
+		uport->icount.overrun++;
+		tty_insert_flip_char(tport, 0, TTY_OVERRUN);
+	}
+
+	if ((m_irq_status & m_irq_en) &

Is M_ILLEGAL_CMD_EN part of m_irq_en? Can you mask the m_irq_status based on the irq_en above instead of doing it like this?

drivers/tty/serial/qcom_geni_serial.c line 732

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	    (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN))
+		qcom_geni_serial_handle_tx(uport);
+
+	if ((s_irq_status & S_GP_IRQ_0_EN) || (s_irq_status & S_GP_IRQ_1_EN)) {

Drop the parenthesis.

drivers/tty/serial/qcom_geni_serial.c line 737

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+		if (s_irq_status & S_GP_IRQ_0_EN)
+			uport->icount.parity++;
+		drop_rx = true;
+	} else if ((s_irq_status & S_GP_IRQ_2_EN) ||
+		(s_irq_status & S_GP_IRQ_3_EN)) {

Ditto.

drivers/tty/serial/qcom_geni_serial.c line 742

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+		uport->icount.brk++;
+	}
+
+	if ((s_irq_status & S_RX_FIFO_WATERMARK_EN) ||
+		(s_irq_status & S_RX_FIFO_LAST_EN))

Ditto.

Quoted 28 lines
drivers/tty/serial/qcom_geni_serial.c new file +28 -0
+		qcom_geni_serial_handle_rx(uport, drop_rx);
+
+exit_geni_serial_isr:
+	spin_unlock_irqrestore(&uport->lock, flags);
+	return IRQ_HANDLED;
+}
+
+static int get_tx_fifo_size(struct qcom_geni_serial_port *port)
+{
+	struct uart_port *uport;
+
+	if (!port)
+		return -ENODEV;
+
+	uport = &port->uport;
+	port->tx_fifo_depth = geni_se_get_tx_fifo_depth(uport->membase);
+	if (!port->tx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->tx_fifo_width = geni_se_get_tx_fifo_width(uport->membase);
+	if (!port->tx_fifo_width) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO width read\n",
+								__func__);
+		return -ENXIO;
+	}

drivers/tty/serial/qcom_geni_serial.c line 780

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+	port->rx_fifo_depth = geni_se_get_rx_fifo_depth(uport->membase);
+	if (!port->rx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid RX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	uport->fifosize =
+		((port->tx_fifo_depth * port->tx_fifo_width) >> 3);

This line wrap isn't necessary, use division rather than shifting and describe why the fifosize is 1/8 of the depth * width (is the width expressed in bits perhaps?)

Quoted 45 lines
drivers/tty/serial/qcom_geni_serial.c new file +45 -0
+	return 0;
+}
+
+static void set_rfr_wm(struct qcom_geni_serial_port *port)
+{
+	/*
+	 * Set RFR (Flow off) to FIFO_DEPTH - 2.
+	 * RX WM level at 10% RX_FIFO_DEPTH.
+	 * TX WM level at 10% TX_FIFO_DEPTH.
+	 */
+	port->rx_rfr = port->rx_fifo_depth - 2;
+	port->rx_wm = UART_CONSOLE_RX_WM;
+	port->tx_wm = 2;
+}
+
+static void qcom_geni_serial_shutdown(struct uart_port *uport)
+{
+	unsigned long flags;
+
+	/* Stop the console before stopping the current tx */
+	console_stop(uport->cons);
+
+	disable_irq(uport->irq);
+	free_irq(uport->irq, uport);
+	spin_lock_irqsave(&uport->lock, flags);
+	qcom_geni_serial_stop_tx(uport);
+	qcom_geni_serial_stop_rx(uport);
+	spin_unlock_irqrestore(&uport->lock, flags);
+}
+
+static int qcom_geni_serial_port_setup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned long cfg0, cfg1;
+	unsigned int rxstale = DEFAULT_BITS_PER_CHAR * STALE_TIMEOUT;
+
+	set_rfr_wm(qcom_port);
+	geni_write_reg_nolog(rxstale, uport->membase, SE_UART_RX_STALE_CNT);
+	/*
+	 * Make an unconditional cancel on the main sequencer to reset
+	 * it else we could end up in data loss scenarios.
+	 */
+	qcom_port->xfer_mode = FIFO_MODE;
+	qcom_geni_serial_poll_cancel_tx(uport);

drivers/tty/serial/qcom_geni_serial.c line 835

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	geni_se_get_packing_config(8, 1, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_TX_PACKING_CFG1);
+	geni_se_get_packing_config(8, 4, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_RX_PACKING_CFG1);

These aren't above 80 chars, why are you line breaking?

drivers/tty/serial/qcom_geni_serial.c line 843

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+	ret = geni_se_init(uport->membase, qcom_port->rx_wm, qcom_port->rx_rfr);
+	if (ret) {
+		dev_err(uport->dev, "%s: Fail\n", __func__);
+		goto exit_portsetup;
+	}
+
+	ret = geni_se_select_mode(uport->membase, qcom_port->xfer_mode);
+	if (ret)

Do you need to roll back any init done in the wrapper code? How about passing the mode to the init function?

drivers/tty/serial/qcom_geni_serial.c line 849

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		goto exit_portsetup;
+
+	qcom_port->port_setup = true;
+	/*
+	 * Ensure Port setup related IO completes before returning to
+	 * framework.

That's not what mb does.

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	 */
+	mb();
+exit_portsetup:
+	return ret;
+}

drivers/tty/serial/qcom_geni_serial.c line 864

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+static int qcom_geni_serial_startup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	scnprintf(qcom_port->name, sizeof(qcom_port->name),
+		  "qcom_serial_geni%d",	uport->line);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {

Drop the unlikely(), in favour of readable code.

drivers/tty/serial/qcom_geni_serial.c line 866

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+		dev_err(uport->dev, "%s: Invalid FW %d loaded.\n",
+				 __func__, geni_se_get_proto(uport->membase));

Drop the __func__, the message should describe the issue in itself.

drivers/tty/serial/qcom_geni_serial.c

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+		ret = -ENXIO;
+		goto exit_startup;

We haven't done anything, so just return here.

drivers/tty/serial/qcom_geni_serial.c line 879

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+	}
+
+	get_tx_fifo_size(qcom_port);
+	if (!qcom_port->port_setup) {
+		if (qcom_geni_serial_port_setup(uport))
+			goto exit_startup;
+	}
+
+	/*
+	 * Ensure that all the port configuration writes complete
+	 * before returning to the framework.

That's not what mb() does.

drivers/tty/serial/qcom_geni_serial.c line 886

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+	 */
+	mb();
+	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
+			qcom_port->name, uport);
+	if (unlikely(ret)) {
+		dev_err(uport->dev, "%s: Failed to get IRQ ret %d\n",
+							__func__, ret);

Drop the __func__

Quoted 17 lines
drivers/tty/serial/qcom_geni_serial.c new file +17 -0
+		goto exit_startup;
+	}
+
+exit_startup:
+	return ret;
+}
+
+static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
+{
+	unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
+		32000000, 48000000, 64000000, 80000000, 96000000, 100000000};
+	int i;
+	int match = -1;
+
+	for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
+		if (clk_freq > root_freq[i])
+			continue;

drivers/tty/serial/qcom_geni_serial.c line 913

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+		if (!(root_freq[i] % clk_freq)) {
+			match = i;
+			break;
+		}
+	}
+	if (match != -1)
+		*ser_clk = root_freq[match];
+	else
+		pr_err("clk_freq %ld\n", clk_freq);

Errors are for humans to consume, so make the message useful for a human.

drivers/tty/serial/qcom_geni_serial.c line 914

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	return match;

The index isn't used, so return the frequency instead of filling in the ser_clk reference.

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+}
+
+static void geni_serial_write_term_regs(struct uart_port *uport,
+		u32 tx_trans_cfg, u32 tx_parity_cfg, u32 rx_trans_cfg,
+		u32 rx_parity_cfg, u32 bits_per_char, u32 stop_bit_len,
+		u32 s_clk_cfg)
+{
+	geni_write_reg_nolog(tx_trans_cfg, uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	geni_write_reg_nolog(tx_parity_cfg, uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	geni_write_reg_nolog(rx_trans_cfg, uport->membase,
+							SE_UART_RX_TRANS_CFG);

drivers/tty/serial/qcom_geni_serial.c line 937

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	geni_write_reg_nolog(rx_parity_cfg, uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_TX_WORD_LEN);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_RX_WORD_LEN);
+	geni_write_reg_nolog(stop_bit_len, uport->membase,
+						SE_UART_TX_STOP_BIT_LEN);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_M_CLK_CFG);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_S_CLK_CFG);

Drop the _nolog and you should be able to fit these within 80 chars.

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+}
+
+static int get_clk_div_rate(unsigned int baud, unsigned long *desired_clk_rate)
+{

drivers/tty/serial/qcom_geni_serial.c line 951

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	unsigned long ser_clk;
+	int dfs_index;
+	int clk_div = 0;
+
+	*desired_clk_rate = baud * UART_OVERSAMPLING;
+	dfs_index = get_clk_cfg(*desired_clk_rate, &ser_clk);
+	if (dfs_index < 0) {
+		pr_err("%s: Can't find matching DFS entry for baud %d\n",
+								__func__, baud);
+		clk_div = -EINVAL;

Just return -EINVAL here, instead of using goto.

drivers/tty/serial/qcom_geni_serial.c line 958

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+		goto exit_get_clk_div_rate;
+	}
+
+	clk_div = ser_clk / *desired_clk_rate;
+	*desired_clk_rate = ser_clk;
+exit_get_clk_div_rate:
+	return clk_div;

Clock functions typically return a frequency, so I think it's better to return that and pass the divider by reference.

Quoted 14 lines
drivers/tty/serial/qcom_geni_serial.c new file +14 -0
+}
+
+static void qcom_geni_serial_set_termios(struct uart_port *uport,
+				struct ktermios *termios, struct ktermios *old)
+{
+	unsigned int baud;
+	unsigned int bits_per_char = 0;
+	unsigned int tx_trans_cfg;
+	unsigned int tx_parity_cfg;
+	unsigned int rx_trans_cfg;
+	unsigned int rx_parity_cfg;
+	unsigned int stop_bit_len;
+	unsigned int clk_div;
+	unsigned long ser_clk_cfg = 0;

drivers/tty/serial/qcom_geni_serial.c line 982

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	unsigned long clk_rate;
+
+	qcom_geni_serial_stop_rx(uport);
+	/* baud rate */
+	baud = uart_get_baud_rate(uport, termios, old, 300, 4000000);
+	port->cur_baud = baud;
+	clk_div = get_clk_div_rate(baud, &clk_rate);
+	if (clk_div <= 0)
+		goto exit_set_termios;

Name your labels based on their actions; if you name it "out_restart_rx" you don't even have to look below to know what will happen when you jump.

drivers/tty/serial/qcom_geni_serial.c line 990

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+
+	uport->uartclk = clk_rate;
+	clk_set_rate(port->serial_rsc.se_clk, clk_rate);
+	ser_clk_cfg |= SER_CLK_EN;
+	ser_clk_cfg |= (clk_div << CLK_DIV_SHFT);
+
+	/* parity */
+	tx_trans_cfg = geni_read_reg_nolog(uport->membase,

Drop the _nolog and you don't need to line wrap

Quoted 49 lines
drivers/tty/serial/qcom_geni_serial.c new file +49 -0
+							SE_UART_TX_TRANS_CFG);
+	tx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	rx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	rx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	if (termios->c_cflag & PARENB) {
+		tx_trans_cfg |= UART_TX_PAR_EN;
+		rx_trans_cfg |= UART_RX_PAR_EN;
+		tx_parity_cfg |= PAR_CALC_EN;
+		rx_parity_cfg |= PAR_CALC_EN;
+		if (termios->c_cflag & PARODD) {
+			tx_parity_cfg |= PAR_ODD;
+			rx_parity_cfg |= PAR_ODD;
+		} else if (termios->c_cflag & CMSPAR) {
+			tx_parity_cfg |= PAR_SPACE;
+			rx_parity_cfg |= PAR_SPACE;
+		} else {
+			tx_parity_cfg |= PAR_EVEN;
+			rx_parity_cfg |= PAR_EVEN;
+		}
+	} else {
+		tx_trans_cfg &= ~UART_TX_PAR_EN;
+		rx_trans_cfg &= ~UART_RX_PAR_EN;
+		tx_parity_cfg &= ~PAR_CALC_EN;
+		rx_parity_cfg &= ~PAR_CALC_EN;
+	}
+
+	/* bits per char */
+	switch (termios->c_cflag & CSIZE) {
+	case CS5:
+		bits_per_char = 5;
+		break;
+	case CS6:
+		bits_per_char = 6;
+		break;
+	case CS7:
+		bits_per_char = 7;
+		break;
+	case CS8:
+	default:
+		bits_per_char = 8;
+		break;
+	}
+
+	/* stop bits */
+	if (termios->c_cflag & CSTOPB)
+		stop_bit_len = TX_STOP_BIT_LEN_2;

drivers/tty/serial/qcom_geni_serial.c line 1049

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	else
+		stop_bit_len = TX_STOP_BIT_LEN_1;
+
+	/* flow control, clear the CTS_MASK bit if using flow control. */
+	if (termios->c_cflag & CRTSCTS)
+		tx_trans_cfg &= ~UART_CTS_MASK;
+	else
+		tx_trans_cfg |= UART_CTS_MASK;
+
+	if (likely(baud))

Don't do likely/unlikely.

drivers/tty/serial/qcom_geni_serial.c line 1054

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+		uart_update_timeout(uport, termios->c_cflag, baud);
+
+	geni_serial_write_term_regs(uport, tx_trans_cfg, tx_parity_cfg,
+		rx_trans_cfg, rx_parity_cfg, bits_per_char, stop_bit_len,
+								ser_clk_cfg);

It would likely be fine to just inline the register writes here, instead of this long list of parameters.

drivers/tty/serial/qcom_geni_serial.c line 1057

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+exit_set_termios:
+	qcom_geni_serial_start_rx(uport);
+	return;

No need to keep an empty return last in the function, and drop the empty line following it.

drivers/tty/serial/qcom_geni_serial.c line 1067

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+
+}
+
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
+{
+	unsigned int tx_fifo_status;
+	unsigned int is_tx_empty = 1;
+
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_TX_FIFO_STATUS);

Drop the "_nolog" and naming the result "status" would be just as expressive, but keep you below 80 chars.

drivers/tty/serial/qcom_geni_serial.c line 1071

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+	if (tx_fifo_status)
+		is_tx_empty = 0;
+
+	return is_tx_empty;

Instead of what you're doing with is_tx_empty, just do:

	return !readl(membase + FIFO_STATUS);

drivers/tty/serial/qcom_geni_serial.c line 1083

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+}
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
+static int __init qcom_geni_console_setup(struct console *co, char *options)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *dev_port;
+	int baud = 115200;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+	int ret = 0;

Drop initialization of all these variables.

drivers/tty/serial/qcom_geni_serial.c line 1085

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+
+	if (unlikely(co->index >= GENI_UART_NR_PORTS  || co->index < 0))

Drop the unlikely.

drivers/tty/serial/qcom_geni_serial.c line 1089

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+		return -ENXIO;
+
+	dev_port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(dev_port)) {

port can't be NULL.

drivers/tty/serial/qcom_geni_serial.c line 1092

Quoted 3 lines
drivers/tty/serial/qcom_geni_serial.c new file +3 -0
+		ret = PTR_ERR(dev_port);
+		pr_err("Invalid line %d(%d)\n", co->index, ret);
+		return ret;

Just return PTR_ERR(dev_port);

drivers/tty/serial/qcom_geni_serial.c line 1101

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	}
+
+	uport = &dev_port->uport;
+
+	if (unlikely(!uport->membase))
+		return -ENXIO;
+
+	if (geni_se_resources_on(&dev_port->serial_rsc))
+		WARN_ON(1);

If this fails we're likely to access unclocked resources causing the system to restart, so we should probably not continue here.

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		geni_se_resources_off(&dev_port->serial_rsc);
+		return -ENXIO;
+	}
+

[..]

drivers/tty/serial/qcom_geni_serial.c line 1192

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+
+static const struct of_device_id qcom_geni_serial_match_table[] = {
+	{ .compatible = "qcom,geni-debug-uart",
+			.data = (void *)&qcom_geni_console_driver},

Shouldn't need this typecast.

Is it necessary to treat the console uart differently and will there be a patch adding support for non-console instances? How will this differ and why would that be a different compatible?

drivers/tty/serial/qcom_geni_serial.c line 1205

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+};
+
+static int qcom_geni_serial_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	int line = -1;
+	struct qcom_geni_serial_port *dev_port;
+	struct uart_port *uport;
+	struct resource *res;
+	struct uart_driver *drv;
+	const struct of_device_id *id;
+
+	id = of_match_device(qcom_geni_serial_match_table, &pdev->dev);

Use of_device_get_match_data()

drivers/tty/serial/qcom_geni_serial.c line 1215

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	if (id) {
+		dev_dbg(&pdev->dev, "%s: %s\n", __func__, id->compatible);
+		drv = (struct uart_driver *)id->data;
+	} else {
+		dev_err(&pdev->dev, "%s: No matching device found", __func__);
+		return -ENODEV;
+	}
+
+	if (pdev->dev.of_node) {
+		if (drv->cons)

The one and only uart_driver has a cons.

drivers/tty/serial/qcom_geni_serial.c line 1227

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+			line = of_alias_get_id(pdev->dev.of_node, "serial");
+	} else {
+		line = pdev->id;
+	}
+
+	if (line < 0)
+		line = atomic_inc_return(&uart_line_id) - 1;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		return -ENXIO;
+	dev_port = get_port_from_line(line);
+	if (IS_ERR_OR_NULL(dev_port)) {

port can't be NULL.

drivers/tty/serial/qcom_geni_serial.c line 1231

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+		ret = PTR_ERR(dev_port);
+		dev_err(&pdev->dev, "Invalid line %d(%d)\n",
+					line, ret);
+		goto exit_geni_serial_probe;

You're not doing anything other than returning in exit_geni_serial_probe, if you just return here I don't need to jump to the bottom of the function to figure this out...

Quoted 11 lines
drivers/tty/serial/qcom_geni_serial.c new file +11 -0
+	}
+
+	uport = &dev_port->uport;
+
+	/* Don't allow 2 drivers to access the same port */
+	if (uport->private_data) {
+		ret = -ENODEV;
+		goto exit_geni_serial_probe;
+	}
+
+	uport->dev = &pdev->dev;

drivers/tty/serial/qcom_geni_serial.c line 1252

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	dev_port->wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(dev_port->serial_rsc.se_clk)) {
+		ret = PTR_ERR(dev_port->serial_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "se-phys");

Don't grab this by name, just pick the first one.

drivers/tty/serial/qcom_geni_serial.c line 1257

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	if (!res) {
+		ret = -ENXIO;
+		dev_err(&pdev->dev, "Err getting IO region\n");
+		goto exit_geni_serial_probe;
+	}

Drop the error handling here.

drivers/tty/serial/qcom_geni_serial.c line 1259

Quoted 1 line
drivers/tty/serial/qcom_geni_serial.c new file +1 -0
+	uport->mapbase = res->start;

No

drivers/tty/serial/qcom_geni_serial.c line 1268

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+	uport->membase = devm_ioremap(&pdev->dev, res->start,
+						resource_size(res));
+	if (!uport->membase) {
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "Err IO mapping serial iomem");
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);

Drop all of the pinctrl stuff.

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_pinctrl);
+		goto exit_geni_serial_probe;
+	}

[..]

drivers/tty/serial/qcom_geni_serial.c line 1296

Quoted 5 lines
drivers/tty/serial/qcom_geni_serial.c new file +5 -0
+	dev_port->tx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
+	uport->fifosize =
+		((dev_port->tx_fifo_depth * dev_port->tx_fifo_width) >> 3);

qcom_geni_serial_startup() sets this as well.

drivers/tty/serial/qcom_geni_serial.c line 1305

Quoted 9 lines
drivers/tty/serial/qcom_geni_serial.c new file +9 -0
+
+	uport->irq = platform_get_irq(pdev, 0);
+	if (uport->irq < 0) {
+		ret = uport->irq;
+		dev_err(&pdev->dev, "Failed to get IRQ %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport->private_data = (void *)drv;

No need to explicitly typecast to void*

drivers/tty/serial/qcom_geni_serial.c line 1307

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	platform_set_drvdata(pdev, dev_port);
+	dev_port->handle_rx = handle_rx_console;

Why have a function pointer when you're only referencing a fixed function.

drivers/tty/serial/qcom_geni_serial.c line 1309

Quoted 2 lines
drivers/tty/serial/qcom_geni_serial.c new file +2 -0
+	dev_port->rx_fifo = devm_kzalloc(uport->dev, sizeof(u32),
+								GFP_KERNEL);

It takes 8 bytes to store a pointer and the allocation will have some overhead...just to provide storage space for 4 bytes. And you don't have any error handling...

drivers/tty/serial/qcom_geni_serial.c line 1321

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+	dev_port->port_setup = false;
+	return uart_add_one_port(drv, uport);
+
+exit_geni_serial_probe:
+	return ret;
+}
+
+static int qcom_geni_serial_remove(struct platform_device *pdev)
+{
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_driver *drv =
+			(struct uart_driver *)port->uport.private_data;

No need to typecast private_data.

drivers/tty/serial/qcom_geni_serial.c line 1328

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+
+	uart_remove_one_port(drv, &port->uport);
+	return 0;
+}
+
+
+#ifdef CONFIG_PM

Drop this and mark the functions __maybe_unused.

drivers/tty/serial/qcom_geni_serial.c line 1336

Quoted 8 lines
drivers/tty/serial/qcom_geni_serial.c new file +8 -0
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	uart_suspend_port((struct uart_driver *)uport->private_data,
+				uport);

No need to typecast private_data.

drivers/tty/serial/qcom_geni_serial.c line 1348

Quoted 12 lines
drivers/tty/serial/qcom_geni_serial.c new file +12 -0
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	if (console_suspend_enabled && uport->suspended) {
+		uart_resume_port((struct uart_driver *)uport->private_data,
+									uport);

No need to typecast private_data.

Quoted 4 lines
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+		disable_irq(uport->irq);
+	}
+	return 0;
+}

[..]

drivers/tty/serial/qcom_geni_serial.c line 1385

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+static int __init qcom_geni_serial_init(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < GENI_UART_CONS_PORTS; i++) {

Don't loop over [0,1) to update the one global variable.

Quoted 6 lines
drivers/tty/serial/qcom_geni_serial.c new file +6 -0
+		qcom_geni_console_port.uport.iotype = UPIO_MEM;
+		qcom_geni_console_port.uport.ops = &qcom_geni_console_pops;
+		qcom_geni_console_port.uport.flags = UPF_BOOT_AUTOCONF;
+		qcom_geni_console_port.uport.line = i;
+	}
+

drivers/tty/serial/qcom_geni_serial.c line 1401

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+	ret = console_register(&qcom_geni_console_driver);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&qcom_geni_serial_platform_driver);
+	if (ret) {
+		console_unregister(&qcom_geni_console_driver);
+		return ret;
+	}
+	return ret;

ret is 0 here, drop the return from within the if statement or just return 0 for clarity.

drivers/tty/serial/qcom_geni_serial.c line 1414

Quoted 13 lines
drivers/tty/serial/qcom_geni_serial.c new file +13 -0
+}
+module_init(qcom_geni_serial_init);
+
+static void __exit qcom_geni_serial_exit(void)
+{
+	platform_driver_unregister(&qcom_geni_serial_platform_driver);
+	console_unregister(&qcom_geni_console_driver);
+}
+module_exit(qcom_geni_serial_exit);
+
+MODULE_DESCRIPTION("Serial driver for GENI based QUP cores");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("tty:qcom_geni_serial");

What will request the kernel module by this alias?

Regards,
Bjorn

#29 lore raw
In reply to a message not in the archive
Quoted 11 lines · Karthikeyan Ramasubramanian

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a next generation programmable module for supporting a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial Interfaces using its internal Serial Engines (SE). The protocol supported by each interface is determined by the firmware loaded to the Serial Engine.

This patch series introduces GENI SE Driver to manage the GENI based QUP Wrapper and the common aspects of all SEs inside the QUP Wrapper. This patch series also introduces the UART and I2C Controller drivers to drive the SEs that are programmed with the respective protocols.

Hi,

Will there be follow-up drivers for SPI, I3C, etc.?

Thanks.

Quoted 43 lines

[v2]
* Updated device tree bindings to describe the hardware
* Updated SE DT node as child node of QUP Wrapper DT node
* Moved common AHB clocks to QUP Wrapper DT node
* Use the standard "clock-frequency" I2C property
* Update compatible field in UART Controller to reflect hardware manual
* Addressed other device tree binding specific comments from Rob Herring

Karthikeyan Ramasubramanian (7):
qcom-geni-se: Add QCOM GENI SE Driver summary
dt-bindings: soc: qcom: Add device tree binding for GENI SE
soc: qcom: Add GENI based QUP Wrapper driver
dt-bindings: i2c: Add device tree bindings for GENI I2C Controller
i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C
controller
dt-bindings: serial: Add bindings for GENI based UART Controller
tty: serial: msm_geni_serial: Add serial driver support for GENI based
QUP

 .../devicetree/bindings/i2c/i2c-qcom-geni.txt      |   35 +
 .../devicetree/bindings/serial/qcom,geni-uart.txt  |   29 +
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  |   66 +
 Documentation/qcom-geni-se.txt                     |   56 +
 drivers/i2c/busses/Kconfig                         |   10 +
 drivers/i2c/busses/Makefile                        |    1 +
 drivers/i2c/busses/i2c-qcom-geni.c                 |  656 +++++++++
 drivers/soc/qcom/Kconfig                           |    8 +
 drivers/soc/qcom/Makefile                          |    1 +
 drivers/soc/qcom/qcom-geni-se.c                    | 1016 ++++++++++++++
 drivers/tty/serial/Kconfig                         |   10 +
 drivers/tty/serial/Makefile                        |    1 +
 drivers/tty/serial/qcom_geni_serial.c              | 1414 ++++++++++++++++++++
 include/linux/qcom-geni-se.h                       |  807 +++++++++++
 14 files changed, 4110 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt
 create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
 create mode 100644 Documentation/qcom-geni-se.txt
 create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
 create mode 100644 include/linux/qcom-geni-se.h
Signature · 5 lines
~Randy
--
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
#6 lore raw

Re: [PATCH v2 2/7] dt-bindings: soc: qcom: Add device tree binding for GENI SE

In reply to Bjorn Andersson
Quoted 32 lines · Bjorn Andersson
Quoted 3 lines · Karthikeyan Ramasubramanian

Add device tree binding support for the QCOM GENI SE driver.

Better describe the entire GENI, with it's functions in the same binding.

Quoted 23 lines
---
 .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +12 -0
new file mode 100644
index 0000000..66f8a16
@@ -0,0 +1,34 @@
+Qualcomm Technologies, Inc. GENI Serial Engine QUP Wrapper Controller
+
+Generic Interface (GENI) based Qualcomm Universal Peripheral (QUP) wrapper
+is a programmable module for supporting a wide range of serial interfaces
+like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial
+Interfaces, using its internal Serial Engines. The GENI Serial Engine QUP
+Wrapper controller is modeled as a node with zero or more child nodes each
+representing a serial engine.
+
+Required properties:
+- compatible:		Must be "qcom,geni-se-qup".
+- reg:			Must contain QUP register address and length.
Quoted 8 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 18

Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +6 -0
+- clock-names:		Must contain "m-ahb" and "s-ahb".
+- clocks:		AHB clocks needed by the device.
+
+Required properties if child node exists:
+- #address-cells: Must be 1
+- #size-cells: Must be 1

But on a 64-bit system, shouldn't these be 2?

No, depends on the bus and ranges. It annoys me to no end that folks needlessly use 2 cells when the perpheral address space and/or module sizes don't exceed 4G.

Quoted 2 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 19

Quoted 2 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +1 -0
+- ranges: Must be present

And ideally with a value, but that's beyond the scope of the binding.

Quoted 22 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 28

Quoted 9 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +9 -0
+
+Properties for children:
+
+A GENI based QUP wrapper controller node can contain 0 or more child nodes
+representing serial devices.  These serial devices can be a QCOM UART, I2C
+controller, spi controller, or some combination of aforementioned devices.
+
+Example:
+	qup0: qcom,geniqup0@8c0000 {

I don't see a reason for this to be referenced, so skip the label. And don't use qcom, in the node name; "geni" would be perfectly fine?

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 34

Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +6 -0
+		compatible = "qcom,geni-se-qup";
+		reg = <0x8c0000 0x6000>;
+		clock-names = "m-ahb", "s-ahb";
+		clocks = <&clock_gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
+			<&clock_gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
+	}

Regards,
Bjorn

maintainer
#13 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Bjorn Andersson
Quoted 34 lines · Bjorn Andersson
Quoted 32 lines · Rajendra Nayak

[]..

Quoted 22 lines
Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

Quoted 4 lines

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

Looks like Mark Brown commented elsewhere [1] that we should use the C++ commenting style even for the Linux Foundation copyright?

Quoted 6 lines
Quoted 2 lines

[1] https://marc.info/?l=linux-clk&m=151497978626135&w=2

While I can agree with Mark on the ugliness of the mixed commenting style, this is the style that I found communicated and is what you find in other files.

Well, that's pretty new guidance. Moving target...

Given that Linus said '//' comments are the only thing C++ got right, I expect to see more of them.

Rob

#20 lore raw

Re: [v2,3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to a message not in the archive
Quoted 10 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

Quoted 8 lines
---
 drivers/soc/qcom/Kconfig        |    8 +
 drivers/soc/qcom/Makefile       |    1 +
 drivers/soc/qcom/qcom-geni-se.c | 1016 +++++++++++++++++++++++++++++++++++++++
 include/linux/qcom-geni-se.h    |  807 +++++++++++++++++++++++++++++++
 4 files changed, 1832 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 include/linux/qcom-geni-se.h

I'm a newbie here, just starting to get up to speed. Please forgive any indiscretions. But I am interested in this driver, so I'm throwing in my minor comments.

Quoted 12 lines
include/linux/qcom-geni-se.h new file +12 -0
+/**
+ * geni_se_setup_m_cmd() - Setup the primary sequencer
+ * @base:      Base address of the serial engine's register block.
+ * @cmd:       Command/Operation to setup in the primary sequencer.
+ * @params:    Parameter for the sequencer command.
+ *
+ * This function is used to configure the primary sequencer with the
+ * command and its assoicated parameters.
+ */
+void geni_se_setup_m_cmd(void __iomem *base, u32 cmd, u32 params);
+
+/**

include/linux/qcom-geni-se.h line 410

Quoted 10 lines
include/linux/qcom-geni-se.h new file +10 -0
+ * geni_se_setup_s_cmd() - Setup the secondary sequencer
+ * @base:      Base address of the serial engine's register block.
+ * @cmd:       Command/Operation to setup in the secondary sequencer.
+ * @params:    Parameter for the sequencer command.
+ *
+ * This function is used to configure the secondary sequencer with the
+ * command and its assoicated parameters.
+ */
+void geni_se_setup_s_cmd(void __iomem *base, u32 cmd, u32 params);
+

s/assoicated/associated/ (twice)

Quoted 19 lines
drivers/soc/qcom/qcom-geni-se.c new file +19 -0
+/**
+ * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
+ * @wrapper_dev:       QUP Wrapper Device to which the TX buffer is mapped.
+ * @base:              Base address of the SE register block.
+ * @tx_buf:            Pointer to the TX buffer.
+ * @tx_len:            Length of the TX buffer.
+ * @tx_dma:            Pointer to store the mapped DMA address.
+ *
+ * This function is used to prepare the buffers for DMA TX.
+ *
+ * Return:     0 on success, standard Linux error codes on error/failure.
+ */
+int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
+                       void *tx_buf, int tx_len, dma_addr_t *tx_dma)
+{
+       int ret;
+
+       if (unlikely(!wrapper_dev || !base || !tx_buf || !tx_len || !tx_dma))
+               return -EINVAL;

drivers/soc/qcom/qcom-geni-se.c line 784

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+       ret = geni_se_map_buf(wrapper_dev, tx_dma, tx_buf, tx_len,
+                                   DMA_TO_DEVICE);
+       if (ret)
+               return ret;
+
+       geni_write_reg(7, base, SE_DMA_TX_IRQ_EN_SET);
+       geni_write_reg((u32)(*tx_dma), base, SE_DMA_TX_PTR_L);
+       geni_write_reg((u32)((*tx_dma) >> 32), base, SE_DMA_TX_PTR_H);
+       geni_write_reg(1, base, SE_DMA_TX_ATTR);

Bjorn touched on this, but as someone trying to understand what's going on it would be great to see #defines for the magic values in here (7 and 1)

drivers/soc/qcom/qcom-geni-se.c line 488

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+void geni_se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
+                               unsigned long *cfg0, unsigned long *cfg1)
+{
+       u32 cfg[4] = {0};
+       int len;
+       int temp_bpw = bpw;
+       int idx_start = (msb_to_lsb ? (bpw - 1) : 0);
+       int idx = idx_start;
+       int idx_delta = (msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE);
+       int ceil_bpw = ((bpw & (BITS_PER_BYTE - 1)) ?
+                       ((bpw & ~(BITS_PER_BYTE - 1)) + BITS_PER_BYTE) : bpw);
+       int iter = (ceil_bpw * pack_words) >> 3;

Is the shift by 3 here really meant to divide by BITS_PER_BYTE? It might be clearer to divide by BITS_PER_BYTE and let the compiler convert that into a shift.

drivers/soc/qcom/qcom-geni-se.c line 500

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+       int i;
+
+       if (unlikely(iter <= 0 || iter > 4)) {
+               *cfg0 = 0;
+               *cfg1 = 0;
+               return;
+       }
+
+       for (i = 0; i < iter; i++) {
+               len = (temp_bpw < BITS_PER_BYTE) ?
+                               (temp_bpw - 1) : BITS_PER_BYTE - 1;
+               cfg[i] = ((idx << 5) | (msb_to_lsb << 4) | (len << 1));

...more magic numbers here. These are register bitfields? It would be great to get the field shifts defined.

drivers/soc/qcom/qcom-geni-se.c line 510

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+               idx = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+                               ((i + 1) * BITS_PER_BYTE) + idx_start :
+                               idx + idx_delta;
+               temp_bpw = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+                               bpw : (temp_bpw - BITS_PER_BYTE);
+       }
+       cfg[iter - 1] |= 1;
+       *cfg0 = cfg[0] | (cfg[1] << 10);
+       *cfg1 = cfg[2] | (cfg[3] << 10);
+}

...more magic shifts here.

drivers/soc/qcom/qcom-geni-se.c line 535

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+void geni_se_config_packing(void __iomem *base, int bpw,
+                           int pack_words, bool msb_to_lsb)
+{
+       unsigned long cfg0, cfg1;
+
+       geni_se_get_packing_config(bpw, pack_words, msb_to_lsb, &cfg0, &cfg1);
+       geni_write_reg(cfg0, base, SE_GENI_TX_PACKING_CFG0);
+       geni_write_reg(cfg1, base, SE_GENI_TX_PACKING_CFG1);
+       geni_write_reg(cfg0, base, SE_GENI_RX_PACKING_CFG0);
+       geni_write_reg(cfg1, base, SE_GENI_RX_PACKING_CFG1);
+       if (pack_words || bpw == 32)
+               geni_write_reg((bpw >> 4), base, SE_GENI_BYTE_GRAN);
+}

...Same here for the bpw >> 4.

Thanks,
Evan
--
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

#28 lore raw

Re: [v2, 5/7] i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller

In reply to Karthikeyan Ramasubramanian
Quoted 9 lines · Karthikeyan Ramasubramanian

This bus driver supports the GENI based i2c hardware controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including I2C. The driver supports FIFO mode and DMA mode of transfer and switches modes dynamically depending on the size of the transfer.

Quoted 6 lines
---
 drivers/i2c/busses/Kconfig         |  10 +
 drivers/i2c/busses/Makefile        |   1 +
 drivers/i2c/busses/i2c-qcom-geni.c | 656 +++++++++++++++++++++++++++++++++++++
 3 files changed, 667 insertions(+)
 create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c

Newbie again, throwing in my two cents.

drivers/i2c/busses/i2c-qcom-geni.c line 160

Quoted 9 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +9 -0
+static inline void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c, int dfs)
+{
+       struct geni_i2c_clk_fld *itr = geni_i2c_clk_map + gi2c->clk_fld_idx;
+
+       geni_write_reg(dfs, gi2c->base, SE_GENI_CLK_SEL);
+
+       geni_write_reg((itr->clk_div << 4) | 1, gi2c->base, GENI_SER_M_CLK_CFG);
+       geni_write_reg(((itr->t_high << 20) | (itr->t_low << 10) |
+                       itr->t_cycle), gi2c->base, SE_I2C_SCL_COUNTERS);

It would be great to get these register field shifts defined, as they're otherwise fairly opaque.

Quoted 23 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +23 -0
+static irqreturn_t geni_i2c_irq(int irq, void *dev)
+{
+       struct geni_i2c_dev *gi2c = dev;
+       int i, j;
+       u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
+       u32 rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
+       u32 dm_tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
+       u32 dm_rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
+       u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
+       struct i2c_msg *cur = gi2c->cur;
+
+       if (!cur || (m_stat & M_CMD_FAILURE_EN) ||
+                   (dm_rx_st & (DM_I2C_CB_ERR)) ||
+                   (m_stat & M_CMD_ABORT_EN)) {
+
+               if (m_stat & M_GP_IRQ_1_EN)
+                       geni_i2c_err(gi2c, I2C_NACK);
+               if (m_stat & M_GP_IRQ_3_EN)
+                       geni_i2c_err(gi2c, I2C_BUS_PROTO);
+               if (m_stat & M_GP_IRQ_4_EN)
+                       geni_i2c_err(gi2c, I2C_ARB_LOST);
+               if (m_stat & M_CMD_OVERRUN_EN)
+                       geni_i2c_err(gi2c, GENI_OVERRUN);

drivers/i2c/busses/i2c-qcom-geni.c line 233

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+               if (m_stat & M_ILLEGAL_CMD_EN)
+                       geni_i2c_err(gi2c, GENI_ILLEGAL_CMD);
+               if (m_stat & M_CMD_ABORT_EN)
+                       geni_i2c_err(gi2c, GENI_ABORT_DONE);
+               if (m_stat & M_GP_IRQ_0_EN)
+                       geni_i2c_err(gi2c, GP_IRQ0);
+
+               if (!dma)
+                       writel_relaxed(0, (gi2c->base +
+                                          SE_GENI_TX_WATERMARK_REG));

The writes to the TX_WATERMARK_REG here and a little further down in the irq handler stick out to me. A comment as to why poking at the watermark register is necessary here would be very helpful.

-Evan

#42 lore raw

Re: [v2, 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian

drivers/tty/serial/qcom_geni_serial.c line 897

Quoted 4 lines · Karthikeyan Ramasubramanian
drivers/tty/serial/qcom_geni_serial.c new file +4 -0
+static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
+{
+       unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
+               32000000, 48000000, 64000000, 80000000, 96000000, 100000000};

This table should be static const, right?

#21 lore raw

Re: [v2,3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Karthikeyan Ramasubramanian

Hi,

Quoted 24 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

---
 drivers/soc/qcom/Kconfig        |    8 +
 drivers/soc/qcom/Makefile       |    1 +
 drivers/soc/qcom/qcom-geni-se.c | 1016 +++++++++++++++++++++++++++++++++++++++
 include/linux/qcom-geni-se.h    |  807 +++++++++++++++++++++++++++++++
 4 files changed, 1832 insertions(+)
 create mode 100644 drivers/soc/qcom/qcom-geni-se.c
 create mode 100644 include/linux/qcom-geni-se.h
drivers/soc/qcom/Kconfig +0 -0
index b81374b..b306d51 100644

drivers/soc/qcom/Kconfig line 7

Quoted 5 lines
drivers/soc/qcom/Kconfig +2 -0
@@ -3,6 +3,14 @@
 #
 menu "Qualcomm SoC drivers"
 
+config QCOM_GENI_SE
+       tristate "QCOM GENI Serial Engine Driver"

One tiny nit here: maybe it makes sense to add:

depends on ARCH_QCOM

...like all the other stuff in this file? Otherwise this ends up polluting .config files for non-Qualcomm architectures.

-Doug

#3 lore raw

Re: [PATCH v2 1/7] qcom-geni-se: Add QCOM GENI SE Driver summary

In reply to Bjorn Andersson
Quoted 8 lines · Bjorn Andersson
Quoted 6 lines · Karthikeyan Ramasubramanian

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a programmable module that is composed of multiple Serial Engines (SE) and can support various Serial Interfaces like UART, SPI, I2C, I3C, etc. This document provides a high level overview of the GENI based QUP Wrapper.

Quoted 5 lines
Quoted 1 line

Rather than adding a disconnected chunk of documentation move this into the driver(s), using the format described in
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html?highlight=kernel%20doc#overview-documentation-comments

I will move the documentation into the driver source file.

Quoted 8 lines

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

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#17 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Bjorn Andersson
Quoted 17 lines · Bjorn Andersson
Quoted 7 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

Quoted 7 lines
---
  drivers/soc/qcom/Kconfig        |    8 +
  drivers/soc/qcom/Makefile       |    1 +
  drivers/soc/qcom/qcom-geni-se.c | 1016 +++++++++++++++++++++++++++++++++++++++
Quoted 2 lines

I'm not aware of any non-serial-engine "geni" at Qualcomm, so can we drop the "se" throughout this driver?

Currently GENI is used to program just the serial engines. But it is not restricted to that. It can be used to program other hardware cores. Hence keeping "se" will help to clarify that this driver is meant for GENI based serial engines only.

Quoted 14 lines
Quoted 14 lines
  include/linux/qcom-geni-se.h    |  807 +++++++++++++++++++++++++++++++
  4 files changed, 1832 insertions(+)

create mode 100644 drivers/soc/qcom/qcom-geni-se.c create mode 100644 include/linux/qcom-geni-se.h

drivers/soc/qcom/Kconfig +0 -0
index b81374b..b306d51 100644
@@ -3,6 +3,14 @@
  #
  menu "Qualcomm SoC drivers"
 
Quoted 5 lines

drivers/soc/qcom/Kconfig line 7

Quoted 2 lines
drivers/soc/qcom/Kconfig +2 -0
+config QCOM_GENI_SE
+	tristate "QCOM GENI Serial Engine Driver"

Options in drivers/soc/qcom/Kconfig should have "depends on ARCH_QCOM", as the makefile in this directory won't be processed when !ARCH_QCOM.

I will update the config to depend on ARCH_QCOM.

Quoted 63 lines
Quoted 29 lines
drivers/soc/qcom/Kconfig +6 -0
+	help
+	  This module is used to manage Generic Interface (GENI) firmware based
+	  Qualcomm Technologies, Inc. Universal Peripheral (QUP) Wrapper. This
+	  module is also used to manage the common aspects of multiple Serial
+	  Engines present in the QUP.
+
  config QCOM_GLINK_SSR
  	tristate "Qualcomm Glink SSR driver"
  	depends on RPMSG
drivers/soc/qcom/Makefile +1 -0
index 40c56f6..74d5db8 100644
@@ -1,4 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_QCOM_GENI_SE) +=	qcom-geni-se.o
  obj-$(CONFIG_QCOM_GLINK_SSR) +=	glink_ssr.o
  obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
  obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

drivers/soc/qcom/qcom-geni-se.c line 19

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+#include <linux/clk.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/list.h>

This isn't used.

drivers/soc/qcom/qcom-geni-se.c line 23

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/pm_runtime.h>

Is this used?

Quoted 4 lines

drivers/soc/qcom/qcom-geni-se.c line 25

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+#include <linux/qcom-geni-se.h>
+#include <linux/spinlock.h>

Is this used?

I will remove including unused header files.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 30

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+#define MAX_CLK_PERF_LEVEL 32
+
+/**
+ * @struct geni_se_device - Data structure to represent the QUP Wrapper Core

Make this name indicate that this is the wrapper; e.g. struct geni_wrapper

geni_wrapper makes sense.

Quoted 10 lines
Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +9 -0
+ * @dev:		Device pointer of the QUP wrapper core.
+ * @base:		Base address of this instance of QUP wrapper core.
+ * @m_ahb_clk:		Handle to the primary AHB clock.
+ * @s_ahb_clk:		Handle to the secondary AHB clock.
+ * @geni_dev_lock:	Lock to protect the device elements.
+ * @num_clk_levels:	Number of valid clock levels in clk_perf_tbl.
+ * @clk_perf_tbl:	Table of clock frequency input to Serial Engine clock.
+ */
+struct geni_se_device {
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 43

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	struct device *dev;
+	void __iomem *base;
+	struct clk *m_ahb_clk;
+	struct clk *s_ahb_clk;

As these two clocks always seems to be operated in tandem use clk_bulk_data to keep track of them and use the clk_bulk*() operations to simplify your prepare/unprepare sites.

I will use the clk_bulk* approach.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 44

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	struct mutex geni_dev_lock;

There's only one lock and it should be obvious from context that it's the lock of the geni_se_device, so naming this "lock" should be sufficient.

I will rename it to "lock".

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 50

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+	unsigned int num_clk_levels;
+	unsigned long *clk_perf_tbl;
+};
+
+/* Offset of QUP Hardware Version Register */
+#define QUP_HW_VER (0x4)

Drop the parenthesis. It would be nice if this define indicated that this is a register and not a value. E.g. call it QUP_HW_VER_REG.

Ok.

Quoted 10 lines
Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +9 -0
+
+#define HW_VER_MAJOR_MASK GENMASK(31, 28)
+#define HW_VER_MAJOR_SHFT 28
+#define HW_VER_MINOR_MASK GENMASK(27, 16)
+#define HW_VER_MINOR_SHFT 16
+#define HW_VER_STEP_MASK GENMASK(15, 0)
+
+/**
+ * geni_read_reg_nolog() - Helper function to read from a GENI register
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 65

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.
+ */
+unsigned int geni_read_reg_nolog(void __iomem *base, int offset)

Remove this function.

Ok.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 77

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+{
+	return readl_relaxed(base + offset);
+}
+EXPORT_SYMBOL(geni_read_reg_nolog);
+
+/**
+ * geni_write_reg_nolog() - Helper function to write into a GENI register
+ * @value:	Value to be written into the register.
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ */
+void geni_write_reg_nolog(unsigned int value, void __iomem *base, int offset)

Ditto

Ok.

Quoted 14 lines

drivers/soc/qcom/qcom-geni-se.c line 88

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+{
+	return writel_relaxed(value, (base + offset));
+}
+EXPORT_SYMBOL(geni_write_reg_nolog);
+
+/**
+ * geni_read_reg() - Helper function to read from a GENI register
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.

Drop the extra spaces after "Return:" in all your kerneldoc.

Ok.

Quoted 46 lines
Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+ */
+unsigned int geni_read_reg(void __iomem *base, int offset)
+{
+	return readl_relaxed(base + offset);
+}
+EXPORT_SYMBOL(geni_read_reg);

drivers/soc/qcom/qcom-geni-se.c line 104

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+/**
+ * geni_write_reg() - Helper function to write into a GENI register
+ * @value:	Value to be written into the register.
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ */
+void geni_write_reg(unsigned int value, void __iomem *base, int offset)
+{
+	return writel_relaxed(value, (base + offset));

As written, this function adds no value and I find it quite confusing that this is used both for read/writes on the wrapper as well as the individual functions.Ok.

Compare:

	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);

with just inlining:

	writel(common_geni_m_irq_en, base + SE_GENI_M_IRQ_EN);
Quoted 16 lines
drivers/soc/qcom/qcom-geni-se.c new file +16 -0
+}
+EXPORT_SYMBOL(geni_write_reg);
+
+/**
+ * geni_get_qup_hw_version() - Read the QUP wrapper Hardware version
+ * @wrapper_dev:	Pointer to the corresponding QUP wrapper core.
+ * @major:		Buffer for Major Version field.
+ * @minor:		Buffer for Minor Version field.
+ * @step:		Buffer for Step Version field.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */
+int geni_get_qup_hw_version(struct device *wrapper_dev, unsigned int *major,
+			    unsigned int *minor, unsigned int *step)
+{
+	unsigned int version;
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 124

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !major || !minor || !step)
+		return -EINVAL;

This would only happen during development, as the engineer calls the function incorrectly. Consider it a contract that these has to be valid and skip the checks.

Ok.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 128

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -ENODEV;

Make the children acquire the geni_se_dev handle (keep the type opaque) and pass that instead of wrapper_dev. Then you can just drop this chunk.

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 134

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	version = geni_read_reg(geni_se_dev->base, QUP_HW_VER);
+	*major = (version & HW_VER_MAJOR_MASK) >> HW_VER_MAJOR_SHFT;
+	*minor = (version & HW_VER_MINOR_MASK) >> HW_VER_MINOR_SHFT;
+	*step = version & HW_VER_STEP_MASK;
+	return 0;

If you implement these two changes there's no way this function can fail, so you don't have to return a value here.

Ok.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 144

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+}
+EXPORT_SYMBOL(geni_get_qup_hw_version);
+
+/**
+ * geni_se_get_proto() - Read the protocol configured for a serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * Return:	Protocol value as configured in the serial engine.
+ */
+int geni_se_get_proto(void __iomem *base)

I keep reading this as "geni set get proto", you should be fine just dropping _se_ from these function names. And if you want to denote that it's the Qualcomm GENI then make it qcom_geni_*.

"_se" prefix is used to help differentiate operations on a serial engine from those on the wrapper. I can rename it as geni_se_read_proto to avoid the confusion.

Quoted 8 lines

But more importantly, it is not obvious when reading this driver that the typeless "base" being passed is that of the individual functional block, and not the wrapper.

If you want to do this in an "object oriented" fashion create a struct that's common for all geni instances, include it in the context of the individual function devices and pass it into these functions.

There is a structure named geni_se_rsc to group resources associated with a serial engine. I can rename it to geni_serial_engine and include the opaque "base" address in that structure. That structure can be passed as an input parameter to all the serial engine operations.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 149

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+{
+	int proto;
+
+	proto = ((geni_read_reg(base, GENI_FW_REVISION_RO)
+			& FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT);

Don't do everything in one go, as you can't fit it on one line anyways. Writing it like this instead makes it easier to read:

Quoted 5 lines
	u32 val;

	val = readl(base + GENI_FW_S_REVISION_RO);

	return (val & FW_REV_PROTOCOL_MSK) >> FW_REV_PROTOCOL_SHFT;

Ok.

Quoted 16 lines

drivers/soc/qcom/qcom-geni-se.c line 157

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	return proto;
+}
+EXPORT_SYMBOL(geni_se_get_proto);
+
+static int geni_se_irq_en(void __iomem *base)
+{
+	unsigned int common_geni_m_irq_en;
+	unsigned int common_geni_s_irq_en;

The size of these values isn't unsigned int, it's u32. And if you give them a shorter name the function becomes easier to read.

Further more, as you don't care about ordering you don't need two of them either. So you should be able to just do:

Quoted 9 lines
	u32 val;

	val = readl(base + SE_GENI_M_IRQ_EN);
	val |= M_COMMON_GENI_M_IRQ_EN;
	writel(val, base + SE_GENI_M_IRQ_EN);

	val = readl(base + SE_GENI_S_IRQ_EN);
	val |= S_COMMON_GENI_S_IRQ_EN;
	writel(val, base + SE_GENI_S_IRQ_EN);

Ok.

Quoted 13 lines

drivers/soc/qcom/qcom-geni-se.c line 167

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	common_geni_m_irq_en = geni_read_reg(base, SE_GENI_M_IRQ_EN);
+	common_geni_s_irq_en = geni_read_reg(base, SE_GENI_S_IRQ_EN);
+	/* Common to all modes */
+	common_geni_m_irq_en |= M_COMMON_GENI_M_IRQ_EN;
+	common_geni_s_irq_en |= S_COMMON_GENI_S_IRQ_EN;
+
+	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);
+	geni_write_reg(common_geni_s_irq_en, base, SE_GENI_S_IRQ_EN);
+	return 0;

And as this can't fail there's no reason to have a return value.

Ok.

Quoted 21 lines
Quoted 21 lines
drivers/soc/qcom/qcom-geni-se.c new file +20 -0
+}
+
+
+static void geni_se_set_rx_rfr_wm(void __iomem *base, unsigned int rx_wm,
+				  unsigned int rx_rfr)
+{
+	geni_write_reg(rx_wm, base, SE_GENI_RX_WATERMARK_REG);
+	geni_write_reg(rx_rfr, base, SE_GENI_RX_RFR_WATERMARK_REG);
+}
+
+static int geni_se_io_set_mode(void __iomem *base)
+{
+	unsigned int io_mode;
+	unsigned int geni_dma_mode;
+
+	io_mode = geni_read_reg(base, SE_IRQ_EN);
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+
+	io_mode |= (GENI_M_IRQ_EN | GENI_S_IRQ_EN);
+	io_mode |= (DMA_TX_IRQ_EN | DMA_RX_IRQ_EN);
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 193

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+	geni_dma_mode &= ~GENI_DMA_MODE_EN;
+
+	geni_write_reg(io_mode, base, SE_IRQ_EN);
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	return 0;

As this function can't fail, don't return a value.

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 200

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+}
+
+static void geni_se_io_init(void __iomem *base)
+{
+	unsigned int io_op_ctrl;
+	unsigned int geni_cgc_ctrl;
+	unsigned int dma_general_cfg;

These are all u32, be explicit.

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 206

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	geni_cgc_ctrl = geni_read_reg(base, GENI_CGC_CTRL);
+	dma_general_cfg = geni_read_reg(base, SE_DMA_GENERAL_CFG);
+	geni_cgc_ctrl |= DEFAULT_CGC_EN;
+	dma_general_cfg |= (AHB_SEC_SLV_CLK_CGC_ON | DMA_AHB_SLV_CFG_ON |
+			DMA_TX_CLK_CGC_ON | DMA_RX_CLK_CGC_ON);

Drop the parenthesis and there's no harm in making multiple assignments in favour of splitting the line.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 209

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	io_op_ctrl = DEFAULT_IO_OUTPUT_CTRL_MSK;
+	geni_write_reg(geni_cgc_ctrl, base, GENI_CGC_CTRL);
+	geni_write_reg(dma_general_cfg, base, SE_DMA_GENERAL_CFG);

Is there a reason why this chunk of code is a mix of 3 independent register updates?

I am not sure I understand the context of your question. This is how the hardware programming manual is describing to program the registers as part of initializing a serial engine. Please let me know if this is not the information you are looking for.

Quoted 13 lines

drivers/soc/qcom/qcom-geni-se.c line 219

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	geni_write_reg(io_op_ctrl, base, GENI_OUTPUT_CTRL);
+	geni_write_reg(FORCE_DEFAULT, base, GENI_FORCE_DEFAULT_REG);
+}
+
+/**
+ * geni_se_init() - Initialize the GENI Serial Engine
+ * @base:	Base address of the serial engine's register block.
+ * @rx_wm:	Receive watermark to be configured.
+ * @rx_rfr_wm:	Ready-for-receive watermark to be configured.

What's the unit for these?

The unit is the number of hardware FIFO words.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 224

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+ *
+ * This function is used to initialize the GENI serial engine, configure
+ * receive watermark and ready-for-receive watermarks.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.

As neither geni_se_io_set_mode() nor geni_se_irq_en() can fail there's no way geni_se_init() can fail and as such you don't need a return value of this function.

Ok.

Quoted 23 lines

drivers/soc/qcom/qcom-geni-se.c line 236

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+ */
+int geni_se_init(void __iomem *base, unsigned int rx_wm, unsigned int rx_rfr)
+{
+	int ret;
+
+	geni_se_io_init(base);
+	ret = geni_se_io_set_mode(base);
+	if (ret)
+		return ret;
+
+	geni_se_set_rx_rfr_wm(base, rx_wm, rx_rfr);
+	ret = geni_se_irq_en(base);

Just inline these two functions here.

drivers/soc/qcom/qcom-geni-se.c line 239

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_init);

This is an excellent candidate for initializing a common "geni function"-struct shared among the children, i.e. make this:

Quoted 6 lines

void geni_init_port(struct geni_port *port, struct device *dev,

		    size_t rx_wm, rfr_wm);

And have this do the ioremap of the memory of dev and initialize some common "geni_port" struct, then you can pass this to some set of geni_port_*() helper functions.

Sure, this sounds like a good place to do ioremap of children and initialize common serial engine resources.

Quoted 11 lines

drivers/soc/qcom/qcom-geni-se.c line 246

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+static int geni_se_select_fifo_mode(void __iomem *base)
+{
+	int proto = geni_se_get_proto(base);
+	unsigned int common_geni_m_irq_en;
+	unsigned int common_geni_s_irq_en;
+	unsigned int geni_dma_mode;

These are of type u32.

Quoted 2 lines

If you use more succinct names the function will be easier to read; what about master, slave and mode? (Or m_en, s_en and mode)

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 253

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_TX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_RX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_IRQ_EN);

Use lowercase for the hex constants.

Ok.

Quoted 12 lines

drivers/soc/qcom/qcom-geni-se.c line 261

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+
+	common_geni_m_irq_en = geni_read_reg(base, SE_GENI_M_IRQ_EN);
+	common_geni_s_irq_en = geni_read_reg(base, SE_GENI_S_IRQ_EN);
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+	if (proto != UART) {
+		common_geni_m_irq_en |=
+			(M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN |
+			M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);

Drop the parenthesis, split the assignment in multiple to make things not span 3 lines.

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 264

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		common_geni_s_irq_en |= S_CMD_DONE_EN;
+	}
+	geni_dma_mode &= ~GENI_DMA_MODE_EN;

Please group things that are related.

The compiler doesn't care if you stretch the life time of your local variables through your functions, but the brain does.

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 193

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+	geni_write_reg(common_geni_m_irq_en, base, SE_GENI_M_IRQ_EN);
+	geni_write_reg(common_geni_s_irq_en, base, SE_GENI_S_IRQ_EN);
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	return 0;

This can't fail, and you ignore the returned value in geni_se_select_mode().

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 274

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+}
+
+static int geni_se_select_dma_mode(void __iomem *base)
+{
+	unsigned int geni_dma_mode = 0;

This is u32, can be shorten to "mode" and it's first use is an assignment - so you don't have to initialize it here.

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 253

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	geni_write_reg(0, base, SE_GSI_EVENT_EN);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_TX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_DMA_RX_IRQ_CLR);
+	geni_write_reg(0xFFFFFFFF, base, SE_IRQ_EN);

Please lower case your hex constants.

Ok.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 286

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+
+	geni_dma_mode = geni_read_reg(base, SE_GENI_DMA_MODE_EN);
+	geni_dma_mode |= GENI_DMA_MODE_EN;
+	geni_write_reg(geni_dma_mode, base, SE_GENI_DMA_MODE_EN);
+	return 0;

Can't fail.

Ok.

Quoted 17 lines

drivers/soc/qcom/qcom-geni-se.c line 298

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+}
+
+/**
+ * geni_se_select_mode() - Select the serial engine transfer mode
+ * @base:	Base address of the serial engine's register block.
+ * @mode:	Transfer mode to be selected.
+ *
+ * Return:	0 on success, standard Linux error codes on failure.
+ */
+int geni_se_select_mode(void __iomem *base, int mode)
+{
+	int ret = 0;

Drop the return value and "ret", if you want to help the developer of child devices you can start off by a WARN_ON(mode != FIFO_MODE && mode != SE_DMA);

Ok.

Quoted 36 lines
Quoted 22 lines
drivers/soc/qcom/qcom-geni-se.c new file +21 -0
+
+	switch (mode) {
+	case FIFO_MODE:
+		geni_se_select_fifo_mode(base);
+		break;
+	case SE_DMA:
+		geni_se_select_dma_mode(base);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_select_mode);
+
+/**
+ * geni_se_setup_m_cmd() - Setup the primary sequencer
+ * @base:	Base address of the serial engine's register block.
+ * @cmd:	Command/Operation to setup in the primary sequencer.

drivers/soc/qcom/qcom-geni-se.c line 329

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @params:	Parameter for the sequencer command.
+ *
+ * This function is used to configure the primary sequencer with the
+ * command and its assoicated parameters.
+ */
+void geni_se_setup_m_cmd(void __iomem *base, u32 cmd, u32 params)
+{
+	u32 m_cmd = (cmd << M_OPCODE_SHFT);
+
+	m_cmd |= (params & M_PARAMS_MSK);

Rather than initializing the variable during declaration and then amending the value it's cleaner if you do:

Quoted 1 line
	val = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);

Ok.

Quoted 24 lines
Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	geni_write_reg(m_cmd, base, SE_GENI_M_CMD0);
+}
+EXPORT_SYMBOL(geni_se_setup_m_cmd);
+

[..]

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+/**
+ * geni_se_get_tx_fifo_depth() - Get the TX fifo depth of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the depth i.e. number of elements in the

drivers/soc/qcom/qcom-geni-se.c line 423

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * TX fifo of the serial engine.
+ *
+ * Return:	TX fifo depth in units of FIFO words.
+ */
+int geni_se_get_tx_fifo_depth(void __iomem *base)
+{
+	int tx_fifo_depth;
+
+	tx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_0)
+			& TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT);

It easier to read this way:

Quoted 5 lines
	u32 val;

	val = readl(base, SE_HW_PARAM_0);

	return (val & TX_FIFO_DEPTH_MSK) >> TX_FIFO_DEPTH_SHFT;

Ok.

Quoted 15 lines
Quoted 15 lines
drivers/soc/qcom/qcom-geni-se.c new file +14 -0
+	return tx_fifo_depth;
+}
+EXPORT_SYMBOL(geni_se_get_tx_fifo_depth);
+
+/**
+ * geni_se_get_tx_fifo_width() - Get the TX fifo width of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the width i.e. word size per element in the
+ * TX fifo of the serial engine.
+ *
+ * Return:	TX fifo width in bits
+ */
+int geni_se_get_tx_fifo_width(void __iomem *base)
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 443

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+{
+	int tx_fifo_width;
+
+	tx_fifo_width = ((geni_read_reg(base, SE_HW_PARAM_0)
+			& TX_FIFO_WIDTH_MSK) >> TX_FIFO_WIDTH_SHFT);
+	return tx_fifo_width;

Ditto.

Ok.

Quoted 14 lines
Quoted 14 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+}
+EXPORT_SYMBOL(geni_se_get_tx_fifo_width);
+
+/**
+ * geni_se_get_rx_fifo_depth() - Get the RX fifo depth of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ *
+ * This function is used to get the depth i.e. number of elements in the
+ * RX fifo of the serial engine.
+ *
+ * Return:	RX fifo depth in units of FIFO words
+ */
+int geni_se_get_rx_fifo_depth(void __iomem *base)
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 462

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+{
+	int rx_fifo_depth;
+
+	rx_fifo_depth = ((geni_read_reg(base, SE_HW_PARAM_1)
+			& RX_FIFO_DEPTH_MSK) >> RX_FIFO_DEPTH_SHFT);
+	return rx_fifo_depth;

Ditto.

Ok.

Quoted 22 lines
Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+}
+EXPORT_SYMBOL(geni_se_get_rx_fifo_depth);
+
+/**
+ * geni_se_get_packing_config() - Get the packing configuration based on input
+ * @bpw:	Bits of data per transfer word.

drivers/soc/qcom/qcom-geni-se.c line 478

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @pack_words:	Number of words per fifo element.
+ * @msb_to_lsb:	Transfer from MSB to LSB or vice-versa.
+ * @cfg0:	Output buffer to hold the first half of configuration.
+ * @cfg1:	Output buffer to hold the second half of configuration.
+ *
+ * This function is used to calculate the packing configuration based on
+ * the input packing requirement and the configuration logic.
+ */
+void geni_se_get_packing_config(int bpw, int pack_words, bool msb_to_lsb,
+				unsigned long *cfg0, unsigned long *cfg1)

This function is used only from geni_se_config_packing() which writes the new config to the associated registers and from the serial driver that does the same - but here pack_words differ for rx and tx.

Quoted 3 lines

If you improve geni_se_config_packing() to take rx and tx fifo sizes independently you don't have to expose this function to the client drivers and you don't need to return cfg0 and cfg1 like you do here.

Ok.

Quoted 57 lines
Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+{
+	u32 cfg[4] = {0};
+	int len;

drivers/soc/qcom/qcom-geni-se.c line 491

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	int temp_bpw = bpw;
+	int idx_start = (msb_to_lsb ? (bpw - 1) : 0);
+	int idx = idx_start;
+	int idx_delta = (msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE);
+	int ceil_bpw = ((bpw & (BITS_PER_BYTE - 1)) ?
+			((bpw & ~(BITS_PER_BYTE - 1)) + BITS_PER_BYTE) : bpw);
+	int iter = (ceil_bpw * pack_words) >> 3;
+	int i;
+
+	if (unlikely(iter <= 0 || iter > 4)) {

Don't use unlikely(), this function is not called one per port, there's no need to clutter the code to "optimize" it.

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+		*cfg0 = 0;
+		*cfg1 = 0;
+		return;
+	}

drivers/soc/qcom/qcom-geni-se.c line 505

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+
+	for (i = 0; i < iter; i++) {
+		len = (temp_bpw < BITS_PER_BYTE) ?
+				(temp_bpw - 1) : BITS_PER_BYTE - 1;
+		cfg[i] = ((idx << 5) | (msb_to_lsb << 4) | (len << 1));
+		idx = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+				((i + 1) * BITS_PER_BYTE) + idx_start :
+				idx + idx_delta;
+		temp_bpw = ((temp_bpw - BITS_PER_BYTE) <= 0) ?
+				bpw : (temp_bpw - BITS_PER_BYTE);

Each operation in this loop depend on temp_bpw being smaller or larger than BITS_PER_BYTE, please rewrite it with a single if/else based on this.

drivers/soc/qcom/qcom-geni-se.c

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+	}
+	cfg[iter - 1] |= 1;

The 1 you're writing here looks like an "EOF". It would be nice with a comment describing the format of these 4 registers and the meaning of BIT(0).

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +13 -0
+	*cfg0 = cfg[0] | (cfg[1] << 10);
+	*cfg1 = cfg[2] | (cfg[3] << 10);
+}
+EXPORT_SYMBOL(geni_se_get_packing_config);
+
+/**
+ * geni_se_config_packing() - Packing configuration of the serial engine
+ * @base:	Base address of the serial engine's register block.
+ * @bpw:	Bits of data per transfer word.
+ * @pack_words:	Number of words per fifo element.
+ * @msb_to_lsb:	Transfer from MSB to LSB or vice-versa.
+ *
+ * This function is used to configure the packing rules for the current
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 526

Quoted 6 lines

+ * transfer.
+ */

drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+void geni_se_config_packing(void __iomem *base, int bpw,
+			    int pack_words, bool msb_to_lsb)
+{
+	unsigned long cfg0, cfg1;

These are u32.

Ok.

Quoted 12 lines
Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+
+	geni_se_get_packing_config(bpw, pack_words, msb_to_lsb, &cfg0, &cfg1);
+	geni_write_reg(cfg0, base, SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg(cfg1, base, SE_GENI_TX_PACKING_CFG1);
+	geni_write_reg(cfg0, base, SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg(cfg1, base, SE_GENI_RX_PACKING_CFG1);
+	if (pack_words || bpw == 32)
+		geni_write_reg((bpw >> 4), base, SE_GENI_BYTE_GRAN);
+}
+EXPORT_SYMBOL(geni_se_config_packing);
+
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 542

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+static void geni_se_clks_off(struct geni_se_rsc *rsc)
+{
+	struct geni_se_device *geni_se_dev;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))

Drop the unlikely(). Why would you be passed a rsc with wrapper_dev NULL?

Used it just to handle any development time issues. I will remove the unlikely().

Quoted 16 lines
Quoted 16 lines
drivers/soc/qcom/qcom-geni-se.c new file +15 -0
+		return;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return;
+
+	clk_disable_unprepare(rsc->se_clk);
+	clk_disable_unprepare(geni_se_dev->s_ahb_clk);
+	clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+}
+
+/**
+ * geni_se_resources_off() - Turn off resources associated with the serial
+ *                           engine
+ * @rsc:	Handle to resources associated with the serial engine.
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 563

Quoted 6 lines

+ *
+ * Return: 0 on success, standard Linux error codes on failure/error.
+ */

drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+int geni_se_resources_off(struct geni_se_rsc *rsc)
+{
+	int ret = 0;

No need to initialize ret.

Ok.

Quoted 13 lines

drivers/soc/qcom/qcom-geni-se.c line 570

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+	struct geni_se_device *geni_se_dev;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))

Only child devices would call this, so it's unlikely that this is a probe defer.

Quoted 3 lines

Also the returned value is not used.

And drop the unlikely()

Ok.

Quoted 10 lines
Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +9 -0
+		return -ENODEV;
+
+	ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_sleep);
+	if (ret)
+		return ret;
+
+	geni_se_clks_off(rsc);
+	return 0;
+}
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 585

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+EXPORT_SYMBOL(geni_se_resources_off);
+
+static int geni_se_clks_on(struct geni_se_rsc *rsc)
+{
+	int ret;
+	struct geni_se_device *geni_se_dev;

If you name this "geni" instead, or "wrapper" the rest will be cleaner.

Ok.

Quoted 12 lines
Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -EPROBE_DEFER;
+
+	ret = clk_prepare_enable(geni_se_dev->m_ahb_clk);
+	if (ret)
+		return ret;
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 602

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	ret = clk_prepare_enable(geni_se_dev->s_ahb_clk);
+	if (ret) {
+		clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+		return ret;
+	}

These two could be dealt with in a single clk_bulk_prepare_enable().

Ok.

Quoted 21 lines
Quoted 21 lines
drivers/soc/qcom/qcom-geni-se.c new file +20 -0
+
+	ret = clk_prepare_enable(rsc->se_clk);
+	if (ret) {
+		clk_disable_unprepare(geni_se_dev->s_ahb_clk);
+		clk_disable_unprepare(geni_se_dev->m_ahb_clk);
+	}
+	return ret;
+}
+
+/**
+ * geni_se_resources_on() - Turn on resources associated with the serial
+ *                          engine
+ * @rsc:	Handle to resources associated with the serial engine.
+ *
+ * Return:	0 on success, standard Linux error codes on failure/error.
+ */
+int geni_se_resources_on(struct geni_se_rsc *rsc)
+{
+	int ret = 0;
+	struct geni_se_device *geni_se_dev;
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 570

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	if (unlikely(!rsc || !rsc->wrapper_dev))
+		return -EINVAL;
+
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))

As with geni_se_resources_off()

Ok.

Quoted 13 lines

drivers/soc/qcom/qcom-geni-se.c line 635

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+		return -EPROBE_DEFER;
+
+	ret = geni_se_clks_on(rsc);
+	if (ret)
+		return ret;
+
+	ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_active);

pinctrl_pm_select_default_state(rsc->dev);

So you need the dev associated with the rsc.

Quoted 16 lines
Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	if (ret)
+		geni_se_clks_off(rsc);
+
+	return ret;

drivers/soc/qcom/qcom-geni-se.c line 649

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+}
+EXPORT_SYMBOL(geni_se_resources_on);
+
+/**
+ * geni_se_clk_tbl_get() - Get the clock table to program DFS
+ * @rsc:	Resource for which the clock table is requested.
+ * @tbl:	Table in which the output is returned.
+ *
+ * This function is called by the protocol drivers to determine the different
+ * clock frequencies supported by Serail Engine Core Clock. The protocol

s/Serail/Serial/

Ok.

Quoted 17 lines
Quoted 7 lines

+ * drivers use the output to determine the clock frequency index to be
+ * programmed into DFS.
+ *
+ * Return: number of valid performance levels in the table on success,
+ * standard Linux error codes on failure.
+ */

drivers/soc/qcom/qcom-geni-se.c line 663

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+int geni_se_clk_tbl_get(struct geni_se_rsc *rsc, unsigned long **tbl)
+{
+	struct geni_se_device *geni_se_dev;
+	int i;
+	unsigned long prev_freq = 0;
+	int ret = 0;
+
+	if (unlikely(!rsc || !rsc->wrapper_dev || !rsc->se_clk || !tbl))

Drop the "unlikely", you're only calling this once.

Ok.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 666

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		return -EINVAL;
+
+	*tbl = NULL;

Don't touch tbl on error.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 592

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+	if (unlikely(!geni_se_dev))
+		return -EPROBE_DEFER;

How would this even be possible? This function should only be called by child devices, which per definition means that this device been probed.

I agree. Prior to this patchset, the serial engine nodes were not children nodes of wrapper devices. Hence the check existed. Now that the device tree nodes are re-structured, this check can be removed.

Quoted 12 lines

drivers/soc/qcom/qcom-geni-se.c line 676

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+
+	mutex_lock(&geni_se_dev->geni_dev_lock);
+	if (geni_se_dev->clk_perf_tbl) {
+		*tbl = geni_se_dev->clk_perf_tbl;
+		ret = geni_se_dev->num_clk_levels;
+		goto exit_se_clk_tbl_get;
+	}

You're never freeing clk_perf_tbl, and the only reason you have geni_dev_lock is to protect the "cached" array in geni_se_dev.

Quoted 3 lines

Move the allocation and generation of clk_perf_tbl to geni_se_probe() and store the value, then make this function just return that array. That way you can drop the lock and the code becomes cleaner.

Currently this driver is initializing in arch_init. It can be moved to module_init stage as long as the clk_round_rate() returns -EPROBE_DEFER when it is not ready. I will look into it and do the appropriate change.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 679

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	geni_se_dev->clk_perf_tbl = kzalloc(sizeof(*geni_se_dev->clk_perf_tbl) *
+						MAX_CLK_PERF_LEVEL, GFP_KERNEL);

Use kcalloc()

Ok.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 689

Quoted 11 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+	if (!geni_se_dev->clk_perf_tbl) {
+		ret = -ENOMEM;
+		goto exit_se_clk_tbl_get;
+	}
+
+	for (i = 0; i < MAX_CLK_PERF_LEVEL; i++) {
+		geni_se_dev->clk_perf_tbl[i] = clk_round_rate(rsc->se_clk,
+								prev_freq + 1);
+		if (geni_se_dev->clk_perf_tbl[i] == prev_freq) {
+			geni_se_dev->clk_perf_tbl[i] = 0;

Use a local variable to keep the return value of clk_round_rate(), that way you don't have to revert the value here (not that it matters...) and you don't need to line wrap the assignment above.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 692

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+			break;
+		}
+		prev_freq = geni_se_dev->clk_perf_tbl[i];

...and then you don't need a separate local variable to keep track of the last value...

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 697

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+	}
+	geni_se_dev->num_clk_levels = i;
+	*tbl = geni_se_dev->clk_perf_tbl;
+	ret = geni_se_dev->num_clk_levels;
+exit_se_clk_tbl_get:

Name your labels based on what action they perform, e.g. "out_unlock" (not err_unlock here because it's the successful path as well)

Ok.

Quoted 22 lines
Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	mutex_unlock(&geni_se_dev->geni_dev_lock);
+	return ret;
+}
+EXPORT_SYMBOL(geni_se_clk_tbl_get);
+
+/**
+ * geni_se_clk_freq_match() - Get the matching or closest SE clock frequency
+ * @rsc:	Resource for which the clock frequency is requested.

drivers/soc/qcom/qcom-geni-se.c line 715

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @req_freq:	Requested clock frequency.
+ * @index:	Index of the resultant frequency in the table.
+ * @res_freq:	Resultant frequency which matches or is closer to the
+ *		requested frequency.
+ * @exact:	Flag to indicate exact multiple requirement of the requested
+ *		frequency .
+ *
+ * This function is called by the protocol drivers to determine the matching
+ * or closest frequency of the Serial Engine clock to be selected in order
+ * to meet the performance requirements.

What's the benefit compared to calling clk_round_rate()?

Quoted 3 lines

Given that the function can return a rate that is a fraction of the requested frequency even though "exact" is set, this description isn't explaining the entire picture.

I agree, the description makes it look like clk_round_rate(). But it is different from clk_round_rate() in the sense that it will try to return the matching or exact multiple of the requested frequency. If there is no matching or exact multiple value found, then it returns the closest floor frequency available. I will update the description accordingly.

Quoted 23 lines
Quoted 3 lines

+ *
+ * Return: 0 on success, standard Linux error codes on failure.

Returning the new clockrate would make more sense.

Quoted 17 lines

+ */

drivers/soc/qcom/qcom-geni-se.c new file +16 -0
+int geni_se_clk_freq_match(struct geni_se_rsc *rsc, unsigned long req_freq,
+			   unsigned int *index, unsigned long *res_freq,
+			   bool exact)
+{
+	unsigned long *tbl;
+	int num_clk_levels;
+	int i;
+
+	num_clk_levels = geni_se_clk_tbl_get(rsc, &tbl);
+	if (num_clk_levels < 0)
+		return num_clk_levels;
+
+	if (num_clk_levels == 0)
+		return -EFAULT;
+
+	*res_freq = 0;
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 738

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	for (i = 0; i < num_clk_levels; i++) {
+		if (!(tbl[i] % req_freq)) {
+			*index = i;
+			*res_freq = tbl[i];

So this will return a frequency that divides the requested frequency without a remainder, will index be used to calculate a multiplier from this?

The serial interface drivers need to program the hardware register with the index of the clock rate from the clock controller source. Hence the index is returned.

Quoted 11 lines

drivers/soc/qcom/qcom-geni-se.c line 745

Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+			return 0;
+		}
+
+		if (!(*res_freq) || ((tbl[i] > *res_freq) &&
+				     (tbl[i] < req_freq))) {
+			*index = i;
+			*res_freq = tbl[i];

What if there's a previous value in tbl that given some multiplier has a smaller difference to the requested frequency?

At this point the requirement is to return matching or exact multiple of the requested frequency. If those criteria are not met, return the closest floor frequency.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 749

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+		}
+	}
+
+	if (exact || !(*res_freq))

*res_freq can't be 0, because in the case that num_clk_levels is 0 you already returned -EFAULT above, in all other cases you will assign it at least once.

Ok.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 752

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+		return -ENOKEY;
+
+	return 0;

Why not use the return value for the calculated frequency?

With frequency being unsigned long, I dont see a clean way to return any error.

Quoted 24 lines
Quoted 8 lines
drivers/soc/qcom/qcom-geni-se.c new file +7 -0
+}
+EXPORT_SYMBOL(geni_se_clk_freq_match);
+
+/**
+ * geni_se_tx_dma_prep() - Prepare the Serial Engine for TX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the TX buffer is mapped.
+ * @base:		Base address of the SE register block.

drivers/soc/qcom/qcom-geni-se.c line 769

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * @tx_buf:		Pointer to the TX buffer.
+ * @tx_len:		Length of the TX buffer.
+ * @tx_dma:		Pointer to store the mapped DMA address.
+ *
+ * This function is used to prepare the buffers for DMA TX.
+ *
+ * Return:	0 on success, standard Linux error codes on error/failure.
+ */
+int geni_se_tx_dma_prep(struct device *wrapper_dev, void __iomem *base,
+			void *tx_buf, int tx_len, dma_addr_t *tx_dma)

All child devices will have a "base", so if you move that into what you today call a geni_se_rsc and you pass that to all these functions operating on behalf of the child device you have the first two parameters passed in the same object.

Quoted 6 lines

A "tx_len" is typically of type size_t.

Also note that there are no other buf than tx_buf, no other len than tx_len and no other dma address than tx_dma in this function, so you can drop "tx_" without loosing any information - but improving code cleanliness.

Ok.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 774

Quoted 6 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+{
+	int ret;
+
+	if (unlikely(!wrapper_dev || !base || !tx_buf || !tx_len || !tx_dma))
+		return -EINVAL;

Reduce the error checking here.

Ok.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 777

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	ret = geni_se_map_buf(wrapper_dev, tx_dma, tx_buf, tx_len,
+				    DMA_TO_DEVICE);

I think you should pass the wrapper itself to geni_se_tx_dma_prep() and if you name this "wrapper" (instead of wrapper_dev) you're under 80 chars and don't need the line break.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 781

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	if (ret)
+		return ret;
+
+	geni_write_reg(7, base, SE_DMA_TX_IRQ_EN_SET);

So that's DMA_RX_IRQ_EN | DMA_TX_IRQ_EN | GENI_M_IRQ_EN?

No, that is DMA_DONE_EN (BIT 0), EOT_EN (BIT 1) and AHB_ERR_EN (BIT 2).

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 783

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+	geni_write_reg((u32)(*tx_dma), base, SE_DMA_TX_PTR_L);
+	geni_write_reg((u32)((*tx_dma) >> 32), base, SE_DMA_TX_PTR_H);

If you return the dma_addr_t from this function you will have the happy side effect of being able to use tx_dma directly instead of *tx_dma and you can remove some craziness from these calls.

Quoted 3 lines

drivers/soc/qcom/qcom-geni-se.c line 784

Quoted 1 line
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	geni_write_reg(1, base, SE_DMA_TX_ATTR);

This "1" would be nice to have some clarification on.

This indicates to the hardware that the current buffer is of End-of-Transfer Type. I will add a comment here or replace the magic 1 with an appropriate preprocessor macro.

Quoted 12 lines
Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+	geni_write_reg(tx_len, base, SE_DMA_TX_LEN);
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_tx_dma_prep);
+
+/**
+ * geni_se_rx_dma_prep() - Prepare the Serial Engine for RX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @base:		Base address of the SE register block.
+ * @rx_buf:		Pointer to the RX buffer.
+ * @rx_len:		Length of the RX buffer.
Quoted 8 lines
Quoted 5 lines

+ * @rx_dma: Pointer to store the mapped DMA address.
+ *
+ * This function is used to prepare the buffers for DMA RX.
+ *
+ * Return: 0 on success, standard Linux error codes on error/failure.

The only real error that can come out of this is dma_mapping_error(), so just return the dma_addr_t.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 803

Quoted 4 lines

+ */

drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+int geni_se_rx_dma_prep(struct device *wrapper_dev, void __iomem *base,
+			void *rx_buf, int rx_len, dma_addr_t *rx_dma)

As with tx, drop all the "rx_". And pass that geni_se_rsc object instead.

Ok.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 815

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+{
+	int ret;
+
+	if (unlikely(!wrapper_dev || !base || !rx_buf || !rx_len || !rx_dma))
+		return -EINVAL;
+
+	ret = geni_se_map_buf(wrapper_dev, rx_dma, rx_buf, rx_len,
+				    DMA_FROM_DEVICE);
+	if (ret)
+		return ret;
+
+	geni_write_reg(7, base, SE_DMA_RX_IRQ_EN_SET);

We enable same interrupts for rx as tx? Why enable TX interrupt here?

No, the interrupts enabled are DMA_DONE_EN, EOT_EN and AHB_ERR_EN.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 818

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+	geni_write_reg((u32)(*rx_dma), base, SE_DMA_RX_PTR_L);
+	geni_write_reg((u32)((*rx_dma) >> 32), base, SE_DMA_RX_PTR_H);
+	/* RX does not have EOT bit */

Okay? How does this relate to the 0 being written into RX_ATTR?

Instead of EOT bit, this register has RX DMA mode bits. Writing 0 means the buffer is a single buffer. Writing 1 means the data is present as part of the command itself and 2 means the buffer is scatter-gather buffer.

Quoted 39 lines
Quoted 39 lines
drivers/soc/qcom/qcom-geni-se.c new file +38 -0
+	geni_write_reg(0, base, SE_DMA_RX_ATTR);
+	geni_write_reg(rx_len, base, SE_DMA_RX_LEN);
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_rx_dma_prep);
+
+/**
+ * geni_se_tx_dma_unprep() - Unprepare the Serial Engine after TX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @tx_dma:		DMA address of the TX buffer.
+ * @tx_len:		Length of the TX buffer.
+ *
+ * This function is used to unprepare the DMA buffers after DMA TX.
+ */
+void geni_se_tx_dma_unprep(struct device *wrapper_dev,
+			   dma_addr_t tx_dma, int tx_len)
+{
+	if (tx_dma)
+		geni_se_unmap_buf(wrapper_dev, &tx_dma, tx_len,
+						DMA_TO_DEVICE);
+}
+EXPORT_SYMBOL(geni_se_tx_dma_unprep);
+
+/**
+ * geni_se_rx_dma_unprep() - Unprepare the Serial Engine after RX DMA transfer
+ * @wrapper_dev:	QUP Wrapper Device to which the RX buffer is mapped.
+ * @rx_dma:		DMA address of the RX buffer.
+ * @rx_len:		Length of the RX buffer.
+ *
+ * This function is used to unprepare the DMA buffers after DMA RX.
+ */
+void geni_se_rx_dma_unprep(struct device *wrapper_dev,
+			   dma_addr_t rx_dma, int rx_len)
+{
+	if (rx_dma)
+		geni_se_unmap_buf(wrapper_dev, &rx_dma, rx_len,
+						DMA_FROM_DEVICE);
+}
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 860

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+EXPORT_SYMBOL(geni_se_rx_dma_unprep);
+
+/**
+ * geni_se_map_buf() - Map a single buffer into QUP wrapper device

I find the mixture of prepare and map in the API (where prepare also maps) confusing, but no-one calls genbi_se_map_buf() can it be made internal?

Sure it can be made internal and later exposed when the serial interface drivers need it.

Quoted 16 lines
Quoted 16 lines

+ * @wrapper_dev: Pointer to the corresponding QUP wrapper core.
+ * @iova: Pointer in which the mapped virtual address is stored.
+ * @buf: Address of the buffer that needs to be mapped.
+ * @size: Size of the buffer.
+ * @dir: Direction of the DMA transfer.
+ *
+ * This function is used to map an already allocated buffer into the
+ * QUP device space.
+ *
+ * Return: 0 on success, standard Linux error codes on failure/error.
+ */

drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+int geni_se_map_buf(struct device *wrapper_dev, dma_addr_t *iova,
+		    void *buf, size_t size, enum dma_data_direction dir)
+{
+	struct device *dev_p;
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 879

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !iova || !buf || !size)
+		return -EINVAL;

No need to check that the programmer of the intermediate function checked that the programmer of the client filled all these out correctly.

Ok.

Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 883

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (!geni_se_dev || !geni_se_dev->dev)
+		return -ENODEV;

Pass the geni_se_device from the child driver, to remove the need for this.

Ok.

Quoted 5 lines

drivers/soc/qcom/qcom-geni-se.c

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+
+	dev_p = geni_se_dev->dev;

Name your variables more succinct and you don't need this local alias.

Ok.

Quoted 5 lines

drivers/soc/qcom/qcom-geni-se.c line 887

Quoted 3 lines
drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+
+	*iova = dma_map_single(dev_p, buf, size, dir);

Just inline dma_map_single() in the functions calling this.

Ok.

Quoted 16 lines
Quoted 16 lines
drivers/soc/qcom/qcom-geni-se.c new file +15 -0
+	if (dma_mapping_error(dev_p, *iova))
+		return -EIO;
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_map_buf);
+
+/**
+ * geni_se_unmap_buf() - Unmap a single buffer from QUP wrapper device
+ * @wrapper_dev:	Pointer to the corresponding QUP wrapper core.
+ * @iova:		Pointer in which the mapped virtual address is stored.
+ * @size:		Size of the buffer.
+ * @dir:		Direction of the DMA transfer.
+ *
+ * This function is used to unmap an already mapped buffer from the
+ * QUP device space.
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 907

Quoted 5 lines

+ *
+ * Return: 0 on success, standard Linux error codes on failure/error.
+ */

drivers/soc/qcom/qcom-geni-se.c new file +2 -0
+int geni_se_unmap_buf(struct device *wrapper_dev, dma_addr_t *iova,
+		      size_t size, enum dma_data_direction dir)

There's no reason for iova to be a pointer. Just pass the dma_addr_t as is.

Ok.

Quoted 2 lines

Should this function really be exposed to the clients?

It can be made internal based on the current use-case.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 913

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+{
+	struct device *dev_p;
+	struct geni_se_device *geni_se_dev;
+
+	if (!wrapper_dev || !iova || !size)
+		return -EINVAL;

Reduce the error checking.

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 883

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +4 -0
+
+	geni_se_dev = dev_get_drvdata(wrapper_dev);
+	if (!geni_se_dev || !geni_se_dev->dev)
+		return -ENODEV;

And pass the geni_se_rsc to this function for symmetry purposes, which would give you the wrapper by just following the pointer and then the device from there.

Ok.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 920

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	dev_p = geni_se_dev->dev;
+	dma_unmap_single(dev_p, *iova, size, dir);

Just inline dma_unmap_single() in the calling functions.

Ok.

Quoted 12 lines

drivers/soc/qcom/qcom-geni-se.c line 928

Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +8 -0
+	return 0;
+}
+EXPORT_SYMBOL(geni_se_unmap_buf);
+
+static const struct of_device_id geni_se_dt_match[] = {
+	{ .compatible = "qcom,geni-se-qup", },
+	{}
+};

Move this next to the geni_se_driver below and don't forget the MODULE_DEVICE_TABLE()

Ok.

Quoted 9 lines

drivers/soc/qcom/qcom-geni-se.c line 934

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+static int geni_se_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct resource *res;
+	struct geni_se_device *geni_se_dev;

Just name this "geni".

Ok.

Quoted 4 lines

drivers/soc/qcom/qcom-geni-se.c

Quoted 2 lines
drivers/soc/qcom/qcom-geni-se.c new file +1 -0
+	int ret = 0;

No need to initialize ret, it's only ever used after assignment.

Ok.

Quoted 16 lines

drivers/soc/qcom/qcom-geni-se.c line 947

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+
+	geni_se_dev = devm_kzalloc(dev, sizeof(*geni_se_dev), GFP_KERNEL);
+	if (!geni_se_dev)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(dev, "%s: Mandatory resource info not found\n",
+			__func__);
+		devm_kfree(dev, geni_se_dev);
+		return -EINVAL;
+	}

It's idiomatic to not check for errors of platform_get_resource() as devm_ioremap_resource() will fail gracefully if this happens.

Ok, I will remove the check and use the error returned by devm_ioremap_resource, if any.

Quoted 6 lines

drivers/soc/qcom/qcom-geni-se.c line 950

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+	geni_se_dev->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR_OR_NULL(geni_se_dev->base)) {

This should be IS_ERR() only.

Ok.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 961

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+		dev_err(dev, "%s: Error mapping the resource\n", __func__);
+		devm_kfree(dev, geni_se_dev);
+		return -EFAULT;
+	}
+
+	geni_se_dev->m_ahb_clk = devm_clk_get(dev, "m-ahb");
+	if (IS_ERR(geni_se_dev->m_ahb_clk)) {
+		ret = PTR_ERR(geni_se_dev->m_ahb_clk);
+		dev_err(dev, "Err getting M AHB clk %d\n", ret);
+		devm_iounmap(dev, geni_se_dev->base);
+		devm_kfree(dev, geni_se_dev);

The reason we use the devm_ versions of these is so that we don't have to release our resources explicitly.

Ok, I will remove releasing the resources explicitly.

Quoted 15 lines

drivers/soc/qcom/qcom-geni-se.c line 973

Quoted 13 lines
drivers/soc/qcom/qcom-geni-se.c new file +12 -0
+		return ret;
+	}
+
+	geni_se_dev->s_ahb_clk = devm_clk_get(dev, "s-ahb");
+	if (IS_ERR(geni_se_dev->s_ahb_clk)) {
+		ret = PTR_ERR(geni_se_dev->s_ahb_clk);
+		dev_err(dev, "Err getting S AHB clk %d\n", ret);
+		devm_clk_put(dev, geni_se_dev->m_ahb_clk);
+		devm_iounmap(dev, geni_se_dev->base);
+		devm_kfree(dev, geni_se_dev);
+		return ret;
+	}

Use devm_clk_bulk_get().

Ok.

Quoted 10 lines

drivers/soc/qcom/qcom-geni-se.c line 979

Quoted 7 lines
drivers/soc/qcom/qcom-geni-se.c new file +6 -0
+
+	geni_se_dev->dev = dev;
+	mutex_init(&geni_se_dev->geni_dev_lock);
+	dev_set_drvdata(dev, geni_se_dev);
+	dev_dbg(dev, "GENI SE Driver probed\n");
+	return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);

You're not depopulating these devices when the wrapper goes away. Use devm_of_platform_populate() here instead to make that happen.

Ok.

Quoted 16 lines

drivers/soc/qcom/qcom-geni-se.c line 990

Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +11 -0
+}
+
+static int geni_se_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct geni_se_device *geni_se_dev = dev_get_drvdata(dev);
+
+	devm_clk_put(dev, geni_se_dev->s_ahb_clk);
+	devm_clk_put(dev, geni_se_dev->m_ahb_clk);
+	devm_iounmap(dev, geni_se_dev->base);
+	devm_kfree(dev, geni_se_dev);

Again, the reason to use devm_* is so that you don't have to free things...so if this is what you have here you don't even need a remove function.

Ok.

Quoted 19 lines
Quoted 19 lines
drivers/soc/qcom/qcom-geni-se.c new file +18 -0
+	return 0;
+}
+
+static struct platform_driver geni_se_driver = {
+	.driver = {
+		.name = "geni_se_qup",
+		.of_match_table = geni_se_dt_match,
+	},
+	.probe = geni_se_probe,
+	.remove = geni_se_remove,
+};
+
+static int __init geni_se_driver_init(void)
+{
+	return platform_driver_register(&geni_se_driver);
+}
+arch_initcall(geni_se_driver_init);
+
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 1013

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c new file +5 -0
+static void __exit geni_se_driver_exit(void)
+{
+	platform_driver_unregister(&geni_se_driver);
+}
+module_exit(geni_se_driver_exit);

Should be fine to just use module_platform_driver(), you need separate support for earlycon regardless.

Ok.

Quoted 13 lines
Quoted 12 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+
+MODULE_DESCRIPTION("GENI Serial Engine Driver");
+MODULE_LICENSE("GPL v2");
include/linux/qcom-geni-se.h new file +2 -0
new file mode 100644
index 0000000..5695da9
@@ -0,0 +1,807 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.

[..]

Quoted 4 lines
Quoted 2 lines

+ */
+

Use SPDX header as above.

Ok.

Quoted 9 lines

include/linux/qcom-geni-se.h line 20

Quoted 7 lines
include/linux/qcom-geni-se.h new file +6 -0
+#ifndef _LINUX_QCOM_GENI_SE
+#define _LINUX_QCOM_GENI_SE
+#include <linux/clk.h>
+#include <linux/dma-direction.h>
+#include <linux/io.h>
+#include <linux/list.h>

I don't think there's a need for io.h or list.h here.

Ok.

Quoted 9 lines

include/linux/qcom-geni-se.h line 26

Quoted 7 lines
include/linux/qcom-geni-se.h new file +6 -0
+
+/* Transfer mode supported by GENI Serial Engines */
+enum geni_se_xfer_mode {
+	INVALID,
+	FIFO_MODE,
+	SE_DMA,

These are quite bad names for things in a header file.

I am not sure if you are suggesting me to use a prefix to make these definitions look GENI specific. I would prefer some clarification in this regard.

Quoted 13 lines

include/linux/qcom-geni-se.h line 35

Quoted 10 lines
include/linux/qcom-geni-se.h new file +9 -0
+};
+
+/* Protocols supported by GENI Serial Engines */
+enum geni_se_protocol_types {
+	NONE,
+	SPI,
+	UART,
+	I2C,
+	I3C

Ditto

Quoted 13 lines

include/linux/qcom-geni-se.h line 46

Quoted 11 lines
include/linux/qcom-geni-se.h new file +11 -0
+};
+
+/**
+ * struct geni_se_rsc - GENI Serial Engine Resource
+ * @wrapper_dev:	Pointer to the parent QUP Wrapper core.
+ * @se_clk:		Handle to the core serial engine clock.
+ * @geni_pinctrl:	Handle to the pinctrl configuration.
+ * @geni_gpio_active:	Handle to the default/active pinctrl state.
+ * @geni_gpi_sleep:	Handle to the sleep pinctrl state.
+ */
+struct geni_se_rsc {

This looks like the common geni_port or geni_device I requested above.

Yes that is right. I will use it to include the serial engine base address.

Quoted 5 lines

include/linux/qcom-geni-se.h line 48

Quoted 3 lines
include/linux/qcom-geni-se.h new file +2 -0
+	struct device *wrapper_dev;
+	struct clk *se_clk;

The one and only clock can be named "clk".

Ok.

Quoted 10 lines

include/linux/qcom-geni-se.h line 51

Quoted 4 lines
include/linux/qcom-geni-se.h new file +3 -0
+	struct pinctrl *geni_pinctrl;
+	struct pinctrl_state *geni_gpio_active;
+	struct pinctrl_state *geni_gpio_sleep;

The associated struct device already has init, default, idle and sleep pinctrl states associated through the device->pins struct. Typically this means that if you provide a "default" and "sleep" state, the default will be selected when the device probes.

Quoted 2 lines

In order to select between the states call pinctrl_pm_select_{default,sleep,idle}_state(dev);

Ok.

Quoted 12 lines

include/linux/qcom-geni-se.h line 57

Quoted 7 lines
include/linux/qcom-geni-se.h new file +6 -0
+};
+
+#define PINCTRL_DEFAULT	"default"
+#define PINCTRL_SLEEP	"sleep"
+
+/* Common SE registers */

The purpose of the helper functions in the wrapper driver is to hide the common details from the individual function drivers, so move these defines into the c-file as they shouldn't be needed in the individual drivers.

I will move the register definitions that are accessed through helper functions inside the source file. I may have to keep those register definitions that are common and are directly accessed by the serial interface drivers here so that there are no duplicate definitions.

Quoted 4 lines
Quoted 2 lines

+#define GENI_INIT_CFG_REVISION (0x0)

Drop the parenthesis.

Ok.

Quoted 13 lines

[..]

include/linux/qcom-geni-se.h line 319

Quoted 8 lines
include/linux/qcom-geni-se.h new file +8 -0
+#ifdef CONFIG_QCOM_GENI_SE
+/**
+ * geni_read_reg_nolog() - Helper function to read from a GENI register
+ * @base:	Base address of the serial engine's register block.
+ * @offset:	Offset within the serial engine's register block.
+ *
+ * Return:	Return the contents of the register.
+ */

The kerneldoc goes in the implementation, not the header file. And you already have a copy there, so remove it from here.

Ok.

Quoted 7 lines
Quoted 2 lines

+unsigned int geni_read_reg_nolog(void __iomem *base, int offset);

[..]

Quoted 1 line

+#else

I see no point in providing dummy functions for these, just make the individual drivers either depend or select the core helpers.

Ok.

Quoted 9 lines

include/linux/qcom-geni-se.h line 649

Quoted 5 lines
include/linux/qcom-geni-se.h new file +4 -0
+static inline unsigned int geni_read_reg_nolog(void __iomem *base, int offset)
+{
+	return 0;
+}

Regards,
Bjorn

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#30 lore raw
In reply to Randy Dunlap
Quoted 8 lines · Randy Dunlap
Quoted 7 lines · Karthikeyan Ramasubramanian

Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper is a next generation programmable module for supporting a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial Interfaces using its internal Serial Engines (SE). The protocol supported by each interface is determined by the firmware loaded to the Serial Engine.

Quoted 8 lines
Quoted 4 lines

This patch series introduces GENI SE Driver to manage the GENI based QUP Wrapper and the common aspects of all SEs inside the QUP Wrapper. This patch series also introduces the UART and I2C Controller drivers to drive the SEs that are programmed with the respective protocols.

Hi,

Will there be follow-up drivers for SPI, I3C, etc.?

Yes.

Quoted 48 lines

Thanks.

Quoted 43 lines

[v2]
* Updated device tree bindings to describe the hardware
* Updated SE DT node as child node of QUP Wrapper DT node
* Moved common AHB clocks to QUP Wrapper DT node
* Use the standard "clock-frequency" I2C property
* Update compatible field in UART Controller to reflect hardware manual
* Addressed other device tree binding specific comments from Rob Herring

Karthikeyan Ramasubramanian (7):
qcom-geni-se: Add QCOM GENI SE Driver summary
dt-bindings: soc: qcom: Add device tree binding for GENI SE
soc: qcom: Add GENI based QUP Wrapper driver
dt-bindings: i2c: Add device tree bindings for GENI I2C Controller
i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C
controller
dt-bindings: serial: Add bindings for GENI based UART Controller
tty: serial: msm_geni_serial: Add serial driver support for GENI based
QUP

  .../devicetree/bindings/i2c/i2c-qcom-geni.txt      |   35 +
  .../devicetree/bindings/serial/qcom,geni-uart.txt  |   29 +
  .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  |   66 +
  Documentation/qcom-geni-se.txt                     |   56 +
  drivers/i2c/busses/Kconfig                         |   10 +
  drivers/i2c/busses/Makefile                        |    1 +
  drivers/i2c/busses/i2c-qcom-geni.c                 |  656 +++++++++
  drivers/soc/qcom/Kconfig                           |    8 +
  drivers/soc/qcom/Makefile                          |    1 +
  drivers/soc/qcom/qcom-geni-se.c                    | 1016 ++++++++++++++
  drivers/tty/serial/Kconfig                         |   10 +
  drivers/tty/serial/Makefile                        |    1 +
  drivers/tty/serial/qcom_geni_serial.c              | 1414 ++++++++++++++++++++
  include/linux/qcom-geni-se.h                       |  807 +++++++++++
  14 files changed, 4110 insertions(+)

create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt create mode 100644 Documentation/qcom-geni-se.txt
create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c
create mode 100644 drivers/soc/qcom/qcom-geni-se.c
create mode 100644 drivers/tty/serial/qcom_geni_serial.c
create mode 100644 include/linux/qcom-geni-se.h

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#14 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Rob Herring
Quoted 38 lines · Rob Herring
Quoted 37 lines · Bjorn Andersson
Quoted 34 lines · Rajendra Nayak

[]..

Quoted 22 lines
Quoted 9 lines
drivers/soc/qcom/qcom-geni-se.c new file +3 -0
new file mode 100644
index 0000000..3f43582
@@ -0,0 +1,1016 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *

drivers/soc/qcom/qcom-geni-se.c line 13

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ *
+ */

Please use SPDX style license header, i.e. this file should start with:

Quoted 4 lines

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

Looks like Mark Brown commented elsewhere [1] that we should use the C++ commenting style even for the Linux Foundation copyright?

[1] https://marc.info/?l=linux-clk&m=151497978626135&w=2

Quoted 8 lines
Quoted 3 lines

While I can agree with Mark on the ugliness of the mixed commenting style, this is the style that I found communicated and is what you find in other files.

Well, that's pretty new guidance. Moving target...

Given that Linus said '//' comments are the only thing C++ got right, I expect to see more of them.

I believe that in the source file I have to use C++ style comments(as per this discussion) and in the header file I have to use C-style comments (as per https://lwn.net/Articles/739183/ for reasons related to tooling). Please correct me otherwise.

Quoted 3 lines

Rob

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#18 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Karthik Ramasubramanian
Quoted 2 lines · Karthik Ramasubramanian
Quoted 1 line · Bjorn Andersson

On Fri 12 Jan 17:05 PST 2018, Karthikeyan Ramasubramanian wrote:

[..]

Quoted 6 lines
Quoted 2 lines

I'm not aware of any non-serial-engine "geni" at Qualcomm, so can we drop the "se" throughout this driver?

Currently GENI is used to program just the serial engines. But it is not restricted to that. It can be used to program other hardware cores. Hence keeping "se" will help to clarify that this driver is meant for GENI based serial engines only.

Okay, fair enough.

[..]

Quoted 1 line
Quoted 1 line
Quoted 1 line
drivers/soc/qcom/qcom-geni-se.c +0 -0

[..]

Quoted 16 lines
Quoted 8 lines

drivers/soc/qcom/qcom-geni-se.c line 206

Quoted 5 lines
drivers/soc/qcom/qcom-geni-se.c +5 -0
+	geni_cgc_ctrl = geni_read_reg(base, GENI_CGC_CTRL);
+	dma_general_cfg = geni_read_reg(base, SE_DMA_GENERAL_CFG);
+	geni_cgc_ctrl |= DEFAULT_CGC_EN;
+	dma_general_cfg |= (AHB_SEC_SLV_CLK_CGC_ON | DMA_AHB_SLV_CFG_ON |
+			DMA_TX_CLK_CGC_ON | DMA_RX_CLK_CGC_ON);

Drop the parenthesis and there's no harm in making multiple assignments in favour of splitting the line.

Ok.

Quoted 7 lines

drivers/soc/qcom/qcom-geni-se.c line 209

Quoted 4 lines
drivers/soc/qcom/qcom-geni-se.c +3 -0
+	io_op_ctrl = DEFAULT_IO_OUTPUT_CTRL_MSK;
+	geni_write_reg(geni_cgc_ctrl, base, GENI_CGC_CTRL);
+	geni_write_reg(dma_general_cfg, base, SE_DMA_GENERAL_CFG);

Is there a reason why this chunk of code is a mix of 3 independent register updates?

Quoted 4 lines

I am not sure I understand the context of your question. This is how the hardware programming manual is describing to program the registers as part of initializing a serial engine. Please let me know if this is not the information you are looking for.

Can you please double check with the hardware guys if it really is required that you do:

a = read(A)
b = read(B)

modify a
modify b
assign c

write(a)
write(b)
write(c)

And if that is the case, then try to make things as easy to read as possible - e.g. by inlining the value of "c" and adding an empty line between reads, modifications and writes as I did here.

Regards,
Bjorn

#16 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to a message not in the archive
Quoted 3 lines · Karthik Ramasubramanian
Quoted 2 lines · Rob Herring
Quoted 1 line · Bjorn Andersson

On Thu 18 Jan 01:13 PST 2018, Rajendra Nayak wrote:

[..]

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines

Please use SPDX style license header, i.e. this file should start with:

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. */

Quoted 5 lines

Looks like Mark Brown commented elsewhere [1] that we should use the C++ commenting style even for the Linux Foundation copyright?

[1] https://marc.info/?l=linux-clk&m=151497978626135&w=2

While I can agree with Mark on the ugliness of the mixed commenting style, this is the style that I found communicated and is what you find in other files.

Quoted 8 lines
Quoted 4 lines

Well, that's pretty new guidance. Moving target...

Given that Linus said '//' comments are the only thing C++ got right, I expect to see more of them.

I believe that in the source file I have to use C++ style comments(as per this discussion) and in the header file I have to use C-style comments (as per https://lwn.net/Articles/739183/ for reasons related to tooling). Please correct me otherwise.

I had missed that detail, you're right.

Thanks,
Bjorn
--
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

#43 lore raw

Re: [PATCH v2 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian
Quoted 15 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c

drivers/tty/serial/qcom_geni_serial.c line 1268

Quoted 7 lines
drivers/tty/serial/qcom_geni_serial.c new file +7 -0
+       if (!uport->membase) {
+               ret = -ENOMEM;
+               dev_err(&pdev->dev, "Err IO mapping serial iomem");
+               goto exit_geni_serial_probe;
+       }
+
+       dev_port->serial_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);

You need to include linux/pinctrl/consumer.h for devm_pinctrl_get

I couldn't compile test it w/o it.

#22 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

In reply to Karthikeyan Ramasubramanian
Quoted 15 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+int geni_se_resources_off(struct geni_se_rsc *rsc)
+{
+       int ret = 0;

drivers/soc/qcom/qcom-geni-se.c line 573

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+       struct geni_se_device *geni_se_dev;
+
+       if (unlikely(!rsc || !rsc->wrapper_dev))
+               return -EINVAL;
+
+       geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+       if (unlikely(!geni_se_dev))
+               return -ENODEV;
+
+       ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_sleep);

You need to include linux/pinctrl/consumer.h for devm_pinctrl_get

I couldn't compile test it w/o it.

#23 lore raw

Re: [PATCH v2 3/7] soc: qcom: Add GENI based QUP Wrapper driver

Quoted 30 lines · Amit Kucheria
Quoted 15 lines · Karthikeyan Ramasubramanian

This driver manages the Generic Interface (GENI) firmware based Qualcomm Universal Peripheral (QUP) Wrapper. GENI based QUP is the next generation programmable module composed of multiple Serial Engines (SE) and supports a wide range of serial interfaces like UART, SPI, I2C, I3C, etc. This driver also enables managing the serial interface independent aspects of Serial Engines.

drivers/soc/qcom/qcom-geni-se.c new file +3 -0
+int geni_se_resources_off(struct geni_se_rsc *rsc)
+{
+       int ret = 0;

drivers/soc/qcom/qcom-geni-se.c line 573

Quoted 10 lines
drivers/soc/qcom/qcom-geni-se.c new file +10 -0
+       struct geni_se_device *geni_se_dev;
+
+       if (unlikely(!rsc || !rsc->wrapper_dev))
+               return -EINVAL;
+
+       geni_se_dev = dev_get_drvdata(rsc->wrapper_dev);
+       if (unlikely(!geni_se_dev))
+               return -ENODEV;
+
+       ret = pinctrl_select_state(rsc->geni_pinctrl, rsc->geni_gpio_sleep);

You need to include linux/pinctrl/consumer.h for devm_pinctrl_get

Quoted 2 lines

I couldn't compile test it w/o it.

I think marking the dependencies might help with this compilation issue. Else I will include the concerned header file. One way or the other, I will ensure that this issue does not get hit in my follow-up patch series.

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#44 lore raw

Re: [v2, 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian
Quoted 20 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
drivers/tty/serial/Kconfig +0 -0
index b788fee..1be30e5 100644

drivers/tty/serial/Kconfig config SERIAL_MSM_CONSOLE · line 1105

Quoted 8 lines
drivers/tty/serial/Kconfig +5 -0
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
 	select SERIAL_CORE_CONSOLE
 	select SERIAL_EARLYCON
 
+config SERIAL_QCOM_GENI
+	tristate "QCOM on-chip GENI based serial port support"
+	depends on ARCH_QCOM
+	select SERIAL_CORE
+	select SERIAL_CORE_CONSOLE

Serial console drivers have to be bool, not tristate. Building a console driver as module doesn't make sense (it is needed before modules are loaded). It also results in a build failure due to a symbol which is not exported.

Quoted 335 lines
drivers/tty/serial/Kconfig +5 -0
+	select SERIAL_EARLYCON
+	help
+	  Serial driver for Qualcomm Technologies Inc's GENI based QUP
+	  hardware.
+
 config SERIAL_VT8500
 	bool "VIA VT8500 on-chip serial port support"
 	depends on ARCH_VT8500
drivers/tty/serial/Makefile +1 -0
index 842d185..64a8d82 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_serial.o
 obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
 obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_MSM) += msm_serial.o
+obj-$(CONFIG_SERIAL_QCOM_GENI) += qcom_geni_serial.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
 obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
drivers/tty/serial/qcom_geni_serial.c new file +309 -0
new file mode 100644
index 0000000..0dbd329
@@ -0,0 +1,1414 @@
+/*
+ * Copyright (c) 2017-2018, The Linux foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ */
+
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/console.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/qcom-geni-se.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+
+/* UART specific GENI registers */
+#define SE_UART_TX_TRANS_CFG		(0x25C)
+#define SE_UART_TX_WORD_LEN		(0x268)
+#define SE_UART_TX_STOP_BIT_LEN		(0x26C)
+#define SE_UART_TX_TRANS_LEN		(0x270)
+#define SE_UART_RX_TRANS_CFG		(0x280)
+#define SE_UART_RX_WORD_LEN		(0x28C)
+#define SE_UART_RX_STALE_CNT		(0x294)
+#define SE_UART_TX_PARITY_CFG		(0x2A4)
+#define SE_UART_RX_PARITY_CFG		(0x2A8)
+
+/* SE_UART_TRANS_CFG */
+#define UART_TX_PAR_EN		(BIT(0))
+#define UART_CTS_MASK		(BIT(1))
+
+/* SE_UART_TX_WORD_LEN */
+#define TX_WORD_LEN_MSK		(GENMASK(9, 0))
+
+/* SE_UART_TX_STOP_BIT_LEN */
+#define TX_STOP_BIT_LEN_MSK	(GENMASK(23, 0))
+#define TX_STOP_BIT_LEN_1	(0)
+#define TX_STOP_BIT_LEN_1_5	(1)
+#define TX_STOP_BIT_LEN_2	(2)
+
+/* SE_UART_TX_TRANS_LEN */
+#define TX_TRANS_LEN_MSK	(GENMASK(23, 0))
+
+/* SE_UART_RX_TRANS_CFG */
+#define UART_RX_INS_STATUS_BIT	(BIT(2))
+#define UART_RX_PAR_EN		(BIT(3))
+
+/* SE_UART_RX_WORD_LEN */
+#define RX_WORD_LEN_MASK	(GENMASK(9, 0))
+
+/* SE_UART_RX_STALE_CNT */
+#define RX_STALE_CNT		(GENMASK(23, 0))
+
+/* SE_UART_TX_PARITY_CFG/RX_PARITY_CFG */
+#define PAR_CALC_EN		(BIT(0))
+#define PAR_MODE_MSK		(GENMASK(2, 1))
+#define PAR_MODE_SHFT		(1)
+#define PAR_EVEN		(0x00)
+#define PAR_ODD			(0x01)
+#define PAR_SPACE		(0x10)
+#define PAR_MARK		(0x11)
+
+/* UART M_CMD OP codes */
+#define UART_START_TX		(0x1)
+#define UART_START_BREAK	(0x4)
+#define UART_STOP_BREAK		(0x5)
+/* UART S_CMD OP codes */
+#define UART_START_READ		(0x1)
+#define UART_PARAM		(0x1)
+
+#define UART_OVERSAMPLING	(32)
+#define STALE_TIMEOUT		(16)
+#define DEFAULT_BITS_PER_CHAR	(10)
+#define GENI_UART_NR_PORTS	(15)
+#define GENI_UART_CONS_PORTS	(1)
+#define DEF_FIFO_DEPTH_WORDS	(16)
+#define DEF_TX_WM		(2)
+#define DEF_FIFO_WIDTH_BITS	(32)
+#define UART_CORE2X_VOTE	(10000)
+#define UART_CONSOLE_RX_WM	(2)
+
+static int owr;
+module_param(owr, int, 0644);
+
+struct qcom_geni_serial_port {
+	struct uart_port uport;
+	char name[20];
+	unsigned int tx_fifo_depth;
+	unsigned int tx_fifo_width;
+	unsigned int rx_fifo_depth;
+	unsigned int tx_wm;
+	unsigned int rx_wm;
+	unsigned int rx_rfr;
+	int xfer_mode;
+	bool port_setup;
+	unsigned int *rx_fifo;
+	int (*handle_rx)(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+	struct device *wrapper_dev;
+	struct geni_se_rsc serial_rsc;
+	unsigned int xmit_size;
+	void *rx_buf;
+	unsigned int cur_baud;
+};
+
+static const struct uart_ops qcom_geni_serial_pops;
+static struct uart_driver qcom_geni_console_driver;
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port);
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set);
+static void qcom_geni_serial_stop_rx(struct uart_port *uport);
+
+static atomic_t uart_line_id = ATOMIC_INIT(0);
+
+#define GET_DEV_PORT(uport) \
+	container_of(uport, struct qcom_geni_serial_port, uport)
+
+static struct qcom_geni_serial_port qcom_geni_console_port;
+
+static void qcom_geni_serial_config_port(struct uart_port *uport, int cfg_flags)
+{
+	if (cfg_flags & UART_CONFIG_TYPE)
+		uport->type = PORT_MSM;
+}
+
+static unsigned int qcom_geni_cons_get_mctrl(struct uart_port *uport)
+{
+	return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS;
+}
+
+static void qcom_geni_cons_set_mctrl(struct uart_port *uport,
+							unsigned int mctrl)
+{
+}
+
+static const char *qcom_geni_serial_get_type(struct uart_port *uport)
+{
+	return "MSM";
+}
+
+static struct qcom_geni_serial_port *get_port_from_line(int line)
+{
+	struct qcom_geni_serial_port *port = NULL;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		port = ERR_PTR(-ENXIO);
+	port = &qcom_geni_console_port;
+	return port;
+}
+
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set)
+{
+	int iter = 0;
+	unsigned int reg;
+	bool met = false;
+	struct qcom_geni_serial_port *port = NULL;
+	bool cond = false;
+	unsigned int baud = 115200;
+	unsigned int fifo_bits = DEF_FIFO_DEPTH_WORDS * DEF_FIFO_WIDTH_BITS;
+	unsigned long total_iter = 2000;
+
+
+	if (uport->private_data) {
+		port = GET_DEV_PORT(uport);
+		baud = (port->cur_baud ? port->cur_baud : 115200);
+		fifo_bits = port->tx_fifo_depth * port->tx_fifo_width;
+		/*
+		 * Total polling iterations based on FIFO worth of bytes to be
+		 * sent at current baud .Add a little fluff to the wait.
+		 */
+		total_iter = ((fifo_bits * USEC_PER_SEC) / baud) / 10;
+		total_iter += 50;
+	}
+
+	while (iter < total_iter) {
+		reg = geni_read_reg_nolog(uport->membase, offset);
+		cond = reg & bit_field;
+		if (cond == set) {
+			met = true;
+			break;
+		}
+		udelay(10);
+		iter++;
+	}
+	return met;
+}
+
+static void qcom_geni_serial_setup_tx(struct uart_port *uport,
+				unsigned int xmit_size)
+{
+	u32 m_cmd = 0;
+
+	geni_write_reg_nolog(xmit_size, uport->membase, SE_UART_TX_TRANS_LEN);
+	m_cmd |= (UART_START_TX << M_OPCODE_SHFT);
+	geni_write_reg_nolog(m_cmd, uport->membase, SE_GENI_M_CMD0);
+	/*
+	 * Writes to enable the primary sequencer should go through before
+	 * exiting this function.
+	 */
+	mb();
+}
+
+static void qcom_geni_serial_poll_cancel_tx(struct uart_port *uport)
+{
+	int done = 0;
+	unsigned int irq_clear = M_CMD_DONE_EN;
+	unsigned int geni_status = 0;
+
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_DONE_EN, true);
+	if (!done) {
+		geni_write_reg_nolog(M_GENI_CMD_ABORT, uport->membase,
+					SE_GENI_M_CMD_CTRL_REG);
+		owr++;
+		irq_clear |= M_CMD_ABORT_EN;
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+							M_CMD_ABORT_EN, true);
+	}
+	geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+	if (geni_status & M_GENI_CMD_ACTIVE)
+		owr++;
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_abort_rx(struct uart_port *uport)
+{
+	unsigned int irq_clear = S_CMD_DONE_EN;
+
+	geni_se_abort_s_cmd(uport->membase);
+	/* Ensure this goes through before polling. */
+	mb();
+	irq_clear |= S_CMD_ABORT_EN;
+	qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_ABORT, false);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(FORCE_DEFAULT, uport->membase, GENI_FORCE_DEFAULT_REG);
+}
+
+#ifdef CONFIG_CONSOLE_POLL
+static int qcom_geni_serial_get_char(struct uart_port *uport)
+{
+	unsigned int rx_fifo;
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+			M_SEC_IRQ_EN, true)))
+		return -ENXIO;
+
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	geni_write_reg_nolog(m_irq_status, uport->membase,
+						SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase,
+						SE_GENI_S_IRQ_CLEAR);
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_RX_FIFO_STATUS,
+			RX_FIFO_WC_MSK, true)))
+		return -ENXIO;
+
+	/*
+	 * Read the Rx FIFO only after clearing the interrupt registers and
+	 * getting valid RX fifo status.
+	 */
+	mb();
+	rx_fifo = geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+	rx_fifo &= 0xFF;
+	return rx_fifo;
+}
+
+static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
+					unsigned char c)
+{
+	int b = (int) c;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_write_reg_nolog(port->tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, 1);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+				M_TX_FIFO_WATERMARK_EN, true))
+		WARN_ON(1);
+	geni_write_reg_nolog(b, uport->membase, SE_GENI_TX_FIFOn);
+	geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,

drivers/tty/serial/qcom_geni_serial.c line 319

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+							SE_GENI_M_IRQ_CLEAR);
+	/*
+	 * Ensure FIFO write goes through before polling for status but.
+	 */
+	mb();
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)

"if defined(CONFIG_SERIAL_CORE_CONSOLE)" doesn't make much sense here since the Kconfig entry selects it. Given that, the entire conditional is unnecessary since it will always be true.

Quoted 1,095 lines
drivers/tty/serial/qcom_geni_serial.c new file +1095 -0
+static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
+{
+	geni_write_reg_nolog(ch, uport->membase, SE_GENI_TX_FIFOn);
+	/*
+	 * Ensure FIFO write clear goes through before
+	 * next iteration.
+	 */
+	mb();
+
+}
+
+static void
+__qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
+				unsigned int count)
+{
+	int new_line = 0;
+	int i;
+	int bytes_to_send = count;
+	int fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	int tx_wm = DEF_TX_WM;
+
+	for (i = 0; i < count; i++) {
+		if (s[i] == '\n')
+			new_line++;
+	}
+
+	bytes_to_send += new_line;
+	geni_write_reg_nolog(tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, bytes_to_send);
+	i = 0;
+	while (i < count) {
+		u32 chars_to_write = 0;
+		u32 avail_fifo_bytes = (fifo_depth - tx_wm);
+
+		/*
+		 * 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 (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_TX_FIFO_WATERMARK_EN, true))
+			break;
+		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,
+						qcom_geni_serial_wr_char);
+		geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+		/* Ensure this goes through before polling for WM IRQ again.*/
+		mb();
+		i += chars_to_write;
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+
+static void qcom_geni_serial_console_write(struct console *co, const char *s,
+			      unsigned int count)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *port;
+	int locked = 1;
+	unsigned long flags;
+
+	WARN_ON(co->index < 0 || co->index >= GENI_UART_NR_PORTS);
+
+	port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(port))
+		return;
+
+	uport = &port->uport;
+	if (oops_in_progress)
+		locked = spin_trylock_irqsave(&uport->lock, flags);
+	else
+		spin_lock_irqsave(&uport->lock, flags);
+
+	if (locked) {
+		__qcom_geni_serial_console_write(uport, s, count);
+		spin_unlock_irqrestore(&uport->lock, flags);
+	}
+}
+
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx)
+{
+	int i, c;
+	unsigned char *rx_char;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	for (i = 0; i < rx_fifo_wc; i++) {
+		int bytes = 4;
+
+		*(qcom_port->rx_fifo) =
+			geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+		if (drop_rx)
+			continue;
+		rx_char = (unsigned char *)qcom_port->rx_fifo;
+
+		if (i == (rx_fifo_wc - 1)) {
+			if (rx_last && rx_last_byte_valid)
+				bytes = rx_last_byte_valid;
+		}
+		for (c = 0; c < bytes; c++) {
+			char flag = TTY_NORMAL;
+			int sysrq;
+
+			uport->icount.rx++;
+			sysrq = uart_handle_sysrq_char(uport, rx_char[c]);
+			if (!sysrq)
+				tty_insert_flip_char(tport, rx_char[c], flag);
+		}
+	}
+	if (!drop_rx)
+		tty_flip_buffer_push(tport);
+	return 0;
+}
+#else
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx)
+{
+	return -EPERM;
+}
+
+#endif /* (CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)) */
+
+static void qcom_geni_serial_start_tx(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned int geni_status;
+
+	if (qcom_port->xfer_mode == FIFO_MODE) {
+		geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+		if (geni_status & M_GENI_CMD_ACTIVE)
+			goto exit_start_tx;
+
+		if (!qcom_geni_serial_tx_empty(uport))
+			goto exit_start_tx;
+
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+						    SE_GENI_M_IRQ_EN);
+		geni_m_irq_en |= (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN);
+
+		geni_write_reg_nolog(qcom_port->tx_wm, uport->membase,
+						SE_GENI_TX_WATERMARK_REG);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+		/* Geni command setup should complete before returning.*/
+		mb();
+	}
+exit_start_tx:
+	return;
+}
+
+static void stop_tx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_m_irq_en &= ~M_CMD_DONE_EN;
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_m_irq_en &= ~M_TX_FIFO_WATERMARK_EN;
+		geni_write_reg_nolog(0, uport->membase,
+				     SE_GENI_TX_WATERMARK_REG);
+	}
+	port->xmit_size = 0;
+	geni_write_reg_nolog(geni_m_irq_en, uport->membase, SE_GENI_M_IRQ_EN);
+	geni_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_STATUS);
+	/* Possible stop tx is called multiple times. */
+	if (!(geni_status & M_GENI_CMD_ACTIVE))
+		return;
+
+	geni_se_cancel_m_cmd(uport->membase);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_CANCEL_EN, true)) {
+		geni_se_abort_m_cmd(uport->membase);
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_ABORT_EN, true);
+		geni_write_reg_nolog(M_CMD_ABORT_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	}
+	geni_write_reg_nolog(M_CMD_CANCEL_EN, uport, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_stop_tx(struct uart_port *uport)
+{
+	stop_tx_sequencer(uport);
+}
+
+static void start_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	if (geni_status & S_GENI_CMD_ACTIVE)
+		qcom_geni_serial_stop_rx(uport);
+
+	geni_se_setup_s_cmd(uport->membase, UART_START_READ, 0);
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+
+		geni_s_irq_en |= S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN;
+		geni_m_irq_en |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+	/*
+	 * Ensure the writes to the secondary sequencer and interrupt enables
+	 * go through.
+	 */
+	mb();
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+}
+
+static void qcom_geni_serial_start_rx(struct uart_port *uport)
+{
+	start_rx_sequencer(uport);
+}
+
+static void stop_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	u32 irq_clear = S_CMD_DONE_EN;
+	bool done;
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+		geni_s_irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);
+		geni_m_irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	/* Possible stop rx is called multiple times. */
+	if (!(geni_status & S_GENI_CMD_ACTIVE))
+		return;
+	geni_se_cancel_s_cmd(uport->membase);
+	/*
+	 * Ensure that the cancel goes through before polling for the
+	 * cancel control bit.
+	 */
+	mb();
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_CANCEL, false);
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	if ((geni_status & S_GENI_CMD_ACTIVE))
+		qcom_geni_serial_abort_rx(uport);
+}
+
+static void qcom_geni_serial_stop_rx(struct uart_port *uport)
+{
+	stop_rx_sequencer(uport);
+}
+
+static int qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop_rx)
+{
+	int ret = 0;
+	unsigned int rx_fifo_status;
+	unsigned int rx_fifo_wc = 0;
+	unsigned int rx_last_byte_valid = 0;
+	unsigned int rx_last = 0;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	rx_fifo_status = geni_read_reg_nolog(uport->membase,
+				SE_GENI_RX_FIFO_STATUS);
+	rx_fifo_wc = rx_fifo_status & RX_FIFO_WC_MSK;
+	rx_last_byte_valid = ((rx_fifo_status & RX_LAST_BYTE_VALID_MSK) >>
+						RX_LAST_BYTE_VALID_SHFT);
+	rx_last = rx_fifo_status & RX_LAST;
+	if (rx_fifo_wc)
+		port->handle_rx(uport, rx_fifo_wc, rx_last_byte_valid,
+							rx_last, drop_rx);
+	return ret;
+}
+
+static int qcom_geni_serial_handle_tx(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	struct circ_buf *xmit = &uport->state->xmit;
+	unsigned int avail_fifo_bytes = 0;
+	unsigned int bytes_remaining = 0;
+	int i = 0;
+	unsigned int tx_fifo_status;
+	unsigned int xmit_size;
+	unsigned int fifo_width_bytes = 1;
+	int temp_tail = 0;
+
+	xmit_size = uart_circ_chars_pending(xmit);
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+					SE_GENI_TX_FIFO_STATUS);
+	/* Both FIFO and framework buffer are drained */
+	if ((xmit_size == qcom_port->xmit_size) && !tx_fifo_status) {
+		qcom_port->xmit_size = 0;
+		uart_circ_clear(xmit);
+		qcom_geni_serial_stop_tx(uport);
+		goto exit_handle_tx;
+	}
+	xmit_size -= qcom_port->xmit_size;
+
+	avail_fifo_bytes = (qcom_port->tx_fifo_depth - qcom_port->tx_wm) *
+							fifo_width_bytes;
+	temp_tail = (xmit->tail + qcom_port->xmit_size) & (UART_XMIT_SIZE - 1);
+	if (xmit_size > (UART_XMIT_SIZE - temp_tail))
+		xmit_size = (UART_XMIT_SIZE - temp_tail);
+	if (xmit_size > avail_fifo_bytes)
+		xmit_size = avail_fifo_bytes;
+
+	if (!xmit_size)
+		goto exit_handle_tx;
+
+	qcom_geni_serial_setup_tx(uport, xmit_size);
+
+	bytes_remaining = xmit_size;
+	while (i < xmit_size) {
+		unsigned int tx_bytes;
+		unsigned int buf = 0;
+		int c;
+
+		tx_bytes = ((bytes_remaining < fifo_width_bytes) ?
+					bytes_remaining : fifo_width_bytes);
+
+		for (c = 0; c < tx_bytes ; c++)
+			buf |= (xmit->buf[temp_tail + c] << (c * 8));
+		geni_write_reg_nolog(buf, uport->membase, SE_GENI_TX_FIFOn);
+		i += tx_bytes;
+		temp_tail = (temp_tail + tx_bytes) & (UART_XMIT_SIZE - 1);
+		uport->icount.tx += tx_bytes;
+		bytes_remaining -= tx_bytes;
+		/* Ensure FIFO write goes through */
+		wmb();
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+	qcom_port->xmit_size += xmit_size;
+exit_handle_tx:
+	uart_write_wakeup(uport);
+	return ret;
+}
+
+static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
+{
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;
+	struct uart_port *uport = dev;
+	unsigned long flags;
+	unsigned int m_irq_en;
+	bool drop_rx = false;
+	struct tty_port *tport = &uport->state->port;
+
+	spin_lock_irqsave(&uport->lock, flags);
+	if (uport->suspended)
+		goto exit_geni_serial_isr;
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_write_reg_nolog(m_irq_status, uport->membase, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase, SE_GENI_S_IRQ_CLEAR);
+
+	if ((m_irq_status & M_ILLEGAL_CMD_EN)) {
+		WARN_ON(1);
+		goto exit_geni_serial_isr;
+	}
+
+	if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
+		uport->icount.overrun++;
+		tty_insert_flip_char(tport, 0, TTY_OVERRUN);
+	}
+
+	if ((m_irq_status & m_irq_en) &
+	    (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN))
+		qcom_geni_serial_handle_tx(uport);
+
+	if ((s_irq_status & S_GP_IRQ_0_EN) || (s_irq_status & S_GP_IRQ_1_EN)) {
+		if (s_irq_status & S_GP_IRQ_0_EN)
+			uport->icount.parity++;
+		drop_rx = true;
+	} else if ((s_irq_status & S_GP_IRQ_2_EN) ||
+		(s_irq_status & S_GP_IRQ_3_EN)) {
+		uport->icount.brk++;
+	}
+
+	if ((s_irq_status & S_RX_FIFO_WATERMARK_EN) ||
+		(s_irq_status & S_RX_FIFO_LAST_EN))
+		qcom_geni_serial_handle_rx(uport, drop_rx);
+
+exit_geni_serial_isr:
+	spin_unlock_irqrestore(&uport->lock, flags);
+	return IRQ_HANDLED;
+}
+
+static int get_tx_fifo_size(struct qcom_geni_serial_port *port)
+{
+	struct uart_port *uport;
+
+	if (!port)
+		return -ENODEV;
+
+	uport = &port->uport;
+	port->tx_fifo_depth = geni_se_get_tx_fifo_depth(uport->membase);
+	if (!port->tx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->tx_fifo_width = geni_se_get_tx_fifo_width(uport->membase);
+	if (!port->tx_fifo_width) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO width read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->rx_fifo_depth = geni_se_get_rx_fifo_depth(uport->membase);
+	if (!port->rx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid RX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	uport->fifosize =
+		((port->tx_fifo_depth * port->tx_fifo_width) >> 3);
+	return 0;
+}
+
+static void set_rfr_wm(struct qcom_geni_serial_port *port)
+{
+	/*
+	 * Set RFR (Flow off) to FIFO_DEPTH - 2.
+	 * RX WM level at 10% RX_FIFO_DEPTH.
+	 * TX WM level at 10% TX_FIFO_DEPTH.
+	 */
+	port->rx_rfr = port->rx_fifo_depth - 2;
+	port->rx_wm = UART_CONSOLE_RX_WM;
+	port->tx_wm = 2;
+}
+
+static void qcom_geni_serial_shutdown(struct uart_port *uport)
+{
+	unsigned long flags;
+
+	/* Stop the console before stopping the current tx */
+	console_stop(uport->cons);
+
+	disable_irq(uport->irq);
+	free_irq(uport->irq, uport);
+	spin_lock_irqsave(&uport->lock, flags);
+	qcom_geni_serial_stop_tx(uport);
+	qcom_geni_serial_stop_rx(uport);
+	spin_unlock_irqrestore(&uport->lock, flags);
+}
+
+static int qcom_geni_serial_port_setup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned long cfg0, cfg1;
+	unsigned int rxstale = DEFAULT_BITS_PER_CHAR * STALE_TIMEOUT;
+
+	set_rfr_wm(qcom_port);
+	geni_write_reg_nolog(rxstale, uport->membase, SE_UART_RX_STALE_CNT);
+	/*
+	 * Make an unconditional cancel on the main sequencer to reset
+	 * it else we could end up in data loss scenarios.
+	 */
+	qcom_port->xfer_mode = FIFO_MODE;
+	qcom_geni_serial_poll_cancel_tx(uport);
+	geni_se_get_packing_config(8, 1, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_TX_PACKING_CFG1);
+	geni_se_get_packing_config(8, 4, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_RX_PACKING_CFG1);
+	ret = geni_se_init(uport->membase, qcom_port->rx_wm, qcom_port->rx_rfr);
+	if (ret) {
+		dev_err(uport->dev, "%s: Fail\n", __func__);
+		goto exit_portsetup;
+	}
+
+	ret = geni_se_select_mode(uport->membase, qcom_port->xfer_mode);
+	if (ret)
+		goto exit_portsetup;
+
+	qcom_port->port_setup = true;
+	/*
+	 * Ensure Port setup related IO completes before returning to
+	 * framework.
+	 */
+	mb();
+exit_portsetup:
+	return ret;
+}
+
+static int qcom_geni_serial_startup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	scnprintf(qcom_port->name, sizeof(qcom_port->name),
+		  "qcom_serial_geni%d",	uport->line);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		dev_err(uport->dev, "%s: Invalid FW %d loaded.\n",
+				 __func__, geni_se_get_proto(uport->membase));
+		ret = -ENXIO;
+		goto exit_startup;
+	}
+
+	get_tx_fifo_size(qcom_port);
+	if (!qcom_port->port_setup) {
+		if (qcom_geni_serial_port_setup(uport))
+			goto exit_startup;
+	}
+
+	/*
+	 * Ensure that all the port configuration writes complete
+	 * before returning to the framework.
+	 */
+	mb();
+	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
+			qcom_port->name, uport);
+	if (unlikely(ret)) {
+		dev_err(uport->dev, "%s: Failed to get IRQ ret %d\n",
+							__func__, ret);
+		goto exit_startup;
+	}
+
+exit_startup:
+	return ret;
+}
+
+static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
+{
+	unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
+		32000000, 48000000, 64000000, 80000000, 96000000, 100000000};
+	int i;
+	int match = -1;
+
+	for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
+		if (clk_freq > root_freq[i])
+			continue;
+
+		if (!(root_freq[i] % clk_freq)) {
+			match = i;
+			break;
+		}
+	}
+	if (match != -1)
+		*ser_clk = root_freq[match];
+	else
+		pr_err("clk_freq %ld\n", clk_freq);
+	return match;
+}
+
+static void geni_serial_write_term_regs(struct uart_port *uport,
+		u32 tx_trans_cfg, u32 tx_parity_cfg, u32 rx_trans_cfg,
+		u32 rx_parity_cfg, u32 bits_per_char, u32 stop_bit_len,
+		u32 s_clk_cfg)
+{
+	geni_write_reg_nolog(tx_trans_cfg, uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	geni_write_reg_nolog(tx_parity_cfg, uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	geni_write_reg_nolog(rx_trans_cfg, uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	geni_write_reg_nolog(rx_parity_cfg, uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_TX_WORD_LEN);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_RX_WORD_LEN);
+	geni_write_reg_nolog(stop_bit_len, uport->membase,
+						SE_UART_TX_STOP_BIT_LEN);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_M_CLK_CFG);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_S_CLK_CFG);
+}
+
+static int get_clk_div_rate(unsigned int baud, unsigned long *desired_clk_rate)
+{
+	unsigned long ser_clk;
+	int dfs_index;
+	int clk_div = 0;
+
+	*desired_clk_rate = baud * UART_OVERSAMPLING;
+	dfs_index = get_clk_cfg(*desired_clk_rate, &ser_clk);
+	if (dfs_index < 0) {
+		pr_err("%s: Can't find matching DFS entry for baud %d\n",
+								__func__, baud);
+		clk_div = -EINVAL;
+		goto exit_get_clk_div_rate;
+	}
+
+	clk_div = ser_clk / *desired_clk_rate;
+	*desired_clk_rate = ser_clk;
+exit_get_clk_div_rate:
+	return clk_div;
+}
+
+static void qcom_geni_serial_set_termios(struct uart_port *uport,
+				struct ktermios *termios, struct ktermios *old)
+{
+	unsigned int baud;
+	unsigned int bits_per_char = 0;
+	unsigned int tx_trans_cfg;
+	unsigned int tx_parity_cfg;
+	unsigned int rx_trans_cfg;
+	unsigned int rx_parity_cfg;
+	unsigned int stop_bit_len;
+	unsigned int clk_div;
+	unsigned long ser_clk_cfg = 0;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	unsigned long clk_rate;
+
+	qcom_geni_serial_stop_rx(uport);
+	/* baud rate */
+	baud = uart_get_baud_rate(uport, termios, old, 300, 4000000);
+	port->cur_baud = baud;
+	clk_div = get_clk_div_rate(baud, &clk_rate);
+	if (clk_div <= 0)
+		goto exit_set_termios;
+
+	uport->uartclk = clk_rate;
+	clk_set_rate(port->serial_rsc.se_clk, clk_rate);
+	ser_clk_cfg |= SER_CLK_EN;
+	ser_clk_cfg |= (clk_div << CLK_DIV_SHFT);
+
+	/* parity */
+	tx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	tx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	rx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	rx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	if (termios->c_cflag & PARENB) {
+		tx_trans_cfg |= UART_TX_PAR_EN;
+		rx_trans_cfg |= UART_RX_PAR_EN;
+		tx_parity_cfg |= PAR_CALC_EN;
+		rx_parity_cfg |= PAR_CALC_EN;
+		if (termios->c_cflag & PARODD) {
+			tx_parity_cfg |= PAR_ODD;
+			rx_parity_cfg |= PAR_ODD;
+		} else if (termios->c_cflag & CMSPAR) {
+			tx_parity_cfg |= PAR_SPACE;
+			rx_parity_cfg |= PAR_SPACE;
+		} else {
+			tx_parity_cfg |= PAR_EVEN;
+			rx_parity_cfg |= PAR_EVEN;
+		}
+	} else {
+		tx_trans_cfg &= ~UART_TX_PAR_EN;
+		rx_trans_cfg &= ~UART_RX_PAR_EN;
+		tx_parity_cfg &= ~PAR_CALC_EN;
+		rx_parity_cfg &= ~PAR_CALC_EN;
+	}
+
+	/* bits per char */
+	switch (termios->c_cflag & CSIZE) {
+	case CS5:
+		bits_per_char = 5;
+		break;
+	case CS6:
+		bits_per_char = 6;
+		break;
+	case CS7:
+		bits_per_char = 7;
+		break;
+	case CS8:
+	default:
+		bits_per_char = 8;
+		break;
+	}
+
+	/* stop bits */
+	if (termios->c_cflag & CSTOPB)
+		stop_bit_len = TX_STOP_BIT_LEN_2;
+	else
+		stop_bit_len = TX_STOP_BIT_LEN_1;
+
+	/* flow control, clear the CTS_MASK bit if using flow control. */
+	if (termios->c_cflag & CRTSCTS)
+		tx_trans_cfg &= ~UART_CTS_MASK;
+	else
+		tx_trans_cfg |= UART_CTS_MASK;
+
+	if (likely(baud))
+		uart_update_timeout(uport, termios->c_cflag, baud);
+
+	geni_serial_write_term_regs(uport, tx_trans_cfg, tx_parity_cfg,
+		rx_trans_cfg, rx_parity_cfg, bits_per_char, stop_bit_len,
+								ser_clk_cfg);
+exit_set_termios:
+	qcom_geni_serial_start_rx(uport);
+	return;
+
+}
+
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
+{
+	unsigned int tx_fifo_status;
+	unsigned int is_tx_empty = 1;
+
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_TX_FIFO_STATUS);
+	if (tx_fifo_status)
+		is_tx_empty = 0;
+
+	return is_tx_empty;
+}
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
+static int __init qcom_geni_console_setup(struct console *co, char *options)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *dev_port;
+	int baud = 115200;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+	int ret = 0;
+
+	if (unlikely(co->index >= GENI_UART_NR_PORTS  || co->index < 0))
+		return -ENXIO;
+
+	dev_port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		pr_err("Invalid line %d(%d)\n", co->index, ret);
+		return ret;
+	}
+
+	uport = &dev_port->uport;
+
+	if (unlikely(!uport->membase))
+		return -ENXIO;
+
+	if (geni_se_resources_on(&dev_port->serial_rsc))
+		WARN_ON(1);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		geni_se_resources_off(&dev_port->serial_rsc);
+		return -ENXIO;
+	}
+
+	if (!dev_port->port_setup) {
+		qcom_geni_serial_stop_rx(uport);
+		qcom_geni_serial_port_setup(uport);
+	}
+
+	if (options)
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+	return uart_set_options(uport, co, baud, parity, bits, flow);
+}
+
+static int console_register(struct uart_driver *drv)
+{
+	return uart_register_driver(drv);
+}
+static void console_unregister(struct uart_driver *drv)
+{
+	uart_unregister_driver(drv);
+}
+
+static struct console cons_ops = {
+	.name = "ttyMSM",
+	.write = qcom_geni_serial_console_write,
+	.device = uart_console_device,
+	.setup = qcom_geni_console_setup,
+	.flags = CON_PRINTBUFFER,
+	.index = -1,
+	.data = &qcom_geni_console_driver,
+};
+
+static struct uart_driver qcom_geni_console_driver = {
+	.owner = THIS_MODULE,
+	.driver_name = "qcom_geni_console",
+	.dev_name = "ttyMSM",
+	.nr =  GENI_UART_NR_PORTS,
+	.cons = &cons_ops,
+};
+#else
+static int console_register(struct uart_driver *drv)
+{
+	return 0;
+}
+
+static void console_unregister(struct uart_driver *drv)
+{
+}
+#endif /* defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) */
+
+static void qcom_geni_serial_cons_pm(struct uart_port *uport,
+		unsigned int new_state, unsigned int old_state)
+{
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	if (unlikely(!uart_console(uport)))
+		return;
+
+	if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
+		geni_se_resources_on(&qcom_port->serial_rsc);
+	else if (new_state == UART_PM_STATE_OFF &&
+			old_state == UART_PM_STATE_ON)
+		geni_se_resources_off(&qcom_port->serial_rsc);
+}
+
+static const struct uart_ops qcom_geni_console_pops = {
+	.tx_empty = qcom_geni_serial_tx_empty,
+	.stop_tx = qcom_geni_serial_stop_tx,
+	.start_tx = qcom_geni_serial_start_tx,
+	.stop_rx = qcom_geni_serial_stop_rx,
+	.set_termios = qcom_geni_serial_set_termios,
+	.startup = qcom_geni_serial_startup,
+	.config_port = qcom_geni_serial_config_port,
+	.shutdown = qcom_geni_serial_shutdown,
+	.type = qcom_geni_serial_get_type,
+	.set_mctrl = qcom_geni_cons_set_mctrl,
+	.get_mctrl = qcom_geni_cons_get_mctrl,
+#ifdef CONFIG_CONSOLE_POLL
+	.poll_get_char	= qcom_geni_serial_get_char,
+	.poll_put_char	= qcom_geni_serial_poll_put_char,
+#endif
+	.pm = qcom_geni_serial_cons_pm,
+};
+
+static const struct of_device_id qcom_geni_serial_match_table[] = {
+	{ .compatible = "qcom,geni-debug-uart",
+			.data = (void *)&qcom_geni_console_driver},
+};
+
+static int qcom_geni_serial_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	int line = -1;
+	struct qcom_geni_serial_port *dev_port;
+	struct uart_port *uport;
+	struct resource *res;
+	struct uart_driver *drv;
+	const struct of_device_id *id;
+
+	id = of_match_device(qcom_geni_serial_match_table, &pdev->dev);
+	if (id) {
+		dev_dbg(&pdev->dev, "%s: %s\n", __func__, id->compatible);
+		drv = (struct uart_driver *)id->data;
+	} else {
+		dev_err(&pdev->dev, "%s: No matching device found", __func__);
+		return -ENODEV;
+	}
+
+	if (pdev->dev.of_node) {
+		if (drv->cons)
+			line = of_alias_get_id(pdev->dev.of_node, "serial");
+	} else {
+		line = pdev->id;
+	}
+
+	if (line < 0)
+		line = atomic_inc_return(&uart_line_id) - 1;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		return -ENXIO;
+	dev_port = get_port_from_line(line);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		dev_err(&pdev->dev, "Invalid line %d(%d)\n",
+					line, ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport = &dev_port->uport;
+
+	/* Don't allow 2 drivers to access the same port */
+	if (uport->private_data) {
+		ret = -ENODEV;
+		goto exit_geni_serial_probe;
+	}
+
+	uport->dev = &pdev->dev;
+	dev_port->wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(dev_port->serial_rsc.se_clk)) {
+		ret = PTR_ERR(dev_port->serial_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "se-phys");
+	if (!res) {
+		ret = -ENXIO;
+		dev_err(&pdev->dev, "Err getting IO region\n");
+		goto exit_geni_serial_probe;
+	}
+
+	uport->mapbase = res->start;
+	uport->membase = devm_ioremap(&pdev->dev, res->start,
+						resource_size(res));
+	if (!uport->membase) {
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "Err IO mapping serial iomem");
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_pinctrl);
+		goto exit_geni_serial_probe;
+	}
+	dev_port->serial_rsc.geni_gpio_active =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_DEFAULT);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_active)) {
+		dev_err(&pdev->dev, "No default config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_active);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_gpio_sleep =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_SLEEP);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_sleep)) {
+		dev_err(&pdev->dev, "No sleep config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_sleep);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->tx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
+	uport->fifosize =
+		((dev_port->tx_fifo_depth * dev_port->tx_fifo_width) >> 3);
+
+	uport->irq = platform_get_irq(pdev, 0);
+	if (uport->irq < 0) {
+		ret = uport->irq;
+		dev_err(&pdev->dev, "Failed to get IRQ %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport->private_data = (void *)drv;
+	platform_set_drvdata(pdev, dev_port);
+	dev_port->handle_rx = handle_rx_console;
+	dev_port->rx_fifo = devm_kzalloc(uport->dev, sizeof(u32),
+								GFP_KERNEL);
+	dev_port->port_setup = false;
+	return uart_add_one_port(drv, uport);
+
+exit_geni_serial_probe:
+	return ret;
+}
+
+static int qcom_geni_serial_remove(struct platform_device *pdev)
+{
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_driver *drv =
+			(struct uart_driver *)port->uport.private_data;
+
+	uart_remove_one_port(drv, &port->uport);
+	return 0;
+}
+
+
+#ifdef CONFIG_PM
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	uart_suspend_port((struct uart_driver *)uport->private_data,
+				uport);
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	if (console_suspend_enabled && uport->suspended) {
+		uart_resume_port((struct uart_driver *)uport->private_data,
+									uport);
+		disable_irq(uport->irq);
+	}
+	return 0;
+}
+#else
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
+	.suspend_noirq = qcom_geni_serial_sys_suspend_noirq,
+	.resume_noirq = qcom_geni_serial_sys_resume_noirq,
+};
+
+static struct platform_driver qcom_geni_serial_platform_driver = {
+	.remove = qcom_geni_serial_remove,
+	.probe = qcom_geni_serial_probe,
+	.driver = {
+		.name = "qcom_geni_serial",
+		.of_match_table = qcom_geni_serial_match_table,
+		.pm = &qcom_geni_serial_pm_ops,
+	},
+};
+
+static int __init qcom_geni_serial_init(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < GENI_UART_CONS_PORTS; i++) {
+		qcom_geni_console_port.uport.iotype = UPIO_MEM;
+		qcom_geni_console_port.uport.ops = &qcom_geni_console_pops;
+		qcom_geni_console_port.uport.flags = UPF_BOOT_AUTOCONF;
+		qcom_geni_console_port.uport.line = i;
+	}
+
+	ret = console_register(&qcom_geni_console_driver);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&qcom_geni_serial_platform_driver);
+	if (ret) {
+		console_unregister(&qcom_geni_console_driver);
+		return ret;
+	}
+	return ret;
+}
+module_init(qcom_geni_serial_init);
+
+static void __exit qcom_geni_serial_exit(void)
+{
+	platform_driver_unregister(&qcom_geni_serial_platform_driver);
+	console_unregister(&qcom_geni_console_driver);
+}
+module_exit(qcom_geni_serial_exit);
+
+MODULE_DESCRIPTION("Serial driver for GENI based QUP cores");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("tty:qcom_geni_serial");
#46 lore raw

Re: [v2, 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Karthikeyan Ramasubramanian

Hi,

Quoted 20 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
 drivers/tty/serial/Kconfig            |   10 +
 drivers/tty/serial/Makefile           |    1 +
 drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
 3 files changed, 1425 insertions(+)
 create mode 100644 drivers/tty/serial/qcom_geni_serial.c
drivers/tty/serial/Kconfig +0 -0
index b788fee..1be30e5 100644

drivers/tty/serial/Kconfig config SERIAL_MSM_CONSOLE · line 1102

Quoted 5 lines
drivers/tty/serial/Kconfig +2 -0
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
        select SERIAL_CORE_CONSOLE
        select SERIAL_EARLYCON
 
+config SERIAL_QCOM_GENI
+       tristate "QCOM on-chip GENI based serial port support"

Should this be bool instead of tristate? Guenter noticed that we'll get link errors if we try building this as a module. Specifically, he noted that the "qcom_geni_serial.c" file refers to "uart_console_device" and "uart_console_device" is not exported (and shouldn't be since a console has to be available before modules are loaded).

-Doug

#7 lore raw

Re: [PATCH v2 2/7] dt-bindings: soc: qcom: Add device tree binding for GENI SE

In reply to Bjorn Andersson
Quoted 8 lines · Bjorn Andersson
Quoted 3 lines · Karthikeyan Ramasubramanian

Add device tree binding support for the QCOM GENI SE driver.

Better describe the entire GENI, with it's functions in the same binding.

Ok.

Quoted 24 lines
Quoted 24 lines
---
  .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 34 ++++++++++++++++++++++
  1 file changed, 34 insertions(+)

create mode 100644 Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +12 -0
new file mode 100644
index 0000000..66f8a16
@@ -0,0 +1,34 @@
+Qualcomm Technologies, Inc. GENI Serial Engine QUP Wrapper Controller
+
+Generic Interface (GENI) based Qualcomm Universal Peripheral (QUP) wrapper
+is a programmable module for supporting a wide range of serial interfaces
+like UART, SPI, I2C, I3C, etc. A single QUP module can provide upto 8 Serial
+Interfaces, using its internal Serial Engines. The GENI Serial Engine QUP
+Wrapper controller is modeled as a node with zero or more child nodes each
+representing a serial engine.
+
+Required properties:
+- compatible:		Must be "qcom,geni-se-qup".
+- reg:			Must contain QUP register address and length.
Quoted 8 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 18

Quoted 6 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +6 -0
+- clock-names:		Must contain "m-ahb" and "s-ahb".
+- clocks:		AHB clocks needed by the device.
+
+Required properties if child node exists:
+- #address-cells: Must be 1
+- #size-cells: Must be 1

But on a 64-bit system, shouldn't these be 2?

As pointed out by Rob in his response, the module size is less than 4G and hence 1.

Quoted 14 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 28

Quoted 11 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +10 -0
+- ranges: Must be present
+
+Properties for children:
+
+A GENI based QUP wrapper controller node can contain 0 or more child nodes
+representing serial devices.  These serial devices can be a QCOM UART, I2C
+controller, spi controller, or some combination of aforementioned devices.
+
+Example:
+	qup0: qcom,geniqup0@8c0000 {

I don't see a reason for this to be referenced, so skip the label. And don't use qcom, in the node name; "geni" would be perfectly fine?

Ok.

Quoted 11 lines

Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt line 34

Quoted 7 lines
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt new file +6 -0
+		compatible = "qcom,geni-se-qup";
+		reg = <0x8c0000 0x6000>;
+		clock-names = "m-ahb", "s-ahb";
+		clocks = <&clock_gcc GCC_QUPV3_WRAP_0_M_AHB_CLK>,
+			<&clock_gcc GCC_QUPV3_WRAP_0_S_AHB_CLK>;
+	}

Regards,
Bjorn

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#34 lore raw

Re: [PATCH v2 4/7] dt-bindings: i2c: Add device tree bindings for GENI I2C Controller

In reply to Bjorn Andersson
Quoted 13 lines · Bjorn Andersson
Quoted 11 lines · Karthikeyan Ramasubramanian

Add device tree binding support for I2C Controller in GENI based QUP Wrapper.

---
  .../devicetree/bindings/i2c/i2c-qcom-geni.txt      | 35 ++++++++++++++++++++++
  .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 19 ++++++++++++
  2 files changed, 54 insertions(+)

create mode 100644 Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt

Quoted 14 lines

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 5

Quoted 11 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +5 -0
new file mode 100644
index 0000000..ea84be7
@@ -0,0 +1,35 @@
+Qualcomm Technologies Inc. GENI Serial Engine based I2C Controller
+
+Required properties:
+ - compatible: Should be:
+   * "qcom,i2c-geni.

As this is a subset of geni it would look better with qcom,geni-i2c imho.

Ok.

Quoted 6 lines

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 8

Quoted 4 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +3 -0
+ - reg: Should contain QUP register address and length.
+ - interrupts: Should contain I2C interrupt.
+ - clock-names: Should contain "se-clk".

Omit "clk" from the clock names.

Ok.

Quoted 8 lines

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 12

Quoted 5 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +4 -0
+ - clocks: Serial engine core clock needed by the device.
+ - pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+   should be "active" and "sleep" for the pin confuguration when core is active
+   or when entering sleep state.

No need to describe pinctrl properties - and your description here doesn't match the code.

Removed as it is called by the device core before probe.

Quoted 11 lines

Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt line 20

Quoted 9 lines
Documentation/devicetree/bindings/i2c/i2c-qcom-geni.txt new file +8 -0
+ - #address-cells: Should be <1> Address cells for i2c device address
+ - #size-cells: Should be <0> as i2c addresses have no size component
+
+Optional property:
+ - clock-frequency : Desired I2C bus clock frequency in Hz.
+   When missing default to 400000Hz.
+
+Child nodes should conform to i2c bus binding.

..."as described in i2c.txt"

Ok.

Quoted 4 lines

Regards,
Bjorn

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#27 lore raw

Re: [PATCH v2 5/7] i2c: i2c-qcom-geni: Add bus driver for the Qualcomm GENI I2C controller

In reply to Bjorn Andersson
Quoted 26 lines · Bjorn Andersson
Quoted 24 lines · Karthikeyan Ramasubramanian

This bus driver supports the GENI based i2c hardware controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including I2C. The driver supports FIFO mode and DMA mode of transfer and switches modes dynamically depending on the size of the transfer.

---
  drivers/i2c/busses/Kconfig         |  10 +
  drivers/i2c/busses/Makefile        |   1 +
  drivers/i2c/busses/i2c-qcom-geni.c | 656 +++++++++++++++++++++++++++++++++++++
  3 files changed, 667 insertions(+)

create mode 100644 drivers/i2c/busses/i2c-qcom-geni.c

drivers/i2c/busses/Kconfig +0 -0
index 009345d..caef309 100644
@@ -838,6 +838,16 @@ config I2C_PXA_SLAVE
  	  is necessary for systems where the PXA may be a target on the
  	  I2C bus.
 
Quoted 5 lines

drivers/i2c/busses/Kconfig config I2C_PXA_SLAVE · line 843

Quoted 3 lines
drivers/i2c/busses/Kconfig +3 -0
+config I2C_QCOM_GENI
+	tristate "Qualcomm Technologies Inc.'s GENI based I2C controller"
+	depends on ARCH_QCOM

Just depend on the GENI wrapper as well.

Ok.

Quoted 36 lines
Quoted 36 lines
drivers/i2c/busses/Kconfig +7 -0
+	help
+	  If you say yes to this option, support will be included for the
+	  built-in I2C interface on the Qualcomm Technologies Inc.'s SoCs.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-qcom-geni.
+
  config I2C_QUP
  	tristate "Qualcomm QUP based I2C controller"
  	depends on ARCH_QCOM
drivers/i2c/busses/Makefile +1 -0
index 2ce8576..201fce1 100644
@@ -84,6 +84,7 @@ obj-$(CONFIG_I2C_PNX)		+= i2c-pnx.o
  obj-$(CONFIG_I2C_PUV3)		+= i2c-puv3.o
  obj-$(CONFIG_I2C_PXA)		+= i2c-pxa.o
  obj-$(CONFIG_I2C_PXA_PCI)	+= i2c-pxa-pci.o
+obj-$(CONFIG_I2C_QCOM_GENI)	+= i2c-qcom-geni.o
  obj-$(CONFIG_I2C_QUP)		+= i2c-qup.o
  obj-$(CONFIG_I2C_RIIC)		+= i2c-riic.o
  obj-$(CONFIG_I2C_RK3X)		+= i2c-rk3x.o
drivers/i2c/busses/i2c-qcom-geni.c new file +7 -0
new file mode 100644
index 0000000..59ad4da
@@ -0,0 +1,656 @@
+/*
+ * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 13

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+ * This program 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 General Public License for more details.
+ *
+ */

Use SPDX license header.

Ok.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 16

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+#include <linux/clk.h>
+#include <linux/delay.h>

Unused?

Ok, I will remove unused header files.

Quoted 16 lines
Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/interrupt.h>

drivers/i2c/busses/i2c-qcom-geni.c line 29

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/dma-mapping.h>
+#include <linux/qcom-geni-se.h>
+
+#define SE_I2C_TX_TRANS_LEN		(0x26C)

Drop the parenthesis, when not needed.

Ok.

Quoted 51 lines
Quoted 51 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +50 -0
+#define SE_I2C_RX_TRANS_LEN		(0x270)
+#define SE_I2C_SCL_COUNTERS		(0x278)
+#define SE_GENI_IOS			(0x908)
+
+#define SE_I2C_ERR  (M_CMD_OVERRUN_EN | M_ILLEGAL_CMD_EN | M_CMD_FAILURE_EN |\
+			M_GP_IRQ_1_EN | M_GP_IRQ_3_EN | M_GP_IRQ_4_EN)
+#define SE_I2C_ABORT (1U << 1)
+/* M_CMD OP codes for I2C */
+#define I2C_WRITE		(0x1)
+#define I2C_READ		(0x2)
+#define I2C_WRITE_READ		(0x3)
+#define I2C_ADDR_ONLY		(0x4)
+#define I2C_BUS_CLEAR		(0x6)
+#define I2C_STOP_ON_BUS		(0x7)
+/* M_CMD params for I2C */
+#define PRE_CMD_DELAY		(BIT(0))
+#define TIMESTAMP_BEFORE	(BIT(1))
+#define STOP_STRETCH		(BIT(2))
+#define TIMESTAMP_AFTER		(BIT(3))
+#define POST_COMMAND_DELAY	(BIT(4))
+#define IGNORE_ADD_NACK		(BIT(6))
+#define READ_FINISHED_WITH_ACK	(BIT(7))
+#define BYPASS_ADDR_PHASE	(BIT(8))
+#define SLV_ADDR_MSK		(GENMASK(15, 9))
+#define SLV_ADDR_SHFT		(9)
+
+#define I2C_CORE2X_VOTE		(10000)
+#define GP_IRQ0			0
+#define GP_IRQ1			1
+#define GP_IRQ2			2
+#define GP_IRQ3			3
+#define GP_IRQ4			4
+#define GP_IRQ5			5
+#define GENI_OVERRUN		6
+#define GENI_ILLEGAL_CMD	7
+#define GENI_ABORT_DONE		8
+#define GENI_TIMEOUT		9
+
+#define I2C_NACK		GP_IRQ1
+#define I2C_BUS_PROTO		GP_IRQ3
+#define I2C_ARB_LOST		GP_IRQ4
+#define DM_I2C_CB_ERR		((BIT(GP_IRQ1) | BIT(GP_IRQ3) | BIT(GP_IRQ4)) \
+									<< 5)
+
+#define I2C_AUTO_SUSPEND_DELAY	250
+#define KHz(freq)		(1000 * freq)
+
+struct geni_i2c_dev {
+	struct device *dev;
+	void __iomem *base;
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 84

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	unsigned int tx_wm;
+	int irq;
+	int err;
+	struct i2c_adapter adap;
+	struct completion xfer;

How about naming this "done" or something like that, gi2c->xfer doesn't really give the sense of being a "we're done with the operation"-event.

Ok.

Quoted 10 lines

drivers/i2c/busses/i2c-qcom-geni.c line 89

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	struct i2c_msg *cur;
+	struct geni_se_rsc i2c_rsc;
+	int cur_wr;
+	int cur_rd;
+	struct device *wrapper_dev;

This is already availabe in i2c_rsc, and in particular if you pass the i2c_rsc down to the wrapper in the 2 cases you use the wrapper_dev you don't need this duplication.

Ok.

Quoted 5 lines

drivers/i2c/busses/i2c-qcom-geni.c line 91

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+	u32 clk_freq_out;
+	int clk_fld_idx;

Keep track of the const struct geni_i2c_clk_fld * here instead.

Ok.

Quoted 14 lines

drivers/i2c/busses/i2c-qcom-geni.c line 102

Quoted 12 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+};
+
+struct geni_i2c_err_log {
+	int err;
+	const char *msg;
+};
+
+static struct geni_i2c_err_log gi2c_log[] = {
+	[GP_IRQ0] = {-EINVAL, "Unknown I2C err GP_IRQ0"},
+	[I2C_NACK] = {-ENOTCONN,
+			"NACK: slv unresponsive, check its power/reset-ln"},

Break the 80-char rule, to improve readability.

Ok.

Quoted 17 lines
Quoted 17 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +16 -0
+	[GP_IRQ2] = {-EINVAL, "Unknown I2C err GP IRQ2"},
+	[I2C_BUS_PROTO] = {-EPROTO,
+				"Bus proto err, noisy/unepxected start/stop"},
+	[I2C_ARB_LOST] = {-EBUSY,
+				"Bus arbitration lost, clock line undriveable"},
+	[GP_IRQ5] = {-EINVAL, "Unknown I2C err GP IRQ5"},
+	[GENI_OVERRUN] = {-EIO, "Cmd overrun, check GENI cmd-state machine"},
+	[GENI_ILLEGAL_CMD] = {-EILSEQ,
+				"Illegal cmd, check GENI cmd-state machine"},
+	[GENI_ABORT_DONE] = {-ETIMEDOUT, "Abort after timeout successful"},
+	[GENI_TIMEOUT] = {-ETIMEDOUT, "I2C TXN timed out"},
+};
+
+struct geni_i2c_clk_fld {
+	u32	clk_freq_out;
+	u8	clk_div;
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 124

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+	u8	t_high;
+	u8	t_low;
+	u8	t_cycle;
+};
+
+static struct geni_i2c_clk_fld geni_i2c_clk_map[] = {

const

Ok.

Quoted 19 lines
Quoted 7 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+	{KHz(100), 7, 10, 11, 26},
+	{KHz(400), 2,  5, 12, 24},
+	{KHz(1000), 1, 3,  9, 18},
+};
+
+static int geni_i2c_clk_map_idx(struct geni_i2c_dev *gi2c)

drivers/i2c/busses/i2c-qcom-geni.c line 140

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+{
+	int i;
+	int ret = 0;
+	bool clk_map_present = false;
+	struct geni_i2c_clk_fld *itr = geni_i2c_clk_map;
+
+	for (i = 0; i < ARRAY_SIZE(geni_i2c_clk_map); i++, itr++) {
+		if (itr->clk_freq_out == gi2c->clk_freq_out) {
+			clk_map_present = true;
+			break;

Make this:

Quoted 2 lines
			gi2c->clk_fld = geni_i2c_clk_map + i;
			return 0;

Ok.

Quoted 7 lines

drivers/i2c/busses/i2c-qcom-geni.c line 143

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+		}
+	}
+

...then you can drop ret and clk_map_present and just return -EINVAL here.

Ok.

Quoted 14 lines

drivers/i2c/busses/i2c-qcom-geni.c line 152

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +9 -0
+	if (clk_map_present)
+		gi2c->clk_fld_idx = i;
+	else
+		ret = -EINVAL;
+
+	return ret;
+}
+
+static inline void qcom_geni_i2c_conf(struct geni_i2c_dev *gi2c, int dfs)

Drop the "inline", if it makes sense the compiler will inline it, if not it knows better than we do.

Quoted 1 line

dfs is always 0, so drop this parameter and hard code the value below.

Ok.

Quoted 14 lines

drivers/i2c/busses/i2c-qcom-geni.c line 162

Quoted 11 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+{
+	struct geni_i2c_clk_fld *itr = geni_i2c_clk_map + gi2c->clk_fld_idx;
+
+	geni_write_reg(dfs, gi2c->base, SE_GENI_CLK_SEL);
+
+	geni_write_reg((itr->clk_div << 4) | 1, gi2c->base, GENI_SER_M_CLK_CFG);
+	geni_write_reg(((itr->t_high << 20) | (itr->t_low << 10) |
+			itr->t_cycle), gi2c->base, SE_I2C_SCL_COUNTERS);
+
+	/* Ensure Clk config completes before return */

That's not what "mb" does, it ensures that later memory operations aren't reordered beyond the barrier.

Our intention also is for ordering purposes so that any later register writes/reads does not get re-ordered until the writes to clock configuration register is complete. I will update the comment.

Quoted 10 lines

drivers/i2c/busses/i2c-qcom-geni.c line 166

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+	mb();
+}
+
+static void geni_i2c_err(struct geni_i2c_dev *gi2c, int err)

Looking at the code in this function it's just a bunch of logic to print various debug messages...except for the last line that uses the gi2c_log lookup table to convert the error to a errno. Sneaky...and not very nice.

I will update this function so that it is more obvious.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 168

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+{
+	u32 m_cmd = readl_relaxed(gi2c->base + SE_GENI_M_CMD0);

Unless you have a really good reason, just use readl/writel in favour of their _relaxed versions.

The goal is to maintain the order of execution to the Serial Engine register block. I believe _relaxed help enusre that order with a little less overhead compared to non_relaxed function. Please correct me otherwise.

Quoted 61 lines
Quoted 61 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +60 -0
+	u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
+	u32 geni_s = readl_relaxed(gi2c->base + SE_GENI_STATUS);
+	u32 geni_ios = readl_relaxed(gi2c->base + SE_GENI_IOS);
+	u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
+	u32 rx_st, tx_st;
+
+	if (gi2c->cur)
+		dev_dbg(gi2c->dev, "len:%d, slv-addr:0x%x, RD/WR:%d\n",
+			gi2c->cur->len, gi2c->cur->addr, gi2c->cur->flags);
+
+	if (err == I2C_NACK || err == GENI_ABORT_DONE) {
+		dev_dbg(gi2c->dev, "%s\n", gi2c_log[err].msg);
+		goto err_ret;
+	} else {
+		dev_err(gi2c->dev, "%s\n", gi2c_log[err].msg);
+	}
+
+	if (dma) {
+		rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
+		tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
+	} else {
+		rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
+		tx_st = readl_relaxed(gi2c->base + SE_GENI_TX_FIFO_STATUS);
+	}
+	dev_dbg(gi2c->dev, "DMA:%d tx_stat:0x%x, rx_stat:0x%x, irq-stat:0x%x\n",
+		dma, tx_st, rx_st, m_stat);
+	dev_dbg(gi2c->dev, "m_cmd:0x%x, geni_status:0x%x, geni_ios:0x%x\n",
+		m_cmd, geni_s, geni_ios);
+err_ret:
+	gi2c->err = gi2c_log[err].err;
+}
+
+static irqreturn_t geni_i2c_irq(int irq, void *dev)
+{
+	struct geni_i2c_dev *gi2c = dev;
+	int i, j;
+	u32 m_stat = readl_relaxed(gi2c->base + SE_GENI_M_IRQ_STATUS);
+	u32 rx_st = readl_relaxed(gi2c->base + SE_GENI_RX_FIFO_STATUS);
+	u32 dm_tx_st = readl_relaxed(gi2c->base + SE_DMA_TX_IRQ_STAT);
+	u32 dm_rx_st = readl_relaxed(gi2c->base + SE_DMA_RX_IRQ_STAT);
+	u32 dma = readl_relaxed(gi2c->base + SE_GENI_DMA_MODE_EN);
+	struct i2c_msg *cur = gi2c->cur;
+
+	if (!cur || (m_stat & M_CMD_FAILURE_EN) ||
+		    (dm_rx_st & (DM_I2C_CB_ERR)) ||
+		    (m_stat & M_CMD_ABORT_EN)) {
+
+		if (m_stat & M_GP_IRQ_1_EN)
+			geni_i2c_err(gi2c, I2C_NACK);
+		if (m_stat & M_GP_IRQ_3_EN)
+			geni_i2c_err(gi2c, I2C_BUS_PROTO);
+		if (m_stat & M_GP_IRQ_4_EN)
+			geni_i2c_err(gi2c, I2C_ARB_LOST);
+		if (m_stat & M_CMD_OVERRUN_EN)
+			geni_i2c_err(gi2c, GENI_OVERRUN);
+		if (m_stat & M_ILLEGAL_CMD_EN)
+			geni_i2c_err(gi2c, GENI_ILLEGAL_CMD);
+		if (m_stat & M_CMD_ABORT_EN)
+			geni_i2c_err(gi2c, GENI_ABORT_DONE);
+		if (m_stat & M_GP_IRQ_0_EN)
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 233

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+			geni_i2c_err(gi2c, GP_IRQ0);
+
+		if (!dma)
+			writel_relaxed(0, (gi2c->base +
+					   SE_GENI_TX_WATERMARK_REG));

Drop the extra parenthesis. And using writel() instead keeps you under 80 chars.

Ok, to dropping the parenthesis.

Quoted 18 lines

drivers/i2c/busses/i2c-qcom-geni.c line 244

Quoted 12 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+		goto irqret;
+	}
+
+	if (dma) {
+		dev_dbg(gi2c->dev, "i2c dma tx:0x%x, dma rx:0x%x\n", dm_tx_st,
+			dm_rx_st);
+		goto irqret;
+	}
+
+	if (((m_stat & M_RX_FIFO_WATERMARK_EN) ||
+		(m_stat & M_RX_FIFO_LAST_EN)) && (cur->flags & I2C_M_RD)) {

Some of these parenthesis are unnecessary, but more importantly the way you wrap this line is misleading; the wrapping indicates that the two latter conditionals are related, but the parenthesis says the first two are.

Quoted 2 lines

The most significant part of this conditional is "is this a read operation", so put this first.

Ok.

Quoted 17 lines

drivers/i2c/busses/i2c-qcom-geni.c line 255

Quoted 13 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+		u32 rxcnt = rx_st & RX_FIFO_WC_MSK;
+
+		for (j = 0; j < rxcnt; j++) {
+			u32 temp;
+			int p;
+
+			temp = readl_relaxed(gi2c->base + SE_GENI_RX_FIFOn);
+			for (i = gi2c->cur_rd, p = 0; (i < cur->len && p < 4);
+				i++, p++)
+				cur->buf[i] = (u8) ((temp >> (p * 8)) & 0xff);
+			gi2c->cur_rd = i;

The two-range for loop with a line wrap isn't very clean and the wrap calls for a set of braces - which will look ugly.

Quoted 8 lines

How about something like this instead?

			p = 0;
			while (p < 4 && gi2c->cur_rd < cur->len) {
				cur->buf[gi2c->cur_rd++] = temp & 0xff;
				temp >>= 8;
				p++;
			}

Ok.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 258

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+			if (gi2c->cur_rd == cur->len) {
+				dev_dbg(gi2c->dev, "FIFO i:%d,read 0x%x\n",
+					i, temp);

Who's the consumer of this debug line?

I will make the debug message more comprehensible, if that is what you mean.

Quoted 16 lines
Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+				break;
+			}
+		}

drivers/i2c/busses/i2c-qcom-geni.c line 271

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+	} else if ((m_stat & M_TX_FIFO_WATERMARK_EN) &&
+					!(cur->flags & I2C_M_RD)) {
+		for (j = 0; j < gi2c->tx_wm; j++) {
+			u32 temp = 0;
+			int p;
+
+			for (i = gi2c->cur_wr, p = 0; (i < cur->len && p < 4);
+				i++, p++)
+				temp |= (((u32)(cur->buf[i]) << (p * 8)));
+			writel_relaxed(temp, gi2c->base + SE_GENI_TX_FIFOn);

Same concern as above.

Ok.

Quoted 10 lines

drivers/i2c/busses/i2c-qcom-geni.c line 277

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+			gi2c->cur_wr = i;
+			dev_dbg(gi2c->dev, "FIFO i:%d,wrote 0x%x\n", i, temp);
+			if (gi2c->cur_wr == cur->len) {
+				dev_dbg(gi2c->dev, "FIFO i2c bytes done writing\n");
+				writel_relaxed(0,
+				(gi2c->base + SE_GENI_TX_WATERMARK_REG));

The line break here is bad. checkpatch.pl --strict will help you find these.

Ok/

Quoted 3 lines

Also using writel() and dropping the parenthesis keeps you below 80 chars.

Ok, to dropping the parenthesis.

Quoted 10 lines

drivers/i2c/busses/i2c-qcom-geni.c line 284

Quoted 8 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +7 -0
+				break;
+			}
+		}
+	}
+irqret:
+	if (m_stat)
+		writel_relaxed(m_stat, gi2c->base + SE_GENI_M_IRQ_CLEAR);

Is it okay for this to be re-ordered wrt above writes?

It is okay. The interrupt bitmask can be cleared anytime while handling the IRQ.

Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 289

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+
+	if (dma) {
+		if (dm_tx_st)
+			writel_relaxed(dm_tx_st, gi2c->base +
+				       SE_DMA_TX_IRQ_CLR);

Use writel() and you don't have to wrap the line.

Please refer to my earlier response regarding using _relaxed() variants.

Quoted 7 lines

drivers/i2c/busses/i2c-qcom-geni.c line 293

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+		if (dm_rx_st)
+			writel_relaxed(dm_rx_st, gi2c->base +
+				       SE_DMA_RX_IRQ_CLR);
+		/* Ensure all writes are done before returning from ISR. */

That's not what wmb does.

I will drop it.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 296

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+		wmb();
+	}
+	/* if this is err with done-bit not set, handle that thr' timeout. */

Is "thr'" should for "through"?

Yes. I will make it clear.

Quoted 17 lines
Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+	if (m_stat & M_CMD_DONE_EN)
+		complete(&gi2c->xfer);
+	else if ((dm_tx_st & TX_DMA_DONE) || (dm_rx_st & RX_DMA_DONE))
+		complete(&gi2c->xfer);

drivers/i2c/busses/i2c-qcom-geni.c line 310

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+
+	return IRQ_HANDLED;
+}
+
+static int geni_i2c_xfer(struct i2c_adapter *adap,
+			 struct i2c_msg msgs[],
+			 int num)
+{
+	struct geni_i2c_dev *gi2c = i2c_get_adapdata(adap);
+	int i, ret = 0, timeout = 0;

No need to initialize these, first use is an assignment.

Ok.

Quoted 7 lines

drivers/i2c/busses/i2c-qcom-geni.c line 313

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+	gi2c->err = 0;
+	gi2c->cur = &msgs[0];

You're assigning cur in each iteration of the loop below, why do you need to do it here as well?

I will remove.

Quoted 12 lines

drivers/i2c/busses/i2c-qcom-geni.c line 321

Quoted 9 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +8 -0
+	reinit_completion(&gi2c->xfer);
+	ret = pm_runtime_get_sync(gi2c->dev);
+	if (ret < 0) {
+		dev_err(gi2c->dev, "error turning SE resources:%d\n", ret);
+		pm_runtime_put_noidle(gi2c->dev);
+		/* Set device in suspended since resume failed */
+		pm_runtime_set_suspended(gi2c->dev);
+		return ret;

With the questionable assignment above you're leaving the function with gi2c->cur pointing to an object that will soon be invalid.

I will fix the assignment.

Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 326

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	}
+
+	qcom_geni_i2c_conf(gi2c, 0);
+	dev_dbg(gi2c->dev, "i2c xfer:num:%d, msgs:len:%d,flg:%d\n",
+				num, msgs[0].len, msgs[0].flags);

Use dynamic function tracing instead of debug prints for this.

Ok. I will remove the debug statements for now and use dynamic function tracing in a different patch.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 327

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +1 -0
+	for (i = 0; i < num; i++) {

I suggest that you split out two functions here, one for rx-one-message and one for tx-one-message. There are some duplication between the two, but not too bad.

Ok.

Quoted 9 lines

drivers/i2c/busses/i2c-qcom-geni.c line 333

Quoted 7 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+		int stretch = (i < (num - 1));
+		u32 m_param = 0;
+		u32 m_cmd = 0;
+		dma_addr_t tx_dma = 0;
+		dma_addr_t rx_dma = 0;
+		enum geni_se_xfer_mode mode = FIFO_MODE;

No need to initialize mode, as the first use is an assignment.

Ok.

Quoted 6 lines

drivers/i2c/busses/i2c-qcom-geni.c line 336

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+		m_param |= (stretch ? STOP_STRETCH : 0);
+		m_param |= ((msgs[i].addr & 0x7F) << SLV_ADDR_SHFT);

Drop some parenthesis.

Ok.

Quoted 12 lines
Quoted 12 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +11 -0
+
+		gi2c->cur = &msgs[i];
+		mode = msgs[i].len > 32 ? SE_DMA : FIFO_MODE;
+		ret = geni_se_select_mode(gi2c->base, mode);
+		if (ret) {
+			dev_err(gi2c->dev, "%s: Error mode init %d:%d:%d\n",
+				__func__, mode, i, msgs[i].len);
+			break;
+		}
+		if (msgs[i].flags & I2C_M_RD) {
+			dev_dbg(gi2c->dev,
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 353

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+				"READ,n:%d,i:%d len:%d, stretch:%d\n",
+					num, i, msgs[i].len, stretch);
+			geni_write_reg(msgs[i].len,
+				       gi2c->base, SE_I2C_RX_TRANS_LEN);
+			m_cmd = I2C_READ;
+			geni_se_setup_m_cmd(gi2c->base, m_cmd, m_param);

Drop m_cmd and just write I2C_READ in the function call.

Ok.

Quoted 28 lines
Quoted 28 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +27 -0
+			if (mode == SE_DMA) {
+				ret = geni_se_rx_dma_prep(gi2c->wrapper_dev,
+							gi2c->base, msgs[i].buf,
+							msgs[i].len, &rx_dma);
+				if (ret) {
+					mode = FIFO_MODE;
+					ret = geni_se_select_mode(gi2c->base,
+								  mode);
+				}
+			}
+		} else {
+			dev_dbg(gi2c->dev,
+				"WRITE:n:%d,i:%d len:%d, stretch:%d, m_param:0x%x\n",
+					num, i, msgs[i].len, stretch, m_param);
+			geni_write_reg(msgs[i].len, gi2c->base,
+						SE_I2C_TX_TRANS_LEN);
+			m_cmd = I2C_WRITE;
+			geni_se_setup_m_cmd(gi2c->base, m_cmd, m_param);
+			if (mode == SE_DMA) {
+				ret = geni_se_tx_dma_prep(gi2c->wrapper_dev,
+							gi2c->base, msgs[i].buf,
+							msgs[i].len, &tx_dma);
+				if (ret) {
+					mode = FIFO_MODE;
+					ret = geni_se_select_mode(gi2c->base,
+								  mode);
+				}
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 386

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+			}
+			if (mode == FIFO_MODE) /* Get FIFO IRQ */
+				geni_write_reg(1, gi2c->base,
+						SE_GENI_TX_WATERMARK_REG);
+		}
+		/* Ensure FIFO write go through before waiting for Done evet */

That's not what mb does, drop it.

Ok.

Quoted 7 lines

drivers/i2c/busses/i2c-qcom-geni.c line 388

Quoted 3 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+		mb();
+		timeout = wait_for_completion_timeout(&gi2c->xfer, HZ);

As written you should just use "ret", but the return value of wait_for_completion_timeout() is unsigned long, so change the type of timeout instead.

Ok.

Quoted 10 lines

drivers/i2c/busses/i2c-qcom-geni.c line 393

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+		if (!timeout) {
+			geni_i2c_err(gi2c, GENI_TIMEOUT);
+			gi2c->cur = NULL;
+			geni_se_abort_m_cmd(gi2c->base);
+			timeout = wait_for_completion_timeout(&gi2c->xfer, HZ);

What if it takes a fraction above HZ time to complete the previous operation, then you might end up here with the completion completed, but from the wrong operation.

I will update it to checking the specific "abort" flag using readl_poll_timeout.

Quoted 20 lines
Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+		}
+		gi2c->cur_wr = 0;
+		gi2c->cur_rd = 0;
+		if (mode == SE_DMA) {
+			if (gi2c->err) {

drivers/i2c/busses/i2c-qcom-geni.c line 408

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+				if (msgs[i].flags != I2C_M_RD)
+					writel_relaxed(1, gi2c->base +
+							SE_DMA_TX_FSM_RST);
+				else
+					writel_relaxed(1, gi2c->base +
+							SE_DMA_RX_FSM_RST);
+				wait_for_completion_timeout(&gi2c->xfer, HZ);
+			}
+			geni_se_rx_dma_unprep(gi2c->wrapper_dev, rx_dma,
+					      msgs[i].len);

Reduce the length of gi2c->wrapper_dev here by using a local variable, so that you get below (or close to) 80 chars.

Quoted 2 lines

Also, in either rx or tx cases above I see only that you prep one of thse, and then you're unprepping both.

I will re-organize the tx and rx into 2 separate functions. That way all the comments will be taken care of.

Quoted 30 lines
Quoted 20 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +19 -0
+			geni_se_tx_dma_unprep(gi2c->wrapper_dev, tx_dma,
+					      msgs[i].len);
+		}
+		ret = gi2c->err;
+		if (gi2c->err) {
+			dev_err(gi2c->dev, "i2c error :%d\n", gi2c->err);
+			break;
+		}
+	}
+	if (ret == 0)
+		ret = num;
+
+	pm_runtime_mark_last_busy(gi2c->dev);
+	pm_runtime_put_autosuspend(gi2c->dev);
+	gi2c->cur = NULL;
+	gi2c->err = 0;
+	dev_dbg(gi2c->dev, "i2c txn ret:%d\n", ret);
+	return ret;
+}

[..]

Quoted 9 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +9 -0
+static int geni_i2c_probe(struct platform_device *pdev)
+{
+	struct geni_i2c_dev *gi2c;
+	struct resource *res;
+	int ret;
+
+	gi2c = devm_kzalloc(&pdev->dev, sizeof(*gi2c), GFP_KERNEL);
+	if (!gi2c)
+		return -ENOMEM;
Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 453

Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +6 -0
+
+	gi2c->dev = &pdev->dev;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;

Put this right before devm_ioremap_resource() and drop the error check.

Ok.

Quoted 8 lines

drivers/i2c/busses/i2c-qcom-geni.c line 456

Quoted 4 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +3 -0
+
+	gi2c->wrapper_dev = pdev->dev.parent;
+	gi2c->i2c_rsc.wrapper_dev = pdev->dev.parent;

As suggested in the other patch, if you have an helper function in the wrapper driver that initializes the i2c_rsc then this could fill out the actual wrapper, instead of just the device.

Ok.

Quoted 17 lines

drivers/i2c/busses/i2c-qcom-geni.c line 468

Quoted 13 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +12 -0
+	gi2c->i2c_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(gi2c->i2c_rsc.se_clk)) {
+		ret = PTR_ERR(gi2c->i2c_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		return ret;
+	}
+
+	gi2c->base = devm_ioremap_resource(gi2c->dev, res);
+	if (IS_ERR(gi2c->base))
+		return PTR_ERR(gi2c->base);
+
+	gi2c->i2c_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);

Drop all the pinctrl stuff. You might still want to call pinctrl_pm_select_{idle,default,sleep}_state(), in the various stages of PM state though.

Ok.

Quoted 7 lines
Quoted 6 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +5 -0
+	if (IS_ERR_OR_NULL(gi2c->i2c_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified\n");
+		ret = PTR_ERR(gi2c->i2c_rsc.geni_pinctrl);
+		return ret;
+	}

[..]

Quoted 12 lines

drivers/i2c/busses/i2c-qcom-geni.c line 572

Quoted 10 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +10 -0
+static int geni_i2c_runtime_resume(struct device *dev)
+{
+	int ret;
+	struct geni_i2c_dev *gi2c = dev_get_drvdata(dev);
+
+	ret = geni_se_resources_on(&gi2c->i2c_rsc);
+	if (ret)
+		return ret;
+
+	if (!unlikely(gi2c->tx_wm)) {

Drop the unlikely()

Ok.

Quoted 9 lines

drivers/i2c/busses/i2c-qcom-geni.c line 576

Quoted 5 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +4 -0
+		int proto = geni_se_get_proto(gi2c->base);
+		int gi2c_tx_depth = geni_se_get_tx_fifo_depth(gi2c->base);
+
+		if (unlikely(proto != I2C)) {

Has this changes since probe? Can't we verify that the proto is correct during probe and then just trust that the hardware doesn't change function?

Yes we can do that. I will move the check to the probe.

Quoted 17 lines
Quoted 16 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +15 -0
+			dev_err(gi2c->dev, "Invalid proto %d\n", proto);
+			geni_se_resources_off(&gi2c->i2c_rsc);
+			return -ENXIO;
+		}
+
+		gi2c->tx_wm = gi2c_tx_depth - 1;
+		geni_se_init(gi2c->base, gi2c->tx_wm, gi2c_tx_depth);
+		geni_se_config_packing(gi2c->base, 8, 4, true);
+		dev_dbg(gi2c->dev, "i2c fifo/se-dma mode. fifo depth:%d\n",
+			gi2c_tx_depth);
+	}
+	enable_irq(gi2c->irq);
+
+	return 0;
+}

[..]

Quoted 4 lines

drivers/i2c/busses/i2c-qcom-geni.c line 656

Quoted 2 lines
drivers/i2c/busses/i2c-qcom-geni.c new file +2 -0
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:i2c_geni");

What will reference the kernel module by this alias?

I will remove it.

Quoted 9 lines
Quoted 9 lines
Signature · 8 lines
-- 
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#45 lore raw

Re: [v2, 7/7] tty: serial: msm_geni_serial: Add serial driver support for GENI based QUP

In reply to Guenter Roeck
Quoted 24 lines · Guenter Roeck
Quoted 23 lines · Karthikeyan Ramasubramanian

This driver supports GENI based UART Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including UART. This driver support console operations using FIFO mode of transfer.

---
  drivers/tty/serial/Kconfig            |   10 +
  drivers/tty/serial/Makefile           |    1 +
  drivers/tty/serial/qcom_geni_serial.c | 1414 +++++++++++++++++++++++++++++++++
  3 files changed, 1425 insertions(+)

create mode 100644 drivers/tty/serial/qcom_geni_serial.c

drivers/tty/serial/Kconfig +0 -0
index b788fee..1be30e5 100644
@@ -1098,6 +1098,16 @@ config SERIAL_MSM_CONSOLE
  	select SERIAL_CORE_CONSOLE
  	select SERIAL_EARLYCON
 
Quoted 10 lines

drivers/tty/serial/Kconfig config SERIAL_MSM_CONSOLE · line 1105

Quoted 5 lines
drivers/tty/serial/Kconfig +5 -0
+config SERIAL_QCOM_GENI
+	tristate "QCOM on-chip GENI based serial port support"
+	depends on ARCH_QCOM
+	select SERIAL_CORE
+	select SERIAL_CORE_CONSOLE

Serial console drivers have to be bool, not tristate. Building a console driver as module doesn't make sense (it is needed before modules are loaded). It also results in a build failure due to a symbol which is not exported.

I will mark it as bool.

Quoted 1,451 lines
Quoted 336 lines
drivers/tty/serial/Kconfig +5 -0
+	select SERIAL_EARLYCON
+	help
+	  Serial driver for Qualcomm Technologies Inc's GENI based QUP
+	  hardware.
+
  config SERIAL_VT8500
  	bool "VIA VT8500 on-chip serial port support"
  	depends on ARCH_VT8500
drivers/tty/serial/Makefile +1 -0
index 842d185..64a8d82 100644
@@ -63,6 +63,7 @@ obj-$(CONFIG_SERIAL_SGI_IOC3) += ioc3_serial.o
  obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
  obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
  obj-$(CONFIG_SERIAL_MSM) += msm_serial.o
+obj-$(CONFIG_SERIAL_QCOM_GENI) += qcom_geni_serial.o
  obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
  obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
  obj-$(CONFIG_SERIAL_OMAP) += omap-serial.o
drivers/tty/serial/qcom_geni_serial.c new file +309 -0
new file mode 100644
index 0000000..0dbd329
@@ -0,0 +1,1414 @@
+/*
+ * Copyright (c) 2017-2018, The Linux foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program 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 General Public License for more details.
+ */
+
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
+#include <linux/delay.h>
+#include <linux/console.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/qcom-geni-se.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+
+/* UART specific GENI registers */
+#define SE_UART_TX_TRANS_CFG		(0x25C)
+#define SE_UART_TX_WORD_LEN		(0x268)
+#define SE_UART_TX_STOP_BIT_LEN		(0x26C)
+#define SE_UART_TX_TRANS_LEN		(0x270)
+#define SE_UART_RX_TRANS_CFG		(0x280)
+#define SE_UART_RX_WORD_LEN		(0x28C)
+#define SE_UART_RX_STALE_CNT		(0x294)
+#define SE_UART_TX_PARITY_CFG		(0x2A4)
+#define SE_UART_RX_PARITY_CFG		(0x2A8)
+
+/* SE_UART_TRANS_CFG */
+#define UART_TX_PAR_EN		(BIT(0))
+#define UART_CTS_MASK		(BIT(1))
+
+/* SE_UART_TX_WORD_LEN */
+#define TX_WORD_LEN_MSK		(GENMASK(9, 0))
+
+/* SE_UART_TX_STOP_BIT_LEN */
+#define TX_STOP_BIT_LEN_MSK	(GENMASK(23, 0))
+#define TX_STOP_BIT_LEN_1	(0)
+#define TX_STOP_BIT_LEN_1_5	(1)
+#define TX_STOP_BIT_LEN_2	(2)
+
+/* SE_UART_TX_TRANS_LEN */
+#define TX_TRANS_LEN_MSK	(GENMASK(23, 0))
+
+/* SE_UART_RX_TRANS_CFG */
+#define UART_RX_INS_STATUS_BIT	(BIT(2))
+#define UART_RX_PAR_EN		(BIT(3))
+
+/* SE_UART_RX_WORD_LEN */
+#define RX_WORD_LEN_MASK	(GENMASK(9, 0))
+
+/* SE_UART_RX_STALE_CNT */
+#define RX_STALE_CNT		(GENMASK(23, 0))
+
+/* SE_UART_TX_PARITY_CFG/RX_PARITY_CFG */
+#define PAR_CALC_EN		(BIT(0))
+#define PAR_MODE_MSK		(GENMASK(2, 1))
+#define PAR_MODE_SHFT		(1)
+#define PAR_EVEN		(0x00)
+#define PAR_ODD			(0x01)
+#define PAR_SPACE		(0x10)
+#define PAR_MARK		(0x11)
+
+/* UART M_CMD OP codes */
+#define UART_START_TX		(0x1)
+#define UART_START_BREAK	(0x4)
+#define UART_STOP_BREAK		(0x5)
+/* UART S_CMD OP codes */
+#define UART_START_READ		(0x1)
+#define UART_PARAM		(0x1)
+
+#define UART_OVERSAMPLING	(32)
+#define STALE_TIMEOUT		(16)
+#define DEFAULT_BITS_PER_CHAR	(10)
+#define GENI_UART_NR_PORTS	(15)
+#define GENI_UART_CONS_PORTS	(1)
+#define DEF_FIFO_DEPTH_WORDS	(16)
+#define DEF_TX_WM		(2)
+#define DEF_FIFO_WIDTH_BITS	(32)
+#define UART_CORE2X_VOTE	(10000)
+#define UART_CONSOLE_RX_WM	(2)
+
+static int owr;
+module_param(owr, int, 0644);
+
+struct qcom_geni_serial_port {
+	struct uart_port uport;
+	char name[20];
+	unsigned int tx_fifo_depth;
+	unsigned int tx_fifo_width;
+	unsigned int rx_fifo_depth;
+	unsigned int tx_wm;
+	unsigned int rx_wm;
+	unsigned int rx_rfr;
+	int xfer_mode;
+	bool port_setup;
+	unsigned int *rx_fifo;
+	int (*handle_rx)(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+	struct device *wrapper_dev;
+	struct geni_se_rsc serial_rsc;
+	unsigned int xmit_size;
+	void *rx_buf;
+	unsigned int cur_baud;
+};
+
+static const struct uart_ops qcom_geni_serial_pops;
+static struct uart_driver qcom_geni_console_driver;
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx);
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *port);
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set);
+static void qcom_geni_serial_stop_rx(struct uart_port *uport);
+
+static atomic_t uart_line_id = ATOMIC_INIT(0);
+
+#define GET_DEV_PORT(uport) \
+	container_of(uport, struct qcom_geni_serial_port, uport)
+
+static struct qcom_geni_serial_port qcom_geni_console_port;
+
+static void qcom_geni_serial_config_port(struct uart_port *uport, int cfg_flags)
+{
+	if (cfg_flags & UART_CONFIG_TYPE)
+		uport->type = PORT_MSM;
+}
+
+static unsigned int qcom_geni_cons_get_mctrl(struct uart_port *uport)
+{
+	return TIOCM_DSR | TIOCM_CAR | TIOCM_CTS;
+}
+
+static void qcom_geni_cons_set_mctrl(struct uart_port *uport,
+							unsigned int mctrl)
+{
+}
+
+static const char *qcom_geni_serial_get_type(struct uart_port *uport)
+{
+	return "MSM";
+}
+
+static struct qcom_geni_serial_port *get_port_from_line(int line)
+{
+	struct qcom_geni_serial_port *port = NULL;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		port = ERR_PTR(-ENXIO);
+	port = &qcom_geni_console_port;
+	return port;
+}
+
+static int qcom_geni_serial_poll_bit(struct uart_port *uport,
+				int offset, int bit_field, bool set)
+{
+	int iter = 0;
+	unsigned int reg;
+	bool met = false;
+	struct qcom_geni_serial_port *port = NULL;
+	bool cond = false;
+	unsigned int baud = 115200;
+	unsigned int fifo_bits = DEF_FIFO_DEPTH_WORDS * DEF_FIFO_WIDTH_BITS;
+	unsigned long total_iter = 2000;
+
+
+	if (uport->private_data) {
+		port = GET_DEV_PORT(uport);
+		baud = (port->cur_baud ? port->cur_baud : 115200);
+		fifo_bits = port->tx_fifo_depth * port->tx_fifo_width;
+		/*
+		 * Total polling iterations based on FIFO worth of bytes to be
+		 * sent at current baud .Add a little fluff to the wait.
+		 */
+		total_iter = ((fifo_bits * USEC_PER_SEC) / baud) / 10;
+		total_iter += 50;
+	}
+
+	while (iter < total_iter) {
+		reg = geni_read_reg_nolog(uport->membase, offset);
+		cond = reg & bit_field;
+		if (cond == set) {
+			met = true;
+			break;
+		}
+		udelay(10);
+		iter++;
+	}
+	return met;
+}
+
+static void qcom_geni_serial_setup_tx(struct uart_port *uport,
+				unsigned int xmit_size)
+{
+	u32 m_cmd = 0;
+
+	geni_write_reg_nolog(xmit_size, uport->membase, SE_UART_TX_TRANS_LEN);
+	m_cmd |= (UART_START_TX << M_OPCODE_SHFT);
+	geni_write_reg_nolog(m_cmd, uport->membase, SE_GENI_M_CMD0);
+	/*
+	 * Writes to enable the primary sequencer should go through before
+	 * exiting this function.
+	 */
+	mb();
+}
+
+static void qcom_geni_serial_poll_cancel_tx(struct uart_port *uport)
+{
+	int done = 0;
+	unsigned int irq_clear = M_CMD_DONE_EN;
+	unsigned int geni_status = 0;
+
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_DONE_EN, true);
+	if (!done) {
+		geni_write_reg_nolog(M_GENI_CMD_ABORT, uport->membase,
+					SE_GENI_M_CMD_CTRL_REG);
+		owr++;
+		irq_clear |= M_CMD_ABORT_EN;
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+							M_CMD_ABORT_EN, true);
+	}
+	geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+	if (geni_status & M_GENI_CMD_ACTIVE)
+		owr++;
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_abort_rx(struct uart_port *uport)
+{
+	unsigned int irq_clear = S_CMD_DONE_EN;
+
+	geni_se_abort_s_cmd(uport->membase);
+	/* Ensure this goes through before polling. */
+	mb();
+	irq_clear |= S_CMD_ABORT_EN;
+	qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_ABORT, false);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	geni_write_reg(FORCE_DEFAULT, uport->membase, GENI_FORCE_DEFAULT_REG);
+}
+
+#ifdef CONFIG_CONSOLE_POLL
+static int qcom_geni_serial_get_char(struct uart_port *uport)
+{
+	unsigned int rx_fifo;
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+			M_SEC_IRQ_EN, true)))
+		return -ENXIO;
+
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	geni_write_reg_nolog(m_irq_status, uport->membase,
+						SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase,
+						SE_GENI_S_IRQ_CLEAR);
+
+	if (!(qcom_geni_serial_poll_bit(uport, SE_GENI_RX_FIFO_STATUS,
+			RX_FIFO_WC_MSK, true)))
+		return -ENXIO;
+
+	/*
+	 * Read the Rx FIFO only after clearing the interrupt registers and
+	 * getting valid RX fifo status.
+	 */
+	mb();
+	rx_fifo = geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+	rx_fifo &= 0xFF;
+	return rx_fifo;
+}
+
+static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
+					unsigned char c)
+{
+	int b = (int) c;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_write_reg_nolog(port->tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, 1);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+				M_TX_FIFO_WATERMARK_EN, true))
+		WARN_ON(1);
+	geni_write_reg_nolog(b, uport->membase, SE_GENI_TX_FIFOn);
+	geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,

drivers/tty/serial/qcom_geni_serial.c line 319

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+							SE_GENI_M_IRQ_CLEAR);
+	/*
+	 * Ensure FIFO write goes through before polling for status but.
+	 */
+	mb();
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+#endif
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)

"if defined(CONFIG_SERIAL_CORE_CONSOLE)" doesn't make much sense here since the Kconfig entry selects it. Given that, the entire conditional is unnecessary since it will always be true.

Quoted 1,085 lines
drivers/tty/serial/qcom_geni_serial.c new file +1085 -0
+static void qcom_geni_serial_wr_char(struct uart_port *uport, int ch)
+{
+	geni_write_reg_nolog(ch, uport->membase, SE_GENI_TX_FIFOn);
+	/*
+	 * Ensure FIFO write clear goes through before
+	 * next iteration.
+	 */
+	mb();
+
+}
+
+static void
+__qcom_geni_serial_console_write(struct uart_port *uport, const char *s,
+				unsigned int count)
+{
+	int new_line = 0;
+	int i;
+	int bytes_to_send = count;
+	int fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	int tx_wm = DEF_TX_WM;
+
+	for (i = 0; i < count; i++) {
+		if (s[i] == '\n')
+			new_line++;
+	}
+
+	bytes_to_send += new_line;
+	geni_write_reg_nolog(tx_wm, uport->membase,
+					SE_GENI_TX_WATERMARK_REG);
+	qcom_geni_serial_setup_tx(uport, bytes_to_send);
+	i = 0;
+	while (i < count) {
+		u32 chars_to_write = 0;
+		u32 avail_fifo_bytes = (fifo_depth - tx_wm);
+
+		/*
+		 * 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 (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_TX_FIFO_WATERMARK_EN, true))
+			break;
+		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,
+						qcom_geni_serial_wr_char);
+		geni_write_reg_nolog(M_TX_FIFO_WATERMARK_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+		/* Ensure this goes through before polling for WM IRQ again.*/
+		mb();
+		i += chars_to_write;
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+}
+
+static void qcom_geni_serial_console_write(struct console *co, const char *s,
+			      unsigned int count)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *port;
+	int locked = 1;
+	unsigned long flags;
+
+	WARN_ON(co->index < 0 || co->index >= GENI_UART_NR_PORTS);
+
+	port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(port))
+		return;
+
+	uport = &port->uport;
+	if (oops_in_progress)
+		locked = spin_trylock_irqsave(&uport->lock, flags);
+	else
+		spin_lock_irqsave(&uport->lock, flags);
+
+	if (locked) {
+		__qcom_geni_serial_console_write(uport, s, count);
+		spin_unlock_irqrestore(&uport->lock, flags);
+	}
+}
+
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx)
+{
+	int i, c;
+	unsigned char *rx_char;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	for (i = 0; i < rx_fifo_wc; i++) {
+		int bytes = 4;
+
+		*(qcom_port->rx_fifo) =
+			geni_read_reg_nolog(uport->membase, SE_GENI_RX_FIFOn);
+		if (drop_rx)
+			continue;
+		rx_char = (unsigned char *)qcom_port->rx_fifo;
+
+		if (i == (rx_fifo_wc - 1)) {
+			if (rx_last && rx_last_byte_valid)
+				bytes = rx_last_byte_valid;
+		}
+		for (c = 0; c < bytes; c++) {
+			char flag = TTY_NORMAL;
+			int sysrq;
+
+			uport->icount.rx++;
+			sysrq = uart_handle_sysrq_char(uport, rx_char[c]);
+			if (!sysrq)
+				tty_insert_flip_char(tport, rx_char[c], flag);
+		}
+	}
+	if (!drop_rx)
+		tty_flip_buffer_push(tport);
+	return 0;
+}
+#else
+static int handle_rx_console(struct uart_port *uport,
+			unsigned int rx_fifo_wc,
+			unsigned int rx_last_byte_valid,
+			unsigned int rx_last,
+			bool drop_rx)
+{
+	return -EPERM;
+}
+
+#endif /* (CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)) */
+
+static void qcom_geni_serial_start_tx(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned int geni_status;
+
+	if (qcom_port->xfer_mode == FIFO_MODE) {
+		geni_status = geni_read_reg_nolog(uport->membase,
+						  SE_GENI_STATUS);
+		if (geni_status & M_GENI_CMD_ACTIVE)
+			goto exit_start_tx;
+
+		if (!qcom_geni_serial_tx_empty(uport))
+			goto exit_start_tx;
+
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+						    SE_GENI_M_IRQ_EN);
+		geni_m_irq_en |= (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN);
+
+		geni_write_reg_nolog(qcom_port->tx_wm, uport->membase,
+						SE_GENI_TX_WATERMARK_REG);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+		/* Geni command setup should complete before returning.*/
+		mb();
+	}
+exit_start_tx:
+	return;
+}
+
+static void stop_tx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_m_irq_en &= ~M_CMD_DONE_EN;
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_m_irq_en &= ~M_TX_FIFO_WATERMARK_EN;
+		geni_write_reg_nolog(0, uport->membase,
+				     SE_GENI_TX_WATERMARK_REG);
+	}
+	port->xmit_size = 0;
+	geni_write_reg_nolog(geni_m_irq_en, uport->membase, SE_GENI_M_IRQ_EN);
+	geni_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_STATUS);
+	/* Possible stop tx is called multiple times. */
+	if (!(geni_status & M_GENI_CMD_ACTIVE))
+		return;
+
+	geni_se_cancel_m_cmd(uport->membase);
+	if (!qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_CANCEL_EN, true)) {
+		geni_se_abort_m_cmd(uport->membase);
+		qcom_geni_serial_poll_bit(uport, SE_GENI_M_IRQ_STATUS,
+						M_CMD_ABORT_EN, true);
+		geni_write_reg_nolog(M_CMD_ABORT_EN, uport->membase,
+							SE_GENI_M_IRQ_CLEAR);
+	}
+	geni_write_reg_nolog(M_CMD_CANCEL_EN, uport, SE_GENI_M_IRQ_CLEAR);
+}
+
+static void qcom_geni_serial_stop_tx(struct uart_port *uport)
+{
+	stop_tx_sequencer(uport);
+}
+
+static void start_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	if (geni_status & S_GENI_CMD_ACTIVE)
+		qcom_geni_serial_stop_rx(uport);
+
+	geni_se_setup_s_cmd(uport->membase, UART_START_READ, 0);
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+
+		geni_s_irq_en |= S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN;
+		geni_m_irq_en |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+	/*
+	 * Ensure the writes to the secondary sequencer and interrupt enables
+	 * go through.
+	 */
+	mb();
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+}
+
+static void qcom_geni_serial_start_rx(struct uart_port *uport)
+{
+	start_rx_sequencer(uport);
+}
+
+static void stop_rx_sequencer(struct uart_port *uport)
+{
+	unsigned int geni_s_irq_en;
+	unsigned int geni_m_irq_en;
+	unsigned int geni_status;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	u32 irq_clear = S_CMD_DONE_EN;
+	bool done;
+
+	if (port->xfer_mode == FIFO_MODE) {
+		geni_s_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_m_irq_en = geni_read_reg_nolog(uport->membase,
+							SE_GENI_M_IRQ_EN);
+		geni_s_irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);
+		geni_m_irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
+
+		geni_write_reg_nolog(geni_s_irq_en, uport->membase,
+							SE_GENI_S_IRQ_EN);
+		geni_write_reg_nolog(geni_m_irq_en, uport->membase,
+							SE_GENI_M_IRQ_EN);
+	}
+
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	/* Possible stop rx is called multiple times. */
+	if (!(geni_status & S_GENI_CMD_ACTIVE))
+		return;
+	geni_se_cancel_s_cmd(uport->membase);
+	/*
+	 * Ensure that the cancel goes through before polling for the
+	 * cancel control bit.
+	 */
+	mb();
+	done = qcom_geni_serial_poll_bit(uport, SE_GENI_S_CMD_CTRL_REG,
+					S_GENI_CMD_CANCEL, false);
+	geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS);
+	geni_write_reg_nolog(irq_clear, uport->membase, SE_GENI_S_IRQ_CLEAR);
+	if ((geni_status & S_GENI_CMD_ACTIVE))
+		qcom_geni_serial_abort_rx(uport);
+}
+
+static void qcom_geni_serial_stop_rx(struct uart_port *uport)
+{
+	stop_rx_sequencer(uport);
+}
+
+static int qcom_geni_serial_handle_rx(struct uart_port *uport, bool drop_rx)
+{
+	int ret = 0;
+	unsigned int rx_fifo_status;
+	unsigned int rx_fifo_wc = 0;
+	unsigned int rx_last_byte_valid = 0;
+	unsigned int rx_last = 0;
+	struct tty_port *tport;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+
+	tport = &uport->state->port;
+	rx_fifo_status = geni_read_reg_nolog(uport->membase,
+				SE_GENI_RX_FIFO_STATUS);
+	rx_fifo_wc = rx_fifo_status & RX_FIFO_WC_MSK;
+	rx_last_byte_valid = ((rx_fifo_status & RX_LAST_BYTE_VALID_MSK) >>
+						RX_LAST_BYTE_VALID_SHFT);
+	rx_last = rx_fifo_status & RX_LAST;
+	if (rx_fifo_wc)
+		port->handle_rx(uport, rx_fifo_wc, rx_last_byte_valid,
+							rx_last, drop_rx);
+	return ret;
+}
+
+static int qcom_geni_serial_handle_tx(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	struct circ_buf *xmit = &uport->state->xmit;
+	unsigned int avail_fifo_bytes = 0;
+	unsigned int bytes_remaining = 0;
+	int i = 0;
+	unsigned int tx_fifo_status;
+	unsigned int xmit_size;
+	unsigned int fifo_width_bytes = 1;
+	int temp_tail = 0;
+
+	xmit_size = uart_circ_chars_pending(xmit);
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+					SE_GENI_TX_FIFO_STATUS);
+	/* Both FIFO and framework buffer are drained */
+	if ((xmit_size == qcom_port->xmit_size) && !tx_fifo_status) {
+		qcom_port->xmit_size = 0;
+		uart_circ_clear(xmit);
+		qcom_geni_serial_stop_tx(uport);
+		goto exit_handle_tx;
+	}
+	xmit_size -= qcom_port->xmit_size;
+
+	avail_fifo_bytes = (qcom_port->tx_fifo_depth - qcom_port->tx_wm) *
+							fifo_width_bytes;
+	temp_tail = (xmit->tail + qcom_port->xmit_size) & (UART_XMIT_SIZE - 1);
+	if (xmit_size > (UART_XMIT_SIZE - temp_tail))
+		xmit_size = (UART_XMIT_SIZE - temp_tail);
+	if (xmit_size > avail_fifo_bytes)
+		xmit_size = avail_fifo_bytes;
+
+	if (!xmit_size)
+		goto exit_handle_tx;
+
+	qcom_geni_serial_setup_tx(uport, xmit_size);
+
+	bytes_remaining = xmit_size;
+	while (i < xmit_size) {
+		unsigned int tx_bytes;
+		unsigned int buf = 0;
+		int c;
+
+		tx_bytes = ((bytes_remaining < fifo_width_bytes) ?
+					bytes_remaining : fifo_width_bytes);
+
+		for (c = 0; c < tx_bytes ; c++)
+			buf |= (xmit->buf[temp_tail + c] << (c * 8));
+		geni_write_reg_nolog(buf, uport->membase, SE_GENI_TX_FIFOn);
+		i += tx_bytes;
+		temp_tail = (temp_tail + tx_bytes) & (UART_XMIT_SIZE - 1);
+		uport->icount.tx += tx_bytes;
+		bytes_remaining -= tx_bytes;
+		/* Ensure FIFO write goes through */
+		wmb();
+	}
+	qcom_geni_serial_poll_cancel_tx(uport);
+	qcom_port->xmit_size += xmit_size;
+exit_handle_tx:
+	uart_write_wakeup(uport);
+	return ret;
+}
+
+static irqreturn_t qcom_geni_serial_isr(int isr, void *dev)
+{
+	unsigned int m_irq_status;
+	unsigned int s_irq_status;
+	struct uart_port *uport = dev;
+	unsigned long flags;
+	unsigned int m_irq_en;
+	bool drop_rx = false;
+	struct tty_port *tport = &uport->state->port;
+
+	spin_lock_irqsave(&uport->lock, flags);
+	if (uport->suspended)
+		goto exit_geni_serial_isr;
+	m_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_M_IRQ_STATUS);
+	s_irq_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_S_IRQ_STATUS);
+	m_irq_en = geni_read_reg_nolog(uport->membase, SE_GENI_M_IRQ_EN);
+	geni_write_reg_nolog(m_irq_status, uport->membase, SE_GENI_M_IRQ_CLEAR);
+	geni_write_reg_nolog(s_irq_status, uport->membase, SE_GENI_S_IRQ_CLEAR);
+
+	if ((m_irq_status & M_ILLEGAL_CMD_EN)) {
+		WARN_ON(1);
+		goto exit_geni_serial_isr;
+	}
+
+	if (s_irq_status & S_RX_FIFO_WR_ERR_EN) {
+		uport->icount.overrun++;
+		tty_insert_flip_char(tport, 0, TTY_OVERRUN);
+	}
+
+	if ((m_irq_status & m_irq_en) &
+	    (M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN))
+		qcom_geni_serial_handle_tx(uport);
+
+	if ((s_irq_status & S_GP_IRQ_0_EN) || (s_irq_status & S_GP_IRQ_1_EN)) {
+		if (s_irq_status & S_GP_IRQ_0_EN)
+			uport->icount.parity++;
+		drop_rx = true;
+	} else if ((s_irq_status & S_GP_IRQ_2_EN) ||
+		(s_irq_status & S_GP_IRQ_3_EN)) {
+		uport->icount.brk++;
+	}
+
+	if ((s_irq_status & S_RX_FIFO_WATERMARK_EN) ||
+		(s_irq_status & S_RX_FIFO_LAST_EN))
+		qcom_geni_serial_handle_rx(uport, drop_rx);
+
+exit_geni_serial_isr:
+	spin_unlock_irqrestore(&uport->lock, flags);
+	return IRQ_HANDLED;
+}
+
+static int get_tx_fifo_size(struct qcom_geni_serial_port *port)
+{
+	struct uart_port *uport;
+
+	if (!port)
+		return -ENODEV;
+
+	uport = &port->uport;
+	port->tx_fifo_depth = geni_se_get_tx_fifo_depth(uport->membase);
+	if (!port->tx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->tx_fifo_width = geni_se_get_tx_fifo_width(uport->membase);
+	if (!port->tx_fifo_width) {
+		dev_err(uport->dev, "%s:Invalid TX FIFO width read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	port->rx_fifo_depth = geni_se_get_rx_fifo_depth(uport->membase);
+	if (!port->rx_fifo_depth) {
+		dev_err(uport->dev, "%s:Invalid RX FIFO depth read\n",
+								__func__);
+		return -ENXIO;
+	}
+
+	uport->fifosize =
+		((port->tx_fifo_depth * port->tx_fifo_width) >> 3);
+	return 0;
+}
+
+static void set_rfr_wm(struct qcom_geni_serial_port *port)
+{
+	/*
+	 * Set RFR (Flow off) to FIFO_DEPTH - 2.
+	 * RX WM level at 10% RX_FIFO_DEPTH.
+	 * TX WM level at 10% TX_FIFO_DEPTH.
+	 */
+	port->rx_rfr = port->rx_fifo_depth - 2;
+	port->rx_wm = UART_CONSOLE_RX_WM;
+	port->tx_wm = 2;
+}
+
+static void qcom_geni_serial_shutdown(struct uart_port *uport)
+{
+	unsigned long flags;
+
+	/* Stop the console before stopping the current tx */
+	console_stop(uport->cons);
+
+	disable_irq(uport->irq);
+	free_irq(uport->irq, uport);
+	spin_lock_irqsave(&uport->lock, flags);
+	qcom_geni_serial_stop_tx(uport);
+	qcom_geni_serial_stop_rx(uport);
+	spin_unlock_irqrestore(&uport->lock, flags);
+}
+
+static int qcom_geni_serial_port_setup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+	unsigned long cfg0, cfg1;
+	unsigned int rxstale = DEFAULT_BITS_PER_CHAR * STALE_TIMEOUT;
+
+	set_rfr_wm(qcom_port);
+	geni_write_reg_nolog(rxstale, uport->membase, SE_UART_RX_STALE_CNT);
+	/*
+	 * Make an unconditional cancel on the main sequencer to reset
+	 * it else we could end up in data loss scenarios.
+	 */
+	qcom_port->xfer_mode = FIFO_MODE;
+	qcom_geni_serial_poll_cancel_tx(uport);
+	geni_se_get_packing_config(8, 1, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_TX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_TX_PACKING_CFG1);
+	geni_se_get_packing_config(8, 4, false, &cfg0, &cfg1);
+	geni_write_reg_nolog(cfg0, uport->membase,
+					SE_GENI_RX_PACKING_CFG0);
+	geni_write_reg_nolog(cfg1, uport->membase,
+					SE_GENI_RX_PACKING_CFG1);
+	ret = geni_se_init(uport->membase, qcom_port->rx_wm, qcom_port->rx_rfr);
+	if (ret) {
+		dev_err(uport->dev, "%s: Fail\n", __func__);
+		goto exit_portsetup;
+	}
+
+	ret = geni_se_select_mode(uport->membase, qcom_port->xfer_mode);
+	if (ret)
+		goto exit_portsetup;
+
+	qcom_port->port_setup = true;
+	/*
+	 * Ensure Port setup related IO completes before returning to
+	 * framework.
+	 */
+	mb();
+exit_portsetup:
+	return ret;
+}
+
+static int qcom_geni_serial_startup(struct uart_port *uport)
+{
+	int ret = 0;
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	scnprintf(qcom_port->name, sizeof(qcom_port->name),
+		  "qcom_serial_geni%d",	uport->line);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		dev_err(uport->dev, "%s: Invalid FW %d loaded.\n",
+				 __func__, geni_se_get_proto(uport->membase));
+		ret = -ENXIO;
+		goto exit_startup;
+	}
+
+	get_tx_fifo_size(qcom_port);
+	if (!qcom_port->port_setup) {
+		if (qcom_geni_serial_port_setup(uport))
+			goto exit_startup;
+	}
+
+	/*
+	 * Ensure that all the port configuration writes complete
+	 * before returning to the framework.
+	 */
+	mb();
+	ret = request_irq(uport->irq, qcom_geni_serial_isr, IRQF_TRIGGER_HIGH,
+			qcom_port->name, uport);
+	if (unlikely(ret)) {
+		dev_err(uport->dev, "%s: Failed to get IRQ ret %d\n",
+							__func__, ret);
+		goto exit_startup;
+	}
+
+exit_startup:
+	return ret;
+}
+
+static int get_clk_cfg(unsigned long clk_freq, unsigned long *ser_clk)
+{
+	unsigned long root_freq[] = {7372800, 14745600, 19200000, 29491200,
+		32000000, 48000000, 64000000, 80000000, 96000000, 100000000};
+	int i;
+	int match = -1;
+
+	for (i = 0; i < ARRAY_SIZE(root_freq); i++) {
+		if (clk_freq > root_freq[i])
+			continue;
+
+		if (!(root_freq[i] % clk_freq)) {
+			match = i;
+			break;
+		}
+	}
+	if (match != -1)
+		*ser_clk = root_freq[match];
+	else
+		pr_err("clk_freq %ld\n", clk_freq);
+	return match;
+}
+
+static void geni_serial_write_term_regs(struct uart_port *uport,
+		u32 tx_trans_cfg, u32 tx_parity_cfg, u32 rx_trans_cfg,
+		u32 rx_parity_cfg, u32 bits_per_char, u32 stop_bit_len,
+		u32 s_clk_cfg)
+{
+	geni_write_reg_nolog(tx_trans_cfg, uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	geni_write_reg_nolog(tx_parity_cfg, uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	geni_write_reg_nolog(rx_trans_cfg, uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	geni_write_reg_nolog(rx_parity_cfg, uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_TX_WORD_LEN);
+	geni_write_reg_nolog(bits_per_char, uport->membase,
+							SE_UART_RX_WORD_LEN);
+	geni_write_reg_nolog(stop_bit_len, uport->membase,
+						SE_UART_TX_STOP_BIT_LEN);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_M_CLK_CFG);
+	geni_write_reg_nolog(s_clk_cfg, uport->membase, GENI_SER_S_CLK_CFG);
+}
+
+static int get_clk_div_rate(unsigned int baud, unsigned long *desired_clk_rate)
+{
+	unsigned long ser_clk;
+	int dfs_index;
+	int clk_div = 0;
+
+	*desired_clk_rate = baud * UART_OVERSAMPLING;
+	dfs_index = get_clk_cfg(*desired_clk_rate, &ser_clk);
+	if (dfs_index < 0) {
+		pr_err("%s: Can't find matching DFS entry for baud %d\n",
+								__func__, baud);
+		clk_div = -EINVAL;
+		goto exit_get_clk_div_rate;
+	}
+
+	clk_div = ser_clk / *desired_clk_rate;
+	*desired_clk_rate = ser_clk;
+exit_get_clk_div_rate:
+	return clk_div;
+}
+
+static void qcom_geni_serial_set_termios(struct uart_port *uport,
+				struct ktermios *termios, struct ktermios *old)
+{
+	unsigned int baud;
+	unsigned int bits_per_char = 0;
+	unsigned int tx_trans_cfg;
+	unsigned int tx_parity_cfg;
+	unsigned int rx_trans_cfg;
+	unsigned int rx_parity_cfg;
+	unsigned int stop_bit_len;
+	unsigned int clk_div;
+	unsigned long ser_clk_cfg = 0;
+	struct qcom_geni_serial_port *port = GET_DEV_PORT(uport);
+	unsigned long clk_rate;
+
+	qcom_geni_serial_stop_rx(uport);
+	/* baud rate */
+	baud = uart_get_baud_rate(uport, termios, old, 300, 4000000);
+	port->cur_baud = baud;
+	clk_div = get_clk_div_rate(baud, &clk_rate);
+	if (clk_div <= 0)
+		goto exit_set_termios;
+
+	uport->uartclk = clk_rate;
+	clk_set_rate(port->serial_rsc.se_clk, clk_rate);
+	ser_clk_cfg |= SER_CLK_EN;
+	ser_clk_cfg |= (clk_div << CLK_DIV_SHFT);
+
+	/* parity */
+	tx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_TRANS_CFG);
+	tx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_TX_PARITY_CFG);
+	rx_trans_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_TRANS_CFG);
+	rx_parity_cfg = geni_read_reg_nolog(uport->membase,
+							SE_UART_RX_PARITY_CFG);
+	if (termios->c_cflag & PARENB) {
+		tx_trans_cfg |= UART_TX_PAR_EN;
+		rx_trans_cfg |= UART_RX_PAR_EN;
+		tx_parity_cfg |= PAR_CALC_EN;
+		rx_parity_cfg |= PAR_CALC_EN;
+		if (termios->c_cflag & PARODD) {
+			tx_parity_cfg |= PAR_ODD;
+			rx_parity_cfg |= PAR_ODD;
+		} else if (termios->c_cflag & CMSPAR) {
+			tx_parity_cfg |= PAR_SPACE;
+			rx_parity_cfg |= PAR_SPACE;
+		} else {
+			tx_parity_cfg |= PAR_EVEN;
+			rx_parity_cfg |= PAR_EVEN;
+		}
+	} else {
+		tx_trans_cfg &= ~UART_TX_PAR_EN;
+		rx_trans_cfg &= ~UART_RX_PAR_EN;
+		tx_parity_cfg &= ~PAR_CALC_EN;
+		rx_parity_cfg &= ~PAR_CALC_EN;
+	}
+
+	/* bits per char */
+	switch (termios->c_cflag & CSIZE) {
+	case CS5:
+		bits_per_char = 5;
+		break;
+	case CS6:
+		bits_per_char = 6;
+		break;
+	case CS7:
+		bits_per_char = 7;
+		break;
+	case CS8:
+	default:
+		bits_per_char = 8;
+		break;
+	}
+
+	/* stop bits */
+	if (termios->c_cflag & CSTOPB)
+		stop_bit_len = TX_STOP_BIT_LEN_2;
+	else
+		stop_bit_len = TX_STOP_BIT_LEN_1;
+
+	/* flow control, clear the CTS_MASK bit if using flow control. */
+	if (termios->c_cflag & CRTSCTS)
+		tx_trans_cfg &= ~UART_CTS_MASK;
+	else
+		tx_trans_cfg |= UART_CTS_MASK;
+
+	if (likely(baud))
+		uart_update_timeout(uport, termios->c_cflag, baud);
+
+	geni_serial_write_term_regs(uport, tx_trans_cfg, tx_parity_cfg,
+		rx_trans_cfg, rx_parity_cfg, bits_per_char, stop_bit_len,
+								ser_clk_cfg);
+exit_set_termios:
+	qcom_geni_serial_start_rx(uport);
+	return;
+
+}
+
+static unsigned int qcom_geni_serial_tx_empty(struct uart_port *uport)
+{
+	unsigned int tx_fifo_status;
+	unsigned int is_tx_empty = 1;
+
+	tx_fifo_status = geni_read_reg_nolog(uport->membase,
+						SE_GENI_TX_FIFO_STATUS);
+	if (tx_fifo_status)
+		is_tx_empty = 0;
+
+	return is_tx_empty;
+}
+
+#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
+static int __init qcom_geni_console_setup(struct console *co, char *options)
+{
+	struct uart_port *uport;
+	struct qcom_geni_serial_port *dev_port;
+	int baud = 115200;
+	int bits = 8;
+	int parity = 'n';
+	int flow = 'n';
+	int ret = 0;
+
+	if (unlikely(co->index >= GENI_UART_NR_PORTS  || co->index < 0))
+		return -ENXIO;
+
+	dev_port = get_port_from_line(co->index);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		pr_err("Invalid line %d(%d)\n", co->index, ret);
+		return ret;
+	}
+
+	uport = &dev_port->uport;
+
+	if (unlikely(!uport->membase))
+		return -ENXIO;
+
+	if (geni_se_resources_on(&dev_port->serial_rsc))
+		WARN_ON(1);
+
+	if (unlikely(geni_se_get_proto(uport->membase) != UART)) {
+		geni_se_resources_off(&dev_port->serial_rsc);
+		return -ENXIO;
+	}
+
+	if (!dev_port->port_setup) {
+		qcom_geni_serial_stop_rx(uport);
+		qcom_geni_serial_port_setup(uport);
+	}
+
+	if (options)
+		uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+	return uart_set_options(uport, co, baud, parity, bits, flow);
+}
+
+static int console_register(struct uart_driver *drv)
+{
+	return uart_register_driver(drv);
+}
+static void console_unregister(struct uart_driver *drv)
+{
+	uart_unregister_driver(drv);
+}
+
+static struct console cons_ops = {
+	.name = "ttyMSM",
+	.write = qcom_geni_serial_console_write,
+	.device = uart_console_device,
+	.setup = qcom_geni_console_setup,
+	.flags = CON_PRINTBUFFER,
+	.index = -1,
+	.data = &qcom_geni_console_driver,
+};
+
+static struct uart_driver qcom_geni_console_driver = {
+	.owner = THIS_MODULE,
+	.driver_name = "qcom_geni_console",
+	.dev_name = "ttyMSM",
+	.nr =  GENI_UART_NR_PORTS,
+	.cons = &cons_ops,
+};
+#else
+static int console_register(struct uart_driver *drv)
+{
+	return 0;
+}
+
+static void console_unregister(struct uart_driver *drv)
+{
+}
+#endif /* defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL) */
+
+static void qcom_geni_serial_cons_pm(struct uart_port *uport,
+		unsigned int new_state, unsigned int old_state)
+{
+	struct qcom_geni_serial_port *qcom_port = GET_DEV_PORT(uport);
+
+	if (unlikely(!uart_console(uport)))
+		return;
+
+	if (new_state == UART_PM_STATE_ON && old_state == UART_PM_STATE_OFF)
+		geni_se_resources_on(&qcom_port->serial_rsc);
+	else if (new_state == UART_PM_STATE_OFF &&
+			old_state == UART_PM_STATE_ON)
+		geni_se_resources_off(&qcom_port->serial_rsc);
+}
+
+static const struct uart_ops qcom_geni_console_pops = {
+	.tx_empty = qcom_geni_serial_tx_empty,
+	.stop_tx = qcom_geni_serial_stop_tx,
+	.start_tx = qcom_geni_serial_start_tx,
+	.stop_rx = qcom_geni_serial_stop_rx,
+	.set_termios = qcom_geni_serial_set_termios,
+	.startup = qcom_geni_serial_startup,
+	.config_port = qcom_geni_serial_config_port,
+	.shutdown = qcom_geni_serial_shutdown,
+	.type = qcom_geni_serial_get_type,
+	.set_mctrl = qcom_geni_cons_set_mctrl,
+	.get_mctrl = qcom_geni_cons_get_mctrl,
+#ifdef CONFIG_CONSOLE_POLL
+	.poll_get_char	= qcom_geni_serial_get_char,
+	.poll_put_char	= qcom_geni_serial_poll_put_char,
+#endif
+	.pm = qcom_geni_serial_cons_pm,
+};
+
+static const struct of_device_id qcom_geni_serial_match_table[] = {
+	{ .compatible = "qcom,geni-debug-uart",
+			.data = (void *)&qcom_geni_console_driver},
+};
+
+static int qcom_geni_serial_probe(struct platform_device *pdev)
+{
+	int ret = 0;
+	int line = -1;
+	struct qcom_geni_serial_port *dev_port;
+	struct uart_port *uport;
+	struct resource *res;
+	struct uart_driver *drv;
+	const struct of_device_id *id;
+
+	id = of_match_device(qcom_geni_serial_match_table, &pdev->dev);
+	if (id) {
+		dev_dbg(&pdev->dev, "%s: %s\n", __func__, id->compatible);
+		drv = (struct uart_driver *)id->data;
+	} else {
+		dev_err(&pdev->dev, "%s: No matching device found", __func__);
+		return -ENODEV;
+	}
+
+	if (pdev->dev.of_node) {
+		if (drv->cons)
+			line = of_alias_get_id(pdev->dev.of_node, "serial");
+	} else {
+		line = pdev->id;
+	}
+
+	if (line < 0)
+		line = atomic_inc_return(&uart_line_id) - 1;
+
+	if ((line < 0) || (line >= GENI_UART_CONS_PORTS))
+		return -ENXIO;
+	dev_port = get_port_from_line(line);
+	if (IS_ERR_OR_NULL(dev_port)) {
+		ret = PTR_ERR(dev_port);
+		dev_err(&pdev->dev, "Invalid line %d(%d)\n",
+					line, ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport = &dev_port->uport;
+
+	/* Don't allow 2 drivers to access the same port */
+	if (uport->private_data) {
+		ret = -ENODEV;
+		goto exit_geni_serial_probe;
+	}
+
+	uport->dev = &pdev->dev;
+	dev_port->wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.wrapper_dev = pdev->dev.parent;
+	dev_port->serial_rsc.se_clk = devm_clk_get(&pdev->dev, "se-clk");
+	if (IS_ERR(dev_port->serial_rsc.se_clk)) {
+		ret = PTR_ERR(dev_port->serial_rsc.se_clk);
+		dev_err(&pdev->dev, "Err getting SE Core clk %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "se-phys");
+	if (!res) {
+		ret = -ENXIO;
+		dev_err(&pdev->dev, "Err getting IO region\n");
+		goto exit_geni_serial_probe;
+	}
+
+	uport->mapbase = res->start;
+	uport->membase = devm_ioremap(&pdev->dev, res->start,
+						resource_size(res));
+	if (!uport->membase) {
+		ret = -ENOMEM;
+		dev_err(&pdev->dev, "Err IO mapping serial iomem");
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_pinctrl = devm_pinctrl_get(&pdev->dev);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_pinctrl)) {
+		dev_err(&pdev->dev, "No pinctrl config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_pinctrl);
+		goto exit_geni_serial_probe;
+	}
+	dev_port->serial_rsc.geni_gpio_active =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_DEFAULT);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_active)) {
+		dev_err(&pdev->dev, "No default config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_active);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->serial_rsc.geni_gpio_sleep =
+		pinctrl_lookup_state(dev_port->serial_rsc.geni_pinctrl,
+							PINCTRL_SLEEP);
+	if (IS_ERR_OR_NULL(dev_port->serial_rsc.geni_gpio_sleep)) {
+		dev_err(&pdev->dev, "No sleep config specified!\n");
+		ret = PTR_ERR(dev_port->serial_rsc.geni_gpio_sleep);
+		goto exit_geni_serial_probe;
+	}
+
+	dev_port->tx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->rx_fifo_depth = DEF_FIFO_DEPTH_WORDS;
+	dev_port->tx_fifo_width = DEF_FIFO_WIDTH_BITS;
+	uport->fifosize =
+		((dev_port->tx_fifo_depth * dev_port->tx_fifo_width) >> 3);
+
+	uport->irq = platform_get_irq(pdev, 0);
+	if (uport->irq < 0) {
+		ret = uport->irq;
+		dev_err(&pdev->dev, "Failed to get IRQ %d\n", ret);
+		goto exit_geni_serial_probe;
+	}
+
+	uport->private_data = (void *)drv;
+	platform_set_drvdata(pdev, dev_port);
+	dev_port->handle_rx = handle_rx_console;
+	dev_port->rx_fifo = devm_kzalloc(uport->dev, sizeof(u32),
+								GFP_KERNEL);
+	dev_port->port_setup = false;
+	return uart_add_one_port(drv, uport);
+
+exit_geni_serial_probe:
+	return ret;
+}
+
+static int qcom_geni_serial_remove(struct platform_device *pdev)
+{
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_driver *drv =
+			(struct uart_driver *)port->uport.private_data;
+
+	uart_remove_one_port(drv, &port->uport);
+	return 0;
+}
+
+
+#ifdef CONFIG_PM
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	uart_suspend_port((struct uart_driver *)uport->private_data,
+				uport);
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
+	struct uart_port *uport = &port->uport;
+
+	if (console_suspend_enabled && uport->suspended) {
+		uart_resume_port((struct uart_driver *)uport->private_data,
+									uport);
+		disable_irq(uport->irq);
+	}
+	return 0;
+}
+#else
+static int qcom_geni_serial_sys_suspend_noirq(struct device *dev)
+{
+	return 0;
+}
+
+static int qcom_geni_serial_sys_resume_noirq(struct device *dev)
+{
+	return 0;
+}
+#endif
+
+static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
+	.suspend_noirq = qcom_geni_serial_sys_suspend_noirq,
+	.resume_noirq = qcom_geni_serial_sys_resume_noirq,
+};
+
+static struct platform_driver qcom_geni_serial_platform_driver = {
+	.remove = qcom_geni_serial_remove,
+	.probe = qcom_geni_serial_probe,
+	.driver = {
+		.name = "qcom_geni_serial",
+		.of_match_table = qcom_geni_serial_match_table,
+		.pm = &qcom_geni_serial_pm_ops,
+	},
+};
+
+static int __init qcom_geni_serial_init(void)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 0; i < GENI_UART_CONS_PORTS; i++) {
+		qcom_geni_console_port.uport.iotype = UPIO_MEM;
+		qcom_geni_console_port.uport.ops = &qcom_geni_console_pops;
+		qcom_geni_console_port.uport.flags = UPF_BOOT_AUTOCONF;
+		qcom_geni_console_port.uport.line = i;
+	}
+
+	ret = console_register(&qcom_geni_console_driver);
+	if (ret)
+		return ret;
+
+	ret = platform_driver_register(&qcom_geni_serial_platform_driver);
+	if (ret) {
+		console_unregister(&qcom_geni_console_driver);
+		return ret;
+	}
+	return ret;
+}
+module_init(qcom_geni_serial_init);
+

drivers/tty/serial/qcom_geni_serial.c line 1414

Quoted 10 lines
drivers/tty/serial/qcom_geni_serial.c new file +10 -0
+static void __exit qcom_geni_serial_exit(void)
+{
+	platform_driver_unregister(&qcom_geni_serial_platform_driver);
+	console_unregister(&qcom_geni_console_driver);
+}
+module_exit(qcom_geni_serial_exit);
+
+MODULE_DESCRIPTION("Serial driver for GENI based QUP cores");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("tty:qcom_geni_serial");

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

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#37 lore raw

Re: [PATCH v2 6/7] dt-bindings: serial: Add bindings for GENI based UART Controller

In reply to Bjorn Andersson
Quoted 22 lines · Bjorn Andersson
Quoted 20 lines · Karthikeyan Ramasubramanian

Add device tree binding support for GENI based UART Controller in the QUP Wrapper.

---
  .../devicetree/bindings/serial/qcom,geni-uart.txt  | 29 ++++++++++++++++++++++
  .../devicetree/bindings/soc/qcom/qcom,geni-se.txt  | 13 ++++++++++
  2 files changed, 42 insertions(+)

create mode 100644 Documentation/devicetree/bindings/serial/qcom,geni-uart.txt

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +3 -0
new file mode 100644
index 0000000..e7b9e24
@@ -0,0 +1,29 @@
+Qualcomm Technologies Inc. GENI Serial Engine based UART Controller
+
+The Generic Interface (GENI) Serial Engine based UART controller supports
Quoted 8 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 8

Quoted 5 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +5 -0
+console use-cases and is supported only by GENI based Qualcomm Universal
+Peripheral (QUP) cores.
+
+Required properties:
+- compatible: should contain "qcom,geni-debug-uart".

Why is this uart a _debug_ uart? Is there a separate binding for the geni-uart?

Yes. It will be uploaded at a later point in time.

Quoted 7 lines

I like that your naming here matches my suggestion with qcom,geni-i2c.

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 10

Quoted 2 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +2 -0
+- reg: Should contain UART register location and length.
+- reg-names: Should contain "se-phys".

No need to specify reg-names for a single reg.

Ok.

Quoted 5 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 12

Quoted 3 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +2 -0
+- interrupts: Should contain UART core interrupts.
+- clock-names: Should contain "se-clk".

Omit the "clk"

Ok.

Quoted 4 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 13

Quoted 2 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +1 -0
+- clocks: clocks needed for UART, includes the core clock.

Be more specific.

Ok.

Quoted 6 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 16

Quoted 4 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +3 -0
+- pinctrl-names/pinctrl-0/1: The GPIOs assigned to this core. The names
+  Should be "active" and "sleep" for the pin confuguration when core is active
+  or when entering sleep state.

Omit pinctrl information.

Ok.

Quoted 6 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 19

Quoted 4 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +3 -0
+
+Example:
+uart0: qcom,serial@a88000 {

Don't use qcom, in node name. This should be named "serial".

Ok.

Quoted 7 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 23

Quoted 5 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +4 -0
+	compatible = "qcom,geni-debug-uart";
+	reg = <0xa88000 0x7000>;
+	reg-names = "se-phys";
+	interrupts = <0 355 0>;

<GIC_SPI 355 IRQ_TYPE_LEVEL_HIGH>

Ok.

Quoted 11 lines

Documentation/devicetree/bindings/serial/qcom,geni-uart.txt line 29

Quoted 7 lines
Documentation/devicetree/bindings/serial/qcom,geni-uart.txt new file +6 -0
+	clock-names = "se-clk";
+	clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>;
+	pinctrl-names = "default", "sleep";
+	pinctrl-0 = <&qup_1_uart_3_active>;
+	pinctrl-1 = <&qup_1_uart_3_sleep>;
+};

Regards,
Bjorn

Regards,
Karthik.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project