pt3.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Earthsoft PT3 driver
  3. *
  4. * Copyright (C) 2014 Akihiro Tsukada <tskd08@gmail.com>
  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 as
  8. * published by the Free Software Foundation version 2.
  9. *
  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. #ifndef PT3_H
  17. #define PT3_H
  18. #include <linux/atomic.h>
  19. #include <linux/types.h>
  20. #include "dvb_demux.h"
  21. #include "dvb_frontend.h"
  22. #include "dmxdev.h"
  23. #include "tc90522.h"
  24. #include "mxl301rf.h"
  25. #include "qm1d1c0042.h"
  26. #define DRV_NAME KBUILD_MODNAME
  27. #define PT3_NUM_FE 4
  28. /*
  29. * register index of the FPGA chip
  30. */
  31. #define REG_VERSION 0x00
  32. #define REG_BUS 0x04
  33. #define REG_SYSTEM_W 0x08
  34. #define REG_SYSTEM_R 0x0c
  35. #define REG_I2C_W 0x10
  36. #define REG_I2C_R 0x14
  37. #define REG_RAM_W 0x18
  38. #define REG_RAM_R 0x1c
  39. #define REG_DMA_BASE 0x40 /* regs for FE[i] = REG_DMA_BASE + 0x18 * i */
  40. #define OFST_DMA_DESC_L 0x00
  41. #define OFST_DMA_DESC_H 0x04
  42. #define OFST_DMA_CTL 0x08
  43. #define OFST_TS_CTL 0x0c
  44. #define OFST_STATUS 0x10
  45. #define OFST_TS_ERR 0x14
  46. /*
  47. * internal buffer for I2C
  48. */
  49. #define PT3_I2C_MAX 4091
  50. struct pt3_i2cbuf {
  51. u8 data[PT3_I2C_MAX];
  52. u8 tmp;
  53. u32 num_cmds;
  54. };
  55. /*
  56. * DMA things
  57. */
  58. #define TS_PACKET_SZ 188
  59. /* DMA transfers must not cross 4GiB, so use one page / transfer */
  60. #define DATA_XFER_SZ 4096
  61. #define DATA_BUF_XFERS 47
  62. /* (num_bufs * DATA_BUF_SZ) % TS_PACKET_SZ must be 0 */
  63. #define DATA_BUF_SZ (DATA_BUF_XFERS * DATA_XFER_SZ)
  64. #define MAX_DATA_BUFS 16
  65. #define MIN_DATA_BUFS 2
  66. #define DESCS_IN_PAGE (PAGE_SIZE / sizeof(struct xfer_desc))
  67. #define MAX_NUM_XFERS (MAX_DATA_BUFS * DATA_BUF_XFERS)
  68. #define MAX_DESC_BUFS DIV_ROUND_UP(MAX_NUM_XFERS, DESCS_IN_PAGE)
  69. /* DMA transfer description.
  70. * device is passed a pointer to this struct, dma-reads it,
  71. * and gets the DMA buffer ring for storing TS data.
  72. */
  73. struct xfer_desc {
  74. u32 addr_l; /* bus address of target data buffer */
  75. u32 addr_h;
  76. u32 size;
  77. u32 next_l; /* bus adddress of the next xfer_desc */
  78. u32 next_h;
  79. };
  80. /* A DMA mapping of a page containing xfer_desc's */
  81. struct xfer_desc_buffer {
  82. dma_addr_t b_addr;
  83. struct xfer_desc *descs; /* PAGE_SIZE (xfer_desc[DESCS_IN_PAGE]) */
  84. };
  85. /* A DMA mapping of a data buffer */
  86. struct dma_data_buffer {
  87. dma_addr_t b_addr;
  88. u8 *data; /* size: u8[PAGE_SIZE] */
  89. };
  90. /*
  91. * device things
  92. */
  93. struct pt3_adap_config {
  94. struct i2c_board_info demod_info;
  95. struct tc90522_config demod_cfg;
  96. struct i2c_board_info tuner_info;
  97. union tuner_config {
  98. struct qm1d1c0042_config qm1d1c0042;
  99. struct mxl301rf_config mxl301rf;
  100. } tuner_cfg;
  101. u32 init_freq;
  102. };
  103. struct pt3_adapter {
  104. struct dvb_adapter dvb_adap; /* dvb_adap.priv => struct pt3_board */
  105. int adap_idx;
  106. struct dvb_demux demux;
  107. struct dmxdev dmxdev;
  108. struct dvb_frontend *fe;
  109. struct i2c_client *i2c_demod;
  110. struct i2c_client *i2c_tuner;
  111. /* data fetch thread */
  112. struct task_struct *thread;
  113. int num_feeds;
  114. bool cur_lna;
  115. bool cur_lnb; /* current LNB power status (on/off) */
  116. /* items below are for DMA */
  117. struct dma_data_buffer buffer[MAX_DATA_BUFS];
  118. int buf_idx;
  119. int buf_ofs;
  120. int num_bufs; /* == pt3_board->num_bufs */
  121. int num_discard; /* how many access units to discard initially */
  122. struct xfer_desc_buffer desc_buf[MAX_DESC_BUFS];
  123. int num_desc_bufs; /* == num_bufs * DATA_BUF_XFERS / DESCS_IN_PAGE */
  124. };
  125. struct pt3_board {
  126. struct pci_dev *pdev;
  127. void __iomem *regs[2];
  128. /* regs[0]: registers, regs[1]: internal memory, used for I2C */
  129. struct mutex lock;
  130. /* LNB power shared among sat-FEs */
  131. int lnb_on_cnt; /* LNB power on count */
  132. /* LNA shared among terr-FEs */
  133. int lna_on_cnt; /* booster enabled count */
  134. int num_bufs; /* number of DMA buffers allocated/mapped per FE */
  135. struct i2c_adapter i2c_adap;
  136. struct pt3_i2cbuf *i2c_buf;
  137. struct pt3_adapter *adaps[PT3_NUM_FE];
  138. };
  139. /*
  140. * prototypes
  141. */
  142. extern int pt3_alloc_dmabuf(struct pt3_adapter *adap);
  143. extern void pt3_init_dmabuf(struct pt3_adapter *adap);
  144. extern void pt3_free_dmabuf(struct pt3_adapter *adap);
  145. extern int pt3_start_dma(struct pt3_adapter *adap);
  146. extern int pt3_stop_dma(struct pt3_adapter *adap);
  147. extern int pt3_proc_dma(struct pt3_adapter *adap);
  148. extern int pt3_i2c_master_xfer(struct i2c_adapter *adap,
  149. struct i2c_msg *msgs, int num);
  150. extern u32 pt3_i2c_functionality(struct i2c_adapter *adap);
  151. extern void pt3_i2c_reset(struct pt3_board *pt3);
  152. extern int pt3_init_all_demods(struct pt3_board *pt3);
  153. extern int pt3_init_all_mxl301rf(struct pt3_board *pt3);
  154. #endif /* PT3_H */