gpmc-smc91x.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * linux/arch/arm/mach-omap2/gpmc-smc91x.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Contact: Tony Lindgren
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/gpio.h>
  14. #include <linux/delay.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/io.h>
  17. #include <linux/smc91x.h>
  18. #include <plat/board.h>
  19. #include <plat/gpmc.h>
  20. #include <plat/gpmc-smc91x.h>
  21. static struct omap_smc91x_platform_data *gpmc_cfg;
  22. static struct resource gpmc_smc91x_resources[] = {
  23. [0] = {
  24. .flags = IORESOURCE_MEM,
  25. },
  26. [1] = {
  27. .flags = IORESOURCE_IRQ,
  28. },
  29. };
  30. static struct smc91x_platdata gpmc_smc91x_info = {
  31. .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT | SMC91X_IO_SHIFT_0,
  32. .leda = RPC_LED_100_10,
  33. .ledb = RPC_LED_TX_RX,
  34. };
  35. static struct platform_device gpmc_smc91x_device = {
  36. .name = "smc91x",
  37. .id = -1,
  38. .dev = {
  39. .platform_data = &gpmc_smc91x_info,
  40. },
  41. .num_resources = ARRAY_SIZE(gpmc_smc91x_resources),
  42. .resource = gpmc_smc91x_resources,
  43. };
  44. /*
  45. * Set the gpmc timings for smc91c96. The timings are taken
  46. * from the data sheet available at:
  47. * http://www.smsc.com/main/catalog/lan91c96.html
  48. * REVISIT: Level shifters can add at least to the access latency.
  49. */
  50. static int smc91c96_gpmc_retime(void)
  51. {
  52. struct gpmc_timings t;
  53. const int t3 = 10; /* Figure 12.2 read and 12.4 write */
  54. const int t4_r = 20; /* Figure 12.2 read */
  55. const int t4_w = 5; /* Figure 12.4 write */
  56. const int t5 = 25; /* Figure 12.2 read */
  57. const int t6 = 15; /* Figure 12.2 read */
  58. const int t7 = 5; /* Figure 12.4 write */
  59. const int t8 = 5; /* Figure 12.4 write */
  60. const int t20 = 185; /* Figure 12.2 read and 12.4 write */
  61. u32 l;
  62. memset(&t, 0, sizeof(t));
  63. /* Read timings */
  64. t.cs_on = 0;
  65. t.adv_on = t.cs_on;
  66. t.oe_on = t.adv_on + t3;
  67. t.access = t.oe_on + t5;
  68. t.oe_off = t.access;
  69. t.adv_rd_off = t.oe_off + max(t4_r, t6);
  70. t.cs_rd_off = t.oe_off;
  71. t.rd_cycle = t20 - t.oe_on;
  72. /* Write timings */
  73. t.we_on = t.adv_on + t3;
  74. if (cpu_is_omap34xx() && (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)) {
  75. t.wr_data_mux_bus = t.we_on;
  76. t.we_off = t.wr_data_mux_bus + t7;
  77. } else
  78. t.we_off = t.we_on + t7;
  79. if (cpu_is_omap34xx())
  80. t.wr_access = t.we_off;
  81. t.adv_wr_off = t.we_off + max(t4_w, t8);
  82. t.cs_wr_off = t.we_off + t4_w;
  83. t.wr_cycle = t20 - t.we_on;
  84. l = GPMC_CONFIG1_DEVICESIZE_16;
  85. if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
  86. l |= GPMC_CONFIG1_MUXADDDATA;
  87. if (gpmc_cfg->flags & GPMC_READ_MON)
  88. l |= GPMC_CONFIG1_WAIT_READ_MON;
  89. if (gpmc_cfg->flags & GPMC_WRITE_MON)
  90. l |= GPMC_CONFIG1_WAIT_WRITE_MON;
  91. if (gpmc_cfg->wait_pin)
  92. l |= GPMC_CONFIG1_WAIT_PIN_SEL(gpmc_cfg->wait_pin);
  93. gpmc_cs_write_reg(gpmc_cfg->cs, GPMC_CS_CONFIG1, l);
  94. /*
  95. * FIXME: Calculate the address and data bus muxed timings.
  96. * Note that at least adv_rd_off needs to be changed according
  97. * to omap3430 TRM Figure 11-11. Are the sdp boards using the
  98. * FPGA in between smc91x and omap as the timings are different
  99. * from above?
  100. */
  101. if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
  102. return 0;
  103. return gpmc_cs_set_timings(gpmc_cfg->cs, &t);
  104. }
  105. /*
  106. * Initialize smc91x device connected to the GPMC. Note that we
  107. * assume that pin multiplexing is done in the board-*.c file,
  108. * or in the bootloader.
  109. */
  110. void __init gpmc_smc91x_init(struct omap_smc91x_platform_data *board_data)
  111. {
  112. unsigned long cs_mem_base;
  113. int ret;
  114. gpmc_cfg = board_data;
  115. if (gpmc_cfg->flags & GPMC_TIMINGS_SMC91C96)
  116. gpmc_cfg->retime = smc91c96_gpmc_retime;
  117. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  118. printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
  119. return;
  120. }
  121. gpmc_smc91x_resources[0].start = cs_mem_base + 0x300;
  122. gpmc_smc91x_resources[0].end = cs_mem_base + 0x30f;
  123. gpmc_smc91x_resources[1].flags |= (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
  124. if (gpmc_cfg->retime) {
  125. ret = gpmc_cfg->retime();
  126. if (ret != 0)
  127. goto free1;
  128. }
  129. if (gpio_request(gpmc_cfg->gpio_irq, "SMC91X irq") < 0)
  130. goto free1;
  131. gpio_direction_input(gpmc_cfg->gpio_irq);
  132. gpmc_smc91x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  133. if (gpmc_cfg->gpio_pwrdwn) {
  134. ret = gpio_request(gpmc_cfg->gpio_pwrdwn, "SMC91X powerdown");
  135. if (ret)
  136. goto free2;
  137. gpio_direction_output(gpmc_cfg->gpio_pwrdwn, 0);
  138. }
  139. if (gpmc_cfg->gpio_reset) {
  140. ret = gpio_request(gpmc_cfg->gpio_reset, "SMC91X reset");
  141. if (ret)
  142. goto free3;
  143. gpio_direction_output(gpmc_cfg->gpio_reset, 0);
  144. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  145. msleep(100);
  146. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  147. }
  148. if (platform_device_register(&gpmc_smc91x_device) < 0) {
  149. printk(KERN_ERR "Unable to register smc91x device\n");
  150. gpio_free(gpmc_cfg->gpio_reset);
  151. goto free3;
  152. }
  153. return;
  154. free3:
  155. if (gpmc_cfg->gpio_pwrdwn)
  156. gpio_free(gpmc_cfg->gpio_pwrdwn);
  157. free2:
  158. gpio_free(gpmc_cfg->gpio_irq);
  159. free1:
  160. gpmc_cs_free(gpmc_cfg->cs);
  161. printk(KERN_ERR "Could not initialize smc91x\n");
  162. }