summaryrefslogtreecommitdiffstats
path: root/arch/mips/powertv/asic/asic_devices.c
blob: 9f64c23878082c7e5622733486652381af0315b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
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
300
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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
403
404
405
406
407
408
409
410
411
412
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
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
 *
 * Description:	 Defines the platform resources for Gaia-based settops.
 *
 * Copyright (C) 2005-2009 Scientific-Atlanta, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * NOTE: The bootloader allocates persistent memory at an address which is
 * 16 MiB below the end of the highest address in KSEG0. All fixed
 * address memory reservations must avoid this region.
 */

#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/resource.h>
#include <linux/serial_reg.h>
#include <linux/io.h>
#include <linux/bootmem.h>
#include <linux/mm.h>
#include <linux/platform_device.h>
#include <linux/module.h>
#include <asm/page.h>
#include <linux/swap.h>
#include <linux/highmem.h>
#include <linux/dma-mapping.h>

#include <asm/mach-powertv/asic.h>
#include <asm/mach-powertv/asic_regs.h>
#include <asm/mach-powertv/interrupts.h>

#ifdef CONFIG_BOOTLOADER_DRIVER
#include <asm/mach-powertv/kbldr.h>
#endif
#include <asm/bootinfo.h>

#define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))

/*
 * Forward Prototypes
 */
static void pmem_setup_resource(void);

/*
 * Global Variables
 */
enum asic_type asic;

unsigned int platform_features;
unsigned int platform_family;
struct register_map _asic_register_map;
EXPORT_SYMBOL(_asic_register_map);		/* Exported for testing */
unsigned long asic_phy_base;
unsigned long asic_base;
EXPORT_SYMBOL(asic_base);			/* Exported for testing */
struct resource *gp_resources;

/*
 * Don't recommend to use it directly, it is usually used by kernel internally.
 * Portable code should be using interfaces such as ioremp, dma_map_single, etc.
 */
unsigned long phys_to_dma_offset;
EXPORT_SYMBOL(phys_to_dma_offset);

/*
 *
 * IO Resource Definition
 *
 */

struct resource asic_resource = {
	.name  = "ASIC Resource",
	.start = 0,
	.end   = ASIC_IO_SIZE,
	.flags = IORESOURCE_MEM,
};

/*
 * Allow override of bootloader-specified model
 * Returns zero on success, a negative errno value on failure.	This parameter
 * allows overriding of the bootloader-specified model.
 */
static char __initdata cmdline[COMMAND_LINE_SIZE];

#define FORCEFAMILY_PARAM	"forcefamily"

/*
 * check_forcefamily - check for, and parse, forcefamily command line parameter
 * @forced_family:	Pointer to two-character array in which to store the
 *			value of the forcedfamily parameter, if any.
 */
static __init int check_forcefamily(unsigned char forced_family[2])
{
	const char *p;

	forced_family[0] = '\0';
	forced_family[1] = '\0';

	/* Check the command line for a forcefamily directive */
	strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1);
	p = strstr(cmdline, FORCEFAMILY_PARAM);
	if (p && (p != cmdline) && (*(p - 1) != ' '))
		p = strstr(p, " " FORCEFAMILY_PARAM "=");

	if (p) {
		p += strlen(FORCEFAMILY_PARAM "=");

		if (*p == '\0' || *(p + 1) == '\0' ||
			(*(p + 2) != '\0' && *(p + 2) != ' '))
			pr_err(FORCEFAMILY_PARAM " must be exactly two "
				"characters long, ignoring value\n");

		else {
			forced_family[0] = *p;
			forced_family[1] = *(p + 1);
		}
	}

	return 0;
}

/*
 * platform_set_family - determine major platform family type.
 *
 * Returns family type; -1 if none
 * Returns the family type; -1 if none
 *
 */
