platform.c 12.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5
/*
 * Platform device support for Au1x00 SoCs.
 *
 * Copyright 2004, Matt Porter <mporter@kernel.crashing.org>
 *
6 7 8
 * (C) Copyright Embedded Alley Solutions, Inc 2005
 * Author: Pantelis Antoniou <pantelis@embeddedalley.com>
 *
L
Linus Torvalds 已提交
9 10 11 12
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */
13

14
#include <linux/dma-mapping.h>
15
#include <linux/etherdevice.h>
16
#include <linux/platform_device.h>
17
#include <linux/serial_8250.h>
L
Linus Torvalds 已提交
18 19
#include <linux/init.h>

P
Pete Popov 已提交
20
#include <asm/mach-au1x00/au1xxx.h>
21 22
#include <asm/mach-au1x00/au1xxx_dbdma.h>
#include <asm/mach-au1x00/au1100_mmc.h>
23
#include <asm/mach-au1x00/au1xxx_eth.h>
L
Linus Torvalds 已提交
24

25 26
#include <prom.h>

M
Manuel Lauss 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
static void alchemy_8250_pm(struct uart_port *port, unsigned int state,
			    unsigned int old_state)
{
	switch (state) {
	case 0:
		if ((__raw_readl(port->membase + UART_MOD_CNTRL) & 3) != 3) {
			/* power-on sequence as suggested in the databooks */
			__raw_writel(0, port->membase + UART_MOD_CNTRL);
			wmb();
			__raw_writel(1, port->membase + UART_MOD_CNTRL);
			wmb();
		}
		__raw_writel(3, port->membase + UART_MOD_CNTRL); /* full on */
		wmb();
		serial8250_do_pm(port, state, old_state);
		break;
	case 3:		/* power off */
		serial8250_do_pm(port, state, old_state);
		__raw_writel(0, port->membase + UART_MOD_CNTRL);
		wmb();
		break;
	default:
		serial8250_do_pm(port, state, old_state);
		break;
	}
}

54 55 56 57 58 59
#define PORT(_base, _irq)					\
	{							\
		.mapbase	= _base,			\
		.irq		= _irq,				\
		.regshift	= 2,				\
		.iotype		= UPIO_AU,			\
60 61 62
		.flags		= UPF_SKIP_TEST | UPF_IOREMAP |	\
				  UPF_FIXED_TYPE,		\
		.type		= PORT_16550A,			\
M
Manuel Lauss 已提交
63
		.pm		= alchemy_8250_pm,		\
64 65 66 67
	}

static struct plat_serial8250_port au1x00_uart_data[] = {
#if defined(CONFIG_SOC_AU1000)
68 69 70 71
	PORT(UART0_PHYS_ADDR, AU1000_UART0_INT),
	PORT(UART1_PHYS_ADDR, AU1000_UART1_INT),
	PORT(UART2_PHYS_ADDR, AU1000_UART2_INT),
	PORT(UART3_PHYS_ADDR, AU1000_UART3_INT),
72
#elif defined(CONFIG_SOC_AU1500)
73 74
	PORT(UART0_PHYS_ADDR, AU1500_UART0_INT),
	PORT(UART3_PHYS_ADDR, AU1500_UART3_INT),
75
#elif defined(CONFIG_SOC_AU1100)
76 77 78
	PORT(UART0_PHYS_ADDR, AU1100_UART0_INT),
	PORT(UART1_PHYS_ADDR, AU1100_UART1_INT),
	PORT(UART3_PHYS_ADDR, AU1100_UART3_INT),
79
#elif defined(CONFIG_SOC_AU1550)
80 81 82
	PORT(UART0_PHYS_ADDR, AU1550_UART0_INT),
	PORT(UART1_PHYS_ADDR, AU1550_UART1_INT),
	PORT(UART3_PHYS_ADDR, AU1550_UART3_INT),
83
#elif defined(CONFIG_SOC_AU1200)
84 85
	PORT(UART0_PHYS_ADDR, AU1200_UART0_INT),
	PORT(UART1_PHYS_ADDR, AU1200_UART1_INT),
86 87 88 89 90 91 92 93 94 95 96 97
#endif
	{ },
};

static struct platform_device au1xx0_uart_device = {
	.name			= "serial8250",
	.id			= PLAT8250_DEV_AU1X00,
	.dev			= {
		.platform_data	= au1x00_uart_data,
	},
};

