mantis_ioc.c 3.1 KB

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