static __init noinline void platform_set_family(void)
{
	unsigned char forced_family[2];
	unsigned short bootldr_family;

	if (check_forcefamily(forced_family) == 0)
		bootldr_family = BOOTLDRFAMILY(forced_family[0],
			forced_family[1]);
	else {

#ifdef CONFIG_BOOTLOADER_DRIVER
		bootldr_family = (unsigned short) kbldr_GetSWFamily();
#else
#if defined(CONFIG_BOOTLOADER_FAMILY)
		bootldr_family = (unsigned short) BOOTLDRFAMILY(
			CONFIG_BOOTLOADER_FAMILY[0],
			CONFIG_BOOTLOADER_FAMILY[1]);
#else
#error "Unknown Bootloader Family"
#endif
#endif
	}

	pr_info("Bootloader Family = 0x%04X\n", bootldr_family);

	switch (bootldr_family) {
	case BOOTLDRFAMILY('R', '1'):
		platform_family = FAMILY_1500;
		break;
	case BOOTLDRFAMILY('4', '4'):
		platform_family = FAMILY_4500;
		break;
	case BOOTLDRFAMILY('4', '6'):
		platform_family = FAMILY_4600;
		break;
	case BOOTLDRFAMILY('A', '1'):
		platform_family = FAMILY_4600VZA;
		break;
	case BOOTLDRFAMILY('8', '5'):
		platform_family = FAMILY_8500;
		break;
	case BOOTLDRFAMILY('R', '2'):
		platform_family = FAMILY_8500RNG;
		break;
	case BOOTLDRFAMILY('8', '6'):
		platform_family = FAMILY_8600;
		break;
	case BOOTLDRFAMILY('B', '1'):
		platform_family = FAMILY_8600VZB;
		break;
	case BOOTLDRFAMILY('E', '1'):
		platform_family = FAMILY_1500VZE;
		break;
	case BOOTLDRFAMILY('F', '1'):
		platform_family = FAMILY_1500VZF;
		break;
	case BOOTLDRFAMILY('8', '7'):
		platform_family = FAMILY_8700;
		break;
	default:
		platform_family = -1;
	}
}

unsigned int platform_get_family(void)
{
	return platform_family;
}
EXPORT_SYMBOL(platform_get_family);

/*
 * platform_get_asic - determine the ASIC type.
 *
 * Returns the ASIC type, or ASIC_UNKNOWN if unknown
 *
 */
enum asic_type platform_get_asic(void)
{
	return asic;
}
EXPORT_SYMBOL(platform_get_asic);

/*
 * set_register_map - set ASIC register configuration
 * @phys_base:	Physical address of the base of the ASIC registers
 * @map:	Description of key ASIC registers
 */
static void __init set_register_map(unsigned long phys_base,
	const struct register_map *map)
{
	asic_phy_base = phys_base;
	_asic_register_map = *map;
	register_map_virtualize(&_asic_register_map);
	asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);
}

/**
 * configure_platform - configuration based on platform type.
 */
