linux/drivers/media/pci/cx23885/cx23885-ioctl.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*
   3 *  Driver for the Conexant CX23885/7/8 PCIe bridge
   4 *
   5 *  Various common ioctl() support functions
   6 *
   7 *  Copyright (c) 2009 Andy Walls <awalls@md.metrocast.net>
   8 */
   9
  10#include "cx23885.h"
  11#include "cx23885-ioctl.h"
  12
  13#ifdef CONFIG_VIDEO_ADV_DEBUG
  14int cx23885_g_chip_info(struct file *file, void *fh,
  15                         struct v4l2_dbg_chip_info *chip)
  16{
  17        struct cx23885_dev *dev = video_drvdata(file);
  18
  19        if (chip->match.addr > 1)
  20                return -EINVAL;
  21        if (chip->match.addr == 1) {
  22                if (dev->v4l_device == NULL)
  23                        return -EINVAL;
  24                strscpy(chip->name, "cx23417", sizeof(chip->name));
  25        } else {
  26                strscpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name));
  27        }
  28        return 0;
  29}
  30
  31static int cx23417_g_register(struct cx23885_dev *dev,
  32                              struct v4l2_dbg_register *reg)
  33{
  34        u32 value;
  35
  36        if (dev->v4l_device == NULL)
  37                return -EINVAL;
  38
  39        if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  40                return -EINVAL;
  41
  42        if (mc417_register_read(dev, (u16) reg->reg, &value))
  43                return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  44
  45        reg->size = 4;
  46        reg->val = value;
  47        return 0;
  48}
  49
  50int cx23885_g_register(struct file *file, void *fh,
  51                       struct v4l2_dbg_register *reg)
  52{
  53        struct cx23885_dev *dev = video_drvdata(file);
  54
  55        if (reg->match.addr > 1)
  56                return -EINVAL;
  57        if (reg->match.addr)
  58                return cx23417_g_register(dev, reg);
  59
  60        if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  61                return -EINVAL;
  62
  63        reg->size = 4;
  64        reg->val = cx_read(reg->reg);
  65        return 0;
  66}
  67
  68static int cx23417_s_register(struct cx23885_dev *dev,
  69                              const struct v4l2_dbg_register *reg)
  70{
  71        if (dev->v4l_device == NULL)
  72                return -EINVAL;
  73
  74        if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000)
  75                return -EINVAL;
  76
  77        if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val))
  78                return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */
  79        return 0;
  80}
  81
  82int cx23885_s_register(struct file *file, void *fh,
  83                       const struct v4l2_dbg_register *reg)
  84{
  85        struct cx23885_dev *dev = video_drvdata(file);
  86
  87        if (reg->match.addr > 1)
  88                return -EINVAL;
  89        if (reg->match.addr)
  90                return cx23417_s_register(dev, reg);
  91
  92        if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0))
  93                return -EINVAL;
  94
  95        cx_write(reg->reg, reg->val);
  96        return 0;
  97}
  98#endif
  99