mantis_ioc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, " MAC Address=[%pM]\n", mac_addr);
  56. return 0;
  57. }
  58. EXPORT_SYMBOL_GPL(mantis_get_mac);
  59. /* Turn the given bit on or off. */
  60. void mantis_gpio_set_bits(struct mantis_pci *mantis, u32 bitpos, u8 value)
  61. {
  62. u32 cur;
  63. dprintk(MANTIS_DEBUG, 1, "Set Bit <%d> to <%d>", bitpos, value);
  64. cur = mmread(MANTIS_GPIF_ADDR);
  65. if (value)
  66. mantis->gpio_status = cur | (1 << bitpos);
  67. else
  68. mantis->gpio_status = cur & (~(1 << bitpos));
  69. dprintk(MANTIS_DEBUG, 1, "GPIO Value <%02x>", mantis->gpio_status);
  70. mmwrite(mantis->gpio_status, MANTIS_GPIF_ADDR);
  71. mmwrite(0x00, MANTIS_GPIF_DOUT);
  72. }
  73. EXPORT_SYMBOL_GPL(mantis_gpio_set_bits);
  74. int mantis_stream_control(struct mantis_pci *mantis, enum mantis_stream_control stream_ctl)
  75. {
  76. u32 reg;
  77. reg = mmread(MANTIS_CONTROL);
  78. switch (stream_ctl) {
  79. case STREAM_TO_HIF:
  80. dprintk(MANTIS_DEBUG, 1, "Set stream to HIF");
  81. reg &= 0xff - MANTIS_BYPASS;
  82. mmwrite(reg, MANTIS_CONTROL);
  83. reg |= MANTIS_BYPASS;
  84. mmwrite(reg, MANTIS_CONTROL);
  85. break;
  86. case STREAM_TO_CAM:
  87. dprintk(MANTIS_DEBUG, 1, "Set stream to CAM");
  88. reg |= MANTIS_BYPASS;
  89. mmwrite(reg, MANTIS_CONTROL);
  90. reg &= 0xff - MANTIS_BYPASS;
  91. mmwrite(reg, MANTIS_CONTROL);
  92. break;
  93. default:
  94. dprintk(MANTIS_ERROR, 1, "Unknown MODE <%02x>", stream_ctl);
  95. return -1;
  96. }
  97. return 0;
  98. }
  99. EXPORT_SYMBOL_GPL(mantis_stream_control);