Skip to contentSkip to conversation

mips: add base support for QCA/Atheros ath79 SOCs

PATCH Superseded Wills Wang 5 participants 25 messages Jan 4, 2016 – Jan 16, 2016 1 message not in the archive

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Wills Wang

author
#1 lore raw

PATCH v6 2/10 mips: add base support for QCA/Atheros ath79 SOCs

---

Changes in v6:
- Move ar933x as separate patch
- Add get_bootstrap in reset.c
- Use map_physmem instead of KSEG1ADDR
- Add arch_cpu_init for detect SOC type for early

Changes in v5:
- Add independent Kconfig
- Use SRAM for initial stack
- Move DDR initialization into board_early_init_f
- Convert DDR tap tunning code to C
- Save SOC's version into arch_global_data

Changes in v4:
- Use global_data to save CPU/DDR/AHB clock
- Use arch_global_data to save SOC's type, revison and id

Changes in v3:
- Move SoC specific header files into arch/mips/mach-ath79/include/mach
- Optimize assembly code
- Same code style convertion

Changes in v2:
- Move all SoC specific header files into arch/mips/include/asm/arch-ath79
- Check SOC type and extract common code into arch/mips/mach-ath79

 arch/mips/Kconfig                               |    6 +
 arch/mips/Makefile                              |    1 +
 arch/mips/include/asm/global_data.h             |    6 +
 arch/mips/mach-ath79/Kconfig                    |   10 +
 arch/mips/mach-ath79/Makefile                   |    7 +
 arch/mips/mach-ath79/cpu.c                      |  204 ++++
 arch/mips/mach-ath79/dram.c                     |   17 +
 arch/mips/mach-ath79/include/mach/ar71xx_regs.h | 1187 +++++++++++++++++++++++
 arch/mips/mach-ath79/include/mach/ath79.h       |  143 +++
 arch/mips/mach-ath79/include/mach/ddr.h         |   14 +
 arch/mips/mach-ath79/include/mach/reset.h       |   15 +
 arch/mips/mach-ath79/reset.c                    |   75 ++
 12 files changed, 1685 insertions(+)
 create mode 100644 arch/mips/mach-ath79/Kconfig
 create mode 100644 arch/mips/mach-ath79/Makefile
 create mode 100644 arch/mips/mach-ath79/cpu.c
 create mode 100644 arch/mips/mach-ath79/dram.c
 create mode 100644 arch/mips/mach-ath79/include/mach/ar71xx_regs.h
 create mode 100644 arch/mips/mach-ath79/include/mach/ath79.h
 create mode 100644 arch/mips/mach-ath79/include/mach/ddr.h
 create mode 100644 arch/mips/mach-ath79/include/mach/reset.h
 create mode 100644 arch/mips/mach-ath79/reset.c
arch/mips/Kconfig +6 -0
index 388e4c0..c9c6aae 100644
@@ -53,6 +53,11 @@ config TARGET_PB1X00
 	select SYS_MIPS_CACHE_INIT_RAM_LOAD
 	select MIPS_TUNE_4KC
 
+config ARCH_ATH79
+	bool "Support ath79"
+	select OF_CONTROL
+	select DM
+
 endchoice
 
 source "board/dbau1x00/Kconfig"
@@ -60,6 +65,7 @@ source "board/imgtec/malta/Kconfig"
 source "board/micronas/vct/Kconfig"
 source "board/pb1x00/Kconfig"
 source "board/qemu-mips/Kconfig"
+source "arch/mips/mach-ath79/Kconfig"
 
 if MIPS
 
arch/mips/Makefile +1 -0
index 90cd590..93c461c 100644
@@ -8,6 +8,7 @@ libs-y += arch/mips/cpu/
 libs-y += arch/mips/lib/
 
 machine-$(CONFIG_SOC_AU1X00) += au1x00
+machine-$(CONFIG_ARCH_ATH79) += ath79
 
 machdirs := $(patsubst %,arch/mips/mach-%/,$(machine-y))
 libs-y += $(machdirs)
arch/mips/include/asm/global_data.h +6 -0
index 2d9a0c9..3799e98 100644
@@ -20,6 +20,12 @@ struct arch_global_data {
 	unsigned long tbl;
 	unsigned long lastinc;
 #endif
+#ifdef CONFIG_ARCH_ATH79
+	unsigned long id;
+	unsigned long soc;
+	unsigned long rev;
+	unsigned long ver;
+#endif
 };
 
 #include <asm-generic/global_data.h>
arch/mips/mach-ath79/Kconfig new file +10 -0
new file mode 100644
index 0000000..df84876
@@ -0,0 +1,10 @@
+menu "QCA/Athroes 7xxx/9xxx platforms"
+	depends on ARCH_ATH79
+
+config SYS_VENDOR
+	default "ath79"
+
+config SYS_SOC
+	default "ath79"
+
+endmenu
arch/mips/mach-ath79/Makefile new file +7 -0
new file mode 100644
index 0000000..6203cf0
@@ -0,0 +1,7 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += reset.o
+obj-y += cpu.o
+obj-y += dram.o
arch/mips/mach-ath79/cpu.c new file +204 -0

204 lines not on this page · raw message

arch/mips/mach-ath79/dram.c new file +17 -0
new file mode 100644
index 0000000..53810d5
@@ -0,0 +1,17 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <linux/sizes.h>
+#include <asm/addrspace.h>
+#include <mach/ddr.h>
+
+phys_size_t initdram(int board_type)
+{
+	ddr_tap_tuning();
+	return get_ram_size((void *)KSEG1, SZ_256M);
+}
arch/mips/mach-ath79/include/mach/ar71xx_regs.h new file +1187 -0

1,187 lines not on this page · raw message

arch/mips/mach-ath79/include/mach/ath79.h new file +143 -0

143 lines not on this page · raw message

arch/mips/mach-ath79/include/mach/ddr.h new file +14 -0
new file mode 100644
index 0000000..95e7971
@@ -0,0 +1,14 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __ASM_MACH_DDR_H
+#define __ASM_MACH_DDR_H
+
+void ddr_init(void);
+void ddr_tap_tuning(void);
+
+#endif /* __ASM_MACH_DDR_H */
arch/mips/mach-ath79/include/mach/reset.h new file +15 -0
new file mode 100644
index 0000000..3e7519d
@@ -0,0 +1,15 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __ASM_MACH_RESET_H
+#define __ASM_MACH_RESET_H
+
+#include <linux/types.h>
+
+u32 get_bootstrap(void);
+
+#endif /* __ASM_MACH_RESET_H */
arch/mips/mach-ath79/reset.c new file +75 -0

75 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v6 3/10 mips: ath79: add support for AR933x SOCs

In reply to a message not in the archive

This patch enable work for ar933x SOC.

---

Changes in v6:
- Remove board.c
- Define magic value in ddr.c

Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/mips/mach-ath79/Kconfig                |  10 +
 arch/mips/mach-ath79/Makefile               |   2 +
 arch/mips/mach-ath79/ar933x/Makefile        |   7 +
 arch/mips/mach-ath79/ar933x/clk.c           |  90 ++++++++
 arch/mips/mach-ath79/ar933x/ddr.c           | 317 ++++++++++++++++++++++++++++
 arch/mips/mach-ath79/ar933x/lowlevel_init.S | 280 ++++++++++++++++++++++++
 6 files changed, 706 insertions(+)
 create mode 100644 arch/mips/mach-ath79/ar933x/Makefile
 create mode 100644 arch/mips/mach-ath79/ar933x/clk.c
 create mode 100644 arch/mips/mach-ath79/ar933x/ddr.c
 create mode 100644 arch/mips/mach-ath79/ar933x/lowlevel_init.S
arch/mips/mach-ath79/Kconfig +10 -0
index df84876..ff2c491 100644
@@ -7,4 +7,14 @@ config SYS_VENDOR
 config SYS_SOC
 	default "ath79"
 
+config SOC_AR933X
+	bool
+	select SUPPORTS_BIG_ENDIAN
+	select SUPPORTS_CPU_MIPS32_R1
+	select SUPPORTS_CPU_MIPS32_R2
+	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select MIPS_TUNE_24KC
+	help
+	  This supports QCA/Atheros ar933x family SOCs.
+
 endmenu
arch/mips/mach-ath79/Makefile +2 -0
index 6203cf0..9b9447e 100644
@@ -5,3 +5,5 @@
 obj-y += reset.o
 obj-y += cpu.o
 obj-y += dram.o
+
+obj-$(CONFIG_SOC_AR933X)	+= ar933x/
\ No newline at end of file
arch/mips/mach-ath79/ar933x/Makefile new file +7 -0
new file mode 100644
index 0000000..fd74f0c
@@ -0,0 +1,7 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += clk.o
+obj-y += ddr.o
+obj-y += lowlevel_init.o
arch/mips/mach-ath79/ar933x/clk.c new file +90 -0

90 lines not on this page · raw message

arch/mips/mach-ath79/ar933x/ddr.c new file +317 -0

317 lines not on this page · raw message

arch/mips/mach-ath79/ar933x/lowlevel_init.S new file +280 -0

280 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#3 lore raw

PATCH v6 4/10 mips: ath79: add support for QCA953x SOCs

In reply to a message not in the archive

This patch enable work for qca953x SOC.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/mips/mach-ath79/Kconfig                 |  10 +
 arch/mips/mach-ath79/Makefile                |   3 +-
 arch/mips/mach-ath79/qca953x/Makefile        |   7 +
 arch/mips/mach-ath79/qca953x/clk.c           | 112 +++++++
 arch/mips/mach-ath79/qca953x/ddr.c           | 463 +++++++++++++++++++++++++++
 arch/mips/mach-ath79/qca953x/lowlevel_init.S | 186 +++++++++++
 6 files changed, 780 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/mach-ath79/qca953x/Makefile
 create mode 100644 arch/mips/mach-ath79/qca953x/clk.c
 create mode 100644 arch/mips/mach-ath79/qca953x/ddr.c
 create mode 100644 arch/mips/mach-ath79/qca953x/lowlevel_init.S
arch/mips/mach-ath79/Kconfig +10 -0
index ff2c491..f7801e4 100644
@@ -17,4 +17,14 @@ config SOC_AR933X
 	help
 	  This supports QCA/Atheros ar933x family SOCs.
 
+config SOC_QCA953X
+	bool
+	select SUPPORTS_BIG_ENDIAN
+	select SUPPORTS_CPU_MIPS32_R1
+	select SUPPORTS_CPU_MIPS32_R2
+	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select MIPS_TUNE_24KC
+	help
+	  This supports QCA/Atheros qca953x family SOCs.
+
 endmenu
arch/mips/mach-ath79/Makefile +2 -1
index 9b9447e..160dfaa 100644
@@ -6,4 +6,5 @@ obj-y += reset.o
 obj-y += cpu.o
 obj-y += dram.o
 
-obj-$(CONFIG_SOC_AR933X)	+= ar933x/
\ No newline at end of file
+obj-$(CONFIG_SOC_AR933X)	+= ar933x/
+obj-$(CONFIG_SOC_QCA953X)	+= qca953x/
\ No newline at end of file
arch/mips/mach-ath79/qca953x/Makefile new file +7 -0
new file mode 100644
index 0000000..fd74f0c
@@ -0,0 +1,7 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y += clk.o
+obj-y += ddr.o
+obj-y += lowlevel_init.o
arch/mips/mach-ath79/qca953x/clk.c new file +112 -0

112 lines not on this page · raw message

arch/mips/mach-ath79/qca953x/ddr.c new file +463 -0

463 lines not on this page · raw message

arch/mips/mach-ath79/qca953x/lowlevel_init.S new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#4 lore raw

PATCH v6 5/10 mips: ath79: add serial driver for ar933x SOC

In reply to a message not in the archive

---

Changes in v6:
- Remove wait loop in putc and getc
- Use map_physmem instead of KSEG1ADDR

Changes in v5:
- remove ar933x_serial_platdata
- Import document "qca,ar9330-uart.txt" from kernel
- Add support for debug UART

Changes in v4:
- Auto calculate baudrate for serial driver
- Move pinctrl code in serial driver into arch/mips/mach-ath79
- Use get_serial_clock to serial clock source

Changes in v3:
- Convert serial driver to driver model
- Same code style convertion

Changes in v2:
- Move serial driver code into drivers/serial

 .../serial/qca,ar9330-uart.txt                     |  24 ++
 drivers/serial/Kconfig                             |  17 ++
 drivers/serial/Makefile                            |   1 +
 drivers/serial/serial_ar933x.c                     | 264 +++++++++++++++++++++
 4 files changed, 306 insertions(+)
 create mode 100644 doc/device-tree-bindings/serial/qca,ar9330-uart.txt
 create mode 100644 drivers/serial/serial_ar933x.c
