warp-nand.c 2.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * PIKA Warp(tm) NAND flash specific routines
 *
 * Copyright (c) 2008 PIKA Technologies
 *   Sean MacLennan <smaclennan@pikatech.com>
 */

#include <linux/platform_device.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/ndfc.h>
14
#include <linux/of.h>
15
#include <asm/machdep.h>
16

17

18 19 20 21 22 23 24 25 26
#ifdef CONFIG_MTD_NAND_NDFC

#define CS_NAND_0	1	/* use chip select 1 for NAND device 0 */

#define WARP_NAND_FLASH_REG_ADDR	0xD0000000UL
#define WARP_NAND_FLASH_REG_SIZE	0x2000

static struct resource warp_ndfc = {
	.start = WARP_NAND_FLASH_REG_ADDR,
27
	.end   = WARP_NAND_FLASH_REG_ADDR + WARP_NAND_FLASH_REG_SIZE - 1,
28 29 30 31 32 33 34 35 36 37 38 39
	.flags = IORESOURCE_MEM,
};

static struct mtd_partition nand_parts[] = {
	{
		.name   = "kernel",
		.offset = 0,
		.size   = 0x0200000
	},
	{
		.name   = "root",
		.offset = 0x0200000,
40 41 42 43 44 45
		.size   = 0x3E00000
	},
	{
		.name   = "persistent",
		.offset = 0x4000000,
		.size   = 0x4000000
46 47
	},
	{
48 49 50
		.name   = "persistent1",
		.offset = 0x8000000,
		.size   = 0x4000000
51
	},
52 53 54 55 56
	{
		.name   = "persistent2",
		.offset = 0xC000000,
		.size   = 0x4000000
	}
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
};

struct ndfc_controller_settings warp_ndfc_settings = {
	.ccr_settings = (NDFC_CCR_BS(CS_NAND_0) | NDFC_CCR_ARAC1),
	.ndfc_erpn = 0,
};

static struct ndfc_chip_settings warp_chip0_settings = {
	.bank_settings = 0x80002222,
};

struct platform_nand_ctrl warp_nand_ctrl = {
	.priv = &warp_ndfc_settings,
};

static struct platform_device warp_ndfc_device = {
	.name = "ndfc-nand",
	.id = 0,
	.dev = {
		.platform_data = &warp_nand_ctrl,
	},
	.num_resources = 1,
	.resource = &warp_ndfc,
};

82 83 84
/* Do NOT set the ecclayout: let it default so it is correct for both
 * 64M and 256M flash chips.
 */
85 86 87 88 89
static struct platform_nand_chip warp_nand_chip0 = {
	.nr_chips = 1,
	.chip_offset = CS_NAND_0,
	.nr_partitions = ARRAY_SIZE(nand_parts),
	.partitions = nand_parts,
90
	.chip_delay = 20,
91 92 93 94 95 96
	.priv = &warp_chip0_settings,
};

static struct platform_device warp_nand_device = {
	.name = "ndfc-chip",
	.id = 0,
97
	.num_resources = 0,
98 99 100 101 102 103 104 105
	.dev = {
		.platform_data = &warp_nand_chip0,
		.parent = &warp_ndfc_device.dev,
	}
};

static int warp_setup_nand_flash(void)
{
106 107 108 109 110 111 112 113 114 115
	struct device_node *np;

	/* Try to detect a rev A based on NOR size. */
	np = of_find_compatible_node(NULL, NULL, "cfi-flash");
	if (np) {
		struct property *pp;

		pp = of_find_property(np, "reg", NULL);
		if (pp && (pp->length == 12)) {
			u32 *v = pp->value;
116
			if (v[2] == 0x4000000) {
117
				/* Rev A = 64M NAND */
118 119 120 121 122 123
				warp_nand_chip0.nr_partitions = 3;

				nand_parts[1].size   = 0x3000000;
				nand_parts[2].offset = 0x3200000;
				nand_parts[2].size   = 0x0e00000;
			}
124 125 126 127
		}
		of_node_put(np);
	}

128 129 130 131 132
	platform_device_register(&warp_ndfc_device);
	platform_device_register(&warp_nand_device);

	return 0;
}
133
machine_device_initcall(warp, warp_setup_nand_flash);
134 135

#endif