Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Conexant CX23885/7/8 PCIe bridge |
| 3 | * |
| 4 | * Various common ioctl() support functions |
| 5 | * |
Andy Walls | 6afdeaf | 2010-05-23 18:53:35 -0300 | [diff] [blame] | 6 | * Copyright (c) 2009 Andy Walls <awalls@md.metrocast.net> |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 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 | |
| 24 | #include "cx23885.h" |
Mauro Carvalho Chehab | ada73ee | 2012-10-27 11:29:23 -0300 | [diff] [blame] | 25 | #include "cx23885-ioctl.h" |
| 26 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 27 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 28 | int cx23885_g_chip_info(struct file *file, void *fh, |
| 29 | struct v4l2_dbg_chip_info *chip) |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 30 | { |
| 31 | struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 32 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 33 | if (chip->match.addr > 1) |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 34 | return -EINVAL; |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 35 | if (chip->match.addr == 1) { |
| 36 | if (dev->v4l_device == NULL) |
| 37 | return -EINVAL; |
| 38 | strlcpy(chip->name, "cx23417", sizeof(chip->name)); |
| 39 | } else { |
| 40 | strlcpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name)); |
| 41 | } |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int cx23417_g_register(struct cx23885_dev *dev, |
| 46 | struct v4l2_dbg_register *reg) |
| 47 | { |
| 48 | u32 value; |
| 49 | |
| 50 | if (dev->v4l_device == NULL) |
| 51 | return -EINVAL; |
| 52 | |
| 53 | if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000) |
| 54 | return -EINVAL; |
| 55 | |
| 56 | if (mc417_register_read(dev, (u16) reg->reg, &value)) |
| 57 | return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */ |
| 58 | |
| 59 | reg->size = 4; |
| 60 | reg->val = value; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int cx23885_g_register(struct file *file, void *fh, |
| 65 | struct v4l2_dbg_register *reg) |
| 66 | { |
| 67 | struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; |
| 68 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 69 | if (reg->match.addr > 1) |
| 70 | return -EINVAL; |
| 71 | if (reg->match.addr) |
| 72 | return cx23417_g_register(dev, reg); |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 73 | |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 74 | if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) |
| 75 | return -EINVAL; |
| 76 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 77 | reg->size = 4; |
| 78 | reg->val = cx_read(reg->reg); |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int cx23417_s_register(struct cx23885_dev *dev, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 83 | const struct v4l2_dbg_register *reg) |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 84 | { |
| 85 | if (dev->v4l_device == NULL) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000) |
| 89 | return -EINVAL; |
| 90 | |
| 91 | if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val)) |
| 92 | return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */ |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | int cx23885_s_register(struct file *file, void *fh, |
Hans Verkuil | 977ba3b | 2013-03-24 08:28:46 -0300 | [diff] [blame] | 97 | const struct v4l2_dbg_register *reg) |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 98 | { |
| 99 | struct cx23885_dev *dev = ((struct cx23885_fh *)fh)->dev; |
| 100 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 101 | if (reg->match.addr > 1) |
| 102 | return -EINVAL; |
| 103 | if (reg->match.addr) |
| 104 | return cx23417_s_register(dev, reg); |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 105 | |
Hans Verkuil | 80f8568 | 2013-05-29 06:59:39 -0300 | [diff] [blame] | 106 | if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) |
| 107 | return -EINVAL; |
| 108 | |
| 109 | cx_write(reg->reg, reg->val); |
Andy Walls | 7461824 | 2009-09-26 22:50:44 -0300 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | #endif |