mcp-sa11x0.c 5.4 KB

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