~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/u-boot/board/esd/cpci405/flash.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * (C) Copyright 2001-2003
 
3
 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
 
4
 *
 
5
 * SPDX-License-Identifier:     GPL-2.0+
 
6
 */
 
7
 
 
8
#include <common.h>
 
9
#include <asm/ppc4xx.h>
 
10
#include <asm/processor.h>
 
11
 
 
12
/*
 
13
 * include common flash code (for esd boards)
 
14
 */
 
15
#include "../common/flash.c"
 
16
 
 
17
/*-----------------------------------------------------------------------
 
18
 * Functions
 
19
 */
 
20
static ulong flash_get_size (vu_long * addr, flash_info_t * info);
 
21
static void flash_get_offsets (ulong base, flash_info_t * info);
 
22
 
 
23
/*-----------------------------------------------------------------------
 
24
 */
 
25
 
 
26
unsigned long calc_size(unsigned long size)
 
27
{
 
28
        switch (size) {
 
29
        case 1 << 20:
 
30
                return 0;
 
31
        case 2 << 20:
 
32
                return 1;
 
33
        case 4 << 20:
 
34
                return 2;
 
35
        case 8 << 20:
 
36
                return 3;
 
37
        case 16 << 20:
 
38
                return 4;
 
39
        default:
 
40
                return 0;
 
41
        }
 
42
}
 
43
 
 
44
 
 
45
unsigned long flash_init (void)
 
46
{
 
47
        unsigned long size_b0, size_b1;
 
48
        int i;
 
49
        uint pbcr;
 
50
        unsigned long base_b0, base_b1;
 
51
 
 
52
        /* Init: no FLASHes known */
 
53
        for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
 
54
                flash_info[i].flash_id = FLASH_UNKNOWN;
 
55
        }
 
56
 
 
57
        /* Static FLASH Bank configuration here - FIXME XXX */
 
58
 
 
59
        base_b0 = FLASH_BASE0_PRELIM;
 
60
        size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
 
61
 
 
62
        if (flash_info[0].flash_id == FLASH_UNKNOWN) {
 
63
                printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
 
64
                                size_b0, size_b0 << 20);
 
65
        }
 
66
 
 
67
        base_b1 = FLASH_BASE1_PRELIM;
 
68
        size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
 
69
 
 
70
        /* Re-do sizing to get full correct info */
 
71
 
 
72
        if (size_b1) {
 
73
                if (size_b1 < (1 << 20)) {
 
74
                        /* minimum CS size on PPC405GP is 1MB !!! */
 
75
                        size_b1 = 1 << 20;
 
76
                }
 
77
                base_b1 = -size_b1;
 
78
                mtdcr (EBC0_CFGADDR, PB0CR);
 
79
                pbcr = mfdcr (EBC0_CFGDATA);
 
80
                mtdcr (EBC0_CFGADDR, PB0CR);
 
81
                pbcr = (pbcr & 0x0001ffff) | base_b1 | (calc_size(size_b1) << 17);
 
82
                mtdcr (EBC0_CFGDATA, pbcr);
 
83
#if 0 /* test-only */
 
84
                printf("size_b1=%x base_b1=%x PB1CR = %x\n",
 
85
                       size_b1, base_b1, pbcr); /* test-only */
 
86
#endif
 
87
        }
 
88
 
 
89
        if (size_b0) {
 
90
                if (size_b0 < (1 << 20)) {
 
91
                        /* minimum CS size on PPC405GP is 1MB !!! */
 
92
                        size_b0 = 1 << 20;
 
93
                }
 
94
                base_b0 = base_b1 - size_b0;
 
95
                mtdcr (EBC0_CFGADDR, PB1CR);
 
96
                pbcr = mfdcr (EBC0_CFGDATA);
 
97
                mtdcr (EBC0_CFGADDR, PB1CR);
 
98
                pbcr = (pbcr & 0x0001ffff) | base_b0 | (calc_size(size_b0) << 17);
 
99
                mtdcr (EBC0_CFGDATA, pbcr);
 
100
#if 0 /* test-only */
 
101
                printf("size_b0=%x base_b0=%x PB0CR = %x\n",
 
102
                       size_b0, base_b0, pbcr); /* test-only */
 
103
#endif
 
104
        }
 
105
 
 
106
        size_b0 = flash_get_size ((vu_long *) base_b0, &flash_info[0]);
 
107
 
 
108
        flash_get_offsets (base_b0, &flash_info[0]);
 
109
 
 
110
        /* monitor protection ON by default */
 
111
        flash_protect (FLAG_PROTECT_SET,
 
112
                        base_b0 + size_b0 - monitor_flash_len,
 
113
                        base_b0 + size_b0 - 1, &flash_info[0]);
 
114
 
 
115
        if (size_b1) {
 
116
                /* Re-do sizing to get full correct info */
 
117
                size_b1 = flash_get_size ((vu_long *) base_b1, &flash_info[1]);
 
118
 
 
119
                flash_get_offsets (base_b1, &flash_info[1]);
 
120
 
 
121
                /* monitor protection ON by default */
 
122
                flash_protect (FLAG_PROTECT_SET,
 
123
                                base_b1 + size_b1 - monitor_flash_len,
 
124
                                base_b1 + size_b1 - 1, &flash_info[1]);
 
125
                /* monitor protection OFF by default (one is enough) */
 
126
                flash_protect (FLAG_PROTECT_CLEAR,
 
127
                                base_b0 + size_b0 - monitor_flash_len,
 
128
                                base_b0 + size_b0 - 1, &flash_info[0]);
 
129
        } else {
 
130
                flash_info[1].flash_id = FLASH_UNKNOWN;
 
131
                flash_info[1].sector_count = -1;
 
132
        }
 
133
 
 
134
        flash_info[0].size = size_b0;
 
135
        flash_info[1].size = size_b1;
 
136
 
 
137
        return (size_b0 + size_b1);
 
138
}