cx18-io.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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-irq.h"
  24. void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  25. {
  26. __raw_writel(val, addr);
  27. }
  28. u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
  29. {
  30. return __raw_readl(addr);
  31. }
  32. u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
  33. {
  34. writel(val, addr);
  35. return readl(addr);
  36. }
  37. void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
  38. {
  39. writel(val, addr);
  40. }
  41. u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
  42. {
  43. return readl(addr);
  44. }
  45. /* Access "register" region of CX23418 memory mapped I/O */
  46. u32 cx18_read_reg(struct cx18 *cx, u32 reg)
  47. {
  48. return readl(cx->reg_mem + reg);
  49. }
  50. void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
  51. {
  52. writel(val, cx->reg_mem + reg);
  53. }
  54. u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
  55. {
  56. return cx18_write_sync(cx, val, cx->reg_mem + reg);
  57. }
  58. /* Access "encoder memory" region of CX23418 memory mapped I/O */
  59. u32 cx18_read_enc(struct cx18 *cx, u32 addr)
  60. {
  61. return readl(cx->enc_mem + addr);
  62. }
  63. void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
  64. {
  65. writel(val, cx->enc_mem + addr);
  66. }
  67. u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
  68. {
  69. return cx18_write_sync(cx, val, cx->enc_mem + addr);
  70. }
  71. void cx18_memcpy_fromio(struct cx18 *cx, void *to,
  72. const void __iomem *from, unsigned int len)
  73. {
  74. memcpy_fromio(to, from, len);
  75. }
  76. void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count)
  77. {
  78. memset_io(addr, val, count);
  79. }
  80. void cx18_sw1_irq_enable(struct cx18 *cx, u32 val)
  81. {
  82. u32 r;
  83. cx18_write_reg(cx, val, SW1_INT_STATUS);
  84. r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
  85. cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI);
  86. }
  87. void cx18_sw1_irq_disable(struct cx18 *cx, u32 val)
  88. {
  89. u32 r;
  90. r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
  91. cx18_write_reg(cx, r & ~val, SW1_INT_ENABLE_PCI);
  92. }
  93. void cx18_sw2_irq_enable(struct cx18 *cx, u32 val)
  94. {
  95. u32 r;
  96. cx18_write_reg(cx, val, SW2_INT_STATUS);
  97. r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
  98. cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI);
  99. }
  100. void cx18_sw2_irq_disable(struct cx18 *cx, u32 val)
  101. {
  102. u32 r;
  103. r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
  104. cx18_write_reg(cx, r & ~val, SW2_INT_ENABLE_PCI);
  105. }
  106. void cx18_setup_page(struct cx18 *cx, u32 addr)
  107. {
  108. u32 val;
  109. val = cx18_read_reg(cx, 0xD000F8);
  110. val = (val & ~0x1f00) | ((addr >> 17) & 0x1f00);
  111. cx18_write_reg(cx, val, 0xD000F8);
  112. }
  113. /* Tries to recover from the CX23418 responding improperly on the PCI bus */
  114. int cx18_pci_try_recover(struct cx18 *cx)
  115. {
  116. u16 status;
  117. pci_read_config_word(cx->dev, PCI_STATUS, &status);
  118. pci_write_config_word(cx->dev, PCI_STATUS, status);
  119. return 0;
  120. }