gpmc-smsc911x.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 resource gpmc_smsc911x_resources[] = {
  25. [0] = {
  26. .flags = IORESOURCE_MEM,
  27. },
  28. [1] = {
  29. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  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. };
  37. /*
  38. * Initialize smsc911x device connected to the GPMC. Note that we
  39. * assume that pin multiplexing is done in the board-*.c file,
  40. * or in the bootloader.
  41. */
  42. void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
  43. {
  44. struct platform_device *pdev;
  45. unsigned long cs_mem_base;
  46. int ret;
  47. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  48. pr_err("Failed to request GPMC mem region\n");
  49. return;
  50. }
  51. gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
  52. gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
  53. if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
  54. pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
  55. goto free1;
  56. }
  57. gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  58. if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
  59. ret = gpio_request_one(gpmc_cfg->gpio_reset,
  60. GPIOF_OUT_INIT_HIGH, "smsc911x reset");
  61. if (ret) {
  62. pr_err("Failed to request reset GPIO%d\n",
  63. gpmc_cfg->gpio_reset);
  64. goto free2;
  65. }
  66. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  67. msleep(100);
  68. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  69. }
  70. gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT;
  71. pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
  72. gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
  73. &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
  74. if (!pdev) {
  75. pr_err("Unable to register platform device\n");
  76. gpio_free(gpmc_cfg->gpio_reset);
  77. goto free2;
  78. }
  79. return;
  80. free2:
  81. gpio_free(gpmc_cfg->gpio_irq);
  82. free1:
  83. gpmc_cs_free(gpmc_cfg->cs);
  84. pr_err("Could not initialize smsc911x device\n");
  85. }