mantis_core.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. Mantis PCI bridge 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 "mantis_common.h"
  17. #include "mantis_core.h"
  18. #include "mantis_vp1033.h"
  19. #include "mantis_vp1034.h"
  20. #include "mantis_vp1041.h"
  21. #include "mantis_vp2033.h"
  22. #include "mantis_vp2040.h"
  23. #include "mantis_vp3030.h"
  24. static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
  25. {
  26. int err;
  27. struct i2c_msg msg[] = {
  28. {
  29. .addr = 0x50,
  30. .flags = 0,
  31. .buf = data,
  32. .len = 1
  33. }, {
  34. .addr = 0x50,
  35. .flags = I2C_M_RD,
  36. .buf = data,
  37. .len = length
  38. },
  39. };
  40. err = i2c_transfer(&mantis->adapter, msg, 2);
  41. if (err < 0) {
  42. dprintk(verbose, MANTIS_ERROR, 1,
  43. "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
  44. err, data[0], data[1]);
  45. return err;
  46. }
  47. return 0;
  48. }
  49. static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
  50. {
  51. int err;
  52. struct i2c_msg msg = {
  53. .addr = 0x50,
  54. .flags = 0,
  55. .buf = data,
  56. .len = length
  57. };
  58. err = i2c_transfer(&mantis->adapter, &msg, 1);
  59. if (err < 0) {
  60. dprintk(verbose, MANTIS_ERROR, 1,
  61. "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
  62. err, length, data[0], data[1]);
  63. return err;
  64. }
  65. return 0;
  66. }
  67. static int get_mac_address(struct mantis_pci *mantis)
  68. {
  69. int err;
  70. mantis->mac_address[0] = 0x08;
  71. err = read_eeprom_byte(mantis, &mantis->mac_address[0], 6);
  72. if (err < 0) {
  73. dprintk(verbose, MANTIS_ERROR, 1, "Mantis EEPROM read error");
  74. return err;
  75. }
  76. dprintk(verbose, MANTIS_ERROR, 0,
  77. " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
  78. mantis->mac_address[0], mantis->mac_address[1],
  79. mantis->mac_address[2], mantis->mac_address[3],
  80. mantis->mac_address[4], mantis->mac_address[5]);
  81. return 0;
  82. }
  83. #define MANTIS_MODEL_UNKNOWN "UNKNOWN"
  84. #define MANTIS_DEV_UNKNOWN "UNKNOWN"
  85. struct mantis_hwconfig unknown_device = {
  86. .model_name = MANTIS_MODEL_UNKNOWN,
  87. .dev_type = MANTIS_DEV_UNKNOWN,
  88. };
  89. static void mantis_load_config(struct mantis_pci *mantis)
  90. {
  91. switch (mantis->subsystem_device) {
  92. case MANTIS_VP_1033_DVB_S: /* VP-1033 */
  93. mantis->hwconfig = &vp1033_mantis_config;
  94. break;
  95. case MANTIS_VP_1034_DVB_S: /* VP-1034 */
  96. mantis->hwconfig = &vp1034_mantis_config;
  97. break;
  98. case MANTIS_VP_1041_DVB_S2: /* VP-1041 */
  99. case TECHNISAT_SKYSTAR_HD2:
  100. mantis->hwconfig = &vp1041_mantis_config;
  101. break;
  102. case MANTIS_VP_2033_DVB_C: /* VP-2033 */
  103. mantis->hwconfig = &vp2033_mantis_config;
  104. break;
  105. case MANTIS_VP_2040_DVB_C: /* VP-2040 */
  106. case TERRATEC_CINERGY_C_PCI: /* VP-2040 clone */
  107. case TECHNISAT_CABLESTAR_HD2:
  108. mantis->hwconfig = &vp2040_mantis_config;
  109. break;
  110. case MANTIS_VP_3030_DVB_T: /* VP-3030 */
  111. mantis->hwconfig = &vp3030_mantis_config;
  112. break;
  113. default:
  114. mantis->hwconfig = &unknown_device;
  115. break;
  116. }
  117. }
  118. int mantis_core_init(struct mantis_pci *mantis)
  119. {
  120. int err = 0;
  121. mantis_load_config(mantis);
  122. dprintk(verbose, MANTIS_ERROR, 0, "found a %s PCI %s device on (%02x:%02x.%x),\n",
  123. mantis->hwconfig->model_name, mantis->hwconfig->dev_type,
  124. mantis->pdev->bus->number, PCI_SLOT(mantis->pdev->devfn), PCI_FUNC(mantis->pdev->devfn));
  125. dprintk(verbose, MANTIS_ERROR, 0, " Mantis Rev %d [%04x:%04x], ",
  126. mantis->revision,
  127. mantis->subsystem_vendor, mantis->subsystem_device);
  128. dprintk(verbose, MANTIS_ERROR, 0,
  129. "irq: %d, latency: %d\n memory: 0x%lx, mmio: 0x%p\n",
  130. mantis->pdev->irq, mantis->latency,
  131. mantis->mantis_addr, mantis->mantis_mmio);
  132. err = mantis_i2c_init(mantis);
  133. if (err < 0) {
  134. dprintk(verbose, MANTIS_ERROR, 1, "Mantis I2C init failed");
  135. return err;
  136. }
  137. err = get_mac_address(mantis);
  138. if (err < 0) {
  139. dprintk(verbose, MANTIS_ERROR, 1, "get MAC address failed");
  140. return err;
  141. }
  142. err = mantis_dma_init(mantis);
  143. if (err < 0) {
  144. dprintk(verbose, MANTIS_ERROR, 1, "Mantis DMA init failed");
  145. return err;
  146. }
  147. err = mantis_dvb_init(mantis);
  148. if (err < 0) {
  149. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis DVB init failed");
  150. return err;
  151. }
  152. err = mantis_uart_init(mantis);
  153. if (err < 0) {
  154. dprintk(verbose, MANTIS_DEBUG, 1, "Mantis UART init failed");
  155. return err;
  156. }
  157. return 0;
  158. }
  159. int mantis_core_exit(struct mantis_pci *mantis)
  160. {
  161. mantis_dma_stop(mantis);
  162. dprintk(verbose, MANTIS_ERROR, 1, "DMA engine stopping");
  163. mantis_uart_exit(mantis);
  164. dprintk(verbose, MANTIS_ERROR, 1, "UART exit failed");
  165. if (mantis_dma_exit(mantis) < 0)
  166. dprintk(verbose, MANTIS_ERROR, 1, "DMA exit failed");
  167. if (mantis_dvb_exit(mantis) < 0)
  168. dprintk(verbose, MANTIS_ERROR, 1, "DVB exit failed");
  169. if (mantis_i2c_exit(mantis) < 0)
  170. dprintk(verbose, MANTIS_ERROR, 1, "I2C adapter delete.. failed");
  171. return 0;
  172. }
  173. /* Turn the given bit on or off. */
  174. void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
  175. {
  176. u32 cur;
  177. cur = mmread(MANTIS_GPIF_ADDR);
  178. if (value)
  179. mantis->gpio_status = cur | (1 << bitpos);
  180. else
  181. mantis->gpio_status = cur & (~(1 << bitpos));
  182. mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
  183. mmwrite(0x00, MANTIS_GPIF_DOUT);
  184. udelay(100);
  185. }
  186. /* direction = 0 , no CI passthrough ; 1 , CI passthrough */
  187. void mantis_set_direction(struct mantis_pci *mantis, int direction)
  188. {
  189. u32 reg;
  190. reg = mmread(0x28);
  191. dprintk(verbose, MANTIS_DEBUG, 1, "TS direction setup");
  192. if (direction == 0x01) {
  193. /* to CI */
  194. reg |= 0x04;
  195. mmwrite(reg, 0x28);
  196. reg &= 0xff - 0x04;
  197. mmwrite(reg, 0x28);
  198. } else {
  199. reg &= 0xff - 0x04;
  200. mmwrite(reg, 0x28);
  201. reg |= 0x04;
  202. mmwrite(reg, 0x28);
  203. }
  204. }