pxa2xx_stargate2.c 3.4 KB

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