mantis_vp1033.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. Mantis VP-1033 driver
  3. Copyright (C) Manu Abraham (abraham.manu@gmail.com)
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <linux/signal.h>
  17. #include <linux/sched.h>
  18. #include <linux/interrupt.h>
  19. #include "dmxdev.h"
  20. #include "dvbdev.h"
  21. #include "dvb_demux.h"
  22. #include "dvb_frontend.h"
  23. #include "dvb_net.h"
  24. #include "stv0299.h"
  25. #include "mantis_common.h"
  26. #include "mantis_ioc.h"
  27. #include "mantis_dvb.h"
  28. #include "mantis_vp1033.h"
  29. #include "mantis_reg.h"
  30. static u8 lgtdqcs001f_inittab[] = {
  31. 0x01, 0x15,
  32. 0x02, 0x30,
  33. 0x03, 0x00,
  34. 0x04, 0x2a,
  35. 0x05, 0x85,
  36. 0x06, 0x02,
  37. 0x07, 0x00,
  38. 0x08, 0x00,
  39. 0x0c, 0x01,
  40. 0x0d, 0x81,
  41. 0x0e, 0x44,
  42. 0x0f, 0x94,
  43. 0x10, 0x3c,
  44. 0x11, 0x84,
  45. 0x12, 0xb9,
  46. 0x13, 0xb5,
  47. 0x14, 0x4f,
  48. 0x15, 0xc9,
  49. 0x16, 0x80,
  50. 0x17, 0x36,
  51. 0x18, 0xfb,
  52. 0x19, 0xcf,
  53. 0x1a, 0xbc,
  54. 0x1c, 0x2b,
  55. 0x1d, 0x27,
  56. 0x1e, 0x00,
  57. 0x1f, 0x0b,
  58. 0x20, 0xa1,
  59. 0x21, 0x60,
  60. 0x22, 0x00,
  61. 0x23, 0x00,
  62. 0x28, 0x00,
  63. 0x29, 0x28,
  64. 0x2a, 0x14,
  65. 0x2b, 0x0f,
  66. 0x2c, 0x09,
  67. 0x2d, 0x05,
  68. 0x31, 0x1f,
  69. 0x32, 0x19,
  70. 0x33, 0xfc,
  71. 0x34, 0x13,
  72. 0xff, 0xff,
  73. };
  74. #define MANTIS_MODEL_NAME "VP-1033"
  75. #define MANTIS_DEV_TYPE "DVB-S/DSS"
  76. static int lgtdqcs001f_tuner_set(struct dvb_frontend *fe)
  77. {
  78. struct dtv_frontend_properties *p = &fe->dtv_property_cache;
  79. struct mantis_pci *mantis = fe->dvb->priv;
  80. struct i2c_adapter *adapter = &mantis->adapter;
  81. u8 buf[4];
  82. u32 div;
  83. struct i2c_msg msg = {.addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf)};
  84. div = p->frequency / 250;
  85. buf[0] = (div >> 8) & 0x7f;
  86. buf[1] = div & 0xff;
  87. buf[2] = 0x83;
  88. buf[3] = 0xc0;
  89. if (p->frequency < 1531000)
  90. buf[3] |= 0x04;
  91. else
  92. buf[3] &= ~0x04;
  93. if (i2c_transfer(adapter, &msg, 1) < 0) {
  94. dprintk(MANTIS_ERROR, 1, "Write: I2C Transfer failed");
  95. return -EIO;
  96. }
  97. msleep_interruptible(100);
  98. return 0;
  99. }
  100. static int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe,
  101. u32 srate, u32 ratio)
  102. {
  103. u8 aclk = 0;
  104. u8 bclk = 0;
  105. if (srate < 1500000) {
  106. aclk = 0xb7;
  107. bclk = 0x47;
  108. } else if (srate < 3000000) {
  109. aclk = 0xb7;
  110. bclk = 0x4b;
  111. } else if (srate < 7000000) {
  112. aclk = 0xb7;
  113. bclk = 0x4f;
  114. } else if (srate < 14000000) {
  115. aclk = 0xb7;
  116. bclk = 0x53;
  117. } else if (srate < 30000000) {
  118. aclk = 0xb6;
  119. bclk = 0x53;
  120. } else if (srate < 45000000) {
  121. aclk = 0xb4;
  122. bclk = 0x51;
  123. }
  124. stv0299_writereg(fe, 0x13, aclk);
  125. stv0299_writereg(fe, 0x14, bclk);
  126. stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
  127. stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
  128. stv0299_writereg(fe, 0x21, ratio & 0xf0);
  129. return 0;
  130. }
  131. static struct stv0299_config lgtdqcs001f_config = {
  132. .demod_address = 0x68,
  133. .inittab = lgtdqcs001f_inittab,
  134. .mclk = 88000000UL,
  135. .invert = 0,
  136. .skip_reinit = 0,
  137. .volt13_op0_op1 = STV0299_VOLT13_OP0,
  138. .min_delay_ms = 100,
  139. .set_symbol_rate = lgtdqcs001f_set_symbol_rate,
  140. };
  141. static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
  142. {
  143. struct i2c_adapter *adapter = &mantis->adapter;
  144. int err = 0;
  145. err = mantis_frontend_power(mantis, POWER_ON);
  146. if (err == 0) {
  147. mantis_frontend_soft_reset(mantis);
  148. msleep(250);
  149. dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
  150. fe = dvb_attach(stv0299_attach, &lgtdqcs001f_config, adapter);
  151. if (fe) {
  152. fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
  153. dprintk(MANTIS_ERROR, 1, "found STV0299 DVB-S frontend @ 0x%02x",
  154. lgtdqcs001f_config.demod_address);
  155. dprintk(MANTIS_ERROR, 1, "Mantis DVB-S STV0299 frontend attach success");
  156. } else {
  157. return -1;
  158. }
  159. } else {
  160. dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
  161. adapter->name,
  162. err);
  163. return -EIO;
  164. }
  165. mantis->fe = fe;
  166. dprintk(MANTIS_ERROR, 1, "Done!");
  167. return 0;
  168. }
  169. struct mantis_hwconfig vp1033_config = {
  170. .model_name = MANTIS_MODEL_NAME,
  171. .dev_type = MANTIS_DEV_TYPE,
  172. .ts_size = MANTIS_TS_204,
  173. .baud_rate = MANTIS_BAUD_9600,
  174. .parity = MANTIS_PARITY_NONE,
  175. .bytes = 0,
  176. .frontend_init = vp1033_frontend_init,
  177. .power = GPIF_A12,
  178. .reset = GPIF_A13,
  179. };