mantis_vp1033.c 3.9 KB

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