gpmc-smc91x.c 4.8 KB

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