Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / shared / hndgige.c
blob4937ced298772e9c081118363a915424673d84a9
1 /*
2 * HND SiliconBackplane Gigabit Ethernet core software interface
4 * Copyright (C) 2009, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: hndgige.c,v 1.11 2008/03/28 19:31:55 Exp $
15 #include <typedefs.h>
16 #include <osl.h>
17 #include <pcicfg.h>
18 #include <hndsoc.h>
19 #include <bcmutils.h>
20 #include <siutils.h>
21 #include <sbgige.h>
22 #include <hndpci.h>
23 #include <hndgige.h>
26 * Setup the gige core.
27 * Resetting the core will lose all settings.
29 void
30 hndgige_init(si_t *sih, uint32 unit, bool *rgmii)
32 volatile pci_config_regs *pci;
33 sbgige_pcishim_t *ocp;
34 sbconfig_t *sb;
35 osl_t *osh;
36 uint32 statelow;
37 uint32 statehigh;
38 uint32 base;
39 uint32 idx;
40 void *regs;
42 /* Sanity checks */
43 ASSERT(sih);
44 ASSERT(rgmii);
46 idx = si_coreidx(sih);
48 /* point to the gige core registers */
49 regs = si_setcore(sih, GIGETH_CORE_ID, unit);
50 ASSERT(regs);
52 osh = si_osh(sih);
54 pci = &((sbgige_t *)regs)->pcicfg;
55 ocp = &((sbgige_t *)regs)->pcishim;
56 sb = &((sbgige_t *)regs)->sbconfig;
58 /* Enable the core clock and memory access */
59 if (!si_iscoreup(sih))
60 si_core_reset(sih, 0, 0);
63 * Setup the 64K memory-mapped region base address through BAR0.
64 * Leave the other BAR values alone.
66 base = si_addrspace(sih, 1);
67 W_REG(osh, &pci->base[0], base);
68 W_REG(osh, &pci->base[1], 0);
71 * Enable the PCI memory access anyway. Any PCI config commands
72 * issued before the core is enabled will go to the emulation
73 * only and will not go to the real PCI config registers.
75 OR_REG(osh, &pci->command, 2);
78 * Enable the posted write flush scheme as follows:
80 * - Enable flush on any core register read
81 * - Enable timeout on the flush
82 * - Disable the interrupt mask when flushing
84 * This differs from the default setting only in that interrupts are
85 * not masked. Since posted writes are not flushed on interrupt, the
86 * driver must explicitly request a flush in its interrupt handling
87 * by reading a core register.
89 W_REG(osh, &ocp->FlushStatusControl, 0x68);
92 * Determine whether the GbE is in GMII or RGMII mode. This is
93 * indicated in bit 16 of the SBTMStateHigh register, which is
94 * part of the core-specific flags field.
96 * For GMII, bypass the Rx/Tx DLLs, i.e. add no delay to RXC/GTXC
97 * within the core. For RGMII, do not bypass the DLLs, resulting
98 * in added delay for RXC/GTXC. The SBTMStateLow register contains
99 * the controls for doing this in the core-specific flags field:
101 * bit 24 - Enable DLL controls
102 * bit 20 - Bypass Rx DLL
103 * bit 19 - Bypass Tx DLL
105 statelow = R_REG(osh, &sb->sbtmstatelow); /* DLL controls */
106 statehigh = R_REG(osh, &sb->sbtmstatehigh); /* GMII/RGMII mode */
107 if ((statehigh & (1 << 16)) != 0) /* RGMII */
109 statelow &= ~(1 << 20); /* no Rx bypass (delay) */
110 statelow &= ~(1 << 19); /* no Tx bypass (delay) */
111 *rgmii = TRUE;
113 else /* GMII */
115 statelow |= (1 << 20); /* Rx bypass (no delay) */
116 statelow |= (1 << 19); /* Tx bypass (no delay) */
117 *rgmii = FALSE;
119 statelow |= (1 << 24); /* enable DLL controls */
120 W_REG(osh, &sb->sbtmstatelow, statelow);
122 si_setcoreidx(sih, idx);