summaryrefslogtreecommitdiffstats
path: root/arch/avr32/boards/merisc/flash.c
blob: 8e856fd6f0131d06c440f4c75b27cc8330873e43 (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
/*
 * Merisc board-specific flash initialization
 *
 * Copyright (C) 2008 Martinsson Elektronik AB
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include <linux/mtd/physmap.h>
#include <mach/smc.h>

/* Will be translated to units of 14.3 ns, rounded up */
static struct smc_timing flash_timing __initdata = {
	.ncs_read_setup		= 1 * 14,
	.nrd_setup		= 5 * 14,
	.ncs_write_setup	= 1 * 14,
	.nwe_setup		= 2 * 14,

	.ncs_read_pulse		= 12 * 14,
	.nrd_pulse		= 7 * 14,
	.ncs_write_pulse	= 8 * 14,
	.nwe_pulse		= 4 * 14,

	.read_cycle		= 14 * 14,
	.write_cycle		= 10 * 14,
};

static struct smc_config flash_config __initdata = {
	.bus_width	= 2,
	.nrd_controlled	= 1,
	.nwe_controlled	= 1,
	.byte_write	= 1,
	.tdf_cycles	= 3,
};

static struct mtd_partition flash_0_parts[] = {
	{
		.name		= "boot",
		.offset		= 0x00000000,
		.size		= 0x00060000,
		.mask_flags	= 0,
	},
	{
		.name		= "kernel",
		.offset		= 0x00060000,
		.size		= 0x00200000,
		.mask_flags	= 0,
	},
	{
		.name		= "root",
		.offset		= 0x00260000,
		.size		= MTDPART_SIZ_FULL,
		.mask_flags	= 0,
	},
};

static struct mtd_partition flash_1_parts[] = {
	{
		.name		= "2ndflash",
		.offset		= 0x00000000,
		.size		= MTDPART_SIZ_FULL,
		.mask_flags	= 0,
	},
};

static struct physmap_flash_data flash_data[] = {
	{
		.width		= 2,
		.nr_parts	= ARRAY_SIZE(flash_0_parts),
		.parts		= flash_0_parts,
	},
	{
		.width		= 2,
		.nr_parts	= ARRAY_SIZE(flash_1_parts),
		.parts		= flash_1_parts,
	}
};

static struct resource flash_resource[] = {
	{
		.start		= 0x00000000,
		.end		= 0x03ffffff,
		.flags		= IORESOURCE_MEM,
	},
	{
		.start		= 0x04000000,
		.end		= 0x07ffffff,
		.flags		= IORESOURCE_MEM,
	},
};

static struct platform_device flash_device[] = {
	{
		.name		= "physmap-flash",
		.id		= 0,
		.resource	= &flash_resource[0],
		.num_resources	= 1,
		.dev		= {
			.platform_data	= &flash_data[0],
		},
	},
	{
		.name		= "physmap-flash",
		.id		= 1,
		.resource	= &flash_resource[1],
		.num_resources	= 1,
		.dev		= {
			.platform_data	= &flash_data[1],
		},
	},
};

static int __init merisc_flash_init(void)
{
	int ret;
	smc_set_timing(&flash_config, &flash_timing);

	ret = smc_set_configuration(0, &flash_config);
	if (ret < 0) {
		printk(KERN_ERR "Merisc: failed to set NOR flash timing #0\n");
		return ret;
	}

	ret = smc_set_configuration(4, &flash_config);
	if (ret < 0) {
		printk(KERN_ERR "Merisc: failed to set NOR flash timing #1\n");
		return ret;
	}

	platform_device_register(&flash_device[0]);
	platform_device_register(&flash_device[1]);
	return 0;
}
device_initcall(merisc_flash_init);
OpenPOWER on IntegriCloud