P
Pete Popov 已提交
98
/* OHCI (USB full speed host controller) */
L
Linus Torvalds 已提交
99 100 101
static struct resource au1xxx_usb_ohci_resources[] = {
	[0] = {
		.start		= USB_OHCI_BASE,
J
Jordan Crouse 已提交
102
		.end		= USB_OHCI_BASE + USB_OHCI_LEN - 1,
L
Linus Torvalds 已提交
103 104 105
		.flags		= IORESOURCE_MEM,
	},
	[1] = {
106 107
		.start		= FOR_PLATFORM_C_USB_HOST_INT,
		.end		= FOR_PLATFORM_C_USB_HOST_INT,
L
Linus Torvalds 已提交
108 109 110 111 112
		.flags		= IORESOURCE_IRQ,
	},
};

/* The dmamask must be set for OHCI to work */
113
static u64 ohci_dmamask = DMA_BIT_MASK(32);
L
Linus Torvalds 已提交
114 115 116 117 118 119

static struct platform_device au1xxx_usb_ohci_device = {
	.name		= "au1xxx-ohci",
	.id		= 0,
	.dev = {
		.dma_mask		= &ohci_dmamask,
120
		.coherent_dma_mask	= DMA_BIT_MASK(32),
L
Linus Torvalds 已提交
121 122 123 124 125
	},
	.num_resources	= ARRAY_SIZE(au1xxx_usb_ohci_resources),
	.resource	= au1xxx_usb_ohci_resources,
};

P
Pete Popov 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
/*** AU1100 LCD controller ***/

#ifdef CONFIG_FB_AU1100
static struct resource au1100_lcd_resources[] = {
	[0] = {
		.start          = LCD_PHYS_ADDR,
		.end            = LCD_PHYS_ADDR + 0x800 - 1,
		.flags          = IORESOURCE_MEM,
	},
	[1] = {
		.start          = AU1100_LCD_INT,
		.end            = AU1100_LCD_INT,
		.flags          = IORESOURCE_IRQ,
	}
};

142
static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32);
P
Pete Popov 已提交
143 144 145 146 147 148

static struct platform_device au1100_lcd_device = {
	.name           = "au1100-lcd",
	.id             = 0,
	.dev = {
		.dma_mask               = &au1100_lcd_dmamask,
149
		.coherent_dma_mask      = DMA_BIT_MASK(32),
P
Pete Popov 已提交
150 151 152 153 154 155
	},
	.num_resources  = ARRAY_SIZE(au1100_lcd_resources),
	.resource       = au1100_lcd_resources,
};
#endif

P
Pete Popov 已提交
156 157 158 159 160 161 162 163 164
#ifdef CONFIG_SOC_AU1200
/* EHCI (USB high speed host controller) */
static struct resource au1xxx_usb_ehci_resources[] = {
	[0] = {
		.start		= USB_EHCI_BASE,
		.end		= USB_EHCI_BASE + USB_EHCI_LEN - 1,
		.flags		= IORESOURCE_MEM,
	},
	[1] = {
165 166
		.start		= AU1200_USB_INT,
		.end		= AU1200_USB_INT,
P
Pete Popov 已提交
167 168 169 170
		.flags		= IORESOURCE_IRQ,
	},
};

171
static u64 ehci_dmamask = DMA_BIT_MASK(32);
P
Pete Popov 已提交
172 173 174 175 176 177

static struct platform_device au1xxx_usb_ehci_device = {
	.name		= "au1xxx-ehci",
	.id		= 0,
	.dev = {
		.dma_mask		= &ehci_dmamask,
178
		.coherent_dma_mask	= DMA_BIT_MASK(32),
P
Pete Popov 已提交
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
	},
	.num_resources	= ARRAY_SIZE(au1xxx_usb_ehci_resources),
	.resource	= au1xxx_usb_ehci_resources,
};

/* Au1200 UDC (USB gadget controller) */
static struct resource au1xxx_usb_gdt_resources[] = {
	[0] = {
		.start		= USB_UDC_BASE,
		.end		= USB_UDC_BASE + USB_UDC_LEN - 1,
		.flags		= IORESOURCE_MEM,
	},
	[1] = {
		.start		= AU1200_USB_INT,
		.end		= AU1200_USB_INT,
		.flags		= IORESOURCE_IRQ,
	},
};

