sa1100_generic.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*======================================================================
  2. Device driver for the PCMCIA control functionality of StrongARM
  3. SA-1100 microprocessors.
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is John G. Dorsey
  13. <john+@cs.cmu.edu>. Portions created by John G. Dorsey are
  14. Copyright (C) 1999 John G. Dorsey. All Rights Reserved.
  15. Alternatively, the contents of this file may be used under the
  16. terms of the GNU Public License version 2 (the "GPL"), in which
  17. case the provisions of the GPL are applicable instead of the
  18. above. If you wish to allow the use of your version of this file
  19. only under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision
  21. by deleting the provisions above and replace them with the notice
  22. and other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this
  24. file under either the MPL or the GPL.
  25. ======================================================================*/
  26. #include <linux/module.h>
  27. #include <linux/gpio/consumer.h>
  28. #include <linux/init.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <linux/slab.h>
  31. #include <linux/platform_device.h>
  32. #include <pcmcia/ss.h>
  33. #include <asm/hardware/scoop.h>
  34. #include "sa1100_generic.h"
  35. static const char *sa11x0_cf_gpio_names[] = {
  36. [SOC_STAT_CD] = "detect",
  37. [SOC_STAT_BVD1] = "bvd1",
  38. [SOC_STAT_BVD2] = "bvd2",
  39. [SOC_STAT_RDY] = "ready",
  40. };
  41. static int sa11x0_cf_hw_init(struct soc_pcmcia_socket *skt)
  42. {
  43. struct device *dev = skt->socket.dev.parent;
  44. int i;
  45. skt->gpio_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  46. if (IS_ERR(skt->gpio_reset))
  47. return PTR_ERR(skt->gpio_reset);
  48. skt->gpio_bus_enable = devm_gpiod_get_optional(dev, "bus-enable",
  49. GPIOD_OUT_HIGH);
  50. if (IS_ERR(skt->gpio_bus_enable))
  51. return PTR_ERR(skt->gpio_bus_enable);
  52. skt->vcc.reg = devm_regulator_get_optional(dev, "vcc");
  53. if (IS_ERR(skt->vcc.reg))
  54. return PTR_ERR(skt->vcc.reg);
  55. if (!skt->vcc.reg)
  56. dev_warn(dev,
  57. "no Vcc regulator provided, ignoring Vcc controls\n");
  58. for (i = 0; i < ARRAY_SIZE(sa11x0_cf_gpio_names); i++) {
  59. skt->stat[i].name = sa11x0_cf_gpio_names[i];
  60. skt->stat[i].desc = devm_gpiod_get_optional(dev,
  61. sa11x0_cf_gpio_names[i], GPIOD_IN);
  62. if (IS_ERR(skt->stat[i].desc))
  63. return PTR_ERR(skt->stat[i].desc);
  64. }
  65. return 0;
  66. }
  67. static int sa11x0_cf_configure_socket(struct soc_pcmcia_socket *skt,
  68. const socket_state_t *state)
  69. {
  70. return soc_pcmcia_regulator_set(skt, &skt->vcc, state->Vcc);
  71. }
  72. static struct pcmcia_low_level sa11x0_cf_ops = {
  73. .owner = THIS_MODULE,
  74. .hw_init = sa11x0_cf_hw_init,
  75. .socket_state = soc_common_cf_socket_state,
  76. .configure_socket = sa11x0_cf_configure_socket,
  77. };
  78. int __init pcmcia_collie_init(struct device *dev);
  79. static int (*sa11x0_pcmcia_legacy_hw_init[])(struct device *dev) = {
  80. #if defined(CONFIG_SA1100_H3100) || defined(CONFIG_SA1100_H3600)
  81. pcmcia_h3600_init,
  82. #endif
  83. #ifdef CONFIG_SA1100_SIMPAD
  84. pcmcia_simpad_init,
  85. #endif
  86. #ifdef CONFIG_SA1100_COLLIE
  87. pcmcia_collie_init,
  88. #endif
  89. };
  90. static int sa11x0_drv_pcmcia_legacy_probe(struct platform_device *dev)
  91. {
  92. int i, ret = -ENODEV;
  93. /*
  94. * Initialise any "on-board" PCMCIA sockets.
  95. */
  96. for (i = 0; i < ARRAY_SIZE(sa11x0_pcmcia_legacy_hw_init); i++) {
  97. ret = sa11x0_pcmcia_legacy_hw_init[i](&dev->dev);
  98. if (ret == 0)
  99. break;
  100. }
  101. return ret;
  102. }
  103. static int sa11x0_drv_pcmcia_legacy_remove(struct platform_device *dev)
  104. {
  105. struct skt_dev_info *sinfo = platform_get_drvdata(dev);
  106. int i;
  107. platform_set_drvdata(dev, NULL);
  108. for (i = 0; i < sinfo->nskt; i++)
  109. soc_pcmcia_remove_one(&sinfo->skt[i]);
  110. return 0;
  111. }
  112. static int sa11x0_drv_pcmcia_probe(struct platform_device *pdev)
  113. {
  114. struct soc_pcmcia_socket *skt;
  115. struct device *dev = &pdev->dev;
  116. if (pdev->id == -1)
  117. return sa11x0_drv_pcmcia_legacy_probe(pdev);
  118. skt = devm_kzalloc(dev, sizeof(*skt), GFP_KERNEL);
  119. if (!skt)
  120. return -ENOMEM;
  121. platform_set_drvdata(pdev, skt);
  122. skt->nr = pdev->id;
  123. skt->clk = devm_clk_get(dev, NULL);
  124. if (IS_ERR(skt->clk))
  125. return PTR_ERR(skt->clk);
  126. sa11xx_drv_pcmcia_ops(&sa11x0_cf_ops);
  127. soc_pcmcia_init_one(skt, &sa11x0_cf_ops, dev);
  128. return sa11xx_drv_pcmcia_add_one(skt);
  129. }
  130. static int sa11x0_drv_pcmcia_remove(struct platform_device *dev)
  131. {
  132. struct soc_pcmcia_socket *skt;
  133. if (dev->id == -1)
  134. return sa11x0_drv_pcmcia_legacy_remove(dev);
  135. skt = platform_get_drvdata(dev);
  136. soc_pcmcia_remove_one(skt);
  137. return 0;
  138. }
  139. static struct platform_driver sa11x0_pcmcia_driver = {
  140. .driver = {
  141. .name = "sa11x0-pcmcia",
  142. },
  143. .probe = sa11x0_drv_pcmcia_probe,
  144. .remove = sa11x0_drv_pcmcia_remove,
  145. };
  146. /* sa11x0_pcmcia_init()
  147. * ^^^^^^^^^^^^^^^^^^^^
  148. *
  149. * This routine performs low-level PCMCIA initialization and then
  150. * registers this socket driver with Card Services.
  151. *
  152. * Returns: 0 on success, -ve error code on failure
  153. */
  154. static int __init sa11x0_pcmcia_init(void)
  155. {
  156. return platform_driver_register(&sa11x0_pcmcia_driver);
  157. }
  158. /* sa11x0_pcmcia_exit()
  159. * ^^^^^^^^^^^^^^^^^^^^
  160. * Invokes the low-level kernel service to free IRQs associated with this
  161. * socket controller and reset GPIO edge detection.
  162. */
  163. static void __exit sa11x0_pcmcia_exit(void)
  164. {
  165. platform_driver_unregister(&sa11x0_pcmcia_driver);
  166. }
  167. MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
  168. MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11x0 Socket Controller");
  169. MODULE_LICENSE("Dual MPL/GPL");
  170. fs_initcall(sa11x0_pcmcia_init);
  171. module_exit(sa11x0_pcmcia_exit);