cx18-io.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * cx18 driver PCI memory mapped IO access routines
  3. *
  4. * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
  5. * Copyright (C) 2008 Andy Walls <awalls@radix.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  20. * 02111-1307 USA
  21. */
  22. #include "cx18-driver.h"
  23. #include "cx18-io.h"
  24. #include "cx18-irq.h"
  25. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  26. const void __iomem *from, unsigned int len)
  27. {
  28. /* Align reads on the CX23418's addresses */
  29. if ((len > 0) && ((unsigned)from & 1)) {
  30. *((u8 *)to) = cx18_readb(cx, from);
  31. len--;
  32. to++;
  33. from++;
  34. }
  35. if ((len > 1) && ((unsigned)from & 2)) {
  36. *((u16 *)to) = cx18_raw_readw(cx, from);
  37. len -= 2;
  38. to += 2;
  39. from += 2;
  40. }
  41. while (len > 3) {
  42. *((u32 *)to) = cx18_raw_readl(cx, from);
  43. len -= 4;
  44. to += 4;
  45. from += 4;
  46. }
  47. if (len > 1) {
  48. *((u16 *)to) = cx18_raw_readw(cx, from);
  49. len -= 2;
  50. to += 2;
  51. from += 2;
  52. }
  53. if (len > 0)
  54. *((u8 *)to) = cx18_readb(cx, from);
  55. }
  56. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count)
  57. {
  58. u16 val2 = val | (val << 8);
  59. u32 val4 = val2 | (val2 << 16);
  60. /* Align writes on the CX23418's addresses */
  61. if ((count > 0) && ((unsigned)addr & 1)) {
  62. cx18_writeb(cx, (u8) val, addr);
  63. count--;
  64. addr++;
  65. }
  66. if ((count > 1) && ((unsigned)addr & 2)) {
  67. cx18_writew(cx, val2, addr);
  68. count -= 2;
  69. addr += 2;
  70. }
  71. while (count > 3) {
  72. cx18_writel(cx, val4, addr);
  73. count -= 4;
  74. addr += 4;
  75. }
  76. if (count > 1) {
  77. cx18_writew(cx, val2, addr);
  78. count -= 2;
  79. addr += 2;
  80. }
  81. if (count > 0)
  82. cx18_writeb(cx, (u8) val, addr);
  83. }
  84. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val)
  85. {
  86. u32 r;
  87. cx18_write_reg(cx, val, SW1_INT_STATUS);
  88. r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
  89. cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI);
  90. }
  91. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val)
  92. {
  93. u32 r;
  94. r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
  95. cx18_write_reg(cx, r & ~val, SW1_INT_ENABLE_PCI);
  96. }
  97. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val)
  98. {
  99. u32 r;
  100. cx18_write_reg(cx, val, SW2_INT_STATUS);
  101. r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
  102. cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI);
  103. }
  104. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val)
  105. {
  106. u32 r;
  107. r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
  108. cx18_write_reg(cx, r & ~val, SW2_INT_ENABLE_PCI);
  109. }
  110. void cx18_setup_page(struct cx18 *cx, u32 addr)
  111. {
  112. u32 val;
  113. val = cx18_read_reg(cx, 0xD000F8);
  114. val = (val & ~0x1f00) | ((addr >> 17) & 0x1f00);
  115. cx18_write_reg(cx, val, 0xD000F8);
  116. }
  117. /* Tries to recover from the CX23418 responding improperly on the PCI bus */
  118. int cx18_pci_try_recover(struct cx18 *cx)
  119. {
  120. u16 status;
  121. pci_read_config_word(cx->dev, PCI_STATUS, &status);
  122. pci_write_config_word(cx->dev, PCI_STATUS, status);
  123. return 0;
  124. }