pxa2xx_sharpsl.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * Sharp SL-C7xx Series PCMCIA routines
  3. *
  4. * Copyright (c) 2004-2005 Richard Purdie
  5. *
  6. * Based on Sharp's 2.4 kernel patches and pxa2xx_mainstone.c
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/errno.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/platform_device.h>
  19. #include <asm/mach-types.h>
  20. #include <mach/hardware.h>
  21. #include <asm/irq.h>
  22. #include <asm/hardware/scoop.h>
  23. #include "soc_common.h"
  24. #define NO_KEEP_VS 0x0001
  25. #define SCOOP_DEV platform_scoop_config->devs
  26. static void sharpsl_pcmcia_init_reset(struct soc_pcmcia_socket *skt)
  27. {
  28. struct scoop_pcmcia_dev *scoopdev = &SCOOP_DEV[skt->nr];
  29. reset_scoop(scoopdev->dev);
  30. /* Shared power controls need to be handled carefully */
  31. if (platform_scoop_config->power_ctrl)
  32. platform_scoop_config->power_ctrl(scoopdev->dev, 0x0000, skt->nr);
  33. else
  34. write_scoop_reg(scoopdev->dev, SCOOP_CPR, 0x0000);
  35. scoopdev->keep_vs = NO_KEEP_VS;
  36. scoopdev->keep_rd = 0;
  37. }
  38. static int sharpsl_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
  39. {
  40. if (SCOOP_DEV[skt->nr].cd_irq >= 0) {
  41. skt->stat[SOC_STAT_CD].irq = SCOOP_DEV[skt->nr].cd_irq;
  42. skt->stat[SOC_STAT_CD].name = SCOOP_DEV[skt->nr].cd_irq_str;
  43. }
  44. skt->socket.pci_irq = SCOOP_DEV[skt->nr].irq;
  45. return 0;
  46. }
  47. static void sharpsl_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
  48. struct pcmcia_state *state)
  49. {
  50. unsigned short cpr, csr;
  51. struct device *scoop = SCOOP_DEV[skt->nr].dev;
  52. cpr = read_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_CPR);
  53. write_scoop_reg(scoop, SCOOP_IRM, 0x00FF);
  54. write_scoop_reg(scoop, SCOOP_ISR, 0x0000);
  55. write_scoop_reg(scoop, SCOOP_IRM, 0x0000);
  56. csr = read_scoop_reg(scoop, SCOOP_CSR);
  57. if (csr & 0x0004) {
  58. /* card eject */
  59. write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
  60. SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
  61. }
  62. else if (!(SCOOP_DEV[skt->nr].keep_vs & NO_KEEP_VS)) {
  63. /* keep vs1,vs2 */
  64. write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
  65. csr |= SCOOP_DEV[skt->nr].keep_vs;
  66. }
  67. else if (cpr & 0x0003) {
  68. /* power on */
  69. write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
  70. SCOOP_DEV[skt->nr].keep_vs = (csr & 0x00C0);
  71. }
  72. else {
  73. /* card detect */
  74. if ((machine_is_spitz() || machine_is_borzoi()) && skt->nr == 1) {
  75. write_scoop_reg(scoop, SCOOP_CDR, 0x0000);
  76. } else {
  77. write_scoop_reg(scoop, SCOOP_CDR, 0x0002);
  78. }
  79. }
  80. state->detect = (csr & 0x0004) ? 0 : 1;
  81. state->ready = (csr & 0x0002) ? 1 : 0;
  82. state->bvd1 = (csr & 0x0010) ? 1 : 0;
  83. state->bvd2 = (csr & 0x0020) ? 1 : 0;
  84. state->wrprot = (csr & 0x0008) ? 1 : 0;
  85. state->vs_3v = (csr & 0x0040) ? 0 : 1;
  86. state->vs_Xv = (csr & 0x0080) ? 0 : 1;
  87. if ((cpr & 0x0080) && ((cpr & 0x8040) != 0x8040)) {
  88. printk(KERN_ERR "sharpsl_pcmcia_socket_state(): CPR=%04X, Low voltage!\n", cpr);
  89. }
  90. }
  91. static int sharpsl_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
  92. const socket_state_t *state)
  93. {
  94. unsigned long flags;
  95. struct device *scoop = SCOOP_DEV[skt->nr].dev;
  96. unsigned short cpr, ncpr, ccr, nccr, mcr, nmcr, imr, nimr;
  97. switch (state->Vcc) {
  98. case 0: break;
  99. case 33: break;
  100. case 50: break;
  101. default:
  102. printk(KERN_ERR "sharpsl_pcmcia_configure_socket(): bad Vcc %u\n", state->Vcc);
  103. return -1;
  104. }
  105. if ((state->Vpp!=state->Vcc) && (state->Vpp!=0)) {
  106. printk(KERN_ERR "CF slot cannot support Vpp %u\n", state->Vpp);
  107. return -1;
  108. }
  109. local_irq_save(flags);
  110. nmcr = (mcr = read_scoop_reg(scoop, SCOOP_MCR)) & ~0x0010;
  111. ncpr = (cpr = read_scoop_reg(scoop, SCOOP_CPR)) & ~0x0083;
  112. nccr = (ccr = read_scoop_reg(scoop, SCOOP_CCR)) & ~0x0080;
  113. nimr = (imr = read_scoop_reg(scoop, SCOOP_IMR)) & ~0x003E;
  114. if ((machine_is_spitz() || machine_is_borzoi() || machine_is_akita()) && skt->nr == 0) {
  115. ncpr |= (state->Vcc == 33) ? 0x0002 :
  116. (state->Vcc == 50) ? 0x0002 : 0;
  117. } else {
  118. ncpr |= (state->Vcc == 33) ? 0x0001 :
  119. (state->Vcc == 50) ? 0x0002 : 0;
  120. }
  121. nmcr |= (state->flags&SS_IOCARD) ? 0x0010 : 0;
  122. ncpr |= (state->flags&SS_OUTPUT_ENA) ? 0x0080 : 0;
  123. nccr |= (state->flags&SS_RESET)? 0x0080: 0;
  124. nimr |= ((skt->status&SS_DETECT) ? 0x0004 : 0)|
  125. ((skt->status&SS_READY) ? 0x0002 : 0)|
  126. ((skt->status&SS_BATDEAD)? 0x0010 : 0)|
  127. ((skt->status&SS_BATWARN)? 0x0020 : 0)|
  128. ((skt->status&SS_STSCHG) ? 0x0010 : 0)|
  129. ((skt->status&SS_WRPROT) ? 0x0008 : 0);
  130. if (!(ncpr & 0x0003)) {
  131. SCOOP_DEV[skt->nr].keep_rd = 0;
  132. } else if (!SCOOP_DEV[skt->nr].keep_rd) {
  133. if (nccr & 0x0080)
  134. SCOOP_DEV[skt->nr].keep_rd = 1;
  135. else
  136. nccr |= 0x0080;
  137. }
  138. if (mcr != nmcr)
  139. write_scoop_reg(scoop, SCOOP_MCR, nmcr);
  140. if (cpr != ncpr) {
  141. if (platform_scoop_config->power_ctrl)
  142. platform_scoop_config->power_ctrl(scoop, ncpr , skt->nr);
  143. else
  144. write_scoop_reg(scoop, SCOOP_CPR, ncpr);
  145. }
  146. if (ccr != nccr)
  147. write_scoop_reg(scoop, SCOOP_CCR, nccr);
  148. if (imr != nimr)
  149. write_scoop_reg(scoop, SCOOP_IMR, nimr);
  150. local_irq_restore(flags);
  151. return 0;
  152. }
  153. static void sharpsl_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
  154. {
  155. sharpsl_pcmcia_init_reset(skt);
  156. /* Enable interrupt */
  157. write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_IMR, 0x00C0);
  158. write_scoop_reg(SCOOP_DEV[skt->nr].dev, SCOOP_MCR, 0x0101);
  159. SCOOP_DEV[skt->nr].keep_vs = NO_KEEP_VS;
  160. }
  161. static void sharpsl_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
  162. {
  163. sharpsl_pcmcia_init_reset(skt);
  164. }
  165. static struct pcmcia_low_level sharpsl_pcmcia_ops = {
  166. .owner = THIS_MODULE,
  167. .hw_init = sharpsl_pcmcia_hw_init,
  168. .socket_state = sharpsl_pcmcia_socket_state,
  169. .configure_socket = sharpsl_pcmcia_configure_socket,
  170. .socket_init = sharpsl_pcmcia_socket_init,
  171. .socket_suspend = sharpsl_pcmcia_socket_suspend,
  172. .first = 0,
  173. .nr = 0,
  174. };
  175. #ifdef CONFIG_SA1100_COLLIE
  176. #include "sa11xx_base.h"
  177. int pcmcia_collie_init(struct device *dev)
  178. {
  179. int ret = -ENODEV;
  180. if (machine_is_collie())
  181. ret = sa11xx_drv_pcmcia_probe(dev, &sharpsl_pcmcia_ops, 0, 1);
  182. return ret;
  183. }
  184. #else
  185. static struct platform_device *sharpsl_pcmcia_device;
  186. static int __init sharpsl_pcmcia_init(void)
  187. {
  188. int ret;
  189. if (!platform_scoop_config)
  190. return -ENODEV;
  191. sharpsl_pcmcia_ops.nr = platform_scoop_config->num_devs;
  192. sharpsl_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
  193. if (!sharpsl_pcmcia_device)
  194. return -ENOMEM;
  195. ret = platform_device_add_data(sharpsl_pcmcia_device,
  196. &sharpsl_pcmcia_ops, sizeof(sharpsl_pcmcia_ops));
  197. if (ret == 0) {
  198. sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
  199. ret = platform_device_add(sharpsl_pcmcia_device);
  200. }
  201. if (ret)
  202. platform_device_put(sharpsl_pcmcia_device);
  203. return ret;
  204. }
  205. static void __exit sharpsl_pcmcia_exit(void)
  206. {
  207. platform_device_unregister(sharpsl_pcmcia_device);
  208. }
  209. fs_initcall(sharpsl_pcmcia_init);
  210. module_exit(sharpsl_pcmcia_exit);
  211. #endif
  212. MODULE_DESCRIPTION("Sharp SL Series PCMCIA Support");
  213. MODULE_LICENSE("GPL");
  214. MODULE_ALIAS("platform:pxa2xx-pcmcia");