pxa2xx_stargate2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/drivers/pcmcia/pxa2xx_stargate2.c
  4. *
  5. * Stargate 2 PCMCIA specific routines.
  6. *
  7. * Created: December 6, 2005
  8. * Author: Ed C. Epp
  9. * Copyright: Intel Corp 2005
  10. * Jonathan Cameron <jic23@cam.ac.uk> 2009
  11. */
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/kernel.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/delay.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/gpio.h>
  19. #include <pcmcia/ss.h>
  20. #include <asm/irq.h>
  21. #include <asm/mach-types.h>
  22. #include "soc_common.h"
  23. #define SG2_S0_POWER_CTL 108
  24. #define SG2_S0_GPIO_RESET 82
  25. #define SG2_S0_GPIO_DETECT 53
  26. #define SG2_S0_GPIO_READY 81
  27. static struct gpio sg2_pcmcia_gpios[] = {
  28. { SG2_S0_GPIO_RESET, GPIOF_OUT_INIT_HIGH, "PCMCIA Reset" },
  29. { SG2_S0_POWER_CTL, GPIOF_OUT_INIT_HIGH, "PCMCIA Power Ctrl" },
  30. };
  31. static int sg2_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  32. {
  33. skt->stat[SOC_STAT_CD].gpio = SG2_S0_GPIO_DETECT;
  34. skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD";
  35. skt->stat[SOC_STAT_RDY].gpio = SG2_S0_GPIO_READY;
  36. skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY";
  37. return 0;
  38. }
  39. static void sg2_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  40. struct pcmcia_state *state)
  41. {
  42. state->bvd1 = 0; /* not available - battery detect on card */
  43. state->bvd2 = 0; /* not available */
  44. state->vs_3v = 1; /* not available - voltage detect for card */
  45. state->vs_Xv = 0; /* not available */
  46. }
  47. static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  48. const socket_state_t *state)
  49. {
  50. /* Enable card power */
  51. switch (state->Vcc) {
  52. case 0:
  53. /* sets power ctl register high */
  54. gpio_set_value(SG2_S0_POWER_CTL, 1);
  55. break;
  56. case 33:
  57. case 50:
  58. /* sets power control register low (clear) */
  59. gpio_set_value(SG2_S0_POWER_CTL, 0);
  60. msleep(100);
  61. break;
  62. default:
  63. pr_err("%s(): bad Vcc %u\n",
  64. __func__, state->Vcc);
  65. return -1;
  66. }
  67. /* reset */
  68. gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
  69. return 0;
  70. }
  71. static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
  72. .owner = THIS_MODULE,
  73. .hw_init = sg2_pcmcia_hw_init,
  74. .socket_state = sg2_pcmcia_socket_state,
  75. .configure_socket = sg2_pcmcia_configure_socket,
  76. .nr = 1,
  77. };
  78. static struct platform_device *sg2_pcmcia_device;
  79. static int __init sg2_pcmcia_init(void)
  80. {
  81. int ret;
  82. if (!machine_is_stargate2())
  83. return -ENODEV;
  84. sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  85. if (!sg2_pcmcia_device)
  86. return -ENOMEM;
  87. ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  88. if (ret)
  89. goto error_put_platform_device;
  90. ret = platform_device_add_data(sg2_pcmcia_device,
  91. &sg2_pcmcia_ops,
  92. sizeof(sg2_pcmcia_ops));
  93. if (ret)
  94. goto error_free_gpios;
  95. ret = platform_device_add(sg2_pcmcia_device);
  96. if (ret)
  97. goto error_free_gpios;
  98. return 0;
  99. error_free_gpios:
  100. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  101. error_put_platform_device:
  102. platform_device_put(sg2_pcmcia_device);
  103. return ret;
  104. }
  105. static void __exit sg2_pcmcia_exit(void)
  106. {
  107. platform_device_unregister(sg2_pcmcia_device);
  108. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  109. }
  110. fs_initcall(sg2_pcmcia_init);
  111. module_exit(sg2_pcmcia_exit);
  112. MODULE_LICENSE("GPL");
  113. MODULE_ALIAS("platform:pxa2xx-pcmcia");