Linux 2.6.20.7
[linux/fpc-iii.git] / drivers / net / fec_8xx / fec_8xx-netta.c
blob790d9dbe42ddf127b4e9f6794d8b26cb60cdbb6c
1 /*
2 * FEC instantatiation file for NETTA
3 */
5 #include <linux/kernel.h>
6 #include <linux/types.h>
7 #include <linux/sched.h>
8 #include <linux/string.h>
9 #include <linux/ptrace.h>
10 #include <linux/errno.h>
11 #include <linux/ioport.h>
12 #include <linux/slab.h>
13 #include <linux/interrupt.h>
14 #include <linux/pci.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
17 #include <linux/netdevice.h>
18 #include <linux/etherdevice.h>
19 #include <linux/skbuff.h>
20 #include <linux/spinlock.h>
21 #include <linux/mii.h>
22 #include <linux/ethtool.h>
23 #include <linux/bitops.h>
25 #include <asm/8xx_immap.h>
26 #include <asm/pgtable.h>
27 #include <asm/mpc8xx.h>
28 #include <asm/irq.h>
29 #include <asm/uaccess.h>
30 #include <asm/commproc.h>
32 #include "fec_8xx.h"
34 /*************************************************/
36 static struct fec_platform_info fec1_info = {
37 .fec_no = 0,
38 .use_mdio = 1,
39 .phy_addr = 8,
40 .fec_irq = SIU_LEVEL1,
41 .phy_irq = CPM_IRQ_OFFSET + CPMVEC_PIO_PC6,
42 .rx_ring = 128,
43 .tx_ring = 16,
44 .rx_copybreak = 240,
45 .use_napi = 1,
46 .napi_weight = 17,
49 static struct fec_platform_info fec2_info = {
50 .fec_no = 1,
51 .use_mdio = 1,
52 .phy_addr = 2,
53 .fec_irq = SIU_LEVEL3,
54 .phy_irq = CPM_IRQ_OFFSET + CPMVEC_PIO_PC7,
55 .rx_ring = 128,
56 .tx_ring = 16,
57 .rx_copybreak = 240,
58 .use_napi = 1,
59 .napi_weight = 17,
62 static struct net_device *fec1_dev;
63 static struct net_device *fec2_dev;
65 /* XXX custom u-boot & Linux startup needed */
66 extern const char *__fw_getenv(const char *var);
68 /* access ports */
69 #define setbits32(_addr, _v) __fec_out32(&(_addr), __fec_in32(&(_addr)) | (_v))
70 #define clrbits32(_addr, _v) __fec_out32(&(_addr), __fec_in32(&(_addr)) & ~(_v))
72 #define setbits16(_addr, _v) __fec_out16(&(_addr), __fec_in16(&(_addr)) | (_v))
73 #define clrbits16(_addr, _v) __fec_out16(&(_addr), __fec_in16(&(_addr)) & ~(_v))
75 int fec_8xx_platform_init(void)
77 immap_t *immap = (immap_t *)IMAP_ADDR;
78 bd_t *bd = (bd_t *) __res;
79 const char *s;
80 char *e;
81 int i;
83 /* use MDC for MII */
84 setbits16(immap->im_ioport.iop_pdpar, 0x0080);
85 clrbits16(immap->im_ioport.iop_pddir, 0x0080);
87 /* configure FEC1 pins */
88 setbits16(immap->im_ioport.iop_papar, 0xe810);
89 setbits16(immap->im_ioport.iop_padir, 0x0810);
90 clrbits16(immap->im_ioport.iop_padir, 0xe000);
92 setbits32(immap->im_cpm.cp_pbpar, 0x00000001);
93 clrbits32(immap->im_cpm.cp_pbdir, 0x00000001);
95 setbits32(immap->im_cpm.cp_cptr, 0x00000100);
96 clrbits32(immap->im_cpm.cp_cptr, 0x00000050);
98 clrbits16(immap->im_ioport.iop_pcpar, 0x0200);
99 clrbits16(immap->im_ioport.iop_pcdir, 0x0200);
100 clrbits16(immap->im_ioport.iop_pcso, 0x0200);
101 setbits16(immap->im_ioport.iop_pcint, 0x0200);
103 /* configure FEC2 pins */
104 setbits32(immap->im_cpm.cp_pepar, 0x00039620);
105 setbits32(immap->im_cpm.cp_pedir, 0x00039620);
106 setbits32(immap->im_cpm.cp_peso, 0x00031000);
107 clrbits32(immap->im_cpm.cp_peso, 0x00008620);
109 setbits32(immap->im_cpm.cp_cptr, 0x00000080);
110 clrbits32(immap->im_cpm.cp_cptr, 0x00000028);
112 clrbits16(immap->im_ioport.iop_pcpar, 0x0200);
113 clrbits16(immap->im_ioport.iop_pcdir, 0x0200);
114 clrbits16(immap->im_ioport.iop_pcso, 0x0200);
115 setbits16(immap->im_ioport.iop_pcint, 0x0200);
117 /* fill up */
118 fec1_info.sys_clk = bd->bi_intfreq;
119 fec2_info.sys_clk = bd->bi_intfreq;
121 s = __fw_getenv("ethaddr");
122 if (s != NULL) {
123 for (i = 0; i < 6; i++) {
124 fec1_info.macaddr[i] = simple_strtoul(s, &e, 16);
125 if (*e)
126 s = e + 1;
130 s = __fw_getenv("eth1addr");
131 if (s != NULL) {
132 for (i = 0; i < 6; i++) {
133 fec2_info.macaddr[i] = simple_strtoul(s, &e, 16);
134 if (*e)
135 s = e + 1;
139 fec_8xx_init_one(&fec1_info, &fec1_dev);
140 fec_8xx_init_one(&fec2_info, &fec2_dev);
142 return fec1_dev != NULL && fec2_dev != NULL ? 0 : -1;
145 void fec_8xx_platform_cleanup(void)
147 if (fec2_dev != NULL)
148 fec_8xx_cleanup_one(fec2_dev);
150 if (fec1_dev != NULL)
151 fec_8xx_cleanup_one(fec1_dev);