198
static u64 udc_dmamask = DMA_BIT_MASK(32);
P
Pete Popov 已提交
199 200 201 202 203 204

static struct platform_device au1xxx_usb_gdt_device = {
	.name		= "au1xxx-udc",
	.id		= 0,
	.dev = {
		.dma_mask		= &udc_dmamask,
205
		.coherent_dma_mask	= DMA_BIT_MASK(32),
P
Pete Popov 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	},
	.num_resources	= ARRAY_SIZE(au1xxx_usb_gdt_resources),
	.resource	= au1xxx_usb_gdt_resources,
};

/* Au1200 UOC (USB OTG controller) */
static struct resource au1xxx_usb_otg_resources[] = {
	[0] = {
		.start		= USB_UOC_BASE,
		.end		= USB_UOC_BASE + USB_UOC_LEN - 1,
		.flags		= IORESOURCE_MEM,
	},
	[1] = {
		.start		= AU1200_USB_INT,
		.end		= AU1200_USB_INT,
		.flags		= IORESOURCE_IRQ,
	},
};

225
static u64 uoc_dmamask = DMA_BIT_MASK(32);
P
Pete Popov 已提交
226 227 228 229 230 231

static struct platform_device au1xxx_usb_otg_device = {
	.name		= "au1xxx-uoc",
	.id		= 0,
	.dev = {
		.dma_mask		= &uoc_dmamask,
232
		.coherent_dma_mask	= DMA_BIT_MASK(32),
P
Pete Popov 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
	},
	.num_resources	= ARRAY_SIZE(au1xxx_usb_otg_resources),
	.resource	= au1xxx_usb_otg_resources,
};

static struct resource au1200_lcd_resources[] = {
	[0] = {
		.start          = LCD_PHYS_ADDR,
		.end            = LCD_PHYS_ADDR + 0x800 - 1,
		.flags          = IORESOURCE_MEM,
	},
	[1] = {
		.start          = AU1200_LCD_INT,
		.end            = AU1200_LCD_INT,
		.flags          = IORESOURCE_IRQ,
	}
};

251
static u64 au1200_lcd_dmamask = DMA_BIT_MASK(32);
P
Pete Popov 已提交
252 253 254 255 256 257

static struct platform_device au1200_lcd_device = {
	.name           = "au1200-lcd",
	.id             = 0,
	.dev = {
		.dma_mask               = &au1200_lcd_dmamask,
258
		.coherent_dma_mask      = DMA_BIT_MASK(32),
P
Pete Popov 已提交
259 260 261 262
	},
	.num_resources  = ARRAY_SIZE(au1200_lcd_resources),
	.resource       = au1200_lcd_resources,
};
P
Pete Popov 已提交
263

264
static u64 au1xxx_mmc_dmamask =  DMA_BIT_MASK(32);
265

266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
extern struct au1xmmc_platform_data au1xmmc_platdata[2];

static struct resource au1200_mmc0_resources[] = {
	[0] = {
		.start          = SD0_PHYS_ADDR,
		.end            = SD0_PHYS_ADDR + 0x7ffff,
		.flags          = IORESOURCE_MEM,
	},
	[1] = {
		.start		= AU1200_SD_INT,
		.end		= AU1200_SD_INT,
		.flags		= IORESOURCE_IRQ,
	},
	[2] = {
		.start		= DSCR_CMD0_SDMS_TX0,
		.end		= DSCR_CMD0_SDMS_TX0,
		.flags		= IORESOURCE_DMA,
	},
	[3] = {
		.start          = DSCR_CMD0_SDMS_RX0,
		.end		= DSCR_CMD0_SDMS_RX0,
		.flags          = IORESOURCE_DMA,
	}
};

static struct platform_device au1200_mmc0_device = {
292 293 294
	.name = "au1xxx-mmc",
	.id = 0,
	.dev = {
295
		.dma_mask		= &au1xxx_mmc_dmamask,
296
		.coherent_dma_mask	= DMA_BIT_MASK(32),
297
		.platform_data		= &au1xmmc_platdata[0],
298
	},
299 300
	.num_resources	= ARRAY_SIZE(au1200_mmc0_resources),
	.resource	= au1200_mmc0_resources,
301
};
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331

