Skip to contentSkip to conversation

MIPS: Alchemy: common clk framework integration

RFC PATCH Superseded Manuel Lauss 2 participants 5 messages Jun 29, 2014 – Jul 2, 2014

Subsystems (11)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Manuel Lauss

author maintainer
#0 lore raw

cover MIPS: Alchemy: common clk framework integration

This is a request for comments for the below patches.

Patch 1 is a cleanup I came up with while writing patch 2. I'm sending
it along because the other one depends on some things introduced in it to compile cleanly.

Patch 2 adds COMMON_CLK support for all configurable internal
clock sources on alchemy socs.

Please have a look!

Thanks a lot,
Manuel Lauss

Manuel Lauss (2):
MIPS: Alchemy: au1000 header file cleanup
MIPS: Alchemy: common clock framework integration

 arch/mips/Kconfig                               |    1 +
 arch/mips/alchemy/board-mtx1.c                  |    4 +-
 arch/mips/alchemy/board-xxs1500.c               |    4 +-
 arch/mips/alchemy/common/Makefile               |    2 +-
 arch/mips/alchemy/common/clock.c                | 1113 ++++++++++
 arch/mips/alchemy/common/clocks.c               |  105 -
 arch/mips/alchemy/common/dbdma.c                |   22 +-
 arch/mips/alchemy/common/dma.c                  |   15 +-
 arch/mips/alchemy/common/irq.c                  |    4 +-
 arch/mips/alchemy/common/platform.c             |   12 +-
 arch/mips/alchemy/common/power.c                |   88 +-
 arch/mips/alchemy/common/setup.c                |   21 +-
 arch/mips/alchemy/common/time.c                 |   25 +-
 arch/mips/alchemy/common/usb.c                  |   10 +
 arch/mips/alchemy/devboards/db1000.c            |   19 +-
 arch/mips/alchemy/devboards/db1200.c            |   73 +-
 arch/mips/alchemy/devboards/db1300.c            |   10 +-
 arch/mips/alchemy/devboards/db1550.c            |   25 +-
 arch/mips/alchemy/devboards/pm.c                |   39 +-
 arch/mips/include/asm/mach-au1x00/au1000.h      | 2514 ++++++++++-------------
 arch/mips/include/asm/mach-au1x00/au1000_dma.h  |   51 +-
 arch/mips/include/asm/mach-au1x00/gpio-au1000.h |   66 +-
 arch/mips/pci/pci-alchemy.c                     |   85 +-
 drivers/mmc/host/au1xmmc.c                      |  194 +-
 drivers/mtd/nand/au1550nd.c                     |   52 +-
 drivers/net/ethernet/amd/au1000_eth.c           |  155 +-
 drivers/net/irda/au1k_ir.c                      |   48 +-
 drivers/rtc/rtc-au1xxx.c                        |   18 +-
 drivers/spi/spi-au1550.c                        |   66 +-
 drivers/video/fbdev/au1100fb.c                  |   19 +-
 drivers/video/fbdev/au1200fb.c                  |   34 +-
 sound/soc/au1x/psc-ac97.c                       |  140 +-
 sound/soc/au1x/psc-i2s.c                        |  100 +-
 sound/soc/au1x/psc.h                            |   22 +-
 34 files changed, 3017 insertions(+), 2139 deletions(-)
 create mode 100644 arch/mips/alchemy/common/clock.c
 delete mode 100644 arch/mips/alchemy/common/clocks.c
Signature · 1 line
2.0.0
author maintainer
#1 lore raw

PATCH 1/2 MIPS: Alchemy: au1000 header file cleanup

- remove the custom au_read/write{bwl} accessors as well as au_sync, and replace them with __raw_readl/writel/wmb in all users.
- changes absolute register addresses to offsets from their base:
- rename the SYS_xxx definitions to AU1000_SYS_ so people know that addresses have changed.
- add helpers to read/write SYS registers, and use them.
- removes unused register/bit definitions (unused hw blocks, ...)
- moves ethernet register/bit descriptions to au1000_eth driver. It's not used there either, but I didn't want to lose it.

No functional changes.

Tested on DB1300 and DB1500.

---
 arch/mips/alchemy/board-mtx1.c                  |    4 +-
 arch/mips/alchemy/board-xxs1500.c               |    4 +-
 arch/mips/alchemy/common/clocks.c               |    7 +-
 arch/mips/alchemy/common/dbdma.c                |   22 +-
 arch/mips/alchemy/common/dma.c                  |   15 +-
 arch/mips/alchemy/common/irq.c                  |    4 +-
 arch/mips/alchemy/common/platform.c             |    2 +-
 arch/mips/alchemy/common/power.c                |   88 +-
 arch/mips/alchemy/common/setup.c                |    3 +-
 arch/mips/alchemy/common/time.c                 |   25 +-
 arch/mips/alchemy/devboards/db1000.c            |    5 +-
 arch/mips/alchemy/devboards/db1200.c            |   29 +-
 arch/mips/alchemy/devboards/db1300.c            |   10 +-
 arch/mips/alchemy/devboards/db1550.c            |   25 +-
 arch/mips/alchemy/devboards/pm.c                |   39 +-
 arch/mips/include/asm/mach-au1x00/au1000.h      | 2571 ++++++++++-------------
 arch/mips/include/asm/mach-au1x00/au1000_dma.h  |   51 +-
 arch/mips/include/asm/mach-au1x00/gpio-au1000.h |   66 +-
 arch/mips/pci/pci-alchemy.c                     |   65 +-
 drivers/mmc/host/au1xmmc.c                      |  168 +-
 drivers/mtd/nand/au1550nd.c                     |   52 +-
 drivers/net/ethernet/amd/au1000_eth.c           |  155 +-
 drivers/rtc/rtc-au1xxx.c                        |   18 +-
 drivers/spi/spi-au1550.c                        |   66 +-
 drivers/video/fbdev/au1100fb.c                  |   15 +-
 drivers/video/fbdev/au1200fb.c                  |   34 +-
 sound/soc/au1x/psc-ac97.c                       |  140 +-
 sound/soc/au1x/psc-i2s.c                        |  100 +-
 sound/soc/au1x/psc.h                            |   22 +-
 29 files changed, 1826 insertions(+), 1979 deletions(-)
arch/mips/alchemy/board-mtx1.c +2 -2
index 25a59a2..962cefa 100644
@@ -85,10 +85,10 @@ void __init board_setup(void)
 #endif /* IS_ENABLED(CONFIG_USB_OHCI_HCD) */
 
 	/* Initialize sys_pinfunc */
-	au_writel(SYS_PF_NI2, SYS_PINFUNC);
+	AU1X_WRSYS(SYS_PF_NI2, AU1000_SYS_PINFUNC);
 
 	/* Initialize GPIO */