void __init configure_platform(void)
{
	platform_set_family();

	switch (platform_family) {
	case FAMILY_1500:
	case FAMILY_1500VZE:
	case FAMILY_1500VZF:
		platform_features = FFS_CAPABLE;
		asic = ASIC_CALLIOPE;
		set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);

		if (platform_family == FAMILY_1500VZE) {
			gp_resources = non_dvr_vze_calliope_resources;
			pr_info("Platform: 1500/Vz Class E - "
				"CALLIOPE, NON_DVR_CAPABLE\n");
		} else if (platform_family == FAMILY_1500VZF) {
			gp_resources = non_dvr_vzf_calliope_resources;
			pr_info("Platform: 1500/Vz Class F - "
				"CALLIOPE, NON_DVR_CAPABLE\n");
		} else {
			gp_resources = non_dvr_calliope_resources;
			pr_info("Platform: 1500/RNG100 - CALLIOPE, "
				"NON_DVR_CAPABLE\n");
		}
		break;

	case FAMILY_4500:
		platform_features = FFS_CAPABLE | PCIE_CAPABLE |
			DISPLAY_CAPABLE;
		asic = ASIC_ZEUS;
		set_register_map(ZEUS_IO_BASE, &zeus_register_map);
		gp_resources = non_dvr_zeus_resources;

		pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");
		break;

	case FAMILY_4600:
	{
		unsigned int chipversion = 0;

		/* The settop has PCIE but it isn't used, so don't advertise
		 * it*/
		platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;

		/* Cronus and Cronus Lite have the same register map */
		set_register_map(CRONUS_IO_BASE, &cronus_register_map);

		/* ASIC version will determine if this is a real CronusLite or
		 * Castrati(Cronus) */
		chipversion  = asic_read(chipver3) << 24;
		chipversion |= asic_read(chipver2) << 16;
		chipversion |= asic_read(chipver1) << 8;
		chipversion |= asic_read(chipver0);

		if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))
			asic = ASIC_CRONUS;
		else
			asic = ASIC_CRONUSLITE;

		gp_resources = non_dvr_cronuslite_resources;
		pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "
			"chipversion=0x%08X\n",
			(asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",
			chipversion);
		break;
	}
	case FAMILY_4600VZA:
		platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
		asic = ASIC_CRONUS;
		set_register_map(CRONUS_IO_BASE, &cronus_register_map);
		gp_resources = non_dvr_cronus_resources;

		pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");
		break;

	case FAMILY_8500:
	case FAMILY_8500RNG:
		platform_features = DVR_CAPABLE | PCIE_CAPABLE |
			DISPLAY_CAPABLE;
		asic = ASIC_ZEUS;
		set_register_map(ZEUS_IO_BASE, &zeus_register_map);
		gp_resources = dvr_zeus_resources;

		pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");
		break;

	case FAMILY_8600:
	case FAMILY_8600VZB:
		platform_features = DVR_CAPABLE | PCIE_CAPABLE |
			DISPLAY_CAPABLE;
		asic = ASIC_CRONUS;
		set_register_map(CRONUS_IO_BASE, &cronus_register_map);
		gp_resources = dvr_cronus_resources;

		pr_info("Platform: 8600/Vz Class B - CRONUS, "
			"DVR_CAPABLE\n");
		break;

	case FAMILY_8700:
		platform_features = FFS_CAPABLE | PCIE_CAPABLE;
		asic = ASIC_GAIA;
		set_register_map(GAIA_IO_BASE, &gaia_register_map);
		gp_resources = dvr_gaia_resources;

		pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n");
		break;

	default:
		pr_crit("Platform:  UNKNOWN PLATFORM\n");
		break;
	}

	switch (asic) {
	case ASIC_ZEUS:
		phys_to_dma_offset = 0x30000000;
		break;
	case ASIC_CALLIOPE:
		phys_to_dma_offset = 0x10000000;
		break;
	case ASIC_CRONUSLITE:
		/* Fall through */
	case ASIC_CRONUS:
		/*
		 * TODO: We suppose 0x10000000 aliases into 0x20000000-
		 * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-
		 * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.
		 */
		phys_to_dma_offset = 0x10000000;
		break;
	default:
		phys_to_dma_offset = 0x00000000;
		break;
	}
}

/*
 * RESOURCE ALLOCATION
 *
 */
/*
 * Allocates/reserves the Platform memory resources early in the boot process.
 * This ignores any resources that are designated IORESOURCE_IO
 */
