Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * John Clemens <clemens@mclx.com>, Mission Critical Linux, Inc. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /************************************************************************* |
| 9 | * changes for Marvell DB64460 eval board 2003 by Ingo Assmus <ingo.assmus@keymile.com> |
| 10 | * |
| 11 | ************************************************************************/ |
| 12 | |
| 13 | /* |
| 14 | * mpsc.c - driver for console over the MPSC. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #include <common.h> |
| 19 | #include <config.h> |
| 20 | #include <asm/cache.h> |
| 21 | |
| 22 | #include <malloc.h> |
| 23 | #include "mpsc.h" |
| 24 | |
| 25 | #include "mv_regs.h" |
| 26 | |
| 27 | #include "../../Marvell/include/memory.h" |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | /* Define this if you wish to use the MPSC as a register based UART. |
| 32 | * This will force the serial port to not use the SDMA engine at all. |
| 33 | */ |
| 34 | #undef CONFIG_MPSC_DEBUG_PORT |
| 35 | |
| 36 | |
| 37 | int (*mpsc_putchar) (char ch) = mpsc_putchar_early; |
| 38 | char (*mpsc_getchar) (void) = mpsc_getchar_debug; |
| 39 | int (*mpsc_test_char) (void) = mpsc_test_char_debug; |
| 40 | |
| 41 | |
| 42 | static volatile unsigned int *rx_desc_base = NULL; |
| 43 | static unsigned int rx_desc_index = 0; |
| 44 | static volatile unsigned int *tx_desc_base = NULL; |
| 45 | static unsigned int tx_desc_index = 0; |
| 46 | |
| 47 | /* local function declarations */ |
| 48 | static int galmpsc_connect (int channel, int connect); |
| 49 | static int galmpsc_route_rx_clock (int channel, int brg); |
| 50 | static int galmpsc_route_tx_clock (int channel, int brg); |
| 51 | static int galmpsc_write_config_regs (int mpsc, int mode); |
| 52 | static int galmpsc_config_channel_regs (int mpsc); |
| 53 | static int galmpsc_set_char_length (int mpsc, int value); |
| 54 | static int galmpsc_set_stop_bit_length (int mpsc, int value); |
| 55 | static int galmpsc_set_parity (int mpsc, int value); |
| 56 | static int galmpsc_enter_hunt (int mpsc); |
| 57 | static int galmpsc_set_brkcnt (int mpsc, int value); |
| 58 | static int galmpsc_set_tcschar (int mpsc, int value); |
| 59 | static int galmpsc_set_snoop (int mpsc, int value); |
| 60 | static int galmpsc_shutdown (int mpsc); |
| 61 | |
| 62 | static int galsdma_set_RFT (int channel); |
| 63 | static int galsdma_set_SFM (int channel); |
| 64 | static int galsdma_set_rxle (int channel); |
| 65 | static int galsdma_set_txle (int channel); |
| 66 | static int galsdma_set_burstsize (int channel, unsigned int value); |
| 67 | static int galsdma_set_RC (int channel, unsigned int value); |
| 68 | |
| 69 | static int galbrg_set_CDV (int channel, int value); |
| 70 | static int galbrg_enable (int channel); |
| 71 | static int galbrg_disable (int channel); |
| 72 | static int galbrg_set_clksrc (int channel, int value); |
| 73 | static int galbrg_set_CUV (int channel, int value); |
| 74 | |
| 75 | static void galsdma_enable_rx (void); |
| 76 | static int galsdma_set_mem_space (unsigned int memSpace, |
| 77 | unsigned int memSpaceTarget, |
| 78 | unsigned int memSpaceAttr, |
| 79 | unsigned int baseAddress, |
| 80 | unsigned int size); |
| 81 | |
| 82 | |
| 83 | #define SOFTWARE_CACHE_MANAGEMENT |
| 84 | |
| 85 | #ifdef SOFTWARE_CACHE_MANAGEMENT |
| 86 | #define FLUSH_DCACHE(a,b) if(dcache_status()){clean_dcache_range((u32)(a),(u32)(b));} |
| 87 | #define FLUSH_AND_INVALIDATE_DCACHE(a,b) if(dcache_status()){flush_dcache_range((u32)(a),(u32)(b));} |
| 88 | #define INVALIDATE_DCACHE(a,b) if(dcache_status()){invalidate_dcache_range((u32)(a),(u32)(b));} |
| 89 | #else |
| 90 | #define FLUSH_DCACHE(a,b) |
| 91 | #define FLUSH_AND_INVALIDATE_DCACHE(a,b) |
| 92 | #define INVALIDATE_DCACHE(a,b) |
| 93 | #endif |
| 94 | |
| 95 | #ifdef CONFIG_MPSC_DEBUG_PORT |
| 96 | static void mpsc_debug_init (void) |
| 97 | { |
| 98 | |
| 99 | volatile unsigned int temp; |
| 100 | |
| 101 | /* Clear the CFR (CHR4) */ |
| 102 | /* Write random 'Z' bit (bit 29) of CHR4 to enable debug uart *UNDOCUMENTED FEATURE* */ |
| 103 | temp = GTREGREAD (GALMPSC_CHANNELREG_4 + (CHANNEL * GALMPSC_REG_GAP)); |
| 104 | temp &= 0xffffff00; |
| 105 | temp |= BIT29; |
| 106 | GT_REG_WRITE (GALMPSC_CHANNELREG_4 + (CHANNEL * GALMPSC_REG_GAP), |
| 107 | temp); |
| 108 | |
| 109 | /* Set the Valid bit 'V' (bit 12) and int generation bit 'INT' (bit 15) */ |
| 110 | temp = GTREGREAD (GALMPSC_CHANNELREG_5 + (CHANNEL * GALMPSC_REG_GAP)); |
| 111 | temp |= (BIT12 | BIT15); |
| 112 | GT_REG_WRITE (GALMPSC_CHANNELREG_5 + (CHANNEL * GALMPSC_REG_GAP), |
| 113 | temp); |
| 114 | |
| 115 | /* Set int mask */ |
| 116 | temp = GTREGREAD (GALMPSC_0_INT_MASK); |
| 117 | temp |= BIT6; |
| 118 | GT_REG_WRITE (GALMPSC_0_INT_MASK, temp); |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | char mpsc_getchar_debug (void) |
| 123 | { |
| 124 | volatile int temp; |
| 125 | volatile unsigned int cause; |
| 126 | |
| 127 | cause = GTREGREAD (GALMPSC_0_INT_CAUSE); |
| 128 | while ((cause & BIT6) == 0) { |
| 129 | cause = GTREGREAD (GALMPSC_0_INT_CAUSE); |
| 130 | } |
| 131 | |
| 132 | temp = GTREGREAD (GALMPSC_CHANNELREG_10 + |
| 133 | (CHANNEL * GALMPSC_REG_GAP)); |
| 134 | /* By writing 1's to the set bits, the register is cleared */ |
| 135 | GT_REG_WRITE (GALMPSC_CHANNELREG_10 + (CHANNEL * GALMPSC_REG_GAP), |
| 136 | temp); |
| 137 | GT_REG_WRITE (GALMPSC_0_INT_CAUSE, cause & ~BIT6); |
| 138 | return (temp >> 16) & 0xff; |
| 139 | } |
| 140 | |
| 141 | /* special function for running out of flash. doesn't modify any |
| 142 | * global variables [josh] */ |
| 143 | int mpsc_putchar_early (char ch) |
| 144 | { |
| 145 | int mpsc = CHANNEL; |
| 146 | int temp = |
| 147 | GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)); |
| 148 | galmpsc_set_tcschar (mpsc, ch); |
| 149 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), |
| 150 | temp | 0x200); |
| 151 | |
| 152 | #define MAGIC_FACTOR (10*1000000) |
| 153 | |
| 154 | udelay (MAGIC_FACTOR / gd->baudrate); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | /* This is used after relocation, see serial.c and mpsc_init2 */ |
| 159 | static int mpsc_putchar_sdma (char ch) |
| 160 | { |
| 161 | volatile unsigned int *p; |
| 162 | unsigned int temp; |
| 163 | |
| 164 | |
| 165 | /* align the descriptor */ |
| 166 | p = tx_desc_base; |
| 167 | memset ((void *) p, 0, 8 * sizeof (unsigned int)); |
| 168 | |
| 169 | /* fill one 64 bit buffer */ |
| 170 | /* word swap, pad with 0 */ |
| 171 | p[4] = 0; /* x */ |
| 172 | p[5] = (unsigned int) ch; /* x */ |
| 173 | |
| 174 | /* CHANGED completely according to GT64260A dox - NTL */ |
| 175 | p[0] = 0x00010001; /* 0 */ |
| 176 | p[1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; /* 4 */ |
| 177 | p[2] = 0; /* 8 */ |
| 178 | p[3] = (unsigned int) &p[4]; /* c */ |
| 179 | |
| 180 | #if 0 |
| 181 | p[9] = DESC_FIRST | DESC_LAST; |
| 182 | p[10] = (unsigned int) &p[0]; |
| 183 | p[11] = (unsigned int) &p[12]; |
| 184 | #endif |
| 185 | |
| 186 | FLUSH_DCACHE (&p[0], &p[8]); |
| 187 | |
| 188 | GT_REG_WRITE (GALSDMA_0_CUR_TX_PTR + (CHANNEL * GALSDMA_REG_DIFF), |
| 189 | (unsigned int) &p[0]); |
| 190 | GT_REG_WRITE (GALSDMA_0_FIR_TX_PTR + (CHANNEL * GALSDMA_REG_DIFF), |
| 191 | (unsigned int) &p[0]); |
| 192 | |
| 193 | temp = GTREGREAD (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF)); |
| 194 | temp |= (TX_DEMAND | TX_STOP); |
| 195 | GT_REG_WRITE (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF), temp); |
| 196 | |
| 197 | INVALIDATE_DCACHE (&p[1], &p[2]); |
| 198 | |
| 199 | while (p[1] & DESC_OWNER_BIT) { |
| 200 | udelay (100); |
| 201 | INVALIDATE_DCACHE (&p[1], &p[2]); |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | char mpsc_getchar_sdma (void) |
| 207 | { |
| 208 | static unsigned int done = 0; |
| 209 | volatile char ch; |
| 210 | unsigned int len = 0, idx = 0, temp; |
| 211 | |
| 212 | volatile unsigned int *p; |
| 213 | |
| 214 | |
| 215 | do { |
| 216 | p = &rx_desc_base[rx_desc_index * 8]; |
| 217 | |
| 218 | INVALIDATE_DCACHE (&p[0], &p[1]); |
| 219 | /* Wait for character */ |
| 220 | while (p[1] & DESC_OWNER_BIT) { |
| 221 | udelay (100); |
| 222 | INVALIDATE_DCACHE (&p[0], &p[1]); |
| 223 | } |
| 224 | |
| 225 | /* Handle error case */ |
| 226 | if (p[1] & (1 << 15)) { |
| 227 | printf ("oops, error: %08x\n", p[1]); |
| 228 | |
| 229 | temp = GTREGREAD (GALMPSC_CHANNELREG_2 + |
| 230 | (CHANNEL * GALMPSC_REG_GAP)); |
| 231 | temp |= (1 << 23); |
| 232 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + |
| 233 | (CHANNEL * GALMPSC_REG_GAP), temp); |
| 234 | |
| 235 | /* Can't poll on abort bit, so we just wait. */ |
| 236 | udelay (100); |
| 237 | |
| 238 | galsdma_enable_rx (); |
| 239 | } |
| 240 | |
| 241 | /* Number of bytes left in this descriptor */ |
| 242 | len = p[0] & 0xffff; |
| 243 | |
| 244 | if (len) { |
| 245 | /* Where to look */ |
| 246 | idx = 5; |
| 247 | if (done > 3) |
| 248 | idx = 4; |
| 249 | if (done > 7) |
| 250 | idx = 7; |
| 251 | if (done > 11) |
| 252 | idx = 6; |
| 253 | |
| 254 | INVALIDATE_DCACHE (&p[idx], &p[idx + 1]); |
| 255 | ch = p[idx] & 0xff; |
| 256 | done++; |
| 257 | } |
| 258 | |
| 259 | if (done < len) { |
| 260 | /* this descriptor has more bytes still |
| 261 | * shift down the char we just read, and leave the |
| 262 | * buffer in place for the next time around |
| 263 | */ |
| 264 | p[idx] = p[idx] >> 8; |
| 265 | FLUSH_DCACHE (&p[idx], &p[idx + 1]); |
| 266 | } |
| 267 | |
| 268 | if (done == len) { |
| 269 | /* nothing left in this descriptor. |
| 270 | * go to next one |
| 271 | */ |
| 272 | p[1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; |
| 273 | p[0] = 0x00100000; |
| 274 | FLUSH_DCACHE (&p[0], &p[1]); |
| 275 | /* Next descriptor */ |
| 276 | rx_desc_index = (rx_desc_index + 1) % RX_DESC; |
| 277 | done = 0; |
| 278 | } |
| 279 | } while (len == 0); /* galileo bug.. len might be zero */ |
| 280 | |
| 281 | return ch; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | int mpsc_test_char_debug (void) |
| 286 | { |
| 287 | if ((GTREGREAD (GALMPSC_0_INT_CAUSE) & BIT6) == 0) |
| 288 | return 0; |
| 289 | else { |
| 290 | return 1; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | |
| 295 | int mpsc_test_char_sdma (void) |
| 296 | { |
| 297 | volatile unsigned int *p = &rx_desc_base[rx_desc_index * 8]; |
| 298 | |
| 299 | INVALIDATE_DCACHE (&p[1], &p[2]); |
| 300 | |
| 301 | if (p[1] & DESC_OWNER_BIT) |
| 302 | return 0; |
| 303 | else |
| 304 | return 1; |
| 305 | } |
| 306 | |
| 307 | int mpsc_init (int baud) |
| 308 | { |
| 309 | /* BRG CONFIG */ |
| 310 | galbrg_set_baudrate (CHANNEL, baud); |
| 311 | galbrg_set_clksrc (CHANNEL, 8); /* set source=Tclk */ |
| 312 | galbrg_set_CUV (CHANNEL, 0); /* set up CountUpValue */ |
| 313 | galbrg_enable (CHANNEL); /* Enable BRG */ |
| 314 | |
| 315 | /* Set up clock routing */ |
| 316 | galmpsc_connect (CHANNEL, GALMPSC_CONNECT); /* connect it */ |
| 317 | |
| 318 | galmpsc_route_rx_clock (CHANNEL, CHANNEL); /* chosse BRG0 for Rx */ |
| 319 | galmpsc_route_tx_clock (CHANNEL, CHANNEL); /* chose BRG0 for Tx */ |
| 320 | |
| 321 | /* reset MPSC state */ |
| 322 | galmpsc_shutdown (CHANNEL); |
| 323 | |
| 324 | /* SDMA CONFIG */ |
| 325 | galsdma_set_burstsize (CHANNEL, L1_CACHE_BYTES / 8); /* in 64 bit words (8 bytes) */ |
| 326 | galsdma_set_txle (CHANNEL); |
| 327 | galsdma_set_rxle (CHANNEL); |
| 328 | galsdma_set_RC (CHANNEL, 0xf); |
| 329 | galsdma_set_SFM (CHANNEL); |
| 330 | galsdma_set_RFT (CHANNEL); |
| 331 | |
| 332 | /* MPSC CONFIG */ |
| 333 | galmpsc_write_config_regs (CHANNEL, GALMPSC_UART); |
| 334 | galmpsc_config_channel_regs (CHANNEL); |
| 335 | galmpsc_set_char_length (CHANNEL, GALMPSC_CHAR_LENGTH_8); /* 8 */ |
| 336 | galmpsc_set_parity (CHANNEL, GALMPSC_PARITY_NONE); /* N */ |
| 337 | galmpsc_set_stop_bit_length (CHANNEL, GALMPSC_STOP_BITS_1); /* 1 */ |
| 338 | |
| 339 | #ifdef CONFIG_MPSC_DEBUG_PORT |
| 340 | mpsc_debug_init (); |
| 341 | #endif |
| 342 | |
| 343 | /* COMM_MPSC CONFIG */ |
| 344 | #ifdef SOFTWARE_CACHE_MANAGEMENT |
| 345 | galmpsc_set_snoop (CHANNEL, 0); /* disable snoop */ |
| 346 | #else |
| 347 | galmpsc_set_snoop (CHANNEL, 1); /* enable snoop */ |
| 348 | #endif |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | void mpsc_sdma_init (void) |
| 355 | { |
| 356 | /* Setup SDMA channel0 SDMA_CONFIG_REG*/ |
| 357 | GT_REG_WRITE (SDMA_CONFIG_REG (0), 0x000020ff); |
| 358 | |
| 359 | /* Enable MPSC-Window0 for DRAM Bank 0 */ |
| 360 | if (galsdma_set_mem_space (MV64460_CUNIT_BASE_ADDR_WIN_0_BIT, |
| 361 | MV64460_SDMA_DRAM_CS_0_TARGET, |
| 362 | 0, |
| 363 | memoryGetBankBaseAddress(0), |
| 364 | memoryGetBankSize(0)) != true) |
| 365 | printf ("%s: SDMA_Window0 memory setup failed !!! \n", |
| 366 | __FUNCTION__); |
| 367 | |
| 368 | |
| 369 | /* Enable MPSC-Window1 for DRAM Bank 1 */ |
| 370 | if (galsdma_set_mem_space (MV64460_CUNIT_BASE_ADDR_WIN_1_BIT, |
| 371 | MV64460_SDMA_DRAM_CS_1_TARGET, |
| 372 | 0, |
| 373 | memoryGetBankBaseAddress(1), |
| 374 | memoryGetBankSize(1)) != true) |
| 375 | printf ("%s: SDMA_Window1 memory setup failed !!! \n", |
| 376 | __FUNCTION__); |
| 377 | |
| 378 | |
| 379 | /* Disable MPSC-Window2 */ |
| 380 | if (galsdma_set_mem_space (MV64460_CUNIT_BASE_ADDR_WIN_2_BIT, |
| 381 | MV64460_SDMA_DRAM_CS_2_TARGET, |
| 382 | 0, |
| 383 | memoryGetBankBaseAddress(2), |
| 384 | memoryGetBankSize(2)) != true) |
| 385 | printf ("%s: SDMA_Window2 memory setup failed !!! \n", |
| 386 | __FUNCTION__); |
| 387 | |
| 388 | |
| 389 | /* Disable MPSC-Window3 */ |
| 390 | if (galsdma_set_mem_space (MV64460_CUNIT_BASE_ADDR_WIN_3_BIT, |
| 391 | MV64460_SDMA_DRAM_CS_3_TARGET, |
| 392 | 0, |
| 393 | memoryGetBankBaseAddress(3), |
| 394 | memoryGetBankSize(3)) != true) |
| 395 | printf ("%s: SDMA_Window3 memory setup failed !!! \n", |
| 396 | __FUNCTION__); |
| 397 | |
| 398 | /* Setup MPSC0 access mode Window0 full access */ |
| 399 | GT_SET_REG_BITS (MPSC0_ACCESS_PROTECTION_REG, |
| 400 | (MV64460_SDMA_WIN_ACCESS_FULL << |
| 401 | (MV64460_CUNIT_BASE_ADDR_WIN_0_BIT * 2))); |
| 402 | |
| 403 | /* Setup MPSC1 access mode Window1 full access */ |
| 404 | GT_SET_REG_BITS (MPSC1_ACCESS_PROTECTION_REG, |
| 405 | (MV64460_SDMA_WIN_ACCESS_FULL << |
| 406 | (MV64460_CUNIT_BASE_ADDR_WIN_0_BIT * 2))); |
| 407 | |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 408 | /* Setup MPSC internal address space base address */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 409 | GT_REG_WRITE (CUNIT_INTERNAL_SPACE_BASE_ADDR_REG, CONFIG_SYS_GT_REGS); |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 410 | |
| 411 | /* no high address remap*/ |
| 412 | GT_REG_WRITE (CUNIT_HIGH_ADDR_REMAP_REG0, 0x00); |
| 413 | GT_REG_WRITE (CUNIT_HIGH_ADDR_REMAP_REG1, 0x00); |
| 414 | |
| 415 | /* clear interrupt cause register for MPSC (fault register)*/ |
| 416 | GT_REG_WRITE (CUNIT_INTERRUPT_CAUSE_REG, 0x00); |
| 417 | } |
| 418 | |
| 419 | |
| 420 | void mpsc_init2 (void) |
| 421 | { |
| 422 | int i; |
| 423 | |
| 424 | #ifndef CONFIG_MPSC_DEBUG_PORT |
| 425 | mpsc_putchar = mpsc_putchar_sdma; |
| 426 | mpsc_getchar = mpsc_getchar_sdma; |
| 427 | mpsc_test_char = mpsc_test_char_sdma; |
| 428 | #endif |
| 429 | /* RX descriptors */ |
| 430 | rx_desc_base = (unsigned int *) malloc (((RX_DESC + 1) * 8) * |
| 431 | sizeof (unsigned int)); |
| 432 | |
| 433 | /* align descriptors */ |
| 434 | rx_desc_base = (unsigned int *) |
| 435 | (((unsigned int) rx_desc_base + 32) & 0xFFFFFFF0); |
| 436 | |
| 437 | rx_desc_index = 0; |
| 438 | |
| 439 | memset ((void *) rx_desc_base, 0, |
| 440 | (RX_DESC * 8) * sizeof (unsigned int)); |
| 441 | |
| 442 | for (i = 0; i < RX_DESC; i++) { |
| 443 | rx_desc_base[i * 8 + 3] = (unsigned int) &rx_desc_base[i * 8 + 4]; /* Buffer */ |
| 444 | rx_desc_base[i * 8 + 2] = (unsigned int) &rx_desc_base[(i + 1) * 8]; /* Next descriptor */ |
| 445 | rx_desc_base[i * 8 + 1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; /* Command & control */ |
| 446 | rx_desc_base[i * 8] = 0x00100000; |
| 447 | } |
| 448 | rx_desc_base[(i - 1) * 8 + 2] = (unsigned int) &rx_desc_base[0]; |
| 449 | |
| 450 | FLUSH_DCACHE (&rx_desc_base[0], &rx_desc_base[RX_DESC * 8]); |
| 451 | GT_REG_WRITE (GALSDMA_0_CUR_RX_PTR + (CHANNEL * GALSDMA_REG_DIFF), |
| 452 | (unsigned int) &rx_desc_base[0]); |
| 453 | |
| 454 | /* TX descriptors */ |
| 455 | tx_desc_base = (unsigned int *) malloc (((TX_DESC + 1) * 8) * |
| 456 | sizeof (unsigned int)); |
| 457 | |
| 458 | /* align descriptors */ |
| 459 | tx_desc_base = (unsigned int *) |
| 460 | (((unsigned int) tx_desc_base + 32) & 0xFFFFFFF0); |
| 461 | |
| 462 | tx_desc_index = -1; |
| 463 | |
| 464 | memset ((void *) tx_desc_base, 0, |
| 465 | (TX_DESC * 8) * sizeof (unsigned int)); |
| 466 | |
| 467 | for (i = 0; i < TX_DESC; i++) { |
| 468 | tx_desc_base[i * 8 + 5] = (unsigned int) 0x23232323; |
| 469 | tx_desc_base[i * 8 + 4] = (unsigned int) 0x23232323; |
| 470 | tx_desc_base[i * 8 + 3] = |
| 471 | (unsigned int) &tx_desc_base[i * 8 + 4]; |
| 472 | tx_desc_base[i * 8 + 2] = |
| 473 | (unsigned int) &tx_desc_base[(i + 1) * 8]; |
| 474 | tx_desc_base[i * 8 + 1] = |
| 475 | DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; |
| 476 | |
| 477 | /* set sbytecnt and shadow byte cnt to 1 */ |
| 478 | tx_desc_base[i * 8] = 0x00010001; |
| 479 | } |
| 480 | tx_desc_base[(i - 1) * 8 + 2] = (unsigned int) &tx_desc_base[0]; |
| 481 | |
| 482 | FLUSH_DCACHE (&tx_desc_base[0], &tx_desc_base[TX_DESC * 8]); |
| 483 | |
| 484 | udelay (100); |
| 485 | |
| 486 | galsdma_enable_rx (); |
| 487 | |
| 488 | return; |
| 489 | } |
| 490 | |
| 491 | int galbrg_set_baudrate (int channel, int rate) |
| 492 | { |
| 493 | int clock; |
| 494 | |
| 495 | galbrg_disable (channel); /*ok */ |
| 496 | |
| 497 | #ifdef ZUMA_NTL |
| 498 | /* from tclk */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 499 | clock = (CONFIG_SYS_TCLK / (16 * rate)) - 1; |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 500 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 501 | clock = (CONFIG_SYS_TCLK / (16 * rate)) - 1; |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 502 | #endif |
| 503 | |
| 504 | galbrg_set_CDV (channel, clock); /* set timer Reg. for BRG */ |
| 505 | |
| 506 | galbrg_enable (channel); |
| 507 | |
| 508 | gd->baudrate = rate; |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | /* ------------------------------------------------------------------ */ |
| 514 | |
| 515 | /* Below are all the private functions that no one else needs */ |
| 516 | |
| 517 | static int galbrg_set_CDV (int channel, int value) |
| 518 | { |
| 519 | unsigned int temp; |
| 520 | |
| 521 | temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP)); |
| 522 | temp &= 0xFFFF0000; |
| 523 | temp |= (value & 0x0000FFFF); |
| 524 | GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp); |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static int galbrg_enable (int channel) |
| 530 | { |
| 531 | unsigned int temp; |
| 532 | |
| 533 | temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP)); |
| 534 | temp |= 0x00010000; |
| 535 | GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp); |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | static int galbrg_disable (int channel) |
| 541 | { |
| 542 | unsigned int temp; |
| 543 | |
| 544 | temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP)); |
| 545 | temp &= 0xFFFEFFFF; |
| 546 | GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp); |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static int galbrg_set_clksrc (int channel, int value) |
| 552 | { |
| 553 | unsigned int temp; |
| 554 | |
| 555 | temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP)); |
| 556 | temp &= 0xFFC3FFFF; /* Bit 18 - 21 (MV 64260 18-22) */ |
| 557 | temp |= (value << 18); |
| 558 | GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp); |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | static int galbrg_set_CUV (int channel, int value) |
| 563 | { |
| 564 | /* set CountUpValue */ |
| 565 | GT_REG_WRITE (GALBRG_0_BTREG + (channel * GALBRG_REG_GAP), value); |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | #if 0 |
| 571 | static int galbrg_reset (int channel) |
| 572 | { |
| 573 | unsigned int temp; |
| 574 | |
| 575 | temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP)); |
| 576 | temp |= 0x20000; |
| 577 | GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp); |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | #endif |
| 582 | |
| 583 | static int galsdma_set_RFT (int channel) |
| 584 | { |
| 585 | unsigned int temp; |
| 586 | |
| 587 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 588 | temp |= 0x00000001; |
| 589 | GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF), |
| 590 | temp); |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | static int galsdma_set_SFM (int channel) |
| 596 | { |
| 597 | unsigned int temp; |
| 598 | |
| 599 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 600 | temp |= 0x00000002; |
| 601 | GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF), |
| 602 | temp); |
| 603 | |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | static int galsdma_set_rxle (int channel) |
| 608 | { |
| 609 | unsigned int temp; |
| 610 | |
| 611 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 612 | temp |= 0x00000040; |
| 613 | GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF), |
| 614 | temp); |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int galsdma_set_txle (int channel) |
| 620 | { |
| 621 | unsigned int temp; |
| 622 | |
| 623 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 624 | temp |= 0x00000080; |
| 625 | GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF), |
| 626 | temp); |
| 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static int galsdma_set_RC (int channel, unsigned int value) |
| 632 | { |
| 633 | unsigned int temp; |
| 634 | |
| 635 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 636 | temp &= ~0x0000003c; |
| 637 | temp |= (value << 2); |
| 638 | GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF), |
| 639 | temp); |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static int galsdma_set_burstsize (int channel, unsigned int value) |
| 645 | { |
| 646 | unsigned int temp; |
| 647 | |
| 648 | temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF)); |
| 649 | temp &= 0xFFFFCFFF; |
| 650 | switch (value) { |
| 651 | case 8: |
| 652 | GT_REG_WRITE (GALSDMA_0_CONF_REG + |
| 653 | (channel * GALSDMA_REG_DIFF), |
| 654 | (temp | (0x3 << 12))); |
| 655 | break; |
| 656 | |
| 657 | case 4: |
| 658 | GT_REG_WRITE (GALSDMA_0_CONF_REG + |
| 659 | (channel * GALSDMA_REG_DIFF), |
| 660 | (temp | (0x2 << 12))); |
| 661 | break; |
| 662 | |
| 663 | case 2: |
| 664 | GT_REG_WRITE (GALSDMA_0_CONF_REG + |
| 665 | (channel * GALSDMA_REG_DIFF), |
| 666 | (temp | (0x1 << 12))); |
| 667 | break; |
| 668 | |
| 669 | case 1: |
| 670 | GT_REG_WRITE (GALSDMA_0_CONF_REG + |
| 671 | (channel * GALSDMA_REG_DIFF), |
| 672 | (temp | (0x0 << 12))); |
| 673 | break; |
| 674 | |
| 675 | default: |
| 676 | return -1; |
| 677 | break; |
| 678 | } |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int galmpsc_connect (int channel, int connect) |
| 684 | { |
| 685 | unsigned int temp; |
| 686 | |
| 687 | temp = GTREGREAD (GALMPSC_ROUTING_REGISTER); |
| 688 | |
| 689 | if ((channel == 0) && connect) |
| 690 | temp &= ~0x00000007; |
| 691 | else if ((channel == 1) && connect) |
| 692 | temp &= ~(0x00000007 << 6); |
| 693 | else if ((channel == 0) && !connect) |
| 694 | temp |= 0x00000007; |
| 695 | else |
| 696 | temp |= (0x00000007 << 6); |
| 697 | |
| 698 | /* Just in case... */ |
| 699 | temp &= 0x3fffffff; |
| 700 | |
| 701 | GT_REG_WRITE (GALMPSC_ROUTING_REGISTER, temp); |
| 702 | |
| 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int galmpsc_route_rx_clock (int channel, int brg) |
| 707 | { |
| 708 | unsigned int temp; |
| 709 | |
| 710 | temp = GTREGREAD (GALMPSC_RxC_ROUTE); |
| 711 | |
| 712 | if (channel == 0) { |
| 713 | temp &= ~0x0000000F; |
| 714 | temp |= brg; |
| 715 | } else { |
| 716 | temp &= ~0x00000F00; |
| 717 | temp |= (brg << 8); |
| 718 | } |
| 719 | |
| 720 | GT_REG_WRITE (GALMPSC_RxC_ROUTE, temp); |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static int galmpsc_route_tx_clock (int channel, int brg) |
| 726 | { |
| 727 | unsigned int temp; |
| 728 | |
| 729 | temp = GTREGREAD (GALMPSC_TxC_ROUTE); |
| 730 | |
| 731 | if (channel == 0) { |
| 732 | temp &= ~0x0000000F; |
| 733 | temp |= brg; |
| 734 | } else { |
| 735 | temp &= ~0x00000F00; |
| 736 | temp |= (brg << 8); |
| 737 | } |
| 738 | |
| 739 | GT_REG_WRITE (GALMPSC_TxC_ROUTE, temp); |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static int galmpsc_write_config_regs (int mpsc, int mode) |
| 745 | { |
| 746 | if (mode == GALMPSC_UART) { |
| 747 | /* Main config reg Low (Null modem, Enable Tx/Rx, UART mode) */ |
| 748 | GT_REG_WRITE (GALMPSC_MCONF_LOW + (mpsc * GALMPSC_REG_GAP), |
| 749 | 0x000004c4); |
| 750 | |
| 751 | /* Main config reg High (32x Rx/Tx clock mode, width=8bits */ |
| 752 | GT_REG_WRITE (GALMPSC_MCONF_HIGH + (mpsc * GALMPSC_REG_GAP), |
| 753 | 0x024003f8); |
| 754 | /* 22 2222 1111 */ |
| 755 | /* 54 3210 9876 */ |
| 756 | /* 0000 0010 0000 0000 */ |
| 757 | /* 1 */ |
| 758 | /* 098 7654 3210 */ |
| 759 | /* 0000 0011 1111 1000 */ |
| 760 | } else |
| 761 | return -1; |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | static int galmpsc_config_channel_regs (int mpsc) |
| 767 | { |
| 768 | GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), 0); |
| 769 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), 0); |
| 770 | GT_REG_WRITE (GALMPSC_CHANNELREG_3 + (mpsc * GALMPSC_REG_GAP), 1); |
| 771 | GT_REG_WRITE (GALMPSC_CHANNELREG_4 + (mpsc * GALMPSC_REG_GAP), 0); |
| 772 | GT_REG_WRITE (GALMPSC_CHANNELREG_5 + (mpsc * GALMPSC_REG_GAP), 0); |
| 773 | GT_REG_WRITE (GALMPSC_CHANNELREG_6 + (mpsc * GALMPSC_REG_GAP), 0); |
| 774 | GT_REG_WRITE (GALMPSC_CHANNELREG_7 + (mpsc * GALMPSC_REG_GAP), 0); |
| 775 | GT_REG_WRITE (GALMPSC_CHANNELREG_8 + (mpsc * GALMPSC_REG_GAP), 0); |
| 776 | GT_REG_WRITE (GALMPSC_CHANNELREG_9 + (mpsc * GALMPSC_REG_GAP), 0); |
| 777 | GT_REG_WRITE (GALMPSC_CHANNELREG_10 + (mpsc * GALMPSC_REG_GAP), 0); |
| 778 | |
| 779 | galmpsc_set_brkcnt (mpsc, 0x3); |
| 780 | galmpsc_set_tcschar (mpsc, 0xab); |
| 781 | |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | static int galmpsc_set_brkcnt (int mpsc, int value) |
| 786 | { |
| 787 | unsigned int temp; |
| 788 | |
| 789 | temp = GTREGREAD (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP)); |
| 790 | temp &= 0x0000FFFF; |
| 791 | temp |= (value << 16); |
| 792 | GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), temp); |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | static int galmpsc_set_tcschar (int mpsc, int value) |
| 798 | { |
| 799 | unsigned int temp; |
| 800 | |
| 801 | temp = GTREGREAD (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP)); |
| 802 | temp &= 0xFFFF0000; |
| 803 | temp |= value; |
| 804 | GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), temp); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | static int galmpsc_set_char_length (int mpsc, int value) |
| 810 | { |
| 811 | unsigned int temp; |
| 812 | |
| 813 | temp = GTREGREAD (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP)); |
| 814 | temp &= 0xFFFFCFFF; |
| 815 | temp |= (value << 12); |
| 816 | GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), temp); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static int galmpsc_set_stop_bit_length (int mpsc, int value) |
| 822 | { |
| 823 | unsigned int temp; |
| 824 | |
| 825 | temp = GTREGREAD (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP)); |
| 826 | temp &= 0xFFFFBFFF; |
| 827 | temp |= (value << 14); |
| 828 | GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), temp); |
| 829 | |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | static int galmpsc_set_parity (int mpsc, int value) |
| 834 | { |
| 835 | unsigned int temp; |
| 836 | |
| 837 | temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)); |
| 838 | if (value != -1) { |
| 839 | temp &= 0xFFF3FFF3; |
| 840 | temp |= ((value << 18) | (value << 2)); |
| 841 | temp |= ((value << 17) | (value << 1)); |
| 842 | } else { |
| 843 | temp &= 0xFFF1FFF1; |
| 844 | } |
| 845 | |
| 846 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp); |
| 847 | |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static int galmpsc_enter_hunt (int mpsc) |
| 852 | { |
| 853 | int temp; |
| 854 | |
| 855 | temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)); |
| 856 | temp |= 0x80000000; |
| 857 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp); |
| 858 | |
| 859 | while (GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)) & |
| 860 | MPSC_ENTER_HUNT) { |
| 861 | udelay (1); |
| 862 | } |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | |
| 867 | static int galmpsc_shutdown (int mpsc) |
| 868 | { |
| 869 | unsigned int temp; |
| 870 | |
| 871 | /* cause RX abort (clears RX) */ |
| 872 | temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)); |
| 873 | temp |= MPSC_RX_ABORT | MPSC_TX_ABORT; |
| 874 | temp &= ~MPSC_ENTER_HUNT; |
| 875 | GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp); |
| 876 | |
| 877 | GT_REG_WRITE (GALSDMA_0_COM_REG, 0); |
| 878 | GT_REG_WRITE (GALSDMA_0_COM_REG, SDMA_TX_ABORT | SDMA_RX_ABORT); |
| 879 | |
| 880 | /* shut down the MPSC */ |
| 881 | GT_REG_WRITE (GALMPSC_MCONF_LOW, 0); |
| 882 | GT_REG_WRITE (GALMPSC_MCONF_HIGH, 0); |
| 883 | GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), 0); |
| 884 | |
| 885 | udelay (100); |
| 886 | |
| 887 | /* shut down the sdma engines. */ |
| 888 | /* reset config to default */ |
| 889 | GT_REG_WRITE (GALSDMA_0_CONF_REG, 0x000000fc); |
| 890 | |
| 891 | udelay (100); |
| 892 | |
| 893 | /* clear the SDMA current and first TX and RX pointers */ |
| 894 | GT_REG_WRITE (GALSDMA_0_CUR_RX_PTR, 0); |
| 895 | GT_REG_WRITE (GALSDMA_0_CUR_TX_PTR, 0); |
| 896 | GT_REG_WRITE (GALSDMA_0_FIR_TX_PTR, 0); |
| 897 | |
| 898 | udelay (100); |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | static void galsdma_enable_rx (void) |
| 904 | { |
| 905 | int temp; |
| 906 | |
| 907 | /* Enable RX processing */ |
| 908 | temp = GTREGREAD (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF)); |
| 909 | temp |= RX_ENABLE; |
| 910 | GT_REG_WRITE (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF), temp); |
| 911 | |
| 912 | galmpsc_enter_hunt (CHANNEL); |
| 913 | } |
| 914 | |
| 915 | static int galmpsc_set_snoop (int mpsc, int value) |
| 916 | { |
| 917 | int reg = |
| 918 | mpsc ? MPSC_1_ADDRESS_CONTROL_LOW : |
| 919 | MPSC_0_ADDRESS_CONTROL_LOW; |
| 920 | int temp = GTREGREAD (reg); |
| 921 | |
| 922 | if (value) |
| 923 | temp |= (1 << 6) | (1 << 14) | (1 << 22) | (1 << 30); |
| 924 | else |
| 925 | temp &= ~((1 << 6) | (1 << 14) | (1 << 22) | (1 << 30)); |
| 926 | GT_REG_WRITE (reg, temp); |
| 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | /******************************************************************************* |
| 931 | * galsdma_set_mem_space - Set MV64460 IDMA memory decoding map. |
| 932 | * |
| 933 | * DESCRIPTION: |
| 934 | * the MV64460 SDMA has its own address decoding map that is de-coupled |
| 935 | * from the CPU interface address decoding windows. The SDMA channels |
| 936 | * share four address windows. Each region can be individually configured |
| 937 | * by this function by associating it to a target interface and setting |
| 938 | * base and size values. |
| 939 | * |
| 940 | * NOTE!!! |
| 941 | * The size must be in 64Kbyte granularity. |
| 942 | * The base address must be aligned to the size. |
| 943 | * The size must be a series of 1s followed by a series of zeros |
| 944 | * |
| 945 | * OUTPUT: |
| 946 | * None. |
| 947 | * |
| 948 | * RETURN: |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 949 | * true for success, false otherwise. |
Stefan Roese | 45993ea | 2006-11-29 15:42:37 +0100 | [diff] [blame] | 950 | * |
| 951 | *******************************************************************************/ |
| 952 | |
| 953 | static int galsdma_set_mem_space (unsigned int memSpace, |
| 954 | unsigned int memSpaceTarget, |
| 955 | unsigned int memSpaceAttr, |
| 956 | unsigned int baseAddress, unsigned int size) |
| 957 | { |
| 958 | unsigned int temp; |
| 959 | |
| 960 | if (size == 0) { |
| 961 | GT_RESET_REG_BITS (MV64460_CUNIT_BASE_ADDR_ENABLE_REG, |
| 962 | 1 << memSpace); |
| 963 | return true; |
| 964 | } |
| 965 | |
| 966 | /* The base address must be aligned to the size. */ |
| 967 | if (baseAddress % size != 0) { |
| 968 | return false; |
| 969 | } |
| 970 | if (size < 0x10000) { |
| 971 | return false; |
| 972 | } |
| 973 | |
| 974 | /* Align size and base to 64K */ |
| 975 | baseAddress &= 0xffff0000; |
| 976 | size &= 0xffff0000; |
| 977 | temp = size >> 16; |
| 978 | |
| 979 | /* Checking that the size is a sequence of '1' followed by a |
| 980 | sequence of '0' starting from LSB to MSB. */ |
| 981 | while ((temp > 0) && (temp & 0x1)) { |
| 982 | temp = temp >> 1; |
| 983 | } |
| 984 | |
| 985 | if (temp != 0) { |
| 986 | GT_REG_WRITE (MV64460_CUNIT_BASE_ADDR_REG0 + memSpace * 8, |
| 987 | (baseAddress | memSpaceTarget | memSpaceAttr)); |
| 988 | GT_REG_WRITE ((MV64460_CUNIT_SIZE0 + memSpace * 8), |
| 989 | (size - 1) & 0xffff0000); |
| 990 | GT_RESET_REG_BITS (MV64460_CUNIT_BASE_ADDR_ENABLE_REG, |
| 991 | 1 << memSpace); |
| 992 | } else { |
| 993 | /* An invalid size was specified */ |
| 994 | return false; |
| 995 | } |
| 996 | return true; |
| 997 | } |