common.c 10.0 KB
Newer Older
1
/*
2
 * arch/arm/mach-orion5x/common.c
3
 *
4
 * Core functions for Marvell Orion 5x SoCs
5 6 7
 *
 * Maintainer: Tzachi Perelstein <tzachi@marvell.com>
 *
L
Lennert Buytenhek 已提交
8 9
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
10 11 12 13 14
 * warranty of any kind, whether express or implied.
 */

#include <linux/kernel.h>
#include <linux/init.h>
15 16
#include <linux/platform_device.h>
#include <linux/serial_8250.h>
17
#include <linux/mbus.h>
18
#include <linux/mv643xx_eth.h>
19
#include <linux/mv643xx_i2c.h>
20
#include <linux/ata_platform.h>
21
#include <asm/page.h>
22
#include <asm/setup.h>
23
#include <asm/timex.h>
24
#include <asm/mach/arch.h>
25
#include <asm/mach/map.h>
26
#include <asm/mach/time.h>
27
#include <asm/arch/hardware.h>
28
#include <asm/arch/orion5x.h>
29
#include <asm/plat-orion/ehci-orion.h>
30
#include <asm/plat-orion/orion_nand.h>
31
#include <asm/plat-orion/time.h>
32 33 34 35 36
#include "common.h"

/*****************************************************************************
 * I/O Address Mapping
 ****************************************************************************/
37
static struct map_desc orion5x_io_desc[] __initdata = {
38
	{
39 40 41
		.virtual	= ORION5X_REGS_VIRT_BASE,
		.pfn		= __phys_to_pfn(ORION5X_REGS_PHYS_BASE),
		.length		= ORION5X_REGS_SIZE,
42 43 44
		.type		= MT_DEVICE
	},
	{
45 46 47
		.virtual	= ORION5X_PCIE_IO_VIRT_BASE,
		.pfn		= __phys_to_pfn(ORION5X_PCIE_IO_PHYS_BASE),
		.length		= ORION5X_PCIE_IO_SIZE,
48 49 50
		.type		= MT_DEVICE
	},
	{
51 52 53
		.virtual	= ORION5X_PCI_IO_VIRT_BASE,
		.pfn		= __phys_to_pfn(ORION5X_PCI_IO_PHYS_BASE),
		.length		= ORION5X_PCI_IO_SIZE,
54 55 56
		.type		= MT_DEVICE
	},
	{
57 58 59
		.virtual	= ORION5X_PCIE_WA_VIRT_BASE,
		.pfn		= __phys_to_pfn(ORION5X_PCIE_WA_PHYS_BASE),
		.length		= ORION5X_PCIE_WA_SIZE,
60 61 62 63
		.type		= MT_DEVICE
	},
};

64
void __init orion5x_map_io(void)
65
{
66
	iotable_init(orion5x_io_desc, ARRAY_SIZE(orion5x_io_desc));
67
}
68

69 70 71 72
/*****************************************************************************
 * UART
 ****************************************************************************/

73
static struct resource orion5x_uart_resources[] = {
74
	{
75 76
		.start		= UART0_PHYS_BASE,
		.end		= UART0_PHYS_BASE + 0xff,
77 78 79
		.flags		= IORESOURCE_MEM,
	},
	{
80 81
		.start		= IRQ_ORION5X_UART0,
		.end		= IRQ_ORION5X_UART0,
82 83 84
		.flags		= IORESOURCE_IRQ,
	},
	{
85 86
		.start		= UART1_PHYS_BASE,
		.end		= UART1_PHYS_BASE + 0xff,
87 88 89
		.flags		= IORESOURCE_MEM,
	},
	{
90 91
		.start		= IRQ_ORION5X_UART1,
		.end		= IRQ_ORION5X_UART1,
92 93 94 95
		.flags		= IORESOURCE_IRQ,
	},
};

96
static struct plat_serial8250_port orion5x_uart_data[] = {
97
	{
98 99
		.mapbase	= UART0_PHYS_BASE,
		.membase	= (char *)UART0_VIRT_BASE,
100
		.irq		= IRQ_ORION5X_UART0,
101 102 103
		.flags		= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
104
		.uartclk	= ORION5X_TCLK,
105 106
	},
	{
107 108
		.mapbase	= UART1_PHYS_BASE,
		.membase	= (char *)UART1_VIRT_BASE,
109
		.irq		= IRQ_ORION5X_UART1,
110 111 112
		.flags		= UPF_SKIP_TEST | UPF_BOOT_AUTOCONF,
		.iotype		= UPIO_MEM,
		.regshift	= 2,
113
		.uartclk	= ORION5X_TCLK,
114 115 116 117
	},
	{ },
};

118
static struct platform_device orion5x_uart = {
119 120 121
	.name			= "serial8250",
	.id			= PLAT8250_DEV_PLATFORM,
	.dev			= {
122
		.platform_data	= orion5x_uart_data,
123
	},
124 125
	.resource		= orion5x_uart_resources,
	.num_resources		= ARRAY_SIZE(orion5x_uart_resources),
126 127 128 129 130 131
};

