cx18-av-firmware.c 4.2 KB

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