#ifndef CONFIG_MIPS_DB1200
static struct resource au1200_mmc1_resources[] = {
	[0] = {
		.start          = SD1_PHYS_ADDR,
		.end            = SD1_PHYS_ADDR + 0x7ffff,
		.flags          = IORESOURCE_MEM,
	},
	[1] = {
		.start		= AU1200_SD_INT,
		.end		= AU1200_SD_INT,
		.flags		= IORESOURCE_IRQ,
	},
	[2] = {
		.start		= DSCR_CMD0_SDMS_TX1,
		.end		= DSCR_CMD0_SDMS_TX1,
		.flags		= IORESOURCE_DMA,
	},
	[3] = {
		.start          = DSCR_CMD0_SDMS_RX1,
		.end		= DSCR_CMD0_SDMS_RX1,
		.flags          = IORESOURCE_DMA,
	}
};

static struct platform_device au1200_mmc1_device = {
	.name = "au1xxx-mmc",
	.id = 1,
	.dev = {
		.dma_mask		= &au1xxx_mmc_dmamask,
332
		.coherent_dma_mask	= DMA_BIT_MASK(32),
333 334 335 336 337 338
		.platform_data		= &au1xmmc_platdata[1],
	},
	.num_resources	= ARRAY_SIZE(au1200_mmc1_resources),
	.resource	= au1200_mmc1_resources,
};
#endif /* #ifndef CONFIG_MIPS_DB1200 */
339 340
#endif /* #ifdef CONFIG_SOC_AU1200 */

341 342 343 344
/* All Alchemy demoboards with I2C have this #define in their headers */
#ifdef SMBUS_PSC_BASE
static struct resource pbdb_smbus_resources[] = {
	{
345 346
		.start	= CPHYSADDR(SMBUS_PSC_BASE),
		.end	= CPHYSADDR(SMBUS_PSC_BASE + 0xfffff),
347 348 349 350 351 352 353 354 355 356 357 358
		.flags	= IORESOURCE_MEM,
	},
};

static struct platform_device pbdb_smbus_device = {
	.name		= "au1xpsc_smbus",
	.id		= 0,	/* bus number */
	.num_resources	= ARRAY_SIZE(pbdb_smbus_resources),
	.resource	= pbdb_smbus_resources,
};
#endif

359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
/* Macro to help defining the Ethernet MAC resources */
#define MAC_RES(_base, _enable, _irq)			\
	{						\
		.start	= CPHYSADDR(_base),		\
		.end	= CPHYSADDR(_base + 0xffff),	\
		.flags	= IORESOURCE_MEM,		\
	},						\
	{						\
		.start	= CPHYSADDR(_enable),		\
		.end	= CPHYSADDR(_enable + 0x3),	\
		.flags	= IORESOURCE_MEM,		\
	},						\
	{						\
		.start	= _irq,				\
		.end	= _irq,				\
		.flags	= IORESOURCE_IRQ		\
	}

static struct resource au1xxx_eth0_resources[] = {
#if defined(CONFIG_SOC_AU1000)
	MAC_RES(AU1000_ETH0_BASE, AU1000_MAC0_ENABLE, AU1000_MAC0_DMA_INT),
#elif defined(CONFIG_SOC_AU1100)
	MAC_RES(AU1100_ETH0_BASE, AU1100_MAC0_ENABLE, AU1100_MAC0_DMA_INT),
#elif defined(CONFIG_SOC_AU1550)
	MAC_RES(AU1550_ETH0_BASE, AU1550_MAC0_ENABLE, AU1550_MAC0_DMA_INT),
#elif defined(CONFIG_SOC_AU1500)
	MAC_RES(AU1500_ETH0_BASE, AU1500_MAC0_ENABLE, AU1500_MAC0_DMA_INT),
#endif
};


static struct au1000_eth_platform_data au1xxx_eth0_platform_data = {
	.phy1_search_mac0 = 1,
};

static struct platform_device au1xxx_eth0_device = {
	.name		= "au1000-eth",
	.id		= 0,
	.num_resources	= ARRAY_SIZE(au1xxx_eth0_resources),
	.resource	= au1xxx_eth0_resources,
	.dev.platform_data = &au1xxx_eth0_platform_data,
};

