xref: /openbmc/linux/arch/mips/ath25/ar5312.c (revision 0ccd7890)
13b12308fSSergey Ryazanov /*
23b12308fSSergey Ryazanov  * This file is subject to the terms and conditions of the GNU General Public
33b12308fSSergey Ryazanov  * License.  See the file "COPYING" in the main directory of this archive
43b12308fSSergey Ryazanov  * for more details.
53b12308fSSergey Ryazanov  *
63b12308fSSergey Ryazanov  * Copyright (C) 2003 Atheros Communications, Inc.,  All Rights Reserved.
73b12308fSSergey Ryazanov  * Copyright (C) 2006 FON Technology, SL.
83b12308fSSergey Ryazanov  * Copyright (C) 2006 Imre Kaloz <kaloz@openwrt.org>
93b12308fSSergey Ryazanov  * Copyright (C) 2006-2009 Felix Fietkau <nbd@openwrt.org>
103b12308fSSergey Ryazanov  * Copyright (C) 2012 Alexandros C. Couloumbis <alex@ozo.com>
113b12308fSSergey Ryazanov  */
123b12308fSSergey Ryazanov 
133b12308fSSergey Ryazanov /*
143b12308fSSergey Ryazanov  * Platform devices for Atheros AR5312 SoCs
153b12308fSSergey Ryazanov  */
163b12308fSSergey Ryazanov 
173b12308fSSergey Ryazanov #include <linux/init.h>
183b12308fSSergey Ryazanov #include <linux/kernel.h>
191753e74eSSergey Ryazanov #include <linux/bitops.h>
201753e74eSSergey Ryazanov #include <linux/irqdomain.h>
211753e74eSSergey Ryazanov #include <linux/interrupt.h>
22e7ae8d17SThomas Bogendoerfer #include <linux/memblock.h>
23d58eaa7fSSergey Ryazanov #include <linux/platform_device.h>
24d58eaa7fSSergey Ryazanov #include <linux/mtd/physmap.h>
253b12308fSSergey Ryazanov #include <linux/reboot.h>
263b12308fSSergey Ryazanov #include <asm/bootinfo.h>
273b12308fSSergey Ryazanov #include <asm/reboot.h>
283b12308fSSergey Ryazanov #include <asm/time.h>
293b12308fSSergey Ryazanov 
301654861fSSergey Ryazanov #include <ath25_platform.h>
311654861fSSergey Ryazanov 
323b12308fSSergey Ryazanov #include "devices.h"
333b12308fSSergey Ryazanov #include "ar5312.h"
343b12308fSSergey Ryazanov #include "ar5312_regs.h"
353b12308fSSergey Ryazanov 
363b12308fSSergey Ryazanov static void __iomem *ar5312_rst_base;
371753e74eSSergey Ryazanov static struct irq_domain *ar5312_misc_irq_domain;
383b12308fSSergey Ryazanov 
ar5312_rst_reg_read(u32 reg)393b12308fSSergey Ryazanov static inline u32 ar5312_rst_reg_read(u32 reg)
403b12308fSSergey Ryazanov {
413b12308fSSergey Ryazanov 	return __raw_readl(ar5312_rst_base + reg);
423b12308fSSergey Ryazanov }
433b12308fSSergey Ryazanov 
ar5312_rst_reg_write(u32 reg,u32 val)443b12308fSSergey Ryazanov static inline void ar5312_rst_reg_write(u32 reg, u32 val)
453b12308fSSergey Ryazanov {
463b12308fSSergey Ryazanov 	__raw_writel(val, ar5312_rst_base + reg);
473b12308fSSergey Ryazanov }
483b12308fSSergey Ryazanov 
ar5312_rst_reg_mask(u32 reg,u32 mask,u32 val)493b12308fSSergey Ryazanov static inline void ar5312_rst_reg_mask(u32 reg, u32 mask, u32 val)
503b12308fSSergey Ryazanov {
513b12308fSSergey Ryazanov 	u32 ret = ar5312_rst_reg_read(reg);
523b12308fSSergey Ryazanov 
533b12308fSSergey Ryazanov 	ret &= ~mask;
543b12308fSSergey Ryazanov 	ret |= val;
553b12308fSSergey Ryazanov 	ar5312_rst_reg_write(reg, ret);
563b12308fSSergey Ryazanov }
573b12308fSSergey Ryazanov 
ar5312_ahb_err_handler(int cpl,void * dev_id)581753e74eSSergey Ryazanov static irqreturn_t ar5312_ahb_err_handler(int cpl, void *dev_id)
591753e74eSSergey Ryazanov {
601753e74eSSergey Ryazanov 	u32 proc1 = ar5312_rst_reg_read(AR5312_PROC1);
611753e74eSSergey Ryazanov 	u32 proc_addr = ar5312_rst_reg_read(AR5312_PROCADDR); /* clears error */
621753e74eSSergey Ryazanov 	u32 dma1 = ar5312_rst_reg_read(AR5312_DMA1);
631753e74eSSergey Ryazanov 	u32 dma_addr = ar5312_rst_reg_read(AR5312_DMAADDR);   /* clears error */
641753e74eSSergey Ryazanov 
651753e74eSSergey Ryazanov 	pr_emerg("AHB interrupt: PROCADDR=0x%8.8x PROC1=0x%8.8x DMAADDR=0x%8.8x DMA1=0x%8.8x\n",
661753e74eSSergey Ryazanov 		 proc_addr, proc1, dma_addr, dma1);
671753e74eSSergey Ryazanov 
681753e74eSSergey Ryazanov 	machine_restart("AHB error"); /* Catastrophic failure */
691753e74eSSergey Ryazanov 	return IRQ_HANDLED;
701753e74eSSergey Ryazanov }
711753e74eSSergey Ryazanov 
ar5312_misc_irq_handler(struct irq_desc * desc)72bd0b9ac4SThomas Gleixner static void ar5312_misc_irq_handler(struct irq_desc *desc)
731753e74eSSergey Ryazanov {
741753e74eSSergey Ryazanov 	u32 pending = ar5312_rst_reg_read(AR5312_ISR) &
751753e74eSSergey Ryazanov 		      ar5312_rst_reg_read(AR5312_IMR);
760661cb2aSMarc Zyngier 	unsigned nr;
770661cb2aSMarc Zyngier 	int ret = 0;
781753e74eSSergey Ryazanov 
791753e74eSSergey Ryazanov 	if (pending) {
8025aae561SJiang Liu 		struct irq_domain *domain = irq_desc_get_handler_data(desc);
811753e74eSSergey Ryazanov 
821753e74eSSergey Ryazanov 		nr = __ffs(pending);
831753e74eSSergey Ryazanov 
840661cb2aSMarc Zyngier 		ret = generic_handle_domain_irq(domain, nr);
851753e74eSSergey Ryazanov 		if (nr == AR5312_MISC_IRQ_TIMER)
861753e74eSSergey Ryazanov 			ar5312_rst_reg_read(AR5312_TIMER);
871753e74eSSergey Ryazanov 	}
880661cb2aSMarc Zyngier 
890661cb2aSMarc Zyngier 	if (!pending || ret)
900661cb2aSMarc Zyngier 		spurious_interrupt();
911753e74eSSergey Ryazanov }
921753e74eSSergey Ryazanov 
931753e74eSSergey Ryazanov /* Enable the specified AR5312_MISC_IRQ interrupt */
ar5312_misc_irq_unmask(struct irq_data * d)941753e74eSSergey Ryazanov static void ar5312_misc_irq_unmask(struct irq_data *d)
951753e74eSSergey Ryazanov {
961753e74eSSergey Ryazanov 	ar5312_rst_reg_mask(AR5312_IMR, 0, BIT(d->hwirq));
971753e74eSSergey Ryazanov }
981753e74eSSergey Ryazanov 
991753e74eSSergey Ryazanov /* Disable the specified AR5312_MISC_IRQ interrupt */
ar5312_misc_irq_mask(struct irq_data * d)1001753e74eSSergey Ryazanov static void ar5312_misc_irq_mask(struct irq_data *d)
1011753e74eSSergey Ryazanov {
1021753e74eSSergey Ryazanov 	ar5312_rst_reg_mask(AR5312_IMR, BIT(d->hwirq), 0);
1031753e74eSSergey Ryazanov 	ar5312_rst_reg_read(AR5312_IMR); /* flush write buffer */
1041753e74eSSergey Ryazanov }
1051753e74eSSergey Ryazanov 
1061753e74eSSergey Ryazanov static struct irq_chip ar5312_misc_irq_chip = {
1071753e74eSSergey Ryazanov 	.name		= "ar5312-misc",
1081753e74eSSergey Ryazanov 	.irq_unmask	= ar5312_misc_irq_unmask,
1091753e74eSSergey Ryazanov 	.irq_mask	= ar5312_misc_irq_mask,
1101753e74eSSergey Ryazanov };
1111753e74eSSergey Ryazanov 
ar5312_misc_irq_map(struct irq_domain * d,unsigned irq,irq_hw_number_t hw)1121753e74eSSergey Ryazanov static int ar5312_misc_irq_map(struct irq_domain *d, unsigned irq,
1131753e74eSSergey Ryazanov 			       irq_hw_number_t hw)
1141753e74eSSergey Ryazanov {
1151753e74eSSergey Ryazanov 	irq_set_chip_and_handler(irq, &ar5312_misc_irq_chip, handle_level_irq);
1161753e74eSSergey Ryazanov 	return 0;
1171753e74eSSergey Ryazanov }
1181753e74eSSergey Ryazanov 
119*0ccd7890SRikard Falkeborn static const struct irq_domain_ops ar5312_misc_irq_domain_ops = {
1201753e74eSSergey Ryazanov 	.map = ar5312_misc_irq_map,
1211753e74eSSergey Ryazanov };
1221753e74eSSergey Ryazanov 
ar5312_irq_dispatch(void)1231753e74eSSergey Ryazanov static void ar5312_irq_dispatch(void)
1241753e74eSSergey Ryazanov {
1251753e74eSSergey Ryazanov 	u32 pending = read_c0_status() & read_c0_cause();
1261753e74eSSergey Ryazanov 
1271753e74eSSergey Ryazanov 	if (pending & CAUSEF_IP2)
1281753e74eSSergey Ryazanov 		do_IRQ(AR5312_IRQ_WLAN0);
1291753e74eSSergey Ryazanov 	else if (pending & CAUSEF_IP5)
1301753e74eSSergey Ryazanov 		do_IRQ(AR5312_IRQ_WLAN1);
1311753e74eSSergey Ryazanov 	else if (pending & CAUSEF_IP6)
1321753e74eSSergey Ryazanov 		do_IRQ(AR5312_IRQ_MISC);
1331753e74eSSergey Ryazanov 	else if (pending & CAUSEF_IP7)
1341753e74eSSergey Ryazanov 		do_IRQ(ATH25_IRQ_CPU_CLOCK);
1351753e74eSSergey Ryazanov 	else
1361753e74eSSergey Ryazanov 		spurious_interrupt();
1371753e74eSSergey Ryazanov }
1381753e74eSSergey Ryazanov 
ar5312_arch_init_irq(void)1391753e74eSSergey Ryazanov void __init ar5312_arch_init_irq(void)
1401753e74eSSergey Ryazanov {
1411753e74eSSergey Ryazanov 	struct irq_domain *domain;
1421753e74eSSergey Ryazanov 	unsigned irq;
1431753e74eSSergey Ryazanov 
1441753e74eSSergey Ryazanov 	ath25_irq_dispatch = ar5312_irq_dispatch;
1451753e74eSSergey Ryazanov 
1461753e74eSSergey Ryazanov 	domain = irq_domain_add_linear(NULL, AR5312_MISC_IRQ_COUNT,
1471753e74eSSergey Ryazanov 				       &ar5312_misc_irq_domain_ops, NULL);
1481753e74eSSergey Ryazanov 	if (!domain)
1491753e74eSSergey Ryazanov 		panic("Failed to add IRQ domain");
1501753e74eSSergey Ryazanov 
1511753e74eSSergey Ryazanov 	irq = irq_create_mapping(domain, AR5312_MISC_IRQ_AHB_PROC);
152ac8fd122Safzal mohammed 	if (request_irq(irq, ar5312_ahb_err_handler, 0, "ar5312-ahb-error",
153ac8fd122Safzal mohammed 			NULL))
154ac8fd122Safzal mohammed 		pr_err("Failed to register ar5312-ahb-error interrupt\n");
1551753e74eSSergey Ryazanov 
15608ece35eSThomas Gleixner 	irq_set_chained_handler_and_data(AR5312_IRQ_MISC,
15708ece35eSThomas Gleixner 					 ar5312_misc_irq_handler, domain);
1581753e74eSSergey Ryazanov 
1591753e74eSSergey Ryazanov 	ar5312_misc_irq_domain = domain;
1601753e74eSSergey Ryazanov }
1611753e74eSSergey Ryazanov 
162d58eaa7fSSergey Ryazanov static struct physmap_flash_data ar5312_flash_data = {
163d58eaa7fSSergey Ryazanov 	.width = 2,
164d58eaa7fSSergey Ryazanov };
165d58eaa7fSSergey Ryazanov 
166d58eaa7fSSergey Ryazanov static struct resource ar5312_flash_resource = {
167d58eaa7fSSergey Ryazanov 	.start = AR5312_FLASH_BASE,
168d58eaa7fSSergey Ryazanov 	.end = AR5312_FLASH_BASE + AR5312_FLASH_SIZE - 1,
169d58eaa7fSSergey Ryazanov 	.flags = IORESOURCE_MEM,
170d58eaa7fSSergey Ryazanov };
171d58eaa7fSSergey Ryazanov 
172d58eaa7fSSergey Ryazanov static struct platform_device ar5312_physmap_flash = {
173d58eaa7fSSergey Ryazanov 	.name = "physmap-flash",
174d58eaa7fSSergey Ryazanov 	.id = 0,
175d58eaa7fSSergey Ryazanov 	.dev.platform_data = &ar5312_flash_data,
176d58eaa7fSSergey Ryazanov 	.resource = &ar5312_flash_resource,
177d58eaa7fSSergey Ryazanov 	.num_resources = 1,
178d58eaa7fSSergey Ryazanov };
179d58eaa7fSSergey Ryazanov 
ar5312_flash_init(void)180a7473717SSergey Ryazanov static void __init ar5312_flash_init(void)
181a7473717SSergey Ryazanov {
182a7473717SSergey Ryazanov 	void __iomem *flashctl_base;
183a7473717SSergey Ryazanov 	u32 ctl;
184a7473717SSergey Ryazanov 
1854bdc0d67SChristoph Hellwig 	flashctl_base = ioremap(AR5312_FLASHCTL_BASE,
186a7473717SSergey Ryazanov 					AR5312_FLASHCTL_SIZE);
187a7473717SSergey Ryazanov 
188d58eaa7fSSergey Ryazanov 	ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL0);
189d58eaa7fSSergey Ryazanov 	ctl &= AR5312_FLASHCTL_MW;
190d58eaa7fSSergey Ryazanov 
191d58eaa7fSSergey Ryazanov 	/* fixup flash width */
192d58eaa7fSSergey Ryazanov 	switch (ctl) {
193d58eaa7fSSergey Ryazanov 	case AR5312_FLASHCTL_MW16:
194d58eaa7fSSergey Ryazanov 		ar5312_flash_data.width = 2;
195d58eaa7fSSergey Ryazanov 		break;
196d58eaa7fSSergey Ryazanov 	case AR5312_FLASHCTL_MW8:
197d58eaa7fSSergey Ryazanov 	default:
198d58eaa7fSSergey Ryazanov 		ar5312_flash_data.width = 1;
199d58eaa7fSSergey Ryazanov 		break;
200d58eaa7fSSergey Ryazanov 	}
201d58eaa7fSSergey Ryazanov 
202a7473717SSergey Ryazanov 	/*
203a7473717SSergey Ryazanov 	 * Configure flash bank 0.
204a7473717SSergey Ryazanov 	 * Assume 8M window size. Flash will be aliased if it's smaller
205a7473717SSergey Ryazanov 	 */
206a7473717SSergey Ryazanov 	ctl |= AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC_8M | AR5312_FLASHCTL_RBLE;
207a7473717SSergey Ryazanov 	ctl |= 0x01 << AR5312_FLASHCTL_IDCY_S;
208a7473717SSergey Ryazanov 	ctl |= 0x07 << AR5312_FLASHCTL_WST1_S;
209a7473717SSergey Ryazanov 	ctl |= 0x07 << AR5312_FLASHCTL_WST2_S;
210a7473717SSergey Ryazanov 	__raw_writel(ctl, flashctl_base + AR5312_FLASHCTL0);
211a7473717SSergey Ryazanov 
212a7473717SSergey Ryazanov 	/* Disable other flash banks */
213a7473717SSergey Ryazanov 	ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL1);
214a7473717SSergey Ryazanov 	ctl &= ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
215a7473717SSergey Ryazanov 	__raw_writel(ctl, flashctl_base + AR5312_FLASHCTL1);
216a7473717SSergey Ryazanov 	ctl = __raw_readl(flashctl_base + AR5312_FLASHCTL2);
217a7473717SSergey Ryazanov 	ctl &= ~(AR5312_FLASHCTL_E | AR5312_FLASHCTL_AC);
218a7473717SSergey Ryazanov 	__raw_writel(ctl, flashctl_base + AR5312_FLASHCTL2);
219a7473717SSergey Ryazanov 
220a7473717SSergey Ryazanov 	iounmap(flashctl_base);
221a7473717SSergey Ryazanov }
222a7473717SSergey Ryazanov 
ar5312_init_devices(void)223a7473717SSergey Ryazanov void __init ar5312_init_devices(void)
224a7473717SSergey Ryazanov {
2251654861fSSergey Ryazanov 	struct ath25_boarddata *config;
2261654861fSSergey Ryazanov 
227a7473717SSergey Ryazanov 	ar5312_flash_init();
228a7473717SSergey Ryazanov 
229a7473717SSergey Ryazanov 	/* Locate board/radio config data */
230a7473717SSergey Ryazanov 	ath25_find_config(AR5312_FLASH_BASE, AR5312_FLASH_SIZE);
2311654861fSSergey Ryazanov 	config = ath25_board.config;
2321654861fSSergey Ryazanov 
2331654861fSSergey Ryazanov 	/* AR2313 has CPU minor rev. 10 */
2341654861fSSergey Ryazanov 	if ((current_cpu_data.processor_id & 0xff) == 0x0a)
2351654861fSSergey Ryazanov 		ath25_soc = ATH25_SOC_AR2313;
2361654861fSSergey Ryazanov 
2371654861fSSergey Ryazanov 	/* AR2312 shares the same Silicon ID as AR5312 */
2381654861fSSergey Ryazanov 	else if (config->flags & BD_ISCASPER)
2391654861fSSergey Ryazanov 		ath25_soc = ATH25_SOC_AR2312;
2401654861fSSergey Ryazanov 
2411654861fSSergey Ryazanov 	/* Everything else is probably AR5312 or compatible */
2421654861fSSergey Ryazanov 	else
2431654861fSSergey Ryazanov 		ath25_soc = ATH25_SOC_AR5312;
244d58eaa7fSSergey Ryazanov 
245d58eaa7fSSergey Ryazanov 	platform_device_register(&ar5312_physmap_flash);
246d6a4c72aSSergey Ryazanov 
247d6a4c72aSSergey Ryazanov 	switch (ath25_soc) {
248d6a4c72aSSergey Ryazanov 	case ATH25_SOC_AR5312:
249d6a4c72aSSergey Ryazanov 		if (!ath25_board.radio)
250d6a4c72aSSergey Ryazanov 			return;
251d6a4c72aSSergey Ryazanov 
252d6a4c72aSSergey Ryazanov 		if (!(config->flags & BD_WLAN0))
253d6a4c72aSSergey Ryazanov 			break;
254d6a4c72aSSergey Ryazanov 
255d6a4c72aSSergey Ryazanov 		ath25_add_wmac(0, AR5312_WLAN0_BASE, AR5312_IRQ_WLAN0);
256d6a4c72aSSergey Ryazanov 		break;
257d6a4c72aSSergey Ryazanov 	case ATH25_SOC_AR2312:
258d6a4c72aSSergey Ryazanov 	case ATH25_SOC_AR2313:
259d6a4c72aSSergey Ryazanov 		if (!ath25_board.radio)
260d6a4c72aSSergey Ryazanov 			return;
261d6a4c72aSSergey Ryazanov 		break;
262d6a4c72aSSergey Ryazanov 	default:
263d6a4c72aSSergey Ryazanov 		break;
264d6a4c72aSSergey Ryazanov 	}
265d6a4c72aSSergey Ryazanov 
266d6a4c72aSSergey Ryazanov 	if (config->flags & BD_WLAN1)
267d6a4c72aSSergey Ryazanov 		ath25_add_wmac(1, AR5312_WLAN1_BASE, AR5312_IRQ_WLAN1);
268a7473717SSergey Ryazanov }
269a7473717SSergey Ryazanov 
ar5312_restart(char * command)2703b12308fSSergey Ryazanov static void ar5312_restart(char *command)
2713b12308fSSergey Ryazanov {
2723b12308fSSergey Ryazanov 	/* reset the system */
2733b12308fSSergey Ryazanov 	local_irq_disable();
2743b12308fSSergey Ryazanov 	while (1)
2753b12308fSSergey Ryazanov 		ar5312_rst_reg_write(AR5312_RESET, AR5312_RESET_SYSTEM);
2763b12308fSSergey Ryazanov }
2773b12308fSSergey Ryazanov 
2783b12308fSSergey Ryazanov /*
2793b12308fSSergey Ryazanov  * This table is indexed by bits 5..4 of the CLOCKCTL1 register
2803b12308fSSergey Ryazanov  * to determine the predevisor value.
2813b12308fSSergey Ryazanov  */
2823b12308fSSergey Ryazanov static unsigned clockctl1_predivide_table[4] __initdata = { 1, 2, 4, 5 };
2833b12308fSSergey Ryazanov 
ar5312_cpu_frequency(void)2843b12308fSSergey Ryazanov static unsigned __init ar5312_cpu_frequency(void)
2853b12308fSSergey Ryazanov {
2863b12308fSSergey Ryazanov 	u32 scratch, devid, clock_ctl1;
2873b12308fSSergey Ryazanov 	u32 predivide_mask, multiplier_mask, doubler_mask;
2883b12308fSSergey Ryazanov 	unsigned predivide_shift, multiplier_shift;
2893b12308fSSergey Ryazanov 	unsigned predivide_select, predivisor, multiplier;
2903b12308fSSergey Ryazanov 
2913b12308fSSergey Ryazanov 	/* Trust the bootrom's idea of cpu frequency. */
2923b12308fSSergey Ryazanov 	scratch = ar5312_rst_reg_read(AR5312_SCRATCH);
2933b12308fSSergey Ryazanov 	if (scratch)
2943b12308fSSergey Ryazanov 		return scratch;
2953b12308fSSergey Ryazanov 
2963b12308fSSergey Ryazanov 	devid = ar5312_rst_reg_read(AR5312_REV);
2973b12308fSSergey Ryazanov 	devid = (devid & AR5312_REV_MAJ) >> AR5312_REV_MAJ_S;
2983b12308fSSergey Ryazanov 	if (devid == AR5312_REV_MAJ_AR2313) {
2993b12308fSSergey Ryazanov 		predivide_mask = AR2313_CLOCKCTL1_PREDIVIDE_MASK;
3003b12308fSSergey Ryazanov 		predivide_shift = AR2313_CLOCKCTL1_PREDIVIDE_SHIFT;
3013b12308fSSergey Ryazanov 		multiplier_mask = AR2313_CLOCKCTL1_MULTIPLIER_MASK;
3023b12308fSSergey Ryazanov 		multiplier_shift = AR2313_CLOCKCTL1_MULTIPLIER_SHIFT;
3033b12308fSSergey Ryazanov 		doubler_mask = AR2313_CLOCKCTL1_DOUBLER_MASK;
3043b12308fSSergey Ryazanov 	} else { /* AR5312 and AR2312 */
3053b12308fSSergey Ryazanov 		predivide_mask = AR5312_CLOCKCTL1_PREDIVIDE_MASK;
3063b12308fSSergey Ryazanov 		predivide_shift = AR5312_CLOCKCTL1_PREDIVIDE_SHIFT;
3073b12308fSSergey Ryazanov 		multiplier_mask = AR5312_CLOCKCTL1_MULTIPLIER_MASK;
3083b12308fSSergey Ryazanov 		multiplier_shift = AR5312_CLOCKCTL1_MULTIPLIER_SHIFT;
3093b12308fSSergey Ryazanov 		doubler_mask = AR5312_CLOCKCTL1_DOUBLER_MASK;
3103b12308fSSergey Ryazanov 	}
3113b12308fSSergey Ryazanov 
3123b12308fSSergey Ryazanov 	/*
3133b12308fSSergey Ryazanov 	 * Clocking is derived from a fixed 40MHz input clock.
3143b12308fSSergey Ryazanov 	 *
3153b12308fSSergey Ryazanov 	 *  cpu_freq = input_clock * MULT (where MULT is PLL multiplier)
3163b12308fSSergey Ryazanov 	 *  sys_freq = cpu_freq / 4	  (used for APB clock, serial,
3173b12308fSSergey Ryazanov 	 *				   flash, Timer, Watchdog Timer)
3183b12308fSSergey Ryazanov 	 *
3193b12308fSSergey Ryazanov 	 *  cnt_freq = cpu_freq / 2	  (use for CPU count/compare)
3203b12308fSSergey Ryazanov 	 *
3213b12308fSSergey Ryazanov 	 * So, for example, with a PLL multiplier of 5, we have
3223b12308fSSergey Ryazanov 	 *
3233b12308fSSergey Ryazanov 	 *  cpu_freq = 200MHz
3243b12308fSSergey Ryazanov 	 *  sys_freq = 50MHz
3253b12308fSSergey Ryazanov 	 *  cnt_freq = 100MHz
3263b12308fSSergey Ryazanov 	 *
3273b12308fSSergey Ryazanov 	 * We compute the CPU frequency, based on PLL settings.
3283b12308fSSergey Ryazanov 	 */
3293b12308fSSergey Ryazanov 
3303b12308fSSergey Ryazanov 	clock_ctl1 = ar5312_rst_reg_read(AR5312_CLOCKCTL1);
3313b12308fSSergey Ryazanov 	predivide_select = (clock_ctl1 & predivide_mask) >> predivide_shift;
3323b12308fSSergey Ryazanov 	predivisor = clockctl1_predivide_table[predivide_select];
3333b12308fSSergey Ryazanov 	multiplier = (clock_ctl1 & multiplier_mask) >> multiplier_shift;
3343b12308fSSergey Ryazanov 
3353b12308fSSergey Ryazanov 	if (clock_ctl1 & doubler_mask)
3363b12308fSSergey Ryazanov 		multiplier <<= 1;
3373b12308fSSergey Ryazanov 
3383b12308fSSergey Ryazanov 	return (40000000 / predivisor) * multiplier;
3393b12308fSSergey Ryazanov }
3403b12308fSSergey Ryazanov 
ar5312_sys_frequency(void)3413b12308fSSergey Ryazanov static inline unsigned ar5312_sys_frequency(void)
3423b12308fSSergey Ryazanov {
3433b12308fSSergey Ryazanov 	return ar5312_cpu_frequency() / 4;
3443b12308fSSergey Ryazanov }
3453b12308fSSergey Ryazanov 
ar5312_plat_time_init(void)3463b12308fSSergey Ryazanov void __init ar5312_plat_time_init(void)
3473b12308fSSergey Ryazanov {
3483b12308fSSergey Ryazanov 	mips_hpt_frequency = ar5312_cpu_frequency() / 2;
3493b12308fSSergey Ryazanov }
3503b12308fSSergey Ryazanov 
ar5312_plat_mem_setup(void)3513b12308fSSergey Ryazanov void __init ar5312_plat_mem_setup(void)
3523b12308fSSergey Ryazanov {
3533b12308fSSergey Ryazanov 	void __iomem *sdram_base;
3543b12308fSSergey Ryazanov 	u32 memsize, memcfg, bank0_ac, bank1_ac;
3551654861fSSergey Ryazanov 	u32 devid;
3563b12308fSSergey Ryazanov 
3573b12308fSSergey Ryazanov 	/* Detect memory size */
3584bdc0d67SChristoph Hellwig 	sdram_base = ioremap(AR5312_SDRAMCTL_BASE,
3593b12308fSSergey Ryazanov 				     AR5312_SDRAMCTL_SIZE);
3603b12308fSSergey Ryazanov 	memcfg = __raw_readl(sdram_base + AR5312_MEM_CFG1);
3613b12308fSSergey Ryazanov 	bank0_ac = ATH25_REG_MS(memcfg, AR5312_MEM_CFG1_AC0);
3623b12308fSSergey Ryazanov 	bank1_ac = ATH25_REG_MS(memcfg, AR5312_MEM_CFG1_AC1);
3633b12308fSSergey Ryazanov 	memsize = (bank0_ac ? (1 << (bank0_ac + 1)) : 0) +
3643b12308fSSergey Ryazanov 		  (bank1_ac ? (1 << (bank1_ac + 1)) : 0);
3653b12308fSSergey Ryazanov 	memsize <<= 20;
366e7ae8d17SThomas Bogendoerfer 	memblock_add(0, memsize);
3673b12308fSSergey Ryazanov 	iounmap(sdram_base);
3683b12308fSSergey Ryazanov 
3694bdc0d67SChristoph Hellwig 	ar5312_rst_base = ioremap(AR5312_RST_BASE, AR5312_RST_SIZE);
3703b12308fSSergey Ryazanov 
3711654861fSSergey Ryazanov 	devid = ar5312_rst_reg_read(AR5312_REV);
3721654861fSSergey Ryazanov 	devid >>= AR5312_REV_WMAC_MIN_S;
3731654861fSSergey Ryazanov 	devid &= AR5312_REV_CHIP;
3741654861fSSergey Ryazanov 	ath25_board.devid = (u16)devid;
3751654861fSSergey Ryazanov 
3763b12308fSSergey Ryazanov 	/* Clear any lingering AHB errors */
3773b12308fSSergey Ryazanov 	ar5312_rst_reg_read(AR5312_PROCADDR);
3783b12308fSSergey Ryazanov 	ar5312_rst_reg_read(AR5312_DMAADDR);
3793b12308fSSergey Ryazanov 	ar5312_rst_reg_write(AR5312_WDT_CTRL, AR5312_WDT_CTRL_IGNORE);
3803b12308fSSergey Ryazanov 
3813b12308fSSergey Ryazanov 	_machine_restart = ar5312_restart;
3823b12308fSSergey Ryazanov }
3831ac91b1fSSergey Ryazanov 
ar5312_arch_init(void)3841ac91b1fSSergey Ryazanov void __init ar5312_arch_init(void)
3851ac91b1fSSergey Ryazanov {
3861ac91b1fSSergey Ryazanov 	unsigned irq = irq_create_mapping(ar5312_misc_irq_domain,
3871ac91b1fSSergey Ryazanov 					  AR5312_MISC_IRQ_UART0);
3881ac91b1fSSergey Ryazanov 
3891ac91b1fSSergey Ryazanov 	ath25_serial_setup(AR5312_UART0_BASE, irq, ar5312_sys_frequency());
3901ac91b1fSSergey Ryazanov }
391