raontv_port.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. *
  3. * File name: raontv_port.c
  4. *
  5. * Description : User-supplied Routines for RAONTECH TV Services.
  6. *
  7. * Copyright (C) (2014, RAONTECH)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation version 2.
  12. *
  13. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  14. * kind, whether express or implied; without even the implied warranty
  15. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #include <linux/spi/spi.h>
  20. #include "isdbt.h"
  21. #include "isdbt_port_mtv222.h"
  22. /* Declares a variable of gurad object if neccessry. */
  23. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  24. #if defined(__KERNEL__)
  25. struct mutex raontv_guard;
  26. #elif defined(WINCE)
  27. CRITICAL_SECTION raontv_guard;
  28. #else
  29. /* non-OS and RTOS. */
  30. #endif
  31. #endif
  32. void rtvOEM_ConfigureInterrupt(void)
  33. {
  34. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)
  35. RTV_REG_MAP_SEL(SPI_CTRL_PAGE);
  36. RTV_REG_SET(0x21, SPI_INTR_POL_ACTIVE|0x02);
  37. #ifdef RTV_IF_SPI
  38. RTV_REG_SET(0x27, 0x01); /* AUTO_INTR: 0, Recovery mode ON */
  39. #endif
  40. RTV_REG_SET(0x2B, RTV_SPI_INTR_DEACT_PRD_VAL);
  41. RTV_REG_SET(0x2A, 1); /* SRAM init */
  42. RTV_REG_SET(0x2A, 0);
  43. #endif
  44. }
  45. #if defined(RTV_IF_SPI)
  46. #define SPI_CMD_SIZE MTV222_SPI_CMD_SIZE
  47. static struct spi_device *mtv_spi;
  48. void mtv222_set_port_if(unsigned long interface)
  49. {
  50. mtv_spi = (struct spi_device *)interface;
  51. }
  52. unsigned char mtv222_spi_read(unsigned char page, unsigned char reg)
  53. {
  54. int ret;
  55. u8 out_buf[4], in_buf[4];
  56. struct spi_message msg;
  57. struct spi_transfer msg_xfer = {
  58. .tx_buf = out_buf,
  59. .rx_buf = in_buf,
  60. .len = 4,
  61. .cs_change = 0,
  62. .delay_usecs = 0
  63. };
  64. out_buf[0] = 0x90 | page;
  65. out_buf[1] = reg;
  66. out_buf[2] = 1; /* Read size */
  67. spi_message_init(&msg);
  68. spi_message_add_tail(&msg_xfer, &msg);
  69. ret = spi_sync(mtv_spi, &msg);
  70. if (ret) {
  71. DMBERR("error: %d\n", ret);
  72. return 0xFF;
  73. }
  74. #if 0
  75. DMBMSG("0x%02X 0x%02X 0x%02X 0x%02X\n",
  76. in_buf[0], in_buf[1], in_buf[2], in_buf[3]);
  77. #endif
  78. return in_buf[SPI_CMD_SIZE];
  79. }
  80. void mtv222_spi_read_burst(unsigned char page, unsigned char reg,
  81. unsigned char *buf, int size)
  82. {
  83. int ret;
  84. u8 out_buf[SPI_CMD_SIZE];
  85. struct spi_message msg;
  86. struct spi_transfer msg_xfer0 = {
  87. .tx_buf = out_buf,
  88. .rx_buf = buf,
  89. .len = SPI_CMD_SIZE,
  90. .cs_change = 0,
  91. .delay_usecs = 0
  92. };
  93. struct spi_transfer msg_xfer1 = {
  94. .tx_buf = buf,
  95. .rx_buf = buf,
  96. .len = size,
  97. .cs_change = 0,
  98. .delay_usecs = 0
  99. };
  100. if (page > 15) { /* 0 ~ 15: not SPI memory */
  101. out_buf[0] = 0xA0; /* Memory read */
  102. out_buf[1] = 0x00;
  103. out_buf[2] = 188; /* Fix */
  104. } else {
  105. out_buf[0] = 0x90 | page; /* Register read */
  106. out_buf[1] = reg;
  107. out_buf[2] = size;
  108. }
  109. spi_message_init(&msg);
  110. spi_message_add_tail(&msg_xfer0, &msg);
  111. spi_message_add_tail(&msg_xfer1, &msg);
  112. ret = spi_sync(mtv_spi, &msg);
  113. if (ret)
  114. DMBERR("1 error: %d\n", ret);
  115. }
  116. void mtv222_spi_write(unsigned char page, unsigned char reg, unsigned char val)
  117. {
  118. u8 out_buf[4];
  119. u8 in_buf[4];
  120. struct spi_message msg;
  121. struct spi_transfer msg_xfer = {
  122. .tx_buf = out_buf,
  123. .rx_buf = in_buf,
  124. .len = 4,
  125. .cs_change = 0,
  126. .delay_usecs = 0
  127. };
  128. int ret;
  129. out_buf[0] = 0x80 | page;
  130. out_buf[1] = reg;
  131. out_buf[2] = 1; /* size */
  132. out_buf[3] = val;
  133. spi_message_init(&msg);
  134. spi_message_add_tail(&msg_xfer, &msg);
  135. ret = spi_sync(mtv_spi, &msg);
  136. if (ret)
  137. DMBERR("error: %d\n", ret);
  138. }
  139. void mtv222_spi_recover(unsigned char *buf, unsigned int size)
  140. {
  141. int ret;
  142. struct spi_message msg;
  143. struct spi_transfer msg_xfer = {
  144. .tx_buf = buf,
  145. .rx_buf = buf,
  146. .len = size,
  147. .cs_change = 0,
  148. .delay_usecs = 0,
  149. };
  150. memset(buf, 0xFF, size);
  151. spi_message_init(&msg);
  152. spi_message_add_tail(&msg_xfer, &msg);
  153. ret = spi_sync(mtv_spi, &msg);
  154. if (ret)
  155. DMBERR("error: %d\n", ret);
  156. }
  157. #endif /* #if defined(RTV_IF_SPI) */