cx23885-ioctl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #ifdef CONFIG_VIDEO_ADV_DEBUG
  26. int cx23885_g_chip_info(struct file *file, void *fh,
  27. struct v4l2_dbg_chip_info *chip)
  28. {
  29. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  30. if (chip->match.addr > 1)
  31. return -EINVAL;
  32. if (chip->match.addr == 1) {
  33. if (dev->v4l_device == NULL)
  34. return -EINVAL;
  35. strlcpy(chip->name, "cx23417", sizeof(chip->name));
  36. } else {
  37. strlcpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name));
  38. }
  39. return 0;
  40. }
  41. static int cx23417_g_register(struct cx23885_dev *dev,
  42. struct v4l2_dbg_register *reg)
  43. {
  44. u32 value;
  45. if (dev->v4l_device == NULL)
  46. return -EINVAL;
  47. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  48. return -EINVAL;
  49. if (mc417_register_read(dev, (u16) reg->reg, &value))
  50. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  51. reg->size = 4;
  52. reg->val = value;
  53. return 0;
  54. }
  55. int cx23885_g_register(struct file *file, void *fh,
  56. struct v4l2_dbg_register *reg)
  57. {
  58. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  59. if (reg->match.addr > 1)
  60. return -EINVAL;
  61. if (reg->match.addr)
  62. return cx23417_g_register(dev, reg);
  63. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  64. return -EINVAL;
  65. reg->size = 4;
  66. reg->val = cx_read(reg->reg);
  67. return 0;
  68. }
  69. static int cx23417_s_register(struct cx23885_dev *dev,
  70. const struct v4l2_dbg_register *reg)
  71. {
  72. if (dev->v4l_device == NULL)
  73. return -EINVAL;
  74. if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  75. return -EINVAL;
  76. if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
  77. return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  78. return 0;
  79. }
  80. int cx23885_s_register(struct file *file, void *fh,
  81. const struct v4l2_dbg_register *reg)
  82. {
  83. struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev;
  84. if (reg->match.addr > 1)
  85. return -EINVAL;
  86. if (reg->match.addr)
  87. return cx23417_s_register(dev, reg);
  88. if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  89. return -EINVAL;
  90. cx_write(reg->reg, reg->val);
  91. return 0;
  92. }
  93. #endif