/*******************************************************************************
 * USB Controller - 2 interfaces
 ******************************************************************************/

132
static struct resource orion5x_ehci0_resources[] = {
133
	{
134
		.start	= ORION5X_USB0_PHYS_BASE,
135
		.end	= ORION5X_USB0_PHYS_BASE + SZ_4K - 1,
136 137 138
		.flags	= IORESOURCE_MEM,
	},
	{
139 140
		.start	= IRQ_ORION5X_USB0_CTRL,
		.end	= IRQ_ORION5X_USB0_CTRL,
141 142 143 144
		.flags	= IORESOURCE_IRQ,
	},
};

145
static struct resource orion5x_ehci1_resources[] = {
146
	{
147
		.start	= ORION5X_USB1_PHYS_BASE,
148
		.end	= ORION5X_USB1_PHYS_BASE + SZ_4K - 1,
149 150 151
		.flags	= IORESOURCE_MEM,
	},
	{
152 153
		.start	= IRQ_ORION5X_USB1_CTRL,
		.end	= IRQ_ORION5X_USB1_CTRL,
154 155 156 157
		.flags	= IORESOURCE_IRQ,
	},
};

158 159
static struct orion_ehci_data orion5x_ehci_data = {
	.dram		= &orion5x_mbus_dram_info,
160 161
};

162 163
static u64 ehci_dmamask = 0xffffffffUL;

164
static struct platform_device orion5x_ehci0 = {
165 166 167 168 169
	.name		= "orion-ehci",
	.id		= 0,
	.dev		= {
		.dma_mask		= &ehci_dmamask,
		.coherent_dma_mask	= 0xffffffff,
170
		.platform_data		= &orion5x_ehci_data,
171
	},
172 173
	.resource	= orion5x_ehci0_resources,
	.num_resources	= ARRAY_SIZE(orion5x_ehci0_resources),
174 175
};

176
static struct platform_device orion5x_ehci1 = {
177 178 179 180 181
	.name		= "orion-ehci",
	.id		= 1,
	.dev		= {
		.dma_mask		= &ehci_dmamask,
		.coherent_dma_mask	= 0xffffffff,
182
		.platform_data		= &orion5x_ehci_data,
183
	},
184 185
	.resource	= orion5x_ehci1_resources,
	.num_resources	= ARRAY_SIZE(orion5x_ehci1_resources),
186 187
};

188 189 190 191 192
/*****************************************************************************
 * Gigabit Ethernet port
 * (The Orion and Discovery (MV643xx) families use the same Ethernet driver)
 ****************************************************************************/

193
static struct resource orion5x_eth_shared_resources[] = {
194
	{
195 196
		.start	= ORION5X_ETH_PHYS_BASE + 0x2000,
		.end	= ORION5X_ETH_PHYS_BASE + 0x3fff,
197 198 199 200
		.flags	= IORESOURCE_MEM,
	},
};

201
static struct platform_device orion5x_eth_shared = {
202 203 204
	.name		= MV643XX_ETH_SHARED_NAME,
	.id		= 0,
	.num_resources	= 1,
205
	.resource	= orion5x_eth_shared_resources,
206 207
};

208
static struct resource orion5x_eth_resources[] = {
209 210
	{
		.name	= "eth irq",
211 212
		.start	= IRQ_ORION5X_ETH_SUM,
		.end	= IRQ_ORION5X_ETH_SUM,
213 214 215 216
		.flags	= IORESOURCE_IRQ,
	}
};

217
static struct platform_device orion5x_eth = {
218 219 220
	.name		= MV643XX_ETH_NAME,
	.id		= 0,
	.num_resources	= 1,
221
	.resource	= orion5x_eth_resources,
222 223
};

224
void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data)
225
{
226
	eth_data->shared = &orion5x_eth_shared;
227
	orion5x_eth.dev.platform_data = eth_data;
228

229 230
	platform_device_register(&orion5x_eth_shared);
	platform_device_register(&orion5x_eth);
231 232
}

233 234 235 236 237
/*****************************************************************************
 * I2C controller
 * (The Orion and Discovery (MV643xx) families share the same I2C controller)
 ****************************************************************************/

238
static struct mv64xxx_i2c_pdata orion5x_i2c_pdata = {
239 240 241 242 243
	.freq_m		= 8, /* assumes 166 MHz TCLK */
	.freq_n		= 3,
	.timeout	= 1000, /* Default timeout of 1 second */
};

244
static struct resource orion5x_i2c_resources[] = {
245 246
	{
		.name   = "i2c base",
247 248
		.start  = I2C_PHYS_BASE,
		.end    = I2C_PHYS_BASE + 0x20 -1,
249 250 251 252
		.flags  = IORESOURCE_MEM,
	},
	{
		.name   = "i2c irq",
253 254
		.start  = IRQ_ORION5X_I2C,
		.end    = IRQ_ORION5X_I2C,
255 256 257 258
		.flags  = IORESOURCE_IRQ,
	},
};

