summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700')
-rw-r--r--firmware/target/arm/s5l8700/yps3/nand-target.h33
-rw-r--r--firmware/target/arm/s5l8700/yps3/nand-yps3.c109
2 files changed, 142 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/yps3/nand-target.h b/firmware/target/arm/s5l8700/yps3/nand-target.h
new file mode 100644
index 0000000000..b617c2c27f
--- /dev/null
+++ b/firmware/target/arm/s5l8700/yps3/nand-target.h
@@ -0,0 +1,33 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Bertrik Sikken
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _NAND_TARGET_H_
23#define _NAND_TARGET_H_
24
25#include "config.h"
26
27void nand_ll_init(void);
28unsigned int nand_ll_read_id(int bank);
29
30/* TODO later: create nand_ll_read/write/erase prototypes */
31
32#endif /* _NAND_TARGET_H_ */
33
diff --git a/firmware/target/arm/s5l8700/yps3/nand-yps3.c b/firmware/target/arm/s5l8700/yps3/nand-yps3.c
new file mode 100644
index 0000000000..743c74261a
--- /dev/null
+++ b/firmware/target/arm/s5l8700/yps3/nand-yps3.c
@@ -0,0 +1,109 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Bertrik Sikken
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <string.h>
22
23#include "config.h"
24#include "s5l8700.h"
25#include "nand-target.h"
26
27/* Driver for the S5L8700 flash memory controller for low-level access to the
28 NAND flash of the Samsung YP-S3.
29
30 The YP-S3 seems to use the pins P6.5 and P6.6 as chip selects in GPIO mode
31 instead of using the regular pins P6.3 and P6.4.
32*/
33
34#define FMSTAT_RBB (1<<0)
35#define FMSTAT_RBBDone (1<<1)
36#define FMSTAT_CMDDone (1<<2)
37#define FMSTAT_AddrDone (1<<3)
38#define FMSTAT_TransDone (1<<4)
39#define FMSTAT_WFIFO_HEMPTY (1<<5)
40#define FMSTAT_RFIFO_HFULL (1<<6)
41#define FMSTAT_WFIFO_EMPTY (1<<8)
42#define FMSTAT_RFIFO_FULL (1<<9)
43#define FMSTAT_EndECC (1<<10)
44
45#define FMCTRL1_DoTransAddr (1<<0)
46#define FMCTRL1_DoReadData (1<<1)
47#define FMCTRL1_DoWriteData (1<<2)
48#define FMCTRL1_WriteREQSEL (1<<4)
49#define FMCTRL1_ClearSyndPtr (1<<5)
50#define FMCTRL1_ClearWFIFO (1<<6)
51#define FMCTRL1_ClearRFIFO (1<<7)
52#define FMCTRL1_ParityPtr (1<<8)
53#define FMCTRL1_SyndPtr (1<<9)
54
55static void nand_chip_select(int bank)
56{
57 unsigned int select;
58
59 select = (1 << bank);
60 FMCTRL0 = 0x1821 | ((select & 3) << 1);
61 PDAT6 = (PDAT6 & ~0x60) | ((~select & 0xC) << 3);
62}
63
64void nand_ll_init(void)
65{
66 /* enable flash memory controller */
67 PWRCON &= ~(1 << 1);
68
69 /* P2.X is SMC I/O */
70 PCON2 = 0x55555555;
71 /* P4.1 = CLE, P4.4 = nWR, P4.5 = nRD */
72 PCON4 = (PCON4 & ~0x00FF00F0) | 0x00550050;
73 /* P6.0 = nf_rbn, P6.1 = smc_ce0, P6.2 = smc_ce1,
74 P6.5 = smc_ce2 (as GPIO), P6.6 = smc_ce3 (as GPIO), P6.7 = ALE */
75 PCON6 = (PCON6 & ~0xFFF00FFF) | 0x51100555;
76 PDAT6 |= 0x60;
77}
78
79unsigned int nand_ll_read_id(int bank)
80{
81 unsigned int nand_id;
82
83 nand_chip_select(bank);
84
85 /* send "read id" command */
86 FMCMD = 0x90;
87 while ((FMCSTAT & FMSTAT_CMDDone) == 0);
88 FMCSTAT = FMSTAT_CMDDone;
89
90 /* transfer address */
91 FMANUM = 0;
92 FMADDR0 = 0;
93 FMCTRL1 = FMCTRL1_DoTransAddr;
94 while ((FMCSTAT & FMSTAT_AddrDone) == 0);
95 FMCSTAT = FMSTAT_AddrDone;
96
97 /* read back data */
98 FMDNUM = 3;
99 FMCTRL1 = FMCTRL1_DoReadData;
100 while ((FMCSTAT & FMSTAT_TransDone) == 0);
101 FMCSTAT = FMSTAT_TransDone;
102 nand_id = FMFIFO;
103
104 /* clear read FIFO */
105 FMCTRL1 = FMCTRL1_ClearRFIFO;
106
107 return nand_id;
108}
109