cx18-av-firmware.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * cx18 ADEC firmware functions
  3. *
  4. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  5. * Copyright (C) 2008 Andy Walls <awalls@radix.net>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20. * 02110-1301, USA.
  21. */
  22. #include "cx18-driver.h"
  23. #include "cx18-io.h"
  24. #include <linux/firmware.h>
  25. #define CX18_AUDIO_ENABLE 0xc72014
  26. #define FWFILE "v4l-cx23418-dig.fw"
  27. int cx18_av_loadfw(struct cx18 *cx)
  28. {
  29. struct v4l2_subdev *sd = &cx->av_state.sd;
  30. const struct firmware *fw = NULL;
  31. u32 size;
  32. u32 v;
  33. const u8 *ptr;
  34. int i;
  35. int retries1 = 0;
  36. if (request_firmware(&fw, FWFILE, &cx->pci_dev->dev) != 0) {
  37. CX18_ERR_DEV(sd, "unable to open firmware %s\n", FWFILE);
  38. return -EINVAL;
  39. }
  40. /* The firmware load often has byte errors, so allow for several
  41. retries, both at byte level and at the firmware load level. */
  42. while (retries1 < 5) {
  43. cx18_av_write4_expect(cx, CXADEC_CHIP_CTRL, 0x00010000,
  44. 0x00008430, 0xffffffff); /* cx25843 */
  45. cx18_av_write_expect(cx, CXADEC_STD_DET_CTL, 0xf6, 0xf6, 0xff);
  46. /* Reset the Mako core, Register is alias of CXADEC_CHIP_CTRL */
  47. cx18_av_write4_expect(cx, 0x8100, 0x00010000,
  48. 0x00008430, 0xffffffff); /* cx25843 */
  49. /* Put the 8051 in reset and enable firmware upload */
  50. cx18_av_write4_noretry(cx, CXADEC_DL_CTL, 0x0F000000);
  51. ptr = fw->data;
  52. size = fw->size;
  53. for (i = 0; i < size; i++) {
  54. u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16);
  55. u32 value = 0;
  56. int retries2;
  57. int unrec_err = 0;
  58. for (retries2 = 0; retries2 < CX18_MAX_MMIO_WR_RETRIES;
  59. retries2++) {
  60. cx18_av_write4_noretry(cx, CXADEC_DL_CTL,
  61. dl_control);
  62. udelay(10);
  63. value = cx18_av_read4(cx, CXADEC_DL_CTL);
  64. if (value == dl_control)
  65. break;
  66. /* Check if we can correct the byte by changing
  67. the address. We can only write the lower
  68. address byte of the address. */
  69. if ((value & 0x3F00) != (dl_control & 0x3F00)) {
  70. unrec_err = 1;
  71. break;
  72. }
  73. }
  74. if (unrec_err || retries2 >= CX18_MAX_MMIO_WR_RETRIES)
  75. break;
  76. }
  77. if (i == size)
  78. break;
  79. retries1++;
  80. }
  81. if (retries1 >= 5) {
  82. CX18_ERR_DEV(sd, "unable to load firmware %s\n", FWFILE);
  83. release_firmware(fw);
  84. return -EIO;
  85. }
  86. cx18_av_write4_expect(cx, CXADEC_DL_CTL,
  87. 0x13000000 | fw->size, 0x13000000, 0x13000000);
  88. /* Output to the 416 */
  89. cx18_av_and_or4(cx, CXADEC_PIN_CTRL1, ~0, 0x78000);
  90. /* Audio input control 1 set to Sony mode */
  91. /* Audio output input 2 is 0 for slave operation input */
  92. /* 0xC4000914[5]: 0 = left sample on WS=0, 1 = left sample on WS=1 */
  93. /* 0xC4000914[7]: 0 = Philips mode, 1 = Sony mode (1st SCK rising edge
  94. after WS transition for first bit of audio word. */
  95. cx18_av_write4(cx, CXADEC_I2S_IN_CTL, 0x000000A0);
  96. /* Audio output control 1 is set to Sony mode */
  97. /* Audio output control 2 is set to 1 for master mode */
  98. /* 0xC4000918[5]: 0 = left sample on WS=0, 1 = left sample on WS=1 */
  99. /* 0xC4000918[7]: 0 = Philips mode, 1 = Sony mode (1st SCK rising edge
  100. after WS transition for first bit of audio word. */
  101. /* 0xC4000918[8]: 0 = slave operation, 1 = master (SCK_OUT and WS_OUT
  102. are generated) */
  103. cx18_av_write4(cx, CXADEC_I2S_OUT_CTL, 0x000001A0);
  104. /* set alt I2s master clock to /0x16 and enable alt divider i2s
  105. passthrough */
  106. cx18_av_write4(cx, CXADEC_PIN_CFG3, 0x5600B687);
  107. cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, 0x000000F6, 0x000000F6,
  108. 0x3F00FFFF);
  109. /* CxDevWrReg(CXADEC_STD_DET_CTL, 0x000000FF); */
  110. /* Set bit 0 in register 0x9CC to signify that this is MiniMe. */
  111. /* Register 0x09CC is defined by the Merlin firmware, and doesn't
  112. have a name in the spec. */
  113. cx18_av_write4(cx, 0x09CC, 1);
  114. v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
  115. /* If bit 11 is 1, clear bit 10 */
  116. if (v & 0x800)
  117. cx18_write_reg_expect(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE,
  118. 0, 0x400);
  119. /* Enable WW auto audio standard detection */
  120. v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
  121. v |= 0xFF; /* Auto by default */
  122. v |= 0x400; /* Stereo by default */
  123. v |= 0x14000000;
  124. cx18_av_write4_expect(cx, CXADEC_STD_DET_CTL, v, v, 0x3F00FFFF);
  125. release_firmware(fw);
  126. CX18_INFO_DEV(sd, "loaded %s firmware (%d bytes)\n", FWFILE, size);
  127. return 0;
  128. }