OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [eth/] [cf/] [current/] [src/] [if_sc_lpe.c] - Blame information for rev 868

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      dev/if_sc_lpe.c
4
//
5
//      Ethernet device driver for Socket Communications Compact Flash card
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    gthomas
43
// Contributors: gthomas, jskov
44
// Date:         2000-07-07
45
// Purpose:      
46
// Description:  hardware driver for LPCF+ ethernet
47
//              
48
//
49
//####DESCRIPTIONEND####
50
//
51
//==========================================================================
52
 
53
#include <pkgconf/system.h>
54
#include <pkgconf/io_eth_drivers.h>
55
 
56
#include <cyg/infra/cyg_type.h>
57
#include <cyg/hal/hal_arch.h>
58
#include <cyg/infra/diag.h>
59
#include <cyg/hal/drv_api.h>
60
#include <cyg/io/pcmcia.h>
61
#include <cyg/io/eth/eth_drv.h>
62
#include <cyg/io/eth/netdev.h>
63
 
64
#ifdef CYGPKG_NET
65
#include <pkgconf/net.h>
66
#else
67
#include <cyg/hal/hal_if.h>
68
#endif
69
 
70
#include <cyg/io/dp83902a.h>
71
 
72
#define DP_DATA         0x10
73
#define DP_CARD_RESET   0x1f
74
 
75
#define SC_LPE_MANUF 0x0104
76
 
77
#ifdef CYGPKG_KERNEL
78
#define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL
79
static char sc_lpe_card_handler_stack[STACK_SIZE];
80
static cyg_thread sc_lpe_card_handler_thread_data;
81
static cyg_handle_t sc_lpe_card_handler_thread_handle;
82
#endif  // CYGPKG_KERNEL
83
 
84
__inline__ static void
85
do_delay(int _ticks)
86
{
87
#ifdef CYGPKG_KERNEL
88
    cyg_thread_delay(_ticks);
89
#else
90
    CYGACC_CALL_IF_DELAY_US(10000*_ticks);
91
#endif
92
}
93
 
