MIPS: Loongson1B: Fixes and updates
cover MIPS: Loongson1B: Fixes and updates
These patches are mainly fixes/updates for Loongson1B, and moreover, add cpufreq support.
Kelvin Cheung (6):
MIPS: Loongson1B: Fix reboot problem on LS1B
MIPS: Loongson1B: Improve early printk
MIPS: Loongson1B: Some fixes/updates for LS1B
MIPS: Loongson1B: Add a clockevent/clocksource using PWM Timer
clk: ls1x: Update relationship among all clocks
cpufreq: Loongson1: Add cpufreq driver for Loongson1B
arch/mips/Kconfig | 1 + arch/mips/include/asm/mach-loongson1/cpufreq.h | 23 +++ arch/mips/include/asm/mach-loongson1/loongson1.h | 8 +- arch/mips/include/asm/mach-loongson1/platform.h | 10 +- arch/mips/include/asm/mach-loongson1/regs-clk.h | 23 ++- arch/mips/include/asm/mach-loongson1/regs-mux.h | 67 +++++++ arch/mips/include/asm/mach-loongson1/regs-pwm.h | 29 +++ arch/mips/include/asm/mach-loongson1/regs-wdt.h | 11 +- arch/mips/loongson1/Kconfig | 42 ++++- arch/mips/loongson1/common/Makefile | 2 +- arch/mips/loongson1/common/clock.c | 28 --- arch/mips/loongson1/common/platform.c | 141 ++++++++++++-- arch/mips/loongson1/common/prom.c | 30 ++- arch/mips/loongson1/common/reset.c | 20 +- arch/mips/loongson1/common/time.c | 226 +++++++++++++++++++++++ arch/mips/loongson1/ls1b/board.c | 12 +- drivers/clk/clk-ls1x.c | 109 ++++++++--- drivers/cpufreq/Kconfig | 10 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/ls1x-cpufreq.c | 217 ++++++++++++++++++++++ 20 files changed, 889 insertions(+), 121 deletions(-) create mode 100644 arch/mips/include/asm/mach-loongson1/cpufreq.h create mode 100644 arch/mips/include/asm/mach-loongson1/regs-mux.h create mode 100644 arch/mips/include/asm/mach-loongson1/regs-pwm.h delete mode 100644 arch/mips/loongson1/common/clock.c create mode 100644 arch/mips/loongson1/common/time.c create mode 100644 drivers/cpufreq/ls1x-cpufreq.c
Signature · 1 line
1.9.1
PATCH 1/6 MIPS: Loongson1B: Fix reboot problem on LS1B
- Correct the header file of watchdog registers
- Use ioremap_nocache() to access watchdog registers instead
--- arch/mips/include/asm/mach-loongson1/regs-wdt.h | 11 ++++------- arch/mips/loongson1/common/reset.c | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-)
arch/mips/include/asm/mach-loongson1/regs-wdt.h +4 -7
@@ -1,7 +1,7 @@/* * Copyright (c) 2011 Zhang, Keguang <[email protected]> * -* Loongson 1 watchdog register definitions. +* Loongson 1 Watchdog Register Definitions. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the
@@ -12,11 +12,8 @@#ifndef __ASM_MACH_LOONGSON1_REGS_WDT_H#define __ASM_MACH_LOONGSON1_REGS_WDT_H -#define LS1X_WDT_REG (x) \ - ((void __iomem *)KSEG1ADDR(LS1X_WDT_BASE + (x))) - -#define LS1X_WDT_EN LS1X_WDT_REG(0x0) -#define LS1X_WDT_SET LS1X_WDT_REG(0x4) -#define LS1X_WDT_TIMER LS1X_WDT_REG(0x8) +#define WDT_EN 0x0 +#define WDT_TIMER 0x4 +#define WDT_SET 0x8#endif /* __ASM_MACH_LOONGSON1_REGS_WDT_H */
arch/mips/loongson1/common/reset.c +14 -6
@@ -14,12 +14,7 @@#include <loongson1.h> -static void ls1x_restart (char *command) -{ -__raw_writel (0x1 ,LS1X_WDT_EN ); -__raw_writel (0x5000000 ,LS1X_WDT_TIMER ); -__raw_writel (0x1 ,LS1X_WDT_SET ); -} +static void __iomem *wdt_base;static void ls1x_halt (void ) {
@@ -29,6 +24,15 @@ static void ls1x_halt(void) } } +static void ls1x_restart (char *command) +{ +__raw_writel (0x1 , wdt_base +WDT_EN ); +__raw_writel (0x1 , wdt_base +WDT_TIMER ); +__raw_writel (0x1 , wdt_base +WDT_SET ); + +ls1x_halt (); +} +static void ls1x_power_off (void ) {ls1x_halt ();
@@ -36,6 +40,10 @@ static void ls1x_power_off(void)static int __init ls1x_reboot_setup (void ) { + wdt_base =ioremap_nocache (LS1X_WDT_BASE ,0x0f ); +if (!wdt_base) +panic ("Failed to remap watchdog registers" ); + _machine_restart = ls1x_restart; _machine_halt = ls1x_halt; pm_power_off = ls1x_power_off;
Signature · 1 line
1.9.1
PATCH 2/6 MIPS: Loongson1B: Improve early printk
In reply to Kelvin Cheung - Determine serial port for early printk according to kernel command line.
- Move to 8250/16550 serial early printk driver.
--- arch/mips/loongson1/Kconfig | 1 + arch/mips/loongson1/common/prom.c | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-)
arch/mips/loongson1/Kconfig +1 -0
@@ -16,6 +16,7 @@ config LOONGSON1_LS1B select SYS_SUPPORTS_HIGHMEM select SYS_SUPPORTS_MIPS16 select SYS_HAS_EARLY_PRINTK + select USE_GENERIC_EARLY_PRINTK_8250 select COMMON_CLK endchoice
arch/mips/loongson1/common/prom.c +13 -17
@@ -27,7 +27,7 @@ char *prom_getenv(char *envname) i =strlen (envname);while (*env) { -if (strncmp (envname, *env, i) ==0 && *(*env+i) =='=' ) +if (strncmp (envname, *env, i) ==0 && *(*env + i) =='=' )return *env + i +1 ; env++; }
@@ -49,7 +49,7 @@ void __init prom_init_cmdline(void)for (i =1 ; i < prom_argc; i++) {strcpy (c, prom_argv[i]); c +=strlen (prom_argv[i]); -if (i < prom_argc-1 ) +if (i < prom_argc -1 ) *c++ =' ' ; } *c =0 ;
@@ -57,6 +57,7 @@ void __init prom_init_cmdline(void)void __init prom_init (void ) { +void __iomem *uart_base; prom_argc = fw_arg0; prom_argv = (char **)fw_arg1; prom_envp = (char **)fw_arg2;
@@ -65,23 +66,18 @@ void __init prom_init(void) memsize =env_or_default ("memsize" ,DEFAULT_MEMSIZE ); highmemsize =env_or_default ("highmemsize" ,0x0 ); -} -void __init prom_free_prom_memory (void ) -{ +if (strstr (arcs_cmdline,"console=ttyS3" )) + uart_base =ioremap_nocache (LS1X_UART3_BASE ,0x0f ); +else if (strstr (arcs_cmdline,"console=ttyS2" )) + uart_base =ioremap_nocache (LS1X_UART2_BASE ,0x0f ); +else if (strstr (arcs_cmdline,"console=ttyS1" )) + uart_base =ioremap_nocache (LS1X_UART1_BASE ,0x0f ); +else + uart_base =ioremap_nocache (LS1X_UART0_BASE ,0x0f ); +setup_8250_early_printk_port ((unsigned long )uart_base,0 ,0 ); } -#define PORT (offset) (u8 *)(KSEG1ADDR(LS1X_UART0_BASE + offset)) - -void prom_putchar (char c) +void __init prom_free_prom_memory (void ) { -int timeout; - - timeout =1024 ; - -while (((readb (PORT (UART_LSR )) &UART_LSR_THRE ) ==0 ) - && (timeout-- >0 )) - ; - -writeb (c,PORT (UART_TX )); }
Signature · 1 line
1.9.1
PATCH 3/6 MIPS: Loongson1B: Some fixes/updates for LS1B
In reply to Kelvin Cheung - Fix hanging ethernet issue of LS1B v2.0 by adding pbl field in plat data. (It seems that the MAC controller of LS1B v2.0 can only accept pbl=1)
- Add GMAC1 support and setup MUX in terms of PHY mode.
- Add CPUFreq support.
- Add MUX Register Definitions.
- Add PWM Register Definitions.
- Update clock register bitfields according to the latest spec.
- Update clock related stuff.
--- arch/mips/Kconfig | 1 + arch/mips/include/asm/mach-loongson1/cpufreq.h | 23 ++++ arch/mips/include/asm/mach-loongson1/loongson1.h | 8 +- arch/mips/include/asm/mach-loongson1/platform.h | 10 +- arch/mips/include/asm/mach-loongson1/regs-clk.h | 23 +++- arch/mips/include/asm/mach-loongson1/regs-mux.h | 67 +++++++++++ arch/mips/include/asm/mach-loongson1/regs-pwm.h | 29 +++++ arch/mips/loongson1/common/platform.c | 141 ++++++++++++++++++++--- arch/mips/loongson1/ls1b/board.c | 12 +- 9 files changed, 283 insertions(+), 31 deletions(-) create mode 100644 arch/mips/include/asm/mach-loongson1/cpufreq.h create mode 100644 arch/mips/include/asm/mach-loongson1/regs-mux.h create mode 100644 arch/mips/include/asm/mach-loongson1/regs-pwm.h
arch/mips/Kconfig +1 -0
@@ -1574,6 +1574,7 @@ config CPU_LOONGSON1 select CPU_HAS_PREFETCH select CPU_SUPPORTS_32BIT_KERNEL select CPU_SUPPORTS_HIGHMEM + select CPU_SUPPORTS_CPUFREQ config CPU_BMIPS32_3300 select SMP_UP if SMP
arch/mips/include/asm/mach-loongson1/cpufreq.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright (c) 2014 Zhang, Keguang <[email protected]> +* +* Loongson 1 CPUFreq platform support. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + + +#ifndef __ASM_MACH_LOONGSON1_CPUFREQ_H +#define __ASM_MACH_LOONGSON1_CPUFREQ_H + +struct plat_ls1x_cpufreq { +const char *clk_name;/* CPU clk */ +const char *osc_clk_name;/* OSC clk */ +unsigned int max_freq;/* in kHz */ +unsigned int min_freq;/* in kHz */ +}; + +#endif /* __ASM_MACH_LOONGSON1_CPUFREQ_H */
arch/mips/include/asm/mach-loongson1/loongson1.h +7 -1
@@ -16,6 +16,7 @@#define DEFAULT_MEMSIZE 256/* If no memsize provided */ /* Loongson 1 Register Bases */ +#define LS1X_MUX_BASE 0x1fd00420#define LS1X_INTC_BASE 0x1fd01040#define LS1X_EHCI_BASE 0x1fe00000#define LS1X_OHCI_BASE 0x1fe08000
@@ -31,7 +32,10 @@#define LS1X_I2C0_BASE 0x1fe58000#define LS1X_I2C1_BASE 0x1fe68000#define LS1X_I2C2_BASE 0x1fe70000 -#define LS1X_PWM_BASE 0x1fe5c000 +#define LS1X_PWM0_BASE 0x1fe5c000 +#define LS1X_PWM1_BASE 0x1fe5c010 +#define LS1X_PWM2_BASE 0x1fe5c020 +#define LS1X_PWM3_BASE 0x1fe5c030#define LS1X_WDT_BASE 0x1fe5c060#define LS1X_RTC_BASE 0x1fe64000#define LS1X_AC97_BASE 0x1fe74000
@@ -39,6 +43,8 @@#define LS1X_CLK_BASE 0x1fe78030#include <regs-clk.h> +#include <regs-mux.h> +#include <regs-pwm.h> #include <regs-wdt.h> #endif /* __ASM_MACH_LOONGSON1_LOONGSON1_H */
arch/mips/include/asm/mach-loongson1/platform.h +6 -4
@@ -13,10 +13,12 @@#include <linux/platform_device.h> -extern struct platform_device ls1x_uart_device; -extern struct platform_device ls1x_eth0_device; -extern struct platform_device ls1x_ehci_device; -extern struct platform_device ls1x_rtc_device; +extern struct platform_device ls1x_uart_pdev; +extern struct platform_device ls1x_cpufreq_pdev; +extern struct platform_device ls1x_eth0_pdev; +extern struct platform_device ls1x_eth1_pdev; +extern struct platform_device ls1x_ehci_pdev; +extern struct platform_device ls1x_rtc_pdev;extern void __init ls1x_clk_init (void );extern void __init ls1x_serial_setup (struct platform_device *pdev);
arch/mips/include/asm/mach-loongson1/regs-clk.h +20 -3
@@ -20,15 +20,32 @@/* Clock PLL Divisor Register Bits */ #define DIV_DC_EN (0x1 << 31) +#define DIV_DC_RST (0x1 << 30)#define DIV_CPU_EN (0x1 << 25) +#define DIV_CPU_RST (0x1 << 24)#define DIV_DDR_EN (0x1 << 19) +#define DIV_DDR_RST (0x1 << 18) +#define RST_DC_EN (0x1 << 5) +#define RST_DC (0x1 << 4) +#define RST_DDR_EN (0x1 << 3) +#define RST_DDR (0x1 << 2) +#define RST_CPU_EN (0x1 << 1) +#define RST_CPU 0x1#define DIV_DC_SHIFT 26#define DIV_CPU_SHIFT 20#define DIV_DDR_SHIFT 14 -#define DIV_DC_WIDTH 5 -#define DIV_CPU_WIDTH 5 -#define DIV_DDR_WIDTH 5 +#define DIV_DC_WIDTH 4 +#define DIV_CPU_WIDTH 4 +#define DIV_DDR_WIDTH 4 + +#define BYPASS_DC_SHIFT 12 +#define BYPASS_DDR_SHIFT 10 +#define BYPASS_CPU_SHIFT 8 + +#define BYPASS_DC_WIDTH 1 +#define BYPASS_DDR_WIDTH 1 +#define BYPASS_CPU_WIDTH 1#endif /* __ASM_MACH_LOONGSON1_REGS_CLK_H */
arch/mips/include/asm/mach-loongson1/regs-mux.h new file +67 -0
67 lines not on this page · raw message
arch/mips/include/asm/mach-loongson1/regs-pwm.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014 Zhang, Keguang <[email protected]> +* +* Loongson 1 PWM Register Definitions. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +*/ + +#ifndef __ASM_MACH_LOONGSON1_REGS_PWM_H +#define __ASM_MACH_LOONGSON1_REGS_PWM_H + +/* Loongson 1 PWM Timer Register Definitions */ +#define PWM_CNT 0x0 +#define PWM_HRC 0x4 +#define PWM_LRC 0x8 +#define PWM_CTRL 0xc + +/* PWM Control Register Bits */ +#define CNT_RST (0x1 << 7) +#define INT_SR (0x1 << 6) +#define INT_EN (0x1 << 5) +#define PWM_SINGLE (0x1 << 4) +#define PWM_OE (0x1 << 3) +#define CNT_EN 0x1 + +#endif /* __ASM_MACH_LOONGSON1_REGS_PWM_H */
arch/mips/loongson1/common/platform.c +123 -18
204 lines not on this page · raw message
arch/mips/loongson1/ls1b/board.c +7 -5
@@ -10,17 +10,19 @@#include <platform.h> static struct platform_device *ls1b_platform_devices[]__initdata = { - &ls1x_uart_device, - &ls1x_eth0_device, - &ls1x_ehci_device, - &ls1x_rtc_device, + &ls1x_uart_pdev, + &ls1x_cpufreq_pdev, + &ls1x_eth0_pdev, + &ls1x_eth1_pdev, + &ls1x_ehci_pdev, + &ls1x_rtc_pdev, };static int __init ls1b_platform_init (void ) {int err; -ls1x_serial_setup (&ls1x_uart_device); +ls1x_serial_setup (&ls1x_uart_pdev); err =platform_add_devices (ls1b_platform_devices,ARRAY_SIZE (ls1b_platform_devices));
Signature · 1 line
1.9.1
PATCH 4/6 MIPS: Loongson1B: Add a clockevent/clocksource using PWM Timer
In reply to Kelvin CheungThis patch add a clockevent/clocksource using PWM Timer for Loongson1B, which is based on earlier work by Tang, Haifeng.
--- arch/mips/loongson1/Kconfig | 41 ++++++- arch/mips/loongson1/common/Makefile | 2 +- arch/mips/loongson1/common/clock.c | 28 ----- arch/mips/loongson1/common/time.c | 226 ++++++++++++++++++++++++++++++++++++ 4 files changed, 266 insertions(+), 31 deletions(-) delete mode 100644 arch/mips/loongson1/common/clock.c create mode 100644 arch/mips/loongson1/common/time.c
arch/mips/loongson1/Kconfig +39 -2
@@ -5,8 +5,8 @@ choice config LOONGSON1_LS1B bool "Loongson LS1B board" - select CEVT_R4K - select CSRC_R4K + select CEVT_R4K if !MIPS_EXTERNAL_TIMER + select CSRC_R4K if !MIPS_EXTERNAL_TIMER select SYS_HAS_CPU_LOONGSON1B select DMA_NONCOHERENT select BOOT_ELF32
@@ -21,4 +21,41 @@ config LOONGSON1_LS1B endchoice +menuconfig CEVT_CSRC_LS1X + bool "Use PWM Timer for clockevent/clocksource" + select MIPS_EXTERNAL_TIMER + depends on CPU_LOONGSON1 + help + This option changes the default clockevent/clocksource to PWM Timer, + and is required by Loongson1 CPUFreq support. + + If unsure, say N. + +choice + prompt "Select clockevent/clocksource" + depends on CEVT_CSRC_LS1X + default TIMER_USE_PWM0 + +config TIMER_USE_PWM0 + bool "Use PWM Timer 0" + help + Use PWM Timer 0 as the default clockevent/clocksourcer. + +config TIMER_USE_PWM1 + bool "Use PWM Timer 1" + help + Use PWM Timer 1 as the default clockevent/clocksourcer. + +config TIMER_USE_PWM2 + bool "Use PWM Timer 2" + help + Use PWM Timer 2 as the default clockevent/clocksourcer. + +config TIMER_USE_PWM3 + bool "Use PWM Timer 3" + help + Use PWM Timer 3 as the default clockevent/clocksourcer. + +endchoice + endif # MACH_LOONGSON1
arch/mips/loongson1/common/Makefile +1 -1
@@ -2,4 +2,4 @@ # Makefile for common code of loongson1 based machines. # -obj-y += clock.o irq.o platform.o prom.o reset.o setup.o +obj-y += time.o irq.o platform.o prom.o reset.o setup.o
arch/mips/loongson1/common/clock.c deleted +0 -28
@@ -1,28 +0,0 @@ -/* -* Copyright (c) 2011 Zhang, Keguang <[email protected]> -* -* This program is free software; you can redistribute it and/or modify it -* under the terms of the GNU General Public License as published by the -* Free Software Foundation; either version 2 of the License, or (at your -* option) any later version. -*/ - -#include <linux/clk.h> -#include <linux/err.h> -#include <asm/time.h> -#include <platform.h> - -void __init plat_time_init (void ) -{ -struct clk *clk; - -/* Initialize LS1X clocks */ -ls1x_clk_init (); - -/* setup mips r4k timer */ - clk =clk_get (NULL ,"cpu" ); -if (IS_ERR (clk)) -panic ("unable to get cpu clock, err=%ld" ,PTR_ERR (clk)); - - mips_hpt_frequency =clk_get_rate (clk) /2 ; -}
arch/mips/loongson1/common/time.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
1.9.1