pxa2xx_stargate2.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. }
  50. static int sg2_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  51. const socket_state_t *state)
  52. {
  53. /* Enable card power */
  54. switch (state->Vcc) {
  55. case 0:
  56. /* sets power ctl register high */
  57. gpio_set_value(SG2_S0_POWER_CTL, 1);
  58. break;
  59. case 33:
  60. case 50:
  61. /* sets power control register low (clear) */
  62. gpio_set_value(SG2_S0_POWER_CTL, 0);
  63. msleep(100);
  64. break;
  65. default:
  66. pr_err("%s(): bad Vcc %u\n",
  67. __func__, state->Vcc);
  68. return -1;
  69. }
  70. /* reset */
  71. gpio_set_value(SG2_S0_GPIO_RESET, !!(state->flags & SS_RESET));
  72. return 0;
  73. }
  74. static struct pcmcia_low_level sg2_pcmcia_ops __initdata = {
  75. .owner = THIS_MODULE,
  76. .hw_init = sg2_pcmcia_hw_init,
  77. .socket_state = sg2_pcmcia_socket_state,
  78. .configure_socket = sg2_pcmcia_configure_socket,
  79. .nr = 1,
  80. };
  81. static struct platform_device *sg2_pcmcia_device;
  82. static int __init sg2_pcmcia_init(void)
  83. {
  84. int ret;
  85. if (!machine_is_stargate2())
  86. return -ENODEV;
  87. sg2_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  88. if (!sg2_pcmcia_device)
  89. return -ENOMEM;
  90. ret = gpio_request_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  91. if (ret)
  92. goto error_put_platform_device;
  93. ret = platform_device_add_data(sg2_pcmcia_device,
  94. &sg2_pcmcia_ops,
  95. sizeof(sg2_pcmcia_ops));
  96. if (ret)
  97. goto error_free_gpios;
  98. ret = platform_device_add(sg2_pcmcia_device);
  99. if (ret)
  100. goto error_free_gpios;
  101. return 0;
  102. error_free_gpios:
  103. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  104. error_put_platform_device:
  105. platform_device_put(sg2_pcmcia_device);
  106. return ret;
  107. }
  108. static void __exit sg2_pcmcia_exit(void)
  109. {
  110. platform_device_unregister(sg2_pcmcia_device);
  111. gpio_free_array(sg2_pcmcia_gpios, ARRAY_SIZE(sg2_pcmcia_gpios));
  112. }
  113. fs_initcall(sg2_pcmcia_init);
  114. module_exit(sg2_pcmcia_exit);
  115. MODULE_LICENSE("GPL");
  116. MODULE_ALIAS("platform:pxa2xx-pcmcia");