mtv319_port.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. *
  3. * File name: mtv319_port.c
  4. *
  5. * Description : User-supplied Routines for RAONTECH TV Services.
  6. *
  7. * Copyright (C) (2013, 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 "mtv319.h"
  21. #include "mtv319_internal.h"
  22. #include "tdmb.h"
  23. /* Declares a variable of gurad object if neccessry. */
  24. #if defined(RTV_IF_SPI) || defined(RTV_IF_EBI2)\
  25. || defined(RTV_FIC_I2C_INTR_ENABLED)
  26. #if defined(__KERNEL__)
  27. struct mutex raontv_guard;
  28. #elif defined(WINCE) || defined(WINDOWS) || defined(WIN32)
  29. CRITICAL_SECTION raontv_guard;
  30. #else
  31. /* non-OS and RTOS. */
  32. #endif
  33. #endif
  34. #if defined(RTV_IF_SPI)
  35. static struct spi_device *mtv_spi;
  36. void mtv319_set_port_if(unsigned long interface)
  37. {
  38. mtv_spi = (struct spi_device *)interface;
  39. }
  40. unsigned char mtv319_spi_read(unsigned char page, unsigned char reg)
  41. {
  42. int ret;
  43. u8 out_buf[4], in_buf[4];
  44. struct spi_message msg;
  45. struct spi_transfer msg_xfer = {
  46. .tx_buf = out_buf,
  47. .rx_buf = in_buf,
  48. .len = 4,
  49. .cs_change = 0,
  50. .delay_usecs = 0
  51. };
  52. out_buf[0] = 0x90 | page;
  53. out_buf[1] = reg;
  54. out_buf[2] = 1; /* Read size */
  55. spi_message_init(&msg);
  56. spi_message_add_tail(&msg_xfer, &msg);
  57. ret = spi_sync(mtv_spi, &msg);
  58. if (ret) {
  59. DPRINTK("error: %d\n", ret);
  60. return 0xFF;
  61. }
  62. #if 0
  63. DPRINTK("0x%02X 0x%02X 0x%02X 0x%02X\n",
  64. in_buf[0], in_buf[1], in_buf[2], in_buf[3]);
  65. #endif
  66. return in_buf[MTV319_SPI_CMD_SIZE];
  67. }
  68. void mtv319_spi_read_burst(unsigned char page, unsigned char reg,
  69. unsigned char *buf, int size)
  70. {
  71. int ret;
  72. u8 out_buf[MTV319_SPI_CMD_SIZE];
  73. struct spi_message msg;
  74. struct spi_transfer xfer0 = {
  75. .tx_buf = out_buf,
  76. .rx_buf = buf,
  77. .len = MTV319_SPI_CMD_SIZE,
  78. .cs_change = 0,
  79. .delay_usecs = 0
  80. };
  81. struct spi_transfer xfer1 = {
  82. .tx_buf = buf,
  83. .rx_buf = buf,
  84. .len = size,
  85. .cs_change = 0,
  86. .delay_usecs = 0,
  87. };
  88. out_buf[0] = 0xA0; /* Memory read */
  89. out_buf[1] = 0x00;
  90. out_buf[2] = 188; /* Fix */
  91. spi_message_init(&msg);
  92. spi_message_add_tail(&xfer0, &msg);
  93. spi_message_add_tail(&xfer1, &msg);
  94. ret = spi_sync(mtv_spi, &msg);
  95. if (ret) {
  96. DPRINTK("error: %d\n", ret);
  97. return;
  98. }
  99. }
  100. void mtv319_spi_write(unsigned char page, unsigned char reg, unsigned char val)
  101. {
  102. u8 out_buf[4];
  103. u8 in_buf[4];
  104. struct spi_message msg;
  105. struct spi_transfer msg_xfer = {
  106. .tx_buf = out_buf,
  107. .rx_buf = in_buf,
  108. .len = 4,
  109. .cs_change = 0,
  110. .delay_usecs = 0
  111. };
  112. int ret;
  113. out_buf[0] = 0x80 | page;
  114. out_buf[1] = reg;
  115. out_buf[2] = 1; /* size */
  116. out_buf[3] = val;
  117. spi_message_init(&msg);
  118. spi_message_add_tail(&msg_xfer, &msg);
  119. ret = spi_sync(mtv_spi, &msg);
  120. if (ret)
  121. DPRINTK("error: %d\n", ret);
  122. }
  123. void mtv319_spi_recover(unsigned char *buf, unsigned int intr_size)
  124. {
  125. int ret;
  126. struct spi_message msg;
  127. struct spi_transfer msg_xfer = {
  128. .tx_buf = buf,
  129. .rx_buf = buf,
  130. .len = MTV319_SPI_CMD_SIZE + intr_size,
  131. .cs_change = 0,
  132. .delay_usecs = 0,
  133. };
  134. memset(buf, 0xFF, MTV319_SPI_CMD_SIZE+intr_size);
  135. spi_message_init(&msg);
  136. spi_message_add_tail(&msg_xfer, &msg);
  137. ret = spi_sync(mtv_spi, &msg);
  138. if (ret)
  139. DPRINTK("error: %d\n", ret);
  140. }
  141. #endif