nettel.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: GPL-2.0
  2. /***************************************************************************/
  3. /*
  4. * nettel.c -- startup code support for the NETtel boards
  5. *
  6. * Copyright (C) 2009, Greg Ungerer (gerg@snapgear.com)
  7. */
  8. /***************************************************************************/
  9. #include <linux/kernel.h>
  10. #include <linux/param.h>
  11. #include <linux/init.h>
  12. #include <linux/io.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/coldfire.h>
  15. #include <asm/mcfsim.h>
  16. #include <asm/nettel.h>
  17. /***************************************************************************/
  18. /*
  19. * Define the IO and interrupt resources of the 2 SMC9196 interfaces.
  20. */
  21. #define NETTEL_SMC0_ADDR 0x30600300
  22. #define NETTEL_SMC0_IRQ 29
  23. #define NETTEL_SMC1_ADDR 0x30600000
  24. #define NETTEL_SMC1_IRQ 27
  25. /*
  26. * We need some access into the SMC9196 registers. Define those registers
  27. * we will need here (including the smc91x.h doesn't seem to give us these
  28. * in a simple form).
  29. */
  30. #define SMC91xx_BANKSELECT 14
  31. #define SMC91xx_BASEADDR 2
  32. #define SMC91xx_BASEMAC 4
  33. /***************************************************************************/
  34. static struct resource nettel_smc91x_0_resources[] = {
  35. {
  36. .start = NETTEL_SMC0_ADDR,
  37. .end = NETTEL_SMC0_ADDR + 0x20,
  38. .flags = IORESOURCE_MEM,
  39. },
  40. {
  41. .start = NETTEL_SMC0_IRQ,
  42. .end = NETTEL_SMC0_IRQ,
  43. .flags = IORESOURCE_IRQ,
  44. },
  45. };
  46. static struct resource nettel_smc91x_1_resources[] = {
  47. {
  48. .start = NETTEL_SMC1_ADDR,
  49. .end = NETTEL_SMC1_ADDR + 0x20,
  50. .flags = IORESOURCE_MEM,
  51. },
  52. {
  53. .start = NETTEL_SMC1_IRQ,
  54. .end = NETTEL_SMC1_IRQ,
  55. .flags = IORESOURCE_IRQ,
  56. },
  57. };
  58. static struct platform_device nettel_smc91x[] = {
  59. {
  60. .name = "smc91x",
  61. .id = 0,
  62. .num_resources = ARRAY_SIZE(nettel_smc91x_0_resources),
  63. .resource = nettel_smc91x_0_resources,
  64. },
  65. {
  66. .name = "smc91x",
  67. .id = 1,
  68. .num_resources = ARRAY_SIZE(nettel_smc91x_1_resources),
  69. .resource = nettel_smc91x_1_resources,
  70. },
  71. };
  72. static struct platform_device *nettel_devices[] __initdata = {
  73. &nettel_smc91x[0],
  74. &nettel_smc91x[1],
  75. };
  76. /***************************************************************************/
  77. static u8 nettel_macdefault[] __initdata = {
  78. 0x00, 0xd0, 0xcf, 0x00, 0x00, 0x01,
  79. };
  80. /*
  81. * Set flash contained MAC address into SMC9196 core. Make sure the flash
  82. * MAC address is sane, and not an empty flash. If no good use the Moreton
  83. * Bay default MAC address instead.
  84. */
  85. static void __init nettel_smc91x_setmac(unsigned int ioaddr, unsigned int flashaddr)
  86. {
  87. u16 *macp;
  88. macp = (u16 *) flashaddr;
  89. if ((macp[0] == 0xffff) && (macp[1] == 0xffff) && (macp[2] == 0xffff))
  90. macp = (u16 *) &nettel_macdefault[0];
  91. writew(1, NETTEL_SMC0_ADDR + SMC91xx_BANKSELECT);
  92. writew(macp[0], ioaddr + SMC91xx_BASEMAC);
  93. writew(macp[1], ioaddr + SMC91xx_BASEMAC + 2);
  94. writew(macp[2], ioaddr + SMC91xx_BASEMAC + 4);
  95. }
  96. /***************************************************************************/
  97. /*
  98. * Re-map the address space of at least one of the SMC ethernet
  99. * parts. Both parts power up decoding the same address, so we
  100. * need to move one of them first, before doing anything else.
  101. */
  102. static void __init nettel_smc91x_init(void)
  103. {
  104. writew(0x00ec, MCFSIM_PADDR);
  105. mcf_setppdata(0, 0x0080);
  106. writew(1, NETTEL_SMC0_ADDR + SMC91xx_BANKSELECT);
  107. writew(0x0067, NETTEL_SMC0_ADDR + SMC91xx_BASEADDR);
  108. mcf_setppdata(0x0080, 0);
  109. /* Set correct chip select timing for SMC9196 accesses */
  110. writew(0x1180, MCFSIM_CSCR3);
  111. /* Set the SMC interrupts to be auto-vectored */
  112. mcf_autovector(NETTEL_SMC0_IRQ);
  113. mcf_autovector(NETTEL_SMC1_IRQ);
  114. /* Set MAC addresses from flash for both interfaces */
  115. nettel_smc91x_setmac(NETTEL_SMC0_ADDR, 0xf0006000);
  116. nettel_smc91x_setmac(NETTEL_SMC1_ADDR, 0xf0006006);
  117. }
  118. /***************************************************************************/
  119. static int __init init_nettel(void)
  120. {
  121. nettel_smc91x_init();
  122. platform_add_devices(nettel_devices, ARRAY_SIZE(nettel_devices));
  123. return 0;
  124. }
  125. arch_initcall(init_nettel);
  126. /***************************************************************************/