source: rtems/bsps/powerpc/mpc55xxevb/net/if_smc.c @ 4fb1b79

5
Last change on this file since 4fb1b79 was 031df391, checked in by Sebastian Huber <sebastian.huber@…>, on 04/23/18 at 07:53:31

bsps: Move legacy network drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1#include <bsp.h>
2
3#ifdef HAS_SMC91111
4
5#include <mpc55xx/mpc55xx.h>
6#include <mpc55xx/regs.h>
7
8#include <rtems.h>
9
10#include <bsp/irq.h>
11#include <rtems/bspIo.h>
12#include <libcpu/powerpc-utility.h>
13
14
15#include <stdlib.h>
16#include <stdio.h>
17#include <stdarg.h>
18#include <rtems/error.h>
19#include <rtems/rtems_bsdnet.h>
20#include <rtems/irq-extension.h>
21
22#include <sys/param.h>
23#include <sys/mbuf.h>
24
25#include <sys/socket.h>
26#include <sys/sockio.h>
27#include <net/if.h>
28#include <netinet/in.h>
29#include <netinet/if_ether.h>
30
31#include <libchip/smc91111exp.h>
32
33
34
35/* The SMC91111 on the MPC5554SOM is IRQ2.
36 */
37#define SMC91111_BASE_ADDR (void*)0x22000300
38#define SMC91111_BASE_IRQ  MPC55XX_IRQ_SIU_EXTERNAL_2
39#define SMC91111_BASE_PIO  4
40
41extern void lan91cxx_interrupt_handler(void *arg);
42
43static const union SIU_EISR_tag clear_eisr_2 = {.B.EIF2 = 1};
44
45static void rtems_smc91111_interrupt_wrapper(void *arg)
46{
47    /* Clear external interrupt status */
48
49    SIU.EISR = clear_eisr_2;
50
51    lan91cxx_interrupt_handler(arg);
52}
53
54scmv91111_configuration_t mpc5554_scmv91111_configuration = {
55  SMC91111_BASE_ADDR, /* base address */
56  SMC91111_BASE_IRQ,  /* vector number */
57  SMC91111_BASE_PIO,  /* XXX: What's this? */
58  100,                /* 100b */
59  1,                  /* fulldx */
60  1,                  /* autoneg */
61  "SMC91111",
62  RTEMS_INTERRUPT_UNIQUE,
63  rtems_smc91111_interrupt_wrapper,
64  (void *)0
65};
66
67/*
68 * Attach an SMC91111 driver to the system
69 */
70int rtems_smc91111_driver_attach_mpc5554(struct rtems_bsdnet_ifconfig *config)
71{
72  /* Configure IRQ2 (GPIO pin 211) is set up properly:
73   * Secondary, Alternate, Input.
74   */
75  static const union SIU_PCR_tag irq_input_pcr = {
76      .B.PA = 2,     /* Alternate function 1 */
77      .B.OBE = 0,
78      .B.IBE = 1,    /* Input Buffer Enable */
79      .B.DSC = 0,
80      .B.ODE = 0,
81      .B.HYS = 1,
82      .B.SRC = 3,    /* Maximum slew rate */
83      .B.WPE = 0,    /* Disable weak pullup/pulldown */
84      .B.WPS = 1     /* Specify weak pullup?  But it isn't enabled! */
85    };
86
87    union SIU_ORER_tag orer = MPC55XX_ZERO_FLAGS;
88    union SIU_DIRER_tag direr = MPC55XX_ZERO_FLAGS;
89    union SIU_IREER_tag ireer = MPC55XX_ZERO_FLAGS;
90    union SIU_IFEER_tag ifeer = MPC55XX_ZERO_FLAGS;
91    union SIU_IDFR_tag idfr = MPC55XX_ZERO_FLAGS;
92    union SIU_DIRSR_tag dirsr = MPC55XX_ZERO_FLAGS;
93    rtems_interrupt_level level;
94
95#define MPC55XX_EBI_CS_2_BR 0x22000003
96#define MPC55XX_EBI_CS_2_OR 0xff000010
97#if MPC55XX_EBI_CS_2_BR
98    static const union SIU_PCR_tag primary_50pf_weak_pullup = {                 /* 0x4c3 */
99        .B.PA = 1,
100        .B.DSC = 3,
101        .B.WPE = 1,
102        .B.WPS = 1
103    };
104    EBI.CS[2].BR.R = MPC55XX_EBI_CS_2_BR;
105    EBI.CS[2].OR.R = MPC55XX_EBI_CS_2_OR;
106    SIU.PCR[2] = primary_50pf_weak_pullup;
107#endif
108
109    SIU.PCR[211] = irq_input_pcr;
110
111    /* XXX These should be using bit set and bit clear instructions */
112
113    /* DMA/Interrupt Request Select */
114    rtems_interrupt_disable(level);
115    dirsr.R = SIU.DIRSR.R;
116    dirsr.B.DIRS2 = 0;                  /* Select interrupt not DMA */
117    SIU.DIRSR.R = dirsr.R;
118    rtems_interrupt_enable(level);
119
120    /* Overrun Request Enable */
121    rtems_interrupt_disable(level);
122    orer.R = SIU.ORER.R;
123    orer.B.ORE2 = 0;                    /* Disable overruns. */
124    SIU.ORER.R = orer.R;
125    rtems_interrupt_enable(level);
126
127    /* IRQ Rising-Edge Enable */
128    rtems_interrupt_disable(level);
129    ireer.R = SIU.IREER.R;
130    ireer.B.IREE2 = 1;              /* Enable rising edge. */
131    SIU.IREER.R = ireer.R;
132    rtems_interrupt_enable(level);
133
134    /* IRQ Falling-Edge Enable */
135    rtems_interrupt_disable(level);
136    ifeer.R = SIU.IFEER.R;
137    ifeer.B.IFEE2 = 0;              /* Disable falling edge. */
138    SIU.IFEER.R = ifeer.R;
139    rtems_interrupt_enable(level);
140
141    /* IRQ Digital Filter */
142    rtems_interrupt_disable(level);
143    idfr.R = SIU.IDFR.R;
144    idfr.B.DFL = 0;                 /* Minimal digital filter. */
145    SIU.IDFR.R = idfr.R;
146    rtems_interrupt_enable(level);
147
148    /* Clear external interrupt status */
149    SIU.EISR = clear_eisr_2;
150
151    /* DMA/Interrupt Request Enable */
152    rtems_interrupt_disable(level);
153    direr.R = SIU.DIRER.R;
154    direr.B.EIRE2 = 1;              /* Enable. */
155    SIU.DIRER.R = direr.R;
156    rtems_interrupt_enable(level);
157
158    return _rtems_smc91111_driver_attach(config,&mpc5554_scmv91111_configuration);
159};
160
161#endif /* HAS_SMC91111 */
Note: See TracBrowser for help on using the repository browser.