doc/device-tree-bindings/serial/qca,ar9330-uart.txt new file +24 -0
new file mode 100644
index 0000000..ec576a1
@@ -0,0 +1,24 @@
+* Qualcomm Atheros AR9330 High-Speed UART
+
+Required properties:
+
+- compatible: Must be "qca,ar9330-uart"
+
+- reg: Specifies the physical base address of the controller and
+  the length of the memory mapped region.
+
+Additional requirements:
+
+  Each UART port must have an alias correctly numbered in "aliases"
+  node.
+
+Example:
+
+	aliases {
+		serial0 = &uart0;
+	};
+
+	uart0: uart at 18020000 {
+		compatible = "qca,ar9330-uart";
+		reg = <0x18020000 0x14>;
+	};
drivers/serial/Kconfig +17 -0
index 1fc287e..f147379 100644
@@ -69,6 +69,14 @@ config DEBUG_UART_ALTERA_UART
 	  You will need to provide parameters to make this work. The driver will
 	  be available until the real driver model serial is running.
 
+config DEBUG_UART_AR933X
+	bool "QCA/Atheros ar933x"
+	help
+	  Select this to enable a debug UART using the ar933x uart driver.
+	  You will need to provide parameters to make this work. The
+	  driver will be available until the real driver model serial is
+	  running.
+
 config DEBUG_UART_NS16550
 	bool "ns16550"
 	help
@@ -186,6 +194,15 @@ config ALTERA_UART
 	  Select this to enable an UART for Altera devices. Please find
 	  details on the "Embedded Peripherals IP User Guide" of Altera.
 
+config AR933X_UART
+	bool "QCA/Atheros ar933x UART support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable UART support for QCA/Atheros ar933x
+	  devices. This driver uses driver model and requires a device
+	  tree binding to operate, please refer to the document at
+	  doc/device-tree-bindings/serial/qca,ar9330-uart.txt.
+
 config SYS_NS16550
 	bool "NS16550 UART or compatible"
 	help
drivers/serial/Makefile +1 -0
index dd87147..b7b82ae 100644
@@ -17,6 +17,7 @@ endif
 
 obj-$(CONFIG_ALTERA_UART) += altera_uart.o
 obj-$(CONFIG_ALTERA_JTAG_UART) += altera_jtag_uart.o
+obj-$(CONFIG_AR933X_UART) += serial_ar933x.o
 obj-$(CONFIG_ARM_DCC) += arm_dcc.o
 obj-$(CONFIG_ATMEL_USART) += atmel_usart.o
 obj-$(CONFIG_EFI_APP) += serial_efi.o
drivers/serial/serial_ar933x.c new file +264 -0

264 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

PATCH v6 5/10 mips: ath79: add serial driver for ar933x SOC

Hi Wills,

Quoted 246 lines · Wills Wang

---

Changes in v6:
- Remove wait loop in putc and getc
- Use map_physmem instead of KSEG1ADDR

Changes in v5:
- remove ar933x_serial_platdata
- Import document "qca,ar9330-uart.txt" from kernel
- Add support for debug UART

Changes in v4:
- Auto calculate baudrate for serial driver
- Move pinctrl code in serial driver into arch/mips/mach-ath79
- Use get_serial_clock to serial clock source

Changes in v3:
- Convert serial driver to driver model
- Same code style convertion

Changes in v2:
- Move serial driver code into drivers/serial

  .../serial/qca,ar9330-uart.txt                     |  24 ++
  drivers/serial/Kconfig                             |  17 ++
  drivers/serial/Makefile                            |   1 +
  drivers/serial/serial_ar933x.c                     | 264 +++++++++++++++++++++
  4 files changed, 306 insertions(+)

create mode 100644 doc/device-tree-bindings/serial/qca,ar9330-uart.txt create mode 100644 drivers/serial/serial_ar933x.c

doc/device-tree-bindings/serial/qca,ar9330-uart.txt new file +24 -0
new file mode 100644
index 0000000..ec576a1
@@ -0,0 +1,24 @@
+* Qualcomm Atheros AR9330 High-Speed UART
+
+Required properties:
+
+- compatible: Must be "qca,ar9330-uart"
+
+- reg: Specifies the physical base address of the controller and
+  the length of the memory mapped region.
+
+Additional requirements:
+
+  Each UART port must have an alias correctly numbered in "aliases"
+  node.
+
+Example:
+
+	aliases {
+		serial0 = &uart0;
+	};
+
+	uart0: uart at 18020000 {
+		compatible = "qca,ar9330-uart";
+		reg = <0x18020000 0x14>;
+	};
drivers/serial/Kconfig +17 -0
index 1fc287e..f147379 100644
@@ -69,6 +69,14 @@ config DEBUG_UART_ALTERA_UART
  	  You will need to provide parameters to make this work. The driver will
  	  be available until the real driver model serial is running.
 
+config DEBUG_UART_AR933X
+	bool "QCA/Atheros ar933x"
+	help
+	  Select this to enable a debug UART using the ar933x uart driver.
+	  You will need to provide parameters to make this work. The
+	  driver will be available until the real driver model serial is
+	  running.
+
  config DEBUG_UART_NS16550
  	bool "ns16550"
  	help
@@ -186,6 +194,15 @@ config ALTERA_UART
  	  Select this to enable an UART for Altera devices. Please find
  	  details on the "Embedded Peripherals IP User Guide" of Altera.
 
+config AR933X_UART
+	bool "QCA/Atheros ar933x UART support"
+	depends on DM_SERIAL
+	help
+	  Select this to enable UART support for QCA/Atheros ar933x
+	  devices. This driver uses driver model and requires a device
+	  tree binding to operate, please refer to the document at
+	  doc/device-tree-bindings/serial/qca,ar9330-uart.txt.
+
  config SYS_NS16550
  	bool "NS16550 UART or compatible"
  	help
drivers/serial/Makefile +1 -0
index dd87147..b7b82ae 100644
@@ -17,6 +17,7 @@ endif
 
  obj-$(CONFIG_ALTERA_UART) += altera_uart.o
  obj-$(CONFIG_ALTERA_JTAG_UART) += altera_jtag_uart.o
+obj-$(CONFIG_AR933X_UART) += serial_ar933x.o
  obj-$(CONFIG_ARM_DCC) += arm_dcc.o
  obj-$(CONFIG_ATMEL_USART) += atmel_usart.o
  obj-$(CONFIG_EFI_APP) += serial_efi.o
drivers/serial/serial_ar933x.c new file +131 -0
new file mode 100644
index 0000000..38d34c2
@@ -0,0 +1,264 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <div64.h>
+#include <errno.h>
+#include <serial.h>
+#include <asm/io.h>
+#include <asm/addrspace.h>
+#include <asm/types.h>
+#include <mach/ar71xx_regs.h>
+
+#define AR933X_UART_DATA_REG            0x00
+#define AR933X_UART_CS_REG              0x04
+#define AR933X_UART_CLK_REG             0x08
+
+#define AR933X_UART_DATA_TX_RX_MASK     0xff
+#define AR933X_UART_DATA_RX_CSR         BIT(8)
+#define AR933X_UART_DATA_TX_CSR         BIT(9)
+#define AR933X_UART_CS_IF_MODE_S        2
+#define AR933X_UART_CS_IF_MODE_M        0x3
+#define AR933X_UART_CS_IF_MODE_DTE      1
+#define AR933X_UART_CS_IF_MODE_DCE      2
+#define AR933X_UART_CS_TX_RDY_ORIDE     BIT(7)
+#define AR933X_UART_CS_RX_RDY_ORIDE     BIT(8)
+#define AR933X_UART_CLK_STEP_M          0xffff
+#define AR933X_UART_CLK_SCALE_M         0xfff
+#define AR933X_UART_CLK_SCALE_S         16
+#define AR933X_UART_CLK_STEP_S          0
+
+struct ar933x_serial_priv {
+	void __iomem *regs;
+};
+
+static inline u32 ar933x_serial_read(struct udevice *dev, u32 offset)
+{
+	struct ar933x_serial_priv *priv = dev_get_priv(dev);
+
+	return readl(priv->regs + offset);
+}
+
+static inline void ar933x_serial_write(struct udevice *dev,
+				       u32 val, u32 offset)
+{
+	struct ar933x_serial_priv *priv = dev_get_priv(dev);
+
+	writel(val, priv->regs + offset);
+}
+
+/*
+ * baudrate = (clk / (scale + 1)) * (step * (1 / 2^17))
+ */
+static u32 ar933x_serial_get_baud(u32 clk, u32 scale, u32 step)
+{
+	u64 t;
+	u32 div;
+
+	div = (2 << 16) * (scale + 1);
+	t = clk;
+	t *= step;
+	t += (div / 2);
+	do_div(t, div);
+
+	return t;
+}
+
+static void ar933x_serial_get_scale_step(u32 clk, u32 baud,
+					 u32 *scale, u32 *step)
+{
+	u32 tscale, baudrate;
+	long min_diff;
+
+	*scale = 0;
+	*step = 0;
+
+	min_diff = baud;
+	for (tscale = 0; tscale < AR933X_UART_CLK_SCALE_M; tscale++) {
+		u64 tstep;
+		int diff;
+
+		tstep = baud * (tscale + 1);
+		tstep *= (2 << 16);
+		do_div(tstep, clk);
+
+		if (tstep > AR933X_UART_CLK_STEP_M)
+			break;
+
+		baudrate = ar933x_serial_get_baud(clk, tscale, tstep);
+		diff = abs(baudrate - baud);
+		if (diff < min_diff) {
+			min_diff = diff;
+			*scale = tscale;
+			*step = tstep;
+		}
+	}
+}
+
+static int ar933x_serial_setbrg(struct udevice *dev, int baudrate)
+{
+	u32 val, scale, step;
+
+	val = get_serial_clock();
+	ar933x_serial_get_scale_step(val, baudrate, &scale, &step);
+
+	val  = (scale & AR933X_UART_CLK_SCALE_M)
+			<< AR933X_UART_CLK_SCALE_S;
+	val |= (step & AR933X_UART_CLK_STEP_M)
+			<< AR933X_UART_CLK_STEP_S;
+	ar933x_serial_write(dev, val, AR933X_UART_CLK_REG);
+
+	return 0;
+}
+
+static int ar933x_serial_putc(struct udevice *dev, const char c)
+{
+	u32 data;
+
+	data = ar933x_serial_read(dev, AR933X_UART_DATA_REG);
+	if (!(data & AR933X_UART_DATA_TX_CSR))
+		return -EAGAIN;
+
+	data  = (u32)c | AR933X_UART_DATA_TX_CSR;
+	ar933x_serial_write(dev, data, AR933X_UART_DATA_REG);
+
+	return 0;
+}

drivers/serial/serial_ar933x.c line 141

Quoted 10 lines
drivers/serial/serial_ar933x.c new file +10 -0
+
+static int ar933x_serial_getc(struct udevice *dev)
+{
+	u32 data;
+
+	data = ar933x_serial_read(dev, AR933X_UART_DATA_REG);
+	if (!(data & AR933X_UART_DATA_RX_CSR))
+		return -EAGAIN;
+
+	data = ar933x_serial_read(dev, AR933X_UART_DATA_REG);

Can we use the data from previous read and remove this read?

Quoted 70 lines
drivers/serial/serial_ar933x.c new file +70 -0
+	ar933x_serial_write(dev, AR933X_UART_DATA_RX_CSR,
+			    AR933X_UART_DATA_REG);
+	return data & AR933X_UART_DATA_TX_RX_MASK;
+}
+
+static int ar933x_serial_pending(struct udevice *dev, bool input)
+{
+	u32 data;
+
+	data = ar933x_serial_read(dev, AR933X_UART_DATA_REG);
+	if (input)
+		return (data & AR933X_UART_DATA_RX_CSR) ? 1 : 0;
+	else
+		return (data & AR933X_UART_DATA_TX_CSR) ? 0 : 1;
+}
+
+static int ar933x_serial_probe(struct udevice *dev)
+{
+	struct ar933x_serial_priv *priv = dev_get_priv(dev);
+	u32 val;
+	fdt_addr_t addr;
+
+	addr = dev_get_addr(dev);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	priv->regs = map_physmem(addr,
+				 AR933X_UART_SIZE,
+				 MAP_NOCACHE);
+
+	/*
+	 * UART controller configuration:
+	 * - no DMA
+	 * - no interrupt
+	 * - DCE mode
+	 * - no flow control
+	 * - set RX ready oride
+	 * - set TX ready oride
+	 */
+	val = (AR933X_UART_CS_IF_MODE_DCE << AR933X_UART_CS_IF_MODE_S) |
+	      AR933X_UART_CS_TX_RDY_ORIDE | AR933X_UART_CS_RX_RDY_ORIDE;
+	ar933x_serial_write(dev, val, AR933X_UART_CS_REG);
+	return 0;
+}
+
+static const struct dm_serial_ops ar933x_serial_ops = {
+	.putc = ar933x_serial_putc,
+	.pending = ar933x_serial_pending,
+	.getc = ar933x_serial_getc,
+	.setbrg = ar933x_serial_setbrg,
+};
+
+static const struct udevice_id ar933x_serial_ids[] = {
+	{ .compatible = "qca,ar9330-uart" },
+	{ }
+};
+
+U_BOOT_DRIVER(serial_ar933x) = {
+	.name   = "serial_ar933x",
+	.id = UCLASS_SERIAL,
+	.of_match = ar933x_serial_ids,
+	.priv_auto_alloc_size = sizeof(struct ar933x_serial_priv),
+	.probe = ar933x_serial_probe,
+	.ops    = &ar933x_serial_ops,
+	.flags = DM_FLAG_PRE_RELOC,
+};
+
+#ifdef CONFIG_DEBUG_UART_AR933X
+
+#include <debug_uart.h>

