174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls/* 274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * Driver for the Conexant CX23885/7/8 PCIe bridge 374618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * 474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * Various common ioctl() support functions 574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * 66afdeaf865b729287e02aafc61d8d013b89996efAndy Walls * Copyright (c) 2009 Andy Walls <awalls@md.metrocast.net> 774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * 874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * This program is free software; you can redistribute it and/or modify 974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * it under the terms of the GNU General Public License as published by 1074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * the Free Software Foundation; either version 2 of the License, or 1174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * (at your option) any later version. 1274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * 1374618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * This program is distributed in the hope that it will be useful, 1474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * but WITHOUT ANY WARRANTY; without even the implied warranty of 1574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * 1774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls * GNU General Public License for more details. 1874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls */ 1974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 2074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls#include "cx23885.h" 21ada73eee1246768d5ec6f1e3b8882a5dd0456266Mauro Carvalho Chehab#include "cx23885-ioctl.h" 22ada73eee1246768d5ec6f1e3b8882a5dd0456266Mauro Carvalho Chehab 2380f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil#ifdef CONFIG_VIDEO_ADV_DEBUG 2480f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuilint cx23885_g_chip_info(struct file *file, void *fh, 2580f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil struct v4l2_dbg_chip_info *chip) 2674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls{ 27568f44a18e9b63fbb44fcb3292c3530087ae527bHans Verkuil struct cx23885_dev *dev = video_drvdata(file); 2874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 2980f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (chip->match.addr > 1) 3074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 3180f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (chip->match.addr == 1) { 3280f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (dev->v4l_device == NULL) 3380f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return -EINVAL; 3480f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil strlcpy(chip->name, "cx23417", sizeof(chip->name)); 3580f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil } else { 3680f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil strlcpy(chip->name, dev->v4l2_dev.name, sizeof(chip->name)); 3780f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil } 3874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return 0; 3974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls} 4074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 4174618244003a5a9e11240af8c5795ae747d9a2e0Andy Wallsstatic int cx23417_g_register(struct cx23885_dev *dev, 4274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls struct v4l2_dbg_register *reg) 4374618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls{ 4474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls u32 value; 4574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 4674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if (dev->v4l_device == NULL) 4774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 4874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 4974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000) 5074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 5174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 5274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if (mc417_register_read(dev, (u16) reg->reg, &value)) 5374618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */ 5474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 5574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls reg->size = 4; 5674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls reg->val = value; 5774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return 0; 5874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls} 5974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 6074618244003a5a9e11240af8c5795ae747d9a2e0Andy Wallsint cx23885_g_register(struct file *file, void *fh, 6174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls struct v4l2_dbg_register *reg) 6274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls{ 63568f44a18e9b63fbb44fcb3292c3530087ae527bHans Verkuil struct cx23885_dev *dev = video_drvdata(file); 6474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 6580f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (reg->match.addr > 1) 6680f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return -EINVAL; 6780f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (reg->match.addr) 6880f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return cx23417_g_register(dev, reg); 6974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 7074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) 7174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 7274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 7380f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil reg->size = 4; 7480f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil reg->val = cx_read(reg->reg); 7574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return 0; 7674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls} 7774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 7874618244003a5a9e11240af8c5795ae747d9a2e0Andy Wallsstatic int cx23417_s_register(struct cx23885_dev *dev, 79977ba3b1b73f24fae2d0c8bd59d7a4696f1e0cccHans Verkuil const struct v4l2_dbg_register *reg) 8074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls{ 8174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if (dev->v4l_device == NULL) 8274618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 8374618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 8474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if ((reg->reg & 0x3) != 0 || reg->reg >= 0x10000) 8574618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; 8674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 8774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls if (mc417_register_write(dev, (u16) reg->reg, (u32) reg->val)) 8874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return -EINVAL; /* V4L2 spec, but -EREMOTEIO really */ 8974618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return 0; 9074618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls} 9174618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 9274618244003a5a9e11240af8c5795ae747d9a2e0Andy Wallsint cx23885_s_register(struct file *file, void *fh, 93977ba3b1b73f24fae2d0c8bd59d7a4696f1e0cccHans Verkuil const struct v4l2_dbg_register *reg) 9474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls{ 95568f44a18e9b63fbb44fcb3292c3530087ae527bHans Verkuil struct cx23885_dev *dev = video_drvdata(file); 9674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 9780f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (reg->match.addr > 1) 9880f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return -EINVAL; 9980f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if (reg->match.addr) 10080f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return cx23417_s_register(dev, reg); 10180f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil 10280f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil if ((reg->reg & 0x3) != 0 || reg->reg >= pci_resource_len(dev->pci, 0)) 10380f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil return -EINVAL; 10474618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls 10580f8568f47306dc4453bb6630ac607f22ca4c7b4Hans Verkuil cx_write(reg->reg, reg->val); 10674618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls return 0; 10774618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls} 10874618244003a5a9e11240af8c5795ae747d9a2e0Andy Walls#endif 109