gpmc-smc91x.c 4.6 KB

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