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