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