void __init platform_alloc_bootmem(void)
{
	int i;
	int total = 0;

	/* Get persistent memory data from command line before allocating
	 * resources. This need to happen before normal command line parsing
	 * has been done */
	pmem_setup_resource();

	/* Loop through looking for resources that want a particular address */
	for (i = 0; gp_resources[i].flags != 0; i++) {
		int size = resource_size(&gp_resources[i]);
		if ((gp_resources[i].start != 0) &&
			((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
			reserve_bootmem(dma_to_phys(gp_resources[i].start),
				size, 0);
			total += resource_size(&gp_resources[i]);
			pr_info("reserve resource %s at %08x (%u bytes)\n",
				gp_resources[i].name, gp_resources[i].start,
				resource_size(&gp_resources[i]));
		}
	}

	/* Loop through assigning addresses for those that are left */
	for (i = 0; gp_resources[i].flags != 0; i++) {
		int size = resource_size(&gp_resources[i]);
		if ((gp_resources[i].start == 0) &&
			((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
			void *mem = alloc_bootmem_pages(size);

			if (mem == NULL)
				pr_err("Unable to allocate bootmem pages "
					"for %s\n", gp_resources[i].name);

			else {
				gp_resources[i].start =
					phys_to_dma(virt_to_phys(mem));
				gp_resources[i].end =
					gp_resources[i].start + size - 1;
				total += size;
				pr_info("allocate resource %s at %08x "
						"(%u bytes)\n",
					gp_resources[i].name,
					gp_resources[i].start, size);
			}
		}
	}

	pr_info("Total Platform driver memory allocation: 0x%08x\n", total);

	/* indicate resources that are platform I/O related */
	for (i = 0; gp_resources[i].flags != 0; i++) {
		if ((gp_resources[i].start != 0) &&
			((gp_resources[i].flags & IORESOURCE_IO) != 0)) {
			pr_info("reserved platform resource %s at %08x\n",
				gp_resources[i].name, gp_resources[i].start);
		}
	}
}

/*
 *
 * PERSISTENT MEMORY (PMEM) CONFIGURATION
 *
 */
static unsigned long pmemaddr __initdata;

static int __init early_param_pmemaddr(char *p)
{
	pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);
	return 0;
}
early_param("pmemaddr", early_param_pmemaddr);

static long pmemlen __initdata;

static int __init early_param_pmemlen(char *p)
{
/* TODO: we can use this code when and if the bootloader ever changes this */
#if 0
	pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);
#else
	pmemlen = 0x20000;
#endif
	return 0;
}
early_param("pmemlen", early_param_pmemlen);

/*
 * Set up persistent memory. If we were given values, we patch the array of
 * resources. Otherwise, persistent memory may be allocated anywhere at all.
 */
static void __init pmem_setup_resource(void)
{
	struct resource *resource;
	resource = asic_resource_get("DiagPersistentMemory");

	if (resource && pmemaddr && pmemlen) {
		/* The address provided by bootloader is in kseg0. Convert to
		 * a bus address. */
		resource->start = phys_to_dma(pmemaddr - 0x80000000);
		resource->end = resource->start + pmemlen - 1;

		pr_info("persistent memory: start=0x%x	end=0x%x\n",
			resource->start, resource->end);
	}
}

/*
 *
 * RESOURCE ACCESS FUNCTIONS
 *
 */

/**
 * asic_resource_get - retrieves parameters for a platform resource.
 * @name:	string to match resource
 *
 * Returns a pointer to a struct resource corresponding to the given name.
 *
 * CANNOT BE NAMED platform_resource_get, which would be the obvious choice,
 * as this function name is already declared
 */
struct resource *asic_resource_get(const char *name)
{
	int i;

	for (i = 0; gp_resources[i].flags != 0; i++) {
		if (strcmp(gp_resources[i].name, name) == 0)
			return &gp_resources[i];
	}

	return NULL;
}
EXPORT_SYMBOL(asic_resource_get);

/**
 * platform_release_memory - release pre-allocated memory
 * @ptr:	pointer to memory to release
 * @size:	size of resource
 *
 * This must only be called for memory allocated or reserved via the boot
 * memory allocator.
 */
void platform_release_memory(void *ptr, int size)
{
	free_reserved_area((unsigned long)ptr, (unsigned long)(ptr + size),
			   -1, NULL);
}
EXPORT_SYMBOL(platform_release_memory);

/*
 *
 * FEATURE AVAILABILITY FUNCTIONS
 *
 */
int platform_supports_dvr(void)
{
	return (platform_features & DVR_CAPABLE) != 0;
}

int platform_supports_ffs(void)
{
	return (platform_features & FFS_CAPABLE) != 0;
}

int platform_supports_pcie(void)
{
	return (platform_features & PCIE_CAPABLE) != 0;
}

int platform_supports_display(void)
{
	return (platform_features & DISPLAY_CAPABLE) != 0;
}
OpenPOWER on IntegriCloud