setup.c 12.5 KB
Newer Older
1 2 3 4 5 6 7
/*
 * Copyright (C) 2007 Atmel Corporation.
 * Copyright (C) 2011 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
 *
 * Under GPLv2
 */

8 9
#define pr_fmt(fmt)	"AT91: " fmt

10 11
#include <linux/module.h>
#include <linux/io.h>
12
#include <linux/mm.h>
13
#include <linux/pm.h>
14
#include <linux/of_address.h>
15
#include <linux/pinctrl/machine.h>
16
#include <linux/clk/at91_pmc.h>
17

18
#include <asm/system_misc.h>
19 20 21 22
#include <asm/mach/map.h>

#include <mach/hardware.h>
#include <mach/cpu.h>
23
#include <mach/at91_dbgu.h>
24 25 26

#include "soc.h"
#include "generic.h"
27
#include "pm.h"
28

29 30 31 32 33 34 35 36 37
struct at91_init_soc __initdata at91_boot_soc;

struct at91_socinfo at91_soc_initdata;
EXPORT_SYMBOL(at91_soc_initdata);

void __init at91rm9200_set_type(int type)
{
	if (type == ARCH_REVISON_9200_PQFP)
		at91_soc_initdata.subtype = AT91_SOC_RM9200_PQFP;
38 39 40
	else
		at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;

41
	pr_info("filled in soc subtype: %s\n",
42
		at91_get_soc_subtype(&at91_soc_initdata));
43
}
44

45 46 47 48 49 50 51 52 53 54 55
void __init at91_init_irq_default(void)
{
	at91_init_interrupts(at91_boot_soc.default_irq_priority);
}

void __init at91_init_interrupts(unsigned int *priority)
{
	/* Enable GPIO interrupts */
	at91_gpio_irq_setup();
}

56
void __iomem *at91_ramc_base[2];
57
EXPORT_SYMBOL_GPL(at91_ramc_base);
58 59 60 61 62 63 64 65 66

void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
{
	if (id < 0 || id > 1) {
		pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
		BUG();
	}
	at91_ramc_base[id] = ioremap(addr, size);
	if (!at91_ramc_base[id])
67
		panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
68 69
}

70 71 72 73 74 75
static struct map_desc sram_desc[2] __initdata;

void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
{
	struct map_desc *desc = &sram_desc[bank];

76
	desc->virtual = (unsigned long)AT91_IO_VIRT_BASE - length;
77 78 79 80 81
	if (bank > 0)
		desc->virtual -= sram_desc[bank - 1].length;

	desc->pfn = __phys_to_pfn(base);
	desc->length = length;
82
	desc->type = MT_MEMORY_RWX_NONCACHED;
83

84
	pr_info("sram at 0x%lx of 0x%x mapped at 0x%lx\n",
85 86 87 88 89
		base, length, desc->virtual);

	iotable_init(desc, 1);
}

90
static struct map_desc at91_io_desc __initdata __maybe_unused = {
91
	.virtual	= (unsigned long)AT91_VA_BASE_SYS,
92 93 94 95 96
	.pfn		= __phys_to_pfn(AT91_BASE_SYS),
	.length		= SZ_16K,
	.type		= MT_DEVICE,
};

97 98 99 100 101 102 103
static struct map_desc at91_alt_io_desc __initdata __maybe_unused = {
	.virtual	= (unsigned long)AT91_ALT_VA_BASE_SYS,
	.pfn		= __phys_to_pfn(AT91_ALT_BASE_SYS),
	.length		= 24 * SZ_1K,
	.type		= MT_DEVICE,
};

