mcp-sa11x0.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 (!data->codec)
  124. return -ENODEV;
  125. if (!request_mem_region(0x80060000, 0x60, "sa11x0-mcp"))
  126. return -EBUSY;
  127. mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0));
  128. if (!mcp) {
  129. ret = -ENOMEM;
  130. goto release;
  131. }
  132. mcp->owner = THIS_MODULE;
  133. mcp->ops = &mcp_sa11x0;
  134. mcp->sclk_rate = data->sclk_rate;
  135. mcp->dma_audio_rd = DMA_Ser4MCP0Rd;
  136. mcp->dma_audio_wr = DMA_Ser4MCP0Wr;
  137. mcp->dma_telco_rd = DMA_Ser4MCP1Rd;
  138. mcp->dma_telco_wr = DMA_Ser4MCP1Wr;
  139. mcp->codec = data->codec;
  140. platform_set_drvdata(pdev, mcp);
  141. if (machine_is_assabet()) {
  142. ASSABET_BCR_set(ASSABET_BCR_CODEC_RST);
  143. }
  144. /*
  145. * Setup the PPC unit correctly.
  146. */
  147. PPDR &= ~PPC_RXD4;
  148. PPDR |= PPC_TXD4 | PPC_SCLK | PPC_SFRM;
  149. PSDR |= PPC_RXD4;
  150. PSDR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  151. PPSR &= ~(PPC_TXD4 | PPC_SCLK | PPC_SFRM);
  152. /*
  153. * Initialise device. Note that we initially
  154. * set the sampling rate to minimum.
  155. */
  156. Ser4MCSR = -1;
  157. Ser4MCCR1 = data->mccr1;
  158. Ser4MCCR0 = data->mccr0 | 0x7f7f;
  159. /*
  160. * Calculate the read/write timeout (us) from the bit clock
  161. * rate. This is the period for 3 64-bit frames. Always
  162. * round this time up.
  163. */
  164. mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
  165. mcp->sclk_rate;
  166. ret = mcp_host_register(mcp, data->codec_pdata);
  167. if (ret == 0)
  168. goto out;
  169. release:
  170. release_mem_region(0x80060000, 0x60);
  171. platform_set_drvdata(pdev, NULL);
  172. out:
  173. return ret;
  174. }
  175. static int mcp_sa11x0_remove(struct platform_device *dev)
  176. {
  177. struct mcp *mcp = platform_get_drvdata(dev);
  178. platform_set_drvdata(dev, NULL);
  179. mcp_host_unregister(mcp);
  180. release_mem_region(0x80060000, 0x60);
  181. return 0;
  182. }
  183. static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state)
  184. {
  185. struct mcp *mcp = platform_get_drvdata(dev);
  186. priv(mcp)->mccr0 = Ser4MCCR0;
  187. priv(mcp)->mccr1 = Ser4MCCR1;
  188. Ser4MCCR0 &= ~MCCR0_MCE;
  189. return 0;
  190. }
  191. static int mcp_sa11x0_resume(struct platform_device *dev)
  192. {
  193. struct mcp *mcp = platform_get_drvdata(dev);
  194. Ser4MCCR1 = priv(mcp)->mccr1;
  195. Ser4MCCR0 = priv(mcp)->mccr0;
  196. return 0;
  197. }
  198. /*
  199. * The driver for the SA11x0 MCP port.
  200. */
  201. MODULE_ALIAS("platform:sa11x0-mcp");
  202. static struct platform_driver mcp_sa11x0_driver = {
  203. .probe = mcp_sa11x0_probe,
  204. .remove = mcp_sa11x0_remove,
  205. .suspend = mcp_sa11x0_suspend,
  206. .resume = mcp_sa11x0_resume,
  207. .driver = {
  208. .name = "sa11x0-mcp",
  209. },
  210. };
  211. /*
  212. * This needs re-working
  213. */
  214. module_platform_driver(mcp_sa11x0_driver);
  215. MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
  216. MODULE_DESCRIPTION("SA11x0 multimedia communications port driver");
  217. MODULE_LICENSE("GPL");