Pavel Herrmann | 2c13c4a | 2012-10-09 07:01:56 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * (C) Copyright 2000-2011 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /* Code taken from cmd_ide.c */ |
| 26 | #include <common.h> |
| 27 | #include <ata.h> |
| 28 | #include "ide.h" |
| 29 | |
| 30 | #ifdef CONFIG_IDE_8xx_DIRECT |
| 31 | #include <mpc8xx.h> |
| 32 | #include <pcmcia.h> |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | /* Timings for IDE Interface |
| 36 | * |
| 37 | * SETUP / LENGTH / HOLD - cycles valid for 50 MHz clk |
| 38 | * 70 165 30 PIO-Mode 0, [ns] |
| 39 | * 4 9 2 [Cycles] |
| 40 | * 50 125 20 PIO-Mode 1, [ns] |
| 41 | * 3 7 2 [Cycles] |
| 42 | * 30 100 15 PIO-Mode 2, [ns] |
| 43 | * 2 6 1 [Cycles] |
| 44 | * 30 80 10 PIO-Mode 3, [ns] |
| 45 | * 2 5 1 [Cycles] |
| 46 | * 25 70 10 PIO-Mode 4, [ns] |
| 47 | * 2 4 1 [Cycles] |
| 48 | */ |
| 49 | |
| 50 | static const pio_config_t pio_config_ns[IDE_MAX_PIO_MODE+1] = { |
| 51 | /* Setup Length Hold */ |
| 52 | { 70, 165, 30 }, /* PIO-Mode 0, [ns] */ |
| 53 | { 50, 125, 20 }, /* PIO-Mode 1, [ns] */ |
| 54 | { 30, 101, 15 }, /* PIO-Mode 2, [ns] */ |
| 55 | { 30, 80, 10 }, /* PIO-Mode 3, [ns] */ |
| 56 | { 25, 70, 10 }, /* PIO-Mode 4, [ns] */ |
| 57 | }; |
| 58 | |
| 59 | static pio_config_t pio_config_clk[IDE_MAX_PIO_MODE+1]; |
| 60 | |
| 61 | #ifndef CONFIG_SYS_PIO_MODE |
| 62 | #define CONFIG_SYS_PIO_MODE 0 /* use a relaxed default */ |
| 63 | #endif |
| 64 | static int pio_mode = CONFIG_SYS_PIO_MODE; |
| 65 | |
| 66 | /* Make clock cycles and always round up */ |
| 67 | |
| 68 | #define PCMCIA_MK_CLKS(t, T) (((t) * (T) + 999U) / 1000U) |
| 69 | |
| 70 | static void set_pcmcia_timing(int pmode) |
| 71 | { |
| 72 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 73 | volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia); |
| 74 | ulong timings; |
| 75 | |
| 76 | debug("Set timing for PIO Mode %d\n", pmode); |
| 77 | |
| 78 | timings = PCMCIA_SHT(pio_config_clk[pmode].t_hold) |
| 79 | | PCMCIA_SST(pio_config_clk[pmode].t_setup) |
| 80 | | PCMCIA_SL(pio_config_clk[pmode].t_length); |
| 81 | |
| 82 | /* |
| 83 | * IDE 0 |
| 84 | */ |
| 85 | pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_PBR0; |
| 86 | #if (CONFIG_SYS_PCMCIA_POR0 != 0) |
| 87 | pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0 | timings; |
| 88 | #else |
| 89 | pcmp->pcmc_por0 = CONFIG_SYS_PCMCIA_POR0; |
| 90 | #endif |
| 91 | debug("PBR0: %08x POR0: %08x\n", pcmp->pcmc_pbr0, pcmp->pcmc_por0); |
| 92 | |
| 93 | pcmp->pcmc_pbr1 = CONFIG_SYS_PCMCIA_PBR1; |
| 94 | #if (CONFIG_SYS_PCMCIA_POR1 != 0) |
| 95 | pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1 | timings; |
| 96 | #else |
| 97 | pcmp->pcmc_por1 = CONFIG_SYS_PCMCIA_POR1; |
| 98 | #endif |
| 99 | debug("PBR1: %08x POR1: %08x\n", pcmp->pcmc_pbr1, pcmp->pcmc_por1); |
| 100 | |
| 101 | pcmp->pcmc_pbr2 = CONFIG_SYS_PCMCIA_PBR2; |
| 102 | #if (CONFIG_SYS_PCMCIA_POR2 != 0) |
| 103 | pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2 | timings; |
| 104 | #else |
| 105 | pcmp->pcmc_por2 = CONFIG_SYS_PCMCIA_POR2; |
| 106 | #endif |
| 107 | debug("PBR2: %08x POR2: %08x\n", pcmp->pcmc_pbr2, pcmp->pcmc_por2); |
| 108 | |
| 109 | pcmp->pcmc_pbr3 = CONFIG_SYS_PCMCIA_PBR3; |
| 110 | #if (CONFIG_SYS_PCMCIA_POR3 != 0) |
| 111 | pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3 | timings; |
| 112 | #else |
| 113 | pcmp->pcmc_por3 = CONFIG_SYS_PCMCIA_POR3; |
| 114 | #endif |
| 115 | debug("PBR3: %08x POR3: %08x\n", pcmp->pcmc_pbr3, pcmp->pcmc_por3); |
| 116 | |
| 117 | /* |
| 118 | * IDE 1 |
| 119 | */ |
| 120 | pcmp->pcmc_pbr4 = CONFIG_SYS_PCMCIA_PBR4; |
| 121 | #if (CONFIG_SYS_PCMCIA_POR4 != 0) |
| 122 | pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4 | timings; |
| 123 | #else |
| 124 | pcmp->pcmc_por4 = CONFIG_SYS_PCMCIA_POR4; |
| 125 | #endif |
| 126 | debug("PBR4: %08x POR4: %08x\n", pcmp->pcmc_pbr4, pcmp->pcmc_por4); |
| 127 | |
| 128 | pcmp->pcmc_pbr5 = CONFIG_SYS_PCMCIA_PBR5; |
| 129 | #if (CONFIG_SYS_PCMCIA_POR5 != 0) |
| 130 | pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5 | timings; |
| 131 | #else |
| 132 | pcmp->pcmc_por5 = CONFIG_SYS_PCMCIA_POR5; |
| 133 | #endif |
| 134 | debug("PBR5: %08x POR5: %08x\n", pcmp->pcmc_pbr5, pcmp->pcmc_por5); |
| 135 | |
| 136 | pcmp->pcmc_pbr6 = CONFIG_SYS_PCMCIA_PBR6; |
| 137 | #if (CONFIG_SYS_PCMCIA_POR6 != 0) |
| 138 | pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6 | timings; |
| 139 | #else |
| 140 | pcmp->pcmc_por6 = CONFIG_SYS_PCMCIA_POR6; |
| 141 | #endif |
| 142 | debug("PBR6: %08x POR6: %08x\n", pcmp->pcmc_pbr6, pcmp->pcmc_por6); |
| 143 | |
| 144 | pcmp->pcmc_pbr7 = CONFIG_SYS_PCMCIA_PBR7; |
| 145 | #if (CONFIG_SYS_PCMCIA_POR7 != 0) |
| 146 | pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7 | timings; |
| 147 | #else |
| 148 | pcmp->pcmc_por7 = CONFIG_SYS_PCMCIA_POR7; |
| 149 | #endif |
| 150 | debug("PBR7: %08x POR7: %08x\n", pcmp->pcmc_pbr7, pcmp->pcmc_por7); |
| 151 | |
| 152 | } |
| 153 | |
| 154 | int ide_preinit(void) |
| 155 | { |
| 156 | int i; |
| 157 | /* Initialize PIO timing tables */ |
| 158 | for (i = 0; i <= IDE_MAX_PIO_MODE; ++i) { |
| 159 | pio_config_clk[i].t_setup = |
| 160 | PCMCIA_MK_CLKS(pio_config_ns[i].t_setup, gd->bus_clk); |
| 161 | pio_config_clk[i].t_length = |
| 162 | PCMCIA_MK_CLKS(pio_config_ns[i].t_length, gd->bus_clk); |
| 163 | pio_config_clk[i].t_hold = |
| 164 | PCMCIA_MK_CLKS(pio_config_ns[i].t_hold, gd->bus_clk); |
| 165 | debug("PIO Mode %d: setup=%2d ns/%d clk" " len=%3d ns/%d clk" |
| 166 | " hold=%2d ns/%d clk\n", i, pio_config_ns[i].t_setup, |
| 167 | pio_config_clk[i].t_setup, pio_config_ns[i].t_length, |
| 168 | pio_config_clk[i].t_length, pio_config_ns[i].t_hold, |
| 169 | pio_config_clk[i].t_hold); |
| 170 | } |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | int ide_init_postreset(void) |
| 176 | { |
| 177 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 178 | volatile pcmconf8xx_t *pcmp = &(immr->im_pcmcia); |
| 179 | |
| 180 | /* PCMCIA / IDE initialization for common mem space */ |
| 181 | pcmp->pcmc_pgcrb = 0; |
| 182 | |
| 183 | /* start in PIO mode 0 - most relaxed timings */ |
| 184 | pio_mode = 0; |
| 185 | set_pcmcia_timing(pio_mode); |
| 186 | return 0; |
| 187 | } |
| 188 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
| 189 | |
| 190 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 191 | int ide_preinit(void) |
| 192 | { |
| 193 | ide_devices_found = 0; |
| 194 | /* initialize the PCMCIA IDE adapter card */ |
| 195 | pcmcia_on(); |
| 196 | if (!ide_devices_found) |
| 197 | return 1; |
| 198 | udelay(1000000);/* 1 s */ |
| 199 | return 0; |
| 200 | } |
| 201 | #endif |