104
static void __init soc_detect(u32 dbgu_base)
105
{
106 107 108 109
	u32 cidr, socid;

	cidr = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
	socid = cidr & ~AT91_CIDR_VERSION;
110

111 112 113
	switch (socid) {
	case ARCH_ID_AT91RM9200:
		at91_soc_initdata.type = AT91_SOC_RM9200;
114
		if (at91_soc_initdata.subtype == AT91_SOC_SUBTYPE_UNKNOWN)
115
			at91_soc_initdata.subtype = AT91_SOC_RM9200_BGA;
116
		at91_boot_soc = at91rm9200_soc;
117 118 119 120
		break;

	case ARCH_ID_AT91SAM9260:
		at91_soc_initdata.type = AT91_SOC_SAM9260;
121
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
122
		at91_boot_soc = at91sam9260_soc;
123 124 125 126
		break;

	case ARCH_ID_AT91SAM9261:
		at91_soc_initdata.type = AT91_SOC_SAM9261;
127
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
128
		at91_boot_soc = at91sam9261_soc;
129 130 131 132
		break;

	case ARCH_ID_AT91SAM9263:
		at91_soc_initdata.type = AT91_SOC_SAM9263;
133
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
134
		at91_boot_soc = at91sam9263_soc;
135 136 137 138
		break;

	case ARCH_ID_AT91SAM9G20:
		at91_soc_initdata.type = AT91_SOC_SAM9G20;
139
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
140
		at91_boot_soc = at91sam9260_soc;
141 142 143 144 145 146
		break;

	case ARCH_ID_AT91SAM9G45:
		at91_soc_initdata.type = AT91_SOC_SAM9G45;
		if (cidr == ARCH_ID_AT91SAM9G45ES)
			at91_soc_initdata.subtype = AT91_SOC_SAM9G45ES;
147
		at91_boot_soc = at91sam9g45_soc;
148 149 150 151
		break;

	case ARCH_ID_AT91SAM9RL64:
		at91_soc_initdata.type = AT91_SOC_SAM9RL;
152
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
153
		at91_boot_soc = at91sam9rl_soc;
154 155 156 157
		break;

	case ARCH_ID_AT91SAM9X5:
		at91_soc_initdata.type = AT91_SOC_SAM9X5;
158
		at91_boot_soc = at91sam9x5_soc;
159
		break;
160 161 162 163 164

	case ARCH_ID_AT91SAM9N12:
		at91_soc_initdata.type = AT91_SOC_SAM9N12;
		at91_boot_soc = at91sam9n12_soc;
		break;
165

166 167 168 169 170 171
	case ARCH_ID_SAMA5:
		at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
		if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
			at91_soc_initdata.type = AT91_SOC_SAMA5D3;
			at91_boot_soc = sama5d3_soc;
		}
172
		break;
173 174 175
	}

	/* at91sam9g10 */
176
	if ((socid & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10) {
177
		at91_soc_initdata.type = AT91_SOC_SAM9G10;
178
		at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_NONE;
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
		at91_boot_soc = at91sam9261_soc;
	}
	/* at91sam9xe */
	else if ((cidr & AT91_CIDR_ARCH) == ARCH_FAMILY_AT91SAM9XE) {
		at91_soc_initdata.type = AT91_SOC_SAM9260;
		at91_soc_initdata.subtype = AT91_SOC_SAM9XE;
		at91_boot_soc = at91sam9260_soc;
	}

	if (!at91_soc_is_detected())
		return;

	at91_soc_initdata.cidr = cidr;

	/* sub version of soc */
194 195
	if (!at91_soc_initdata.exid)
		at91_soc_initdata.exid = __raw_readl(AT91_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229

	if (at91_soc_initdata.type == AT91_SOC_SAM9G45) {
		switch (at91_soc_initdata.exid) {
		case ARCH_EXID_AT91SAM9M10:
			at91_soc_initdata.subtype = AT91_SOC_SAM9M10;
			break;
		case ARCH_EXID_AT91SAM9G46:
			at91_soc_initdata.subtype = AT91_SOC_SAM9G46;
			break;
		case ARCH_EXID_AT91SAM9M11:
			at91_soc_initdata.subtype = AT91_SOC_SAM9M11;
			break;
		}
	}

	if (at91_soc_initdata.type == AT91_SOC_SAM9X5) {
		switch (at91_soc_initdata.exid) {
		case ARCH_EXID_AT91SAM9G15:
			at91_soc_initdata.subtype = AT91_SOC_SAM9G15;
			break;
		case ARCH_EXID_AT91SAM9G35:
			at91_soc_initdata.subtype = AT91_SOC_SAM9G35;
			break;
		case ARCH_EXID_AT91SAM9X35:
			at91_soc_initdata.subtype = AT91_SOC_SAM9X35;
			break;
		case ARCH_EXID_AT91SAM9G25:
			at91_soc_initdata.subtype = AT91_SOC_SAM9G25;
			break;
		case ARCH_EXID_AT91SAM9X25:
			at91_soc_initdata.subtype = AT91_SOC_SAM9X25;
			break;
		}
	}
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244

	if (at91_soc_initdata.type == AT91_SOC_SAMA5D3) {
		switch (at91_soc_initdata.exid) {
		case ARCH_EXID_SAMA5D31:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D31;
			break;
		case ARCH_EXID_SAMA5D33:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D33;
			break;
		case ARCH_EXID_SAMA5D34:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D34;
			break;
		case ARCH_EXID_SAMA5D35:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D35;
			break;
245 246 247
		case ARCH_EXID_SAMA5D36:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D36;
			break;
248 249
		}
	}
250 251
}

252 253 254 255 256 257 258 259 260 261 262 263 264 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 292 293 294 295 296 297 298 299
static void __init alt_soc_detect(u32 dbgu_base)
{
	u32 cidr, socid;

	/* SoC ID */
	cidr = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_CIDR);
	socid = cidr & ~AT91_CIDR_VERSION;

	switch (socid) {
	case ARCH_ID_SAMA5:
		at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);
		if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D3) {
			at91_soc_initdata.type = AT91_SOC_SAMA5D3;
			at91_boot_soc = sama5d3_soc;
		} else if (at91_soc_initdata.exid & ARCH_EXID_SAMA5D4) {
			at91_soc_initdata.type = AT91_SOC_SAMA5D4;
			at91_boot_soc = sama5d4_soc;
		}
		break;
	}

	if (!at91_soc_is_detected())
		return;

	at91_soc_initdata.cidr = cidr;

	/* sub version of soc */
	if (!at91_soc_initdata.exid)
		at91_soc_initdata.exid = __raw_readl(AT91_ALT_IO_P2V(dbgu_base) + AT91_DBGU_EXID);

	if (at91_soc_initdata.type == AT91_SOC_SAMA5D4) {
		switch (at91_soc_initdata.exid) {
		case ARCH_EXID_SAMA5D41:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D41;
			break;
		case ARCH_EXID_SAMA5D42:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D42;
			break;
		case ARCH_EXID_SAMA5D43:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D43;
			break;
		case ARCH_EXID_SAMA5D44:
			at91_soc_initdata.subtype = AT91_SOC_SAMA5D44;
			break;
		}
	}
}