drivers/serial/serial_ar933x.c line 221

Quoted 10 lines
drivers/serial/serial_ar933x.c new file +10 -0
+
+static inline void _debug_uart_init(void)
+{
+	void __iomem *regs;
+	u32 val, scale, step;
+
+	regs = map_physmem(CONFIG_DEBUG_UART_BASE,
+				 AR933X_UART_SIZE,
+				 MAP_NOCACHE);
+

Please see my comment on your patch v6 07/10.

Quoted 34 lines
drivers/serial/serial_ar933x.c new file +33 -0
+	/*
+	 * UART controller configuration:
+	 * - no DMA
+	 * - no interrupt
+	 * - DCE mode
+	 * - no flow control
+	 * - set RX ready oride
+	 * - set TX ready oride
+	 */
+	val = (AR933X_UART_CS_IF_MODE_DCE << AR933X_UART_CS_IF_MODE_S) |
+	      AR933X_UART_CS_TX_RDY_ORIDE | AR933X_UART_CS_RX_RDY_ORIDE;
+	writel(val, regs + AR933X_UART_CS_REG);
+
+	ar933x_serial_get_scale_step(CONFIG_DEBUG_UART_CLOCK,
+				     CONFIG_BAUDRATE, &scale, &step);
+
+	val  = (scale & AR933X_UART_CLK_SCALE_M)
+			<< AR933X_UART_CLK_SCALE_S;
+	val |= (step & AR933X_UART_CLK_STEP_M)
+			<< AR933X_UART_CLK_STEP_S;
+	writel(val, regs + AR933X_UART_CLK_REG);
+}
+
+static inline void _debug_uart_putc(int c)
+{
+	void __iomem *regs;
+	u32 data;
+
+	regs = map_physmem(CONFIG_DEBUG_UART_BASE,
+				 AR933X_UART_SIZE,
+				 MAP_NOCACHE);
+
+	do {

drivers/serial/serial_ar933x.c line 264

Quoted 10 lines
drivers/serial/serial_ar933x.c new file +10 -0
+		data = readl(regs + AR933X_UART_DATA_REG);
+	} while (!(data & AR933X_UART_DATA_TX_CSR));
+
+	data  = (u32)c | AR933X_UART_DATA_TX_CSR;
+	writel(data, regs + AR933X_UART_DATA_REG);
+}
+
+DEBUG_UART_FUNCS
+
+#endif

Otherwise,

Best regards,
Thomas

author
#6 lore raw

PATCH v6 6/10 ns16550: add support for mips

In reply to a message not in the archive

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/serial/ns16550.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +16 -8
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void *addr, int shift, int value)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
 	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
 #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
 	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif
 #elif defined(CONFIG_SYS_BIG_ENDIAN)
 	writeb(value, addr + (1 << shift) - 1);
 #else
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void *addr, int shift)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
 	return inb((ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_be32(addr);
 #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
 	return readl(addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
 #elif defined(CONFIG_SYS_BIG_ENDIAN)
 	return readb(addr + (1 << shift) - 1);
 #else
Signature · 1 line
1.9.1
#7 lore raw

PATCH v6 6/10 ns16550: add support for mips

Hi Wills,

Quoted 6 lines · Wills Wang

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

As Marek might have suggested, you should consider add these macro first.

Best regards,
Thomas

#8 lore raw

PATCH v6 6/10 ns16550: add support for mips

Quoted 11 lines · Thomas Chou

Hi Wills,

Quoted 6 lines · Wills Wang

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

As Marek might have suggested, you should consider add these macro first.

I think Marek's suggestions are being ignored :-)

Best regards,
Marek Vasut

author
#9 lore raw

PATCH v6 6/10 ns16550: add support for mips

Quoted 4 lines · Marek Vasut
Quoted 3 lines · Thomas Chou

Hi Wills,

On 2016?01?04? 19:14, Wills Wang wrote:

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

As Marek might have suggested, you should consider add these macro first.

I think Marek's suggestions are being ignored :-)

I don't really know why u-boot and kernel don't both support these macros. In addition, should it be considered in the scope of these patch series?

Quoted 3 lines

Best regards,
Marek Vasut

Signature · 2 lines
Best Regards
Wills
#10 lore raw

PATCH v6 6/10 ns16550: add support for mips

In reply to Wills Wang

Am Montag, den 04.01.2016, 19:14 +0800 schrieb Wills Wang:

Quoted 65 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/serial/ns16550.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +8 -4
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void *addr,
 int shift, int value)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
 	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
 #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
 	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif

#elif defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +8 -4
 	writeb(value, addr + (1 << shift) - 1);
 #else
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void *addr, int
 shift)
 {
 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
 	return inb((ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_be32(addr);
 #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
 	return readl(addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
Quoted 3 lines

#elif defined(CONFIG_SYS_BIG_ENDIAN)
return readb(addr + (1 << shift) - 1);
#else

Could you tell us, if you need port IO or MMIO. In case of MMIO do you need 8 bit or 32 bit I/O access?

Becasue your CPU is running in Big Endian and the NS16550 is Little Endian, you need endianess conversion in the 32 bit case.

The 8 bit access should already work without changing anything. The MIPS Malta board also uses NS16550 and already works in Bit Endian mode.

To make the 32 bit case working, you need to select CONFIG_SWAP_IO_SPACE in your SoC Kconfig code. Then all readl/writel accessors do an endianess conversion to Little Endian if the CPU is running in Big Endian.

Anyway I think the current implementation is wrong:

static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)
	out_le32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
defined(CONFIG_SYS_BIG_ENDIAN)
	out_be32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The branch with writel() will never be taken because the two preceding branches already catch all conditions for CONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch with out_be32 makes no sense. All IO accessors must convert from CPU endianess to NS16550's Little Endian, but out_be32 converts from CPU endianess to Big Endian.

To handle port IO, 32 Bit MMIO and 8 Bit MMIO, following code should be enough:

static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The arch-specific implementation of readl/writel should be responsible for the endianess conversion and not the driver. What do you think?

Signature · 1 line
- Daniel
author
#11 lore raw

PATCH v6 6/10 ns16550: add support for mips

Quoted 124 lines · Daniel Schwierzeck

Am Montag, den 04.01.2016, 19:14 +0800 schrieb Wills Wang:

Quoted 65 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro, but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  drivers/serial/ns16550.c | 24 ++++++++++++++++--------
  1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +8 -4
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void *addr,
 int shift, int value)
  {
  #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
  	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
  #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
  	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif
  #elif defined(CONFIG_SYS_BIG_ENDIAN)
  	writeb(value, addr + (1 << shift) - 1);
  #else
drivers/serial/ns16550.c +8 -4
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void *addr, int
 shift)
  {
  #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
  	return inb((ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	return in_be32(addr);
  #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
  	return readl(addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
Quoted 3 lines
  #elif defined(CONFIG_SYS_BIG_ENDIAN)
  	return readb(addr + (1 << shift) - 1);
  #else

Could you tell us, if you need port IO or MMIO. In case of MMIO do you need 8 bit or 32 bit I/O access?

Becasue your CPU is running in Big Endian and the NS16550 is Little Endian, you need endianess conversion in the 32 bit case.

The 8 bit access should already work without changing anything. The MIPS Malta board also uses NS16550 and already works in Bit Endian mode.

To make the 32 bit case working, you need to select CONFIG_SWAP_IO_SPACE in your SoC Kconfig code. Then all readl/writel accessors do an endianess conversion to Little Endian if the CPU is running in Big Endian.

Anyway I think the current implementation is wrong:

static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)
	out_le32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
defined(CONFIG_SYS_BIG_ENDIAN)
	out_be32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The branch with writel() will never be taken because the two preceding branches already catch all conditions for CONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch with out_be32 makes no sense. All IO accessors must convert from CPU endianess to NS16550's Little Endian, but out_be32 converts from CPU endianess to Big Endian.

To handle port IO, 32 Bit MMIO and 8 Bit MMIO, following code should be enough:

static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);
Quoted 6 lines

#endif
}

The arch-specific implementation of readl/writel should be responsible for the endianess conversion and not the driver. What do you think?

I wholly agree with Daniel, driver should not care the endianness, we need a general mechanism to deal with this situation, no matter the endianness of CPU and peripheral IP Core.
But CONFIG_SWAP_IO_SPACE don't resolve this issue, NS16550 is just one of many peripherals for CPU.
NS16550 use only 8bit register field even if in 32 bit MMIO. In actual, driver may just concern the register offset beause the bit field of register in chip datasheet is coincident with CPU endianness, even though hardware support both big-endian and little-endian, so the optimal code should be the following:
static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
     outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
     writel(value, addr);
#else
     writeb(value, addr);

#endif
}
I use 32bit MMIO to access uart currently, i think that 8 Bit MMIO should work fine if adjust the register offset.

Signature · 2 lines
Best Regards
Wills
#12 lore raw

PATCH v6 6/10 ns16550: add support for mips

Am Samstag, den 09.01.2016, 18:46 +0800 schrieb Wills Wang:

Quoted 166 lines · Daniel Schwierzeck
Quoted 138 lines

Am Montag, den 04.01.2016, 19:14 +0800 schrieb Wills Wang:

Quoted 63 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro,
but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  drivers/serial/ns16550.c | 24 ++++++++++++++++--------
  1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +8 -4
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void
 *addr,
 int shift, int value)
  {
  #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
  	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
  #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
  	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif
  #elif defined(CONFIG_SYS_BIG_ENDIAN)
  	writeb(value, addr + (1 << shift) - 1);
  #else
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void *addr,

int
shift)
{
#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
return inb((ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +0 -2
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&

defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +1 -1
-	return in_be32(addr);
  #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
  	return readl(addr);

drivers/serial/ns16550.c static inline int serial_in_shift(void *addr, int shift) · line 100

Quoted 10 lines
drivers/serial/ns16550.c +7 -0
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
  #elif defined(CONFIG_SYS_BIG_ENDIAN)
  	return readb(addr + (1 << shift) - 1);
  #else

Could you tell us, if you need port IO or MMIO. In case of MMIO do you
need 8 bit or 32 bit I/O access?

Becasue your CPU is running in Big Endian and the NS16550 is Little Endian, you need endianess conversion in the 32 bit case.

The 8 bit access should already work without changing anything. The MIPS Malta board also uses NS16550 and already works in Bit Endian mode.

To make the 32 bit case working, you need to select CONFIG_SWAP_IO_SPACE in your SoC Kconfig code. Then all readl/writel
accessors do an endianess conversion to Little Endian if the CPU is running in Big Endian.

Anyway I think the current implementation is wrong:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)
	out_le32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
defined(CONFIG_SYS_BIG_ENDIAN)
	out_be32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The branch with writel() will never be taken because the two preceding
branches already catch all conditions for CONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch with out_be32 makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, but out_be32 converts from CPU endianess to Big Endian.

To handle port IO, 32 Bit MMIO and 8 Bit MMIO, following code should be
enough:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);
Quoted 7 lines

#endif
}

The arch-specific implementation of readl/writel should be responsible
for the endianess conversion and not the driver. What do you think?

I wholly agree with Daniel, driver should not care the endianness, we need a general mechanism to deal with this situation, no matter the endianness of CPU and peripheral IP Core.
But CONFIG_SWAP_IO_SPACE don't resolve this issue, NS16550 is just one of many peripherals for CPU.
NS16550 use only 8bit register field even if in 32 bit MMIO. In actual,
driver may just concern the register offset beause the bit field of register in chip datasheet is coincident with CPU endianness, even though hardware support both big-endian and little-endian, so the optimal code should be the following:
static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
     outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
     writel(value, addr);
#else
     writeb(value, addr);
Quoted 5 lines

#endif
}
I use 32bit MMIO to access uart currently, i think that 8 Bit MMIO should work fine if adjust the register offset.

then try to use 8 bit access and find the correct register offset. You can configure that offset with the DT property "reg-shift".

Signature · 1 line
- Daniel
author
#13 lore raw

PATCH v6 6/10 ns16550: add support for mips

Quoted 171 lines · Daniel Schwierzeck

Am Samstag, den 09.01.2016, 18:46 +0800 schrieb Wills Wang:

Quoted 165 lines · Daniel Schwierzeck
Quoted 138 lines

Am Montag, den 04.01.2016, 19:14 +0800 schrieb Wills Wang:

Quoted 63 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro,
but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

   drivers/serial/ns16550.c | 24 ++++++++++++++++--------
   1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +8 -4
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void
 *addr,
 int shift, int value)
   {
   #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
   	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
   #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
   	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif
   #elif defined(CONFIG_SYS_BIG_ENDIAN)
   	writeb(value, addr + (1 << shift) - 1);
   #else
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void *addr,

int
shift)

   {
   #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
   	return inb((ulong)addr);

-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +0 -2
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&

defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +1 -1
-	return in_be32(addr);
   #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
   	return readl(addr);

drivers/serial/ns16550.c static inline int serial_in_shift(void *addr, int shift) · line 100

Quoted 10 lines
drivers/serial/ns16550.c +7 -0
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
   #elif defined(CONFIG_SYS_BIG_ENDIAN)
   	return readb(addr + (1 << shift) - 1);
   #else

Could you tell us, if you need port IO or MMIO. In case of MMIO do you
need 8 bit or 32 bit I/O access?

Becasue your CPU is running in Big Endian and the NS16550 is Little Endian, you need endianess conversion in the 32 bit case.

The 8 bit access should already work without changing anything. The MIPS Malta board also uses NS16550 and already works in Bit Endian mode.

To make the 32 bit case working, you need to select CONFIG_SWAP_IO_SPACE in your SoC Kconfig code. Then all readl/writel
accessors do an endianess conversion to Little Endian if the CPU is running in Big Endian.

Anyway I think the current implementation is wrong:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)
	out_le32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
