[b599faa] | 1 | /* BSP-specific bits of flash programmer support */ |
---|
| 2 | |
---|
[ac7af4a] | 3 | /* |
---|
[b599faa] | 4 | * Authorship |
---|
| 5 | * ---------- |
---|
| 6 | * This software ('mvme3100' RTEMS BSP) was created by |
---|
| 7 | * |
---|
| 8 | * Till Straumann <strauman@slac.stanford.edu>, 2005-2007, |
---|
| 9 | * Stanford Linear Accelerator Center, Stanford University. |
---|
[ac7af4a] | 10 | * |
---|
[b599faa] | 11 | * Acknowledgement of sponsorship |
---|
| 12 | * ------------------------------ |
---|
| 13 | * The 'mvme3100' BSP was produced by |
---|
| 14 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
| 15 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
[ac7af4a] | 16 | * |
---|
[b599faa] | 17 | * Government disclaimer of liability |
---|
| 18 | * ---------------------------------- |
---|
| 19 | * Neither the United States nor the United States Department of Energy, |
---|
| 20 | * nor any of their employees, makes any warranty, express or implied, or |
---|
| 21 | * assumes any legal liability or responsibility for the accuracy, |
---|
| 22 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
| 23 | * disclosed, or represents that its use would not infringe privately owned |
---|
| 24 | * rights. |
---|
[ac7af4a] | 25 | * |
---|
[b599faa] | 26 | * Stanford disclaimer of liability |
---|
| 27 | * -------------------------------- |
---|
| 28 | * Stanford University makes no representations or warranties, express or |
---|
| 29 | * implied, nor assumes any liability for the use of this software. |
---|
[ac7af4a] | 30 | * |
---|
[b599faa] | 31 | * Stanford disclaimer of copyright |
---|
| 32 | * -------------------------------- |
---|
| 33 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
| 34 | * copyright and all other rights in this software. Hence, anyone may |
---|
[ac7af4a] | 35 | * freely use it for any purpose without restriction. |
---|
| 36 | * |
---|
[b599faa] | 37 | * Maintenance of notices |
---|
| 38 | * ---------------------- |
---|
| 39 | * In the interest of clarity regarding the origin and status of this |
---|
| 40 | * SLAC software, this and all the preceding Stanford University notices |
---|
| 41 | * are to remain affixed to any copy or derivative of this software made |
---|
| 42 | * or distributed by the recipient and are to be affixed to any copy of |
---|
| 43 | * software made or distributed by the recipient that contains a copy or |
---|
| 44 | * derivative of this software. |
---|
[ac7af4a] | 45 | * |
---|
[b599faa] | 46 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
[ac7af4a] | 47 | */ |
---|
[b599faa] | 48 | #include <rtems.h> |
---|
| 49 | #include <bsp.h> |
---|
| 50 | #include <libcpu/spr.h> |
---|
| 51 | #include <stdio.h> |
---|
| 52 | |
---|
| 53 | #include <bsp/flashPgmPvt.h> |
---|
| 54 | |
---|
| 55 | SPR_RO(TBRL) |
---|
| 56 | |
---|
| 57 | #define STATIC static |
---|
| 58 | |
---|
| 59 | static struct bankdesc mvme3100Flash[] = { |
---|
| 60 | /* |
---|
| 61 | * Bank is populated from the top; make max_size negative to |
---|
| 62 | * indicate this |
---|
| 63 | */ |
---|
| 64 | { 0xf8000000, 0, - 0x08000000, 2, BSP_flash_vendor_spansion, 0, 0, 0 }, |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | STATIC struct bankdesc * |
---|
| 68 | bankcheck(int bank, int quiet) |
---|
| 69 | { |
---|
| 70 | if ( bank ) { |
---|
| 71 | if ( !quiet ) |
---|
| 72 | fprintf(stderr,"Invalid flash bank #%i\n",bank); |
---|
| 73 | return 0; |
---|
| 74 | } |
---|
| 75 | return &mvme3100Flash[bank]; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | STATIC int |
---|
| 79 | flash_wp(int bank, int enbl) |
---|
| 80 | { |
---|
| 81 | uint8_t mask = enbl < 0 ? 0 : BSP_MVME3100_FLASH_CSR_F_WP_SW; |
---|
| 82 | uint8_t val; |
---|
| 83 | |
---|
| 84 | if ( bank != 0 ) { |
---|
| 85 | fprintf(stderr,"Invalid flash bank #%i\n",bank); |
---|
| 86 | return -1; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | if ( enbl ) |
---|
| 90 | val = BSP_setSysReg( BSP_MVME3100_FLASH_CSR, mask ); |
---|
| 91 | else |
---|
| 92 | val = BSP_clrSysReg( BSP_MVME3100_FLASH_CSR, mask ); |
---|
| 93 | |
---|
| 94 | if ( BSP_MVME3100_FLASH_CSR_F_WP_HW & val ) { |
---|
| 95 | fprintf(stderr,"Flash: hardware write-protection engaged (switch)\n"); |
---|
| 96 | return -1; |
---|
| 97 | } |
---|
| 98 | if ( enbl < 0 ) |
---|
| 99 | return val & (BSP_MVME3100_FLASH_CSR_F_WP_HW | BSP_MVME3100_FLASH_CSR_F_WP_SW ); |
---|
| 100 | return 0; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | STATIC uint32_t |
---|
[6987eecc] | 104 | read_us_timer(void) |
---|
[b599faa] | 105 | { |
---|
| 106 | uint32_t mhz = BSP_bus_frequency/BSP_time_base_divisor/1000; |
---|
| 107 | |
---|
| 108 | return _read_TBRL()/mhz; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /* BSP ops (detect banks, handle write-protection on board) */ |
---|
| 112 | struct flash_bsp_ops BSP_flashBspOps = { |
---|
| 113 | bankcheck: bankcheck, |
---|
| 114 | flash_wp: flash_wp, |
---|
| 115 | read_us_timer: read_us_timer, |
---|
| 116 | }; |
---|