| 1 | /* |
| 2 | * device board |
| 3 | * |
| 4 | * Copyright 2009 (C) Qi Hardware Inc., |
| 5 | * Author: Xiangfu Liu <xiangfu@qi-hardware.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 3 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA |
| 20 | */ |
| 21 | |
| 22 | #include "jz4750.h" |
| 23 | #include "configs.h" |
| 24 | #include "usb_boot_defines.h" |
| 25 | |
| 26 | extern struct fw_args *fw_args; |
| 27 | |
| 28 | unsigned int check_sdram(unsigned int saddr, unsigned int size) |
| 29 | { |
| 30 | unsigned int addr,err = 0; |
| 31 | |
| 32 | serial_puts("\nCheck SDRAM ... \n"); |
| 33 | saddr += 0xa0000000; |
| 34 | size += saddr; |
| 35 | serial_put_hex(saddr); |
| 36 | serial_put_hex(size); |
| 37 | saddr &= 0xfffffffc; /* must word align */ |
| 38 | for (addr = saddr; addr < size; addr += 4) |
| 39 | { |
| 40 | *(volatile unsigned int *)addr = addr; |
| 41 | if (*(volatile unsigned int *)addr != addr) |
| 42 | { |
| 43 | serial_put_hex(addr); |
| 44 | err = addr; |
| 45 | } |
| 46 | } |
| 47 | if (err) |
| 48 | serial_puts("Check SDRAM fail!\n"); |
| 49 | else |
| 50 | serial_puts("Check SDRAM pass!\n"); |
| 51 | return err; |
| 52 | } |
| 53 | |
| 54 | void gpio_test(unsigned char ops, unsigned char pin) |
| 55 | { |
| 56 | __gpio_as_output(pin); |
| 57 | if (ops) |
| 58 | { |
| 59 | serial_puts("\nGPIO set "); |
| 60 | serial_put_hex(pin); |
| 61 | __gpio_set_pin(pin); |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | serial_puts("\nGPIO clear "); |
| 66 | serial_put_hex(pin); |
| 67 | __gpio_clear_pin(pin); |
| 68 | } |
| 69 | /* __gpio_as_input(pin); */ |
| 70 | } |
| 71 | |
| 72 | void do_debug() |
| 73 | { |
| 74 | switch (fw_args->debug_ops) { |
| 75 | case 1: /* sdram check */ |
| 76 | switch (CPU_ID) { |
| 77 | case 0x4740: |
| 78 | gpio_init_4740(); |
| 79 | serial_init(); |
| 80 | sdram_init_4740(); |
| 81 | break; |
| 82 | case 0x4750: |
| 83 | gpio_init_4750(); |
| 84 | serial_init(); |
| 85 | sdram_init_4750(); |
| 86 | break; |
| 87 | default: |
| 88 | ; |
| 89 | } |
| 90 | REG8(USB_REG_INDEX) = 1; |
| 91 | REG32(USB_FIFO_EP1) = check_sdram(fw_args->start, fw_args->size); |
| 92 | REG32(USB_FIFO_EP1) = 0x0; |
| 93 | REG8(USB_REG_INCSR) |= USB_INCSR_INPKTRDY; |
| 94 | break; |
| 95 | case 2: /* set gpio */ |
| 96 | gpio_test(1, fw_args->pin_num); |
| 97 | break; |
| 98 | case 3: /* clear gpio */ |
| 99 | gpio_test(0, fw_args->pin_num); |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |