PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/jazzsonic.c

https://bitbucket.org/androidarmv6/android_kernel_semc_msm7x27
C | 288 lines | 192 code | 48 blank | 48 comment | 20 complexity | 6410077bc43be9b864050dc692f14f41 MD5 | raw file
  1. /*
  2. * jazzsonic.c
  3. *
  4. * (C) 2005 Finn Thain
  5. *
  6. * Converted to DMA API, and (from the mac68k project) introduced
  7. * dhd's support for 16-bit cards.
  8. *
  9. * (C) 1996,1998 by Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  10. *
  11. * This driver is based on work from Andreas Busse, but most of
  12. * the code is rewritten.
  13. *
  14. * (C) 1995 by Andreas Busse (andy@waldorf-gmbh.de)
  15. *
  16. * A driver for the onboard Sonic ethernet controller on Mips Jazz
  17. * systems (Acer Pica-61, Mips Magnum 4000, Olivetti M700 and
  18. * perhaps others, too)
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/types.h>
  23. #include <linux/fcntl.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/ioport.h>
  27. #include <linux/in.h>
  28. #include <linux/slab.h>
  29. #include <linux/string.h>
  30. #include <linux/delay.h>
  31. #include <linux/errno.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/etherdevice.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/platform_device.h>
  36. #include <linux/dma-mapping.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/system.h>
  39. #include <asm/pgtable.h>
  40. #include <asm/io.h>
  41. #include <asm/dma.h>
  42. #include <asm/jazz.h>
  43. #include <asm/jazzdma.h>
  44. static char jazz_sonic_string[] = "jazzsonic";
  45. #define SONIC_MEM_SIZE 0x100
  46. #include "sonic.h"
  47. /*
  48. * Macros to access SONIC registers
  49. */
  50. #define SONIC_READ(reg) (*((volatile unsigned int *)dev->base_addr+reg))
  51. #define SONIC_WRITE(reg,val) \
  52. do { \
  53. *((volatile unsigned int *)dev->base_addr+(reg)) = (val); \
  54. } while (0)
  55. /* use 0 for production, 1 for verification, >1 for debug */
  56. #ifdef SONIC_DEBUG
  57. static unsigned int sonic_debug = SONIC_DEBUG;
  58. #else
  59. static unsigned int sonic_debug = 1;
  60. #endif
  61. /*
  62. * We cannot use station (ethernet) address prefixes to detect the
  63. * sonic controller since these are board manufacturer depended.
  64. * So we check for known Silicon Revision IDs instead.
  65. */
  66. static unsigned short known_revisions[] =
  67. {
  68. 0x04, /* Mips Magnum 4000 */
  69. 0xffff /* end of list */
  70. };
  71. static int jazzsonic_open(struct net_device* dev)
  72. {
  73. if (request_irq(dev->irq, &sonic_interrupt, IRQF_DISABLED, "sonic", dev)) {
  74. printk(KERN_ERR "%s: unable to get IRQ %d.\n", dev->name, dev->irq);
  75. return -EAGAIN;
  76. }
  77. return sonic_open(dev);
  78. }
  79. static int jazzsonic_close(struct net_device* dev)
  80. {
  81. int err;
  82. err = sonic_close(dev);
  83. free_irq(dev->irq, dev);
  84. return err;
  85. }
  86. static int __init sonic_probe1(struct net_device *dev)
  87. {
  88. static unsigned version_printed;
  89. unsigned int silicon_revision;
  90. unsigned int val;
  91. struct sonic_local *lp = netdev_priv(dev);
  92. int err = -ENODEV;
  93. int i;
  94. if (!request_mem_region(dev->base_addr, SONIC_MEM_SIZE, jazz_sonic_string))
  95. return -EBUSY;
  96. /*
  97. * get the Silicon Revision ID. If this is one of the known
  98. * one assume that we found a SONIC ethernet controller at
  99. * the expected location.
  100. */
  101. silicon_revision = SONIC_READ(SONIC_SR);
  102. if (sonic_debug > 1)
  103. printk("SONIC Silicon Revision = 0x%04x\n",silicon_revision);
  104. i = 0;
  105. while (known_revisions[i] != 0xffff
  106. && known_revisions[i] != silicon_revision)
  107. i++;
  108. if (known_revisions[i] == 0xffff) {
  109. printk("SONIC ethernet controller not found (0x%4x)\n",
  110. silicon_revision);
  111. goto out;
  112. }
  113. if (sonic_debug && version_printed++ == 0)
  114. printk(version);
  115. printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr);
  116. /*
  117. * Put the sonic into software reset, then
  118. * retrieve and print the ethernet address.
  119. */
  120. SONIC_WRITE(SONIC_CMD,SONIC_CR_RST);
  121. SONIC_WRITE(SONIC_CEP,0);
  122. for (i=0; i<3; i++) {
  123. val = SONIC_READ(SONIC_CAP0-i);
  124. dev->dev_addr[i*2] = val;
  125. dev->dev_addr[i*2+1] = val >> 8;
  126. }
  127. err = -ENOMEM;
  128. /* Initialize the device structure. */
  129. lp->dma_bitmode = SONIC_BITMODE32;
  130. /* Allocate the entire chunk of memory for the descriptors.
  131. Note that this cannot cross a 64K boundary. */
  132. if ((lp->descriptors = dma_alloc_coherent(lp->device,
  133. SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  134. &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
  135. printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id);
  136. goto out;
  137. }
  138. /* Now set up the pointers to point to the appropriate places */
  139. lp->cda = lp->descriptors;
  140. lp->tda = lp->cda + (SIZEOF_SONIC_CDA
  141. * SONIC_BUS_SCALE(lp->dma_bitmode));
  142. lp->rda = lp->tda + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  143. * SONIC_BUS_SCALE(lp->dma_bitmode));
  144. lp->rra = lp->rda + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  145. * SONIC_BUS_SCALE(lp->dma_bitmode));
  146. lp->cda_laddr = lp->descriptors_laddr;
  147. lp->tda_laddr = lp->cda_laddr + (SIZEOF_SONIC_CDA
  148. * SONIC_BUS_SCALE(lp->dma_bitmode));
  149. lp->rda_laddr = lp->tda_laddr + (SIZEOF_SONIC_TD * SONIC_NUM_TDS
  150. * SONIC_BUS_SCALE(lp->dma_bitmode));
  151. lp->rra_laddr = lp->rda_laddr + (SIZEOF_SONIC_RD * SONIC_NUM_RDS
  152. * SONIC_BUS_SCALE(lp->dma_bitmode));
  153. dev->open = jazzsonic_open;
  154. dev->stop = jazzsonic_close;
  155. dev->hard_start_xmit = sonic_send_packet;
  156. dev->get_stats = sonic_get_stats;
  157. dev->set_multicast_list = &sonic_multicast_list;
  158. dev->tx_timeout = sonic_tx_timeout;
  159. dev->watchdog_timeo = TX_TIMEOUT;
  160. /*
  161. * clear tally counter
  162. */
  163. SONIC_WRITE(SONIC_CRCT,0xffff);
  164. SONIC_WRITE(SONIC_FAET,0xffff);
  165. SONIC_WRITE(SONIC_MPT,0xffff);
  166. return 0;
  167. out:
  168. release_region(dev->base_addr, SONIC_MEM_SIZE);
  169. return err;
  170. }
  171. /*
  172. * Probe for a SONIC ethernet controller on a Mips Jazz board.
  173. * Actually probing is superfluous but we're paranoid.
  174. */
  175. static int __init jazz_sonic_probe(struct platform_device *pdev)
  176. {
  177. struct net_device *dev;
  178. struct sonic_local *lp;
  179. struct resource *res;
  180. int err = 0;
  181. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  182. if (!res)
  183. return -ENODEV;
  184. dev = alloc_etherdev(sizeof(struct sonic_local));
  185. if (!dev)
  186. return -ENOMEM;
  187. lp = netdev_priv(dev);
  188. lp->device = &pdev->dev;
  189. SET_NETDEV_DEV(dev, &pdev->dev);
  190. netdev_boot_setup_check(dev);
  191. dev->base_addr = res->start;
  192. dev->irq = platform_get_irq(pdev, 0);
  193. err = sonic_probe1(dev);
  194. if (err)
  195. goto out;
  196. err = register_netdev(dev);
  197. if (err)
  198. goto out1;
  199. printk("%s: MAC %pM IRQ %d\n", dev->name, dev->dev_addr, dev->irq);
  200. return 0;
  201. out1:
  202. release_region(dev->base_addr, SONIC_MEM_SIZE);
  203. out:
  204. free_netdev(dev);
  205. return err;
  206. }
  207. MODULE_DESCRIPTION("Jazz SONIC ethernet driver");
  208. module_param(sonic_debug, int, 0);
  209. MODULE_PARM_DESC(sonic_debug, "jazzsonic debug level (1-4)");
  210. MODULE_ALIAS("platform:jazzsonic");
  211. #include "sonic.c"
  212. static int __devexit jazz_sonic_device_remove (struct platform_device *pdev)
  213. {
  214. struct net_device *dev = platform_get_drvdata(pdev);
  215. struct sonic_local* lp = netdev_priv(dev);
  216. unregister_netdev(dev);
  217. dma_free_coherent(lp->device, SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
  218. lp->descriptors, lp->descriptors_laddr);
  219. release_region (dev->base_addr, SONIC_MEM_SIZE);
  220. free_netdev(dev);
  221. return 0;
  222. }
  223. static struct platform_driver jazz_sonic_driver = {
  224. .probe = jazz_sonic_probe,
  225. .remove = __devexit_p(jazz_sonic_device_remove),
  226. .driver = {
  227. .name = jazz_sonic_string,
  228. .owner = THIS_MODULE,
  229. },
  230. };
  231. static int __init jazz_sonic_init_module(void)
  232. {
  233. return platform_driver_register(&jazz_sonic_driver);
  234. }
  235. static void __exit jazz_sonic_cleanup_module(void)
  236. {
  237. platform_driver_unregister(&jazz_sonic_driver);
  238. }
  239. module_init(jazz_sonic_init_module);
  240. module_exit(jazz_sonic_cleanup_module);