defined(CONFIG_SYS_BIG_ENDIAN)
	out_be32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The branch with writel() will never be taken because the two preceding
branches already catch all conditions for CONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch with out_be32 makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, but out_be32 converts from CPU endianess to Big Endian.

To handle port IO, 32 Bit MMIO and 8 Bit MMIO, following code should be
enough:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);
Quoted 7 lines

#endif
}

The arch-specific implementation of readl/writel should be responsible
for the endianess conversion and not the driver. What do you think?

I wholly agree with Daniel, driver should not care the endianness, we need a general mechanism to deal with this situation, no matter the endianness of CPU and peripheral IP Core.
But CONFIG_SWAP_IO_SPACE don't resolve this issue, NS16550 is just one of many peripherals for CPU.
NS16550 use only 8bit register field even if in 32 bit MMIO. In actual,
driver may just concern the register offset beause the bit field of register in chip datasheet is coincident with CPU endianness, even though hardware support both big-endian and little-endian, so the optimal code should be the following:
static inline void serial_out_shift(void *addr, int shift, int value) {

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
      outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
      writel(value, addr);
#else
      writeb(value, addr);
Quoted 5 lines

#endif
}
I use 32bit MMIO to access uart currently, i think that 8 Bit MMIO should work fine if adjust the register offset.

Quoted 3 lines

then try to use 8 bit access and find the correct register offset. You can configure that offset with the DT property "reg-shift".

CONFIG_SYS_BIG_ENDIAN and CONFIG_SYS_LITTLE_ENDIAN are used just for MIPS in u-boot?

Signature · 2 lines
Best Regards
Wills
#14 lore raw

PATCH v6 6/10 ns16550: add support for mips

Am Sonntag, den 17.01.2016, 00:15 +0800 schrieb Wills Wang:

Quoted 189 lines · Daniel Schwierzeck
Quoted 187 lines

Am Samstag, den 09.01.2016, 18:46 +0800 schrieb Wills Wang:

Quoted 186 lines · Daniel Schwierzeck
Quoted 146 lines

Am Montag, den 04.01.2016, 19:14 +0800 schrieb Wills Wang:

Quoted 65 lines

MIPS archtecture have no "in_le32/in_be32/out_le32/out_be32" macro,
but usually define CONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when define CONFIG_SYS_NS16550_MEM32.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

   drivers/serial/ns16550.c | 24 ++++++++++++++++--------
   1 file changed, 16 insertions(+), 8 deletions(-)
drivers/serial/ns16550.c +8 -4
index 3fab3f1..3b24af0 100644
@@ -64,12 +64,16 @@ static inline void serial_out_shift(void
 *addr,
 int shift, int value)
   {
   #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
   	outb(value, (ulong)addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 !defined(CONFIG_SYS_BIG_ENDIAN)
-	out_le32(addr, value);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
 defined(CONFIG_SYS_BIG_ENDIAN)
-	out_be32(addr, value);
   #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
   	writel(value, addr);
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	out_le32(addr, value);
+#else
+	out_be32(addr, value);
+#endif
+#endif
   #elif defined(CONFIG_SYS_BIG_ENDIAN)
   	writeb(value, addr + (1 << shift) - 1);
   #else
@@ -81,12 +85,16 @@ static inline int serial_in_shift(void
 *addr,

int
shift)

   {
   #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
   	return inb((ulong)addr);

-#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +0 -2
-	return in_le32(addr);
-#elif defined(CONFIG_SYS_NS16550_MEM32) &&

defined(CONFIG_SYS_BIG_ENDIAN)

drivers/serial/ns16550.c +1 -1
-	return in_be32(addr);
   #elif defined(CONFIG_SYS_NS16550_MEM32)
+#ifdef CONFIG_MIPS
   	return readl(addr);

drivers/serial/ns16550.c static inline int serial_in_shift(void *addr, int shift) · line 100

Quoted 10 lines
drivers/serial/ns16550.c +7 -0
+#else
+#ifndef CONFIG_SYS_BIG_ENDIAN
+	return in_le32(addr);
+#else
+	return in_be32(addr);
+#endif
+#endif
   #elif defined(CONFIG_SYS_BIG_ENDIAN)
   	return readb(addr + (1 << shift) - 1);
   #else

Could you tell us, if you need port IO or MMIO. In case of MMIO do
you
need 8 bit or 32 bit I/O access?

Becasue your CPU is running in Big Endian and the NS16550 is Little
Endian, you need endianess conversion in the 32 bit case.

The 8 bit access should already work without changing anything. The
MIPS Malta board also uses NS16550 and already works in Bit Endian
mode.

To make the 32 bit case working, you need to select CONFIG_SWAP_IO_SPACE in your SoC Kconfig code. Then all readl/writel
accessors do an endianess conversion to Little Endian if the CPU is
running in Big Endian.

Anyway I think the current implementation is wrong:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
!defined(CONFIG_SYS_BIG_ENDIAN)
	out_le32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32) &&
defined(CONFIG_SYS_BIG_ENDIAN)
	out_be32(addr, value);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);

#endif
}

The branch with writel() will never be taken because the two preceding
branches already catch all conditions for CONFIG_SYS_NS16550_MEM32.
Also if the NS16550 is Little Endian, the branch with out_be32 makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, but out_be32 converts from CPU endianess to Big Endian.

To handle port IO, 32 Bit MMIO and 8 Bit MMIO, following code should be
enough:

static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
	outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
	writel(value, addr);
#elif defined(CONFIG_SYS_BIG_ENDIAN)
	writeb(value, addr + (1 << shift) - 1);
#else
	writeb(value, addr);
Quoted 8 lines

#endif
}

The arch-specific implementation of readl/writel should be responsible
for the endianess conversion and not the driver. What do you think?

I wholly agree with Daniel, driver should not care the endianness, we
need a general mechanism to deal with this situation, no matter the
endianness of CPU and peripheral IP Core.
But CONFIG_SWAP_IO_SPACE don't resolve this issue, NS16550 is just
one of many peripherals for CPU.
NS16550 use only 8bit register field even if in 32 bit MMIO. In actual,
driver may just concern the register offset beause the bit field of
register in chip datasheet is coincident with CPU endianness, even
though hardware support both big-endian and little-endian, so the optimal code should be the following:
static inline void serial_out_shift(void *addr, int shift, int value)
{

#ifdef CONFIG_SYS_NS16550_PORT_MAPPED
      outb(value, (ulong)addr);
#elif defined(CONFIG_SYS_NS16550_MEM32)
      writel(value, addr);
#else
      writeb(value, addr);

#endif
}
I use 32bit MMIO to access uart currently, i think that 8 Bit MMIO
should work fine if adjust the register offset.

Quoted 6 lines
Quoted 4 lines

then try to use 8 bit access and find the correct register offset. You
can configure that offset with the DT property "reg-shift".

CONFIG_SYS_BIG_ENDIAN and CONFIG_SYS_LITTLE_ENDIAN are used just for MIPS in u-boot?

no, that is a generic config option. E.g. PowerPC also has BE, most other archs have LE, MIPS supports both variants.

Signature · 1 line
- Daniel
author
#15 lore raw

PATCH v6 7/10 ns16550: map register base address for debug UART

In reply to a message not in the archive

