gpmc-smsc911x.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #define pr_fmt(fmt) "%s: " fmt, __func__
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/gpio.h>
  17. #include <linux/delay.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/io.h>
  20. #include <linux/smsc911x.h>
  21. #include <plat/board.h>
  22. #include <plat/gpmc.h>
  23. #include <plat/gpmc-smsc911x.h>
  24. static struct omap_smsc911x_platform_data *gpmc_cfg;
  25. static struct resource gpmc_smsc911x_resources[] = {
  26. [0] = {
  27. .flags = IORESOURCE_MEM,
  28. },
  29. [1] = {
  30. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  31. },
  32. };
  33. static struct smsc911x_platform_config gpmc_smsc911x_config = {
  34. .phy_interface = PHY_INTERFACE_MODE_MII,
  35. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  36. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  37. .flags = SMSC911X_USE_16BIT,
  38. };
  39. /*
  40. * Initialize smsc911x device connected to the GPMC. Note that we
  41. * assume that pin multiplexing is done in the board-*.c file,
  42. * or in the bootloader.
  43. */
  44. void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *board_data)
  45. {
  46. struct platform_device *pdev;
  47. unsigned long cs_mem_base;
  48. int ret;
  49. gpmc_cfg = board_data;
  50. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  51. pr_err("Failed to request GPMC mem region\n");
  52. return;
  53. }
  54. gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
  55. gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
  56. if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
  57. pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
  58. goto free1;
  59. }
  60. gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  61. if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
  62. ret = gpio_request_one(gpmc_cfg->gpio_reset,
  63. GPIOF_OUT_INIT_HIGH, "smsc911x reset");
  64. if (ret) {
  65. pr_err("Failed to request reset GPIO%d\n",
  66. gpmc_cfg->gpio_reset);
  67. goto free2;
  68. }
  69. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  70. msleep(100);
  71. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  72. }
  73. if (gpmc_cfg->flags)
  74. gpmc_smsc911x_config.flags = gpmc_cfg->flags;
  75. pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
  76. gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
  77. &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
  78. if (!pdev) {
  79. pr_err("Unable to register platform device\n");
  80. gpio_free(gpmc_cfg->gpio_reset);
  81. goto free2;
  82. }
  83. return;
  84. free2:
  85. gpio_free(gpmc_cfg->gpio_irq);
  86. free1:
  87. gpmc_cs_free(gpmc_cfg->cs);
  88. pr_err("Could not initialize smsc911x device\n");
  89. }