mips: add base support for QCA/Atheros ath79 SOCs
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v6 3/10 mips: ath79: add support for AR933x SOCs
In reply to a message not in the archiveThis 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
@@ -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
@@ -5,3 +5,5 @@ obj-y += reset.o obj-y += cpu.o obj-y += dram.o + +obj-$(CONFIG_SOC_AR933X) += ar933x/
arch/mips/mach-ath79/ar933x/Makefile new file +7 -0
@@ -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
PATCH v6 4/10 mips: ath79: add support for QCA953x SOCs
In reply to a message not in the archiveThis 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
@@ -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
@@ -6,4 +6,5 @@ obj-y += reset.o obj-y += cpu.o obj-y += dram.o -obj-$(CONFIG_SOC_AR933X) += ar933x/ +obj-$(CONFIG_SOC_AR933X) += ar933x/ +obj-$(CONFIG_SOC_QCA953X) += qca953x/
arch/mips/mach-ath79/qca953x/Makefile new file +7 -0
@@ -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
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
@@ -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
@@ -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
@@ -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
PATCH v6 5/10 mips: ath79: add serial driver for ar933x SOC
Hi Wills,
Quoted 246 lines · Wills Wang
Signed-off-by Wills Wang <[email protected]>---
Changes in v6:
- Remove wait loop in putc and getc
- Usemap_physmeminstead of KSEG1ADDRChanges in v5:
- removear933x_serial_platdata
- Import document "qca,ar9330-uart.txt" from kernel
- Add support for debug UARTChanges in v4:
- Auto calculate baudrate for serial driver
- Move pinctrl code in serial driver intoarch/mips/mach-ath79
- Useget_serial_clockto serial clock sourceChanges in v3:
- Convert serial driver to driver model
- Same code style convertionChanges in v2:
- Move serial driver code intodrivers/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.txtcreate mode 100644drivers/serial/serial_ar933x.cdoc/device-tree-bindings/serial/qca,ar9330-uart.txt new file +24
-0@@ -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@@ -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" helpdrivers/serial/Makefile +1
-0@@ -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.odrivers/serial/serial_ar933x.c new file +131
-0@@ -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
PATCH v6 6/10 ns16550: add support for mips
In reply to a message not in the archiveMIPS 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
@@ -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
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 defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
As Marek might have suggested, you should consider add these macro first.
Best regards,
Thomas
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 defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
As Marek might have suggested, you should consider add these macro first.
I think Marek's suggestions are being ignored :-)
Best regards,
Marek Vasut
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 defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
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
PATCH v6 6/10 ns16550: add support for mips
In reply to Wills WangAm 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 defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/serial/ns16550.c +8
-4@@ -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
-4writeb (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
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 defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/serial/ns16550.c +8
-4@@ -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); #elsedrivers/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); #elseCould 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_SPACEin your SoCKconfigcode. 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 forCONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch without_be32makes no sense. All IO accessors must convert from CPU endianess to NS16550's Little Endian, butout_be32converts 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
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 defineCONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/serial/ns16550.c +8
-4@@ -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)
{
#ifdefCONFIG_SYS_NS16550_PORT_MAPPED
return inb((ulong)addr);
-#elifdefined(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_SPACEin your SoCKconfigcode. 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 forCONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch without_be32makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, butout_be32converts 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.
ButCONFIG_SWAP_IO_SPACEdon'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 voidserial_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
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 defineCONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/serial/ns16550.c +8
-4@@ -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_SPACEin your SoCKconfigcode. 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 forCONFIG_SYS_NS16550_MEM32. Also if the NS16550 is Little Endian, the branch without_be32makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, butout_be32converts 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.
ButCONFIG_SWAP_IO_SPACEdon'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 voidserial_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
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 defineCONFIG_SYS_BIG_ENDIAN, this patch use readl/writel
for register operation in mips when defineCONFIG_SYS_NS16550_MEM32.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)drivers/serial/ns16550.c +8
-4@@ -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_SPACEin your SoCKconfigcode. 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 forCONFIG_SYS_NS16550_MEM32.
Also if the NS16550 is Little Endian, the branch without_be32makes no
sense. All IO accessors must convert from CPU endianess to NS16550's
Little Endian, butout_be32converts 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.
ButCONFIG_SWAP_IO_SPACEdon'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 voidserial_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_ENDIANandCONFIG_SYS_LITTLE_ENDIANare 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
PATCH v6 7/10 ns16550: map register base address for debug UART
In reply to a message not in the archiveMIPS 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
@@ -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
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_physmemto convertCONFIG_DEBUG_UART_BASEfor debug UART.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/serial/ns16550.c +2
-1@@ -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
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_physmemto convertCONFIG_DEBUG_UART_BASEfor debug UART.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/serial/ns16550.c +2
-1@@ -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_BASEhere 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
Naked-by Thomas Chou <[email protected]>Best regards,
Thomas
Signature · 2 lines
Best Regards Wills
PATCH v6 7/10 ns16550: map register base address for debug UART
In reply to Thomas Chou2016-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_physmemto convertCONFIG_DEBUG_UART_BASEfor debug UART.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/serial/ns16550.c +2
-1@@ -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_BASEhere 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.
Naked-by Thomas Chou <[email protected]>
I agree with Thomas. Please set CONFIG_DEBUG_UART_BASE to a KSEG1 address and discard this patch.
Signature · 1 line
- Daniel
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_physmemto convertCONFIG_DEBUG_UART_BASEfor debug UART.Signed-off-by Wills Wang <[email protected]>---
Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: Nonedrivers/serial/ns16550.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/serial/ns16550.c +2
-1@@ -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_BASEhere 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.
Naked-by Thomas Chou <[email protected]>I agree with Thomas. Please set
CONFIG_DEBUG_UART_BASEto a KSEG1 address and discard this patch.
Ok.
I will correct this in the next patch.
Signature · 2 lines
Best Regards Wills
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
@@ -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
@@ -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
@@ -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
PATCH v6 8/10 mips: ath79: add spi driver
Hi Wills,
Quoted 314 lines · Wills Wang
Signed-off-by Wills Wang <[email protected]>---
Changes in v6:
- Addrrw_delayinath79_spi_privfor more accurate timing
- Removeath79_spi_delay
- Calculate delay inath79_spi_set_speedChanges in v5:
- removear933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operationChanges in v4:
- Useget_bus_freqinstead of hardcode in SPI driverChanges in v3:
- Convert spi driver to driver model
- Same code style convertionChanges in v2:
- Add a compatible spi driverdoc/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.txtcreate mode 100644drivers/spi/ath79_spi.cdoc/device-tree-bindings/spi/spi-ath79.txt new file +19
-0@@ -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@@ -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" helpdrivers/spi/Makefile +1
-0@@ -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.odrivers/spi/ath79_spi.c new file +220
-0@@ -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
PATCH v6 8/10 mips: ath79: add spi driver
In reply to Wills WangQuoted 93 lines · Wills Wang
Signed-off-by Wills Wang <[email protected]>---
Changes in v6:
- Addrrw_delayinath79_spi_privfor more accurate timing
- Removeath79_spi_delay
- Calculate delay inath79_spi_set_speedChanges in v5:
- removear933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operationChanges in v4:
- Useget_bus_freqinstead of hardcode in SPI driverChanges in v3:
- Convert spi driver to driver model
- Same code style convertionChanges in v2:
- Add a compatible spi driverdoc/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.cdoc/device-tree-bindings/spi/spi-ath79.txt new file +19
-0@@ -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@@ -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" helpdrivers/spi/Makefile +1
-0@@ -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.odrivers/spi/ath79_spi.c new file +0
-0
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.
PATCH v6 8/10 mips: ath79: add spi driver
Quoted 82 lines · Jagan Teki
Quoted 81 lines · Wills Wang
Signed-off-by Wills Wang <[email protected]>---
Changes in v6:
- Addrrw_delayinath79_spi_privfor more accurate timing
- Removeath79_spi_delay
- Calculate delay inath79_spi_set_speedChanges in v5:
- removear933x_spi_platdata
- Import document "spi-ath79.txt" from kernel
- Add delay for bitbang operationChanges in v4:
- Useget_bus_freqinstead of hardcode in SPI driverChanges in v3:
- Convert spi driver to driver model
- Same code style convertionChanges in v2:
- Add a compatible spi driverdoc/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.txtcreate mode 100644drivers/spi/ath79_spi.cdoc/device-tree-bindings/spi/spi-ath79.txt new file +19
-0@@ -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@@ -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" helpdrivers/spi/Makefile +0
-0@@ -17,6 +17,7 @@ endif
Quoted 16 lines
Quoted 12 lines
drivers/spi/Makefile +1
-0obj-$(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.odrivers/spi/ath79_spi.c new file +0
-0drivers/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_MHZor 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_activateand useclrbits_xxxorsetbits_xxxxif 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_deactivateQuoted 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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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