94
//
95
// This runs as a separate thread to handle the card.  In particular, insertions
96
// and deletions need to be handled and they take time/coordination, thus the
97
// separate thread.
98
//
99
#ifdef CYGPKG_KERNEL
100
static void
101
#else
102
static int
103
#endif
104
sc_lpe_card_handler(cyg_addrword_t param)
105
{
106
    struct eth_drv_sc *sc = (struct eth_drv_sc *)param;
107
    dp83902a_priv_data_t *dp = (dp83902a_priv_data_t*)sc->driver_private;
108
    struct cf_slot *slot;
109
    struct cf_cftable cftable;
110
    struct cf_config config;
111
    int i, len, ptr, cor = 0;
112
    unsigned char buf[256], *cp;
113
    cyg_uint8* base;
114
    unsigned char *vers_product, *vers_manuf, *vers_revision, *vers_date;
115
#ifndef CYGPKG_KERNEL
116
    int tries = 0;
117
#endif
118
    bool first = true;
119
 
120
    slot = (struct cf_slot*)dp->plf_priv;
121
    cyg_drv_dsr_lock();
122
    while (true) {
123
        cyg_drv_dsr_unlock();   // Give DSRs a chance to run (card insertion)
124
        cyg_drv_dsr_lock();
125
        if ((slot->state == CF_SLOT_STATE_Inserted) ||
126
            ((slot->state == CF_SLOT_STATE_Ready) && first)) {
127
            first = false;
128
            if (slot->state != CF_SLOT_STATE_Ready) {
129
                cf_change_state(slot, CF_SLOT_STATE_Ready);
130
            }
131
            if (slot->state != CF_SLOT_STATE_Ready) {
132
                diag_printf("CF card won't go ready!\n");
133
#ifndef CYGPKG_KERNEL
134
                return false;
135
#else
136
                continue;
137
#endif
138
            }
139
            len = sizeof(buf);
140
            ptr = 0;
141
            if (cf_get_CIS(slot, CF_CISTPL_MANFID, buf, &len, &ptr)) {
142
                if (*(short *)&buf[2] != SC_LPE_MANUF) {
143
                    diag_printf("Not a SC LPE, sorry\n");
144
                    continue;
145
                }
146
            }
147
            ptr = 0;
148
            if (cf_get_CIS(slot, CF_CISTPL_VERS_1, buf, &len, &ptr)) {
149
                // Find individual strings
150
                cp = &buf[4];
151
                vers_product = cp;
152
                while (*cp++) ;  // Skip to nul
153
                vers_manuf = cp;
154
                while (*cp++) ;  // Skip to nul
155
                vers_revision = cp;
156
                while (*cp++) ;  // Skip to nul
157
                vers_date = cp;
158
#ifndef CYGPKG_KERNEL
159
                if (tries != 0) diag_printf("\n");
160
                diag_printf("%s: %s %s %s\n", vers_manuf, vers_product, vers_revision, vers_date);
161
#endif
162
            }
163
            ptr = 0;
164
            if (cf_get_CIS(slot, CF_CISTPL_CONFIG, buf, &len, &ptr)) {
165
                if (cf_parse_config(buf, len, &config)) {
166
                    cor = config.base;
167
                }
168
            }
169
            if (!cor) {
170
//                diag_printf("Couldn't find COR pointer!\n");
171
                continue;
172
            }
173
 
174
            ptr = 0;
175
            if (cf_get_CIS(slot, CF_CISTPL_CFTABLE_ENTRY, buf, &len, &ptr)) {
176
                if (cf_parse_cftable(buf, len, &cftable)) {
177
                    cyg_uint8 tmp;
178
                    // Initialize dp83902a IO details
179
                    dp->base = base = (cyg_uint8*)&slot->io[cftable.io_space.base[0]];
180
                    dp->data = base + DP_DATA;
181
                    dp->interrupt = slot->int_num;
182
                    cf_set_COR(slot, cor, cftable.cor);
183
                    // Reset card  (read issues RESET, write clears it)
184
                    HAL_READ_UINT8(base+DP_CARD_RESET, tmp);
185
                    HAL_WRITE_UINT8(base+DP_CARD_RESET, tmp);
186
                    // Wait for card
187
                    do {
188
                        DP_IN(base, DP_ISR, tmp);
189
                    } while (0 == (tmp & DP_ISR_RESET));
190
 
191
                    // Fetch hardware address from card - terrible, but not well defined
192
                    // Patterned after what Linux drivers do
193
                    if (!dp->hardwired_esa) {
194
                        static unsigned char sc_lpe_addr[] = { 0x00, 0xC0, 0x1B, 0x00, 0x99, 0x9E};
195
                        if ((slot->attr[0x1C0] == sc_lpe_addr[0]) &&
196
                            (slot->attr[0x1C2] == sc_lpe_addr[1]) &&
197
                            (slot->attr[0x1C4] == sc_lpe_addr[2])) {
198
                            sc_lpe_addr[3] = slot->attr[0x1C6];
199
                            sc_lpe_addr[4] = slot->attr[0x1C8];
200
                            sc_lpe_addr[5] = slot->attr[0x1CA];
201
                        } else {
202
                            // Coudn't find it in the CIS (attribute) data
203
                            unsigned char prom[32];
204
 
205
                            // Tell device to give up ESA
206
                            DP_OUT(base, DP_DCR, 0x48);  // Bytewide access
207
                            DP_OUT(base, DP_RBCH, 0);    // Remote byte count
208
                            DP_OUT(base, DP_RBCL, 0);
209
                            DP_OUT(base, DP_ISR, 0xFF);  // Clear any pending interrupts
210
                            DP_OUT(base, DP_IMR, 0x00);  // Mask all interrupts 
211
                            DP_OUT(base, DP_RCR, 0x20);  // Monitor
212
                            DP_OUT(base, DP_TCR, 0x02);  // loopback
213
                            DP_OUT(base, DP_RBCH, 32);   // Remote byte count
214
                            DP_OUT(base, DP_RBCL, 0);
215
                            DP_OUT(base, DP_RSAL, 0);    // Remote address
216
                            DP_OUT(base, DP_RSAH, 0);
217
                            DP_OUT(base, DP_CR, DP_CR_START|DP_CR_RDMA);  // Read data
218
                            for (i = 0;  i < 32;  i++) {
219
                                HAL_READ_UINT8(base+DP_DATAPORT, prom[i]);
220
                            }
221
                            if ((prom[0] == sc_lpe_addr[0]) &&
222
                                (prom[2] == sc_lpe_addr[1]) &&
223
                                (prom[4] == sc_lpe_addr[2])) {
224
                                diag_printf("Getting address from port\n");
225
                                sc_lpe_addr[3] = prom[6];
226
                                sc_lpe_addr[4] = prom[8];
227
                                sc_lpe_addr[5] = prom[10];
228
                            } else {
229
                                diag_printf("No valid ESA found in CIS! Hardwiring to 00:C0:1B:00:99:9E\n");
230
                            }
231
                        }
232
                        for (i = 0;  i < 6;  i++) {
233
                            dp->esa[i] = sc_lpe_addr[i];
234
                        }
235
                    }
236
 
237
                    // Initialize upper level driver
238
                    (sc->funs->eth_drv->init)(sc, dp->esa);
239
                    // Tell system card is ready to talk
240
                    dp->tab->status = CYG_NETDEVTAB_STATUS_AVAIL;
241
#ifndef CYGPKG_KERNEL
242
                    cyg_drv_dsr_unlock();
243
                    return true;
244
#endif
245
                } else {
246
                    diag_printf("Can't parse CIS\n");
247
                    continue;
248
                }
249
            } else {
250
                diag_printf("Can't fetch config info\n");
251
                continue;
252
            }
253
        } else if (slot->state == CF_SLOT_STATE_Removed) {
254
            diag_printf("Compact Flash card removed!\n");
255
        } else {
256
            cyg_drv_dsr_unlock();
257
            do_delay(50);  // FIXME!
258
#ifndef CYGPKG_KERNEL
259
            if (tries == 0) diag_printf("... Waiting for network card: ");
260
            diag_printf(".");
261
            if (++tries == 10) {
262
                // 5 seconds have elapsed - give up
263
                return false;
264
            }
265
            cf_hwr_poll(slot);  // Check to see if card has been inserted
266
#endif
267
            cyg_drv_dsr_lock();
268
        }
269
    }
270
}
271
 
