bddc572c669cc5ded507322c07a9970286f910ac
[openwrt/openwrt.git] / target / linux / adm8668 / patches-3.18 / 005-tulip_platform.patch
1 --- a/drivers/net/ethernet/dec/tulip/Kconfig
2 +++ b/drivers/net/ethernet/dec/tulip/Kconfig
3 @@ -60,6 +60,14 @@ config TULIP_PCI
4 To compile this driver as a module, choose M here. The module will
5 be called tulip.
6
7 +config TULIP_PLATFORM
8 + tristate "DECchip Tulip (dc2114x) Platform support"
9 + depends on HAS_IOMEM
10 + select TULIP
11 + select CRC32
12 + ---help---
13 + This driver is for the platform variant.
14 +
15 config TULIP_MWI
16 bool "New bus configuration"
17 depends on TULIP_PCI
18 --- a/drivers/net/ethernet/dec/tulip/tulip_core.c
19 +++ b/drivers/net/ethernet/dec/tulip/tulip_core.c
20 @@ -27,6 +27,8 @@
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/etherdevice.h>
24 +#include <linux/platform_device.h>
25 +#include <linux/platform_data/tulip.h>
26 #include <linux/delay.h>
27 #include <linux/mii.h>
28 #include <linux/crc32.h>
29 @@ -204,6 +206,9 @@ struct tulip_chip_table tulip_tbl[] = {
30 { "Conexant LANfinity", 256, 0x0001ebef,
31 HAS_MII | HAS_ACPI, tulip_timer, tulip_media_task },
32
33 + { "Infineon ADM8668", 256, 0x0001a451,
34 + MC_HASH_ONLY | COMET_MAC_ADDR, tulip_timer, tulip_media_task, },
35 +
36 };
37
38
39 @@ -377,6 +382,11 @@ static void tulip_up(struct net_device *
40 sizeof(tp->setup_frame),
41 PCI_DMA_TODEVICE);
42 #endif
43 +#ifdef CONFIG_TULIP_PLATFORM
44 + mapping = dma_map_single(&tp->pldev->dev, tp->setup_frame,
45 + sizeof(tp->setup_frame),
46 + DMA_TO_DEVICE);
47 +#endif
48 tp->tx_buffers[tp->cur_tx].skb = NULL;
49 tp->tx_buffers[tp->cur_tx].mapping = mapping;
50
51 @@ -396,6 +406,7 @@ static void tulip_up(struct net_device *
52 i = 0;
53 if (tp->mtable == NULL)
54 goto media_picked;
55 +
56 if (dev->if_port) {
57 int looking_for = tulip_media_cap[dev->if_port] & MediaIsMII ? 11 :
58 (dev->if_port == 12 ? 0 : dev->if_port);
59 @@ -489,6 +500,10 @@ media_picked:
60 iowrite32(ioread32(ioaddr + 0x88) | 1, ioaddr + 0x88);
61 dev->if_port = tp->mii_cnt ? 11 : 0;
62 tp->csr6 = 0x00040000;
63 + } else if (tp->chip_id == ADM8668) {
64 + /* Enable automatic Tx underrun recovery. */
65 + iowrite32(ioread32(ioaddr + 0x88) | 1, ioaddr + 0x88);
66 + tp->csr6 = 0x00040000;
67 } else if (tp->chip_id == AX88140) {
68 tp->csr6 = tp->mii_cnt ? 0x00040100 : 0x00000100;
69 } else
70 @@ -660,6 +675,10 @@ static void tulip_init_ring(struct net_d
71 mapping = pci_map_single(tp->pdev, skb->data,
72 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
73 #endif
74 +#ifdef CONFIG_TULIP_PLATFORM
75 + mapping = dma_map_single(&tp->pldev->dev, skb->data,
76 + PKT_BUF_SZ, DMA_FROM_DEVICE);
77 +#endif
78 tp->rx_buffers[i].mapping = mapping;
79 tp->rx_ring[i].status = cpu_to_le32(DescOwned); /* Owned by Tulip chip */
80 tp->rx_ring[i].buffer1 = cpu_to_le32(mapping);
81 @@ -696,6 +715,11 @@ tulip_start_xmit(struct sk_buff *skb, st
82 mapping = pci_map_single(tp->pdev, skb->data,
83 skb->len, PCI_DMA_TODEVICE);
84 #endif
85 +#ifdef CONFIG_TULIP_PLATFORM
86 + mapping = dma_map_single(&tp->pldev->dev, skb->data,
87 + skb->len,
88 + DMA_TO_DEVICE);
89 +#endif
90 tp->tx_buffers[entry].mapping = mapping;
91 tp->tx_ring[entry].buffer1 = cpu_to_le32(mapping);
92
93 @@ -752,6 +776,13 @@ static void tulip_clean_tx_ring(struct t
94 sizeof(tp->setup_frame),
95 PCI_DMA_TODEVICE);
96 #endif
97 +#ifdef CONFIG_TULIP_PLATFORM
98 + dma_unmap_single(&tp->pldev->dev,
99 + tp->tx_buffers[entry].mapping,
100 + sizeof(tp->setup_frame),
101 + DMA_TO_DEVICE);
102 +#endif
103 +
104 continue;
105 }
106 #ifdef CONFIG_TULIP_PCI
107 @@ -759,6 +790,11 @@ static void tulip_clean_tx_ring(struct t
108 tp->tx_buffers[entry].skb->len,
109 PCI_DMA_TODEVICE);
110 #endif
111 +#ifdef CONFIG_TULIP_PLATFORM
112 + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[entry].mapping,
113 + tp->tx_buffers[entry].skb->len,
114 + DMA_TO_DEVICE);
115 +#endif
116
117 /* Free the original skb. */
118 dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
119 @@ -836,6 +872,10 @@ static void tulip_free_ring (struct net_
120 pci_unmap_single(tp->pdev, mapping, PKT_BUF_SZ,
121 PCI_DMA_FROMDEVICE);
122 #endif
123 +#ifdef CONFIG_TULIP_PLATFORM
124 + dma_unmap_single(&tp->pldev->dev, mapping, PKT_BUF_SZ,
125 + DMA_FROM_DEVICE);
126 +#endif
127 dev_kfree_skb (skb);
128 }
129 }
130 @@ -848,6 +888,10 @@ static void tulip_free_ring (struct net_
131 pci_unmap_single(tp->pdev, tp->tx_buffers[i].mapping,
132 skb->len, PCI_DMA_TODEVICE);
133 #endif
134 +#ifdef CONFIG_TULIP_PLATFORM
135 + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[i].mapping,
136 + skb->len, DMA_TO_DEVICE);
137 +#endif
138 dev_kfree_skb (skb);
139 }
140 tp->tx_buffers[i].skb = NULL;
141 @@ -902,6 +946,9 @@ static void tulip_get_drvinfo(struct net
142 #ifdef CONFIG_TULIP_PCI
143 strlcpy(info->bus_info, pci_name(np->pdev), sizeof(info->bus_info));
144 #endif
145 +#ifdef CONFIG_TULIP_PLATFORM
146 + strlcpy(info->bus_info, "platform", sizeof(info->bus_info));
147 +#endif
148 }
149
150
151 @@ -917,6 +964,9 @@ static int tulip_ethtool_set_wol(struct
152 #ifdef CONFIG_TULIP_PCI
153 device_set_wakeup_enable(tp->kdev, tp->wolinfo.wolopts);
154 #endif
155 +#ifdef CONFIG_TULIP_PLATFORM
156 + device_set_wakeup_enable(&tp->pldev->dev, tp->wolinfo.wolopts);
157 +#endif
158 return 0;
159 }
160
161 @@ -1192,13 +1242,20 @@ static void set_rx_mode(struct net_devic
162
163 }
164
165 +#ifdef CONFIG_TULIP_PCI
166 tp->tx_buffers[entry].skb = NULL;
167 tp->tx_buffers[entry].mapping =
168 -#ifdef CONFIG_TULIP_PCI
169 pci_map_single(tp->pdev, tp->setup_frame,
170 sizeof(tp->setup_frame),
171 PCI_DMA_TODEVICE);
172 #endif
173 +#ifdef CONFIG_TULIP_PLATFORM
174 + tp->tx_buffers[entry].skb = NULL;
175 + tp->tx_buffers[entry].mapping =
176 + dma_map_single(&tp->pldev->dev, tp->setup_frame,
177 + sizeof(tp->setup_frame),
178 + DMA_TO_DEVICE);
179 +#endif
180 /* Put the setup frame on the Tx list. */
181 if (entry == TX_RING_SIZE-1)
182 tx_flags |= DESC_RING_WRAP; /* Wrap ring. */
183 @@ -1218,6 +1275,9 @@ static void set_rx_mode(struct net_devic
184 spin_unlock_irqrestore(&tp->lock, flags);
185 }
186
187 + if (tp->chip_id == ADM8668)
188 + csr6 |= (1 << 9); /* force 100Mbps full duplex */
189 +
190 iowrite32(csr6, ioaddr + CSR6);
191 }
192
193 @@ -1984,6 +2044,126 @@ static void tulip_remove_one(struct pci_
194 }
195 #endif /* CONFIG_TULIP_PCI */
196
197 +#ifdef CONFIG_TULIP_PLATFORM
198 +static int tulip_probe(struct platform_device *pdev)
199 +{
200 + struct tulip_private *tp;
201 + struct tulip_platform_data *pdata;
202 + struct net_device *dev;
203 + struct resource *res;
204 + void __iomem *ioaddr;
205 + int irq;
206 +
207 + if (pdev->id < 0 || pdev->id >= MAX_UNITS)
208 + return -EINVAL;
209 +
210 + if (!(res = platform_get_resource(pdev, IORESOURCE_IRQ, 0)))
211 + return -ENODEV;
212 + irq = res->start;
213 + if (!(res = platform_get_resource(pdev, IORESOURCE_MEM, 0)))
214 + return -ENODEV;
215 + if (!(ioaddr = ioremap(res->start, res->end - res->start)))
216 + return -ENODEV;
217 +
218 + pdata = pdev->dev.platform_data;
219 + if (!pdata)
220 + return -ENODEV;
221 +
222 + if (!(dev = alloc_etherdev(sizeof (*tp))))
223 + return -ENOMEM;
224 +
225 + /* setup net dev */
226 + dev->base_addr = (unsigned long)res->start;
227 + dev->irq = irq;
228 + SET_NETDEV_DEV(dev, &pdev->dev);
229 +
230 + /* tulip private struct */
231 + tp = netdev_priv(dev);
232 + tp->dev = dev;
233 + tp->base_addr = ioaddr;
234 + tp->csr0 = 0;
235 + tp->pldev = pdev;
236 + tp->kdev = &pdev->dev;
237 + tp->irq = irq;
238 + tp->rx_ring = dma_alloc_coherent(&pdev->dev,
239 + sizeof(struct tulip_rx_desc) * RX_RING_SIZE +
240 + sizeof(struct tulip_tx_desc) * TX_RING_SIZE,
241 + &tp->rx_ring_dma, GFP_KERNEL);
242 + if (!tp->rx_ring)
243 + return -ENODEV;
244 + tp->tx_ring = (struct tulip_tx_desc *)(tp->rx_ring + RX_RING_SIZE);
245 + tp->tx_ring_dma = tp->rx_ring_dma + sizeof(struct tulip_rx_desc) * RX_RING_SIZE;
246 +
247 + tp->chip_id = pdata->chip_id;
248 + tp->flags = tulip_tbl[tp->chip_id].flags;
249 +
250 + spin_lock_init(&tp->lock);
251 + spin_lock_init(&tp->mii_lock);
252 +
253 + init_timer(&tp->timer);
254 + tp->timer.data = (unsigned long)dev;
255 + tp->timer.function = tulip_tbl[tp->chip_id].media_timer;
256 +
257 + INIT_WORK(&tp->media_work, tulip_tbl[tp->chip_id].media_task);
258 +
259 + /* Stop the chip's Tx and Rx processes. */
260 + tulip_stop_rxtx(tp);
261 +
262 + /* Clear the missed-packet counter. */
263 + ioread32(ioaddr + CSR8);
264 +
265 + if (!is_valid_ether_addr(pdata->mac)) {
266 + dev_info(&pdev->dev, "generating random ethernet MAC\n");
267 + random_ether_addr(dev->dev_addr);
268 + } else
269 + memcpy(dev->dev_addr, pdata->mac, ETH_ALEN);
270 +
271 + /* The Tulip-specific entries in the device structure. */
272 + dev->netdev_ops = &tulip_netdev_ops;
273 + dev->watchdog_timeo = TX_TIMEOUT;
274 + netif_napi_add(dev, &tp->napi, tulip_poll, 16);
275 + dev->ethtool_ops = &ops;
276 +
277 + if (register_netdev(dev))
278 + goto err_out_free_ring;
279 +
280 + dev_info(&dev->dev,
281 + "tulip_platform (%s) at MMIO %#lx %pM, IRQ %d\n",
282 + tulip_tbl[tp->chip_id].chip_name,
283 + (unsigned long)dev->base_addr, dev->dev_addr, irq);
284 +
285 + platform_set_drvdata(pdev, dev);
286 + return 0;
287 +
288 +err_out_free_ring:
289 + dma_free_coherent(&pdev->dev,
290 + sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
291 + sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
292 + tp->rx_ring, tp->rx_ring_dma);
293 + return -ENODEV;
294 +}
295 +
296 +static int tulip_remove(struct platform_device *pdev)
297 +{
298 + struct net_device *dev = platform_get_drvdata (pdev);
299 + struct tulip_private *tp;
300 +
301 + if (!dev)
302 + return -ENODEV;
303 +
304 + tp = netdev_priv(dev);
305 + unregister_netdev(dev);
306 + dma_free_coherent(&pdev->dev,
307 + sizeof (struct tulip_rx_desc) * RX_RING_SIZE +
308 + sizeof (struct tulip_tx_desc) * TX_RING_SIZE,
309 + tp->rx_ring, tp->rx_ring_dma);
310 + iounmap(tp->base_addr);
311 + free_netdev(dev);
312 + platform_set_drvdata(pdev, NULL);
313 + return 0;
314 +}
315 +#endif
316 +
317 #ifdef CONFIG_NET_POLL_CONTROLLER
318 /*
319 * Polling 'interrupt' - used by things like netconsole to send skbs
320 @@ -2017,6 +2197,17 @@ static struct pci_driver tulip_pci_drive
321 };
322 #endif
323
324 +#ifdef CONFIG_TULIP_PLATFORM
325 +static struct platform_driver tulip_platform_driver = {
326 + .probe = tulip_probe,
327 + .remove = tulip_remove,
328 + .driver = {
329 + .owner = THIS_MODULE,
330 + .name = DRV_NAME,
331 + },
332 +};
333 +#endif
334 +
335
336 static int __init tulip_init (void)
337 {
338 @@ -2033,6 +2224,9 @@ static int __init tulip_init (void)
339 #ifdef CONFIG_TULIP_PCI
340 ret = pci_register_driver(&tulip_pci_driver);
341 #endif
342 +#ifdef CONFIG_TULIP_PLATFORM
343 + ret = platform_driver_register(&tulip_platform_driver);
344 +#endif
345 return ret;
346 }
347
348 @@ -2042,6 +2236,9 @@ static void __exit tulip_cleanup (void)
349 #ifdef CONFIG_TULIP_PCI
350 pci_unregister_driver (&tulip_pci_driver);
351 #endif
352 +#ifdef CONFIG_TULIP_PLATFORM
353 + platform_driver_unregister (&tulip_platform_driver);
354 +#endif
355 }
356
357
358 --- a/drivers/net/ethernet/dec/tulip/tulip.h
359 +++ b/drivers/net/ethernet/dec/tulip/tulip.h
360 @@ -21,6 +21,8 @@
361 #include <linux/timer.h>
362 #include <linux/delay.h>
363 #include <linux/pci.h>
364 +#include <linux/platform_device.h>
365 +#include <linux/platform_data/tulip.h>
366 #include <asm/io.h>
367 #include <asm/irq.h>
368 #include <asm/unaligned.h>
369 @@ -69,28 +71,6 @@ enum tbl_flag {
370 };
371
372
373 -/* chip types. careful! order is VERY IMPORTANT here, as these
374 - * are used throughout the driver as indices into arrays */
375 -/* Note 21142 == 21143. */
376 -enum chips {
377 - DC21040 = 0,
378 - DC21041 = 1,
379 - DC21140 = 2,
380 - DC21142 = 3, DC21143 = 3,
381 - LC82C168,
382 - MX98713,
383 - MX98715,
384 - MX98725,
385 - AX88140,
386 - PNIC2,
387 - COMET,
388 - COMPEX9881,
389 - I21145,
390 - DM910X,
391 - CONEXANT,
392 -};
393 -
394 -
395 enum MediaIs {
396 MediaIsFD = 1,
397 MediaAlwaysFD = 2,
398 @@ -446,7 +426,12 @@ struct tulip_private {
399 struct mediatable *mtable;
400 int cur_index; /* Current media index. */
401 int saved_if_port;
402 +#ifdef CONFIG_TULIP_PCI
403 struct pci_dev *pdev;
404 +#endif
405 +#ifdef CONFIG_TULIP_PLATFORM
406 + struct platform_device *pldev;
407 +#endif
408 struct device *kdev;
409 int irq;
410 int ttimer;
411 --- a/drivers/net/ethernet/dec/tulip/interrupt.c
412 +++ b/drivers/net/ethernet/dec/tulip/interrupt.c
413 @@ -77,6 +77,10 @@ int tulip_refill_rx(struct net_device *d
414 mapping = pci_map_single(tp->pdev, skb->data, PKT_BUF_SZ,
415 PCI_DMA_FROMDEVICE);
416 #endif
417 +#ifdef CONFIG_TULIP_PLATFORM
418 + mapping = dma_map_single(&tp->pldev->dev, skb->data, PKT_BUF_SZ,
419 + DMA_FROM_DEVICE);
420 +#endif
421 if (dma_mapping_error(tp->kdev, mapping)) {
422 dev_kfree_skb(skb);
423 tp->rx_buffers[entry].skb = NULL;
424 @@ -204,8 +208,7 @@ int tulip_poll(struct napi_struct *napi,
425 dev->stats.rx_fifo_errors++;
426 }
427 } else {
428 - struct sk_buff *skb;
429 -
430 + struct sk_buff *skb;
431 /* Check if the packet is long enough to accept without copying
432 to a minimally-sized skbuff. */
433 if (pkt_len < tulip_rx_copybreak &&
434 @@ -248,6 +251,10 @@ int tulip_poll(struct napi_struct *napi,
435 pci_unmap_single(tp->pdev, tp->rx_buffers[entry].mapping,
436 PKT_BUF_SZ, PCI_DMA_FROMDEVICE);
437 #endif
438 +#ifdef CONFIG_TULIP_PLATFORM
439 + dma_unmap_single(&tp->pldev->dev, tp->rx_buffers[entry].mapping,
440 + PKT_BUF_SZ, DMA_FROM_DEVICE);
441 +#endif
442
443 tp->rx_buffers[entry].skb = NULL;
444 tp->rx_buffers[entry].mapping = 0;
445 @@ -641,6 +648,11 @@ irqreturn_t tulip_interrupt(int irq, voi
446 tp->tx_buffers[entry].skb->len,
447 PCI_DMA_TODEVICE);
448 #endif
449 +#ifdef CONFIG_TULIP_PLATFORM
450 + dma_unmap_single(&tp->pldev->dev, tp->tx_buffers[entry].mapping,
451 + tp->tx_buffers[entry].skb->len,
452 + DMA_TO_DEVICE);
453 +#endif
454
455 /* Free the original skb. */
456 dev_kfree_skb_irq(tp->tx_buffers[entry].skb);
457 --- /dev/null
458 +++ b/include/linux/platform_data/tulip.h
459 @@ -0,0 +1,31 @@
460 +#ifndef _LINUX_TULIP_PDATA_H
461 +#define _LINUX_TULIP_PDATA_H
462 +
463 +/* chip types. careful! order is VERY IMPORTANT here, as these
464 + * are used throughout the driver as indices into arrays */
465 +/* Note 21142 == 21143. */
466 +enum chips {
467 + DC21040 = 0,
468 + DC21041 = 1,
469 + DC21140 = 2,
470 + DC21142 = 3, DC21143 = 3,
471 + LC82C168,
472 + MX98713,
473 + MX98715,
474 + MX98725,
475 + AX88140,
476 + PNIC2,
477 + COMET,
478 + COMPEX9881,
479 + I21145,
480 + DM910X,
481 + CONEXANT,
482 + ADM8668,
483 +};
484 +
485 +struct tulip_platform_data {
486 + u8 mac[6];
487 + enum chips chip_id;
488 +};
489 +
490 +#endif