cx23885-ioctl.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Driver for the Conexant CX23885/7/8 PCIe bridge
  3. *
  4. * Various common ioctl() support functions
  5. *
  6. * Copyright (c) 2009 Andy Walls <awalls@md.metrocast.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. *
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include "cx23885.h"
  24. #include <media/v4l2-chip-ident.h>
  25. int cx23885_g_chip_ident(struct file *file, void *fh,
  26. struct v4l2_dbg_chip_ident *chip)
  27. {
  28. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  29. int err = 0;
  30. u8 rev;
  31. chip->ident = V4L2_IDENT_NONE;
  32. chip->revision = 0;
  33. switch (chip->match.type) {
  34. case V4L2_CHIP_MATCH_HOST:
  35. switch (chip->match.addr) {
  36. case 0:
  37. rev = cx_read(RDR_CFG2) & 0xff;
  38. switch (dev->pci->device) {
  39. case 0x8852:
  40. /* rev 0x04 could be '885 or '888. Pick '888. */
  41. if (rev == 0x04)
  42. chip->ident = V4L2_IDENT_CX23888;
  43. else
  44. chip->ident = V4L2_IDENT_CX23885;
  45. break;
  46. case 0x8880:
  47. if (rev == 0x0e || rev == 0x0f)
  48. chip->ident = V4L2_IDENT_CX23887;
  49. else
  50. chip->ident = V4L2_IDENT_CX23888;
  51. break;
  52. default:
  53. chip->ident = V4L2_IDENT_UNKNOWN;
  54. break;
  55. }
  56. chip->revision = (dev->pci->device << 16) | (rev << 8) |
  57. (dev->hwrevision & 0xff);
  58. break;
  59. case 1:
  60. if (dev->v4l_device != NULL) {
  61. chip->ident = V4L2_IDENT_CX23417;
  62. chip->revision = 0;
  63. }
  64. break;
  65. case 2:
  66. /*
  67. * The integrated IR controller on the CX23888 is
  68. * host chip 2. It may not be used/initialized or sd_ir
  69. * may be pointing at the cx25840 subdevice for the
  70. * IR controller on the CX23885. Thus we find it
  71. * without using the dev->sd_ir pointer.
  72. */
  73. call_hw(dev, CX23885_HW_888_IR, core, g_chip_ident,
  74. chip);
  75. break;
  76. default:
  77. err = -EINVAL; /* per V4L2 spec */
  78. break;
  79. }
  80. break;
  81. case V4L2_CHIP_MATCH_I2C_DRIVER:
  82. /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
  83. call_all(dev, core, g_chip_ident, chip);
  84. break;
  85. case V4L2_CHIP_MATCH_I2C_ADDR:
  86. /*
  87. * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
  88. * to look if a chip is at the address with no driver. That's a
  89. * dangerous thing to do with EEPROMs anyway.
  90. */
  91. call_all(dev, core, g_chip_ident, chip);
  92. break;
  93. default:
  94. err = -EINVAL;
  95. break;
  96. }
  97. return err;
  98. }
  99. #ifdef CONFIG_VIDEO_ADV_DEBUG
  100. static int cx23885_g_host_register(struct cx23885_dev *dev,
  101. struct v4l2_dbg_register *reg)
  102. {
  103. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  104. return -EINVAL;
  105. reg->size = 4;
  106. reg->val = cx_read(reg->reg);
  107. return 0;
  108. }
  109. static int cx23417_g_register(struct cx23885_dev *dev,
  110. struct v4l2_dbg_register *reg)
  111. {
  112. u32 value;
  113. if (dev->v4l_device == NULL)
  114. return -EINVAL;
  115. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  116. return -EINVAL;
  117. if (mc417_register_read(dev, (u16) reg->reg, &value))
  118. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  119. reg->size = 4;
  120. reg->val = value;
  121. return 0;
  122. }
  123. int cx23885_g_register(struct file *file, void *fh,
  124. struct v4l2_dbg_register *reg)
  125. {
  126. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  127. if (!capable(CAP_SYS_ADMIN))
  128. return -EPERM;
  129. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  130. switch (reg->match.addr) {
  131. case 0:
  132. return cx23885_g_host_register(dev, reg);
  133. case 1:
  134. return cx23417_g_register(dev, reg);
  135. default:
  136. break;
  137. }
  138. }
  139. /* FIXME - any error returns should not be ignored */
  140. call_all(dev, core, g_register, reg);
  141. return 0;
  142. }
  143. static int cx23885_s_host_register(struct cx23885_dev *dev,
  144. struct v4l2_dbg_register *reg)
  145. {
  146. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  147. return -EINVAL;
  148. reg->size = 4;
  149. cx_write(reg->reg, reg->val);
  150. return 0;
  151. }
  152. static int cx23417_s_register(struct cx23885_dev *dev,
  153. struct v4l2_dbg_register *reg)
  154. {
  155. if (dev->v4l_device == NULL)
  156. return -EINVAL;
  157. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  158. return -EINVAL;
  159. if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
  160. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  161. reg->size = 4;
  162. return 0;
  163. }
  164. int cx23885_s_register(struct file *file, void *fh,
  165. struct v4l2_dbg_register *reg)
  166. {
  167. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  168. if (!capable(CAP_SYS_ADMIN))
  169. return -EPERM;
  170. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  171. switch (reg->match.addr) {
  172. case 0:
  173. return cx23885_s_host_register(dev, reg);
  174. case 1:
  175. return cx23417_s_register(dev, reg);
  176. default:
  177. break;
  178. }
  179. }
  180. /* FIXME - any error returns should not be ignored */
  181. call_all(dev, core, s_register, reg);
  182. return 0;
  183. }
  184. #endif