mantis_core.c 5.3 KB

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