pxa2xx_hx4700.c 2.9 KB

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