sa1111_generic.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. void sa1111_pcmcia_socket_state(struct soc_pcmcia_socket *skt, struct pcmcia_state *state)
  59. {
  60. struct sa1111_pcmcia_socket *s = to_skt(skt);
  61. unsigned long status = sa1111_readl(s->dev->mapbase + PCSR);
  62. switch (skt->nr) {
  63. case 0:
  64. state->detect = status & PCSR_S0_DETECT ? 0 : 1;
  65. state->ready = status & PCSR_S0_READY ? 1 : 0;
  66. state->bvd1 = status & PCSR_S0_BVD1 ? 1 : 0;
  67. state->bvd2 = status & PCSR_S0_BVD2 ? 1 : 0;
  68. state->wrprot = status & PCSR_S0_WP ? 1 : 0;
  69. state->vs_3v = status & PCSR_S0_VS1 ? 0 : 1;
  70. state->vs_Xv = status & PCSR_S0_VS2 ? 0 : 1;
  71. break;
  72. case 1:
  73. state->detect = status & PCSR_S1_DETECT ? 0 : 1;
  74. state->ready = status & PCSR_S1_READY ? 1 : 0;
  75. state->bvd1 = status & PCSR_S1_BVD1 ? 1 : 0;
  76. state->bvd2 = status & PCSR_S1_BVD2 ? 1 : 0;
  77. state->wrprot = status & PCSR_S1_WP ? 1 : 0;
  78. state->vs_3v = status & PCSR_S1_VS1 ? 0 : 1;
  79. state->vs_Xv = status & PCSR_S1_VS2 ? 0 : 1;
  80. break;
  81. }
  82. }
  83. int sa1111_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, const socket_state_t *state)
  84. {
  85. struct sa1111_pcmcia_socket *s = to_skt(skt);
  86. unsigned int pccr_skt_mask, pccr_set_mask, val;
  87. unsigned long flags;
  88. switch (skt->nr) {
  89. case 0:
  90. pccr_skt_mask = PCCR_S0_RST|PCCR_S0_FLT|PCCR_S0_PWAITEN|PCCR_S0_PSE;
  91. break;
  92. case 1:
  93. pccr_skt_mask = PCCR_S1_RST|PCCR_S1_FLT|PCCR_S1_PWAITEN|PCCR_S1_PSE;
  94. break;
  95. default:
  96. return -1;
  97. }
  98. pccr_set_mask = 0;
  99. if (state->Vcc != 0)
  100. pccr_set_mask |= PCCR_S0_PWAITEN|PCCR_S1_PWAITEN;
  101. if (state->Vcc == 50)
  102. pccr_set_mask |= PCCR_S0_PSE|PCCR_S1_PSE;
  103. if (state->flags & SS_RESET)
  104. pccr_set_mask |= PCCR_S0_RST|PCCR_S1_RST;
  105. if (state->flags & SS_OUTPUT_ENA)
  106. pccr_set_mask |= PCCR_S0_FLT|PCCR_S1_FLT;
  107. local_irq_save(flags);
  108. val = sa1111_readl(s->dev->mapbase + PCCR);
  109. val &= ~pccr_skt_mask;
  110. val |= pccr_set_mask & pccr_skt_mask;
  111. sa1111_writel(val, s->dev->mapbase + PCCR);
  112. local_irq_restore(flags);
  113. return 0;
  114. }
  115. int sa1111_pcmcia_add(struct sa1111_dev *dev, struct pcmcia_low_level *ops,
  116. int (*add)(struct soc_pcmcia_socket *))
  117. {
  118. struct sa1111_pcmcia_socket *s;
  119. struct clk *clk;
  120. int i, ret = 0;
  121. clk = devm_clk_get(&dev->dev, NULL);
  122. if (IS_ERR(clk))
  123. return PTR_ERR(clk);
  124. ops->socket_state = sa1111_pcmcia_socket_state;
  125. for (i = 0; i < ops->nr; i++) {
  126. s = kzalloc(sizeof(*s), GFP_KERNEL);
  127. if (!s)
  128. return -ENOMEM;
  129. s->soc.nr = ops->first + i;
  130. s->soc.clk = clk;
  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. ret = -ENODEV;
  174. #ifdef CONFIG_SA1100_BADGE4
  175. if (machine_is_badge4())
  176. ret = pcmcia_badge4_init(dev);
  177. #endif
  178. #ifdef CONFIG_SA1100_JORNADA720
  179. if (machine_is_jornada720())
  180. ret = pcmcia_jornada720_init(dev);
  181. #endif
  182. #ifdef CONFIG_ARCH_LUBBOCK
  183. if (machine_is_lubbock())
  184. ret = pcmcia_lubbock_init(dev);
  185. #endif
  186. #ifdef CONFIG_ASSABET_NEPONSET
  187. if (machine_is_assabet())
  188. ret = pcmcia_neponset_init(dev);
  189. #endif
  190. if (ret) {
  191. release_mem_region(dev->res.start, 512);
  192. sa1111_disable_device(dev);
  193. }
  194. return ret;
  195. }
  196. static int pcmcia_remove(struct sa1111_dev *dev)
  197. {
  198. struct sa1111_pcmcia_socket *next, *s = dev_get_drvdata(&dev->dev);
  199. dev_set_drvdata(&dev->dev, NULL);
  200. for (; s; s = next) {
  201. next = s->next;
  202. soc_pcmcia_remove_one(&s->soc);
  203. kfree(s);
  204. }
  205. release_mem_region(dev->res.start, 512);
  206. sa1111_disable_device(dev);
  207. return 0;
  208. }
  209. static struct sa1111_driver pcmcia_driver = {
  210. .drv = {
  211. .name = "sa1111-pcmcia",
  212. },
  213. .devid = SA1111_DEVID_PCMCIA,
  214. .probe = pcmcia_probe,
  215. .remove = pcmcia_remove,
  216. };
  217. static int __init sa1111_drv_pcmcia_init(void)
  218. {
  219. return sa1111_driver_register(&pcmcia_driver);
  220. }
  221. static void __exit sa1111_drv_pcmcia_exit(void)
  222. {
  223. sa1111_driver_unregister(&pcmcia_driver);
  224. }
  225. fs_initcall(sa1111_drv_pcmcia_init);
  226. module_exit(sa1111_drv_pcmcia_exit);
  227. MODULE_DESCRIPTION("SA1111 PCMCIA card socket driver");
  228. MODULE_LICENSE("GPL");