300 301 302 303 304 305 306 307 308 309
static const char *soc_name[] = {
	[AT91_SOC_RM9200]	= "at91rm9200",
	[AT91_SOC_SAM9260]	= "at91sam9260",
	[AT91_SOC_SAM9261]	= "at91sam9261",
	[AT91_SOC_SAM9263]	= "at91sam9263",
	[AT91_SOC_SAM9G10]	= "at91sam9g10",
	[AT91_SOC_SAM9G20]	= "at91sam9g20",
	[AT91_SOC_SAM9G45]	= "at91sam9g45",
	[AT91_SOC_SAM9RL]	= "at91sam9rl",
	[AT91_SOC_SAM9X5]	= "at91sam9x5",
310
	[AT91_SOC_SAM9N12]	= "at91sam9n12",
311
	[AT91_SOC_SAMA5D3]	= "sama5d3",
312
	[AT91_SOC_SAMA5D4]	= "sama5d4",
313
	[AT91_SOC_UNKNOWN]	= "Unknown",
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
};

const char *at91_get_soc_type(struct at91_socinfo *c)
{
	return soc_name[c->type];
}
EXPORT_SYMBOL(at91_get_soc_type);

static const char *soc_subtype_name[] = {
	[AT91_SOC_RM9200_BGA]	= "at91rm9200 BGA",
	[AT91_SOC_RM9200_PQFP]	= "at91rm9200 PQFP",
	[AT91_SOC_SAM9XE]	= "at91sam9xe",
	[AT91_SOC_SAM9G45ES]	= "at91sam9g45es",
	[AT91_SOC_SAM9M10]	= "at91sam9m10",
	[AT91_SOC_SAM9G46]	= "at91sam9g46",
	[AT91_SOC_SAM9M11]	= "at91sam9m11",
	[AT91_SOC_SAM9G15]	= "at91sam9g15",
	[AT91_SOC_SAM9G35]	= "at91sam9g35",
	[AT91_SOC_SAM9X35]	= "at91sam9x35",
	[AT91_SOC_SAM9G25]	= "at91sam9g25",
	[AT91_SOC_SAM9X25]	= "at91sam9x25",
335 336 337 338
	[AT91_SOC_SAMA5D31]	= "sama5d31",
	[AT91_SOC_SAMA5D33]	= "sama5d33",
	[AT91_SOC_SAMA5D34]	= "sama5d34",
	[AT91_SOC_SAMA5D35]	= "sama5d35",
339
	[AT91_SOC_SAMA5D36]	= "sama5d36",
340 341 342 343
	[AT91_SOC_SAMA5D41]	= "sama5d41",
	[AT91_SOC_SAMA5D42]	= "sama5d42",
	[AT91_SOC_SAMA5D43]	= "sama5d43",
	[AT91_SOC_SAMA5D44]	= "sama5d44",
344 345
	[AT91_SOC_SUBTYPE_NONE]	= "None",
	[AT91_SOC_SUBTYPE_UNKNOWN] = "Unknown",
346 347 348 349 350 351 352 353 354 355 356 357 358
};

const char *at91_get_soc_subtype(struct at91_socinfo *c)
{
	return soc_subtype_name[c->subtype];
}
EXPORT_SYMBOL(at91_get_soc_subtype);