MIPS need to use KSEG1 address for register operation, this patch add map_physmem to convert CONFIG_DEBUG_UART_BASE for debug UART.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/serial/ns16550.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +4 -2
index 3b24af0..1e2538e 100644
@@ -270,7 +270,8 @@ int NS16550_tstc(NS16550_t com_port)
 
 static inline void _debug_uart_init(void)
 {
-	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+	struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+				CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 	int baud_divisor;
 
 	/*
@@ -293,7 +294,8 @@ static inline void _debug_uart_init(void)
 
 static inline void _debug_uart_putc(int ch)
 {
-	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+	struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+				CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 
 	while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
 		;
Signature · 1 line
1.9.1
#16 lore raw

PATCH v6 7/10 ns16550: map register base address for debug UART

Hi Wills,

Quoted 31 lines · Wills Wang

MIPS need to use KSEG1 address for register operation, this patch add map_physmem to convert CONFIG_DEBUG_UART_BASE for debug UART.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  drivers/serial/ns16550.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +2 -1
index 3b24af0..1e2538e 100644
@@ -270,7 +270,8 @@ int NS16550_tstc(NS16550_t com_port)
 
  static inline void _debug_uart_init(void)
  {
-	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+	struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+				CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
  	int baud_divisor;
 
  	/*

drivers/serial/ns16550.c static inline void _debug_uart_init(void) · line 301

Quoted 9 lines
drivers/serial/ns16550.c +2 -1
@@ -293,7 +294,8 @@ static inline void _debug_uart_init(void)
 
  static inline void _debug_uart_putc(int ch)
  {
-	struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
+	struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+				CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 
  	while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
  		;

As debug uart may be used in very early stage and SPL, I would suggest the CONFIG_DEBUG_UART_BASE here is mapped to uncached space already. So that we can keep the code and stack usage minimal.

My concern is that the uncache mapping in nios2 arch is different between NOMMU and MMU core, which will be decoded from device tree. So it won't work for nios2 until DM initialized.

Best regards,
Thomas

author
#17 lore raw

PATCH v6 7/10 ns16550: map register base address for debug UART

Quoted 50 lines · Thomas Chou

Hi Wills,

Quoted 40 lines · Wills Wang

MIPS need to use KSEG1 address for register operation, this patch add map_physmem to convert CONFIG_DEBUG_UART_BASE for debug UART.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  drivers/serial/ns16550.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +2 -1
index 3b24af0..1e2538e 100644
@@ -270,7 +270,8 @@ int NS16550_tstc(NS16550_t com_port)
 
  static inline void _debug_uart_init(void)
  {
-    struct NS16550 *com_port = (struct NS16550 
 *)CONFIG_DEBUG_UART_BASE;
+    struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
      int baud_divisor;
 
      /*
drivers/serial/ns16550.c +2 -1
@@ -293,7 +294,8 @@ static inline void _debug_uart_init(void)
 
  static inline void _debug_uart_putc(int ch)
  {
-    struct NS16550 *com_port = (struct NS16550 
 *)CONFIG_DEBUG_UART_BASE;
+    struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 
      while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
Quoted 2 lines
          ;

As debug uart may be used in very early stage and SPL, I would suggest the CONFIG_DEBUG_UART_BASE here is mapped to uncached space already. So that we can keep the code and stack usage minimal.

Quoted 4 lines

My concern is that the uncache mapping in nios2 arch is different between NOMMU and MMU core, which will be decoded from device tree. So it won't work for nios2 until DM initialized.

Ok, i see. CONFIG_DEBUG_UART_BASE is different from the address from device tree if not map.

Quoted 4 lines

Best regards,
Thomas

Signature · 2 lines
Best Regards
Wills
#18 lore raw

PATCH v6 7/10 ns16550: map register base address for debug UART

In reply to Thomas Chou

2016-01-04 14:07 GMT+01:00 Thomas Chou <[email protected]>:

Quoted 52 lines

Hi Wills,

Quoted 41 lines · Wills Wang

MIPS need to use KSEG1 address for register operation, this patch add map_physmem to convert CONFIG_DEBUG_UART_BASE for debug UART.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  drivers/serial/ns16550.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +2 -1
index 3b24af0..1e2538e 100644
@@ -270,7 +270,8 @@ int NS16550_tstc(NS16550_t com_port)
 
  static inline void _debug_uart_init(void)
  {
-       struct NS16550 *com_port = (struct NS16550
 *)CONFIG_DEBUG_UART_BASE;
+       struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                               CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
        int baud_divisor;
 
        /*
drivers/serial/ns16550.c +2 -1
@@ -293,7 +294,8 @@ static inline void _debug_uart_init(void)
 
  static inline void _debug_uart_putc(int ch)
  {
-       struct NS16550 *com_port = (struct NS16550
 *)CONFIG_DEBUG_UART_BASE;
+       struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                               CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 
        while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
Quoted 2 lines
                ;

As debug uart may be used in very early stage and SPL, I would suggest the CONFIG_DEBUG_UART_BASE here is mapped to uncached space already. So that we can keep the code and stack usage minimal.

Quoted 6 lines

My concern is that the uncache mapping in nios2 arch is different between NOMMU and MMU core, which will be decoded from device tree. So it won't work for nios2 until DM initialized.

I agree with Thomas. Please set CONFIG_DEBUG_UART_BASE to a KSEG1 address and discard this patch.

Signature · 1 line
- Daniel
author
#19 lore raw

PATCH v6 7/10 ns16550: map register base address for debug UART

Quoted 51 lines · Daniel Schwierzeck

2016-01-04 14:07 GMT+01:00 Thomas Chou <[email protected]>:

Quoted 50 lines

Hi Wills,

Quoted 40 lines · Wills Wang

MIPS need to use KSEG1 address for register operation, this patch add map_physmem to convert CONFIG_DEBUG_UART_BASE for debug UART.

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

   drivers/serial/ns16550.c | 6 ++++--
   1 file changed, 4 insertions(+), 2 deletions(-)
drivers/serial/ns16550.c +2 -1
index 3b24af0..1e2538e 100644
@@ -270,7 +270,8 @@ int NS16550_tstc(NS16550_t com_port)
 
   static inline void _debug_uart_init(void)
   {
-       struct NS16550 *com_port = (struct NS16550
 *)CONFIG_DEBUG_UART_BASE;
+       struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                               CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
         int baud_divisor;
 
         /*
drivers/serial/ns16550.c +2 -1
@@ -293,7 +294,8 @@ static inline void _debug_uart_init(void)
 
   static inline void _debug_uart_putc(int ch)
   {
-       struct NS16550 *com_port = (struct NS16550
 *)CONFIG_DEBUG_UART_BASE;
+       struct NS16550 *com_port = (struct NS16550 *)map_physmem(
+                               CONFIG_DEBUG_UART_BASE, 0, MAP_NOCACHE);
 
         while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
Quoted 2 lines
                 ;

As debug uart may be used in very early stage and SPL, I would suggest the CONFIG_DEBUG_UART_BASE here is mapped to uncached space already. So that we can keep the code and stack usage minimal.

Quoted 9 lines
Quoted 6 lines

My concern is that the uncache mapping in nios2 arch is different between NOMMU and MMU core, which will be decoded from device tree. So it won't work for nios2 until DM initialized.

I agree with Thomas. Please set CONFIG_DEBUG_UART_BASE to a KSEG1 address and discard this patch.

Ok.
I will correct this in the next patch.

Signature · 2 lines
Best Regards
Wills
author
#20 lore raw

PATCH v6 8/10 mips: ath79: add spi driver

In reply to a message not in the archive

---

Changes in v6:
- Add rrw_delay in ath79_spi_priv for more accurate timing
- Remove ath79_spi_delay
- Calculate delay in ath79_spi_set_speed

Changes in v5:
- remove ar933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operation

Changes in v4:
- Use get_bus_freq instead of hardcode in SPI driver

Changes in v3:
- Convert spi driver to driver model
- Same code style convertion

Changes in v2:
- Add a compatible spi driver

 doc/device-tree-bindings/spi/spi-ath79.txt |  19 +++
 drivers/spi/Kconfig                        |   8 +
 drivers/spi/Makefile                       |   1 +
 drivers/spi/ath79_spi.c                    | 230 +++++++++++++++++++++++++++++
 4 files changed, 258 insertions(+)
 create mode 100644 doc/device-tree-bindings/spi/spi-ath79.txt
 create mode 100644 drivers/spi/ath79_spi.c
doc/device-tree-bindings/spi/spi-ath79.txt new file +19 -0
new file mode 100644
index 0000000..3fd9d67
@@ -0,0 +1,19 @@
+Binding for Qualcomm Atheros AR7xxx/AR9xxx SPI controller
+
+Required properties:
+- compatible: has to be "qca,<soc-type>-spi", "qca,ar7100-spi" as fallback.
+- reg: Base address and size of the controllers memory area
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+	spi at 1f000000 {
+		compatible = "qca,ar9132-spi", "qca,ar7100-spi";
+		reg = <0x1f000000 0x10>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
drivers/spi/Kconfig +8 -0
index 2cdb110..0ab2741 100644
@@ -23,6 +23,14 @@ config ALTERA_SPI
 	  IP core. Please find details on the "Embedded Peripherals IP
 	  User Guide" of Altera.
 
+config ATH79_SPI
+	bool "Atheros SPI driver"
+	help
+	  Enable the Atheros ar7xxx/ar9xxx SoC SPI driver, it was used
+	  to access SPI NOR flash and other SPI peripherals. This driver
+	  uses driver model and requires a device tree binding to operate.
+	  please refer to doc/device-tree-bindings/spi/spi-ath79.txt.
+
 config CADENCE_QSPI
 	bool "Cadence QSPI driver"
 	help
drivers/spi/Makefile +1 -0
index 3eca745..7fb2926 100644
@@ -17,6 +17,7 @@ endif
 
 obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
 obj-$(CONFIG_ARMADA100_SPI) += armada100_spi.o
+obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
 obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/ath79_spi.c new file +230 -0

230 lines not on this page · raw message

Signature · 1 line
1.9.1
#21 lore raw

PATCH v6 8/10 mips: ath79: add spi driver

Hi Wills,

Quoted 314 lines · Wills Wang

---

Changes in v6:
- Add rrw_delay in ath79_spi_priv for more accurate timing
- Remove ath79_spi_delay
- Calculate delay in ath79_spi_set_speed

Changes in v5:
- remove ar933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operation

Changes in v4:
- Use get_bus_freq instead of hardcode in SPI driver

Changes in v3:
- Convert spi driver to driver model
- Same code style convertion

Changes in v2:
- Add a compatible spi driver

  doc/device-tree-bindings/spi/spi-ath79.txt |  19 +++
  drivers/spi/Kconfig                        |   8 +
  drivers/spi/Makefile                       |   1 +
  drivers/spi/ath79_spi.c                    | 230 +++++++++++++++++++++++++++++
  4 files changed, 258 insertions(+)

create mode 100644 doc/device-tree-bindings/spi/spi-ath79.txt create mode 100644 drivers/spi/ath79_spi.c

doc/device-tree-bindings/spi/spi-ath79.txt new file +19 -0
new file mode 100644
index 0000000..3fd9d67
@@ -0,0 +1,19 @@
+Binding for Qualcomm Atheros AR7xxx/AR9xxx SPI controller
+
+Required properties:
+- compatible: has to be "qca,<soc-type>-spi", "qca,ar7100-spi" as fallback.
+- reg: Base address and size of the controllers memory area
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+	spi at 1f000000 {
+		compatible = "qca,ar9132-spi", "qca,ar7100-spi";
+		reg = <0x1f000000 0x10>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
drivers/spi/Kconfig +8 -0
index 2cdb110..0ab2741 100644
@@ -23,6 +23,14 @@ config ALTERA_SPI
  	  IP core. Please find details on the "Embedded Peripherals IP
  	  User Guide" of Altera.
 
+config ATH79_SPI
+	bool "Atheros SPI driver"
+	help
+	  Enable the Atheros ar7xxx/ar9xxx SoC SPI driver, it was used
+	  to access SPI NOR flash and other SPI peripherals. This driver
+	  uses driver model and requires a device tree binding to operate.
+	  please refer to doc/device-tree-bindings/spi/spi-ath79.txt.
+
  config CADENCE_QSPI
  	bool "Cadence QSPI driver"
  	help
drivers/spi/Makefile +1 -0
index 3eca745..7fb2926 100644
@@ -17,6 +17,7 @@ endif
 
  obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
  obj-$(CONFIG_ARMADA100_SPI) += armada100_spi.o
+obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
  obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
  obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
  obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/ath79_spi.c new file +220 -0
new file mode 100644
index 0000000..3912332
@@ -0,0 +1,230 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <spi.h>
+#include <dm.h>
+#include <div64.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/addrspace.h>
+#include <asm/types.h>
+#include <mach/ar71xx_regs.h>
+
+/* CLOCK_DIVIDER = 3 (SPI clock = 200 / 8 ~ 25 MHz) */
+#define ATH79_SPI_CLK_DIV(x)           (((x) >> 1) - 1)
+#define ATH79_SPI_RRW_DELAY_FACTOR     12000
+#define MHZ                             (1000 * 1000)
+
+struct ath79_spi_priv {
+	void __iomem *regs;
+	u32 rrw_delay;
+};
+
+static inline u32 ath79_spi_read(struct udevice *bus, u32 offset)
+{
+	struct ath79_spi_priv *priv = dev_get_priv(bus);
+	return readl(priv->regs + offset);
+}
+
+static inline void ath79_spi_write(struct udevice *bus,
+					u32 val, u32 offset)
+{
+	struct ath79_spi_priv *priv = dev_get_priv(bus);
+	writel(val, priv->regs + offset);
+}
+
+static int ath79_spi_claim_bus(struct udevice *dev)
+{
+	return 0;
+}
+
+static int ath79_spi_release_bus(struct udevice *dev)
+{
+	return 0;
+}
+
+static int ath79_spi_xfer(struct udevice *dev, unsigned int bitlen,
+		const void *dout, void *din, unsigned long flags)
+{
+	struct udevice *bus = dev->parent;
+	struct ath79_spi_priv *priv = dev_get_priv(bus);
+	struct dm_spi_slave_platdata *slave = dev_get_parent_platdata(dev);
+	u8 *rx = din;
+	const u8 *tx = dout;
+	u8 curbyte, curbitlen, restbits;
+	u32 bytes = bitlen / 8;
+	u32 out, in;
+	u64 tick;
+
+
+	if (flags & SPI_XFER_BEGIN) {
+		ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+		ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);
+	}
+
+	restbits = (bitlen % 8);
+	if (restbits)
+		bytes++;
+
+	out = AR71XX_SPI_IOC_CS_ALL & ~(AR71XX_SPI_IOC_CS(slave->cs));
+	while (bytes > 0) {
+		bytes--;
+		curbyte = 0;
+		if (tx)
+			curbyte = *tx++;
+
+		if (restbits && !bytes) {
+			curbitlen = restbits;
+			curbyte <<= 8 - restbits;
+		} else {
+			curbitlen = 8;
+		}
+
+		for (curbyte <<= (8 - curbitlen); curbitlen; curbitlen--) {
+			if (curbyte & 0x80)
+				out |= AR71XX_SPI_IOC_DO;
+			else
+				out &= ~(AR71XX_SPI_IOC_DO);
+
+			ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+			/* delay for low level */
+			if (priv->rrw_delay) {
+				tick = get_ticks() + priv->rrw_delay;
+				while (get_ticks() < tick)
+					/*NOP*/;
+			}
+
+			ath79_spi_write(bus, out | AR71XX_SPI_IOC_CLK,
+					AR71XX_SPI_REG_IOC);
+
+			/* delay for high level */
+			if (priv->rrw_delay) {
+				tick = get_ticks() + priv->rrw_delay;
+				while (get_ticks() < tick)
+					/*NOP*/;
+			}
+
+			curbyte <<= 1;
+		}
+
+		if (!bytes)
+			ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+		in = ath79_spi_read(bus, AR71XX_SPI_REG_RDS);
+		if (rx) {
+			if (restbits && !bytes)
+				*rx++ = (in << (8 - restbits));
+			else
+				*rx++ = in;
+		}
+	}
+
+	if (flags & SPI_XFER_END) {
+		ath79_spi_write(bus, AR71XX_SPI_IOC_CS(slave->cs),
+				AR71XX_SPI_REG_IOC);
+		ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);
+		ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);
+	}
+
+	return 0;
+}
+
+
+static int ath79_spi_set_speed(struct udevice *bus, uint speed)
+{
+	struct ath79_spi_priv *priv = dev_get_priv(bus);
+	u32 val, div = 0;
+	u64 time;
+
+	if (speed)
+		div = get_bus_freq(0) / speed;
+
+	if (div > 63)
+		div = 63;
+
+	if (div < 5)
+		div = 5;
+
+	/* calculate delay */
+	time = get_tbclk();
+	do_div(time, speed / 2);
+	val = ATH79_SPI_RRW_DELAY_FACTOR / (get_bus_freq(0) / MHZ);
+	if (time > val)
+		priv->rrw_delay = time - val + 1;
+	else
+		priv->rrw_delay = 0;
+
+	ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+	val = ath79_spi_read(bus, AR71XX_SPI_REG_CTRL);
+	val &= ~AR71XX_SPI_CTRL_DIV_MASK;
+	val |= ATH79_SPI_CLK_DIV(div);
+	ath79_spi_write(bus, val, AR71XX_SPI_REG_CTRL);
+	ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);
+	return 0;
+}
+
+static int ath79_spi_set_mode(struct udevice *bus, uint mode)
+{
+	return 0;
+}
+
+static int ath79_spi_probe(struct udevice *bus)
+{
+	struct ath79_spi_priv *priv = dev_get_priv(bus);
+	fdt_addr_t addr;
+
+	addr = dev_get_addr(bus);
+	if (addr == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	priv->regs = map_physmem(addr,
+				 AR71XX_SPI_SIZE,
+				 MAP_NOCACHE);
+
+	/* Init SPI Hardware, disable remap, set clock */
+	ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+	ath79_spi_write(bus, AR71XX_SPI_CTRL_RD | ATH79_SPI_CLK_DIV(8),
+			AR71XX_SPI_REG_CTRL);
+	ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);
+
+	return 0;
+}
+
+static int ath79_cs_info(struct udevice *bus, uint cs,
+			   struct spi_cs_info *info)
+{
+	/* Always allow activity on CS 0/1/2 */
+	if (cs >= 3)
+		return -ENODEV;
+
+	return 0;
+}
+
+static const struct dm_spi_ops ath79_spi_ops = {
+	.claim_bus  = ath79_spi_claim_bus,
+	.release_bus    = ath79_spi_release_bus,
+	.xfer       = ath79_spi_xfer,
+	.set_speed  = ath79_spi_set_speed,
+	.set_mode   = ath79_spi_set_mode,
+	.cs_info    = ath79_cs_info,
+};
+
+static const struct udevice_id ath79_spi_ids[] = {
+	{ .compatible = "qca,ar7100-spi" },
+	{}

drivers/spi/ath79_spi.c line 230

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+};
+
+U_BOOT_DRIVER(ath79_spi) = {
+	.name   = "ath79_spi",
+	.id = UCLASS_SPI,
+	.of_match = ath79_spi_ids,
+	.ops    = &ath79_spi_ops,
+	.priv_auto_alloc_size = sizeof(struct ath79_spi_priv),
+	.probe  = ath79_spi_probe,
+};