-	au_writel(~0, KSEG1ADDR(AU1000_SYS_PHYS_ADDR) + SYS_TRIOUTCLR);
+	AU1X_WRSYS(~0, AU1000_SYS_TRIOUTCLR);
 	alchemy_gpio_direction_output(0, 0);	/* Disable M66EN (PCI 66MHz) */
 	alchemy_gpio_direction_output(3, 1);	/* Disable PCI CLKRUN# */
 	alchemy_gpio_direction_output(1, 1);	/* Enable EXT_IO3 */
arch/mips/alchemy/board-xxs1500.c +2 -2
index 3fb814b..b4cd364 100644
@@ -87,9 +87,9 @@ void __init board_setup(void)
 	alchemy_gpio2_enable();
 
 	/* Set multiple use pins (UART3/GPIO) to UART (it's used as UART too) */
-	pin_func  = au_readl(SYS_PINFUNC) & ~SYS_PF_UR3;
+	pin_func  = AU1X_RDSYS(AU1000_SYS_PINFUNC) & ~SYS_PF_UR3;
 	pin_func |= SYS_PF_UR3;
-	au_writel(pin_func, SYS_PINFUNC);
+	AU1X_WRSYS(pin_func, AU1000_SYS_PINFUNC);
 
 	/* Enable UART */
 	alchemy_uart_enable(AU1000_UART3_PHYS_ADDR);
arch/mips/alchemy/common/clocks.c +4 -3
index f38298a..35db35b 100644
@@ -91,13 +91,14 @@ unsigned long au1xxx_calc_clock(void)
 	if (au1xxx_cpu_has_pll_wo())
 		cpu_speed = 396000000;
 	else
-		cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK;
+		cpu_speed = (AU1X_RDSYS(AU1000_SYS_CPUPLL) & 0x0000003f)
+				* AU1000_SRC_CLK;
 
 	/* On Alchemy CPU:counter ratio is 1:1 */
 	mips_hpt_frequency = cpu_speed;
 	/* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */
-	set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL)
-							  & 0x03) + 2) * 16));
+	set_au1x00_uart_baud_base(cpu_speed /
+		(2 * ((AU1X_RDSYS(AU1000_SYS_POWERCTRL) & 0x03) + 2) * 16));
 
 	set_au1x00_speed(cpu_speed);
 
arch/mips/alchemy/common/dbdma.c +11 -11
index 19d5642..508955e 100644
@@ -341,7 +341,7 @@ u32 au1xxx_dbdma_chan_alloc(u32 srcid, u32 destid,
 			(dtp->dev_flags & DEV_FLAGS_SYNC))
 				i |= DDMA_CFG_SYNC;
 		cp->ddma_cfg = i;
-		au_sync();
+		wmb();
 
 		/*
 		 * Return a non-zero value that can be used to find the channel
@@ -631,7 +631,7 @@ u32 au1xxx_dbdma_put_source(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
 	 */
 	dma_cache_wback_inv((unsigned long)buf, nbytes);
 	dp->dscr_cmd0 |= DSCR_CMD0_V;	/* Let it rip */
-	au_sync();
+	wmb();
 	dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
 	ctp->chan_ptr->ddma_dbell = 0;
 
@@ -693,7 +693,7 @@ u32 au1xxx_dbdma_put_dest(u32 chanid, dma_addr_t buf, int nbytes, u32 flags)
 	 */
 	dma_cache_inv((unsigned long)buf, nbytes);
 	dp->dscr_cmd0 |= DSCR_CMD0_V;	/* Let it rip */
-	au_sync();
+	wmb();
 	dma_cache_wback_inv((unsigned long)dp, sizeof(*dp));
 	ctp->chan_ptr->ddma_dbell = 0;
 
@@ -760,7 +760,7 @@ void au1xxx_dbdma_stop(u32 chanid)
 
 	cp = ctp->chan_ptr;
 	cp->ddma_cfg &= ~DDMA_CFG_EN;	/* Disable channel */
-	au_sync();
+	wmb();
 	while (!(cp->ddma_stat & DDMA_STAT_H)) {
 		udelay(1);
 		halt_timeout++;
@@ -771,7 +771,7 @@ void au1xxx_dbdma_stop(u32 chanid)
 	}
 	/* clear current desc valid and doorbell */
 	cp->ddma_stat |= (DDMA_STAT_DB | DDMA_STAT_V);
-	au_sync();
+	wmb();
 }
 EXPORT_SYMBOL(au1xxx_dbdma_stop);
 
@@ -789,9 +789,9 @@ void au1xxx_dbdma_start(u32 chanid)
 	cp = ctp->chan_ptr;
 	cp->ddma_desptr = virt_to_phys(ctp->cur_ptr);
 	cp->ddma_cfg |= DDMA_CFG_EN;	/* Enable channel */
-	au_sync();
+	wmb();
 	cp->ddma_dbell = 0;
-	au_sync();
+	wmb();
 }
 EXPORT_SYMBOL(au1xxx_dbdma_start);
 
@@ -832,7 +832,7 @@ u32 au1xxx_get_dma_residue(u32 chanid)
 
 	/* This is only valid if the channel is stopped. */
 	rv = cp->ddma_bytecnt;
-	au_sync();
+	wmb();
 
 	return rv;
 }
@@ -868,7 +868,7 @@ static irqreturn_t dbdma_interrupt(int irq, void *dev_id)
 	au1x_dma_chan_t *cp;
 
 	intstat = dbdma_gptr->ddma_intstat;
-	au_sync();
+	wmb();
 	chan_index = __ffs(intstat);
 
 	ctp = chan_tab_ptr[chan_index];
@@ -877,7 +877,7 @@ static irqreturn_t dbdma_interrupt(int irq, void *dev_id)
 
 	/* Reset interrupt. */
 	cp->ddma_irq = 0;
-	au_sync();
+	wmb();
 
 	if (ctp->chan_callback)
 		ctp->chan_callback(irq, ctp->chan_callparam);
@@ -1061,7 +1061,7 @@ static int __init dbdma_setup(unsigned int irq, dbdev_tab_t *idtable)
 	dbdma_gptr->ddma_config = 0;
 	dbdma_gptr->ddma_throttle = 0;
 	dbdma_gptr->ddma_inten = 0xffff;
-	au_sync();
+	wmb();
 
 	ret = request_irq(irq, dbdma_interrupt, 0, "dbdma", (void *)dbdma_gptr);
 	if (ret)