void __init at91_map_io(void)
{
	/* Map peripherals */
	iotable_init(&at91_io_desc, 1);

359 360
	at91_soc_initdata.type = AT91_SOC_UNKNOWN;
	at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;
361

362
	soc_detect(AT91_BASE_DBGU0);
363
	if (!at91_soc_is_detected())
364
		soc_detect(AT91_BASE_DBGU1);
365 366

	if (!at91_soc_is_detected())
367
		panic(pr_fmt("Impossible to detect the SOC type"));
368

369
	pr_info("Detected soc type: %s\n",
370
		at91_get_soc_type(&at91_soc_initdata));
371
	if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
372
		pr_info("Detected soc subtype: %s\n",
373
			at91_get_soc_subtype(&at91_soc_initdata));
374 375

	if (!at91_soc_is_enabled())
376
		panic(pr_fmt("Soc not enabled"));
377 378 379 380 381

	if (at91_boot_soc.map_io)
		at91_boot_soc.map_io();
}

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
void __init at91_alt_map_io(void)
{
	/* Map peripherals */
	iotable_init(&at91_alt_io_desc, 1);

	at91_soc_initdata.type = AT91_SOC_UNKNOWN;
	at91_soc_initdata.subtype = AT91_SOC_SUBTYPE_UNKNOWN;

	alt_soc_detect(AT91_BASE_DBGU2);
	if (!at91_soc_is_detected())
		panic("AT91: Impossible to detect the SOC type");

	pr_info("AT91: Detected soc type: %s\n",
		at91_get_soc_type(&at91_soc_initdata));
	if (at91_soc_initdata.subtype != AT91_SOC_SUBTYPE_NONE)
		pr_info("AT91: Detected soc subtype: %s\n",
			at91_get_soc_subtype(&at91_soc_initdata));

	if (!at91_soc_is_enabled())
		panic("AT91: Soc not enabled");

	if (at91_boot_soc.map_io)
		at91_boot_soc.map_io();
}

407
void __iomem *at91_matrix_base;
408
EXPORT_SYMBOL_GPL(at91_matrix_base);
409 410 411 412 413

void __init at91_ioremap_matrix(u32 base_addr)
{
	at91_matrix_base = ioremap(base_addr, 512);
	if (!at91_matrix_base)
414
		panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
415 416
}

417
#if defined(CONFIG_OF)
418
static struct of_device_id ramc_ids[] = {
419 420 421
	{ .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
	{ .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
	{ .compatible = "atmel,at91sam9g45-ddramc", .data = at91_ddr_standby },
422
	{ .compatible = "atmel,sama5d3-ddramc", .data = at91_ddr_standby },
423 424 425 426 427 428
	{ /*sentinel*/ }
};

static void at91_dt_ramc(void)
{
	struct device_node *np;
429
	const struct of_device_id *of_id;
430
	int idx = 0;
431
	const void *standby = NULL;
432

433
	for_each_matching_node_and_match(np, ramc_ids, &of_id) {
434 435 436
		at91_ramc_base[idx] = of_iomap(np, 0);
		if (!at91_ramc_base[idx])
			panic(pr_fmt("unable to map ramc[%d] cpu registers\n"), idx);
437

438 439
		if (!standby)
			standby = of_id->data;
440

441
		idx++;
442 443
	}

444 445
	if (!idx)
		panic(pr_fmt("unable to find compatible ram controller node in dtb\n"));
446

447
	if (!standby) {
448
		pr_warn("ramc no standby function available\n");
449
		return;
450 451
	}

452
	at91_pm_set_standby(standby);
453 454
}

455 456 457 458 459
void __init at91rm9200_dt_initialize(void)
{
	at91_dt_ramc();

	/* Register the processor-specific clocks */
460 461
	if (at91_boot_soc.register_clocks)
		at91_boot_soc.register_clocks();
462 463 464 465

	at91_boot_soc.init();
}

466 467
void __init at91_dt_initialize(void)
{
468
	at91_dt_ramc();
469 470

	/* Register the processor-specific clocks */
471 472
	if (at91_boot_soc.register_clocks)
		at91_boot_soc.register_clocks();
473

474 475
	if (at91_boot_soc.init)
		at91_boot_soc.init();
476 477 478
}
#endif

479 480
void __init at91_initialize(unsigned long main_clock)
{
481 482
	at91_boot_soc.ioremap_registers();

483 484 485
	/* Register the processor-specific clocks */
	at91_boot_soc.register_clocks();

486
	at91_boot_soc.init();
487 488

	pinctrl_provide_dummies();
489
}
490 491 492 493 494

void __init at91_register_devices(void)
{
	at91_boot_soc.register_devices();
}
495 496 497 498 499

void __init at91_init_time(void)
{
	at91_boot_soc.init_time();
}