mcp-sa11x0.c 5.3 KB

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