Best regards,
Thomas

#22 lore raw

PATCH v6 8/10 mips: ath79: add spi driver

In reply to Wills Wang
Quoted 93 lines · Wills Wang

---

Changes in v6:
- Add rrw_delay in ath79_spi_priv for more accurate timing
- Remove ath79_spi_delay
- Calculate delay in ath79_spi_set_speed

Changes in v5:
- remove ar933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operation

Changes in v4:
- Use get_bus_freq instead of hardcode in SPI driver

Changes in v3:
- Convert spi driver to driver model
- Same code style convertion

Changes in v2:
- Add a compatible spi driver

 doc/device-tree-bindings/spi/spi-ath79.txt |  19 +++
 drivers/spi/Kconfig                        |   8 +
 drivers/spi/Makefile                       |   1 +
 drivers/spi/ath79_spi.c                    | 230 +++++++++++++++++++++++++++++
 4 files changed, 258 insertions(+)
 create mode 100644 doc/device-tree-bindings/spi/spi-ath79.txt
 create mode 100644 drivers/spi/ath79_spi.c
doc/device-tree-bindings/spi/spi-ath79.txt new file +19 -0
new file mode 100644
index 0000000..3fd9d67
@@ -0,0 +1,19 @@
+Binding for Qualcomm Atheros AR7xxx/AR9xxx SPI controller
+
+Required properties:
+- compatible: has to be "qca,<soc-type>-spi", "qca,ar7100-spi" as fallback.
+- reg: Base address and size of the controllers memory area
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+       spi at 1f000000 {
+               compatible = "qca,ar9132-spi", "qca,ar7100-spi";
+               reg = <0x1f000000 0x10>;
+
+               #address-cells = <1>;
+               #size-cells = <0>;
+       };
drivers/spi/Kconfig +8 -0
index 2cdb110..0ab2741 100644
@@ -23,6 +23,14 @@ config ALTERA_SPI
          IP core. Please find details on the "Embedded Peripherals IP
          User Guide" of Altera.
 
+config ATH79_SPI
+       bool "Atheros SPI driver"
+       help
+         Enable the Atheros ar7xxx/ar9xxx SoC SPI driver, it was used
+         to access SPI NOR flash and other SPI peripherals. This driver
+         uses driver model and requires a device tree binding to operate.
+         please refer to doc/device-tree-bindings/spi/spi-ath79.txt.
+
 config CADENCE_QSPI
        bool "Cadence QSPI driver"
        help
drivers/spi/Makefile +1 -0
index 3eca745..7fb2926 100644
@@ -17,6 +17,7 @@ endif
 
 obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
 obj-$(CONFIG_ARMADA100_SPI) += armada100_spi.o
+obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
 obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
 obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
 obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/ath79_spi.c new file +0 -0
new file mode 100644
index 0000000..3912332

drivers/spi/ath79_spi.c line 3

Quoted 3 lines
drivers/spi/ath79_spi.c new file +3 -0
@@ -0,0 +1,230 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>

Append this above the line with space.

drivers/spi/ath79_spi.c line 16

Quoted 13 lines
drivers/spi/ath79_spi.c new file +13 -0
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <spi.h>
+#include <dm.h>
+#include <div64.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/addrspace.h>
+#include <asm/types.h>
+#include <mach/ar71xx_regs.h>

Does this regs common for ar71xx or for spi?

drivers/spi/ath79_spi.c line 21

Quoted 5 lines
drivers/spi/ath79_spi.c new file +5 -0
+
+/* CLOCK_DIVIDER = 3 (SPI clock = 200 / 8 ~ 25 MHz) */
+#define ATH79_SPI_CLK_DIV(x)           (((x) >> 1) - 1)
+#define ATH79_SPI_RRW_DELAY_FACTOR     12000
+#define MHZ                             (1000 * 1000)

Rename MHZ to ATH79_SPI_MHZ or similar

Quoted 8 lines
drivers/spi/ath79_spi.c new file +8 -0
+
+struct ath79_spi_priv {
+       void __iomem *regs;
+       u32 rrw_delay;
+};
+
+static inline u32 ath79_spi_read(struct udevice *bus, u32 offset)
+{

drivers/spi/ath79_spi.c line 39

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       return readl(priv->regs + offset);
+}
+
+static inline void ath79_spi_write(struct udevice *bus,
+                                       u32 val, u32 offset)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       writel(val, priv->regs + offset);
+}

Instead of adding these new read|write calls, use readl and writel directly since we can get bus any where using dev

Quoted 18 lines
drivers/spi/ath79_spi.c new file +18 -0
+
+static int ath79_spi_claim_bus(struct udevice *dev)
+{
+       return 0;
+}
+
+static int ath79_spi_release_bus(struct udevice *dev)
+{
+       return 0;
+}
+
+static int ath79_spi_xfer(struct udevice *dev, unsigned int bitlen,
+               const void *dout, void *din, unsigned long flags)
+{
+       struct udevice *bus = dev->parent;
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       struct dm_spi_slave_platdata *slave = dev_get_parent_platdata(dev);
+       u8 *rx = din;

drivers/spi/ath79_spi.c line 67

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+       const u8 *tx = dout;
+       u8 curbyte, curbitlen, restbits;
+       u32 bytes = bitlen / 8;
+       u32 out, in;
+       u64 tick;
+
+
+       if (flags & SPI_XFER_BEGIN) {
+               ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);

Move this code to local spi_cs_activate and use clrbits_xxx or setbits_xxxx if required for just to activate or deactivate specific bits.

Quoted 33 lines
drivers/spi/ath79_spi.c new file +33 -0
+       }
+
+       restbits = (bitlen % 8);
+       if (restbits)
+               bytes++;
+
+       out = AR71XX_SPI_IOC_CS_ALL & ~(AR71XX_SPI_IOC_CS(slave->cs));
+       while (bytes > 0) {
+               bytes--;
+               curbyte = 0;
+               if (tx)
+                       curbyte = *tx++;
+
+               if (restbits && !bytes) {
+                       curbitlen = restbits;
+                       curbyte <<= 8 - restbits;
+               } else {
+                       curbitlen = 8;
+               }
+
+               for (curbyte <<= (8 - curbitlen); curbitlen; curbitlen--) {
+                       if (curbyte & 0x80)
+                               out |= AR71XX_SPI_IOC_DO;
+                       else
+                               out &= ~(AR71XX_SPI_IOC_DO);
+
+                       ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+                       /* delay for low level */
+                       if (priv->rrw_delay) {
+                               tick = get_ticks() + priv->rrw_delay;
+                               while (get_ticks() < tick)
+                                       /*NOP*/;

drivers/spi/ath79_spi.c line 110

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+                       }
+
+                       ath79_spi_write(bus, out | AR71XX_SPI_IOC_CLK,
+                                       AR71XX_SPI_REG_IOC);
+
+                       /* delay for high level */
+                       if (priv->rrw_delay) {
+                               tick = get_ticks() + priv->rrw_delay;
+                               while (get_ticks() < tick)
+                                       /*NOP*/;

Better to do timeout check instead of infinite while.

Quoted 12 lines
drivers/spi/ath79_spi.c new file +12 -0
+                       }
+
+                       curbyte <<= 1;
+               }
+
+               if (!bytes)
+                       ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+               in = ath79_spi_read(bus, AR71XX_SPI_REG_RDS);
+               if (rx) {
+                       if (restbits && !bytes)
+                               *rx++ = (in << (8 - restbits));

drivers/spi/ath79_spi.c line 132

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+                       else
+                               *rx++ = in;
+               }
+       }
+
+       if (flags & SPI_XFER_END) {
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS(slave->cs),
+                               AR71XX_SPI_REG_IOC);
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);
+               ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);

Same as above use spi_cs_deactivate

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+       }
+
+       return 0;
+}
+
+
+static int ath79_spi_set_speed(struct udevice *bus, uint speed)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       u32 val, div = 0;

drivers/spi/ath79_spi.c line 152

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+       u64 time;
+
+       if (speed)
+               div = get_bus_freq(0) / speed;
+
+       if (div > 63)
+               div = 63;
+
+       if (div < 5)
+               div = 5;

Where are these div comparisons? please add clear short comment.

