summaryrefslogtreecommitdiff
path: root/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'bus.c')
-rw-r--r--bus.c65
1 files changed, 44 insertions, 21 deletions
diff --git a/bus.c b/bus.c
index dfa10ba..fd5016d 100644
--- a/bus.c
+++ b/bus.c
@@ -151,15 +151,6 @@ static void gpmc_printinfo()
}
-// The shift amounts
-
-#define CSWROFFTIME 16
-#define CSRDOFFTIME 8
-#define OEOFFTIME 8
-#define RDACCESSTIME 16
-#define WRCYCLETIME 8
-#define RDCYCLETIME 0
-#define WRACCESSTIME 24
#define BIDIR 0x20
#define PULL_UP 0x10
@@ -175,9 +166,42 @@ static void gpmc_printinfo()
#define MODE_7 0x07
-static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs, int baseaddress)
-{
+// multiply by 10 ns
+#define TOTAL_IO_CYCLE 25; // 250 ns cycle
+#define CS_DELAY 2; // CS low 20ns after address valid
+#define DELAY_TO_WR_RD 4; // RD/WR lines low 50ns after address valid
+#define WR_RD_WIDTH 20; // stay low for until 200 ns after address valid
+#define DATA_READY 15; // data ready 150ns after address valid
+
+static void gpmc_setup(void)
+{
+ int chipselect = 0;
+ int size = GPMC_SIZE_16MB;
+ bool enablecs = true;
+ int baseaddress = 1;
+
+
+ int CSWROFFTIME = TOTAL_IO_CYCLE - CS_DELAY;
+ int CSRDOFFTIME = TOTAL_IO_CYCLE - CS_DELAY;
+ int CSONTIME = CS_DELAY;
+ int config2 = (CSWROFFTIME << 16) | (CSRDOFFTIME << 8) | CSONTIME;
+
+ int WEOFFTIME = DELAY_TO_WR_RD + WR_RD_WIDTH;
+ int WEONTIME = DELAY_TO_WR_RD;
+ int OEOFFTIME = DELAY_TO_WR_RD + WR_RD_WIDTH;
+ int OEONTIME = DELAY_TO_WR_RD;
+ int config4 = (WEOFFTIME << 24) | (WEONTIME << 16) | (OEOFFTIME << 8) | OEONTIME;
+
+ int RDACCESSTIME = DATA_READY;
+ int WRCYCLETIME = TOTAL_IO_CYCLE;
+ int RDCYCLETIME = TOTAL_IO_CYCLE;
+ int config5 = (RDACCESSTIME << 16) | (WRCYCLETIME << 8) | RDCYCLETIME;
+
+ int WRACCESSTIME = DATA_READY;
+ int config6 = WRACCESSTIME << 24;
+
+
pinmux_configurepin("gpmc_csn0", PULL_UP | MODE_0);
pinmux_configurepin("gpmc_oen_ren", PULL_UP | MODE_0);
pinmux_configurepin("gpmc_wen", PULL_UP | MODE_0);
@@ -209,12 +233,11 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs
*(registers + displacement + GPMC_CONFIG7) = 0x0;
*(registers + displacement + GPMC_CONFIG1) = 0x0;
- *(registers + displacement + GPMC_CONFIG2) = (accesscycles << CSWROFFTIME) | (accesscycles << CSRDOFFTIME);
+ *(registers + displacement + GPMC_CONFIG2) = config2;
*(registers + displacement + GPMC_CONFIG3) = 0x0; // not using ADV so we can ignore this guy
- *(registers + displacement + GPMC_CONFIG4) = (accesscycles << OEOFFTIME);
- *(registers + displacement + GPMC_CONFIG5) = (accesscycles << RDACCESSTIME) | (accesscycles << WRCYCLETIME)
- | (accesscycles << RDCYCLETIME);
- *(registers + displacement + GPMC_CONFIG6) = (accesscycles << WRACCESSTIME);
+ *(registers + displacement + GPMC_CONFIG4) = config4;
+ *(registers + displacement + GPMC_CONFIG5) = config5;
+ *(registers + displacement + GPMC_CONFIG6) = config6;
*(registers + displacement + GPMC_CONFIG7) = size << 8 | (enablecs ? 1 << 6 : 0) | baseaddress;
gpmc_unmapregisters();
@@ -326,7 +349,7 @@ static unsigned gpio_pins[] = { GPIO0_X + 22, // i.e., GPIO0_22
GPIO1_X + 15, // i.e., GPIO1_15
GPIO1_X + 14,
GPIO0_X + 27,
- GPIO1_X + 12
+ GPIO1_X + 12
};
@@ -343,7 +366,7 @@ void bus_init()
}
if (isbb) {
- gpmc_setup(0, GPMCACCESSTIME, GPMC_SIZE_16MB, true, 1);
+ gpmc_setup();
extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100);
@@ -367,9 +390,9 @@ void bus_init()
int bus_getpin(int pin)
{
- if (isbb) {
- return gpio_readvalue(gpio_pins[pin]);
- } else {
+ if (isbb) {
+ return gpio_readvalue(gpio_pins[pin]);
+ } else {
return 0;
}
}