cx23885-ioctl.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 "cx23885-ioctl.h"
  25. #include <media/v4l2-chip-ident.h>
  26. int cx23885_g_chip_ident(struct file *file, void *fh,
  27. struct v4l2_dbg_chip_ident *chip)
  28. {
  29. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  30. int err = 0;
  31. u8 rev;
  32. chip->ident = V4L2_IDENT_NONE;
  33. chip->revision = 0;
  34. switch (chip->match.type) {
  35. case V4L2_CHIP_MATCH_HOST:
  36. switch (chip->match.addr) {
  37. case 0:
  38. rev = cx_read(RDR_CFG2) & 0xff;
  39. switch (dev->pci->device) {
  40. case 0x8852:
  41. /* rev 0x04 could be '885 or '888. Pick '888. */
  42. if (rev == 0x04)
  43. chip->ident = V4L2_IDENT_CX23888;
  44. else
  45. chip->ident = V4L2_IDENT_CX23885;
  46. break;
  47. case 0x8880:
  48. if (rev == 0x0e || rev == 0x0f)
  49. chip->ident = V4L2_IDENT_CX23887;
  50. else
  51. chip->ident = V4L2_IDENT_CX23888;
  52. break;
  53. default:
  54. chip->ident = V4L2_IDENT_UNKNOWN;
  55. break;
  56. }
  57. chip->revision = (dev->pci->device << 16) | (rev << 8) |
  58. (dev->hwrevision & 0xff);
  59. break;
  60. case 1:
  61. if (dev->v4l_device != NULL) {
  62. chip->ident = V4L2_IDENT_CX23417;
  63. chip->revision = 0;
  64. }
  65. break;
  66. case 2:
  67. /*
  68. * The integrated IR controller on the CX23888 is
  69. * host chip 2. It may not be used/initialized or sd_ir
  70. * may be pointing at the cx25840 subdevice for the
  71. * IR controller on the CX23885. Thus we find it
  72. * without using the dev->sd_ir pointer.
  73. */
  74. call_hw(dev, CX23885_HW_888_IR, core, g_chip_ident,
  75. chip);
  76. break;
  77. default:
  78. err = -EINVAL; /* per V4L2 spec */
  79. break;
  80. }
  81. break;
  82. case V4L2_CHIP_MATCH_I2C_DRIVER:
  83. /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
  84. call_all(dev, core, g_chip_ident, chip);
  85. break;
  86. case V4L2_CHIP_MATCH_I2C_ADDR:
  87. /*
  88. * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
  89. * to look if a chip is at the address with no driver. That's a
  90. * dangerous thing to do with EEPROMs anyway.
  91. */
  92. call_all(dev, core, g_chip_ident, chip);
  93. break;
  94. default:
  95. err = -EINVAL;
  96. break;
  97. }
  98. return err;
  99. }
  100. #ifdef CONFIG_VIDEO_ADV_DEBUG
  101. static int cx23885_g_host_register(struct cx23885_dev *dev,
  102. struct v4l2_dbg_register *reg)
  103. {
  104. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  105. return -EINVAL;
  106. reg->size = 4;
  107. reg->val = cx_read(reg->reg);
  108. return 0;
  109. }
  110. static int cx23417_g_register(struct cx23885_dev *dev,
  111. struct v4l2_dbg_register *reg)
  112. {
  113. u32 value;
  114. if (dev->v4l_device == NULL)
  115. return -EINVAL;
  116. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  117. return -EINVAL;
  118. if (mc417_register_read(dev, (u16) reg->reg, &value))
  119. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  120. reg->size = 4;
  121. reg->val = value;
  122. return 0;
  123. }
  124. int cx23885_g_register(struct file *file, void *fh,
  125. struct v4l2_dbg_register *reg)
  126. {
  127. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  128. if (!capable(CAP_SYS_ADMIN))
  129. return -EPERM;
  130. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  131. switch (reg->match.addr) {
  132. case 0:
  133. return cx23885_g_host_register(dev, reg);
  134. case 1:
  135. return cx23417_g_register(dev, reg);
  136. default:
  137. break;
  138. }
  139. }
  140. /* FIXME - any error returns should not be ignored */
  141. call_all(dev, core, g_register, reg);
  142. return 0;
  143. }
  144. static int cx23885_s_host_register(struct cx23885_dev *dev,
  145. struct v4l2_dbg_register *reg)
  146. {
  147. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  148. return -EINVAL;
  149. reg->size = 4;
  150. cx_write(reg->reg, reg->val);
  151. return 0;
  152. }
  153. static int cx23417_s_register(struct cx23885_dev *dev,
  154. struct v4l2_dbg_register *reg)
  155. {
  156. if (dev->v4l_device == NULL)
  157. return -EINVAL;
  158. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  159. return -EINVAL;
  160. if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
  161. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  162. reg->size = 4;
  163. return 0;
  164. }
  165. int cx23885_s_register(struct file *file, void *fh,
  166. struct v4l2_dbg_register *reg)
  167. {
  168. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  169. if (!capable(CAP_SYS_ADMIN))
  170. return -EPERM;
  171. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  172. switch (reg->match.addr) {
  173. case 0:
  174. return cx23885_s_host_register(dev, reg);
  175. case 1:
  176. return cx23417_s_register(dev, reg);
  177. default:
  178. break;
  179. }
  180. }
  181. /* FIXME - any error returns should not be ignored */
  182. call_all(dev, core, s_register, reg);
  183. return 0;
  184. }
  185. #endif