arch/mips/alchemy/common/dma.c +8 -7
index 9b624e2..7d0ffb8 100644
@@ -141,17 +141,17 @@ void dump_au1000_dma_channel(unsigned int dmanr)
 
 	printk(KERN_INFO "Au1000 DMA%d Register Dump:\n", dmanr);
 	printk(KERN_INFO "  mode = 0x%08x\n",
-	       au_readl(chan->io + DMA_MODE_SET));
+	       __raw_readl(chan->io + DMA_MODE_SET));
 	printk(KERN_INFO "  addr = 0x%08x\n",
-	       au_readl(chan->io + DMA_PERIPHERAL_ADDR));
+	       __raw_readl(chan->io + DMA_PERIPHERAL_ADDR));
 	printk(KERN_INFO "  start0 = 0x%08x\n",
-	       au_readl(chan->io + DMA_BUFFER0_START));
+	       __raw_readl(chan->io + DMA_BUFFER0_START));
 	printk(KERN_INFO "  start1 = 0x%08x\n",
-	       au_readl(chan->io + DMA_BUFFER1_START));
+	       __raw_readl(chan->io + DMA_BUFFER1_START));
 	printk(KERN_INFO "  count0 = 0x%08x\n",
-	       au_readl(chan->io + DMA_BUFFER0_COUNT));
+	       __raw_readl(chan->io + DMA_BUFFER0_COUNT));
 	printk(KERN_INFO "  count1 = 0x%08x\n",
-	       au_readl(chan->io + DMA_BUFFER1_COUNT));
+	       __raw_readl(chan->io + DMA_BUFFER1_COUNT));
 }
 
 /*
@@ -204,7 +204,8 @@ int request_au1000_dma(int dev_id, const char *dev_str,
 	}
 
 	/* fill it in */
-	chan->io = KSEG1ADDR(AU1000_DMA_PHYS_ADDR) + i * DMA_CHANNEL_LEN;
+	chan->io = (void __iomem *)(KSEG1ADDR(AU1000_DMA_PHYS_ADDR) +
+				    i * DMA_CHANNEL_LEN);
 	chan->dev_id = dev_id;
 	chan->dev_str = dev_str;
 	chan->fifo_addr = dev->fifo_addr;
arch/mips/alchemy/common/irq.c +2 -2
index 63a7181..f98c211 100644
@@ -389,12 +389,12 @@ static int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
 		return -EINVAL;
 
 	local_irq_save(flags);
-	wakemsk = __raw_readl((void __iomem *)SYS_WAKEMSK);
+	wakemsk = AU1X_RDSYS(AU1000_SYS_WAKEMSK);
 	if (on)
 		wakemsk |= 1 << bit;
 	else
 		wakemsk &= ~(1 << bit);
-	__raw_writel(wakemsk, (void __iomem *)SYS_WAKEMSK);
+	AU1X_WRSYS(wakemsk, AU1000_SYS_WAKEMSK);
 	wmb();
 	local_irq_restore(flags);
 
arch/mips/alchemy/common/platform.c +1 -1
index 9837a13..4cdc8fd 100644
@@ -420,7 +420,7 @@ static void __init alchemy_setup_macs(int ctype)
 		memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);
 
 	/* Register second MAC if enabled in pinfunc */
