mcp-sa11x0.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * linux/drivers/mfd/mcp-sa11x0.c
  3. *
  4. * Copyright (C) 2001-2005 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. *
  10. * SA11x0 MCP (Multimedia Communications Port) driver.
  11. *
  12. * MCP read/write timeouts from Jordi Colomer, rehacked by rmk.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/kernel.h>
  18. #include <linux/delay.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/mfd/mcp.h>
  22. #include <mach/dma.h>
  23. #include <mach/hardware.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/system.h>
  26. #include <mach/mcp.h>
  27. #include <mach/assabet.h>
  28. struct mcp_sa11x0 {
  29. u32 mccr0;
  30. u32 mccr1;
  31. };
  32. #define priv(mcp) ((struct mcp_sa11x0 *)mcp_priv(mcp))
  33. static void
  34. mcp_sa11x0_set_telecom_divisor(struct mcp *mcp, unsigned int divisor)
  35. {
  36. unsigned int mccr0;
  37. divisor /= 32;
  38. mccr0 = Ser4MCCR0 & ~0x00007f00;
  39. mccr0 |= divisor << 8;
  40. Ser4MCCR0 = mccr0;
  41. }
  42. static void
  43. mcp_sa11x0_set_audio_divisor(struct mcp *mcp, unsigned int divisor)
  44. {
  45. unsigned int mccr0;
  46. divisor /= 32;
  47. mccr0 = Ser4MCCR0 & ~0x0000007f;
  48. mccr0 |= divisor;
  49. Ser4MCCR0 = mccr0;
  50. }
  51. /*
  52. * Write data to the device. The bit should be set after 3 subframe
  53. * times (each frame is 64 clocks). We wait a maximum of 6 subframes.
  54. * We really should try doing something more productive while we
  55. * wait.
  56. */
  57. static void
  58. mcp_sa11x0_write(struct mcp *mcp, unsigned int reg, unsigned int val)
  59. {
  60. int ret = -ETIME;
  61. int i;
  62. Ser4MCDR2 = reg << 17 | MCDR2_Wr | (val & 0xffff);
  63. for (i = 0; i < 2; i++) {
  64. udelay(mcp->rw_timeout);
  65. if (Ser4MCSR & MCSR_CWC) {
  66. ret = 0;
  67. break;
  68. }
  69. }
  70. if (ret < 0)
  71. printk(KERN_WARNING "mcp: write timed out\n");
  72. }
  73. /*
  74. * Read data from the device. The bit should be set after 3 subframe
  75. * times (each frame is 64 clocks). We wait a maximum of 6 subframes.
  76. * We really should try doing something more productive while we
  77. * wait.
  78. */
  79. static unsigned int
  80. mcp_sa11x0_read(struct mcp *mcp, unsigned int reg)
  81. {
  82. int ret = -ETIME;
  83. int i;
  84. Ser4MCDR2 = reg << 17 | MCDR2_Rd;
  85. for (i = 0; i < 2; i++) {
  86. udelay(mcp->rw_timeout);
  87. if (Ser4MCSR & MCSR_CRC) {
  88. ret = Ser4MCDR2 & 0xffff;
  89. break;
  90. }
  91. }
  92. if (ret < 0)
  93. printk(KERN_WARNING "mcp: read timed out\n");
  94. return ret;
  95. }
  96. static void mcp_sa11x0_enable(struct mcp *mcp)
  97. {
  98. Ser4MCSR = -1;
  99. Ser4MCCR0 |= MCCR0_MCE;
  100. }
  101. static void mcp_sa11x0_disable(struct mcp *mcp)
  102. {
  103. Ser4MCCR0 &= ~MCCR0_MCE;
  104. }
  105. /*
  106. * Our methods.
  107. */
  108. static struct mcp_ops mcp_sa11x0 = {
  109. .set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
  110. .set_audio_divisor = mcp_sa11x0_set_audio_divisor,
  111. .reg_write = mcp_sa11x0_write,
  112. .reg_read = mcp_sa11x0_read,
  113. .enable = mcp_sa11x0_enable,
  114. .disable = mcp_sa11x0_disable,
  115. };
  116. static int mcp_sa11x0_probe(struct platform_device *pdev)
  117. {
  118. struct mcp_plat_data *data = pdev->dev.platform_data;
  119. struct mcp *mcp;
  120. int ret;
  121. if (!data)
  122. return -ENODEV;
  123. if (!request_mem_region(0x80060000, 0x60, "sa11x0-mcp"))
  124. return -EBUSY;
  125. mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0));
  126. if (!mcp) {
  127. ret = -ENOMEM;
  128. goto release;
  129. }
  130. mcp->owner = THIS_MODULE;
  131. mcp->ops = &mcp_sa11x0;
  132. mcp->sclk_rate = data->sclk_rate;
  133. mcp->dma_audio_rd = DMA_Ser4MCP0Rd;
  134. mcp->dma_audio_wr = DMA_Ser4MCP0Wr;
  135. mcp->dma_telco_rd = DMA_Ser4MCP1Rd;
  136. mcp->dma_telco_wr = DMA_Ser4MCP1Wr;
  137. mcp->gpio_base = data->gpio_base;
  138. platform_set_drvdata(pdev, mcp);
  139. if (machine_is_assabet()) {
  140. ASSABET_BCR_set(ASSABET_BCR_CODEC_RST);
  141. }
  142. /*
  143. * Setup the PPC unit correctly.
  144. */
  145. PPDR &= ~PPC_RXD4;
  146. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  147. PSDR |= PPC_RXD4;
  148. PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  149. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  150. /*
  151. * Initialise device. Note that we initially
  152. * set the sampling rate to minimum.
  153. */
  154. Ser4MCSR = -1;
  155. Ser4MCCR1 = data->mccr1;
  156. Ser4MCCR0 = data->mccr0 | 0x7f7f;
  157. /*
  158. * Calculate the read/write timeout (us) from the bit clock
  159. * rate. This is the period for 3 64-bit frames. Always
  160. * round this time up.
  161. */
  162. mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
  163. mcp->sclk_rate;
  164. ret = mcp_host_register(mcp);
  165. if (ret == 0)
  166. goto out;
  167. release:
  168. release_mem_region(0x80060000, 0x60);
  169. platform_set_drvdata(pdev, NULL);
  170. out:
  171. return ret;
  172. }
  173. static int mcp_sa11x0_remove(struct platform_device *dev)
  174. {
  175. struct mcp *mcp = platform_get_drvdata(dev);
  176. platform_set_drvdata(dev, NULL);
  177. mcp_host_unregister(mcp);
  178. release_mem_region(0x80060000, 0x60);
  179. return 0;
  180. }
  181. static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state)
  182. {
  183. struct mcp *mcp = platform_get_drvdata(dev);
  184. priv(mcp)->mccr0 = Ser4MCCR0;
  185. priv(mcp)->mccr1 = Ser4MCCR1;
  186. Ser4MCCR0 &= ~MCCR0_MCE;
  187. return 0;
  188. }
  189. static int mcp_sa11x0_resume(struct platform_device *dev)
  190. {
  191. struct mcp *mcp = platform_get_drvdata(dev);
  192. Ser4MCCR1 = priv(mcp)->mccr1;
  193. Ser4MCCR0 = priv(mcp)->mccr0;
  194. return 0;
  195. }
  196. /*
  197. * The driver for the SA11x0 MCP port.
  198. */
  199. MODULE_ALIAS("platform:sa11x0-mcp");
  200. static struct platform_driver mcp_sa11x0_driver = {
  201. .probe = mcp_sa11x0_probe,
  202. .remove = mcp_sa11x0_remove,
  203. .suspend = mcp_sa11x0_suspend,
  204. .resume = mcp_sa11x0_resume,
  205. .driver = {
  206. .name = "sa11x0-mcp",
  207. },
  208. };
  209. /*
  210. * This needs re-working
  211. */
  212. static int __init mcp_sa11x0_init(void)
  213. {
  214. return platform_driver_register(&mcp_sa11x0_driver);
  215. }
  216. static void __exit mcp_sa11x0_exit(void)
  217. {
  218. platform_driver_unregister(&mcp_sa11x0_driver);
  219. }
  220. module_init(mcp_sa11x0_init);
  221. module_exit(mcp_sa11x0_exit);
  222. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  223. MODULE_DESCRIPTION("SA11x0 multimedia communications port driver");
  224. MODULE_LICENSE("GPL");