Quoted 6 lines
drivers/spi/ath79_spi.c new file +6 -0
+
+       /* calculate delay */
+       time = get_tbclk();
+       do_div(time, speed / 2);
+       val = ATH79_SPI_RRW_DELAY_FACTOR / (get_bus_freq(0) / MHZ);
+       if (time > val)

drivers/spi/ath79_spi.c line 168

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+               priv->rrw_delay = time - val + 1;
+       else
+               priv->rrw_delay = 0;
+
+       ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+       val = ath79_spi_read(bus, AR71XX_SPI_REG_CTRL);
+       val &= ~AR71XX_SPI_CTRL_DIV_MASK;
+       val |= ATH79_SPI_CLK_DIV(div);
+       ath79_spi_write(bus, val, AR71XX_SPI_REG_CTRL);
+       ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);

This write also for speed setting, does this function doing other than speed_setup?

Quoted 53 lines
drivers/spi/ath79_spi.c new file +53 -0
+       return 0;
+}
+
+static int ath79_spi_set_mode(struct udevice *bus, uint mode)
+{
+       return 0;
+}
+
+static int ath79_spi_probe(struct udevice *bus)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       fdt_addr_t addr;
+
+       addr = dev_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       priv->regs = map_physmem(addr,
+                                AR71XX_SPI_SIZE,
+                                MAP_NOCACHE);
+
+       /* Init SPI Hardware, disable remap, set clock */
+       ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+       ath79_spi_write(bus, AR71XX_SPI_CTRL_RD | ATH79_SPI_CLK_DIV(8),
+                       AR71XX_SPI_REG_CTRL);
+       ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);
+
+       return 0;
+}
+
+static int ath79_cs_info(struct udevice *bus, uint cs,
+                          struct spi_cs_info *info)
+{
+       /* Always allow activity on CS 0/1/2 */
+       if (cs >= 3)
+               return -ENODEV;
+
+       return 0;
+}
+
+static const struct dm_spi_ops ath79_spi_ops = {
+       .claim_bus  = ath79_spi_claim_bus,
+       .release_bus    = ath79_spi_release_bus,
+       .xfer       = ath79_spi_xfer,
+       .set_speed  = ath79_spi_set_speed,
+       .set_mode   = ath79_spi_set_mode,
+       .cs_info    = ath79_cs_info,
+};
+
+static const struct udevice_id ath79_spi_ids[] = {
+       { .compatible = "qca,ar7100-spi" },
+       {}
+};

drivers/spi/ath79_spi.c

Quoted 10 lines
drivers/spi/ath79_spi.c new file +9 -1
+
+U_BOOT_DRIVER(ath79_spi) = {
+       .name   = "ath79_spi",
+       .id = UCLASS_SPI,
+       .of_match = ath79_spi_ids,
+       .ops    = &ath79_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct ath79_spi_priv),
+       .probe  = ath79_spi_probe,
+};
--

thanks!

Signature · 1 line
Jagan.
author
#23 lore raw

PATCH v6 8/10 mips: ath79: add spi driver

Quoted 82 lines · Jagan Teki
Quoted 81 lines · Wills Wang

---

Changes in v6:
- Add rrw_delay in ath79_spi_priv for more accurate timing
- Remove ath79_spi_delay
- Calculate delay in ath79_spi_set_speed

Changes in v5:
- remove ar933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operation

Changes in v4:
- Use get_bus_freq instead of hardcode in SPI driver

Changes in v3:
- Convert spi driver to driver model
- Same code style convertion

Changes in v2:
- Add a compatible spi driver

  doc/device-tree-bindings/spi/spi-ath79.txt |  19 +++
  drivers/spi/Kconfig                        |   8 +
  drivers/spi/Makefile                       |   1 +
  drivers/spi/ath79_spi.c                    | 230 +++++++++++++++++++++++++++++
  4 files changed, 258 insertions(+)

create mode 100644 doc/device-tree-bindings/spi/spi-ath79.txt create mode 100644 drivers/spi/ath79_spi.c

doc/device-tree-bindings/spi/spi-ath79.txt new file +19 -0
new file mode 100644
index 0000000..3fd9d67
@@ -0,0 +1,19 @@
+Binding for Qualcomm Atheros AR7xxx/AR9xxx SPI controller
+
+Required properties:
+- compatible: has to be "qca,<soc-type>-spi", "qca,ar7100-spi" as fallback.
+- reg: Base address and size of the controllers memory area
+- #address-cells: <1>, as required by generic SPI binding.
+- #size-cells: <0>, also as required by generic SPI binding.
+
+Child nodes as per the generic SPI binding.
+
+Example:
+
+       spi at 1f000000 {
+               compatible = "qca,ar9132-spi", "qca,ar7100-spi";
+               reg = <0x1f000000 0x10>;
+
+               #address-cells = <1>;
+               #size-cells = <0>;
+       };
drivers/spi/Kconfig +8 -0
index 2cdb110..0ab2741 100644
@@ -23,6 +23,14 @@ config ALTERA_SPI
           IP core. Please find details on the "Embedded Peripherals IP
           User Guide" of Altera.
 
+config ATH79_SPI
+       bool "Atheros SPI driver"
+       help
+         Enable the Atheros ar7xxx/ar9xxx SoC SPI driver, it was used
+         to access SPI NOR flash and other SPI peripherals. This driver
+         uses driver model and requires a device tree binding to operate.
+         please refer to doc/device-tree-bindings/spi/spi-ath79.txt.
+
  config CADENCE_QSPI
         bool "Cadence QSPI driver"
         help
drivers/spi/Makefile +0 -0
index 3eca745..7fb2926 100644
@@ -17,6 +17,7 @@ endif
 
Quoted 16 lines
Quoted 12 lines
drivers/spi/Makefile +1 -0
  obj-$(CONFIG_ALTERA_SPI) += altera_spi.o
  obj-$(CONFIG_ARMADA100_SPI) += armada100_spi.o
+obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
  obj-$(CONFIG_ATMEL_DATAFLASH_SPI) += atmel_dataflash_spi.o
  obj-$(CONFIG_ATMEL_SPI) += atmel_spi.o
  obj-$(CONFIG_BFIN_SPI) += bfin_spi.o
drivers/spi/ath79_spi.c new file +0 -0
new file mode 100644
index 0000000..3912332

drivers/spi/ath79_spi.c line 3

Quoted 3 lines
drivers/spi/ath79_spi.c new file +3 -0
@@ -0,0 +1,230 @@
+/*
+ * (C) Copyright 2015
+ * Wills Wang, <[email protected]>

Append this above the line with space.

Where?

Quoted 6 lines
Quoted 6 lines
drivers/spi/ath79_spi.c new file +6 -0
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <spi.h>
Quoted 8 lines

drivers/spi/ath79_spi.c line 16

Quoted 7 lines
drivers/spi/ath79_spi.c new file +7 -0
+#include <dm.h>
+#include <div64.h>
+#include <errno.h>
+#include <asm/io.h>
+#include <asm/addrspace.h>
+#include <asm/types.h>
+#include <mach/ar71xx_regs.h>

Does this regs common for ar71xx or for spi?

Yes

Quoted 6 lines

drivers/spi/ath79_spi.c line 21

Quoted 5 lines
drivers/spi/ath79_spi.c new file +5 -0
+
+/* CLOCK_DIVIDER = 3 (SPI clock = 200 / 8 ~ 25 MHz) */
+#define ATH79_SPI_CLK_DIV(x)           (((x) >> 1) - 1)
+#define ATH79_SPI_RRW_DELAY_FACTOR     12000
+#define MHZ                             (1000 * 1000)

Rename MHZ to ATH79_SPI_MHZ or similar

Ok.

Quoted 12 lines
Quoted 12 lines
drivers/spi/ath79_spi.c new file +12 -0
+
+struct ath79_spi_priv {
+       void __iomem *regs;
+       u32 rrw_delay;
+};
+
+static inline u32 ath79_spi_read(struct udevice *bus, u32 offset)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       return readl(priv->regs + offset);
+}
+
Quoted 9 lines

drivers/spi/ath79_spi.c line 39

Quoted 6 lines
drivers/spi/ath79_spi.c new file +6 -0
+static inline void ath79_spi_write(struct udevice *bus,
+                                       u32 val, u32 offset)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       writel(val, priv->regs + offset);
+}

Instead of adding these new read|write calls, use readl and writel directly since we can get bus any where using dev

There is an inline function.

Quoted 23 lines
Quoted 23 lines
drivers/spi/ath79_spi.c new file +23 -0
+
+static int ath79_spi_claim_bus(struct udevice *dev)
+{
+       return 0;
+}
+
+static int ath79_spi_release_bus(struct udevice *dev)
+{
+       return 0;
+}
+
+static int ath79_spi_xfer(struct udevice *dev, unsigned int bitlen,
+               const void *dout, void *din, unsigned long flags)
+{
+       struct udevice *bus = dev->parent;
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       struct dm_spi_slave_platdata *slave = dev_get_parent_platdata(dev);
+       u8 *rx = din;
+       const u8 *tx = dout;
+       u8 curbyte, curbitlen, restbits;
+       u32 bytes = bitlen / 8;
+       u32 out, in;
+       u64 tick;
Quoted 8 lines

drivers/spi/ath79_spi.c line 67

Quoted 5 lines
drivers/spi/ath79_spi.c new file +5 -0
+
+
+       if (flags & SPI_XFER_BEGIN) {
+               ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);

Move this code to local spi_cs_activate and use clrbits_xxx or setbits_xxxx if required for just to activate or deactivate specific bits.

Ok.

Quoted 36 lines
Quoted 36 lines
drivers/spi/ath79_spi.c new file +36 -0
+       }
+
+       restbits = (bitlen % 8);
+       if (restbits)
+               bytes++;
+
+       out = AR71XX_SPI_IOC_CS_ALL & ~(AR71XX_SPI_IOC_CS(slave->cs));
+       while (bytes > 0) {
+               bytes--;
+               curbyte = 0;
+               if (tx)
+                       curbyte = *tx++;
+
+               if (restbits && !bytes) {
+                       curbitlen = restbits;
+                       curbyte <<= 8 - restbits;
+               } else {
+                       curbitlen = 8;
+               }
+
+               for (curbyte <<= (8 - curbitlen); curbitlen; curbitlen--) {
+                       if (curbyte & 0x80)
+                               out |= AR71XX_SPI_IOC_DO;
+                       else
+                               out &= ~(AR71XX_SPI_IOC_DO);
+
+                       ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+                       /* delay for low level */
+                       if (priv->rrw_delay) {
+                               tick = get_ticks() + priv->rrw_delay;
+                               while (get_ticks() < tick)
+                                       /*NOP*/;
+                       }
+
+                       ath79_spi_write(bus, out | AR71XX_SPI_IOC_CLK,
Quoted 8 lines

drivers/spi/ath79_spi.c line 110

Quoted 7 lines
drivers/spi/ath79_spi.c new file +7 -0
+                                       AR71XX_SPI_REG_IOC);
+
+                       /* delay for high level */
+                       if (priv->rrw_delay) {
+                               tick = get_ticks() + priv->rrw_delay;
+                               while (get_ticks() < tick)
+                                       /*NOP*/;

Better to do timeout check instead of infinite while.

I think it is a timeout check.

Quoted 37 lines
Quoted 12 lines
drivers/spi/ath79_spi.c new file +12 -0
+                       }
+
+                       curbyte <<= 1;
+               }
+
+               if (!bytes)
+                       ath79_spi_write(bus, out, AR71XX_SPI_REG_IOC);
+
+               in = ath79_spi_read(bus, AR71XX_SPI_REG_RDS);
+               if (rx) {
+                       if (restbits && !bytes)
+                               *rx++ = (in << (8 - restbits));

drivers/spi/ath79_spi.c line 132

Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+                       else
+                               *rx++ = in;
+               }
+       }
+
+       if (flags & SPI_XFER_END) {
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS(slave->cs),
+                               AR71XX_SPI_REG_IOC);
+               ath79_spi_write(bus, AR71XX_SPI_IOC_CS_ALL, AR71XX_SPI_REG_IOC);
+               ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);

Same as above use spi_cs_deactivate

Quoted 13 lines
drivers/spi/ath79_spi.c new file +13 -0
+       }
+
+       return 0;
+}
+
+
+static int ath79_spi_set_speed(struct udevice *bus, uint speed)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       u32 val, div = 0;
+       u64 time;
+
+       if (speed)
Quoted 8 lines

drivers/spi/ath79_spi.c line 152