-	if (!(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2)) {
+	if (!(AU1X_RDSYS(AU1000_SYS_PINFUNC) & SYS_PF_NI2)) {
 		ret = platform_device_register(&au1xxx_eth1_device);
 		if (ret)
 			printk(KERN_INFO "Alchemy: failed to register MAC1\n");
arch/mips/alchemy/common/power.c +50 -38

112 lines not on this page · raw message

arch/mips/alchemy/common/setup.c +1 -2
index 8267e3c..6f8b91d 100644
@@ -34,10 +34,9 @@
 #include <asm/mipsregs.h>
 #include <asm/time.h>
 
-#include <au1000.h>
+#include <asm/mach-au1x00/au1000.h>
 
 extern void __init board_setup(void);
-extern void set_cpuspec(void);
 
 void __init plat_mem_setup(void)
 {
arch/mips/alchemy/common/time.c +11 -14
index 93fa586..4d9c303 100644
@@ -46,7 +46,7 @@
 
 static cycle_t au1x_counter1_read(struct clocksource *cs)
 {
-	return au_readl(SYS_RTCREAD);
+	return AU1X_RDSYS(AU1000_SYS_RTCREAD);
 }
 
 static struct clocksource au1x_counter1_clocksource = {
@@ -60,12 +60,11 @@ static struct clocksource au1x_counter1_clocksource = {
 static int au1x_rtcmatch2_set_next_event(unsigned long delta,
 					 struct clock_event_device *cd)
 {
-	delta += au_readl(SYS_RTCREAD);
+	delta += AU1X_RDSYS(AU1000_SYS_RTCREAD);
 	/* wait for register access */
-	while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M21)
-		;
-	au_writel(delta, SYS_RTCMATCH2);
-	au_sync();
+	while (AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_M21)
+		asm volatile ("nop");
+	AU1X_WRSYS(delta, AU1000_SYS_RTCMATCH2);
 
 	return 0;
 }
@@ -112,31 +111,29 @@ static int __init alchemy_time_init(unsigned int m2int)
 	 * (the 32S bit seems to be stuck set to 1 once a single clock-
 	 * edge is detected, hence the timeouts).
 	 */
-	if (CNTR_OK != (au_readl(SYS_COUNTER_CNTRL) & CNTR_OK))
+	if (CNTR_OK != (AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & CNTR_OK))
 		goto cntr_err;
 
 	/*
 	 * setup counter 1 (RTC) to tick at full speed
 	 */
 	t = 0xffffff;
-	while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_T1S) && --t)
+	while ((AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_T1S) && --t)
 		asm volatile ("nop");
 	if (!t)
 		goto cntr_err;
 
-	au_writel(0, SYS_RTCTRIM);	/* 32.768 kHz */
-	au_sync();
+	AU1X_WRSYS(0, AU1000_SYS_RTCTRIM);	/* 32.768 kHz */
 
 	t = 0xffffff;
-	while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
+	while ((AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
 		asm volatile ("nop");
 	if (!t)
 		goto cntr_err;
-	au_writel(0, SYS_RTCWRITE);
-	au_sync();
+	AU1X_WRSYS(0, AU1000_SYS_RTCWRITE);
 
 	t = 0xffffff;
-	while ((au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C1S) && --t)
+	while ((AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_C1S) && --t)
 		asm volatile ("nop");
 	if (!t)
 		goto cntr_err;
arch/mips/alchemy/devboards/db1000.c +2 -3
index 92dd929..6e55bcc 100644
@@ -518,10 +518,9 @@ int __init db1000_dev_setup(void)
 		gpio_direction_input(20);	/* sd1 cd# */
 
 		/* spi_gpio on SSI0 pins */
-		pfc = __raw_readl((void __iomem *)SYS_PINFUNC);
+		pfc = AU1X_RDSYS(AU1000_SYS_PINFUNC);
 		pfc |= (1 << 0);	/* SSI0 pins as GPIOs */
-		__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
-		wmb();
+		AU1X_WRSYS(pfc, AU1000_SYS_PINFUNC);
 
 		spi_register_board_info(db1100_spi_info,
 					ARRAY_SIZE(db1100_spi_info));
arch/mips/alchemy/devboards/db1200.c +13 -16
index 9e46667..8c71cde 100644
@@ -150,12 +150,11 @@ int __init db1200_board_setup(void)
 		(whoami >> 4) & 0xf, (whoami >> 8) & 0xf, whoami & 0xf);
 
 	/* SMBus/SPI on PSC0, Audio on PSC1 */
-	pfc = __raw_readl((void __iomem *)SYS_PINFUNC);
+	pfc = AU1X_RDSYS(AU1000_SYS_PINFUNC);
 	pfc &= ~(SYS_PINFUNC_P0A | SYS_PINFUNC_P0B);
 	pfc &= ~(SYS_PINFUNC_P1A | SYS_PINFUNC_P1B | SYS_PINFUNC_FS3);
 	pfc |= SYS_PINFUNC_P1C; /* SPI is configured later */
-	__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
-	wmb();
+	AU1X_WRSYS(pfc, AU1000_SYS_PINFUNC);
 
 	/* Clock configurations: PSC0: ~50MHz via Clkgen0, derived from
 	 * CPU clock; all other clock generators off/unused.
@@ -166,16 +165,13 @@ int __init db1200_board_setup(void)
 	div = ((div >> 1) - 1) & 0xff;
 
 	freq0 = div << SYS_FC_FRDIV0_BIT;
-	__raw_writel(freq0, (void __iomem *)SYS_FREQCTRL0);
-	wmb();
+	AU1X_WRSYS(freq0, AU1000_SYS_FREQCTRL0);
 	freq0 |= SYS_FC_FE0;	/* enable F0 */
-	__raw_writel(freq0, (void __iomem *)SYS_FREQCTRL0);
-	wmb();
+	AU1X_WRSYS(freq0, AU1000_SYS_FREQCTRL0);
 
 	/* psc0_intclk comes 1:1 from F0 */
 	clksrc = SYS_CS_MUX_FQ0 << SYS_CS_ME0_BIT;
-	__raw_writel(clksrc, (void __iomem *)SYS_CLKSRC);
-	wmb();
+	AU1X_WRSYS(clksrc, AU1000_SYS_CLKSRC);
 
 	return 0;
 }
@@ -234,12 +230,12 @@ static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 	ioaddr &= 0xffffff00;
 
 	if (ctrl & NAND_CLE) {
-		ioaddr += MEM_STNAND_CMD;
+		ioaddr += AU1000_MEM_STNAND_CMD;
 	} else if (ctrl & NAND_ALE) {
-		ioaddr += MEM_STNAND_ADDR;
+		ioaddr += AU1000_MEM_STNAND_ADDR;
 	} else {
 		/* assume we want to r/w real data  by default */
-		ioaddr += MEM_STNAND_DATA;
+		ioaddr += AU1000_MEM_STNAND_DATA;
 	}
 	this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
 	if (cmd != NAND_CMD_NONE) {
@@ -250,7 +246,9 @@ static void au1200_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 
 static int au1200_nand_device_ready(struct mtd_info *mtd)
 {
-	return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
+	void __iomem *b = (void __iomem *)
+		KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
+	return __raw_readl(b + AU1000_MEM_STSTAT) & 1;
 }
 
 static struct mtd_partition db1200_nand_parts[] = {
@@ -886,7 +884,7 @@ int __init db1200_dev_setup(void)
 	 * As a result, in SPI mode, OTG simply won't work (PSC0 uses
 	 * it as an input pin which is pulled high on the boards).
 	 */
-	pfc = __raw_readl((void __iomem *)SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
+	pfc = AU1X_RDSYS(AU1000_SYS_PINFUNC) & ~SYS_PINFUNC_P0A;
 
 	/* switch off OTG VBUS supply */
 	gpio_request(215, "otg-vbus");
@@ -912,8 +910,7 @@ int __init db1200_dev_setup(void)
 		printk(KERN_INFO " S6.8 ON : PSC0 mode SPI\n");
 		printk(KERN_INFO "   OTG port VBUS supply disabled\n");
 	}
-	__raw_writel(pfc, (void __iomem *)SYS_PINFUNC);
-	wmb();
+	AU1X_WRSYS(pfc, AU1000_SYS_PINFUNC);
 
 	/* Audio: DIP7 selects I2S(0)/AC97(1), but need I2C for I2S!
 	 * so: DIP7=1 || DIP8=0 => AC97, DIP7=0 && DIP8=1 => I2S
arch/mips/alchemy/devboards/db1300.c +6 -4
index f3525ca..a00ff77 100644
@@ -154,12 +154,12 @@ static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 	ioaddr &= 0xffffff00;
 
 	if (ctrl & NAND_CLE) {
-		ioaddr += MEM_STNAND_CMD;
+		ioaddr += AU1000_MEM_STNAND_CMD;
 	} else if (ctrl & NAND_ALE) {
-		ioaddr += MEM_STNAND_ADDR;
+		ioaddr += AU1000_MEM_STNAND_ADDR;
 	} else {
 		/* assume we want to r/w real data  by default */
-		ioaddr += MEM_STNAND_DATA;
+		ioaddr += AU1000_MEM_STNAND_DATA;
 	}
 	this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
 	if (cmd != NAND_CMD_NONE) {
@@ -170,7 +170,9 @@ static void au1300_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 
 static int au1300_nand_device_ready(struct mtd_info *mtd)
 {
-	return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
+	void __iomem *b = (void __iomem *)
+		KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
+	return __raw_readl(b + AU1000_MEM_STSTAT) & 1;
 }
 
 static struct mtd_partition db1300_nand_parts[] = {
arch/mips/alchemy/devboards/db1550.c +15 -10
index bbd8d98..e70708f 100644
@@ -31,16 +31,16 @@
 static void __init db1550_hw_setup(void)
 {
 	void __iomem *base;
+	unsigned long v;
 
 	/* complete SPI setup: link psc0_intclk to a 48MHz source,
 	 * and assign GPIO16 to PSC0_SYNC1 (SPI cs# line) as well as PSC1_SYNC
 	 * for AC97 on PB1550.
 	 */
-	base = (void __iomem *)SYS_CLKSRC;
-	__raw_writel(__raw_readl(base) | 0x000001e0, base);
-	base = (void __iomem *)SYS_PINFUNC;
-	__raw_writel(__raw_readl(base) | 1 | SYS_PF_PSC1_S1, base);
-	wmb();
+	v = AU1X_RDSYS(AU1000_SYS_CLKSRC);
+	AU1X_WRSYS(v | 0x000001e0, AU1000_SYS_CLKSRC);
+	v = AU1X_RDSYS(AU1000_SYS_PINFUNC);
+	AU1X_WRSYS(v | 1 | SYS_PF_PSC1_S1, AU1000_SYS_PINFUNC);
 
 	/* reset the AC97 codec now, the reset time in the psc-ac97 driver
 	 * is apparently too short although it's ridiculous as it is.
@@ -135,12 +135,12 @@ static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 	ioaddr &= 0xffffff00;
 
 	if (ctrl & NAND_CLE) {
-		ioaddr += MEM_STNAND_CMD;
+		ioaddr += AU1000_MEM_STNAND_CMD;
 	} else if (ctrl & NAND_ALE) {
-		ioaddr += MEM_STNAND_ADDR;
+		ioaddr += AU1000_MEM_STNAND_ADDR;
 	} else {
 		/* assume we want to r/w real data  by default */
-		ioaddr += MEM_STNAND_DATA;
+		ioaddr += AU1000_MEM_STNAND_DATA;
 	}
 	this->IO_ADDR_R = this->IO_ADDR_W = (void __iomem *)ioaddr;
 	if (cmd != NAND_CMD_NONE) {
@@ -151,7 +151,9 @@ static void au1550_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
 
 static int au1550_nand_device_ready(struct mtd_info *mtd)
 {
-	return __raw_readl((void __iomem *)MEM_STSTAT) & 1;
+	void __iomem *b = (void __iomem *)
+		KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
+	return __raw_readl(b + AU1000_MEM_STSTAT) & 1;
 }
 
 static struct mtd_partition db1550_nand_parts[] = {
@@ -217,7 +219,10 @@ static struct platform_device pb1550_nand_dev = {
 
 static void __init pb1550_nand_setup(void)
 {
-	int boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) |
+	void __iomem *b = (void __iomem *)
+		(KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR)
+		+ AU1000_MEM_STSTAT);
+	int boot_swapboot = (__raw_readl(b) & (0x7 << 1)) |
 			    ((bcsr_read(BCSR_STATUS) >> 6) & 0x1);
 
 	gpio_direction_input(206);	/* de-assert NAND CS# */
arch/mips/alchemy/devboards/pm.c +15 -24
index 61e90fe..38053472 100644
@@ -45,23 +45,20 @@ static int db1x_pm_enter(suspend_state_t state)
 	alchemy_gpio1_input_enable();
 
 	/* clear and setup wake cause and source */
-	au_writel(0, SYS_WAKEMSK);
-	au_sync();
-	au_writel(0, SYS_WAKESRC);
-	au_sync();
+	AU1X_WRSYS(0, AU1000_SYS_WAKEMSK);
+	AU1X_WRSYS(0, AU1000_SYS_WAKESRC);
 
-	au_writel(db1x_pm_wakemsk, SYS_WAKEMSK);
-	au_sync();
+	AU1X_WRSYS(db1x_pm_wakemsk, AU1000_SYS_WAKEMSK);
 
 	/* setup 1Hz-timer-based wakeup: wait for reg access */
-	while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20)
+	while (AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_M20)
 		asm volatile ("nop");
 
-	au_writel(au_readl(SYS_TOYREAD) + db1x_pm_sleep_secs, SYS_TOYMATCH2);
-	au_sync();
+	db1x_pm_sleep_secs += AU1X_RDSYS(AU1000_SYS_TOYREAD);
+	AU1X_WRSYS(db1x_pm_sleep_secs, AU1000_SYS_TOYMATCH2);
 
 	/* wait for value to really hit the register */
-	while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_M20)
+	while (AU1X_RDSYS(AU1000_SYS_CNTRCTRL) & SYS_CNTRL_M20)
 		asm volatile ("nop");
 
 	/* ...and now the sandman can come! */
@@ -102,12 +99,10 @@ static void db1x_pm_end(void)
 	/* read and store wakeup source, the clear the register. To
 	 * be able to clear it, WAKEMSK must be cleared first.
 	 */
-	db1x_pm_last_wakesrc = au_readl(SYS_WAKESRC);
-
-	au_writel(0, SYS_WAKEMSK);
-	au_writel(0, SYS_WAKESRC);
-	au_sync();
+	db1x_pm_last_wakesrc = AU1X_RDSYS(AU1000_SYS_WAKESRC);
 
+	AU1X_WRSYS(0, AU1000_SYS_WAKEMSK);
+	AU1X_WRSYS(0, AU1000_SYS_WAKESRC);
 }
 
 static const struct platform_suspend_ops db1x_pm_ops = {
@@ -242,17 +237,13 @@ static int __init pm_init(void)
 	 * for confirmation since there's plenty of time from here to
 	 * the next suspend cycle.
 	 */
-	if (au_readl(SYS_TOYTRIM) != 32767) {
-		au_writel(32767, SYS_TOYTRIM);
-		au_sync();
-	}
+	if (AU1X_RDSYS(AU1000_SYS_TOYTRIM) != 32767)
+		AU1X_WRSYS(32767, AU1000_SYS_TOYTRIM);
 
-	db1x_pm_last_wakesrc = au_readl(SYS_WAKESRC);
+	db1x_pm_last_wakesrc = AU1X_RDSYS(AU1000_SYS_WAKESRC);
 
-	au_writel(0, SYS_WAKESRC);
-	au_sync();
-	au_writel(0, SYS_WAKEMSK);
-	au_sync();
+	AU1X_WRSYS(0, AU1000_SYS_WAKESRC);
+	AU1X_WRSYS(0, AU1000_SYS_WAKEMSK);
 
 	suspend_set_ops(&db1x_pm_ops);
 
arch/mips/include/asm/mach-au1x00/au1000.h +1130 -1441

2,403 lines not on this page · raw message

arch/mips/include/asm/mach-au1x00/au1000_dma.h +26 -25

51 lines not on this page · raw message

arch/mips/include/asm/mach-au1x00/gpio-au1000.h +34 -32

66 lines not on this page · raw message

arch/mips/pci/pci-alchemy.c +33 -32

65 lines not on this page · raw message

drivers/mmc/host/au1xmmc.c +86 -82

168 lines not on this page · raw message

drivers/mtd/nand/au1550nd.c +34 -18

52 lines not on this page · raw message

drivers/net/ethernet/amd/au1000_eth.c +143 -12

155 lines not on this page · raw message

drivers/rtc/rtc-au1xxx.c +8 -10
index ed526a1..52f14c9 100644

Lines of this file are not shown. View the raw message.

drivers/spi/spi-au1550.c +33 -33

66 lines not on this page · raw message

drivers/video/fbdev/au1100fb.c +8 -7
index 372d4ae..2c2804b 100644

Lines of this file are not shown. View the raw message.

drivers/video/fbdev/au1200fb.c +17 -17
index 4cfba78..230cfa8 100644

Lines of this file are not shown. View the raw message.

sound/soc/au1x/psc-ac97.c +70 -70

140 lines not on this page · raw message

sound/soc/au1x/psc-i2s.c +50 -50

100 lines not on this page · raw message

sound/soc/au1x/psc.h +11 -11
index b16b2e0..74dffeb 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.0.0

Part of the diff is not shown here. View the raw message.

author maintainer
#2 lore raw

PATCH 2/2 MIPS: Alchemy: common clock framework integration

In reply to Manuel Lauss

Expose chip-internal configurable clocks to the common clk framework, and fix a few drivers to take advantage of it.

The patch takes the frequencies and tree configuration set up by the bootloader and runs with it; all boards should continue to work without modifications. A few clocks for which I haven't yet modified the drivers using them are force-enabled when firmware has left them enabled (the clk framework disables all not yet clk_enable()d ones late during boot). This whitelist will go away eventually.

The set_rate logic in the muxes does not request rate changes from upstream sources, nor does it change parents if it seems more
appropriate: I've kept this logic as simple as possible for now. Source and rate changes have to be made manually at each pll and mux.

Tested only on the DB1300 and DB1500 so far, but I see no functional changes / errors on either board, I'll test on the other DB boards I have soon as well.

Example clock summaries right after boot:

db1300 ~ # cat /sys/kernel/debug/clk/clk_summary
clock enable_cnt prepare_cnt rate accuracy
--------------------------------------------------------------------------------

 root_clk                                 3            3    12000000          0
    auxpll2_clk                           1            1   756000000          0
       fg5_clk                            0            0   252000000          0
          maebsa_clk                      0            0   252000000          0
       fg4_clk                            0            0   189000000          0
          maempe_clk                      0            0   189000000          0
       fg3_clk                            0            0   252000000          0
          gpemgp_clk                      0            0   252000000          0
       fg2_clk                            1            1   189000000          0
          EXTCLK1                         1            1    47250000          0
       fg1_clk                            0            0   756000000          0
       fg0_clk                            0            0   756000000          0
    auxpll_clk                            1            1    96000000          0
       EXTCLK0                            0            0    96000000          0
       lcd_intclk                         1            1    96000000          0
    cpu_clk                               1            1   660000000          0
       sysbus_clk                         1            1   330000000          0
          mem_clk                         0            0   330000000          0
          periph_clk                      3            3   165000000          0
             lr_clk                       0            0   165000000          0

db1500 ~ # cat /sys/kernel/debug/clk/clk_summary
clock enable_cnt prepare_cnt rate accuracy
--------------------------------------------------------------------------------

 root_clk                                 2            2    12000000          0
    auxpll_clk                            2            2   384000000          0
       EXTCLK1                            0            0   384000000          0
       EXTCLK0                            0            0   384000000          0
       fg2_clk                            1            1    64000000          0
          pci_clko                        1            1    64000000          0
       fg1_clk                            1            1    96000000          0
          usbh_clk                        1            1    48000000          0
          usbd_clk                        0            0    48000000          0
    cpu_clk                               1            1   396000000          0
       fg5_clk                            0            0   198000000          0
       fg4_clk                            0            0   198000000          0
       fg3_clk                            0            0   198000000          0
       fg0_clk                            0            0   198000000          0
       sysbus_clk                         1            1   198000000          0
          mem_clk                         0            0    99000000          0
          periph_clk                      1            1    99000000          0
             lr_clk                       0            0    99000000          0
---
 arch/mips/Kconfig                          |    1 +
 arch/mips/alchemy/common/Makefile          |    2 +-
 arch/mips/alchemy/common/clock.c           | 1113 ++++++++++++++++++++++++++++
 arch/mips/alchemy/common/clocks.c          |  106 ---
 arch/mips/alchemy/common/platform.c        |   10 +-
 arch/mips/alchemy/common/setup.c           |   18 -
 arch/mips/alchemy/common/usb.c             |   10 +
 arch/mips/alchemy/devboards/db1000.c       |   14 +
 arch/mips/alchemy/devboards/db1200.c       |   54 +-
 arch/mips/include/asm/mach-au1x00/au1000.h |   87 +--
 arch/mips/pci/pci-alchemy.c                |   20 +-
 drivers/mmc/host/au1xmmc.c                 |   28 +-
 drivers/net/irda/au1k_ir.c                 |   48 +-
 drivers/video/fbdev/au1100fb.c             |   16 -
 14 files changed, 1279 insertions(+), 248 deletions(-)
 create mode 100644 arch/mips/alchemy/common/clock.c
 delete mode 100644 arch/mips/alchemy/common/clocks.c
arch/mips/Kconfig +1 -0
index 458608d..86e79de 100644
@@ -72,6 +72,7 @@ config MIPS_ALCHEMY
 	select SYS_SUPPORTS_APM_EMULATION
 	select ARCH_REQUIRE_GPIOLIB
 	select SYS_SUPPORTS_ZBOOT
+	select COMMON_CLK
 
 config AR7
 	bool "Texas Instruments AR7"
arch/mips/alchemy/common/Makefile +1 -1
index cb83d8d..2e4d505 100644
@@ -5,7 +5,7 @@
 # Makefile for the Alchemy Au1xx0 CPUs, generic files.
 #
 
-obj-y += prom.o time.o clocks.o platform.o power.o setup.o \
+obj-y += prom.o time.o clock.o platform.o power.o setup.o \
 	sleeper.o dma.o dbdma.o vss.o irq.o usb.o
 
 # optional gpiolib support
arch/mips/alchemy/common/clock.c new file +1113 -0

1,113 lines not on this page · raw message

arch/mips/alchemy/common/clocks.c deleted +0 -106

106 lines not on this page · raw message

arch/mips/alchemy/common/platform.c +9 -1
index 4cdc8fd..3c6fe70 100644
@@ -11,6 +11,7 @@
  * warranty of any kind, whether express or implied.
  */
 
+#include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/etherdevice.h>
 #include <linux/init.h>
@@ -99,10 +100,17 @@ static struct platform_device au1xx0_uart_device = {
 
 static void __init alchemy_setup_uarts(int ctype)
 {
-	unsigned int uartclk = get_au1x00_uart_baud_base() * 16;
+	long uartclk;
 	int s = sizeof(struct plat_serial8250_port);
 	int c = alchemy_get_uarts(ctype);
 	struct plat_serial8250_port *ports;
+	struct clk *clk = clk_get(NULL, "periph_clk");
+
+	if (IS_ERR(clk))
+		return;
+
+	uartclk = clk_get_rate(clk);
+	clk_put(clk);
 
 	ports = kzalloc(s * (c + 1), GFP_KERNEL);
 	if (!ports) {
arch/mips/alchemy/common/setup.c +0 -18
index 6f8b91d..0e53e6c 100644
@@ -27,31 +27,13 @@
 
 #include <linux/init.h>
 #include <linux/ioport.h>
-#include <linux/jiffies.h>
-#include <linux/module.h>
-
 #include <asm/dma-coherence.h>
-#include <asm/mipsregs.h>
-#include <asm/time.h>
-
 #include <asm/mach-au1x00/au1000.h>
 
 extern void __init board_setup(void);
 
 void __init plat_mem_setup(void)
 {
-	unsigned long est_freq;
-
-	/* determine core clock */
-	est_freq = au1xxx_calc_clock();
-	est_freq += 5000;    /* round */
-	est_freq -= est_freq % 10000;
-	printk(KERN_INFO "(PRId %08x) @ %lu.%02lu MHz\n", read_c0_prid(),
-	       est_freq / 1000000, ((est_freq % 1000000) * 100) / 1000000);
-
-	/* this is faster than wasting cycles trying to approximate it */
-	preset_lpj = (est_freq >> 1) / HZ;
-
 	if (au1xxx_cpu_needs_config_od())
 		/* Various early Au1xx0 errata corrected by this */
 		set_c0_config(1 << 19); /* Set Config[OD] */
arch/mips/alchemy/common/usb.c +10 -0
index d193dbe..86247a9 100644
@@ -9,6 +9,7 @@
  *
  */
 
+#include <linux/clk.h>
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -407,8 +408,15 @@ static inline void __au1xx0_ohci_control(int enable, unsigned long rb, int creg)
 {
 	void __iomem *base = (void __iomem *)KSEG1ADDR(rb);
 	unsigned long r = __raw_readl(base + creg);
+	struct clk *c = clk_get(NULL, "usbh_clk");
+
+	if (IS_ERR(c))
+		return;
 
 	if (enable) {
+		clk_set_rate(c, 48000000);
+		clk_prepare_enable(c);
+
 		__raw_writel(r | USBHEN_CE, base + creg);
 		wmb();
 		udelay(1000);
@@ -423,7 +431,9 @@ static inline void __au1xx0_ohci_control(int enable, unsigned long rb, int creg)
 	} else {
 		__raw_writel(r & ~(USBHEN_CE | USBHEN_E), base + creg);
 		wmb();
+		clk_disable_unprepare(c);
 	}
+	clk_put(c);
 }
 
 static inline int au1000_usb_control(int block, int enable, unsigned long rb,
arch/mips/alchemy/devboards/db1000.c +14 -0
index 6e55bcc..5b4f81b 100644
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
@@ -496,6 +497,7 @@ int __init db1000_dev_setup(void)
 	int board = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
 	int c0, c1, d0, d1, s0, s1, flashsize = 32,  twosocks = 1;
 	unsigned long pfc;
+	struct clk *c, *p;
 
 	if (board == BCSR_WHOAMI_DB1500) {
 		c0 = AU1500_GPIO2_INT;
@@ -525,6 +527,18 @@ int __init db1000_dev_setup(void)
 		spi_register_board_info(db1100_spi_info,
 					ARRAY_SIZE(db1100_spi_info));
 
+		/* link LCD clock to AUXPLL */
+		p = clk_get(NULL, "auxpll_clk");
+		c = clk_get(NULL, "lcd_intclk");
+		if (!IS_ERR(c) && !IS_ERR(p)) {
+			clk_set_parent(c, p);
+			clk_set_rate(c, clk_get_rate(p));
+		}
+		if (!IS_ERR(c))
+			clk_put(c);
+		if (!IS_ERR(p))
+			clk_put(p);
+
 		platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs));
 		platform_device_register(&db1100_spi_dev);
 	} else if (board == BCSR_WHOAMI_DB1000) {
arch/mips/alchemy/devboards/db1200.c +28 -26

84 lines not on this page · raw message

arch/mips/include/asm/mach-au1x00/au1000.h +17 -70

105 lines not on this page · raw message

arch/mips/pci/pci-alchemy.c +19 -1
index 912c5f2..d4dc30a 100644
@@ -7,6 +7,7 @@
  * Support for all devices (greater than 16) added by David Gathright.
  */
 
+#include <linux/clk.h>
 #include <linux/export.h>
 #include <linux/types.h>
 #include <linux/pci.h>
@@ -365,6 +366,7 @@ static int alchemy_pci_probe(struct platform_device *pdev)
 	void __iomem *virt_io;
 	unsigned long val;
 	struct resource *r;
+	struct clk *c;
 	int ret;
 
 	/* need at least PCI IRQ mapping table */
@@ -394,11 +396,24 @@ static int alchemy_pci_probe(struct platform_device *pdev)
 		goto out1;
 	}
 
+	c = clk_get(&pdev->dev, "pci_clko");
+	if (IS_ERR(c)) {
+		dev_err(&pdev->dev, "unable to find PCI clock\n");
+		ret = PTR_ERR(c);
+		goto out2;
+	}
+	ret = clk_prepare_enable(c);
+	if (ret) {
+		dev_err(&pdev->dev, "cannot enable PCI clock\n");
+		clk_put(c);
+		goto out2;
+	}
+
 	ctx->regs = ioremap_nocache(r->start, resource_size(r));
 	if (!ctx->regs) {
 		dev_err(&pdev->dev, "cannot map pci regs\n");
 		ret = -ENODEV;
-		goto out2;
+		goto out5;
 	}
 
 	/* map parts of the PCI IO area */
@@ -472,6 +487,9 @@ out4:
 	iounmap(virt_io);
 out3:
 	iounmap(ctx->regs);
+out5:
+	clk_disable_unprepare(c);
+	clk_put(c);
 out2:
 	release_mem_region(r->start, resource_size(r));
 out1:
drivers/mmc/host/au1xmmc.c +21 -7
index 1837309..28bfe5b 100644
@@ -32,6 +32,7 @@
  * (the low to high transition will not occur).
  */
 
+#include <linux/clk.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
@@ -118,6 +119,7 @@ struct au1xmmc_host {
 	struct au1xmmc_platform_data *platdata;
 	struct platform_device *pdev;
 	struct resource *ioarea;
+	struct clk *clk;
 };
 
 /* Status flags used by the host structure */
@@ -596,15 +598,11 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
 
 static void au1xmmc_set_clock(struct au1xmmc_host *host, int rate)
 {
-	unsigned int pbus = get_au1x00_speed();
+	unsigned int pbus;
 	unsigned int divisor;
 	u32 config;
 
-	/* From databook:
-	 * divisor = ((((cpuclock / sbus_divisor) / 2) / mmcclock) / 2) - 1
-	 */
-	pbus /= ((AU1X_RDSYS(AU1000_SYS_POWERCTRL) & 0x3) + 2);
-	pbus /= 2;
+	pbus = clk_get_rate(host->clk);
 	divisor = ((pbus / rate) / 2) - 1;
 
 	config = __raw_readl(HOST_CONFIG(host));
@@ -1029,6 +1027,16 @@ static int au1xmmc_probe(struct platform_device *pdev)
 		goto out3;
 	}
 
+	host->clk = clk_get(&pdev->dev, ALCHEMY_PERIPH_CLK);
+	if (IS_ERR(host->clk)) {
+		dev_err(&pdev->dev, "cannot find clock\n");
+		goto out_irq;
+	}
+	if (clk_prepare_enable(host->clk)) {
+		dev_err(&pdev->dev, "cannot enable clock\n");
+		goto out_clk;
+	}
+
 	host->status = HOST_S_IDLE;
 
 	/* board-specific carddetect setup, if any */
@@ -1105,7 +1113,10 @@ out5:
 	if (host->platdata && host->platdata->cd_setup &&
 	    !(mmc->caps & MMC_CAP_NEEDS_POLL))
 		host->platdata->cd_setup(mmc, 0);
-
+out_clk:
+	clk_disable_unprepare(host->clk);
+	clk_put(host->clk);
+out_irq:
 	free_irq(host->irq, host);
 out3:
 	iounmap((void *)host->iobase);
@@ -1147,6 +1158,9 @@ static int au1xmmc_remove(struct platform_device *pdev)
 
 		au1xmmc_set_power(host, 0);
 
+		clk_disable_unprepare(host->clk);
+		clk_put(host->clk);
+
 		free_irq(host->irq, host);
 		iounmap((void *)host->iobase);
 		release_resource(host->ioarea);
drivers/net/irda/au1k_ir.c +46 -2

92 lines not on this page · raw message

drivers/video/fbdev/au1100fb.c +0 -16
index 2c2804b..82d7b35 100644
@@ -434,7 +434,6 @@ static int au1100fb_drv_probe(struct platform_device *dev)
 	struct au1100fb_device *fbdev = NULL;
 	struct resource *regs_res;
 	unsigned long page;
-	u32 sys_clksrc;
 
 	/* Allocate new device private */
 	fbdev = devm_kzalloc(&dev->dev, sizeof(struct au1100fb_device),
@@ -506,11 +505,6 @@ static int au1100fb_drv_probe(struct platform_device *dev)
 	print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
 	print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
 
-	/* Setup LCD clock to AUX (48 MHz) */
-	sys_clksrc = AU1X_RDSYS(AU1000_SYS_CLKSRC) &
-			~(SYS_CS_ML_MASK | SYS_CS_DL | SYS_CS_CL);
-	AU1X_WRSYS((sys_clksrc | (1 << SYS_CS_ML_BIT)), AU1000_SYS_CLKSRC);
-
 	/* load the panel info into the var struct */
 	au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
 	au1100fb_var.xres = fbdev->panel->xres;
@@ -581,7 +575,6 @@ int au1100fb_drv_remove(struct platform_device *dev)
 }
 
 #ifdef CONFIG_PM
-static u32 sys_clksrc;
 static struct au1100fb_regs fbregs;
 
 int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
@@ -591,15 +584,9 @@ int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
 	if (!fbdev)
 		return 0;
 
-	/* Save the clock source state */
-	sys_clksrc = AU1X_RDSYS(AU1000_SYS_CLKSRC);
-
 	/* Blank the LCD */
 	au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
 
-	/* Stop LCD clocking */
-	AU1X_WRSYS(sys_clksrc & ~SYS_CS_ML_MASK, AU1000_SYS_CLKSRC);
-
 	memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
 
 	return 0;
@@ -614,9 +601,6 @@ int au1100fb_drv_resume(struct platform_device *dev)
 
 	memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
 
-	/* Restart LCD clocking */
-	AU1X_WRSYS(sys_clksrc, AU1000_SYS_CLKSRC);
-
 	/* Unblank the LCD */
 	au1100fb_fb_blank(VESA_NO_BLANKING, &fbdev->info);
 
Signature · 1 line
2.0.0
#3 lore raw

Re: [PATCH 2/2] MIPS: Alchemy: common clock framework integration

Quoting Manuel Lauss (2014-06-29 09:57:35)

Quoted 2 lines

Expose chip-internal configurable clocks to the common clk framework, and fix a few drivers to take advantage of it.

Thanks for the patch series! Both patches cover a lot of ground, but I'll focus on #2. It would be best to split the driver changes out separately. You can introduce the common clk changes but not compile them in, then change the drivers, then add the logic to compile the new common clock driver all as separate patches.

<snip>

arch/mips/alchemy/common/Makefile line 9

Quoted 11 lines
arch/mips/alchemy/common/Makefile +1 -1
index cb83d8d..2e4d505 100644
@@ -5,7 +5,7 @@
 # Makefile for the Alchemy Au1xx0 CPUs, generic files.
 #
 
-obj-y += prom.o time.o clocks.o platform.o power.o setup.o \
+obj-y += prom.o time.o clock.o platform.o power.o setup.o \
        sleeper.o dma.o dbdma.o vss.o irq.o usb.o

As stated above, in the first patch only introduce arch/mips/alchemy/common/clock, but don't compile it here in the Makefile.

A quick glance through clock.c below looks pretty good. I'll go through it in more detail once the other parts of the series are split out.

Additionally, it would be cool to push this driver out to drivers/clk/ if you are so inclined. It looks like your header dependencies are not so bad as to make that task impossible. Just a suggestion from me.

Regards,
Mike

author maintainer
#4 lore raw

Re: [PATCH 2/2] MIPS: Alchemy: common clock framework integration

Hi Mike,

Quoted 6 lines · Mike Turquette

Quoting Manuel Lauss (2014-06-29 09:57:35)

Quoted 2 lines

Expose chip-internal configurable clocks to the common clk framework, and fix a few drivers to take advantage of it.

Thanks for the patch series! Both patches cover a lot of ground, but I'll focus on #2. It would be best to split the driver changes out

I sent the first one along because the second doesn't compile without it.

Quoted 3 lines

separately. You can introduce the common clk changes but not compile them in, then change the drivers, then add the logic to compile the new common clock driver all as separate patches.

I'll split them into pure clock framework and enablement parts.

Quoted 3 lines

Additionally, it would be cool to push this driver out to drivers/clk/ if you are so inclined. It looks like your header dependencies are not so bad as to make that task impossible. Just a suggestion from me.

This clock framework is for a single line of MIPS SoCs which are no longer being developed by the manufacturer and I don't think it is reusable for any other soc line currently in existence. I'd like to keep it within the mips tree for that reason. (I find the ARM way of sprinkling the whole tree with a single driver for each iteration of each custom on-chip peripheral on
each ARM chip [exaggerated of course] quite messy. But that's just me).

Manuel