259
static struct platform_device orion5x_i2c = {
260 261
	.name		= MV64XXX_I2C_CTLR_NAME,
	.id		= 0,
262 263
	.num_resources	= ARRAY_SIZE(orion5x_i2c_resources),
	.resource	= orion5x_i2c_resources,
264
	.dev		= {
265
		.platform_data = &orion5x_i2c_pdata,
266 267 268
	},
};

269 270 271
/*****************************************************************************
 * Sata port
 ****************************************************************************/
272
static struct resource orion5x_sata_resources[] = {
273 274
        {
                .name   = "sata base",
275 276
                .start  = ORION5X_SATA_PHYS_BASE,
                .end    = ORION5X_SATA_PHYS_BASE + 0x5000 - 1,
277 278 279 280
                .flags  = IORESOURCE_MEM,
        },
	{
                .name   = "sata irq",
281 282
                .start  = IRQ_ORION5X_SATA,
                .end    = IRQ_ORION5X_SATA,
283 284 285 286
                .flags  = IORESOURCE_IRQ,
        },
};

287
static struct platform_device orion5x_sata = {
288 289 290 291 292
	.name           = "sata_mv",
	.id             = 0,
	.dev		= {
		.coherent_dma_mask	= 0xffffffff,
	},
293 294
	.num_resources  = ARRAY_SIZE(orion5x_sata_resources),
	.resource       = orion5x_sata_resources,
295 296
};

297
void __init orion5x_sata_init(struct mv_sata_platform_data *sata_data)
298
{
299 300 301
	sata_data->dram = &orion5x_mbus_dram_info;
	orion5x_sata.dev.platform_data = sata_data;
	platform_device_register(&orion5x_sata);
302 303
}

304 305 306 307
/*****************************************************************************
 * Time handling
 ****************************************************************************/

308
static void orion5x_timer_init(void)
309
{
310
	orion_time_init(IRQ_ORION5X_BRIDGE, ORION5X_TCLK);
311 312
}

313 314
struct sys_timer orion5x_timer = {
        .init = orion5x_timer_init,
315 316
};

317 318 319 320 321
/*****************************************************************************
 * General
 ****************************************************************************/

/*
322
 * Identify device ID and rev from PCIe configuration header space '0'.
323
 */
324
static void __init orion5x_id(u32 *dev, u32 *rev, char **dev_name)
325
{
326
	orion5x_pcie_id(dev, rev);
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

	if (*dev == MV88F5281_DEV_ID) {
		if (*rev == MV88F5281_REV_D2) {
			*dev_name = "MV88F5281-D2";
		} else if (*rev == MV88F5281_REV_D1) {
			*dev_name = "MV88F5281-D1";
		} else {
			*dev_name = "MV88F5281-Rev-Unsupported";
		}
	} else if (*dev == MV88F5182_DEV_ID) {
		if (*rev == MV88F5182_REV_A2) {
			*dev_name = "MV88F5182-A2";
		} else {
			*dev_name = "MV88F5182-Rev-Unsupported";
		}
342 343 344 345 346 347
	} else if (*dev == MV88F5181_DEV_ID) {
		if (*rev == MV88F5181_REV_B1) {
			*dev_name = "MV88F5181-Rev-B1";
		} else {
			*dev_name = "MV88F5181-Rev-Unsupported";
		}
348 349 350 351 352
	} else {
		*dev_name = "Device-Unknown";
	}
}

353
void __init orion5x_init(void)
354 355 356 357
{
	char *dev_name;
	u32 dev, rev;

358 359
	orion5x_id(&dev, &rev, &dev_name);
	printk(KERN_INFO "Orion ID: %s. TCLK=%d.\n", dev_name, ORION5X_TCLK);
360 361 362 363

	/*
	 * Setup Orion address map
	 */
364 365
	orion5x_setup_cpu_mbus_bridge();
	orion5x_setup_eth_wins();
366 367

	/*
L
Lennert Buytenhek 已提交
368
	 * Register devices.
369
	 */
370 371
	platform_device_register(&orion5x_uart);
	platform_device_register(&orion5x_ehci0);
372
	if (dev == MV88F5182_DEV_ID)
373 374
		platform_device_register(&orion5x_ehci1);
	platform_device_register(&orion5x_i2c);
375
}
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

/*
 * Many orion-based systems have buggy bootloader implementations.
 * This is a common fixup for bogus memory tags.
 */
void __init tag_fixup_mem32(struct machine_desc *mdesc, struct tag *t,
			    char **from, struct meminfo *meminfo)
{
	for (; t->hdr.size; t = tag_next(t))
		if (t->hdr.tag == ATAG_MEM &&
		    (!t->u.mem.size || t->u.mem.size & ~PAGE_MASK ||
		     t->u.mem.start & ~PAGE_MASK)) {
			printk(KERN_WARNING
			       "Clearing invalid memory bank %dKB@0x%08x\n",
			       t->u.mem.size / 1024, t->u.mem.start);
			t->hdr.tag = 0;
		}
}