Quoted 7 lines
drivers/spi/ath79_spi.c new file +7 -0
+               div = get_bus_freq(0) / speed;
+
+       if (div > 63)
+               div = 63;
+
+       if (div < 5)
+               div = 5;

Where are these div comparisons? please add clear short comment.

The lower limitation is an empirical value, upper limitation is the maximum value for register filed.

Quoted 10 lines
Quoted 10 lines
drivers/spi/ath79_spi.c new file +10 -0
+
+       /* calculate delay */
+       time = get_tbclk();
+       do_div(time, speed / 2);
+       val = ATH79_SPI_RRW_DELAY_FACTOR / (get_bus_freq(0) / MHZ);
+       if (time > val)
+               priv->rrw_delay = time - val + 1;
+       else
+               priv->rrw_delay = 0;
+
Quoted 9 lines

drivers/spi/ath79_spi.c line 168

Quoted 6 lines
drivers/spi/ath79_spi.c new file +6 -0
+       ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+       val = ath79_spi_read(bus, AR71XX_SPI_REG_CTRL);
+       val &= ~AR71XX_SPI_CTRL_DIV_MASK;
+       val |= ATH79_SPI_CLK_DIV(div);
+       ath79_spi_write(bus, val, AR71XX_SPI_REG_CTRL);
+       ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);

This write also for speed setting, does this function doing other than speed_setup?

Calculate SPI bitbang delay according to speed.

Quoted 64 lines
Quoted 53 lines
drivers/spi/ath79_spi.c new file +53 -0
+       return 0;
+}
+
+static int ath79_spi_set_mode(struct udevice *bus, uint mode)
+{
+       return 0;
+}
+
+static int ath79_spi_probe(struct udevice *bus)
+{
+       struct ath79_spi_priv *priv = dev_get_priv(bus);
+       fdt_addr_t addr;
+
+       addr = dev_get_addr(bus);
+       if (addr == FDT_ADDR_T_NONE)
+               return -EINVAL;
+
+       priv->regs = map_physmem(addr,
+                                AR71XX_SPI_SIZE,
+                                MAP_NOCACHE);
+
+       /* Init SPI Hardware, disable remap, set clock */
+       ath79_spi_write(bus, AR71XX_SPI_FS_GPIO, AR71XX_SPI_REG_FS);
+       ath79_spi_write(bus, AR71XX_SPI_CTRL_RD | ATH79_SPI_CLK_DIV(8),
+                       AR71XX_SPI_REG_CTRL);
+       ath79_spi_write(bus, 0, AR71XX_SPI_REG_FS);
+
+       return 0;
+}
+
+static int ath79_cs_info(struct udevice *bus, uint cs,
+                          struct spi_cs_info *info)
+{
+       /* Always allow activity on CS 0/1/2 */
+       if (cs >= 3)
+               return -ENODEV;
+
+       return 0;
+}
+
+static const struct dm_spi_ops ath79_spi_ops = {
+       .claim_bus  = ath79_spi_claim_bus,
+       .release_bus    = ath79_spi_release_bus,
+       .xfer       = ath79_spi_xfer,
+       .set_speed  = ath79_spi_set_speed,
+       .set_mode   = ath79_spi_set_mode,
+       .cs_info    = ath79_cs_info,
+};
+
+static const struct udevice_id ath79_spi_ids[] = {
+       { .compatible = "qca,ar7100-spi" },
+       {}
+};

drivers/spi/ath79_spi.c

Quoted 10 lines
drivers/spi/ath79_spi.c new file +9 -1
+
+U_BOOT_DRIVER(ath79_spi) = {
+       .name   = "ath79_spi",
+       .id = UCLASS_SPI,
+       .of_match = ath79_spi_ids,
+       .ops    = &ath79_spi_ops,
+       .priv_auto_alloc_size = sizeof(struct ath79_spi_priv),
+       .probe  = ath79_spi_probe,
+};
--

thanks!

Signature · 2 lines
Best Regards
Wills
author
#24 lore raw

PATCH v6 9/10 mips: ath79: add AP121 reference board

In reply to a message not in the archive

---

Changes in v6:
- Convert SZ_XXX into hex in ap121.h
- Remove useless CONFIG_SYS_INIT_SP_OFFSET in ap121.h
- Add board_early_init_f for DDR and pin initialization
- Select UART and SPI in ap121_defconfig

Changes in v5:
- Move CONFIG_SYS_TEXT_BASE into ap121.h, and remove config.mk
- Remove useless README file
- Remove useless checkboard function

Changes in v4: None
Changes in v3:
- Add support for device tree

Changes in v2:
- Add a reference board implemention

 arch/mips/dts/Makefile        |  2 +-
 arch/mips/dts/ap121.dts       | 37 ++++++++++++++++++++
 arch/mips/dts/ar933x.dtsi     | 64 ++++++++++++++++++++++++++++++++++
 arch/mips/mach-ath79/Kconfig  | 11 ++++++
 board/ath79/ap121/Kconfig     |  9 +++++
 board/ath79/ap121/MAINTAINERS |  6 ++++
 board/ath79/ap121/Makefile    |  5 +++
 board/ath79/ap121/ap121.c     | 48 +++++++++++++++++++++++++
 configs/ap121_defconfig       | 42 ++++++++++++++++++++++
 include/configs/ap121.h       | 81 +++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 304 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/dts/ap121.dts
 create mode 100644 arch/mips/dts/ar933x.dtsi
 create mode 100644 board/ath79/ap121/Kconfig
 create mode 100644 board/ath79/ap121/MAINTAINERS
 create mode 100644 board/ath79/ap121/Makefile
 create mode 100644 board/ath79/ap121/ap121.c
 create mode 100644 configs/ap121_defconfig
 create mode 100644 include/configs/ap121.h
arch/mips/dts/Makefile +1 -1
index 47b6eb5..3fd49eb 100644
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-dtb-y +=
+dtb-$(CONFIG_BOARD_AP121) += ap121.dtb
 
 targets += $(dtb-y)
 
arch/mips/dts/ap121.dts new file +37 -0
new file mode 100644
index 0000000..f7c3a1a
@@ -0,0 +1,37 @@
+/dts-v1/;
+#include "ar933x.dtsi"
+
+/ {
+	model = "AP121 Reference Board";
+	compatible = "qca,ap121", "qca,ar933x";
+
+	aliases {
+		spi0 = &spi0;
+		serial0 = &uart0;
+	};
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+	};
+};
+
+&xtal {
+	clock-frequency = <25000000>;
+};
+
+&uart0 {
+	status = "okay";
+};
+
+&spi0 {
+	spi-max-frequency = <25000000>;
+	status = "okay";
+	spi-flash at 0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "spi-flash";
+		memory-map = <0x9f000000 0x00800000>;
+		spi-max-frequency = <25000000>;
+		reg = <0>;
+	};
+};
arch/mips/dts/ar933x.dtsi new file +64 -0

64 lines not on this page · raw message

arch/mips/mach-ath79/Kconfig +11 -0
index f7801e4..0fcd96a 100644
@@ -27,4 +27,15 @@ config SOC_QCA953X
 	help
 	  This supports QCA/Atheros qca953x family SOCs.
 
+choice
+	prompt "Board select"
+
+config BOARD_AP121
+	bool "AP121 Reference Board"
+	select SOC_AR933X
+
+endchoice
+
+source "board/ath79/ap121/Kconfig"
+
 endmenu
board/ath79/ap121/Kconfig new file +9 -0
new file mode 100644
index 0000000..ec72914
@@ -0,0 +1,9 @@
+if BOARD_AP121
+
+config SYS_BOARD
+	default "ap121"
+
+config SYS_CONFIG_NAME
+	default "ap121"
+
+endif
board/ath79/ap121/MAINTAINERS new file +6 -0
new file mode 100644
index 0000000..319b521
@@ -0,0 +1,6 @@
+AP121 BOARD
+M:	Wills Wang <[email protected]>
+S:	Maintained
+F:	board/ath79/ap121/
+F:	include/configs/ap121.h
+F:	configs/ap121_defconfig
board/ath79/ap121/Makefile new file +5 -0
new file mode 100644
index 0000000..ced5432
@@ -0,0 +1,5 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y	= ap121.o
board/ath79/ap121/ap121.c new file +48 -0

48 lines not on this page · raw message

configs/ap121_defconfig new file +42 -0

42 lines not on this page · raw message

include/configs/ap121.h new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#25 lore raw

PATCH v6 10/10 mips: ath79: add AP143 reference board

In reply to a message not in the archive

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/mips/dts/Makefile        |  1 +
 arch/mips/dts/ap143.dts       | 37 +++++++++++++++++++
 arch/mips/dts/qca953x.dtsi    | 66 +++++++++++++++++++++++++++++++++
 arch/mips/mach-ath79/Kconfig  |  5 +++
 board/ath79/ap143/Kconfig     |  9 +++++
 board/ath79/ap143/MAINTAINERS |  6 +++
 board/ath79/ap143/Makefile    |  5 +++
 board/ath79/ap143/ap143.c     | 64 ++++++++++++++++++++++++++++++++
 configs/ap143_defconfig       | 43 ++++++++++++++++++++++
 include/configs/ap143.h       | 86 +++++++++++++++++++++++++++++++++++++++++++
 10 files changed, 322 insertions(+)
 create mode 100644 arch/mips/dts/ap143.dts
 create mode 100644 arch/mips/dts/qca953x.dtsi
 create mode 100644 board/ath79/ap143/Kconfig
 create mode 100644 board/ath79/ap143/MAINTAINERS
 create mode 100644 board/ath79/ap143/Makefile
 create mode 100644 board/ath79/ap143/ap143.c
 create mode 100644 configs/ap143_defconfig
 create mode 100644 include/configs/ap143.h
arch/mips/dts/Makefile +1 -0
index 3fd49eb..7da06c5 100644
@@ -3,6 +3,7 @@
 #
 
 dtb-$(CONFIG_BOARD_AP121) += ap121.dtb
+dtb-$(CONFIG_BOARD_AP143) += ap143.dtb
 
 targets += $(dtb-y)
 
arch/mips/dts/ap143.dts new file +37 -0
new file mode 100644
index 0000000..2133232
@@ -0,0 +1,37 @@
+/dts-v1/;
+#include "qca953x.dtsi"
+
+/ {
+	model = "AP143 Reference Board";
+	compatible = "qca,ap143", "qca,qca953x";
+
+	aliases {
+		spi0 = &spi0;
+		serial0 = &uart0;
+	};
+
+	chosen {
+		stdout-path = "serial0:115200n8";
+	};
+};
+
+&xtal {
+	clock-frequency = <25000000>;
+};
+
+&uart0 {
+	status = "okay";
+};
+
+&spi0 {
+	spi-max-frequency = <25000000>;
+	status = "okay";
+	spi-flash at 0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "spi-flash";
+		memory-map = <0x9f000000 0x00800000>;
+		spi-max-frequency = <25000000>;
+		reg = <0>;
+	};
+};
arch/mips/dts/qca953x.dtsi new file +66 -0

66 lines not on this page · raw message

arch/mips/mach-ath79/Kconfig +5 -0
index 0fcd96a..f61efd2 100644
@@ -34,8 +34,13 @@ config BOARD_AP121
 	bool "AP121 Reference Board"
 	select SOC_AR933X
 
+config BOARD_AP143
+	bool "AP143 Reference Board"
+	select SOC_QCA953X
+
 endchoice
 
 source "board/ath79/ap121/Kconfig"
+source "board/ath79/ap143/Kconfig"
 
 endmenu
board/ath79/ap143/Kconfig new file +9 -0
new file mode 100644
index 0000000..118b9b5
@@ -0,0 +1,9 @@
+if BOARD_AP143
+
+config SYS_BOARD
+	default "ap143"
+
+config SYS_CONFIG_NAME
+	default "ap143"
+
+endif
board/ath79/ap143/MAINTAINERS new file +6 -0
new file mode 100644
index 0000000..d373cf8
@@ -0,0 +1,6 @@
+AP143 BOARD
+M:	Wills Wang <[email protected]>
+S:	Maintained
+F:	board/ath79/ap143/
+F:	include/configs/ap143.h
+F:	configs/ap143_defconfig
board/ath79/ap143/Makefile new file +5 -0
new file mode 100644
index 0000000..00f7837
@@ -0,0 +1,5 @@
+#
+# SPDX-License-Identifier:	GPL-2.0+
+#
+
+obj-y	= ap143.o
board/ath79/ap143/ap143.c new file +64 -0

64 lines not on this page · raw message

configs/ap143_defconfig new file +43 -0

43 lines not on this page · raw message

include/configs/ap143.h new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
1.9.1