sa1111_generic.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /*
  2. * linux/drivers/pcmcia/sa1111_generic.c
  3. *
  4. * We implement the generic parts of a SA1111 PCMCIA driver. This
  5. * basically means we handle everything except controlling the
  6. * power. Power is machine specific...
  7. */
  8. #include <linux/module.h>
  9. #include <linux/kernel.h>
  10. #include <linux/ioport.h>
  11. #include <linux/device.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/slab.h>
  16. #include <pcmcia/ss.h>
  17. #include <mach/hardware.h>
  18. #include <asm/hardware/sa1111.h>
  19. #include <asm/irq.h>
  20. #include "sa1111_generic.h"
  21. /*
  22. * These are offsets from the above base.
  23. */
  24. #define PCCR 0x0000
  25. #define PCSSR 0x0004
  26. #define PCSR 0x0008
  27. #define PCSR_S0_READY (1<<0)
  28. #define PCSR_S1_READY (1<<1)
  29. #define PCSR_S0_DETECT (1<<2)
  30. #define PCSR_S1_DETECT (1<<3)
  31. #define PCSR_S0_VS1 (1<<4)
  32. #define PCSR_S0_VS2 (1<<5)
  33. #define PCSR_S1_VS1 (1<<6)
  34. #define PCSR_S1_VS2 (1<<7)
  35. #define PCSR_S0_WP (1<<8)
  36. #define PCSR_S1_WP (1<<9)
  37. #define PCSR_S0_BVD1 (1<<10)
  38. #define PCSR_S0_BVD2 (1<<11)
  39. #define PCSR_S1_BVD1 (1<<12)
  40. #define PCSR_S1_BVD2 (1<<13)
  41. #define PCCR_S0_RST (1<<0)
  42. #define PCCR_S1_RST (1<<1)
  43. #define PCCR_S0_FLT (1<<2)
  44. #define PCCR_S1_FLT (1<<3)
  45. #define PCCR_S0_PWAITEN (1<<4)
  46. #define PCCR_S1_PWAITEN (1<<5)
  47. #define PCCR_S0_PSE (1<<6)
  48. #define PCCR_S1_PSE (1<<7)
  49. #define PCSSR_S0_SLEEP (1<<0)
  50. #define PCSSR_S1_SLEEP (1<<1)
  51. #define IDX_IRQ_S0_READY_NINT (0)
  52. #define IDX_IRQ_S0_CD_VALID (1)
  53. #define IDX_IRQ_S0_BVD1_STSCHG (2)
  54. #define IDX_IRQ_S1_READY_NINT (3)
  55. #define IDX_IRQ_S1_CD_VALID (4)
  56. #define IDX_IRQ_S1_BVD1_STSCHG (5)
  57. void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  58. {
  59. struct sa1111_pcmcia_socket *s = to_skt(skt);
  60. unsigned long status = sa1111_readl(s->dev->mapbase + PCSR);
  61. switch (skt->nr) {
  62. case 0:
  63. state->detect = status & PCSR_S0_DETECT ? 0 : 1;
  64. state->ready = status & PCSR_S0_READY ? 1 : 0;
  65. state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0;
  66. state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0;
  67. state->wrprot = status & PCSR_S0_WP ? 1 : 0;
  68. state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1;
  69. state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1;
  70. break;
  71. case 1:
  72. state->detect = status & PCSR_S1_DETECT ? 0 : 1;
  73. state->ready = status & PCSR_S1_READY ? 1 : 0;
  74. state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0;
  75. state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0;
  76. state->wrprot = status & PCSR_S1_WP ? 1 : 0;
  77. state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1;
  78. state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1;
  79. break;
  80. }
  81. }
  82. int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
  83. {
  84. struct sa1111_pcmcia_socket *s = to_skt(skt);
  85. unsigned int pccr_skt_mask, pccr_set_mask, val;
  86. unsigned long flags;
  87. switch (skt->nr) {
  88. case 0:
  89. pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE;
  90. break;
  91. case 1:
  92. pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE;
  93. break;
  94. default:
  95. return -1;
  96. }
  97. pccr_set_mask = 0;
  98. if (state->Vcc != 0)
  99. pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN;
  100. if (state->Vcc == 50)
  101. pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE;
  102. if (state->flags & SS_RESET)
  103. pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST;
  104. if (state->flags & SS_OUTPUT_ENA)
  105. pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT;
  106. local_irq_save(flags);
  107. val = sa1111_readl(s->dev->mapbase + PCCR);
  108. val &= ~pccr_skt_mask;
  109. val |= pccr_set_mask & pccr_skt_mask;
  110. sa1111_writel(val, s->dev->mapbase + PCCR);
  111. local_irq_restore(flags);
  112. return 0;
  113. }
  114. int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops,
  115. int (*add)(struct soc_pcmcia_socket *))
  116. {
  117. struct sa1111_pcmcia_socket *s;
  118. int i, ret = 0;
  119. ops->socket_state = sa1111_pcmcia_socket_state;
  120. for (i = 0; i < ops->nr; i++) {
  121. s = kzalloc(sizeof(*s), GFP_KERNEL);
  122. if (!s)
  123. return -ENOMEM;
  124. s->soc.nr = ops->first + i;
  125. s->soc.clk = clk_get(&dev->dev, NULL);
  126. if (IS_ERR(s->soc.clk)) {
  127. ret = PTR_ERR(s->soc.clk);
  128. kfree(s);
  129. return ret;
  130. }
  131. soc_pcmcia_init_one(&s->soc, ops, &dev->dev);
  132. s->dev = dev;
  133. if (s->soc.nr) {
  134. s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S1_READY_NINT];
  135. s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S1_CD_VALID];
  136. s->soc.stat[SOC_STAT_CD].name = "SA1111 CF card detect";
  137. s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S1_BVD1_STSCHG];
  138. s->soc.stat[SOC_STAT_BVD1].name = "SA1111 CF BVD1";
  139. } else {
  140. s->soc.socket.pci_irq = dev->irq[IDX_IRQ_S0_READY_NINT];
  141. s->soc.stat[SOC_STAT_CD].irq = dev->irq[IDX_IRQ_S0_CD_VALID];
  142. s->soc.stat[SOC_STAT_CD].name = "SA1111 PCMCIA card detect";
  143. s->soc.stat[SOC_STAT_BVD1].irq = dev->irq[IDX_IRQ_S0_BVD1_STSCHG];
  144. s->soc.stat[SOC_STAT_BVD1].name = "SA1111 PCMCIA BVD1";
  145. }
  146. ret = add(&s->soc);
  147. if (ret == 0) {
  148. s->next = dev_get_drvdata(&dev->dev);
  149. dev_set_drvdata(&dev->dev, s);
  150. } else
  151. kfree(s);
  152. }
  153. return ret;
  154. }
  155. static int pcmcia_probe(struct sa1111_dev *dev)
  156. {
  157. void __iomem *base;
  158. int ret;
  159. ret = sa1111_enable_device(dev);
  160. if (ret)
  161. return ret;
  162. dev_set_drvdata(&dev->dev, NULL);
  163. if (!request_mem_region(dev->res.start, 512, SA1111_DRIVER_NAME(dev))) {
  164. sa1111_disable_device(dev);
  165. return -EBUSY;
  166. }
  167. base = dev->mapbase;
  168. /*
  169. * Initialise the suspend state.
  170. */
  171. sa1111_writel(PCSSR_S0_SLEEP | PCSSR_S1_SLEEP, base + PCSSR);
  172. sa1111_writel(PCCR_S0_FLT | PCCR_S1_FLT, base + PCCR);
  173. #ifdef CONFIG_SA1100_BADGE4
  174. pcmcia_badge4_init(dev);
  175. #endif
  176. #ifdef CONFIG_SA1100_JORNADA720
  177. pcmcia_jornada720_init(dev);
  178. #endif
  179. #ifdef CONFIG_ARCH_LUBBOCK
  180. pcmcia_lubbock_init(dev);
  181. #endif
  182. #ifdef CONFIG_ASSABET_NEPONSET
  183. pcmcia_neponset_init(dev);
  184. #endif
  185. return 0;
  186. }
  187. static int pcmcia_remove(struct sa1111_dev *dev)
  188. {
  189. struct sa1111_pcmcia_socket *next, *s = dev_get_drvdata(&dev->dev);
  190. dev_set_drvdata(&dev->dev, NULL);
  191. for (; s; s = next) {
  192. next = s->next;
  193. soc_pcmcia_remove_one(&s->soc);
  194. clk_put(s->soc.clk);
  195. kfree(s);
  196. }
  197. release_mem_region(dev->res.start, 512);
  198. sa1111_disable_device(dev);
  199. return 0;
  200. }
  201. static struct sa1111_driver pcmcia_driver = {
  202. .drv = {
  203. .name = "sa1111-pcmcia",
  204. },
  205. .devid = SA1111_DEVID_PCMCIA,
  206. .probe = pcmcia_probe,
  207. .remove = pcmcia_remove,
  208. };
  209. static int __init sa1111_drv_pcmcia_init(void)
  210. {
  211. return sa1111_driver_register(&pcmcia_driver);
  212. }
  213. static void __exit sa1111_drv_pcmcia_exit(void)
  214. {
  215. sa1111_driver_unregister(&pcmcia_driver);
  216. }
  217. fs_initcall(sa1111_drv_pcmcia_init);
  218. module_exit(sa1111_drv_pcmcia_exit);
  219. MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
  220. MODULE_LICENSE("GPL");