#ifndef CONFIG_SOC_AU1100
403 404 405 406 407 408 409 410 411 412
static struct resource au1xxx_eth1_resources[] = {
#if defined(CONFIG_SOC_AU1000)
	MAC_RES(AU1000_ETH1_BASE, AU1000_MAC1_ENABLE, AU1000_MAC1_DMA_INT),
#elif defined(CONFIG_SOC_AU1550)
	MAC_RES(AU1550_ETH1_BASE, AU1550_MAC1_ENABLE, AU1550_MAC1_DMA_INT),
#elif defined(CONFIG_SOC_AU1500)
	MAC_RES(AU1500_ETH1_BASE, AU1500_MAC1_ENABLE, AU1500_MAC1_DMA_INT),
#endif
};

413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
static struct au1000_eth_platform_data au1xxx_eth1_platform_data = {
	.phy1_search_mac0 = 1,
};

static struct platform_device au1xxx_eth1_device = {
	.name		= "au1000-eth",
	.id		= 1,
	.num_resources	= ARRAY_SIZE(au1xxx_eth1_resources),
	.resource	= au1xxx_eth1_resources,
	.dev.platform_data = &au1xxx_eth1_platform_data,
};
#endif

void __init au1xxx_override_eth_cfg(unsigned int port,
			struct au1000_eth_platform_data *eth_data)
{
	if (!eth_data || port > 1)
		return;

	if (port == 0)
		memcpy(&au1xxx_eth0_platform_data, eth_data,
			sizeof(struct au1000_eth_platform_data));
#ifndef CONFIG_SOC_AU1100
	else
		memcpy(&au1xxx_eth1_platform_data, eth_data,
			sizeof(struct au1000_eth_platform_data));
#endif
}

L
Linus Torvalds 已提交
442
static struct platform_device *au1xxx_platform_devices[] __initdata = {
443
	&au1xx0_uart_device,
L
Linus Torvalds 已提交
444
	&au1xxx_usb_ohci_device,
P
Pete Popov 已提交
445 446 447
#ifdef CONFIG_FB_AU1100
	&au1100_lcd_device,
#endif
P
Pete Popov 已提交
448 449 450 451 452
#ifdef CONFIG_SOC_AU1200
	&au1xxx_usb_ehci_device,
	&au1xxx_usb_gdt_device,
	&au1xxx_usb_otg_device,
	&au1200_lcd_device,
453 454 455 456
	&au1200_mmc0_device,
#ifndef CONFIG_MIPS_DB1200
	&au1200_mmc1_device,
#endif
P
Pete Popov 已提交
457
#endif
458 459 460
#ifdef SMBUS_PSC_BASE
	&pbdb_smbus_device,
#endif
461
	&au1xxx_eth0_device,
L
Linus Torvalds 已提交
462 463
};

464
static int __init au1xxx_platform_init(void)
L
Linus Torvalds 已提交
465
{
466
	unsigned int uartclk = get_au1x00_uart_baud_base() * 16;
467
	int err, i;
468
	unsigned char ethaddr[6];
469 470

	/* Fill up uartclk. */
471
	for (i = 0; au1x00_uart_data[i].flags; i++)
472 473
		au1x00_uart_data[i].uartclk = uartclk;

474 475 476 477 478
	/* use firmware-provided mac addr if available and necessary */
	i = prom_get_ethernet_addr(ethaddr);
	if (!i && !is_valid_ether_addr(au1xxx_eth0_platform_data.mac))
		memcpy(au1xxx_eth0_platform_data.mac, ethaddr, 6);

479 480
	err = platform_add_devices(au1xxx_platform_devices,
				   ARRAY_SIZE(au1xxx_platform_devices));
481
#ifndef CONFIG_SOC_AU1100
482 483 484 485
	ethaddr[5] += 1;	/* next addr for 2nd MAC */
	if (!i && !is_valid_ether_addr(au1xxx_eth1_platform_data.mac))
		memcpy(au1xxx_eth1_platform_data.mac, ethaddr, 6);

486
	/* Register second MAC if enabled in pinfunc */
487
	if (!err && !(au_readl(SYS_PINFUNC) & (u32)SYS_PF_NI2))
488
		err = platform_device_register(&au1xxx_eth1_device);
489 490
#endif

491
	return err;
L
Linus Torvalds 已提交
492 493 494
}

arch_initcall(au1xxx_platform_init);