cx23885-ioctl.c 2.7 KB

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