mantis_ioc.c 2.5 KB

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