gpmc-smsc911x.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <linux/regulator/fixed.h>
  22. #include <linux/regulator/machine.h>
  23. #include <plat/board.h>
  24. #include <plat/gpmc.h>
  25. #include <plat/gpmc-smsc911x.h>
  26. static struct resource gpmc_smsc911x_resources[] = {
  27. [0] = {
  28. .flags = IORESOURCE_MEM,
  29. },
  30. [1] = {
  31. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  32. },
  33. };
  34. static struct smsc911x_platform_config gpmc_smsc911x_config = {
  35. .phy_interface = PHY_INTERFACE_MODE_MII,
  36. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  37. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  38. };
  39. static struct regulator_consumer_supply gpmc_smsc911x_supply[] = {
  40. REGULATOR_SUPPLY("vddvario", "smsc911x.0"),
  41. REGULATOR_SUPPLY("vdd33a", "smsc911x.0"),
  42. };
  43. /* Generic regulator definition to satisfy smsc911x */
  44. static struct regulator_init_data gpmc_smsc911x_reg_init_data = {
  45. .constraints = {
  46. .min_uV = 3300000,
  47. .max_uV = 3300000,
  48. .valid_modes_mask = REGULATOR_MODE_NORMAL
  49. | REGULATOR_MODE_STANDBY,
  50. .valid_ops_mask = REGULATOR_CHANGE_MODE
  51. | REGULATOR_CHANGE_STATUS,
  52. },
  53. .num_consumer_supplies = ARRAY_SIZE(gpmc_smsc911x_supply),
  54. .consumer_supplies = gpmc_smsc911x_supply,
  55. };
  56. static struct fixed_voltage_config gpmc_smsc911x_fixed_reg_data = {
  57. .supply_name = "gpmc_smsc911x",
  58. .microvolts = 3300000,
  59. .gpio = -EINVAL,
  60. .startup_delay = 0,
  61. .enable_high = 0,
  62. .enabled_at_boot = 1,
  63. .init_data = &gpmc_smsc911x_reg_init_data,
  64. };
  65. /*
  66. * Platform device id of 42 is a temporary fix to avoid conflicts
  67. * with other reg-fixed-voltage devices. The real fix should
  68. * involve the driver core providing a way of dynamically
  69. * assigning a unique id on registration for platform devices
  70. * in the same name space.
  71. */
  72. static struct platform_device gpmc_smsc911x_regulator = {
  73. .name = "reg-fixed-voltage",
  74. .id = 42,
  75. .dev = {
  76. .platform_data = &gpmc_smsc911x_fixed_reg_data,
  77. },
  78. };
  79. /*
  80. * Initialize smsc911x device connected to the GPMC. Note that we
  81. * assume that pin multiplexing is done in the board-*.c file,
  82. * or in the bootloader.
  83. */
  84. void __init gpmc_smsc911x_init(struct omap_smsc911x_platform_data *gpmc_cfg)
  85. {
  86. struct platform_device *pdev;
  87. unsigned long cs_mem_base;
  88. int ret;
  89. if (!gpmc_cfg->id) {
  90. ret = platform_device_register(&gpmc_smsc911x_regulator);
  91. if (ret < 0) {
  92. pr_err("Unable to register smsc911x regulators: %d\n",
  93. ret);
  94. return;
  95. }
  96. }
  97. if (gpmc_cs_request(gpmc_cfg->cs, SZ_16M, &cs_mem_base) < 0) {
  98. pr_err("Failed to request GPMC mem region\n");
  99. return;
  100. }
  101. gpmc_smsc911x_resources[0].start = cs_mem_base + 0x0;
  102. gpmc_smsc911x_resources[0].end = cs_mem_base + 0xff;
  103. if (gpio_request_one(gpmc_cfg->gpio_irq, GPIOF_IN, "smsc911x irq")) {
  104. pr_err("Failed to request IRQ GPIO%d\n", gpmc_cfg->gpio_irq);
  105. goto free1;
  106. }
  107. gpmc_smsc911x_resources[1].start = gpio_to_irq(gpmc_cfg->gpio_irq);
  108. if (gpio_is_valid(gpmc_cfg->gpio_reset)) {
  109. ret = gpio_request_one(gpmc_cfg->gpio_reset,
  110. GPIOF_OUT_INIT_HIGH, "smsc911x reset");
  111. if (ret) {
  112. pr_err("Failed to request reset GPIO%d\n",
  113. gpmc_cfg->gpio_reset);
  114. goto free2;
  115. }
  116. gpio_set_value(gpmc_cfg->gpio_reset, 0);
  117. msleep(100);
  118. gpio_set_value(gpmc_cfg->gpio_reset, 1);
  119. }
  120. gpmc_smsc911x_config.flags = gpmc_cfg->flags ? : SMSC911X_USE_16BIT;
  121. pdev = platform_device_register_resndata(NULL, "smsc911x", gpmc_cfg->id,
  122. gpmc_smsc911x_resources, ARRAY_SIZE(gpmc_smsc911x_resources),
  123. &gpmc_smsc911x_config, sizeof(gpmc_smsc911x_config));
  124. if (!pdev) {
  125. pr_err("Unable to register platform device\n");
  126. gpio_free(gpmc_cfg->gpio_reset);
  127. goto free2;
  128. }
  129. return;
  130. free2:
  131. gpio_free(gpmc_cfg->gpio_irq);
  132. free1:
  133. gpmc_cs_free(gpmc_cfg->cs);
  134. pr_err("Could not initialize smsc911x device\n");
  135. }