pxa2xx_hx4700.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/err.h>
  11. #include <linux/gpio.h>
  12. #include <linux/irq.h>
  13. #include <asm/mach-types.h>
  14. #include <mach/hx4700.h>
  15. #include "soc_common.h"
  16. static struct gpio gpios[] = {
  17. { GPIO114_HX4700_CF_RESET, GPIOF_OUT_INIT_LOW, "CF reset" },
  18. { EGPIO4_CF_3V3_ON, GPIOF_OUT_INIT_LOW, "CF 3.3V enable" },
  19. };
  20. static int hx4700_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  21. {
  22. int ret;
  23. ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
  24. if (ret)
  25. goto out;
  26. /*
  27. * IRQ type must be set before soc_pcmcia_hw_init() calls request_irq().
  28. * The asic3 default IRQ type is level trigger low level detect, exactly
  29. * the the signal present on GPIOD4_CF_nCD when a CF card is inserted.
  30. * If the IRQ type is not changed, the asic3 interrupt handler will loop
  31. * repeatedly because it is unable to clear the level trigger interrupt.
  32. */
  33. irq_set_irq_type(gpio_to_irq(GPIOD4_CF_nCD), IRQ_TYPE_EDGE_BOTH);
  34. skt->stat[SOC_STAT_CD].gpio = GPIOD4_CF_nCD;
  35. skt->stat[SOC_STAT_CD].name = "PCMCIA CD";
  36. skt->stat[SOC_STAT_RDY].gpio = GPIO60_HX4700_CF_RNB;
  37. skt->stat[SOC_STAT_RDY].name = "PCMCIA Ready";
  38. out:
  39. return ret;
  40. }
  41. static void hx4700_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
  42. {
  43. gpio_free_array(gpios, ARRAY_SIZE(gpios));
  44. }
  45. static void hx4700_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  46. struct pcmcia_state *state)
  47. {
  48. state->vs_3v = 1;
  49. state->vs_Xv = 0;
  50. }
  51. static int hx4700_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  52. const socket_state_t *state)
  53. {
  54. switch (state->Vcc) {
  55. case 0:
  56. gpio_set_value(EGPIO4_CF_3V3_ON, 0);
  57. break;
  58. case 33:
  59. gpio_set_value(EGPIO4_CF_3V3_ON, 1);
  60. break;
  61. default:
  62. printk(KERN_ERR "pcmcia: Unsupported Vcc: %d\n", state->Vcc);
  63. return -EINVAL;
  64. }
  65. gpio_set_value(GPIO114_HX4700_CF_RESET, (state->flags & SS_RESET) != 0);
  66. return 0;
  67. }
  68. static struct pcmcia_low_level hx4700_pcmcia_ops = {
  69. .owner = THIS_MODULE,
  70. .nr = 1,
  71. .hw_init = hx4700_pcmcia_hw_init,
  72. .hw_shutdown = hx4700_pcmcia_hw_shutdown,
  73. .socket_state = hx4700_pcmcia_socket_state,
  74. .configure_socket = hx4700_pcmcia_configure_socket,
  75. };
  76. static struct platform_device *hx4700_pcmcia_device;
  77. static int __init hx4700_pcmcia_init(void)
  78. {
  79. struct platform_device *pdev;
  80. if (!machine_is_h4700())
  81. return -ENODEV;
  82. pdev = platform_device_register_data(NULL, "pxa2xx-pcmcia", -1,
  83. &hx4700_pcmcia_ops, sizeof(hx4700_pcmcia_ops));
  84. if (IS_ERR(pdev))
  85. return PTR_ERR(pdev);
  86. hx4700_pcmcia_device = pdev;
  87. return 0;
  88. }
  89. static void __exit hx4700_pcmcia_exit(void)
  90. {
  91. platform_device_unregister(hx4700_pcmcia_device);
  92. }
  93. module_init(hx4700_pcmcia_init);
  94. module_exit(hx4700_pcmcia_exit);
  95. MODULE_AUTHOR("Paul Parsons <lost.distance@yahoo.com>");
  96. MODULE_DESCRIPTION("HP iPAQ hx4700 PCMCIA driver");
  97. MODULE_LICENSE("GPL");