mantis_ioc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 <linux/kernel.h>
  17. #include <linux/i2c.h>
  18. #include <linux/signal.h>
  19. #include <linux/sched.h>
  20. #include <linux/interrupt.h>
  21. #include "dmxdev.h"
  22. #include "dvbdev.h"
  23. #include "dvb_demux.h"
  24. #include "dvb_frontend.h"
  25. #include "dvb_net.h"
  26. #include "mantis_common.h"
  27. #include "mantis_reg.h"
  28. #include "mantis_ioc.h"
  29. static int read_eeprom_bytes(struct mantis_pci *mantis, u8 reg, u8 *data, u8 length)
  30. {
  31. struct i2c_adapter *adapter = &mantis->adapter;
  32. int err;
  33. u8 buf = reg;
  34. struct i2c_msg msg[] = {
  35. { .addr = 0x50, .flags = 0, .buf = &buf, .len = 1 },
  36. { .addr = 0x50, .flags = I2C_M_RD, .buf = data, .len = length },
  37. };
  38. err = i2c_transfer(adapter, msg, 2);
  39. if (err < 0) {
  40. dprintk(MANTIS_ERROR, 1, "ERROR: i2c read: < err=%i d0=0x%02x d1=0x%02x >",
  41. err, data[0], data[1]);
  42. return err;
  43. }
  44. return 0;
  45. }
  46. int mantis_get_mac(struct mantis_pci *mantis)
  47. {
  48. int err;
  49. u8 mac_addr[6] = {0};
  50. err = read_eeprom_bytes(mantis, 0x08, mac_addr, 6);
  51. if (err < 0) {
  52. dprintk(MANTIS_ERROR, 1, "ERROR: Mantis EEPROM read error <%d>", err);
  53. return err;
  54. }
  55. dprintk(MANTIS_ERROR, 0,
  56. " MAC Address=[%02x:%02x:%02x:%02x:%02x:%02x]\n",
  57. mac_addr[0],
  58. mac_addr[1],
  59. mac_addr[2],
  60. mac_addr[3],
  61. mac_addr[4],
  62. mac_addr[5]);
  63. return 0;
  64. }
  65. EXPORT_SYMBOL_GPL(mantis_get_mac);
  66. /* Turn the given bit on or off. */
  67. void gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
  68. {
  69. u32 cur;
  70. dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value);
  71. cur = mmread(MANTIS_GPIF_ADDR);
  72. if (value)
  73. mantis->gpio_status = cur | (1 << bitpos);
  74. else
  75. mantis->gpio_status = cur & (~(1 << bitpos));
  76. dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status);
  77. mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
  78. mmwrite(0x00, MANTIS_GPIF_DOUT);
  79. }
  80. EXPORT_SYMBOL_GPL(gpio_set_bits);
  81. int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)
  82. {
  83. u32 reg;
  84. reg = mmread(MANTIS_CONTROL);
  85. switch (stream_ctl) {
  86. case STREAM_TO_HIF:
  87. dprintk(MANTIS_DEBUG, 1, "Set stream to HIF");
  88. reg &= 0xff - MANTIS_BYPASS;
  89. mmwrite(reg, MANTIS_CONTROL);
  90. reg |= MANTIS_BYPASS;
  91. mmwrite(reg, MANTIS_CONTROL);
  92. break;
  93. case STREAM_TO_CAM:
  94. dprintk(MANTIS_DEBUG, 1, "Set stream to CAM");
  95. reg |= MANTIS_BYPASS;
  96. mmwrite(reg, MANTIS_CONTROL);
  97. reg &= 0xff - MANTIS_BYPASS;
  98. mmwrite(reg, MANTIS_CONTROL);
  99. break;
  100. default:
  101. dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl);
  102. return -1;
  103. }
  104. return 0;
  105. }
  106. EXPORT_SYMBOL_GPL(mantis_stream_control);