gpmc-smc91x.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 "gpmc.h"
  19. #include "gpmc-smc91x.h"
  20. #include "soc.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. static struct gpmc_settings smc91x_settings = {
  45. .device_width = GPMC_DEVWIDTH_16BIT,
  46. };
  47. /*
  48. * Set the gpmc timings for smc91c96. The timings are taken
  49. * from the data sheet available at:
  50. * http://www.smsc.com/main/catalog/lan91c96.html
  51. * REVISIT: Level shifters can add at least to the access latency.
  52. */
  53. static int smc91c96_gpmc_retime(void)
  54. {
  55. struct gpmc_timings t;
  56. struct gpmc_device_timings dev_t;
  57. const int t3 = 10; /* Figure 12.2 read and 12.4 write */
  58. const int t4_r = 20; /* Figure 12.2 read */
  59. const int t4_w = 5; /* Figure 12.4 write */
  60. const int t5 = 25; /* Figure 12.2 read */
  61. const int t6 = 15; /* Figure 12.2 read */
  62. const int t7 = 5; /* Figure 12.4 write */
  63. const int t8 = 5; /* Figure 12.4 write */
  64. const int t20 = 185; /* Figure 12.2 read and 12.4 write */
  65. /*
  66. * FIXME: Calculate the address and data bus muxed timings.
  67. * Note that at least adv_rd_off needs to be changed according
  68. * to omap3430 TRM Figure 11-11. Are the sdp boards using the
  69. * FPGA in between smc91x and omap as the timings are different
  70. * from above?
  71. */
  72. if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
  73. return 0;
  74. memset(&dev_t, 0, sizeof(dev_t));
  75. dev_t.t_oeasu = t3 * 1000;
  76. dev_t.t_oe = t5 * 1000;
  77. dev_t.t_cez_r = t4_r * 1000;
  78. dev_t.t_oez = t6 * 1000;
  79. dev_t.t_rd_cycle = (t20 - t3) * 1000;
  80. dev_t.t_weasu = t3 * 1000;
  81. dev_t.t_wpl = t7 * 1000;
  82. dev_t.t_wph = t8 * 1000;
  83. dev_t.t_cez_w = t4_w * 1000;
  84. dev_t.t_wr_cycle = (t20 - t3) * 1000;
  85. gpmc_calc_timings(&t, &smc91x_settings, &dev_t);
  86. return gpmc_cs_set_timings(gpmc_cfg->cs, &t);
  87. }
  88. /*
  89. * Initialize smc91x device connected to the GPMC. Note that we
  90. * assume that pin multiplexing is done in the board-*.c file,
  91. * or in the bootloader.
  92. */
  93. void __init gpmc_smc91x_init(struct omap_smc91x_platform_data *board_data)
  94. {
  95. unsigned long cs_mem_base;
  96. int ret;
  97. gpmc_cfg = board_data;
  98. if (gpmc_cfg->flags & GPMC_TIMINGS_SMC91C96)
  99. gpmc_cfg->retime = smc91c96_gpmc_retime;
  100. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  101. printk(KERN_ERR "Failed to request GPMC mem for smc91x\n");
  102. return;
  103. }
  104. gpmc_smc91x_resources[0].start = cs_mem_base + 0x300;
  105. gpmc_smc91x_resources[0].end = cs_mem_base + 0x30f;
  106. gpmc_smc91x_resources[1].flags |= (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
  107. if (gpmc_cfg->flags & GPMC_MUX_ADD_DATA)
  108. smc91x_settings.mux_add_data = GPMC_MUX_AD;
  109. if (gpmc_cfg->flags & GPMC_READ_MON)
  110. smc91x_settings.wait_on_read = true;
  111. if (gpmc_cfg->flags & GPMC_WRITE_MON)
  112. smc91x_settings.wait_on_write = true;
  113. if (gpmc_cfg->wait_pin)
  114. smc91x_settings.wait_pin = gpmc_cfg->wait_pin;
  115. ret = gpmc_cs_program_settings(gpmc_cfg->cs, &smc91x_settings);
  116. if (ret < 0)
  117. goto free1;
  118. if (gpmc_cfg->retime) {
  119. ret = gpmc_cfg->retime();
  120. if (ret != 0)
  121. goto free1;
  122. }
  123. if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "SMC91X irq") < 0)
  124. goto free1;
  125. gpmc_smc91x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  126. if (gpmc_cfg->gpio_pwrdwn) {
  127. ret = gpio_request_one(gpmc_cfg->gpio_pwrdwn,
  128. GPIOF_OUT_INIT_LOW, "SMC91X powerdown");
  129. if (ret)
  130. goto free2;
  131. }
  132. if (gpmc_cfg->gpio_reset) {
  133. ret = gpio_request_one(gpmc_cfg->gpio_reset,
  134. GPIOF_OUT_INIT_LOW, "SMC91X reset");
  135. if (ret)
  136. goto free3;
  137. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  138. msleep(100);
  139. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  140. }
  141. if (platform_device_register(&gpmc_smc91x_device) < 0) {
  142. printk(KERN_ERR "Unable to register smc91x device\n");
  143. gpio_free(gpmc_cfg->gpio_reset);
  144. goto free3;
  145. }
  146. return;
  147. free3:
  148. if (gpmc_cfg->gpio_pwrdwn)
  149. gpio_free(gpmc_cfg->gpio_pwrdwn);
  150. free2:
  151. gpio_free(gpmc_cfg->gpio_irq);
  152. free1:
  153. gpmc_cs_free(gpmc_cfg->cs);
  154. printk(KERN_ERR "Could not initialize smc91x\n");
  155. }