sa1111_generic.c 6.7 KB

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