cx23885-ioctl.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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@radix.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. default:
  66. err = -EINVAL; /* per V4L2 spec */
  67. break;
  68. }
  69. break;
  70. case V4L2_CHIP_MATCH_I2C_DRIVER:
  71. /* If needed, returns V4L2_IDENT_AMBIGUOUS without extra work */
  72. call_all(dev, core, g_chip_ident, chip);
  73. break;
  74. case V4L2_CHIP_MATCH_I2C_ADDR:
  75. /*
  76. * We could return V4L2_IDENT_UNKNOWN, but we don't do the work
  77. * to look if a chip is at the address with no driver. That's a
  78. * dangerous thing to do with EEPROMs anyway.
  79. */
  80. call_all(dev, core, g_chip_ident, chip);
  81. break;
  82. default:
  83. err = -EINVAL;
  84. break;
  85. }
  86. return err;
  87. }
  88. #ifdef CONFIG_VIDEO_ADV_DEBUG
  89. static int cx23885_g_host_register(struct cx23885_dev *dev,
  90. struct v4l2_dbg_register *reg)
  91. {
  92. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  93. return -EINVAL;
  94. reg->size = 4;
  95. reg->val = cx_read(reg->reg);
  96. return 0;
  97. }
  98. static int cx23417_g_register(struct cx23885_dev *dev,
  99. struct v4l2_dbg_register *reg)
  100. {
  101. u32 value;
  102. if (dev->v4l_device == NULL)
  103. return -EINVAL;
  104. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  105. return -EINVAL;
  106. if (mc417_register_read(dev, (u16) reg->reg, &value))
  107. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  108. reg->size = 4;
  109. reg->val = value;
  110. return 0;
  111. }
  112. int cx23885_g_register(struct file *file, void *fh,
  113. struct v4l2_dbg_register *reg)
  114. {
  115. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  116. if (!capable(CAP_SYS_ADMIN))
  117. return -EPERM;
  118. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  119. switch (reg->match.addr) {
  120. case 0:
  121. return cx23885_g_host_register(dev, reg);
  122. case 1:
  123. return cx23417_g_register(dev, reg);
  124. default:
  125. break;
  126. }
  127. }
  128. /* FIXME - any error returns should not be ignored */
  129. call_all(dev, core, g_register, reg);
  130. return 0;
  131. }
  132. static int cx23885_s_host_register(struct cx23885_dev *dev,
  133. struct v4l2_dbg_register *reg)
  134. {
  135. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  136. return -EINVAL;
  137. reg->size = 4;
  138. cx_write(reg->reg, reg->val);
  139. return 0;
  140. }
  141. static int cx23417_s_register(struct cx23885_dev *dev,
  142. struct v4l2_dbg_register *reg)
  143. {
  144. if (dev->v4l_device == NULL)
  145. return -EINVAL;
  146. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  147. return -EINVAL;
  148. if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
  149. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  150. reg->size = 4;
  151. return 0;
  152. }
  153. int cx23885_s_register(struct file *file, void *fh,
  154. struct v4l2_dbg_register *reg)
  155. {
  156. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  157. if (!capable(CAP_SYS_ADMIN))
  158. return -EPERM;
  159. if (reg->match.type == V4L2_CHIP_MATCH_HOST) {
  160. switch (reg->match.addr) {
  161. case 0:
  162. return cx23885_s_host_register(dev, reg);
  163. case 1:
  164. return cx23417_s_register(dev, reg);
  165. default:
  166. break;
  167. }
  168. }
  169. /* FIXME - any error returns should not be ignored */
  170. call_all(dev, core, s_register, reg);
  171. return 0;
  172. }
  173. #endif