gpmc-smsc911x.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * linux/arch/arm/mach-omap2/gpmc-smsc911x.c
  3. *
  4. * Copyright (C) 2009 Li-Pro.Net
  5. * Stephan Linz <linz@li-pro.net>
  6. *
  7. * Modified from linux/arch/arm/mach-omap2/gpmc-smc91x.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/gpio.h>
  16. #include <linux/delay.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/smsc911x.h>
  20. #include <plat/board.h>
  21. #include <plat/gpmc.h>
  22. #include <plat/gpmc-smsc911x.h>
  23. static struct omap_smsc911x_platform_data *gpmc_cfg;
  24. static struct resource gpmc_smsc911x_resources[] = {
  25. [0] = {
  26. .flags = IORESOURCE_MEM,
  27. },
  28. [1] = {
  29. .flags = IORESOURCE_IRQ,
  30. },
  31. };
  32. static struct smsc911x_platform_config gpmc_smsc911x_config = {
  33. .phy_interface = PHY_INTERFACE_MODE_MII,
  34. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  35. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  36. .flags = SMSC911X_USE_16BIT,
  37. };
  38. static struct platform_device gpmc_smsc911x_device = {
  39. .name = "smsc911x",
  40. .id = -1,
  41. .num_resources = ARRAY_SIZE(gpmc_smsc911x_resources),
  42. .resource = gpmc_smsc911x_resources,
  43. .dev = {
  44. .platform_data = &gpmc_smsc911x_config,
  45. },
  46. };
  47. /*
  48. * Initialize smsc911x device connected to the GPMC. Note that we
  49. * assume that pin multiplexing is done in the board-*.c file,
  50. * or in the bootloader.
  51. */
  52. void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data)
  53. {
  54. unsigned long cs_mem_base;
  55. int ret;
  56. gpmc_cfg = board_data;
  57. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  58. printk(KERN_ERR "Failed to request GPMC mem for smsc911x\n");
  59. return;
  60. }
  61. gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
  62. gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
  63. if (gpio_request(gpmc_cfg->gpio_irq, "smsc911x irq") < 0) {
  64. printk(KERN_ERR "Failed to request GPIO%d for smsc911x IRQ\n",
  65. gpmc_cfg->gpio_irq);
  66. goto free1;
  67. }
  68. gpio_direction_input(gpmc_cfg->gpio_irq);
  69. gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  70. gpmc_smsc911x_resources[1].flags |=
  71. (gpmc_cfg->flags & IRQF_TRIGGER_MASK);
  72. if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
  73. ret = gpio_request(gpmc_cfg->gpio_reset, "smsc911x reset");
  74. if (ret) {
  75. printk(KERN_ERR "Failed to request GPIO%d for smsc911x reset\n",
  76. gpmc_cfg->gpio_reset);
  77. goto free2;
  78. }
  79. gpio_direction_output(gpmc_cfg->gpio_reset, 1);
  80. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  81. msleep(100);
  82. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  83. }
  84. if (platform_device_register(&gpmc_smsc911x_device) < 0) {
  85. printk(KERN_ERR "Unable to register smsc911x device\n");
  86. gpio_free(gpmc_cfg->gpio_reset);
  87. goto free2;
  88. }
  89. return;
  90. free2:
  91. gpio_free(gpmc_cfg->gpio_irq);
  92. free1:
  93. gpmc_cs_free(gpmc_cfg->cs);
  94. printk(KERN_ERR "Could not initialize smsc911x\n");
  95. }