xref: /openbmc/linux/arch/arm/mach-pxa/generic.c (revision 6f9182eb32a4e6c46813928bee50df71e3fd1c74)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  linux/arch/arm/mach-pxa/generic.c
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  *  Author:	Nicolas Pitre
51da177e4SLinus Torvalds  *  Created:	Jun 15, 2001
61da177e4SLinus Torvalds  *  Copyright:	MontaVista Software Inc.
71da177e4SLinus Torvalds  *
81da177e4SLinus Torvalds  * Code common to all PXA machines.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * This program is free software; you can redistribute it and/or modify
111da177e4SLinus Torvalds  * it under the terms of the GNU General Public License version 2 as
121da177e4SLinus Torvalds  * published by the Free Software Foundation.
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  * Since this file should be linked before any other machine specific file,
151da177e4SLinus Torvalds  * the __initcall() here will be executed first.  This serves as default
161da177e4SLinus Torvalds  * initialization stuff for PXA machines which can be overridden later if
171da177e4SLinus Torvalds  * need be.
181da177e4SLinus Torvalds  */
191da177e4SLinus Torvalds #include <linux/module.h>
201da177e4SLinus Torvalds #include <linux/kernel.h>
211da177e4SLinus Torvalds #include <linux/init.h>
221da177e4SLinus Torvalds #include <linux/delay.h>
231da177e4SLinus Torvalds #include <linux/device.h>
241da177e4SLinus Torvalds #include <linux/ioport.h>
251da177e4SLinus Torvalds #include <linux/pm.h>
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds #include <asm/hardware.h>
281da177e4SLinus Torvalds #include <asm/irq.h>
291da177e4SLinus Torvalds #include <asm/system.h>
301da177e4SLinus Torvalds #include <asm/pgtable.h>
311da177e4SLinus Torvalds #include <asm/mach/map.h>
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #include <asm/arch/pxa-regs.h>
341da177e4SLinus Torvalds #include <asm/arch/udc.h>
351da177e4SLinus Torvalds #include <asm/arch/pxafb.h>
361da177e4SLinus Torvalds #include <asm/arch/mmc.h>
37eb9181a2SRussell King #include <asm/arch/i2c.h>
381da177e4SLinus Torvalds 
391da177e4SLinus Torvalds #include "generic.h"
401da177e4SLinus Torvalds 
411da177e4SLinus Torvalds /*
421da177e4SLinus Torvalds  * Handy function to set GPIO alternate functions
431da177e4SLinus Torvalds  */
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds void pxa_gpio_mode(int gpio_mode)
461da177e4SLinus Torvalds {
471da177e4SLinus Torvalds 	unsigned long flags;
481da177e4SLinus Torvalds 	int gpio = gpio_mode & GPIO_MD_MASK_NR;
491da177e4SLinus Torvalds 	int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
501da177e4SLinus Torvalds 	int gafr;
511da177e4SLinus Torvalds 
521da177e4SLinus Torvalds 	local_irq_save(flags);
531da177e4SLinus Torvalds 	if (gpio_mode & GPIO_DFLT_LOW)
541da177e4SLinus Torvalds 		GPCR(gpio) = GPIO_bit(gpio);
551da177e4SLinus Torvalds 	else if (gpio_mode & GPIO_DFLT_HIGH)
561da177e4SLinus Torvalds 		GPSR(gpio) = GPIO_bit(gpio);
571da177e4SLinus Torvalds 	if (gpio_mode & GPIO_MD_MASK_DIR)
581da177e4SLinus Torvalds 		GPDR(gpio) |= GPIO_bit(gpio);
591da177e4SLinus Torvalds 	else
601da177e4SLinus Torvalds 		GPDR(gpio) &= ~GPIO_bit(gpio);
611da177e4SLinus Torvalds 	gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
621da177e4SLinus Torvalds 	GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
631da177e4SLinus Torvalds 	local_irq_restore(flags);
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
661da177e4SLinus Torvalds EXPORT_SYMBOL(pxa_gpio_mode);
671da177e4SLinus Torvalds 
681da177e4SLinus Torvalds /*
691da177e4SLinus Torvalds  * Routine to safely enable or disable a clock in the CKEN
701da177e4SLinus Torvalds  */
711da177e4SLinus Torvalds void pxa_set_cken(int clock, int enable)
721da177e4SLinus Torvalds {
731da177e4SLinus Torvalds 	unsigned long flags;
741da177e4SLinus Torvalds 	local_irq_save(flags);
751da177e4SLinus Torvalds 
761da177e4SLinus Torvalds 	if (enable)
771da177e4SLinus Torvalds 		CKEN |= clock;
781da177e4SLinus Torvalds 	else
791da177e4SLinus Torvalds 		CKEN &= ~clock;
801da177e4SLinus Torvalds 
811da177e4SLinus Torvalds 	local_irq_restore(flags);
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds 
841da177e4SLinus Torvalds EXPORT_SYMBOL(pxa_set_cken);
851da177e4SLinus Torvalds 
861da177e4SLinus Torvalds /*
871da177e4SLinus Torvalds  * Intel PXA2xx internal register mapping.
881da177e4SLinus Torvalds  *
891da177e4SLinus Torvalds  * Note 1: not all PXA2xx variants implement all those addresses.
901da177e4SLinus Torvalds  *
911da177e4SLinus Torvalds  * Note 2: virtual 0xfffe0000-0xffffffff is reserved for the vector table
921da177e4SLinus Torvalds  *         and cache flush area.
931da177e4SLinus Torvalds  */
941da177e4SLinus Torvalds static struct map_desc standard_io_desc[] __initdata = {
95*6f9182ebSDeepak Saxena   	{	/* Devs */
96*6f9182ebSDeepak Saxena 		.virtual	=  0xf2000000,
97*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x40000000),
98*6f9182ebSDeepak Saxena 		.length		= 0x02000000,
99*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
100*6f9182ebSDeepak Saxena 	}, {	/* LCD */
101*6f9182ebSDeepak Saxena 		.virtual	=  0xf4000000,
102*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x44000000),
103*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
104*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
105*6f9182ebSDeepak Saxena 	}, {	/* Mem Ctl */
106*6f9182ebSDeepak Saxena 		.virtual	=  0xf6000000,
107*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x48000000),
108*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
109*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
110*6f9182ebSDeepak Saxena 	}, {	/* USB host */
111*6f9182ebSDeepak Saxena 		.virtual	=  0xf8000000,
112*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x4c000000),
113*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
114*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
115*6f9182ebSDeepak Saxena 	}, {	/* Camera */
116*6f9182ebSDeepak Saxena 		.virtual	=  0xfa000000,
117*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x50000000),
118*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
119*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
120*6f9182ebSDeepak Saxena 	}, {	/* IMem ctl */
121*6f9182ebSDeepak Saxena 		.virtual	=  0xfe000000,
122*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x58000000),
123*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
124*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
125*6f9182ebSDeepak Saxena 	}, {	/* UNCACHED_PHYS_0 */
126*6f9182ebSDeepak Saxena 		.virtual	= 0xff000000,
127*6f9182ebSDeepak Saxena 		.pfn		= __phys_to_pfn(0x00000000),
128*6f9182ebSDeepak Saxena 		.length		= 0x00100000,
129*6f9182ebSDeepak Saxena 		.type		= MT_DEVICE
130*6f9182ebSDeepak Saxena 	}
1311da177e4SLinus Torvalds };
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds void __init pxa_map_io(void)
1341da177e4SLinus Torvalds {
1351da177e4SLinus Torvalds 	iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
1361da177e4SLinus Torvalds 	get_clk_frequency_khz(1);
1371da177e4SLinus Torvalds }
1381da177e4SLinus Torvalds 
1391da177e4SLinus Torvalds 
1401da177e4SLinus Torvalds static struct resource pxamci_resources[] = {
1411da177e4SLinus Torvalds 	[0] = {
1421da177e4SLinus Torvalds 		.start	= 0x41100000,
1431da177e4SLinus Torvalds 		.end	= 0x41100fff,
1441da177e4SLinus Torvalds 		.flags	= IORESOURCE_MEM,
1451da177e4SLinus Torvalds 	},
1461da177e4SLinus Torvalds 	[1] = {
1471da177e4SLinus Torvalds 		.start	= IRQ_MMC,
1481da177e4SLinus Torvalds 		.end	= IRQ_MMC,
1491da177e4SLinus Torvalds 		.flags	= IORESOURCE_IRQ,
1501da177e4SLinus Torvalds 	},
1511da177e4SLinus Torvalds };
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds static u64 pxamci_dmamask = 0xffffffffUL;
1541da177e4SLinus Torvalds 
1551da177e4SLinus Torvalds static struct platform_device pxamci_device = {
1561da177e4SLinus Torvalds 	.name		= "pxa2xx-mci",
1571da177e4SLinus Torvalds 	.id		= -1,
1581da177e4SLinus Torvalds 	.dev		= {
1591da177e4SLinus Torvalds 		.dma_mask = &pxamci_dmamask,
1601da177e4SLinus Torvalds 		.coherent_dma_mask = 0xffffffff,
1611da177e4SLinus Torvalds 	},
1621da177e4SLinus Torvalds 	.num_resources	= ARRAY_SIZE(pxamci_resources),
1631da177e4SLinus Torvalds 	.resource	= pxamci_resources,
1641da177e4SLinus Torvalds };
1651da177e4SLinus Torvalds 
1661da177e4SLinus Torvalds void __init pxa_set_mci_info(struct pxamci_platform_data *info)
1671da177e4SLinus Torvalds {
1681da177e4SLinus Torvalds 	pxamci_device.dev.platform_data = info;
1691da177e4SLinus Torvalds }
1701da177e4SLinus Torvalds 
1711da177e4SLinus Torvalds 
1721da177e4SLinus Torvalds static struct pxa2xx_udc_mach_info pxa_udc_info;
1731da177e4SLinus Torvalds 
1741da177e4SLinus Torvalds void __init pxa_set_udc_info(struct pxa2xx_udc_mach_info *info)
1751da177e4SLinus Torvalds {
1761da177e4SLinus Torvalds 	memcpy(&pxa_udc_info, info, sizeof *info);
1771da177e4SLinus Torvalds }
1781da177e4SLinus Torvalds 
1791da177e4SLinus Torvalds static struct resource pxa2xx_udc_resources[] = {
1801da177e4SLinus Torvalds 	[0] = {
1811da177e4SLinus Torvalds 		.start	= 0x40600000,
1821da177e4SLinus Torvalds 		.end	= 0x4060ffff,
1831da177e4SLinus Torvalds 		.flags	= IORESOURCE_MEM,
1841da177e4SLinus Torvalds 	},
1851da177e4SLinus Torvalds 	[1] = {
1861da177e4SLinus Torvalds 		.start	= IRQ_USB,
1871da177e4SLinus Torvalds 		.end	= IRQ_USB,
1881da177e4SLinus Torvalds 		.flags	= IORESOURCE_IRQ,
1891da177e4SLinus Torvalds 	},
1901da177e4SLinus Torvalds };
1911da177e4SLinus Torvalds 
1921da177e4SLinus Torvalds static u64 udc_dma_mask = ~(u32)0;
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds static struct platform_device udc_device = {
1951da177e4SLinus Torvalds 	.name		= "pxa2xx-udc",
1961da177e4SLinus Torvalds 	.id		= -1,
1971da177e4SLinus Torvalds 	.resource	= pxa2xx_udc_resources,
1981da177e4SLinus Torvalds 	.num_resources	= ARRAY_SIZE(pxa2xx_udc_resources),
1991da177e4SLinus Torvalds 	.dev		=  {
2001da177e4SLinus Torvalds 		.platform_data	= &pxa_udc_info,
2011da177e4SLinus Torvalds 		.dma_mask	= &udc_dma_mask,
2021da177e4SLinus Torvalds 	}
2031da177e4SLinus Torvalds };
2041da177e4SLinus Torvalds 
2051da177e4SLinus Torvalds static struct pxafb_mach_info pxa_fb_info;
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds void __init set_pxa_fb_info(struct pxafb_mach_info *hard_pxa_fb_info)
2081da177e4SLinus Torvalds {
2091da177e4SLinus Torvalds 	memcpy(&pxa_fb_info,hard_pxa_fb_info,sizeof(struct pxafb_mach_info));
2101da177e4SLinus Torvalds }
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds static struct resource pxafb_resources[] = {
2131da177e4SLinus Torvalds 	[0] = {
2141da177e4SLinus Torvalds 		.start	= 0x44000000,
2151da177e4SLinus Torvalds 		.end	= 0x4400ffff,
2161da177e4SLinus Torvalds 		.flags	= IORESOURCE_MEM,
2171da177e4SLinus Torvalds 	},
2181da177e4SLinus Torvalds 	[1] = {
2191da177e4SLinus Torvalds 		.start	= IRQ_LCD,
2201da177e4SLinus Torvalds 		.end	= IRQ_LCD,
2211da177e4SLinus Torvalds 		.flags	= IORESOURCE_IRQ,
2221da177e4SLinus Torvalds 	},
2231da177e4SLinus Torvalds };
2241da177e4SLinus Torvalds 
2251da177e4SLinus Torvalds static u64 fb_dma_mask = ~(u64)0;
2261da177e4SLinus Torvalds 
2271da177e4SLinus Torvalds static struct platform_device pxafb_device = {
2281da177e4SLinus Torvalds 	.name		= "pxa2xx-fb",
2291da177e4SLinus Torvalds 	.id		= -1,
2301da177e4SLinus Torvalds 	.dev		= {
2311da177e4SLinus Torvalds  		.platform_data	= &pxa_fb_info,
2321da177e4SLinus Torvalds 		.dma_mask	= &fb_dma_mask,
2331da177e4SLinus Torvalds 		.coherent_dma_mask = 0xffffffff,
2341da177e4SLinus Torvalds 	},
2351da177e4SLinus Torvalds 	.num_resources	= ARRAY_SIZE(pxafb_resources),
2361da177e4SLinus Torvalds 	.resource	= pxafb_resources,
2371da177e4SLinus Torvalds };
2381da177e4SLinus Torvalds 
239cb38c569SRichard Purdie void __init set_pxa_fb_parent(struct device *parent_dev)
240cb38c569SRichard Purdie {
241cb38c569SRichard Purdie 	pxafb_device.dev.parent = parent_dev;
242cb38c569SRichard Purdie }
243cb38c569SRichard Purdie 
2441da177e4SLinus Torvalds static struct platform_device ffuart_device = {
2451da177e4SLinus Torvalds 	.name		= "pxa2xx-uart",
2461da177e4SLinus Torvalds 	.id		= 0,
2471da177e4SLinus Torvalds };
2481da177e4SLinus Torvalds static struct platform_device btuart_device = {
2491da177e4SLinus Torvalds 	.name		= "pxa2xx-uart",
2501da177e4SLinus Torvalds 	.id		= 1,
2511da177e4SLinus Torvalds };
2521da177e4SLinus Torvalds static struct platform_device stuart_device = {
2531da177e4SLinus Torvalds 	.name		= "pxa2xx-uart",
2541da177e4SLinus Torvalds 	.id		= 2,
2551da177e4SLinus Torvalds };
2561da177e4SLinus Torvalds 
257bb9bffcbSRussell King static struct resource i2c_resources[] = {
258bb9bffcbSRussell King 	{
259bb9bffcbSRussell King 		.start	= 0x40301680,
260bb9bffcbSRussell King 		.end	= 0x403016a3,
261bb9bffcbSRussell King 		.flags	= IORESOURCE_MEM,
262bb9bffcbSRussell King 	}, {
263bb9bffcbSRussell King 		.start	= IRQ_I2C,
264bb9bffcbSRussell King 		.end	= IRQ_I2C,
265bb9bffcbSRussell King 		.flags	= IORESOURCE_IRQ,
266bb9bffcbSRussell King 	},
267bb9bffcbSRussell King };
268bb9bffcbSRussell King 
269bb9bffcbSRussell King static struct platform_device i2c_device = {
270bb9bffcbSRussell King 	.name		= "pxa2xx-i2c",
271bb9bffcbSRussell King 	.id		= 0,
272bb9bffcbSRussell King 	.resource	= i2c_resources,
273bb9bffcbSRussell King 	.num_resources	= ARRAY_SIZE(i2c_resources),
274bb9bffcbSRussell King };
275bb9bffcbSRussell King 
276bb9bffcbSRussell King void __init pxa_set_i2c_info(struct i2c_pxa_platform_data *info)
277bb9bffcbSRussell King {
278bb9bffcbSRussell King 	i2c_device.dev.platform_data = info;
279bb9bffcbSRussell King }
280bb9bffcbSRussell King 
281b2640b42SMatt Reimer static struct resource i2s_resources[] = {
282b2640b42SMatt Reimer 	{
283b2640b42SMatt Reimer 		.start	= 0x40400000,
284b2640b42SMatt Reimer 		.end	= 0x40400083,
285b2640b42SMatt Reimer 		.flags	= IORESOURCE_MEM,
286b2640b42SMatt Reimer 	}, {
287b2640b42SMatt Reimer 		.start	= IRQ_I2S,
288b2640b42SMatt Reimer 		.end	= IRQ_I2S,
289b2640b42SMatt Reimer 		.flags	= IORESOURCE_IRQ,
290b2640b42SMatt Reimer 	},
291b2640b42SMatt Reimer };
292b2640b42SMatt Reimer 
293b2640b42SMatt Reimer static struct platform_device i2s_device = {
294b2640b42SMatt Reimer 	.name		= "pxa2xx-i2s",
295b2640b42SMatt Reimer 	.id		= -1,
296b2640b42SMatt Reimer 	.resource	= i2c_resources,
297b2640b42SMatt Reimer 	.num_resources	= ARRAY_SIZE(i2s_resources),
298b2640b42SMatt Reimer };
299b2640b42SMatt Reimer 
3001da177e4SLinus Torvalds static struct platform_device *devices[] __initdata = {
3011da177e4SLinus Torvalds 	&pxamci_device,
3021da177e4SLinus Torvalds 	&udc_device,
3031da177e4SLinus Torvalds 	&pxafb_device,
3041da177e4SLinus Torvalds 	&ffuart_device,
3051da177e4SLinus Torvalds 	&btuart_device,
3061da177e4SLinus Torvalds 	&stuart_device,
307bb9bffcbSRussell King 	&i2c_device,
308b2640b42SMatt Reimer 	&i2s_device,
3091da177e4SLinus Torvalds };
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds static int __init pxa_init(void)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds 	return platform_add_devices(devices, ARRAY_SIZE(devices));
3141da177e4SLinus Torvalds }
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds subsys_initcall(pxa_init);
317