272
bool
273
cyg_sc_lpe_init(struct cyg_netdevtab_entry *tab)
274
{
275
    struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance;
276
    dp83902a_priv_data_t *dp = (dp83902a_priv_data_t *)sc->driver_private;
277
    struct cf_slot* slot;
278
 
279
    cf_init();  // Make sure Compact Flash subsystem is initialized
280
    slot = dp->plf_priv = (void*)cf_get_slot(0);
281
    dp->tab = tab;
282
 
283
#ifdef CYGPKG_KERNEL
284
    // Create card handling [background] thread
285
    cyg_thread_create(CYGPKG_NET_THREAD_PRIORITY-1,          // Priority
286
                      sc_lpe_card_handler,                   // entry
287
                      (cyg_addrword_t)sc,                    // entry parameter
288
                      "SC LP-E card support",                // Name
289
                      &sc_lpe_card_handler_stack[0],         // Stack
290
                      STACK_SIZE,                            // Size
291
                      &sc_lpe_card_handler_thread_handle,    // Handle
292
                      &sc_lpe_card_handler_thread_data       // Thread data structure
293
            );
294
    cyg_thread_resume(sc_lpe_card_handler_thread_handle);    // Start it
295
 
296
    // Initialize environment, setup interrupt handler
297
    // eth_drv_dsr is used to tell the fast net thread to run the deliver funcion.
298
    cf_register_handler(slot, eth_drv_dsr, sc);
299
 
300
    return false;  // Device is not ready until inserted, powered up, etc.
301
#else
302
    // Initialize card
303
    return sc_lpe_card_handler((cyg_addrword_t)sc);
304
#endif
305
}
306
 
307
int
308
cyg_sc_lpe_int_vector(struct eth_drv_sc *sc)
309
{
310
    dp83902a_priv_data_t *dp = (dp83902a_priv_data_t *)sc->driver_private;
311
    struct cf_slot* slot = (struct cf_slot*)dp->plf_priv;
312
 
313
    return slot->int_num;
314
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.