Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 1 | /* |
| 2 | * BF537-STAMP POST code |
| 3 | * |
| 4 | * Enter bugs at http://blackfin.uclinux.org/ |
| 5 | * |
| 6 | * Copyright (c) 2005-2009 Analog Devices Inc. |
| 7 | * |
| 8 | * Licensed under the GPL-2 or later. |
| 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <config.h> |
| 13 | #include <command.h> |
| 14 | #include <asm/blackfin.h> |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 15 | #include <asm/gpio.h> |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 16 | |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 17 | /* Using sw10-PF5 as the hotkey */ |
| 18 | int post_hotkeys_pressed(void) |
| 19 | { |
| 20 | int delay = 3; |
| 21 | int i; |
| 22 | unsigned short value; |
| 23 | |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 24 | gpio_request(GPIO_PF5, "post"); |
| 25 | gpio_direction_input(GPIO_PF5); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 26 | |
| 27 | printf("########Press SW10 to enter Memory POST########: %2d ", delay); |
| 28 | while (delay--) { |
| 29 | for (i = 0; i < 100; i++) { |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 30 | value = gpio_get_value(GPIO_PF5); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 31 | if (value != 0) { |
| 32 | break; |
| 33 | } |
| 34 | udelay(10000); |
| 35 | } |
| 36 | printf("\b\b\b%2d ", delay); |
| 37 | } |
| 38 | printf("\b\b\b 0"); |
| 39 | printf("\n"); |
| 40 | if (value == 0) |
| 41 | return 0; |
| 42 | else { |
| 43 | printf("Hotkey has been pressed, Enter POST . . . . . .\n"); |
| 44 | return 1; |
| 45 | } |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 46 | |
| 47 | gpio_free(GPIO_PF5); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 50 | int uart_post_test(int flags) |
| 51 | { |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | #define BLOCK_SIZE 0x10000 |
| 56 | #define VERIFY_ADDR 0x2000000 |
| 57 | extern int erase_block_flash(int); |
| 58 | extern int write_data(long lStart, long lCount, uchar * pnData); |
| 59 | int flash_post_test(int flags) |
| 60 | { |
| 61 | unsigned short *pbuf, *temp; |
| 62 | int offset, n, i; |
| 63 | int value = 0; |
| 64 | int result = 0; |
| 65 | printf("\n"); |
| 66 | pbuf = (unsigned short *)VERIFY_ADDR; |
| 67 | temp = pbuf; |
| 68 | for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) { |
| 69 | offset = (n - 7) * BLOCK_SIZE; |
| 70 | printf("--------Erase block:%2d..", n); |
| 71 | erase_block_flash(n); |
| 72 | printf("OK\r"); |
| 73 | printf("--------Program block:%2d...", n); |
| 74 | write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf); |
| 75 | printf("OK\r"); |
| 76 | printf("--------Verify block:%2d...", n); |
| 77 | for (i = 0; i < BLOCK_SIZE; i += 2) { |
| 78 | if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) != |
| 79 | *temp++) { |
| 80 | value = 1; |
| 81 | result = 1; |
| 82 | } |
| 83 | } |
| 84 | if (value) |
| 85 | printf("failed\n"); |
| 86 | else |
| 87 | printf("OK %3d%%\r", |
| 88 | (int)( |
| 89 | (n + 1 - |
| 90 | FLASH_START_POST_BLOCK) * |
| 91 | 100 / (FLASH_END_POST_BLOCK - |
| 92 | FLASH_START_POST_BLOCK))); |
| 93 | |
| 94 | temp = pbuf; |
| 95 | value = 0; |
| 96 | } |
| 97 | printf("\n"); |
| 98 | if (result) |
| 99 | return -1; |
| 100 | else |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /**************************************************** |
| 105 | * LED1 ---- PF6 LED2 ---- PF7 * |
| 106 | * LED3 ---- PF8 LED4 ---- PF9 * |
| 107 | * LED5 ---- PF10 LED6 ---- PF11 * |
| 108 | ****************************************************/ |
| 109 | int led_post_test(int flags) |
| 110 | { |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 111 | unsigned int leds[] = { |
| 112 | GPIO_PF6, GPIO_PF7, GPIO_PF8, |
| 113 | GPIO_PF9, GPIO_PF10, GPIO_PF11, |
| 114 | }; |
| 115 | int i; |
| 116 | |
| 117 | for (i = 0; i < ARRAY_SIZE(leds); ++i) { |
| 118 | gpio_request(leds[i], "post"); |
| 119 | gpio_direction_output(leds[i], 0); |
| 120 | |
| 121 | printf("LED%i on", i + 1); |
| 122 | gpio_set_value(leds[i], 1); |
| 123 | udelay(1000000); |
| 124 | printf("\b\b\b\b\b\b\b"); |
| 125 | |
| 126 | gpio_free(leds[i]); |
| 127 | } |
| 128 | |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | /************************************************ |
| 133 | * SW10 ---- PF5 SW11 ---- PF4 * |
| 134 | * SW12 ---- PF3 SW13 ---- PF2 * |
| 135 | ************************************************/ |
| 136 | int button_post_test(int flags) |
| 137 | { |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 138 | unsigned int buttons[] = { |
| 139 | GPIO_PF2, GPIO_PF3, GPIO_PF4, GPIO_PF5, |
| 140 | }; |
| 141 | unsigned int sws[] = { 13, 12, 11, 10, }; |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 142 | int i, delay = 5; |
| 143 | unsigned short value = 0; |
| 144 | int result = 0; |
| 145 | |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 146 | for (i = 0; i < ARRAY_SIZE(buttons); ++i) { |
| 147 | gpio_request(buttons[i], "post"); |
| 148 | gpio_direction_input(buttons[i]); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 149 | |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 150 | delay = 5; |
| 151 | printf("\n--------Press SW%i: %2d ", sws[i], delay); |
| 152 | while (delay--) { |
| 153 | for (i = 0; i < 100; i++) { |
| 154 | value = gpio_get_value(buttons[i]); |
| 155 | if (value != 0) |
| 156 | break; |
| 157 | udelay(10000); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 158 | } |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 159 | printf("\b\b\b%2d ", delay); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 160 | } |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 161 | if (value != 0) |
| 162 | puts("\b\bOK"); |
| 163 | else { |
| 164 | result = -1; |
| 165 | puts("\b\bfailed"); |
| 166 | } |
| 167 | |
| 168 | gpio_free(buttons[i]); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 169 | } |
| 170 | |
Mike Frysinger | 0049053 | 2010-07-25 17:16:50 -0400 | [diff] [blame] | 171 | puts("\n"); |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 172 | |
Mike Frysinger | 4de1a5d | 2009-02-22 16:26:35 -0500 | [diff] [blame] | 173 | return result; |
| 174 | } |