summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-imx/nand.c
blob: 7574fe80b21b41432ffb343f8ab841b53715096c (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
/*
 * 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.
 *
 */

#include <common.h>
#include <mach/generic.h>
#include <mach/imx21-regs.h>
#include <mach/imx25-regs.h>
#include <mach/imx27-regs.h>
#include <mach/imx35-regs.h>
#include <mach/imx-nand.h>
#include <io.h>

#define RCSR_NFC_FMS		(1 << 8)
#define RCSR_NFC_4K		(1 << 9)
#define RCSR_NFC_16BIT_SEL	(1 << 14)

static __maybe_unused void imx25_35_nand_set_layout(void __iomem *reg_rcsr,
		int writesize, int datawidth)
{
	unsigned int rcsr;

	rcsr = readl(reg_rcsr);

	switch (writesize) {
	case 512:
		rcsr &= ~(RCSR_NFC_FMS | RCSR_NFC_4K);
		break;
	case 2048:
		rcsr |= RCSR_NFC_FMS;
		break;
	case 4096:
		rcsr |= RCSR_NFC_FMS | RCSR_NFC_4K;
		break;
	default:
		break;
	}

	switch (datawidth) {
	case 8:
		rcsr &= ~RCSR_NFC_16BIT_SEL;
		break;
	case 16:
		rcsr |= RCSR_NFC_16BIT_SEL;
		break;
	default:
		break;
	}

	writel(rcsr, reg_rcsr);
}

#define FMCR_NF_FMS		(1 << 5)
#define FMCR_NF_16BIT_SEL	(1 << 4)

static __maybe_unused void imx21_27_nand_set_layout(void __iomem *reg_fmcr,
		int writesize, int datawidth)
{
	unsigned int fmcr;

	fmcr = readl(reg_fmcr);

	switch (writesize) {
	case 512:
		fmcr &= ~FMCR_NF_FMS;
		break;
	case 2048:
		fmcr |= FMCR_NF_FMS;
		break;
	default:
		break;
	}

	switch (datawidth) {
	case 8:
		fmcr &= ~FMCR_NF_16BIT_SEL;
		break;
	case 16:
		fmcr |= FMCR_NF_16BIT_SEL;
		break;
	default:
		break;
	}

	writel(fmcr, reg_fmcr);
}

void imx_nand_set_layout(int writesize, int datawidth)
{
#ifdef CONFIG_ARCH_IMX21
	if (cpu_is_mx21())
		imx21_27_nand_set_layout((void *)(MX21_SYSCTRL_BASE_ADDR +
					0x14), writesize, datawidth);
#endif
#ifdef CONFIG_ARCH_IMX27
	if (cpu_is_mx27())
		imx21_27_nand_set_layout((void *)(MX27_SYSCTRL_BASE_ADDR +
					0x14), writesize, datawidth);
#endif
#ifdef CONFIG_ARCH_IMX25
	if (cpu_is_mx25())
		imx25_35_nand_set_layout((void *)MX25_CCM_BASE_ADDR +
				MX25_CCM_RCSR, writesize, datawidth);
#endif
#ifdef CONFIG_ARCH_IMX35
	if (cpu_is_mx35())
		imx25_35_nand_set_layout((void *)MX35_CCM_BASE_ADDR +
				MX35_CCM_RCSR, writesize, datawidth);
#endif
}