gpmc-smsc911x.c 4.3 KB

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