mantis_hif.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_hif.h"
  18. #include "mantis_link.h" /* temporary due to physical layer stuff */
  19. static int mantis_hif_data_available(struct mantis_ca *ca)
  20. {
  21. struct mantis_pci *mantis = ca->ca_priv;
  22. int rc = 0;
  23. if (wait_event_interruptible_timeout(ca->hif_data_wq,
  24. ca->sbuf_status & MANTIS_SBUF_DATA_AVAIL,
  25. msecs_to_jiffies(500)) == -ERESTARTSYS) {
  26. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Read wait event timeout !", mantis->num);
  27. rc = -EREMOTEIO;
  28. }
  29. ca->sbuf_status &= ~MANTIS_SBUF_DATA_AVAIL;
  30. udelay(2);
  31. return rc;
  32. }
  33. static int mantis_hif_sbuf_opdone_wait(struct mantis_ca *ca)
  34. {
  35. struct mantis_pci *mantis = ca->ca_priv;
  36. int rc = 0;
  37. if (wait_event_interruptible_timeout(ca->hif_opdone_wq,
  38. ca->hif_event & MANTIS_SBUF_OPDONE,
  39. msecs_to_jiffies(500)) == -ERESTARTSYS) {
  40. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): Smart buffer operation timeout !", mantis->num);
  41. rc = -EREMOTEIO;
  42. }
  43. dprintk(verbose, MANTIS_DEBUG, 1, "Smart Buffer Operation complete");
  44. ca->hif_event &= ~MANTIS_SBUF_OPDONE;
  45. udelay(5);
  46. return rc;
  47. }
  48. int mantis_hif_read_mem(struct mantis_ca *ca, u32 addr)
  49. {
  50. struct mantis_pci *mantis = ca->ca_priv;
  51. u32 hif_addr = 0, data, count = 4;
  52. dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Read", mantis->num);
  53. hif_addr |= MANTIS_GPIF_HIFRDWRN;
  54. hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
  55. hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
  56. hif_addr |= addr;
  57. mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_BRADDR);
  58. mmwrite(count, MANTIS_GPIF_BRBYTES);
  59. udelay(20);
  60. mmwrite(hif_addr, MANTIS_GPIF_ADDR);
  61. if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
  62. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): GPIF Smart Buffer operation failed", mantis->num);
  63. return -EREMOTEIO;
  64. }
  65. data = mmread(MANTIS_GPIF_DIN);
  66. dprintk(verbose, MANTIS_DEBUG, 1, "Mem Read: 0x%02x", data);
  67. return (data >> 24) & 0xff;
  68. }
  69. int mantis_hif_write_mem(struct mantis_ca *ca, u32 addr, u8 data)
  70. {
  71. struct mantis_slot *slot = ca->slot;
  72. struct mantis_pci *mantis = ca->ca_priv;
  73. u32 hif_addr = 0;
  74. dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF Mem Write", mantis->num);
  75. hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
  76. hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
  77. hif_addr &= ~MANTIS_GPIF_PCMCIAIOM;
  78. hif_addr |= addr;
  79. mmwrite(slot->slave_cfg, MANTIS_GPIF_CFGSLA); /* Slot0 alone for now */
  80. mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
  81. mmwrite(data, MANTIS_GPIF_DOUT);
  82. if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
  83. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
  84. return -EREMOTEIO;
  85. }
  86. dprintk(verbose, MANTIS_DEBUG, 1, "Mem Write: (0x%02x to 0x%02x)", data, addr);
  87. return 0;
  88. }
  89. int mantis_hif_read_iom(struct mantis_ca *ca, u32 addr)
  90. {
  91. struct mantis_pci *mantis = ca->ca_priv;
  92. u32 data, hif_addr = 0;
  93. dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Read", mantis->num);
  94. hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
  95. hif_addr |= MANTIS_GPIF_HIFRDWRN;
  96. hif_addr |= MANTIS_GPIF_PCMCIAIOM;
  97. hif_addr |= addr;
  98. mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
  99. if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
  100. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
  101. return -EREMOTEIO;
  102. }
  103. data = mmread(MANTIS_GPIF_DIN);
  104. dprintk(verbose, MANTIS_DEBUG, 1, "I/O Read: 0x%02x", data);
  105. udelay(50);
  106. return (u8) data;
  107. }
  108. int mantis_hif_write_iom(struct mantis_ca *ca, u32 addr, u8 data)
  109. {
  110. struct mantis_pci *mantis = ca->ca_priv;
  111. u32 hif_addr = 0;
  112. dprintk(verbose, MANTIS_DEBUG, 1, "Adapter(%d) Slot(0): Request HIF I/O Write", mantis->num);
  113. hif_addr &= ~MANTIS_GPIF_PCMCIAREG;
  114. hif_addr &= ~MANTIS_GPIF_HIFRDWRN;
  115. hif_addr |= MANTIS_GPIF_PCMCIAIOM;
  116. hif_addr |= addr;
  117. mmwrite(hif_addr | MANTIS_HIF_STATUS, MANTIS_GPIF_ADDR);
  118. mmwrite(data, MANTIS_GPIF_DOUT);
  119. if (mantis_hif_sbuf_opdone_wait(ca) != 0) {
  120. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Slot(0): HIF Smart Buffer operation failed", mantis->num);
  121. return -EREMOTEIO;
  122. }
  123. dprintk(verbose, MANTIS_DEBUG, 1, "I/O Write: (0x%02x to 0x%02x)", data, addr);
  124. udelay(50);
  125. return 0;
  126. }
  127. int mantis_hif_init(struct mantis_ca *ca)
  128. {
  129. struct mantis_slot *slot = ca->slot;
  130. struct mantis_pci *mantis = ca->ca_priv;
  131. u32 irqcfg;
  132. slot[0].slave_cfg = 0x70773028;
  133. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Initializing Mantis Host Interface", mantis->num);
  134. init_waitqueue_head(&ca->hif_data_wq);
  135. init_waitqueue_head(&ca->hif_opdone_wq);
  136. irqcfg = mmread(MANTIS_GPIF_IRQCFG);
  137. irqcfg = MANTIS_MASK_BRRDY |
  138. MANTIS_MASK_WRACK |
  139. MANTIS_MASK_EXTIRQ |
  140. MANTIS_MASK_WSTO |
  141. MANTIS_MASK_OTHERR |
  142. MANTIS_MASK_OVFLW;
  143. mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
  144. return 0;
  145. }
  146. void mantis_hif_exit(struct mantis_ca *ca)
  147. {
  148. struct mantis_pci *mantis = ca->ca_priv;
  149. u32 irqcfg;
  150. dprintk(verbose, MANTIS_ERROR, 1, "Adapter(%d) Exiting Mantis Host Interface", mantis->num);
  151. irqcfg = mmread(MANTIS_GPIF_IRQCFG);
  152. irqcfg &= ~MANTIS_MASK_BRRDY;
  153. mmwrite(irqcfg, MANTIS_GPIF_IRQCFG);
  154. }