From 0edc4afbcf59e4156e06f9e91f72c8fc47ceb856 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sat, 7 Aug 2010 06:27:16 -0300 Subject: V4L/DVB: v4l: add new YUV mediabus formats Needed for tvp7002 and tvp514x drivers. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-mediabus.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h index f0cf2e7def06..9b44aa5527ee 100644 --- a/include/media/v4l2-mediabus.h +++ b/include/media/v4l2-mediabus.h @@ -28,6 +28,10 @@ enum v4l2_mbus_pixelcode { V4L2_MBUS_FMT_YVYU8_2X8, V4L2_MBUS_FMT_UYVY8_2X8, V4L2_MBUS_FMT_VYUY8_2X8, + V4L2_MBUS_FMT_YVYU10_2X10, + V4L2_MBUS_FMT_YUYV10_2X10, + V4L2_MBUS_FMT_YVYU10_1X20, + V4L2_MBUS_FMT_YUYV10_1X20, V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_MBUS_FMT_RGB565_2X8_LE, -- cgit v1.2.3 From d7709ffff4117f7c7700755accfe9d5e429efc53 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 6 Aug 2010 16:25:04 -0300 Subject: V4L/DVB: v4l: add RGB444 mediabus formats These are needed for the ov7670 driver. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-mediabus.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h index 9b44aa5527ee..7e923fe3db04 100644 --- a/include/media/v4l2-mediabus.h +++ b/include/media/v4l2-mediabus.h @@ -32,6 +32,8 @@ enum v4l2_mbus_pixelcode { V4L2_MBUS_FMT_YUYV10_2X10, V4L2_MBUS_FMT_YVYU10_1X20, V4L2_MBUS_FMT_YUYV10_1X20, + V4L2_MBUS_FMT_RGB444_2X8_PADHI_LE, + V4L2_MBUS_FMT_RGB444_2X8_PADHI_BE, V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE, V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_MBUS_FMT_RGB565_2X8_LE, -- cgit v1.2.3 From fba32e0c70364f46a3d9ff36af5c85f1bd32ac7a Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 9 May 2010 07:42:03 -0300 Subject: V4L/DVB: v4l2-subdev: remove obsolete enum/try/s/g_fmt These have now all been replaced by enum/try/s/g_mbus_fmt. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-subdev.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'include') diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 4a97d7341a94..905879d7742f 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -256,10 +256,6 @@ struct v4l2_subdev_video_ops { int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std); int (*g_input_status)(struct v4l2_subdev *sd, u32 *status); int (*s_stream)(struct v4l2_subdev *sd, int enable); - int (*enum_fmt)(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmtdesc); - int (*g_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); - int (*try_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); - int (*s_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); int (*cropcap)(struct v4l2_subdev *sd, struct v4l2_cropcap *cc); int (*g_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop); int (*s_crop)(struct v4l2_subdev *sd, struct v4l2_crop *crop); -- cgit v1.2.3 From 1f33de0f8b91b70ccadb44958f09aa5bee7c1a44 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 5 Sep 2010 16:05:22 -0300 Subject: V4L/DVB: gspca_xirlink_cit: New gspca subdriver replacing v4l1 usbvideo/ibmcam.c The old usbvideo ibmcam driver needs to be replaced with a v4l2 driver preferably using the gspca webcam framework rather then the old usbvideo framework. This new gspca sub driver sets a first step in that direction. The ibmcam driver supports 4 different model webcams. This new driver (for now) only supports Model 3 cameras, as my test cam is a Model 3 cam, or so I thought. Upon reading: http://www.linux-usb.org/ibmcam/ I learned that the IBM Netcamera Pro I have even though having the same usb id and the same bcd version is different from the Model 3 cameras supported by the ibmcam driver. So this new gscpa subdriver supports Model 3 cameras (untested), and the IBM Netcamera Pro. Currently use with the IBM Netcamera Pro requires a module parameter. I hope to be able to autodetect which is which in the future. Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/Kconfig | 9 + drivers/media/video/gspca/Makefile | 2 + drivers/media/video/gspca/xirlink_cit.c | 1765 +++++++++++++++++++++++++++++++ include/linux/videodev2.h | 1 + 4 files changed, 1777 insertions(+) create mode 100644 drivers/media/video/gspca/xirlink_cit.c (limited to 'include') diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig index 23db0c29f68c..cab7be7eb638 100644 --- a/drivers/media/video/gspca/Kconfig +++ b/drivers/media/video/gspca/Kconfig @@ -337,6 +337,15 @@ config USB_GSPCA_VC032X To compile this driver as a module, choose M here: the module will be called gspca_vc032x. +config USB_GSPCA_XIRLINK_CIT + tristate "Xirlink C-It USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA + help + Say Y here if you want support for Xirlink C-It bases cameras. + + To compile this driver as a module, choose M here: the + module will be called gspca_xirlink_cit. + config USB_GSPCA_ZC3XX tristate "ZC3XX USB Camera Driver" depends on VIDEO_V4L2 && USB_GSPCA diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile index f6616db0b7f8..ea89ac1bd547 100644 --- a/drivers/media/video/gspca/Makefile +++ b/drivers/media/video/gspca/Makefile @@ -33,6 +33,7 @@ obj-$(CONFIG_USB_GSPCA_STV0680) += gspca_stv0680.o obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o +obj-$(CONFIG_USB_GSPCA_XIRLINK_CIT) += gspca_xirlink_cit.o obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o gspca_main-objs := gspca.o @@ -70,6 +71,7 @@ gspca_sunplus-objs := sunplus.o gspca_t613-objs := t613.o gspca_tv8532-objs := tv8532.o gspca_vc032x-objs := vc032x.o +gspca_xirlink_cit-objs := xirlink_cit.o gspca_zc3xx-objs := zc3xx.o obj-$(CONFIG_USB_M5602) += m5602/ diff --git a/drivers/media/video/gspca/xirlink_cit.c b/drivers/media/video/gspca/xirlink_cit.c new file mode 100644 index 000000000000..3525e783f7a2 --- /dev/null +++ b/drivers/media/video/gspca/xirlink_cit.c @@ -0,0 +1,1765 @@ +/* + * USB IBM C-It Video Camera driver + * + * Supports Xirlink C-It Video Camera, IBM PC Camera, + * IBM NetCamera and Veo Stingray. + * + * Copyright (C) 2010 Hans de Goede + * + * This driver is based on earlier work of: + * + * (C) Copyright 1999 Johannes Erdfelt + * (C) Copyright 1999 Randy Dunlap + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#define MODULE_NAME "xirlink-cit" + +#include "gspca.h" + +MODULE_AUTHOR("Hans de Goede "); +MODULE_DESCRIPTION("Xirlink C-IT"); +MODULE_LICENSE("GPL"); + +/* FIXME we should autodetect this */ +static int ibm_netcam_pro; +module_param(ibm_netcam_pro, int, 0); +MODULE_PARM_DESC(ibm_netcam_pro, + "Use IBM Netcamera Pro init sequences for Model 3 cams"); + +/* FIXME this should be handled through the V4L2 input selection API */ +static int rca_input; +module_param(rca_input, int, 0644); +MODULE_PARM_DESC(rca_input, + "Use rca input instead of ccd sensor on Model 3 cams"); + +/* specific webcam descriptor */ +struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + u8 model; +#define CIT_MODEL1 0 /* The model 1 - 4 nomenclature comes from the old */ +#define CIT_MODEL2 1 /* ibmcam driver */ +#define CIT_MODEL3 2 +#define CIT_MODEL4 3 +#define CIT_IBM_NETCAM_PRO 4 + u8 input_index; + u8 sof_read; + u8 contrast; + u8 brightness; + u8 hue; + u8 sharpness; +}; + +/* V4L2 controls supported by the driver */ +static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); +static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); +static void sd_stop0(struct gspca_dev *gspca_dev); + +static const struct ctrl sd_ctrls[] = { +#define SD_BRIGHTNESS 0 + { + { + .id = V4L2_CID_BRIGHTNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Brightness", + .minimum = 0x0c, + .maximum = 0x3f, + .step = 1, +#define BRIGHTNESS_DEFAULT 0x20 + .default_value = BRIGHTNESS_DEFAULT, + .flags = 0, + }, + .set = sd_setbrightness, + .get = sd_getbrightness, + }, +#define SD_CONTRAST 1 + { + { + .id = V4L2_CID_CONTRAST, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "contrast", + .minimum = 0, + .maximum = 20, + .step = 1, +#define CONTRAST_DEFAULT 10 + .default_value = CONTRAST_DEFAULT, + .flags = 0, + }, + .set = sd_setcontrast, + .get = sd_getcontrast, + }, +#define SD_HUE 2 + { + { + .id = V4L2_CID_HUE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Hue", + .minimum = 0x05, + .maximum = 0x37, + .step = 1, +#define HUE_DEFAULT 0x20 + .default_value = HUE_DEFAULT, + .flags = 0, + }, + .set = sd_sethue, + .get = sd_gethue, + }, +#define SD_SHARPNESS 3 + { + { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Sharpness", + .minimum = 0, + .maximum = 6, + .step = 1, +#define SHARPNESS_DEFAULT 3 + .default_value = SHARPNESS_DEFAULT, + .flags = 0, + }, + .set = sd_setsharpness, + .get = sd_getsharpness, + }, +}; + +static const struct v4l2_pix_format vga_yuv_mode[] = { + {160, 120, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, + .bytesperline = 160, + .sizeimage = 160 * 120 * 3 / 2, + .colorspace = V4L2_COLORSPACE_SRGB}, + {320, 240, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240 * 3 / 2, + .colorspace = V4L2_COLORSPACE_SRGB}, + {640, 480, V4L2_PIX_FMT_CIT_YYVYUY, V4L2_FIELD_NONE, + .bytesperline = 640, + .sizeimage = 640 * 480 * 3 / 2, + .colorspace = V4L2_COLORSPACE_SRGB}, +}; + +/* + * 01.01.08 - Added for RCA video in support -LO + * This struct is used to init the Model3 cam to use the RCA video in port + * instead of the CCD sensor. + */ +static const u16 rca_initdata[][3] = { + {0, 0x0000, 0x010c}, + {0, 0x0006, 0x012c}, + {0, 0x0078, 0x012d}, + {0, 0x0046, 0x012f}, + {0, 0xd141, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfea8, 0x0124}, + {1, 0x0000, 0x0116}, + {0, 0x0064, 0x0116}, + {1, 0x0000, 0x0115}, + {0, 0x0003, 0x0115}, + {0, 0x0008, 0x0123}, + {0, 0x0000, 0x0117}, + {0, 0x0000, 0x0112}, + {0, 0x0080, 0x0100}, + {0, 0x0000, 0x0100}, + {1, 0x0000, 0x0116}, + {0, 0x0060, 0x0116}, + {0, 0x0002, 0x0112}, + {0, 0x0000, 0x0123}, + {0, 0x0001, 0x0117}, + {0, 0x0040, 0x0108}, + {0, 0x0019, 0x012c}, + {0, 0x0040, 0x0116}, + {0, 0x000a, 0x0115}, + {0, 0x000b, 0x0115}, + {0, 0x0078, 0x012d}, + {0, 0x0046, 0x012f}, + {0, 0xd141, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfea8, 0x0124}, + {0, 0x0064, 0x0116}, + {0, 0x0000, 0x0115}, + {0, 0x0001, 0x0115}, + {0, 0xffff, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00aa, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xffff, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00f2, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x000f, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xffff, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00f8, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00fc, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xffff, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00f9, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x003c, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xffff, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0027, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0019, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0021, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0006, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0045, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002a, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x000e, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002b, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00f4, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002c, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0004, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002d, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0014, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002e, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0003, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x002f, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0003, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0014, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0053, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0x0000, 0x0101}, + {0, 0x00a0, 0x0103}, + {0, 0x0078, 0x0105}, + {0, 0x0000, 0x010a}, + {0, 0x0024, 0x010b}, + {0, 0x0028, 0x0119}, + {0, 0x0088, 0x011b}, + {0, 0x0002, 0x011d}, + {0, 0x0003, 0x011e}, + {0, 0x0000, 0x0129}, + {0, 0x00fc, 0x012b}, + {0, 0x0008, 0x0102}, + {0, 0x0000, 0x0104}, + {0, 0x0008, 0x011a}, + {0, 0x0028, 0x011c}, + {0, 0x0021, 0x012a}, + {0, 0x0000, 0x0118}, + {0, 0x0000, 0x0132}, + {0, 0x0000, 0x0109}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0031, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x00dc, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0032, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0020, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0001, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0040, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0037, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0030, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0xfff9, 0x0124}, + {0, 0x0086, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0038, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0008, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0x0000, 0x0127}, + {0, 0xfff8, 0x0124}, + {0, 0xfffd, 0x0124}, + {0, 0xfffa, 0x0124}, + {0, 0x0003, 0x0111}, +}; + +static int cit_write_reg(struct gspca_dev *gspca_dev, u16 value, u16 index) +{ + struct usb_device *udev = gspca_dev->dev; + int err; + + err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x00, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, + value, index, NULL, 0, 1000); + if (err < 0) + PDEBUG(D_ERR, "Failed to write a register (index 0x%04X," + " value 0x%02X, error %d)", index, value, err); + + return 0; +} + +static int cit_read_reg(struct gspca_dev *gspca_dev, u16 index) +{ + struct usb_device *udev = gspca_dev->dev; + __u8 *buf = gspca_dev->usb_buf; + int res; + + res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), 0x01, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, + 0x00, index, buf, 8, 1000); + if (res < 0) { + PDEBUG(D_ERR, + "Failed to read a register (index 0x%04X, error %d)", + index, res); + return res; + } + + PDEBUG(D_PROBE, + "Register %04x value: %02x %02x %02x %02x %02x %02x %02x %02x", + index, + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); + + return 0; +} + +/* + * ibmcam_model3_Packet1() + * + * 00_0078_012d + * 00_0097_012f + * 00_d141_0124 + * 00_0096_0127 + * 00_fea8_0124 +*/ +static void cit_model3_Packet1(struct gspca_dev *gspca_dev, u16 v1, u16 v2) +{ + cit_write_reg(gspca_dev, 0x0078, 0x012d); + cit_write_reg(gspca_dev, v1, 0x012f); + cit_write_reg(gspca_dev, 0xd141, 0x0124); + cit_write_reg(gspca_dev, v2, 0x0127); + cit_write_reg(gspca_dev, 0xfea8, 0x0124); +} + +/* this function is called at probe time */ +static int sd_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id) +{ + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam; + + sd->model = id->driver_info; + if (sd->model == CIT_MODEL3 && ibm_netcam_pro) + sd->model = CIT_IBM_NETCAM_PRO; + + cam = &gspca_dev->cam; + switch (sd->model) { + case CIT_MODEL3: + cam->cam_mode = vga_yuv_mode; + cam->nmodes = ARRAY_SIZE(vga_yuv_mode); + gspca_dev->ctrl_dis = (1 << SD_HUE); + break; + case CIT_IBM_NETCAM_PRO: + cam->cam_mode = vga_yuv_mode; + cam->nmodes = 2; /* no 640 x 480 */ + cam->input_flags = V4L2_IN_ST_VFLIP; + gspca_dev->ctrl_dis = ~(1 << SD_CONTRAST); + break; + } + + sd->brightness = BRIGHTNESS_DEFAULT; + sd->contrast = CONTRAST_DEFAULT; + sd->hue = HUE_DEFAULT; + sd->sharpness = SHARPNESS_DEFAULT; + + return 0; +} + +static int cit_init_ibm_netcam_pro(struct gspca_dev *gspca_dev) +{ + cit_read_reg(gspca_dev, 0x128); + cit_write_reg(gspca_dev, 0x0003, 0x0133); + cit_write_reg(gspca_dev, 0x0000, 0x0117); + cit_write_reg(gspca_dev, 0x0008, 0x0123); + cit_write_reg(gspca_dev, 0x0000, 0x0100); + cit_read_reg(gspca_dev, 0x0116); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + cit_write_reg(gspca_dev, 0x0002, 0x0112); + cit_write_reg(gspca_dev, 0x0000, 0x0133); + cit_write_reg(gspca_dev, 0x0000, 0x0123); + cit_write_reg(gspca_dev, 0x0001, 0x0117); + cit_write_reg(gspca_dev, 0x0040, 0x0108); + cit_write_reg(gspca_dev, 0x0019, 0x012c); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + cit_write_reg(gspca_dev, 0x0002, 0x0115); + cit_write_reg(gspca_dev, 0x000b, 0x0115); + + cit_write_reg(gspca_dev, 0x0078, 0x012d); + cit_write_reg(gspca_dev, 0x0001, 0x012f); + cit_write_reg(gspca_dev, 0xd141, 0x0124); + cit_write_reg(gspca_dev, 0x0079, 0x012d); + cit_write_reg(gspca_dev, 0x00ff, 0x0130); + cit_write_reg(gspca_dev, 0xcd41, 0x0124); + cit_write_reg(gspca_dev, 0xfffa, 0x0124); + cit_read_reg(gspca_dev, 0x0126); + + cit_model3_Packet1(gspca_dev, 0x0000, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0000, 0x0001); + cit_model3_Packet1(gspca_dev, 0x000b, 0x0000); + cit_model3_Packet1(gspca_dev, 0x000c, 0x0008); + cit_model3_Packet1(gspca_dev, 0x000d, 0x003a); + cit_model3_Packet1(gspca_dev, 0x000e, 0x0060); + cit_model3_Packet1(gspca_dev, 0x000f, 0x0060); + cit_model3_Packet1(gspca_dev, 0x0010, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0011, 0x0004); + cit_model3_Packet1(gspca_dev, 0x0012, 0x0028); + cit_model3_Packet1(gspca_dev, 0x0013, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0014, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0015, 0x00fb); + cit_model3_Packet1(gspca_dev, 0x0016, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0017, 0x0037); + cit_model3_Packet1(gspca_dev, 0x0018, 0x0036); + cit_model3_Packet1(gspca_dev, 0x001e, 0x0000); + cit_model3_Packet1(gspca_dev, 0x001f, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0020, 0x00c1); + cit_model3_Packet1(gspca_dev, 0x0021, 0x0034); + cit_model3_Packet1(gspca_dev, 0x0022, 0x0034); + cit_model3_Packet1(gspca_dev, 0x0025, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0028, 0x0022); + cit_model3_Packet1(gspca_dev, 0x0029, 0x000a); + cit_model3_Packet1(gspca_dev, 0x002b, 0x0000); + cit_model3_Packet1(gspca_dev, 0x002c, 0x0000); + cit_model3_Packet1(gspca_dev, 0x002d, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x002e, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x002f, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x0030, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x0031, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x0032, 0x0007); + cit_model3_Packet1(gspca_dev, 0x0033, 0x0005); + cit_model3_Packet1(gspca_dev, 0x0037, 0x0040); + cit_model3_Packet1(gspca_dev, 0x0039, 0x0000); + cit_model3_Packet1(gspca_dev, 0x003a, 0x0000); + cit_model3_Packet1(gspca_dev, 0x003b, 0x0001); + cit_model3_Packet1(gspca_dev, 0x003c, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0040, 0x000c); + cit_model3_Packet1(gspca_dev, 0x0041, 0x00fb); + cit_model3_Packet1(gspca_dev, 0x0042, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0043, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0045, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0047, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0048, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0049, 0x0000); + cit_model3_Packet1(gspca_dev, 0x004a, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x004b, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x004c, 0x00ff); + cit_model3_Packet1(gspca_dev, 0x004f, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0050, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0051, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0055, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0056, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0057, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0058, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0059, 0x0000); + cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); + cit_model3_Packet1(gspca_dev, 0x005d, 0x0022); + cit_model3_Packet1(gspca_dev, 0x005e, 0x003c); + cit_model3_Packet1(gspca_dev, 0x005f, 0x0050); + cit_model3_Packet1(gspca_dev, 0x0060, 0x0044); + cit_model3_Packet1(gspca_dev, 0x0061, 0x0005); + cit_model3_Packet1(gspca_dev, 0x006a, 0x007e); + cit_model3_Packet1(gspca_dev, 0x006f, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0072, 0x001b); + cit_model3_Packet1(gspca_dev, 0x0073, 0x0005); + cit_model3_Packet1(gspca_dev, 0x0074, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0075, 0x001b); + cit_model3_Packet1(gspca_dev, 0x0076, 0x002a); + cit_model3_Packet1(gspca_dev, 0x0077, 0x003c); + cit_model3_Packet1(gspca_dev, 0x0078, 0x0050); + cit_model3_Packet1(gspca_dev, 0x007b, 0x0000); + cit_model3_Packet1(gspca_dev, 0x007c, 0x0011); + cit_model3_Packet1(gspca_dev, 0x007d, 0x0024); + cit_model3_Packet1(gspca_dev, 0x007e, 0x0043); + cit_model3_Packet1(gspca_dev, 0x007f, 0x005a); + cit_model3_Packet1(gspca_dev, 0x0084, 0x0020); + cit_model3_Packet1(gspca_dev, 0x0085, 0x0033); + cit_model3_Packet1(gspca_dev, 0x0086, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0087, 0x0030); + cit_model3_Packet1(gspca_dev, 0x0088, 0x0070); + cit_model3_Packet1(gspca_dev, 0x008b, 0x0008); + cit_model3_Packet1(gspca_dev, 0x008f, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0090, 0x0006); + cit_model3_Packet1(gspca_dev, 0x0091, 0x0028); + cit_model3_Packet1(gspca_dev, 0x0092, 0x005a); + cit_model3_Packet1(gspca_dev, 0x0093, 0x0082); + cit_model3_Packet1(gspca_dev, 0x0096, 0x0014); + cit_model3_Packet1(gspca_dev, 0x0097, 0x0020); + cit_model3_Packet1(gspca_dev, 0x0098, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00b0, 0x0046); + cit_model3_Packet1(gspca_dev, 0x00b1, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00b2, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00b3, 0x0004); + cit_model3_Packet1(gspca_dev, 0x00b4, 0x0007); + cit_model3_Packet1(gspca_dev, 0x00b6, 0x0002); + cit_model3_Packet1(gspca_dev, 0x00b7, 0x0004); + cit_model3_Packet1(gspca_dev, 0x00bb, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00bc, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00bd, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00bf, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00c0, 0x00c8); + cit_model3_Packet1(gspca_dev, 0x00c1, 0x0014); + cit_model3_Packet1(gspca_dev, 0x00c2, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00c3, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00c4, 0x0004); + cit_model3_Packet1(gspca_dev, 0x00cb, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00cc, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00cd, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00ce, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00cf, 0x0020); + cit_model3_Packet1(gspca_dev, 0x00d0, 0x0040); + cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00d1, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00d2, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00d3, 0x00bf); + cit_model3_Packet1(gspca_dev, 0x00ea, 0x0008); + cit_model3_Packet1(gspca_dev, 0x00eb, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00ec, 0x00e8); + cit_model3_Packet1(gspca_dev, 0x00ed, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00ef, 0x0022); + cit_model3_Packet1(gspca_dev, 0x00f0, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00f2, 0x0028); + cit_model3_Packet1(gspca_dev, 0x00f4, 0x0002); + cit_model3_Packet1(gspca_dev, 0x00f5, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00fa, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00fb, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00fc, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00fd, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00fe, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00ff, 0x0000); + + cit_model3_Packet1(gspca_dev, 0x00be, 0x0003); + cit_model3_Packet1(gspca_dev, 0x00c8, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00c9, 0x0020); + cit_model3_Packet1(gspca_dev, 0x00ca, 0x0040); + cit_model3_Packet1(gspca_dev, 0x0053, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0082, 0x000e); + cit_model3_Packet1(gspca_dev, 0x0083, 0x0020); + cit_model3_Packet1(gspca_dev, 0x0034, 0x003c); + cit_model3_Packet1(gspca_dev, 0x006e, 0x0055); + cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); + cit_model3_Packet1(gspca_dev, 0x0063, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0066, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0067, 0x0006); + cit_model3_Packet1(gspca_dev, 0x006b, 0x0010); + cit_model3_Packet1(gspca_dev, 0x005a, 0x0001); + cit_model3_Packet1(gspca_dev, 0x005b, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0023, 0x0006); + cit_model3_Packet1(gspca_dev, 0x0026, 0x0004); + cit_model3_Packet1(gspca_dev, 0x0036, 0x0069); + cit_model3_Packet1(gspca_dev, 0x0038, 0x0064); + cit_model3_Packet1(gspca_dev, 0x003d, 0x0003); + cit_model3_Packet1(gspca_dev, 0x003e, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00b8, 0x0014); + cit_model3_Packet1(gspca_dev, 0x00b9, 0x0014); + cit_model3_Packet1(gspca_dev, 0x00e6, 0x0004); + cit_model3_Packet1(gspca_dev, 0x00e8, 0x0001); + + return 0; +} + +/* this function is called at probe and resume time */ +static int sd_init(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + break; /* All is done in sd_start */ + case CIT_IBM_NETCAM_PRO: + cit_init_ibm_netcam_pro(gspca_dev); + sd_stop0(gspca_dev); + break; + } + return 0; +} + +static int cit_set_brightness(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + /* Model 3: Brightness range 'i' in [0x0C..0x3F] */ + cit_model3_Packet1(gspca_dev, 0x0036, sd->brightness); + break; + case CIT_IBM_NETCAM_PRO: + /* No (known) brightness control for ibm netcam pro */ + break; + } + + return 0; +} + +static int cit_set_contrast(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + { /* Preset hardware values */ + static const struct { + unsigned short cv1; + unsigned short cv2; + unsigned short cv3; + } cv[7] = { + { 0x05, 0x05, 0x0f }, /* Minimum */ + { 0x04, 0x04, 0x16 }, + { 0x02, 0x03, 0x16 }, + { 0x02, 0x08, 0x16 }, + { 0x01, 0x0c, 0x16 }, + { 0x01, 0x0e, 0x16 }, + { 0x01, 0x10, 0x16 } /* Maximum */ + }; + int i = sd->contrast / 3; + cit_model3_Packet1(gspca_dev, 0x0067, cv[i].cv1); + cit_model3_Packet1(gspca_dev, 0x005b, cv[i].cv2); + cit_model3_Packet1(gspca_dev, 0x005c, cv[i].cv3); + break; + } + case CIT_IBM_NETCAM_PRO: + cit_model3_Packet1(gspca_dev, 0x005b, sd->contrast + 1); + break; + } + return 0; +} + +static int cit_set_hue(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + /* according to the ibmcam driver this does not work 8/ + /* cit_model3_Packet1(gspca_dev, 0x007e, sd->hue); */ + break; + case CIT_IBM_NETCAM_PRO: + /* No hue control for ibm netcam pro */ + break; + } + return 0; +} + +static int cit_set_sharpness(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + { /* + * "Use a table of magic numbers. + * This setting doesn't really change much. + * But that's how Windows does it." + */ + static const struct { + unsigned short sv1; + unsigned short sv2; + unsigned short sv3; + unsigned short sv4; + } sv[7] = { + { 0x00, 0x00, 0x05, 0x14 }, /* Smoothest */ + { 0x01, 0x04, 0x05, 0x14 }, + { 0x02, 0x04, 0x05, 0x14 }, + { 0x03, 0x04, 0x05, 0x14 }, + { 0x03, 0x05, 0x05, 0x14 }, + { 0x03, 0x06, 0x05, 0x14 }, + { 0x03, 0x07, 0x05, 0x14 } /* Sharpest */ + }; + cit_model3_Packet1(gspca_dev, 0x0060, sv[sd->sharpness].sv1); + cit_model3_Packet1(gspca_dev, 0x0061, sv[sd->sharpness].sv2); + cit_model3_Packet1(gspca_dev, 0x0062, sv[sd->sharpness].sv3); + cit_model3_Packet1(gspca_dev, 0x0063, sv[sd->sharpness].sv4); + break; + } + case CIT_IBM_NETCAM_PRO: + /* No sharpness setting on ibm netcamera pro */ + break; + } + return 0; +} + +static int cit_restart_stream(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + case CIT_IBM_NETCAM_PRO: + cit_write_reg(gspca_dev, 0x0001, 0x0114); + cit_write_reg(gspca_dev, 0x00c0, 0x010c); /* Go! */ + usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); + cit_write_reg(gspca_dev, 0x0001, 0x0113); + } + + sd->sof_read = 0; + + return 0; +} + +static int cit_start_model3(struct gspca_dev *gspca_dev) +{ + const unsigned short compression = 0; /* 0=none, 7=best frame rate */ + int i, clock_div = 0; + + /* HDG not in ibmcam driver, added to see if it helps with + auto-detecting between model3 and ibm netcamera pro */ + cit_read_reg(gspca_dev, 0x128); + + cit_write_reg(gspca_dev, 0x0000, 0x0100); + cit_read_reg(gspca_dev, 0x0116); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + cit_write_reg(gspca_dev, 0x0002, 0x0112); + cit_write_reg(gspca_dev, 0x0000, 0x0123); + cit_write_reg(gspca_dev, 0x0001, 0x0117); + cit_write_reg(gspca_dev, 0x0040, 0x0108); + cit_write_reg(gspca_dev, 0x0019, 0x012c); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + cit_write_reg(gspca_dev, 0x0002, 0x0115); + cit_write_reg(gspca_dev, 0x0003, 0x0115); + cit_read_reg(gspca_dev, 0x0115); + cit_write_reg(gspca_dev, 0x000b, 0x0115); + + /* HDG not in ibmcam driver, added to see if it helps with + auto-detecting between model3 and ibm netcamera pro */ + if (0) { + cit_write_reg(gspca_dev, 0x0078, 0x012d); + cit_write_reg(gspca_dev, 0x0001, 0x012f); + cit_write_reg(gspca_dev, 0xd141, 0x0124); + cit_write_reg(gspca_dev, 0x0079, 0x012d); + cit_write_reg(gspca_dev, 0x00ff, 0x0130); + cit_write_reg(gspca_dev, 0xcd41, 0x0124); + cit_write_reg(gspca_dev, 0xfffa, 0x0124); + cit_read_reg(gspca_dev, 0x0126); + } + + cit_model3_Packet1(gspca_dev, 0x000a, 0x0040); + cit_model3_Packet1(gspca_dev, 0x000b, 0x00f6); + cit_model3_Packet1(gspca_dev, 0x000c, 0x0002); + cit_model3_Packet1(gspca_dev, 0x000d, 0x0020); + cit_model3_Packet1(gspca_dev, 0x000e, 0x0033); + cit_model3_Packet1(gspca_dev, 0x000f, 0x0007); + cit_model3_Packet1(gspca_dev, 0x0010, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0011, 0x0070); + cit_model3_Packet1(gspca_dev, 0x0012, 0x0030); + cit_model3_Packet1(gspca_dev, 0x0013, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0014, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0015, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0016, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0017, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0018, 0x0000); + cit_model3_Packet1(gspca_dev, 0x001e, 0x00c3); + cit_model3_Packet1(gspca_dev, 0x0020, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0028, 0x0010); + cit_model3_Packet1(gspca_dev, 0x0029, 0x0054); + cit_model3_Packet1(gspca_dev, 0x002a, 0x0013); + cit_model3_Packet1(gspca_dev, 0x002b, 0x0007); + cit_model3_Packet1(gspca_dev, 0x002d, 0x0028); + cit_model3_Packet1(gspca_dev, 0x002e, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0031, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0032, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0033, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0034, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0035, 0x0038); + cit_model3_Packet1(gspca_dev, 0x003a, 0x0001); + cit_model3_Packet1(gspca_dev, 0x003c, 0x001e); + cit_model3_Packet1(gspca_dev, 0x003f, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0041, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0046, 0x003f); + cit_model3_Packet1(gspca_dev, 0x0047, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0050, 0x0005); + cit_model3_Packet1(gspca_dev, 0x0052, 0x001a); + cit_model3_Packet1(gspca_dev, 0x0053, 0x0003); + cit_model3_Packet1(gspca_dev, 0x005a, 0x006b); + cit_model3_Packet1(gspca_dev, 0x005d, 0x001e); + cit_model3_Packet1(gspca_dev, 0x005e, 0x0030); + cit_model3_Packet1(gspca_dev, 0x005f, 0x0041); + cit_model3_Packet1(gspca_dev, 0x0064, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0065, 0x0015); + cit_model3_Packet1(gspca_dev, 0x0068, 0x000f); + cit_model3_Packet1(gspca_dev, 0x0079, 0x0000); + cit_model3_Packet1(gspca_dev, 0x007a, 0x0000); + cit_model3_Packet1(gspca_dev, 0x007c, 0x003f); + cit_model3_Packet1(gspca_dev, 0x0082, 0x000f); + cit_model3_Packet1(gspca_dev, 0x0085, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0099, 0x0000); + cit_model3_Packet1(gspca_dev, 0x009b, 0x0023); + cit_model3_Packet1(gspca_dev, 0x009c, 0x0022); + cit_model3_Packet1(gspca_dev, 0x009d, 0x0096); + cit_model3_Packet1(gspca_dev, 0x009e, 0x0096); + cit_model3_Packet1(gspca_dev, 0x009f, 0x000a); + + switch (gspca_dev->width) { + case 160: + cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ + cit_write_reg(gspca_dev, 0x0024, 0x010b); /* Differs everywhere */ + cit_write_reg(gspca_dev, 0x00a9, 0x0119); + cit_write_reg(gspca_dev, 0x0016, 0x011b); + cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */ + cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ + cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ + cit_write_reg(gspca_dev, 0x0018, 0x0102); + cit_write_reg(gspca_dev, 0x0004, 0x0104); + cit_write_reg(gspca_dev, 0x0004, 0x011a); + cit_write_reg(gspca_dev, 0x0028, 0x011c); + cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ + cit_write_reg(gspca_dev, 0x0000, 0x0118); + cit_write_reg(gspca_dev, 0x0000, 0x0132); + cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ + cit_write_reg(gspca_dev, compression, 0x0109); + clock_div = 3; + break; + case 320: + cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ + cit_write_reg(gspca_dev, 0x0028, 0x010b); /* Differs everywhere */ + cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same */ + cit_write_reg(gspca_dev, 0x0000, 0x011e); + cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ + cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ + /* 4 commands from 160x120 skipped */ + cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ + cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ + cit_write_reg(gspca_dev, compression, 0x0109); + cit_write_reg(gspca_dev, 0x00d9, 0x0119); + cit_write_reg(gspca_dev, 0x0006, 0x011b); + cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x0010, 0x0104); + cit_write_reg(gspca_dev, 0x0004, 0x011a); + cit_write_reg(gspca_dev, 0x003f, 0x011c); + cit_write_reg(gspca_dev, 0x001c, 0x0118); + cit_write_reg(gspca_dev, 0x0000, 0x0132); + clock_div = 5; + break; + case 640: + cit_write_reg(gspca_dev, 0x00f0, 0x0105); + cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ + cit_write_reg(gspca_dev, 0x0038, 0x010b); /* Differs everywhere */ + cit_write_reg(gspca_dev, 0x00d9, 0x0119); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x0006, 0x011b); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x0004, 0x011d); /* NC */ + cit_write_reg(gspca_dev, 0x0003, 0x011e); /* Same on 160x120, 640x480 */ + cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ + cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ + cit_write_reg(gspca_dev, 0x0021, 0x0102); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x0016, 0x0104); /* NC */ + cit_write_reg(gspca_dev, 0x0004, 0x011a); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x003f, 0x011c); /* Same on 320x240, 640x480 */ + cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ + cit_write_reg(gspca_dev, 0x001c, 0x0118); /* Same on 320x240, 640x480 */ + cit_model3_Packet1(gspca_dev, 0x0021, 0x0001); /* Same */ + cit_write_reg(gspca_dev, compression, 0x0109); + cit_write_reg(gspca_dev, 0x0040, 0x0101); + cit_write_reg(gspca_dev, 0x0040, 0x0103); + cit_write_reg(gspca_dev, 0x0000, 0x0132); /* Same on 320x240, 640x480 */ + clock_div = 7; + break; + } + + cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); /* Hue */ + cit_model3_Packet1(gspca_dev, 0x0036, 0x0011); /* Brightness */ + cit_model3_Packet1(gspca_dev, 0x0060, 0x0002); /* Sharpness */ + cit_model3_Packet1(gspca_dev, 0x0061, 0x0004); /* Sharpness */ + cit_model3_Packet1(gspca_dev, 0x0062, 0x0005); /* Sharpness */ + cit_model3_Packet1(gspca_dev, 0x0063, 0x0014); /* Sharpness */ + cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */ + cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */ + cit_model3_Packet1(gspca_dev, 0x0067, 0x0001); /* Contrast */ + cit_model3_Packet1(gspca_dev, 0x005b, 0x000c); /* Contrast */ + cit_model3_Packet1(gspca_dev, 0x005c, 0x0016); /* Contrast */ + cit_model3_Packet1(gspca_dev, 0x0098, 0x000b); + cit_model3_Packet1(gspca_dev, 0x002c, 0x0003); /* Was 1, broke 640x480 */ + cit_model3_Packet1(gspca_dev, 0x002f, 0x002a); + cit_model3_Packet1(gspca_dev, 0x0030, 0x0029); + cit_model3_Packet1(gspca_dev, 0x0037, 0x0002); + cit_model3_Packet1(gspca_dev, 0x0038, 0x0059); + cit_model3_Packet1(gspca_dev, 0x003d, 0x002e); + cit_model3_Packet1(gspca_dev, 0x003e, 0x0028); + cit_model3_Packet1(gspca_dev, 0x0078, 0x0005); + cit_model3_Packet1(gspca_dev, 0x007b, 0x0011); + cit_model3_Packet1(gspca_dev, 0x007d, 0x004b); + cit_model3_Packet1(gspca_dev, 0x007f, 0x0022); + cit_model3_Packet1(gspca_dev, 0x0080, 0x000c); + cit_model3_Packet1(gspca_dev, 0x0081, 0x000b); + cit_model3_Packet1(gspca_dev, 0x0083, 0x00fd); + cit_model3_Packet1(gspca_dev, 0x0086, 0x000b); + cit_model3_Packet1(gspca_dev, 0x0087, 0x000b); + cit_model3_Packet1(gspca_dev, 0x007e, 0x000e); + cit_model3_Packet1(gspca_dev, 0x0096, 0x00a0); /* Red sharpness */ + cit_model3_Packet1(gspca_dev, 0x0097, 0x0096); /* Blue sharpness */ + cit_model3_Packet1(gspca_dev, 0x0098, 0x000b); + + cit_write_reg(gspca_dev, clock_div, 0x0111); /* Clock Divider */ + + switch (gspca_dev->width) { + case 160: + cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */ + cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */ + cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */ + cit_model3_Packet1(gspca_dev, 0x0040, 0x000a); + cit_model3_Packet1(gspca_dev, 0x0051, 0x000a); + break; + case 320: + cit_model3_Packet1(gspca_dev, 0x001f, 0x0000); /* Same */ + cit_model3_Packet1(gspca_dev, 0x0039, 0x001f); /* Same */ + cit_model3_Packet1(gspca_dev, 0x003b, 0x003c); /* Same */ + cit_model3_Packet1(gspca_dev, 0x0040, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0051, 0x000b); + break; + case 640: + cit_model3_Packet1(gspca_dev, 0x001f, 0x0002); /* !Same */ + cit_model3_Packet1(gspca_dev, 0x0039, 0x003e); /* !Same */ + cit_model3_Packet1(gspca_dev, 0x0040, 0x0008); + cit_model3_Packet1(gspca_dev, 0x0051, 0x000a); + break; + } + +/* if (sd->input_index) { */ + if (rca_input) { + for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { + if (rca_initdata[i][0]) + cit_read_reg(gspca_dev, rca_initdata[i][2]); + else + cit_write_reg(gspca_dev, rca_initdata[i][1], + rca_initdata[i][2]); + } + } + + return 0; +} + +static int cit_start_ibm_netcam_pro(struct gspca_dev *gspca_dev) +{ + const unsigned short compression = 0; /* 0=none, 7=best frame rate */ + int i, clock_div = 0; + + cit_write_reg(gspca_dev, 0x0003, 0x0133); + cit_write_reg(gspca_dev, 0x0000, 0x0117); + cit_write_reg(gspca_dev, 0x0008, 0x0123); + cit_write_reg(gspca_dev, 0x0000, 0x0100); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + /* cit_write_reg(gspca_dev, 0x0002, 0x0112); see sd_stop0 */ + cit_write_reg(gspca_dev, 0x0000, 0x0133); + cit_write_reg(gspca_dev, 0x0000, 0x0123); + cit_write_reg(gspca_dev, 0x0001, 0x0117); + cit_write_reg(gspca_dev, 0x0040, 0x0108); + cit_write_reg(gspca_dev, 0x0019, 0x012c); + cit_write_reg(gspca_dev, 0x0060, 0x0116); + /* cit_write_reg(gspca_dev, 0x000b, 0x0115); see sd_stop0 */ + + cit_model3_Packet1(gspca_dev, 0x0049, 0x0000); + + cit_write_reg(gspca_dev, 0x0000, 0x0101); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x003a, 0x0102); /* Hstart */ + cit_write_reg(gspca_dev, 0x00a0, 0x0103); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0078, 0x0105); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0000, 0x010a); /* Same */ + cit_write_reg(gspca_dev, 0x0002, 0x011d); /* Same on 160x120, 320x240 */ + cit_write_reg(gspca_dev, 0x0000, 0x0129); /* Same */ + cit_write_reg(gspca_dev, 0x00fc, 0x012b); /* Same */ + cit_write_reg(gspca_dev, 0x0022, 0x012a); /* Same */ + + switch (gspca_dev->width) { + case 160: + cit_write_reg(gspca_dev, 0x0024, 0x010b); + cit_write_reg(gspca_dev, 0x0089, 0x0119); + cit_write_reg(gspca_dev, 0x000a, 0x011b); + cit_write_reg(gspca_dev, 0x0003, 0x011e); + cit_write_reg(gspca_dev, 0x0007, 0x0104); + cit_write_reg(gspca_dev, 0x0009, 0x011a); + cit_write_reg(gspca_dev, 0x008b, 0x011c); + cit_write_reg(gspca_dev, 0x0008, 0x0118); + cit_write_reg(gspca_dev, 0x0000, 0x0132); + clock_div = 3; + break; + case 320: + cit_write_reg(gspca_dev, 0x0028, 0x010b); + cit_write_reg(gspca_dev, 0x00d9, 0x0119); + cit_write_reg(gspca_dev, 0x0006, 0x011b); + cit_write_reg(gspca_dev, 0x0000, 0x011e); + cit_write_reg(gspca_dev, 0x000e, 0x0104); + cit_write_reg(gspca_dev, 0x0004, 0x011a); + cit_write_reg(gspca_dev, 0x003f, 0x011c); + cit_write_reg(gspca_dev, 0x000c, 0x0118); + cit_write_reg(gspca_dev, 0x0000, 0x0132); + clock_div = 5; + break; + } + + cit_model3_Packet1(gspca_dev, 0x0019, 0x0031); + cit_model3_Packet1(gspca_dev, 0x001a, 0x0003); + cit_model3_Packet1(gspca_dev, 0x001b, 0x0038); + cit_model3_Packet1(gspca_dev, 0x001c, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0024, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0027, 0x0001); + cit_model3_Packet1(gspca_dev, 0x002a, 0x0004); + cit_model3_Packet1(gspca_dev, 0x0035, 0x000b); + cit_model3_Packet1(gspca_dev, 0x003f, 0x0001); + cit_model3_Packet1(gspca_dev, 0x0044, 0x0000); + cit_model3_Packet1(gspca_dev, 0x0054, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00c4, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00e7, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00e9, 0x0001); + cit_model3_Packet1(gspca_dev, 0x00ee, 0x0000); + cit_model3_Packet1(gspca_dev, 0x00f3, 0x00c0); + + cit_write_reg(gspca_dev, compression, 0x0109); + cit_write_reg(gspca_dev, clock_div, 0x0111); + +/* if (sd->input_index) { */ + if (rca_input) { + for (i = 0; i < ARRAY_SIZE(rca_initdata); i++) { + if (rca_initdata[i][0]) + cit_read_reg(gspca_dev, rca_initdata[i][2]); + else + cit_write_reg(gspca_dev, rca_initdata[i][1], + rca_initdata[i][2]); + } + } + + return 0; +} + +/* -- start the camera -- */ +static int sd_start(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + struct usb_host_interface *alt; + struct usb_interface *intf; + int packet_size; + + switch (sd->model) { + case CIT_MODEL3: + cit_start_model3(gspca_dev); + break; + case CIT_IBM_NETCAM_PRO: + cit_start_ibm_netcam_pro(gspca_dev); + break; + } + + cit_set_brightness(gspca_dev); + cit_set_contrast(gspca_dev); + cit_set_hue(gspca_dev); + cit_set_sharpness(gspca_dev); + + /* Program max isoc packet size, one day we should use this to + allow us to work together with other isoc devices on the same + root hub. */ + intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); + alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); + if (!alt) { + PDEBUG(D_ERR, "Couldn't get altsetting"); + return -EIO; + } + + packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); + cit_write_reg(gspca_dev, packet_size >> 8, 0x0106); + cit_write_reg(gspca_dev, packet_size & 0xff, 0x0107); + + cit_restart_stream(gspca_dev); + + return 0; +} + +static void sd_stopN(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->model) { + case CIT_MODEL3: + case CIT_IBM_NETCAM_PRO: + cit_write_reg(gspca_dev, 0x0000, 0x010c); + break; + } +} + +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + /* We cannot use gspca_dev->present here as that is not set when + sd_init gets called and we get called from sd_init */ + if (!gspca_dev->dev) + return; + + switch (sd->model) { + case CIT_MODEL3: + cit_write_reg(gspca_dev, 0x0006, 0x012c); + cit_model3_Packet1(gspca_dev, 0x0046, 0x0000); + cit_read_reg(gspca_dev, 0x0116); + cit_write_reg(gspca_dev, 0x0064, 0x0116); + cit_read_reg(gspca_dev, 0x0115); + cit_write_reg(gspca_dev, 0x0003, 0x0115); + cit_write_reg(gspca_dev, 0x0008, 0x0123); + cit_write_reg(gspca_dev, 0x0000, 0x0117); + cit_write_reg(gspca_dev, 0x0000, 0x0112); + cit_write_reg(gspca_dev, 0x0080, 0x0100); + break; + case CIT_IBM_NETCAM_PRO: + cit_model3_Packet1(gspca_dev, 0x0049, 0x00ff); + cit_write_reg(gspca_dev, 0x0006, 0x012c); + cit_write_reg(gspca_dev, 0x0000, 0x0116); + /* HDG windows does this, but I cannot get the camera + to restart with this without redoing the entire init + sequence which makes switching modes really slow */ + /* cit_write_reg(gspca_dev, 0x0006, 0x0115); */ + cit_write_reg(gspca_dev, 0x0008, 0x0123); + cit_write_reg(gspca_dev, 0x0000, 0x0117); + cit_write_reg(gspca_dev, 0x0003, 0x0133); + cit_write_reg(gspca_dev, 0x0000, 0x0111); + /* HDG windows does this, but I get a green picture when + restarting the stream after this */ + /* cit_write_reg(gspca_dev, 0x0000, 0x0112); */ + cit_write_reg(gspca_dev, 0x00c0, 0x0100); + break; + } +} + +static u8 *cit_find_sof(struct gspca_dev *gspca_dev, u8 *data, int len) +{ + struct sd *sd = (struct sd *) gspca_dev; + int i; + + switch (sd->model) { + case CIT_MODEL3: + case CIT_IBM_NETCAM_PRO: + for (i = 0; i < len; i++) { + switch (sd->sof_read) { + case 0: + if (data[i] == 0x00) + sd->sof_read++; + break; + case 1: + if (data[i] == 0xff) + sd->sof_read++; + else + sd->sof_read = 0; + break; + case 2: + sd->sof_read = 0; + if (data[i] != 0xff) { + if (i >= 4) + PDEBUG(D_FRAM, + "header found at offset: %d: %02x %02x 00 ff %02x %02x\n", + i - 2, + data[i - 4], + data[i - 3], + data[i], + data[i + 1]); + return data + i + 2; + } + break; + } + } + break; + } + return NULL; +} + +static void sd_pkt_scan(struct gspca_dev *gspca_dev, + u8 *data, int len) +{ + unsigned char *sof; + + sof = cit_find_sof(gspca_dev, data, len); + if (sof) { + int n; + + /* finish decoding current frame */ + n = sof - data; + if (n > 4) + n -= 4; + else + n = 0; + gspca_frame_add(gspca_dev, LAST_PACKET, + data, n); + gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); + len -= sof - data; + data = sof; + } + + gspca_frame_add(gspca_dev, INTER_PACKET, data, len); +} + +static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->brightness = val; + if (gspca_dev->streaming) { + sd_stopN(gspca_dev); + cit_set_brightness(gspca_dev); + cit_restart_stream(gspca_dev); + } + + return 0; +} + +static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->brightness; + + return 0; +} + +static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->contrast = val; + if (gspca_dev->streaming) { + sd_stopN(gspca_dev); + cit_set_contrast(gspca_dev); + cit_restart_stream(gspca_dev); + } + + return 0; +} + +static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->contrast; + + return 0; +} + +static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->hue = val; + if (gspca_dev->streaming) { + sd_stopN(gspca_dev); + cit_set_hue(gspca_dev); + cit_restart_stream(gspca_dev); + } + return 0; +} + +static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->hue; + + return 0; +} + +static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->sharpness = val; + if (gspca_dev->streaming) { + sd_stopN(gspca_dev); + cit_set_sharpness(gspca_dev); + cit_restart_stream(gspca_dev); + } + return 0; +} + +static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->sharpness; + + return 0; +} + + +/* sub-driver description */ +static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), + .config = sd_config, + .init = sd_init, + .start = sd_start, + .stopN = sd_stopN, + .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, +}; + +/* -- module initialisation -- */ +static const __devinitdata struct usb_device_id device_table[] = { + { USB_DEVICE_VER(0x0545, 0x8080, 0x0002, 0x0002), .driver_info = CIT_MODEL1 }, + { USB_DEVICE_VER(0x0545, 0x8080, 0x030a, 0x030a), .driver_info = CIT_MODEL2 }, + { USB_DEVICE_VER(0x0545, 0x8080, 0x0301, 0x0301), .driver_info = CIT_MODEL3 }, + { USB_DEVICE_VER(0x0545, 0x8002, 0x030a, 0x030a), .driver_info = CIT_MODEL4 }, + { USB_DEVICE_VER(0x0545, 0x800c, 0x030a, 0x030a), .driver_info = CIT_MODEL2 }, + { USB_DEVICE_VER(0x0545, 0x800d, 0x030a, 0x030a), .driver_info = CIT_MODEL4 }, + {} +}; +MODULE_DEVICE_TABLE(usb, device_table); + +/* -- device connect -- */ +static int sd_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return gspca_dev_probe2(intf, id, &sd_desc, sizeof(struct sd), + THIS_MODULE); +} + +static struct usb_driver sd_driver = { + .name = MODULE_NAME, + .id_table = device_table, + .probe = sd_probe, + .disconnect = gspca_disconnect, +#ifdef CONFIG_PM + .suspend = gspca_suspend, + .resume = gspca_resume, +#endif +}; + +/* -- module insert / remove -- */ +static int __init sd_mod_init(void) +{ + int ret; + ret = usb_register(&sd_driver); + if (ret < 0) + return ret; + PDEBUG(D_PROBE, "registered"); + return 0; +} +static void __exit sd_mod_exit(void) +{ + usb_deregister(&sd_driver); + PDEBUG(D_PROBE, "deregistered"); +} + +module_init(sd_mod_init); +module_exit(sd_mod_exit); diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 61490c6dcdbd..0aef67e0281a 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -363,6 +363,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */ #define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */ #define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */ +#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */ /* * F O R M A T E N U M E R A T I O N -- cgit v1.2.3 From b517af722860dcf9878754217575137be35ea0cc Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 5 Sep 2010 16:30:30 -0300 Subject: V4L/DVB: gspca_konica: New gspca subdriver for konica chipset using cams This new driver replaces the (known to not work / crash) usbvideo konicawc driver. Signed-off-by: Hans de Goede Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/gspca/Kconfig | 9 + drivers/media/video/gspca/Makefile | 2 + drivers/media/video/gspca/konica.c | 653 +++++++++++++++++++++++++++++++++++ drivers/media/video/usbvideo/Kconfig | 5 +- include/linux/videodev2.h | 1 + 5 files changed, 669 insertions(+), 1 deletion(-) create mode 100644 drivers/media/video/gspca/konica.c (limited to 'include') diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig index cab7be7eb638..dda56ff834f4 100644 --- a/drivers/media/video/gspca/Kconfig +++ b/drivers/media/video/gspca/Kconfig @@ -77,6 +77,15 @@ config USB_GSPCA_JEILINJ To compile this driver as a module, choose M here: the module will be called gspca_jeilinj. +config USB_GSPCA_KONICA + tristate "Konica USB Camera V4L2 driver" + depends on VIDEO_V4L2 && USB_GSPCA + help + Say Y here if you want support for cameras based on the Konica chip. + + To compile this driver as a module, choose M here: the + module will be called gspca_konica. + config USB_GSPCA_MARS tristate "Mars USB Camera Driver" depends on VIDEO_V4L2 && USB_GSPCA diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile index ea89ac1bd547..24e695b8b077 100644 --- a/drivers/media/video/gspca/Makefile +++ b/drivers/media/video/gspca/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_USB_GSPCA_CPIA1) += gspca_cpia1.o obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o +obj-$(CONFIG_USB_GSPCA_KONICA) += gspca_konica.o obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o @@ -43,6 +44,7 @@ gspca_cpia1-objs := cpia1.o gspca_etoms-objs := etoms.o gspca_finepix-objs := finepix.o gspca_jeilinj-objs := jeilinj.o +gspca_konica-objs := konica.o gspca_mars-objs := mars.o gspca_mr97310a-objs := mr97310a.o gspca_ov519-objs := ov519.o diff --git a/drivers/media/video/gspca/konica.c b/drivers/media/video/gspca/konica.c new file mode 100644 index 000000000000..8cdf1af4257e --- /dev/null +++ b/drivers/media/video/gspca/konica.c @@ -0,0 +1,653 @@ +/* + * Driver for USB webcams based on Konica chipset. This + * chipset is used in Intel YC76 camera. + * + * Copyright (C) 2010 Hans de Goede + * + * Based on the usbvideo v4l1 konicawc driver which is: + * + * Copyright (C) 2002 Simon Evans + * + * The code for making gspca work with a webcam with 2 isoc endpoints was + * taken from the benq gspca subdriver which is: + * + * Copyright (C) 2009 Jean-Francois Moine (http://moinejf.free.fr) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#define MODULE_NAME "konica" + +#include +#include "gspca.h" + +MODULE_AUTHOR("Hans de Goede "); +MODULE_DESCRIPTION("Konica chipset USB Camera Driver"); +MODULE_LICENSE("GPL"); + +#define WHITEBAL_REG 0x01 +#define BRIGHTNESS_REG 0x02 +#define SHARPNESS_REG 0x03 +#define CONTRAST_REG 0x04 +#define SATURATION_REG 0x05 + +/* specific webcam descriptor */ +struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + struct urb *last_data_urb; + u8 snapshot_pressed; + u8 brightness; + u8 contrast; + u8 saturation; + u8 whitebal; + u8 sharpness; +}; + +/* V4L2 controls supported by the driver */ +static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setwhitebal(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getwhitebal(struct gspca_dev *gspca_dev, __s32 *val); +static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); +static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + +static const struct ctrl sd_ctrls[] = { +#define SD_BRIGHTNESS 0 + { + { + .id = V4L2_CID_BRIGHTNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Brightness", + .minimum = 0, + .maximum = 9, + .step = 1, +#define BRIGHTNESS_DEFAULT 4 + .default_value = BRIGHTNESS_DEFAULT, + .flags = 0, + }, + .set = sd_setbrightness, + .get = sd_getbrightness, + }, +#define SD_CONTRAST 1 + { + { + .id = V4L2_CID_CONTRAST, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "contrast", + .minimum = 0, + .maximum = 9, + .step = 4, +#define CONTRAST_DEFAULT 10 + .default_value = CONTRAST_DEFAULT, + .flags = 0, + }, + .set = sd_setcontrast, + .get = sd_getcontrast, + }, +#define SD_SATURATION 2 + { + { + .id = V4L2_CID_SATURATION, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Saturation", + .minimum = 0, + .maximum = 9, + .step = 1, +#define SATURATION_DEFAULT 4 + .default_value = SATURATION_DEFAULT, + .flags = 0, + }, + .set = sd_setsaturation, + .get = sd_getsaturation, + }, +#define SD_WHITEBAL 3 + { + { + .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Whitebalance ", + .minimum = 0, + .maximum = 33, + .step = 1, +#define WHITEBAL_DEFAULT 25 + .default_value = WHITEBAL_DEFAULT, + .flags = 0, + }, + .set = sd_setwhitebal, + .get = sd_getwhitebal, + }, +#define SD_SHARPNESS 4 + { + { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Sharpness", + .minimum = 0, + .maximum = 9, + .step = 1, +#define SHARPNESS_DEFAULT 4 + .default_value = SHARPNESS_DEFAULT, + .flags = 0, + }, + .set = sd_setsharpness, + .get = sd_getsharpness, + }, +}; + +/* .priv is what goes to register 8 for this mode, known working values: + 0x00 -> 176x144, cropped + 0x01 -> 176x144, cropped + 0x02 -> 176x144, cropped + 0x03 -> 176x144, cropped + 0x04 -> 176x144, binned + 0x05 -> 320x240 + 0x06 -> 320x240 + 0x07 -> 160x120, cropped + 0x08 -> 160x120, cropped + 0x09 -> 160x120, binned (note has 136 lines) + 0x0a -> 160x120, binned (note has 136 lines) + 0x0b -> 160x120, cropped +*/ +static const struct v4l2_pix_format vga_mode[] = { + {160, 120, V4L2_PIX_FMT_KONICA420, V4L2_FIELD_NONE, + .bytesperline = 160, + .sizeimage = 160 * 136 * 3 / 2 + 960, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0x0a}, + {176, 144, V4L2_PIX_FMT_KONICA420, V4L2_FIELD_NONE, + .bytesperline = 176, + .sizeimage = 176 * 144 * 3 / 2 + 960, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0x04}, + {320, 240, V4L2_PIX_FMT_KONICA420, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240 * 3 / 2 + 960, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0x05}, +}; + +static void sd_isoc_irq(struct urb *urb); + +static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index) +{ + struct usb_device *dev = gspca_dev->dev; + int ret; + + if (gspca_dev->usb_err < 0) + return; + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + 0x02, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + value, + index, + NULL, + 0, + 1000); + if (ret < 0) { + PDEBUG(D_ERR, "reg_w err %d", ret); + gspca_dev->usb_err = ret; + } +} + +static void reg_r(struct gspca_dev *gspca_dev, u16 value, u16 index) +{ + struct usb_device *dev = gspca_dev->dev; + int ret; + + if (gspca_dev->usb_err < 0) + return; + ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + 0x03, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + value, + index, + gspca_dev->usb_buf, + 2, + 1000); + if (ret < 0) { + PDEBUG(D_ERR, "reg_w err %d", ret); + gspca_dev->usb_err = ret; + } +} + +static void konica_stream_on(struct gspca_dev *gspca_dev) +{ + reg_w(gspca_dev, 1, 0x0b); +} + +static void konica_stream_off(struct gspca_dev *gspca_dev) +{ + reg_w(gspca_dev, 0, 0x0b); +} + +/* this function is called at probe time */ +static int sd_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id) +{ + struct sd *sd = (struct sd *) gspca_dev; + + gspca_dev->cam.cam_mode = vga_mode; + gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); + gspca_dev->cam.no_urb_create = 1; + /* The highest alt setting has an isoc packetsize of 0, so we + don't want to use it */ + gspca_dev->nbalt--; + + sd->brightness = BRIGHTNESS_DEFAULT; + sd->contrast = CONTRAST_DEFAULT; + sd->saturation = SATURATION_DEFAULT; + sd->whitebal = WHITEBAL_DEFAULT; + sd->sharpness = SHARPNESS_DEFAULT; + + return 0; +} + +/* this function is called at probe and resume time */ +static int sd_init(struct gspca_dev *gspca_dev) +{ + /* HDG not sure if these 2 reads are needed */ + reg_r(gspca_dev, 0, 0x10); + PDEBUG(D_PROBE, "Reg 0x10 reads: %02x %02x", + gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]); + reg_r(gspca_dev, 0, 0x10); + PDEBUG(D_PROBE, "Reg 0x10 reads: %02x %02x", + gspca_dev->usb_buf[0], gspca_dev->usb_buf[1]); + reg_w(gspca_dev, 0, 0x0d); + + return 0; +} + +static int sd_start(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + struct urb *urb; + int i, n, packet_size; + struct usb_host_interface *alt; + struct usb_interface *intf; + + intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface); + alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt); + if (!alt) { + PDEBUG(D_ERR, "Couldn't get altsetting"); + return -EIO; + } + + packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize); + + reg_w(gspca_dev, sd->brightness, BRIGHTNESS_REG); + reg_w(gspca_dev, sd->whitebal, WHITEBAL_REG); + reg_w(gspca_dev, sd->contrast, CONTRAST_REG); + reg_w(gspca_dev, sd->saturation, SATURATION_REG); + reg_w(gspca_dev, sd->sharpness, SHARPNESS_REG); + + n = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; + reg_w(gspca_dev, n, 0x08); + + konica_stream_on(gspca_dev); + + if (gspca_dev->usb_err) + return gspca_dev->usb_err; + + /* create 4 URBs - 2 on endpoint 0x83 and 2 on 0x082 */ +#if MAX_NURBS < 4 +#error "Not enough URBs in the gspca table" +#endif +#define SD_NPKT 32 + for (n = 0; n < 4; n++) { + i = n & 1 ? 0 : 1; + packet_size = + le16_to_cpu(alt->endpoint[i].desc.wMaxPacketSize); + urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL); + if (!urb) { + err("usb_alloc_urb failed"); + return -ENOMEM; + } + gspca_dev->urb[n] = urb; + urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, + packet_size * SD_NPKT, + GFP_KERNEL, + &urb->transfer_dma); + if (urb->transfer_buffer == NULL) { + err("usb_buffer_alloc failed"); + return -ENOMEM; + } + + urb->dev = gspca_dev->dev; + urb->context = gspca_dev; + urb->transfer_buffer_length = packet_size * SD_NPKT; + urb->pipe = usb_rcvisocpipe(gspca_dev->dev, + n & 1 ? 0x81 : 0x82); + urb->transfer_flags = URB_ISO_ASAP + | URB_NO_TRANSFER_DMA_MAP; + urb->interval = 1; + urb->complete = sd_isoc_irq; + urb->number_of_packets = SD_NPKT; + for (i = 0; i < SD_NPKT; i++) { + urb->iso_frame_desc[i].length = packet_size; + urb->iso_frame_desc[i].offset = packet_size * i; + } + } + + return 0; +} + +static void sd_stopN(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + konica_stream_off(gspca_dev); +#ifdef CONFIG_INPUT + /* Don't keep the button in the pressed state "forever" if it was + pressed when streaming is stopped */ + if (sd->snapshot_pressed) { + input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); + input_sync(gspca_dev->input_dev); + sd->snapshot_pressed = 0; + } +#endif +} + +/* reception of an URB */ +static void sd_isoc_irq(struct urb *urb) +{ + struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; + struct sd *sd = (struct sd *) gspca_dev; + struct urb *data_urb, *status_urb; + u8 *data; + int i, st; + + PDEBUG(D_PACK, "sd isoc irq"); + if (!gspca_dev->streaming) + return; + + if (urb->status != 0) { + if (urb->status == -ESHUTDOWN) + return; /* disconnection */ +#ifdef CONFIG_PM + if (gspca_dev->frozen) + return; +#endif + PDEBUG(D_ERR, "urb status: %d", urb->status); + st = usb_submit_urb(urb, GFP_ATOMIC); + if (st < 0) + PDEBUG(D_ERR|D_PACK, "resubmit urb error %d", st); + return; + } + + /* if this is a data URB (ep 0x82), wait */ + if (urb->transfer_buffer_length > 32) { + sd->last_data_urb = urb; + return; + } + + status_urb = urb; + data_urb = sd->last_data_urb; + sd->last_data_urb = NULL; + + if (!data_urb || data_urb->start_frame != status_urb->start_frame) { + PDEBUG(D_ERR|D_PACK, "lost sync on frames"); + goto resubmit; + } + + if (data_urb->number_of_packets != status_urb->number_of_packets) { + PDEBUG(D_ERR|D_PACK, + "no packets does not match, data: %d, status: %d", + data_urb->number_of_packets, + status_urb->number_of_packets); + goto resubmit; + } + + for (i = 0; i < status_urb->number_of_packets; i++) { + if (data_urb->iso_frame_desc[i].status || + status_urb->iso_frame_desc[i].status) { + PDEBUG(D_ERR|D_PACK, + "pkt %d data-status %d, status-status %d", i, + data_urb->iso_frame_desc[i].status, + status_urb->iso_frame_desc[i].status); + gspca_dev->last_packet_type = DISCARD_PACKET; + continue; + } + + if (status_urb->iso_frame_desc[i].actual_length != 1) { + PDEBUG(D_ERR|D_PACK, + "bad status packet length %d", + status_urb->iso_frame_desc[i].actual_length); + gspca_dev->last_packet_type = DISCARD_PACKET; + continue; + } + + st = *((u8 *)status_urb->transfer_buffer + + status_urb->iso_frame_desc[i].offset); + + data = (u8 *)data_urb->transfer_buffer + + data_urb->iso_frame_desc[i].offset; + + /* st: 0x80-0xff: frame start with frame number (ie 0-7f) + * otherwise: + * bit 0 0: keep packet + * 1: drop packet (padding data) + * + * bit 4 0 button not clicked + * 1 button clicked + * button is used to `take a picture' (in software) + */ + if (st & 0x80) { + gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); + gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); + } else { +#ifdef CONFIG_INPUT + u8 button_state = st & 0x40 ? 1 : 0; + if (sd->snapshot_pressed != button_state) { + input_report_key(gspca_dev->input_dev, + KEY_CAMERA, + button_state); + input_sync(gspca_dev->input_dev); + sd->snapshot_pressed = button_state; + } +#endif + if (st & 0x01) + continue; + } + gspca_frame_add(gspca_dev, INTER_PACKET, data, + data_urb->iso_frame_desc[i].actual_length); + } + +resubmit: + if (data_urb) { + st = usb_submit_urb(data_urb, GFP_ATOMIC); + if (st < 0) + PDEBUG(D_ERR|D_PACK, + "usb_submit_urb(data_urb) ret %d", st); + } + st = usb_submit_urb(status_urb, GFP_ATOMIC); + if (st < 0) + PDEBUG(D_ERR|D_PACK, "usb_submit_urb(status_urb) ret %d", st); +} + +static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->brightness = val; + if (gspca_dev->streaming) { + konica_stream_off(gspca_dev); + reg_w(gspca_dev, sd->brightness, BRIGHTNESS_REG); + konica_stream_on(gspca_dev); + } + + return 0; +} + +static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->brightness; + + return 0; +} + +static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->contrast = val; + if (gspca_dev->streaming) { + konica_stream_off(gspca_dev); + reg_w(gspca_dev, sd->contrast, CONTRAST_REG); + konica_stream_on(gspca_dev); + } + + return 0; +} + +static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->contrast; + + return 0; +} + +static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->saturation = val; + if (gspca_dev->streaming) { + konica_stream_off(gspca_dev); + reg_w(gspca_dev, sd->saturation, SATURATION_REG); + konica_stream_on(gspca_dev); + } + return 0; +} + +static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->saturation; + + return 0; +} + +static int sd_setwhitebal(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->whitebal = val; + if (gspca_dev->streaming) { + konica_stream_off(gspca_dev); + reg_w(gspca_dev, sd->whitebal, WHITEBAL_REG); + konica_stream_on(gspca_dev); + } + return 0; +} + +static int sd_getwhitebal(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->whitebal; + + return 0; +} + +static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + sd->sharpness = val; + if (gspca_dev->streaming) { + konica_stream_off(gspca_dev); + reg_w(gspca_dev, sd->sharpness, SHARPNESS_REG); + konica_stream_on(gspca_dev); + } + return 0; +} + +static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) +{ + struct sd *sd = (struct sd *) gspca_dev; + + *val = sd->sharpness; + + return 0; +} + +/* sub-driver description */ +static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), + .config = sd_config, + .init = sd_init, + .start = sd_start, + .stopN = sd_stopN, +#ifdef CONFIG_INPUT + .other_input = 1, +#endif +}; + +/* -- module initialisation -- */ +static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x04c8, 0x0720)}, /* Intel YC 76 */ + {} +}; +MODULE_DEVICE_TABLE(usb, device_table); + +/* -- device connect -- */ +static int sd_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), + THIS_MODULE); +} + +static struct usb_driver sd_driver = { + .name = MODULE_NAME, + .id_table = device_table, + .probe = sd_probe, + .disconnect = gspca_disconnect, +#ifdef CONFIG_PM + .suspend = gspca_suspend, + .resume = gspca_resume, +#endif +}; + +/* -- module insert / remove -- */ +static int __init sd_mod_init(void) +{ + int ret; + + ret = usb_register(&sd_driver); + if (ret < 0) + return ret; + info("registered"); + return 0; +} +static void __exit sd_mod_exit(void) +{ + usb_deregister(&sd_driver); + info("deregistered"); +} + +module_init(sd_mod_init); +module_exit(sd_mod_exit); diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig index e5822b1125ed..dfa7fc68a657 100644 --- a/drivers/media/video/usbvideo/Kconfig +++ b/drivers/media/video/usbvideo/Kconfig @@ -30,10 +30,13 @@ config USB_IBMCAM to learn more. config USB_KONICAWC - tristate "USB Konica Webcam support" + tristate "USB Konica Webcam support (DEPRECATED)" depends on VIDEO_V4L1 select VIDEO_USBVIDEO ---help--- + This driver is DEPRECATED (and known to crash) please use the + gspca konica module instead. + Say Y here if you want support for webcams based on a Konica chipset. This is known to work with the Intel YC76 webcam. diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 0aef67e0281a..2d5ce17ca472 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -364,6 +364,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */ #define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */ #define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */ +#define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */ /* * F O R M A T E N U M E R A T I O N -- cgit v1.2.3 From 7a569f524dd36806b995c844f29e28ff40c444b2 Mon Sep 17 00:00:00 2001 From: Jarod Wilson Date: Sat, 7 Aug 2010 13:31:40 -0300 Subject: V4L/DVB: IR/streamzap: functional in-kernel decoding This patch makes in-kernel decoding with the stock Streamzap PC Remote work out of the box. There are quite a few things going on in this patch, all related to getting this working: 1) I had to enable reporting of a long space at the end of each signal, or I had weird buffering and keybounce issues. 2) The keymap has been reworked slightly to match actual decoded values, the first edition was missing the pre-data bits present in the lirc config file for this remote. 3) There's a whole new decoder included, specifically for the not-quite-RC5 15-bit protocol variant used by the Streamzap PC Remote. The decoder, while usable with other recievers (tested with an mceusb receiver), will only be loaded by the streamzap driver, as its likely not of use in almost all other situations. This can be revisited if/when all keytable loading (and disabling of unneeded protocol decoder engines) is moved to userspace, but for now, I think this makes the most sense. Note that I did try to enable handling the streamzap RC5-ish protocol in the current RC5 decoder, but there's no particularly easy way to tell if its 14-bit RC5 or 15-bit Streamzap until we see bit 14, and even then, in testing an attempted decoder merge, only 2/3 of the keys were properly recognized as being the 15-bit variant and decoded correctly, the rest were close enough to compliant with 14-bit that they were decoded as such (but they have overlap with one another, and thus we can't just shrug and use the 14-bit decoded values). Also of note in this patch is the removal of the streamzap driver's internal delay buffer. Per discussion w/Christoph, it shouldn't be needed by lirc any longer anyway, and it doesn't seem to make any difference to the in-kernel decoder engine. That being the case, I'm yanking it all out, as it greatly simplifies the driver code. Signed-off-by: Jarod Wilson Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/Kconfig | 12 + drivers/media/IR/Makefile | 1 + drivers/media/IR/ir-core-priv.h | 6 + drivers/media/IR/ir-rc5-sz-decoder.c | 153 ++++++++++++ drivers/media/IR/ir-sysfs.c | 1 + drivers/media/IR/keymaps/Makefile | 2 +- drivers/media/IR/keymaps/rc-rc5-streamzap.c | 81 ------- drivers/media/IR/keymaps/rc-streamzap.c | 82 +++++++ drivers/media/IR/streamzap.c | 358 ++++++++-------------------- include/media/rc-map.h | 5 +- 10 files changed, 352 insertions(+), 349 deletions(-) create mode 100644 drivers/media/IR/ir-rc5-sz-decoder.c delete mode 100644 drivers/media/IR/keymaps/rc-rc5-streamzap.c create mode 100644 drivers/media/IR/keymaps/rc-streamzap.c (limited to 'include') diff --git a/drivers/media/IR/Kconfig b/drivers/media/IR/Kconfig index 490c57cc4cfe..152000db3526 100644 --- a/drivers/media/IR/Kconfig +++ b/drivers/media/IR/Kconfig @@ -79,6 +79,18 @@ config IR_SONY_DECODER Enable this option if you have an infrared remote control which uses the Sony protocol, and you need software decoding support. +config IR_RC5_SZ_DECODER + tristate "Enable IR raw decoder for the RC-5 (streamzap) protocol" + depends on IR_CORE + select BITREVERSE + default y + + ---help--- + Enable this option if you have IR with RC-5 (streamzap) protocol, + and if the IR is decoded in software. (The Streamzap PC Remote + uses an IR protocol that is almost standard RC-5, but not quite, + as it uses an additional bit). + config IR_LIRC_CODEC tristate "Enable IR to LIRC bridge" depends on IR_CORE diff --git a/drivers/media/IR/Makefile b/drivers/media/IR/Makefile index 53676838fe97..953c6c44330a 100644 --- a/drivers/media/IR/Makefile +++ b/drivers/media/IR/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o +obj-$(CONFIG_IR_RC5_SZ_DECODER) += ir-rc5-sz-decoder.o obj-$(CONFIG_IR_LIRC_CODEC) += ir-lirc-codec.o # stand-alone IR receivers/transmitters diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index a85a8c7c905a..0ad8ea39b39e 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h @@ -76,6 +76,12 @@ struct ir_raw_event_ctrl { bool first; bool toggle; } jvc; + struct rc5_sz_dec { + int state; + u32 bits; + unsigned count; + unsigned wanted_bits; + } rc5_sz; struct lirc_codec { struct ir_input_dev *ir_dev; struct lirc_driver *drv; diff --git a/drivers/media/IR/ir-rc5-sz-decoder.c b/drivers/media/IR/ir-rc5-sz-decoder.c new file mode 100644 index 000000000000..68f11d6acd5b --- /dev/null +++ b/drivers/media/IR/ir-rc5-sz-decoder.c @@ -0,0 +1,153 @@ +/* ir-rc5-sz-decoder.c - handle RC5 Streamzap IR Pulse/Space protocol + * + * Copyright (C) 2010 by Mauro Carvalho Chehab + * Copyright (C) 2010 by Jarod Wilson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * This code handles the 15 bit RC5-ish protocol used by the Streamzap + * PC Remote. + * It considers a carrier of 36 kHz, with a total of 15 bits, where + * the first two bits are start bits, and a third one is a filing bit + */ + +#include "ir-core-priv.h" + +#define RC5_SZ_NBITS 15 +#define RC5_UNIT 888888 /* ns */ +#define RC5_BIT_START (1 * RC5_UNIT) +#define RC5_BIT_END (1 * RC5_UNIT) + +enum rc5_sz_state { + STATE_INACTIVE, + STATE_BIT_START, + STATE_BIT_END, + STATE_FINISHED, +}; + +/** + * ir_rc5_sz_decode() - Decode one RC-5 Streamzap pulse or space + * @input_dev: the struct input_dev descriptor of the device + * @ev: the struct ir_raw_event descriptor of the pulse/space + * + * This function returns -EINVAL if the pulse violates the state machine + */ +static int ir_rc5_sz_decode(struct input_dev *input_dev, struct ir_raw_event ev) +{ + struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); + struct rc5_sz_dec *data = &ir_dev->raw->rc5_sz; + u8 toggle, command, system; + u32 scancode; + + if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5_SZ)) + return 0; + + if (IS_RESET(ev)) { + data->state = STATE_INACTIVE; + return 0; + } + + if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2)) + goto out; + +again: + IR_dprintk(2, "RC5-sz decode started at state %i (%uus %s)\n", + data->state, TO_US(ev.duration), TO_STR(ev.pulse)); + + if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2)) + return 0; + + switch (data->state) { + + case STATE_INACTIVE: + if (!ev.pulse) + break; + + data->state = STATE_BIT_START; + data->count = 1; + data->wanted_bits = RC5_SZ_NBITS; + decrease_duration(&ev, RC5_BIT_START); + goto again; + + case STATE_BIT_START: + if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) + break; + + data->bits <<= 1; + if (!ev.pulse) + data->bits |= 1; + data->count++; + data->state = STATE_BIT_END; + return 0; + + case STATE_BIT_END: + if (!is_transition(&ev, &ir_dev->raw->prev_ev)) + break; + + if (data->count == data->wanted_bits) + data->state = STATE_FINISHED; + else + data->state = STATE_BIT_START; + + decrease_duration(&ev, RC5_BIT_END); + goto again; + + case STATE_FINISHED: + if (ev.pulse) + break; + + /* RC5-sz */ + command = (data->bits & 0x0003F) >> 0; + system = (data->bits & 0x02FC0) >> 6; + toggle = (data->bits & 0x01000) ? 1 : 0; + scancode = system << 6 | command; + + IR_dprintk(1, "RC5-sz scancode 0x%04x (toggle: %u)\n", + scancode, toggle); + + ir_keydown(input_dev, scancode, toggle); + data->state = STATE_INACTIVE; + return 0; + } + +out: + IR_dprintk(1, "RC5-sz decode failed at state %i (%uus %s)\n", + data->state, TO_US(ev.duration), TO_STR(ev.pulse)); + data->state = STATE_INACTIVE; + return -EINVAL; +} + +static struct ir_raw_handler rc5_sz_handler = { + .protocols = IR_TYPE_RC5_SZ, + .decode = ir_rc5_sz_decode, +}; + +static int __init ir_rc5_sz_decode_init(void) +{ + ir_raw_handler_register(&rc5_sz_handler); + + printk(KERN_INFO "IR RC5 (streamzap) protocol handler initialized\n"); + return 0; +} + +static void __exit ir_rc5_sz_decode_exit(void) +{ + ir_raw_handler_unregister(&rc5_sz_handler); +} + +module_init(ir_rc5_sz_decode_init); +module_exit(ir_rc5_sz_decode_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Jarod Wilson "); +MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)"); +MODULE_DESCRIPTION("RC5 (streamzap) IR protocol decoder"); diff --git a/drivers/media/IR/ir-sysfs.c b/drivers/media/IR/ir-sysfs.c index 46d42467f9b4..be09d1995b41 100644 --- a/drivers/media/IR/ir-sysfs.c +++ b/drivers/media/IR/ir-sysfs.c @@ -43,6 +43,7 @@ static struct { { IR_TYPE_RC6, "rc-6" }, { IR_TYPE_JVC, "jvc" }, { IR_TYPE_SONY, "sony" }, + { IR_TYPE_RC5_SZ, "rc-5-sz" }, { IR_TYPE_LIRC, "lirc" }, }; diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 950e5d953c6f..c032b9d2e51a 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -58,10 +58,10 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-purpletv.o \ rc-pv951.o \ rc-rc5-hauppauge-new.o \ - rc-rc5-streamzap.o \ rc-rc5-tv.o \ rc-rc6-mce.o \ rc-real-audio-220-32-keys.o \ + rc-streamzap.o \ rc-tbs-nec.o \ rc-terratec-cinergy-xs.o \ rc-tevii-nec.o \ diff --git a/drivers/media/IR/keymaps/rc-rc5-streamzap.c b/drivers/media/IR/keymaps/rc-rc5-streamzap.c deleted file mode 100644 index 4c19c58b46d8..000000000000 --- a/drivers/media/IR/keymaps/rc-rc5-streamzap.c +++ /dev/null @@ -1,81 +0,0 @@ -/* rc-rc5-streamzap.c - Keytable for Streamzap PC Remote, for use - * with the Streamzap PC Remote IR Receiver. - * - * Copyright (c) 2010 by Jarod Wilson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -#include - -static struct ir_scancode rc5_streamzap[] = { -/* - * FIXME: The Streamzap remote isn't actually true RC-5, it has an extra - * bit in it, which presently throws the in-kernel RC-5 decoder for a loop. - * We either have to enhance the decoder to support it, add a new decoder, - * or just rely on lirc userspace decoding. - */ - { 0x00, KEY_NUMERIC_0 }, - { 0x01, KEY_NUMERIC_1 }, - { 0x02, KEY_NUMERIC_2 }, - { 0x03, KEY_NUMERIC_3 }, - { 0x04, KEY_NUMERIC_4 }, - { 0x05, KEY_NUMERIC_5 }, - { 0x06, KEY_NUMERIC_6 }, - { 0x07, KEY_NUMERIC_7 }, - { 0x08, KEY_NUMERIC_8 }, - { 0x0a, KEY_POWER }, - { 0x0b, KEY_MUTE }, - { 0x0c, KEY_CHANNELUP }, - { 0x0d, KEY_VOLUMEUP }, - { 0x0e, KEY_CHANNELDOWN }, - { 0x0f, KEY_VOLUMEDOWN }, - { 0x10, KEY_UP }, - { 0x11, KEY_LEFT }, - { 0x12, KEY_OK }, - { 0x13, KEY_RIGHT }, - { 0x14, KEY_DOWN }, - { 0x15, KEY_MENU }, - { 0x16, KEY_EXIT }, - { 0x17, KEY_PLAY }, - { 0x18, KEY_PAUSE }, - { 0x19, KEY_STOP }, - { 0x1a, KEY_BACK }, - { 0x1b, KEY_FORWARD }, - { 0x1c, KEY_RECORD }, - { 0x1d, KEY_REWIND }, - { 0x1e, KEY_FASTFORWARD }, - { 0x20, KEY_RED }, - { 0x21, KEY_GREEN }, - { 0x22, KEY_YELLOW }, - { 0x23, KEY_BLUE }, - -}; - -static struct rc_keymap rc5_streamzap_map = { - .map = { - .scan = rc5_streamzap, - .size = ARRAY_SIZE(rc5_streamzap), - .ir_type = IR_TYPE_RC5, - .name = RC_MAP_RC5_STREAMZAP, - } -}; - -static int __init init_rc_map_rc5_streamzap(void) -{ - return ir_register_map(&rc5_streamzap_map); -} - -static void __exit exit_rc_map_rc5_streamzap(void) -{ - ir_unregister_map(&rc5_streamzap_map); -} - -module_init(init_rc_map_rc5_streamzap) -module_exit(exit_rc_map_rc5_streamzap) - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Jarod Wilson "); diff --git a/drivers/media/IR/keymaps/rc-streamzap.c b/drivers/media/IR/keymaps/rc-streamzap.c new file mode 100644 index 000000000000..df32013a321c --- /dev/null +++ b/drivers/media/IR/keymaps/rc-streamzap.c @@ -0,0 +1,82 @@ +/* rc-streamzap.c - Keytable for Streamzap PC Remote, for use + * with the Streamzap PC Remote IR Receiver. + * + * Copyright (c) 2010 by Jarod Wilson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include + +static struct ir_scancode streamzap[] = { +/* + * The Streamzap remote is almost, but not quite, RC-5, as it has an extra + * bit in it, which throws the in-kernel RC-5 decoder for a loop. Currently, + * an additional RC-5-sz decoder is being deployed to support it, but it + * may be possible to merge it back with the standard RC-5 decoder. + */ + { 0x28c0, KEY_NUMERIC_0 }, + { 0x28c1, KEY_NUMERIC_1 }, + { 0x28c2, KEY_NUMERIC_2 }, + { 0x28c3, KEY_NUMERIC_3 }, + { 0x28c4, KEY_NUMERIC_4 }, + { 0x28c5, KEY_NUMERIC_5 }, + { 0x28c6, KEY_NUMERIC_6 }, + { 0x28c7, KEY_NUMERIC_7 }, + { 0x28c8, KEY_NUMERIC_8 }, + { 0x28c9, KEY_NUMERIC_9 }, + { 0x28ca, KEY_POWER }, + { 0x28cb, KEY_MUTE }, + { 0x28cc, KEY_CHANNELUP }, + { 0x28cd, KEY_VOLUMEUP }, + { 0x28ce, KEY_CHANNELDOWN }, + { 0x28cf, KEY_VOLUMEDOWN }, + { 0x28d0, KEY_UP }, + { 0x28d1, KEY_LEFT }, + { 0x28d2, KEY_OK }, + { 0x28d3, KEY_RIGHT }, + { 0x28d4, KEY_DOWN }, + { 0x28d5, KEY_MENU }, + { 0x28d6, KEY_EXIT }, + { 0x28d7, KEY_PLAY }, + { 0x28d8, KEY_PAUSE }, + { 0x28d9, KEY_STOP }, + { 0x28da, KEY_BACK }, + { 0x28db, KEY_FORWARD }, + { 0x28dc, KEY_RECORD }, + { 0x28dd, KEY_REWIND }, + { 0x28de, KEY_FASTFORWARD }, + { 0x28e0, KEY_RED }, + { 0x28e1, KEY_GREEN }, + { 0x28e2, KEY_YELLOW }, + { 0x28e3, KEY_BLUE }, + +}; + +static struct rc_keymap streamzap_map = { + .map = { + .scan = streamzap, + .size = ARRAY_SIZE(streamzap), + .ir_type = IR_TYPE_RC5_SZ, + .name = RC_MAP_STREAMZAP, + } +}; + +static int __init init_rc_map_streamzap(void) +{ + return ir_register_map(&streamzap_map); +} + +static void __exit exit_rc_map_streamzap(void) +{ + ir_unregister_map(&streamzap_map); +} + +module_init(init_rc_map_streamzap) +module_exit(exit_rc_map_streamzap) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Jarod Wilson "); diff --git a/drivers/media/IR/streamzap.c b/drivers/media/IR/streamzap.c index 058e29fd478c..2cf57e64a80b 100644 --- a/drivers/media/IR/streamzap.c +++ b/drivers/media/IR/streamzap.c @@ -38,7 +38,7 @@ #include #include -#define DRIVER_VERSION "1.60" +#define DRIVER_VERSION "1.61" #define DRIVER_NAME "streamzap" #define DRIVER_DESC "Streamzap Remote Control driver" @@ -69,6 +69,13 @@ MODULE_DEVICE_TABLE(usb, streamzap_table); /* number of samples buffered */ #define SZ_BUF_LEN 128 +/* from ir-rc5-sz-decoder.c */ +#ifdef CONFIG_IR_RC5_SZ_DECODER_MODULE +#define load_rc5_sz_decode() request_module("ir-rc5-sz-decoder") +#else +#define load_rc5_sz_decode() 0 +#endif + enum StreamzapDecoderState { PulseSpace, FullPulse, @@ -81,7 +88,6 @@ struct streamzap_ir { /* ir-core */ struct ir_dev_props *props; - struct ir_raw_event rawir; /* core device info */ struct device *dev; @@ -98,17 +104,6 @@ struct streamzap_ir { dma_addr_t dma_in; unsigned int buf_in_len; - /* timer used to support delay buffering */ - struct timer_list delay_timer; - bool timer_running; - spinlock_t timer_lock; - struct timer_list flush_timer; - bool flush; - - /* delay buffer */ - struct kfifo fifo; - bool fifo_initialized; - /* track what state we're in */ enum StreamzapDecoderState decoder_state; /* tracks whether we are currently receiving some signal */ @@ -118,7 +113,7 @@ struct streamzap_ir { /* start time of signal; necessary for gap tracking */ struct timeval signal_last; struct timeval signal_start; - /* bool timeout_enabled; */ + bool timeout_enabled; char name[128]; char phys[64]; @@ -143,122 +138,16 @@ static struct usb_driver streamzap_driver = { .id_table = streamzap_table, }; -static void streamzap_stop_timer(struct streamzap_ir *sz) -{ - unsigned long flags; - - spin_lock_irqsave(&sz->timer_lock, flags); - if (sz->timer_running) { - sz->timer_running = false; - spin_unlock_irqrestore(&sz->timer_lock, flags); - del_timer_sync(&sz->delay_timer); - } else { - spin_unlock_irqrestore(&sz->timer_lock, flags); - } -} - -static void streamzap_flush_timeout(unsigned long arg) -{ - struct streamzap_ir *sz = (struct streamzap_ir *)arg; - - dev_info(sz->dev, "%s: callback firing\n", __func__); - - /* finally start accepting data */ - sz->flush = false; -} - -static void streamzap_delay_timeout(unsigned long arg) -{ - struct streamzap_ir *sz = (struct streamzap_ir *)arg; - struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; - unsigned long flags; - int len, ret; - static unsigned long delay; - bool wake = false; - - /* deliver data every 10 ms */ - delay = msecs_to_jiffies(10); - - spin_lock_irqsave(&sz->timer_lock, flags); - - if (kfifo_len(&sz->fifo) > 0) { - ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir)); - if (ret != sizeof(rawir)) - dev_err(sz->dev, "Problem w/kfifo_out...\n"); - ir_raw_event_store(sz->idev, &rawir); - wake = true; - } - - len = kfifo_len(&sz->fifo); - if (len > 0) { - while ((len < SZ_BUF_LEN / 2) && - (len < SZ_BUF_LEN * sizeof(int))) { - ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir)); - if (ret != sizeof(rawir)) - dev_err(sz->dev, "Problem w/kfifo_out...\n"); - ir_raw_event_store(sz->idev, &rawir); - wake = true; - len = kfifo_len(&sz->fifo); - } - if (sz->timer_running) - mod_timer(&sz->delay_timer, jiffies + delay); - - } else { - sz->timer_running = false; - } - - if (wake) - ir_raw_event_handle(sz->idev); - - spin_unlock_irqrestore(&sz->timer_lock, flags); -} - -static void streamzap_flush_delay_buffer(struct streamzap_ir *sz) +static void sz_push(struct streamzap_ir *sz, struct ir_raw_event rawir) { - struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; - bool wake = false; - int ret; - - while (kfifo_len(&sz->fifo) > 0) { - ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir)); - if (ret != sizeof(rawir)) - dev_err(sz->dev, "Problem w/kfifo_out...\n"); - ir_raw_event_store(sz->idev, &rawir); - wake = true; - } - - if (wake) - ir_raw_event_handle(sz->idev); -} - -static void sz_push(struct streamzap_ir *sz) -{ - struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; - unsigned long flags; - int ret; - - spin_lock_irqsave(&sz->timer_lock, flags); - if (kfifo_len(&sz->fifo) >= sizeof(int) * SZ_BUF_LEN) { - ret = kfifo_out(&sz->fifo, &rawir, sizeof(rawir)); - if (ret != sizeof(rawir)) - dev_err(sz->dev, "Problem w/kfifo_out...\n"); - ir_raw_event_store(sz->idev, &rawir); - } - - kfifo_in(&sz->fifo, &sz->rawir, sizeof(rawir)); - - if (!sz->timer_running) { - sz->delay_timer.expires = jiffies + (HZ / 10); - add_timer(&sz->delay_timer); - sz->timer_running = true; - } - - spin_unlock_irqrestore(&sz->timer_lock, flags); + ir_raw_event_store(sz->idev, &rawir); } static void sz_push_full_pulse(struct streamzap_ir *sz, unsigned char value) { + struct ir_raw_event rawir; + if (sz->idle) { long deltv; @@ -266,33 +155,33 @@ static void sz_push_full_pulse(struct streamzap_ir *sz, do_gettimeofday(&sz->signal_start); deltv = sz->signal_start.tv_sec - sz->signal_last.tv_sec; - sz->rawir.pulse = false; + rawir.pulse = false; if (deltv > 15) { /* really long time */ - sz->rawir.duration = IR_MAX_DURATION; + rawir.duration = IR_MAX_DURATION; } else { - sz->rawir.duration = (int)(deltv * 1000000 + + rawir.duration = (int)(deltv * 1000000 + sz->signal_start.tv_usec - sz->signal_last.tv_usec); - sz->rawir.duration -= sz->sum; - sz->rawir.duration *= 1000; - sz->rawir.duration &= IR_MAX_DURATION; + rawir.duration -= sz->sum; + rawir.duration *= 1000; + rawir.duration &= IR_MAX_DURATION; } - dev_dbg(sz->dev, "ls %u\n", sz->rawir.duration); - sz_push(sz); + dev_dbg(sz->dev, "ls %u\n", rawir.duration); + sz_push(sz, rawir); - sz->idle = 0; + sz->idle = false; sz->sum = 0; } - sz->rawir.pulse = true; - sz->rawir.duration = ((int) value) * STREAMZAP_RESOLUTION; - sz->rawir.duration += STREAMZAP_RESOLUTION / 2; - sz->sum += sz->rawir.duration; - sz->rawir.duration *= 1000; - sz->rawir.duration &= IR_MAX_DURATION; - dev_dbg(sz->dev, "p %u\n", sz->rawir.duration); - sz_push(sz); + rawir.pulse = true; + rawir.duration = ((int) value) * STREAMZAP_RESOLUTION; + rawir.duration += STREAMZAP_RESOLUTION / 2; + sz->sum += rawir.duration; + rawir.duration *= 1000; + rawir.duration &= IR_MAX_DURATION; + dev_dbg(sz->dev, "p %u\n", rawir.duration); + sz_push(sz, rawir); } static void sz_push_half_pulse(struct streamzap_ir *sz, @@ -304,13 +193,15 @@ static void sz_push_half_pulse(struct streamzap_ir *sz, static void sz_push_full_space(struct streamzap_ir *sz, unsigned char value) { - sz->rawir.pulse = false; - sz->rawir.duration = ((int) value) * STREAMZAP_RESOLUTION; - sz->rawir.duration += STREAMZAP_RESOLUTION / 2; - sz->sum += sz->rawir.duration; - sz->rawir.duration *= 1000; - dev_dbg(sz->dev, "s %u\n", sz->rawir.duration); - sz_push(sz); + struct ir_raw_event rawir; + + rawir.pulse = false; + rawir.duration = ((int) value) * STREAMZAP_RESOLUTION; + rawir.duration += STREAMZAP_RESOLUTION / 2; + sz->sum += rawir.duration; + rawir.duration *= 1000; + dev_dbg(sz->dev, "s %u\n", rawir.duration); + sz_push(sz, rawir); } static void sz_push_half_space(struct streamzap_ir *sz, @@ -330,10 +221,8 @@ static void streamzap_callback(struct urb *urb) struct streamzap_ir *sz; unsigned int i; int len; - #if 0 static int timeout = (((STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION) & IR_MAX_DURATION) | 0x03000000); - #endif if (!urb) return; @@ -356,57 +245,53 @@ static void streamzap_callback(struct urb *urb) } dev_dbg(sz->dev, "%s: received urb, len %d\n", __func__, len); - if (!sz->flush) { - for (i = 0; i < urb->actual_length; i++) { - dev_dbg(sz->dev, "%d: %x\n", i, - (unsigned char)sz->buf_in[i]); - switch (sz->decoder_state) { - case PulseSpace: - if ((sz->buf_in[i] & STREAMZAP_PULSE_MASK) == - STREAMZAP_PULSE_MASK) { - sz->decoder_state = FullPulse; - continue; - } else if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK) - == STREAMZAP_SPACE_MASK) { - sz_push_half_pulse(sz, sz->buf_in[i]); - sz->decoder_state = FullSpace; - continue; - } else { - sz_push_half_pulse(sz, sz->buf_in[i]); - sz_push_half_space(sz, sz->buf_in[i]); - } - break; - case FullPulse: - sz_push_full_pulse(sz, sz->buf_in[i]); - sz->decoder_state = IgnorePulse; - break; - case FullSpace: - if (sz->buf_in[i] == STREAMZAP_TIMEOUT) { - sz->idle = 1; - streamzap_stop_timer(sz); - #if 0 - if (sz->timeout_enabled) { - sz->rawir.pulse = false; - sz->rawir.duration = timeout; - sz->rawir.duration *= 1000; - sz_push(sz); - } - #endif - streamzap_flush_delay_buffer(sz); - } else - sz_push_full_space(sz, sz->buf_in[i]); - sz->decoder_state = PulseSpace; - break; - case IgnorePulse: - if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) == - STREAMZAP_SPACE_MASK) { - sz->decoder_state = FullSpace; - continue; - } + for (i = 0; i < len; i++) { + dev_dbg(sz->dev, "sz idx %d: %x\n", + i, (unsigned char)sz->buf_in[i]); + switch (sz->decoder_state) { + case PulseSpace: + if ((sz->buf_in[i] & STREAMZAP_PULSE_MASK) == + STREAMZAP_PULSE_MASK) { + sz->decoder_state = FullPulse; + continue; + } else if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK) + == STREAMZAP_SPACE_MASK) { + sz_push_half_pulse(sz, sz->buf_in[i]); + sz->decoder_state = FullSpace; + continue; + } else { + sz_push_half_pulse(sz, sz->buf_in[i]); sz_push_half_space(sz, sz->buf_in[i]); - sz->decoder_state = PulseSpace; - break; } + break; + case FullPulse: + sz_push_full_pulse(sz, sz->buf_in[i]); + sz->decoder_state = IgnorePulse; + break; + case FullSpace: + if (sz->buf_in[i] == STREAMZAP_TIMEOUT) { + struct ir_raw_event rawir; + + rawir.pulse = false; + rawir.duration = timeout * 1000; + sz->idle = true; + if (sz->timeout_enabled) + sz_push(sz, rawir); + ir_raw_event_handle(sz->idev); + } else { + sz_push_full_space(sz, sz->buf_in[i]); + } + sz->decoder_state = PulseSpace; + break; + case IgnorePulse: + if ((sz->buf_in[i] & STREAMZAP_SPACE_MASK) == + STREAMZAP_SPACE_MASK) { + sz->decoder_state = FullSpace; + continue; + } + sz_push_half_space(sz, sz->buf_in[i]); + sz->decoder_state = PulseSpace; + break; } } @@ -446,12 +331,11 @@ static struct input_dev *streamzap_init_input_dev(struct streamzap_ir *sz) props->priv = sz; props->driver_type = RC_DRIVER_IR_RAW; - /* FIXME: not sure about supported protocols, check on this */ - props->allowed_protos = IR_TYPE_RC5 | IR_TYPE_RC6; + props->allowed_protos = IR_TYPE_ALL; sz->props = props; - ret = ir_input_register(idev, RC_MAP_RC5_STREAMZAP, props, DRIVER_NAME); + ret = ir_input_register(idev, RC_MAP_STREAMZAP, props, DRIVER_NAME); if (ret < 0) { dev_err(dev, "remote input device register failed\n"); goto irdev_failed; @@ -467,29 +351,6 @@ idev_alloc_failed: return NULL; } -static int streamzap_delay_buf_init(struct streamzap_ir *sz) -{ - int ret; - - ret = kfifo_alloc(&sz->fifo, sizeof(int) * SZ_BUF_LEN, - GFP_KERNEL); - if (ret == 0) - sz->fifo_initialized = 1; - - return ret; -} - -static void streamzap_start_flush_timer(struct streamzap_ir *sz) -{ - sz->flush_timer.expires = jiffies + HZ; - sz->flush = true; - add_timer(&sz->flush_timer); - - sz->urb_in->dev = sz->usbdev; - if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) - dev_err(sz->dev, "urb submit failed\n"); -} - /** * streamzap_probe * @@ -575,35 +436,21 @@ static int __devinit streamzap_probe(struct usb_interface *intf, snprintf(name + strlen(name), sizeof(name) - strlen(name), " %s", buf); - retval = streamzap_delay_buf_init(sz); - if (retval) { - dev_err(&intf->dev, "%s: delay buffer init failed\n", __func__); - goto free_urb_in; - } - sz->idev = streamzap_init_input_dev(sz); if (!sz->idev) goto input_dev_fail; sz->idle = true; sz->decoder_state = PulseSpace; + /* FIXME: don't yet have a way to set this */ + sz->timeout_enabled = true; #if 0 /* not yet supported, depends on patches from maxim */ /* see also: LIRC_GET_REC_RESOLUTION and LIRC_SET_REC_TIMEOUT */ - sz->timeout_enabled = false; sz->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000; sz->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION * 1000; #endif - init_timer(&sz->delay_timer); - sz->delay_timer.function = streamzap_delay_timeout; - sz->delay_timer.data = (unsigned long)sz; - spin_lock_init(&sz->timer_lock); - - init_timer(&sz->flush_timer); - sz->flush_timer.function = streamzap_flush_timeout; - sz->flush_timer.data = (unsigned long)sz; - do_gettimeofday(&sz->signal_start); /* Complete final initialisations */ @@ -615,16 +462,18 @@ static int __devinit streamzap_probe(struct usb_interface *intf, usb_set_intfdata(intf, sz); - streamzap_start_flush_timer(sz); + if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) + dev_err(sz->dev, "urb submit failed\n"); dev_info(sz->dev, "Registered %s on usb%d:%d\n", name, usbdev->bus->busnum, usbdev->devnum); + /* Load the streamzap not-quite-rc5 decoder too */ + load_rc5_sz_decode(); + return 0; input_dev_fail: - kfifo_free(&sz->fifo); -free_urb_in: usb_free_urb(sz->urb_in); free_buf_in: usb_free_coherent(usbdev, maxp, sz->buf_in, sz->dma_in); @@ -654,13 +503,6 @@ static void streamzap_disconnect(struct usb_interface *interface) if (!sz) return; - if (sz->flush) { - sz->flush = false; - del_timer_sync(&sz->flush_timer); - } - - streamzap_stop_timer(sz); - sz->usbdev = NULL; ir_input_unregister(sz->idev); usb_kill_urb(sz->urb_in); @@ -674,13 +516,6 @@ static int streamzap_suspend(struct usb_interface *intf, pm_message_t message) { struct streamzap_ir *sz = usb_get_intfdata(intf); - if (sz->flush) { - sz->flush = false; - del_timer_sync(&sz->flush_timer); - } - - streamzap_stop_timer(sz); - usb_kill_urb(sz->urb_in); return 0; @@ -690,13 +525,6 @@ static int streamzap_resume(struct usb_interface *intf) { struct streamzap_ir *sz = usb_get_intfdata(intf); - if (sz->fifo_initialized) - kfifo_reset(&sz->fifo); - - sz->flush_timer.expires = jiffies + HZ; - sz->flush = true; - add_timer(&sz->flush_timer); - if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) { dev_err(sz->dev, "Error sumbiting urb\n"); return -EIO; diff --git a/include/media/rc-map.h b/include/media/rc-map.h index a9c041d49662..6c0324eb4914 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -17,12 +17,13 @@ #define IR_TYPE_RC6 (1 << 2) /* Philips RC6 protocol */ #define IR_TYPE_JVC (1 << 3) /* JVC protocol */ #define IR_TYPE_SONY (1 << 4) /* Sony12/15/20 protocol */ +#define IR_TYPE_RC5_SZ (1 << 5) /* RC5 variant used by Streamzap */ #define IR_TYPE_LIRC (1 << 30) /* Pass raw IR to lirc userspace */ #define IR_TYPE_OTHER (1u << 31) #define IR_TYPE_ALL (IR_TYPE_RC5 | IR_TYPE_NEC | IR_TYPE_RC6 | \ IR_TYPE_JVC | IR_TYPE_SONY | IR_TYPE_LIRC | \ - IR_TYPE_OTHER) + IR_TYPE_RC5_SZ | IR_TYPE_OTHER) struct ir_scancode { u32 scancode; @@ -114,10 +115,10 @@ void rc_map_init(void); #define RC_MAP_PURPLETV "rc-purpletv" #define RC_MAP_PV951 "rc-pv951" #define RC_MAP_RC5_HAUPPAUGE_NEW "rc-rc5-hauppauge-new" -#define RC_MAP_RC5_STREAMZAP "rc-rc5-streamzap" #define RC_MAP_RC5_TV "rc-rc5-tv" #define RC_MAP_RC6_MCE "rc-rc6-mce" #define RC_MAP_REAL_AUDIO_220_32_KEYS "rc-real-audio-220-32-keys" +#define RC_MAP_STREAMZAP "rc-streamzap" #define RC_MAP_TBS_NEC "rc-tbs-nec" #define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" #define RC_MAP_TEVII_NEC "rc-tevii-nec" -- cgit v1.2.3 From 6c2d4dd139de417d18151b98c157aa35387038a3 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Thu, 12 Aug 2010 17:16:00 -0300 Subject: V4L/DVB: V4L2: avoid name conflicts in macros "sd" and "err" are too common names to be used in macros for local variables. Prefix them with an underscore to avoid name clashing. [mchehab@redhat.com: whitespace cleanups] Signed-off-by: Guennadi Liakhovetski Reviewed-by: Andy Walls Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/cx18/cx18-driver.h | 19 ++++++++---- drivers/media/video/ivtv/ivtv-driver.h | 14 +++++++-- include/media/v4l2-device.h | 57 +++++++++++++++++++++++----------- 3 files changed, 63 insertions(+), 27 deletions(-) (limited to 'include') diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h index 9bc51a99376b..77be58c1096b 100644 --- a/drivers/media/video/cx18/cx18-driver.h +++ b/drivers/media/video/cx18/cx18-driver.h @@ -674,18 +674,25 @@ static inline int cx18_raw_vbi(const struct cx18 *cx) /* Call the specified callback for all subdevs with a grp_id bit matching the * mask in hw (if 0, then match them all). Ignore any errors. */ -#define cx18_call_hw(cx, hw, o, f, args...) \ - __v4l2_device_call_subdevs(&(cx)->v4l2_dev, \ - !(hw) || (sd->grp_id & (hw)), o, f , ##args) +#define cx18_call_hw(cx, hw, o, f, args...) \ + do { \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_p(&(cx)->v4l2_dev, __sd, \ + !(hw) || (__sd->grp_id & (hw)), o, f , ##args); \ + } while (0) #define cx18_call_all(cx, o, f, args...) cx18_call_hw(cx, 0, o, f , ##args) /* Call the specified callback for all subdevs with a grp_id bit matching the * mask in hw (if 0, then match them all). If the callback returns an error * other than 0 or -ENOIOCTLCMD, then return with that error code. */ -#define cx18_call_hw_err(cx, hw, o, f, args...) \ - __v4l2_device_call_subdevs_until_err( \ - &(cx)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args) +#define cx18_call_hw_err(cx, hw, o, f, args...) \ +({ \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_until_err_p(&(cx)->v4l2_dev, \ + __sd, !(hw) || (__sd->grp_id & (hw)), o, f, \ + ##args); \ +}) #define cx18_call_all_err(cx, o, f, args...) \ cx18_call_hw_err(cx, 0, o, f , ##args) diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h index 75803141481e..04bacdbd10bb 100644 --- a/drivers/media/video/ivtv/ivtv-driver.h +++ b/drivers/media/video/ivtv/ivtv-driver.h @@ -811,15 +811,23 @@ static inline int ivtv_raw_vbi(const struct ivtv *itv) /* Call the specified callback for all subdevs matching hw (if 0, then match them all). Ignore any errors. */ #define ivtv_call_hw(itv, hw, o, f, args...) \ - __v4l2_device_call_subdevs(&(itv)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args) + do { \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_p(&(itv)->v4l2_dev, __sd, \ + !(hw) || (__sd->grp_id & (hw)), o, f , ##args); \ + } while (0) #define ivtv_call_all(itv, o, f, args...) ivtv_call_hw(itv, 0, o, f , ##args) /* Call the specified callback for all subdevs matching hw (if 0, then match them all). If the callback returns an error other than 0 or -ENOIOCTLCMD, then return with that error code. */ -#define ivtv_call_hw_err(itv, hw, o, f, args...) \ - __v4l2_device_call_subdevs_until_err(&(itv)->v4l2_dev, !(hw) || (sd->grp_id & (hw)), o, f , ##args) +#define ivtv_call_hw_err(itv, hw, o, f, args...) \ +({ \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_until_err_p(&(itv)->v4l2_dev, __sd, \ + !(hw) || (__sd->grp_id & (hw)), o, f , ##args); \ +}) #define ivtv_call_all_err(itv, o, f, args...) ivtv_call_hw_err(itv, 0, o, f , ##args) diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h index 8bcbd7a0271c..6648036b728d 100644 --- a/include/media/v4l2-device.h +++ b/include/media/v4l2-device.h @@ -101,46 +101,67 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd); /* Call the specified callback for all subdevs matching the condition. Ignore any errors. Note that you cannot add or delete a subdev while walking the subdevs list. */ -#define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...) \ +#define __v4l2_device_call_subdevs_p(v4l2_dev, sd, cond, o, f, args...) \ do { \ - struct v4l2_subdev *sd; \ + list_for_each_entry((sd), &(v4l2_dev)->subdevs, list) \ + if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \ + (sd)->ops->o->f((sd) , ##args); \ + } while (0) + +#define __v4l2_device_call_subdevs(v4l2_dev, cond, o, f, args...) \ + do { \ + struct v4l2_subdev *__sd; \ \ - list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) \ - if ((cond) && sd->ops->o && sd->ops->o->f) \ - sd->ops->o->f(sd , ##args); \ + __v4l2_device_call_subdevs_p(v4l2_dev, __sd, cond, o, \ + f , ##args); \ } while (0) /* Call the specified callback for all subdevs matching the condition. If the callback returns an error other than 0 or -ENOIOCTLCMD, then return with that error code. Note that you cannot add or delete a subdev while walking the subdevs list. */ -#define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \ +#define __v4l2_device_call_subdevs_until_err_p(v4l2_dev, sd, cond, o, f, args...) \ ({ \ - struct v4l2_subdev *sd; \ - long err = 0; \ + long __err = 0; \ \ - list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) { \ - if ((cond) && sd->ops->o && sd->ops->o->f) \ - err = sd->ops->o->f(sd , ##args); \ - if (err && err != -ENOIOCTLCMD) \ + list_for_each_entry((sd), &(v4l2_dev)->subdevs, list) { \ + if ((cond) && (sd)->ops->o && (sd)->ops->o->f) \ + __err = (sd)->ops->o->f((sd) , ##args); \ + if (__err && __err != -ENOIOCTLCMD) \ break; \ } \ - (err == -ENOIOCTLCMD) ? 0 : err; \ + (__err == -ENOIOCTLCMD) ? 0 : __err; \ +}) + +#define __v4l2_device_call_subdevs_until_err(v4l2_dev, cond, o, f, args...) \ +({ \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, cond, o, \ + f, args...); \ }) /* Call the specified callback for all subdevs matching grp_id (if 0, then match them all). Ignore any errors. Note that you cannot add or delete a subdev while walking the subdevs list. */ -#define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) \ - __v4l2_device_call_subdevs(v4l2_dev, \ - !(grpid) || sd->grp_id == (grpid), o, f , ##args) +#define v4l2_device_call_all(v4l2_dev, grpid, o, f, args...) \ + do { \ + struct v4l2_subdev *__sd; \ + \ + __v4l2_device_call_subdevs_p(v4l2_dev, __sd, \ + !(grpid) || __sd->grp_id == (grpid), o, f , \ + ##args); \ + } while (0) /* Call the specified callback for all subdevs matching grp_id (if 0, then match them all). If the callback returns an error other than 0 or -ENOIOCTLCMD, then return with that error code. Note that you cannot add or delete a subdev while walking the subdevs list. */ #define v4l2_device_call_until_err(v4l2_dev, grpid, o, f, args...) \ - __v4l2_device_call_subdevs_until_err(v4l2_dev, \ - !(grpid) || sd->grp_id == (grpid), o, f , ##args) +({ \ + struct v4l2_subdev *__sd; \ + __v4l2_device_call_subdevs_until_err_p(v4l2_dev, __sd, \ + !(grpid) || __sd->grp_id == (grpid), o, f , \ + ##args); \ +}) #endif -- cgit v1.2.3 From 692d5522646fdf432329efbe5092dc9c5ca83e85 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 30 Jul 2010 17:24:55 -0300 Subject: V4L/DVB: v4l: Add a v4l2_subdev host private data field The existing priv field stores subdev private data owned by the subdev driver. Host (bridge) drivers might need to store per-subdev host-specific data, such as a pointer to platform data. Add a v4l2_subdev host_priv field to store host-specific data, and rename the existing priv field to dev_priv. Signed-off-by: Laurent Pinchart Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- Documentation/video4linux/v4l2-framework.txt | 5 +++++ include/media/v4l2-subdev.h | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index e831aaca66f8..f5fdb395287f 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt @@ -192,6 +192,11 @@ You also need a way to go from the low-level struct to v4l2_subdev. For the common i2c_client struct the i2c_set_clientdata() call is used to store a v4l2_subdev pointer, for other busses you may have to use other methods. +Bridges might also need to store per-subdev private data, such as a pointer to +bridge-specific per-subdev private data. The v4l2_subdev structure provides +host private data for that purpose that can be accessed with +v4l2_get_subdev_hostdata() and v4l2_set_subdev_hostdata(). + From the bridge driver perspective you load the sub-device module and somehow obtain the v4l2_subdev pointer. For i2c devices this is easy: you call i2c_get_clientdata(). For other busses something similar needs to be done. diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 905879d7742f..b0316a7cf08d 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -438,17 +438,28 @@ struct v4l2_subdev { /* can be used to group similar subdevs, value is driver-specific */ u32 grp_id; /* pointer to private data */ - void *priv; + void *dev_priv; + void *host_priv; }; static inline void v4l2_set_subdevdata(struct v4l2_subdev *sd, void *p) { - sd->priv = p; + sd->dev_priv = p; } static inline void *v4l2_get_subdevdata(const struct v4l2_subdev *sd) { - return sd->priv; + return sd->dev_priv; +} + +static inline void v4l2_set_subdev_hostdata(struct v4l2_subdev *sd, void *p) +{ + sd->host_priv = p; +} + +static inline void *v4l2_get_subdev_hostdata(const struct v4l2_subdev *sd) +{ + return sd->host_priv; } static inline void v4l2_subdev_init(struct v4l2_subdev *sd, @@ -462,7 +473,8 @@ static inline void v4l2_subdev_init(struct v4l2_subdev *sd, sd->flags = 0; sd->name[0] = '\0'; sd->grp_id = 0; - sd->priv = NULL; + sd->dev_priv = NULL; + sd->host_priv = NULL; } /* Call an ops of a v4l2_subdev, doing the right checks against -- cgit v1.2.3 From d2f918bba7a482bee18cc0ede7791f7d846dd5d0 Mon Sep 17 00:00:00 2001 From: Malcolm Priestley Date: Thu, 2 Sep 2010 17:29:30 -0300 Subject: V4L/DVB: Support or LME2510(C) DM04/QQBOX USB DVB-S BOXES DM04/QQBOX DVB-S USB BOX with LME2510C+SHARP:BS2F7HZ7395 or LME2510+LGTDQT-P001F tuner. [mchehab@redhat.com: Fix merge conflicts/compilation and CodingStyle issues] Signed-off-by: Malcolm Priestley Signed-off-by: Mauro Carvalho Chehab --- Documentation/dvb/get_dvb_firmware | 46 +- Documentation/dvb/lmedm04.txt | 55 ++ drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-lme2510.c | 68 +++ drivers/media/dvb/dvb-usb/Kconfig | 11 + drivers/media/dvb/dvb-usb/Makefile | 3 + drivers/media/dvb/dvb-usb/lmedm04.c | 936 ++++++++++++++++++++++++++++++++++ drivers/media/dvb/dvb-usb/lmedm04.h | 187 +++++++ include/media/rc-map.h | 1 + 9 files changed, 1307 insertions(+), 1 deletion(-) create mode 100644 Documentation/dvb/lmedm04.txt create mode 100644 drivers/media/IR/keymaps/rc-lme2510.c create mode 100644 drivers/media/dvb/dvb-usb/lmedm04.c create mode 100644 drivers/media/dvb/dvb-usb/lmedm04.h (limited to 'include') diff --git a/Documentation/dvb/get_dvb_firmware b/Documentation/dvb/get_dvb_firmware index 350959f4e41b..59690de8ebfe 100644 --- a/Documentation/dvb/get_dvb_firmware +++ b/Documentation/dvb/get_dvb_firmware @@ -26,7 +26,8 @@ use IO::Handle; "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", "or51211", "or51132_qam", "or51132_vsb", "bluebird", "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2", "mpc718", - "af9015", "ngene", "az6027"); + "af9015", "ngene", "az6027", "lme2510_lg", "lme2510c_s7395", + "lme2510c_s7395_old"); # Check args syntax() if (scalar(@ARGV) != 1); @@ -584,6 +585,49 @@ sub az6027{ $firmware; } + +sub lme2510_lg { + my $sourcefile = "LMEBDA_DVBS.sys"; + my $hash = "fc6017ad01e79890a97ec53bea157ed2"; + my $outfile = "dvb-usb-lme2510-lg.fw"; + my $hasho = "caa065d5fdbd2c09ad57b399bbf55cad"; + + checkstandard(); + + verify($sourcefile, $hash); + extract($sourcefile, 4168, 3841, $outfile); + verify($outfile, $hasho); + $outfile; +} + +sub lme2510c_s7395 { + my $sourcefile = "US2A0D.sys"; + my $hash = "b0155a8083fb822a3bd47bc360e74601"; + my $outfile = "dvb-usb-lme2510c-s7395.fw"; + my $hasho = "3a3cf1aeebd17b6ddc04cebe131e94cf"; + + checkstandard(); + + verify($sourcefile, $hash); + extract($sourcefile, 37248, 3720, $outfile); + verify($outfile, $hasho); + $outfile; +} + +sub lme2510c_s7395_old { + my $sourcefile = "LMEBDA_DVBS7395C.sys"; + my $hash = "7572ae0eb9cdf91baabd7c0ba9e09b31"; + my $outfile = "dvb-usb-lme2510c-s7395.fw"; + my $hasho = "90430c5b435eb5c6f88fd44a9d950674"; + + checkstandard(); + + verify($sourcefile, $hash); + extract($sourcefile, 4208, 3881, $outfile); + verify($outfile, $hasho); + $outfile; +} + # --------------------------------------------------------------- # Utilities diff --git a/Documentation/dvb/lmedm04.txt b/Documentation/dvb/lmedm04.txt new file mode 100644 index 000000000000..4bde457fafc4 --- /dev/null +++ b/Documentation/dvb/lmedm04.txt @@ -0,0 +1,55 @@ +To extract firmware for the DM04/QQBOX you need to copy the +following file(s) to this directory. + +for DM04+/QQBOX LME2510C (Sharp 7395 Tuner) +------------------------------------------- + +The Sharp 7395 driver can be found in windows/system32/driver + +US2A0D.sys (dated 17 Mar 2009) + + +and run +./get_dvb_firmware lme2510c_s7395 + + will produce + dvb-usb-lme2510c-s7395.fw + +An alternative but older firmware can be found on the driver +disk DVB-S_EN_3.5A in BDADriver/driver + +LMEBDA_DVBS7395C.sys (dated 18 Jan 2008) + +and run +./get_dvb_firmware lme2510c_s7395_old + + will produce + dvb-usb-lme2510c-s7395.fw + +-------------------------------------------------------------------- + +The LG firmware can be found on the driver +disk DM04+_5.1A[LG] in BDADriver/driver + +for DM04 LME2510 (LG Tuner) +--------------------------- + +LMEBDA_DVBS.sys (dated 13 Nov 2007) + +and run +./get_dvb_firmware lme2510_lg + + will produce + dvb-usb-lme2510-lg.fw + + +Other LG firmware can be extracted manually from US280D.sys +only found in windows/system32/driver. +However, this firmware does not run very well under Windows +or with the Linux driver. + +dd if=US280D.sys ibs=1 skip=36856 count=3976 of=dvb-usb-lme2510-lg.fw + +--------------------------------------------------------------------- + +Copy the firmware file(s) to /lib/firmware diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index c032b9d2e51a..f755b21eef1a 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-kworld-315u.o \ rc-kworld-plus-tv-analog.o \ rc-lirc.o \ + rc-lme2510.o \ rc-manli.o \ rc-msi-tvanywhere.o \ rc-msi-tvanywhere-plus.o \ diff --git a/drivers/media/IR/keymaps/rc-lme2510.c b/drivers/media/IR/keymaps/rc-lme2510.c new file mode 100644 index 000000000000..40dcf0b4e21a --- /dev/null +++ b/drivers/media/IR/keymaps/rc-lme2510.c @@ -0,0 +1,68 @@ +/* LME2510 remote control + * + * + * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include + + +static struct ir_scancode lme2510_rc[] = { + { 0xba45, KEY_0 }, + { 0xa05f, KEY_1 }, + { 0xaf50, KEY_2 }, + { 0xa25d, KEY_3 }, + { 0xbe41, KEY_4 }, + { 0xf50a, KEY_5 }, + { 0xbd42, KEY_6 }, + { 0xb847, KEY_7 }, + { 0xb649, KEY_8 }, + { 0xfa05, KEY_9 }, + { 0xbc43, KEY_POWER }, + { 0xb946, KEY_SUBTITLE }, + { 0xf906, KEY_PAUSE }, + { 0xfc03, KEY_MEDIA_REPEAT}, + { 0xfd02, KEY_PAUSE }, + { 0xa15e, KEY_VOLUMEUP }, + { 0xa35c, KEY_VOLUMEDOWN }, + { 0xf609, KEY_CHANNELUP }, + { 0xe51a, KEY_CHANNELDOWN }, + { 0xe11e, KEY_PLAY }, + { 0xe41b, KEY_ZOOM }, + { 0xa659, KEY_MUTE }, + { 0xa55a, KEY_TV }, + { 0xe718, KEY_RECORD }, + { 0xf807, KEY_EPG }, + { 0xfe01, KEY_STOP }, + +}; + +static struct rc_keymap lme2510_map = { + .map = { + .scan = lme2510_rc, + .size = ARRAY_SIZE(lme2510_rc), + .ir_type = IR_TYPE_UNKNOWN, + .name = RC_MAP_LME2510, + } +}; + +static int __init init_rc_lme2510_map(void) +{ + return ir_register_map(&lme2510_map); +} + +static void __exit exit_rc_lme2510_map(void) +{ + ir_unregister_map(&lme2510_map); +} + +module_init(init_rc_lme2510_map) +module_exit(exit_rc_lme2510_map) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Malcolm Priestley tvboxspy@gmail.com"); diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig index c57f828e1eb9..4734ec073e01 100644 --- a/drivers/media/dvb/dvb-usb/Kconfig +++ b/drivers/media/dvb/dvb-usb/Kconfig @@ -347,3 +347,14 @@ config DVB_USB_AZ6027 select DVB_STB6100 if !DVB_FE_CUSTOMISE help Say Y here to support the AZ6027 device + +config DVB_USB_LME2510 + tristate "LME DM04/QQBOX DVB-S USB2.0 support" + depends on DVB_USB + select DVB_TDA10086 if !DVB_FE_CUSTOMISE + select DVB_TDA826X if !DVB_FE_CUSTOMISE + select DVB_STV0288 if !DVB_FE_CUSTOMISE + select DVB_IX2505V if !DVB_FE_CUSTOMISE + depends on IR_CORE + help + Say Y here to support the LME DM04/QQBOX DVB-S USB2.0 . diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile index 1a192453b0e7..5b1d12f2d591 100644 --- a/drivers/media/dvb/dvb-usb/Makefile +++ b/drivers/media/dvb/dvb-usb/Makefile @@ -88,6 +88,9 @@ obj-$(CONFIG_DVB_USB_EC168) += dvb-usb-ec168.o dvb-usb-az6027-objs = az6027.o obj-$(CONFIG_DVB_USB_AZ6027) += dvb-usb-az6027.o +dvb-usb-lmedm04-objs = lmedm04.o +obj-$(CONFIG_DVB_USB_LME2510) += dvb-usb-lmedm04.o + EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ # due to tuner-xc3028 EXTRA_CFLAGS += -Idrivers/media/common/tuners diff --git a/drivers/media/dvb/dvb-usb/lmedm04.c b/drivers/media/dvb/dvb-usb/lmedm04.c new file mode 100644 index 000000000000..d5374ac075d3 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/lmedm04.c @@ -0,0 +1,936 @@ +/* DVB USB compliant linux driver for + * + * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395 + * LME2510 + LGTDQT-P001F + * + * MVB7395 (LME2510C+SHARP:BS2F7HZ7395) + * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V) + * + * MV001F (LME2510 +LGTDQY-P001F) + * LG TDQY - P001F =(TDA8263 + TDA10086H) + * + * For firmware see Documentation/dvb/lmedm04.txt + * + * I2C addresses: + * 0xd0 - STV0288 - Demodulator + * 0xc0 - Sharp IX2505V - Tuner + * --or-- + * 0x1c - TDA10086 - Demodulator + * 0xc0 - TDA8263 - Tuner + * + * ***Please Note*** + * There are other variants of the DM04 + * ***NOT SUPPORTED*** + * MVB0001F (LME2510C+LGTDQT-P001F) + * MV0194 (LME2510+SHARP0194) + * MVB0194 (LME2510C+SHARP0194) + * + * + * VID = 3344 PID LME2510=1122 LME2510C=1120 + * + * Copyright (C) 2010 Malcolm Priestley (tvboxspy@gmail.com) + * LME2510(C)(C) Leaguerme (Shenzhen) MicroElectronics Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * see Documentation/dvb/README.dvb-usb for more information + * + * Known Issues : + * LME2510: Non Intel USB chipsets fail to maintain High Speed on + * Boot or Hot Plug. + * + * DiSEqC functions are not fully supported in this driver. The main + * reason is the frontend is cut off during streaming. Allowing frontend + * access will stall the driver. Applications that attempt to this, the + * commands are ignored. + * + * PID functions have been removed from this driver version due to + * problems with different firmware and application versions. + */ +#define DVB_USB_LOG_PREFIX "LME2510(C)" +#include +#include +#include + +#include "dvb-usb.h" +#include "lmedm04.h" +#include "tda826x.h" +#include "tda10086.h" +#include "stv0288.h" +#include "ix2505v.h" + + + +/* debug */ +static int dvb_usb_lme2510_debug; +#define l_dprintk(var, level, args...) do { \ + if ((var >= level)) \ + printk(KERN_DEBUG DVB_USB_LOG_PREFIX ": " args); \ +} while (0) + +#define deb_info(level, args...) l_dprintk(dvb_usb_lme2510_debug, level, args) +#define debug_data_snipet(level, name, p) \ + deb_info(level, name" (%02x%02x%02x%02x%02x%02x%02x%02x)", \ + *p, *(p+1), *(p+2), *(p+3), *(p+4), \ + *(p+5), *(p+6), *(p+7)); + + +module_param_named(debug, dvb_usb_lme2510_debug, int, 0644); +MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." + DVB_USB_DEBUG_STATUS); + +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); +#define TUNER_LG 0x1 +#define TUNER_S7395 0x2 + +struct lme2510_state { + u8 id; + u8 tuner_config; + u8 signal_lock; + u8 signal_level; + u8 signal_sn; + u8 time_key; + u8 i2c_talk_onoff; + u8 i2c_gate; + u8 i2c_tuner_gate_w; + u8 i2c_tuner_gate_r; + u8 i2c_tuner_addr; + void *buffer; + struct urb *lme_urb; + void *usb_buffer; + +}; + +static int lme2510_bulk_write(struct usb_device *dev, + u8 *snd, int len, u8 pipe) +{ + int ret, actual_l; + ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, pipe), + snd, len , &actual_l, 500); + return ret; +} + +static int lme2510_bulk_read(struct usb_device *dev, + u8 *rev, int len, u8 pipe) +{ + int ret, actual_l; + + ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, pipe), + rev, len , &actual_l, 500); + return ret; +} + +static int lme2510_usb_talk(struct dvb_usb_device *d, + u8 *wbuf, int wlen, u8 *rbuf, int rlen) +{ + struct lme2510_state *st = d->priv; + u8 *buff; + int ret = 0; + + if (st->usb_buffer == NULL) { + st->usb_buffer = kmalloc(512, GFP_KERNEL); + if (st->usb_buffer == NULL) { + info("MEM Error no memory"); + return -ENOMEM; + } + } + buff = st->usb_buffer; + + /* the read/write capped at 512 */ + memcpy(buff, wbuf, (wlen > 512) ? 512 : wlen); + + + ret = mutex_lock_interruptible(&d->usb_mutex); + + if (ret < 0) + return -EAGAIN; + + ret |= usb_clear_halt(d->udev, usb_sndbulkpipe(d->udev, 0x01)); + msleep(5); + ret |= lme2510_bulk_write(d->udev, buff, wlen , 0x1); + + msleep(5); + ret |= usb_clear_halt(d->udev, usb_rcvbulkpipe(d->udev, 0x1)); + + msleep(5); + ret |= lme2510_bulk_read(d->udev, buff, (rlen > 512) ? + 512 : rlen , 0x1); + + if (rlen > 0) + memcpy(rbuf, buff, rlen); + + mutex_unlock(&d->usb_mutex); + + return (ret < 0) ? -ENODEV : 0; +} + +static int lme2510_remote_keypress(struct dvb_usb_adapter *adap, u16 keypress) +{ + struct dvb_usb_device *d = adap->dev; + + deb_info(1, "INT Key Keypress =%04x", keypress); + + if (keypress > 0) + ir_keydown(d->rc_input_dev, keypress, 0); + + return 0; +} + +static void lme2510_int_response(struct urb *lme_urb) +{ + struct dvb_usb_adapter *adap = lme_urb->context; + struct lme2510_state *st = adap->dev->priv; + static u8 *ibuf, *rbuf; + int i = 0, offset; + + switch (lme_urb->status) { + case 0: + case -ETIMEDOUT: + break; + case -ECONNRESET: + case -ENOENT: + case -ESHUTDOWN: + return; + default: + info("Error %x", lme_urb->status); + break; + } + + rbuf = (u8 *) lme_urb->transfer_buffer; + + offset = ((lme_urb->actual_length/8) > 4) + ? 4 : (lme_urb->actual_length/8) ; + + + for (i = 0; i < offset; ++i) { + ibuf = (u8 *)&rbuf[i*8]; + deb_info(5, "INT O/S C =%02x C/O=%02x Type =%02x%02x", + offset, i, ibuf[0], ibuf[1]); + + switch (ibuf[0]) { + case 0xaa: + debug_data_snipet(1, "INT Remote data snipet in", ibuf); + lme2510_remote_keypress(adap, + (u16)(ibuf[4]<<8)+ibuf[5]); + break; + case 0xbb: + switch (st->tuner_config) { + case TUNER_LG: + st->signal_lock = ibuf[2]; + st->signal_level = ibuf[4]; + st->signal_sn = ibuf[3]; + st->time_key = ibuf[7]; + break; + case TUNER_S7395: + /* Tweak for earlier firmware*/ + if (ibuf[1] == 0x03) { + st->signal_level = ibuf[3]; + st->signal_sn = ibuf[2]; + } else { + st->signal_level = ibuf[4]; + st->signal_sn = ibuf[5]; + } + break; + default: + break; + } + debug_data_snipet(5, "INT Remote data snipet in", ibuf); + break; + case 0xcc: + debug_data_snipet(1, "INT Control data snipet", ibuf); + break; + default: + debug_data_snipet(1, "INT Unknown data snipet", ibuf); + break; + } + } + usb_submit_urb(lme_urb, GFP_ATOMIC); +} + +static int lme2510_int_read(struct dvb_usb_adapter *adap) +{ + struct lme2510_state *lme_int = adap->dev->priv; + + lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC); + + if (lme_int->lme_urb == NULL) + return -ENOMEM; + + lme_int->buffer = usb_alloc_coherent(adap->dev->udev, 5000, GFP_ATOMIC, + &lme_int->lme_urb->transfer_dma); + + if (lme_int->buffer == NULL) + return -ENOMEM; + + usb_fill_int_urb(lme_int->lme_urb, + adap->dev->udev, + usb_rcvintpipe(adap->dev->udev, 0xa), + lme_int->buffer, + 4096, + lme2510_int_response, + adap, + 11); + + lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; + + usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC); + info("INT Interupt Service Started"); + + return 0; +} + +static int lme2510_return_status(struct usb_device *dev) +{ + int ret = 0; + u8 data[10] = {0}; + ret |= usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + 0x06, 0x80, 0x0302, 0x00, data, 0x0006, 200); + info("Firmware Status: %x (%x)", ret , data[2]); + + return (ret < 0) ? -ENODEV : data[2]; +} + +static int lme2510_msg(struct dvb_usb_device *d, + u8 *wbuf, int wlen, u8 *rbuf, int rlen) +{ + int ret = 0; + struct lme2510_state *st = d->priv; + + if (st->i2c_talk_onoff == 1) { + if ((wbuf[2] == 0x1c) & (wbuf[3] == 0x0e)) + msleep(80); /*take your time when waiting for tune*/ + + if (mutex_lock_interruptible(&d->i2c_mutex) < 0) + return -EAGAIN; + + ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen); + + mutex_unlock(&d->i2c_mutex); + switch (st->tuner_config) { + case TUNER_S7395: + if (wbuf[3] == 0x24) + st->signal_lock = rbuf[1]; + break; + default: + break; + } + + } else { + switch (st->tuner_config) { + case TUNER_LG: + switch (wbuf[3]) { + case 0x0e: + rbuf[0] = 0x55; + rbuf[1] = st->signal_lock; + break; + case 0x43: + rbuf[0] = 0x55; + rbuf[1] = st->signal_level; + break; + case 0x1c: + rbuf[0] = 0x55; + rbuf[1] = st->signal_sn; + break; + default: + break; + } + break; + case TUNER_S7395: + switch (wbuf[3]) { + case 0x10: + rbuf[0] = 0x55; + rbuf[1] = (st->signal_level & 0x80) + ? 0 : (st->signal_level * 2); + break; + case 0x2d: + rbuf[0] = 0x55; + rbuf[1] = st->signal_sn; + break; + case 0x24: + rbuf[0] = 0x55; + rbuf[1] = (st->signal_level & 0x80) + ? 0 : st->signal_lock; + default: + break; + } + break; + default: + break; + + } + + deb_info(4, "I2C From Interupt Message out(%02x) in(%02x)", + wbuf[3], rbuf[1]); + + } + + return ret; +} + + +static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], + int num) +{ + struct dvb_usb_device *d = i2c_get_adapdata(adap); + struct lme2510_state *st = d->priv; + static u8 obuf[64], ibuf[512]; + int i, read, read_o; + u16 len; + u8 gate = st->i2c_gate; + + if (gate == 0) + gate = 5; + + if (num > 2) + warn("more than 2 i2c messages" + "at a time is not handled yet. TODO."); + + for (i = 0; i < num; i++) { + read_o = 1 & (msg[i].flags & I2C_M_RD); + read = i+1 < num && (msg[i+1].flags & I2C_M_RD); + read |= read_o; + gate = (msg[i].addr == st->i2c_tuner_addr) + ? (read) ? st->i2c_tuner_gate_r + : st->i2c_tuner_gate_w + : st->i2c_gate; + obuf[0] = gate | (read << 7); + + if (gate == 5) + obuf[1] = (read) ? 2 : msg[i].len + 1; + else + obuf[1] = msg[i].len + read + 1; + + obuf[2] = msg[i].addr; + if (read) { + if (read_o) + len = 3; + else { + memcpy(&obuf[3], msg[i].buf, msg[i].len); + obuf[msg[i].len+3] = msg[i+1].len; + len = msg[i].len+4; + } + } else { + memcpy(&obuf[3], msg[i].buf, msg[i].len); + len = msg[i].len+3; + } + + if (lme2510_msg(d, obuf, len, ibuf, 512) < 0) { + deb_info(1, "i2c transfer failed."); + return -EAGAIN; + } + + if (read) { + if (read_o) + memcpy(msg[i].buf, &ibuf[1], msg[i].len); + else { + memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len); + i++; + } + } + } + return i; +} + +static u32 lme2510_i2c_func(struct i2c_adapter *adapter) +{ + return I2C_FUNC_I2C; +} + +static struct i2c_algorithm lme2510_i2c_algo = { + .master_xfer = lme2510_i2c_xfer, + .functionality = lme2510_i2c_func, +}; + +/* Callbacks for DVB USB */ +static int lme2510_identify_state(struct usb_device *udev, + struct dvb_usb_device_properties *props, + struct dvb_usb_device_description **desc, + int *cold) +{ + if (lme2510_return_status(udev) == 0x44) + *cold = 1; + else + *cold = 0; + return 0; +} + +static int lme2510_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) +{ + struct lme2510_state *st = adap->dev->priv; + static u8 reset[] = LME_RESET; + static u8 stream_on[] = LME_ST_ON_W; + static u8 clear_reg_3[] = LME_CLEAR_PID; + static u8 rbuf[1]; + int ret = 0, len = 2, rlen = sizeof(rbuf); + + deb_info(1, "STM (%02x)", onoff); + + if (onoff == 1) { + st->i2c_talk_onoff = 0; + msleep(400); /* give enough time for i2c to stop */ + ret |= lme2510_usb_talk(adap->dev, + stream_on, len, rbuf, rlen); + } else { + deb_info(1, "STM Steam Off"); + if (st->tuner_config == TUNER_LG) + ret |= lme2510_usb_talk(adap->dev, clear_reg_3, + sizeof(clear_reg_3), rbuf, rlen); + else + ret |= lme2510_usb_talk(adap->dev, + reset, sizeof(reset), rbuf, rlen); + + msleep(400); + st->i2c_talk_onoff = 1; + } + + return (ret < 0) ? -ENODEV : 0; +} + +static int lme2510_int_service(struct dvb_usb_adapter *adap) +{ + struct dvb_usb_device *d = adap->dev; + struct input_dev *input_dev; + char *ir_codes = RC_MAP_LME2510; + int ret = 0; + + info("STA Configuring Remote"); + + usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); + + strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); + + input_dev = input_allocate_device(); + if (!input_dev) + return -ENOMEM; + + input_dev->name = "LME2510 Remote Control"; + input_dev->phys = d->rc_phys; + + usb_to_input_id(d->udev, &input_dev->id); + + ret |= ir_input_register(input_dev, ir_codes, NULL, "LME 2510"); + + if (ret) { + input_free_device(input_dev); + return ret; + } + + d->rc_input_dev = input_dev; + /* Start the Interupt */ + ret = lme2510_int_read(adap); + + if (ret < 0) { + ir_input_unregister(input_dev); + input_free_device(input_dev); + } + return (ret < 0) ? -ENODEV : 0; +} + +static u8 check_sum(u8 *p, u8 len) +{ + u8 sum = 0; + while (len--) + sum += *p++; + return sum; +} + +static int lme2510_download_firmware(struct usb_device *dev, + const struct firmware *fw) +{ + int ret = 0; + u8 data[512] = {0}; + u16 j, wlen, len_in, start, end; + u8 packet_size, dlen, i; + u8 *fw_data; + + packet_size = 0x31; + len_in = 1; + + + info("FRM Starting Firmware Download"); + + for (i = 1; i < 3; i++) { + start = (i == 1) ? 0 : 512; + end = (i == 1) ? 512 : fw->size; + for (j = start; j < end; j += (packet_size+1)) { + fw_data = (u8 *)(fw->data + j); + if ((end - j) > packet_size) { + data[0] = i; + dlen = packet_size; + } else { + data[0] = i | 0x80; + dlen = (u8)(end - j)-1; + } + data[1] = dlen; + memcpy(&data[2], fw_data, dlen+1); + wlen = (u8) dlen + 4; + data[wlen-1] = check_sum(fw_data, dlen+1); + deb_info(1, "Data S=%02x:E=%02x CS= %02x", data[3], + data[dlen+2], data[dlen+3]); + ret |= lme2510_bulk_write(dev, data, wlen, 1); + ret |= lme2510_bulk_read(dev, data, len_in , 1); + ret |= (data[0] == 0x88) ? 0 : -1; + } + } + usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), + 0x06, 0x80, 0x0200, 0x00, data, 0x0109, 1000); + + + data[0] = 0x8a; + len_in = 1; + msleep(2000); + ret |= lme2510_bulk_write(dev, data , len_in, 1); /*Resetting*/ + ret |= lme2510_bulk_read(dev, data, len_in, 1); + msleep(400); + + if (ret < 0) + info("FRM Firmware Download Failed (%04x)" , ret); + else + info("FRM Firmware Download Completed - Resetting Device"); + + + return (ret < 0) ? -ENODEV : 0; +} + + +static int lme2510_kill_urb(struct usb_data_stream *stream) +{ + int i; + for (i = 0; i < stream->urbs_submitted; i++) { + deb_info(3, "killing URB no. %d.", i); + + /* stop the URB */ + usb_kill_urb(stream->urb_list[i]); + } + stream->urbs_submitted = 0; + return 0; +} + +static struct tda10086_config tda10086_config = { + .demod_address = 0x1c, + .invert = 0, + .diseqc_tone = 1, + .xtal_freq = TDA10086_XTAL_16M, +}; + +static struct stv0288_config lme_config = { + .demod_address = 0xd0, + .min_delay_ms = 15, + .inittab = s7395_inittab, +}; + +static struct ix2505v_config lme_tuner = { + .tuner_address = 0xc0, + .min_delay_ms = 100, + .tuner_gain = 0x0, + .tuner_chargepump = 0x3, +}; + + +static int dm04_lme2510_set_voltage(struct dvb_frontend *fe, + fe_sec_voltage_t voltage) +{ + struct dvb_usb_adapter *adap = fe->dvb->priv; + struct lme2510_state *st = adap->dev->priv; + static u8 voltage_low[] = LME_VOLTAGE_L; + static u8 voltage_high[] = LME_VOLTAGE_H; + static u8 reset[] = LME_RESET; + static u8 clear_reg_3[] = LME_CLEAR_PID; + static u8 rbuf[1]; + int ret = 0, len = 3, rlen = 1; + + msleep(100); + + if (st->tuner_config == TUNER_LG) + ret |= lme2510_usb_talk(adap->dev, clear_reg_3, + sizeof(clear_reg_3), rbuf, rlen); + else + ret |= lme2510_usb_talk(adap->dev, + reset, sizeof(reset), rbuf, rlen); + + /*always check & stop streaming*/ + lme2510_kill_urb(&adap->stream); + adap->feedcount = 0; + + switch (voltage) { + + case SEC_VOLTAGE_18: + ret |= lme2510_usb_talk(adap->dev, + voltage_high, len, rbuf, rlen); + break; + + case SEC_VOLTAGE_OFF: + case SEC_VOLTAGE_13: + default: + ret |= lme2510_usb_talk(adap->dev, + voltage_low, len, rbuf, rlen); + break; + + + }; + st->i2c_talk_onoff = 1; + return (ret < 0) ? -ENODEV : 0; +} + +static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap) +{ + int ret = 0; + struct lme2510_state *st = adap->dev->priv; + + /* Interupt Start */ + ret = lme2510_int_service(adap); + if (ret < 0) { + info("INT Unable to start Interupt Service"); + return -ENODEV; + } + + st->i2c_talk_onoff = 1; + st->i2c_gate = 4; + + adap->fe = dvb_attach(tda10086_attach, &tda10086_config, + &adap->dev->i2c_adap); + + if (adap->fe) { + info("TUN Found Frontend TDA10086"); + memcpy(&adap->fe->ops.info.name, + &"DM04_LG_TDQY-P001F DVB-S", 24); + adap->fe->ops.set_voltage = dm04_lme2510_set_voltage; + st->i2c_tuner_gate_w = 4; + st->i2c_tuner_gate_r = 4; + st->i2c_tuner_addr = 0xc0; + if (dvb_attach(tda826x_attach, adap->fe, 0xc0, + &adap->dev->i2c_adap, 1)) { + info("TUN TDA8263 Found"); + st->tuner_config = TUNER_LG; + return 0; + } + kfree(adap->fe); + adap->fe = NULL; + } + st->i2c_gate = 5; + adap->fe = dvb_attach(stv0288_attach, &lme_config, + &adap->dev->i2c_adap); + + if (adap->fe) { + info("FE Found Stv0288"); + memcpy(&adap->fe->ops.info.name, + &"DM04_SHARP:BS2F7HZ7395", 22); + adap->fe->ops.set_voltage = dm04_lme2510_set_voltage; + st->i2c_tuner_gate_w = 4; + st->i2c_tuner_gate_r = 5; + st->i2c_tuner_addr = 0xc0; + if (dvb_attach(ix2505v_attach , adap->fe, &lme_tuner, + &adap->dev->i2c_adap)) { + st->tuner_config = TUNER_S7395; + info("TUN Sharp IX2505V silicon tuner"); + return 0; + } + kfree(adap->fe); + adap->fe = NULL; + } + + info("DM04 Not Supported"); + return -ENODEV; +} + +static int lme2510_powerup(struct dvb_usb_device *d, int onoff) +{ + struct lme2510_state *st = d->priv; + st->i2c_talk_onoff = 1; + return 0; +} + +/* DVB USB Driver stuff */ +static struct dvb_usb_device_properties lme2510_properties; +static struct dvb_usb_device_properties lme2510c_properties; + +static int lme2510_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + struct usb_device *udev = interface_to_usbdev(intf); + int ret = 0; + + usb_reset_configuration(udev); + + usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 1); + + if (udev->speed != USB_SPEED_HIGH) { + ret = usb_reset_device(udev); + info("DEV Failed to connect in HIGH SPEED mode"); + return -ENODEV; + } + + if (0 == dvb_usb_device_init(intf, &lme2510_properties, + THIS_MODULE, NULL, adapter_nr)) { + info("DEV registering device driver"); + return 0; + } + if (0 == dvb_usb_device_init(intf, &lme2510c_properties, + THIS_MODULE, NULL, adapter_nr)) { + info("DEV registering device driver"); + return 0; + } + + info("DEV lme2510 Error"); + return -ENODEV; + +} + +static struct usb_device_id lme2510_table[] = { + { USB_DEVICE(0x3344, 0x1122) }, /* LME2510 */ + { USB_DEVICE(0x3344, 0x1120) }, /* LME2510C */ + {} /* Terminating entry */ +}; + +MODULE_DEVICE_TABLE(usb, lme2510_table); + +static struct dvb_usb_device_properties lme2510_properties = { + .caps = DVB_USB_IS_AN_I2C_ADAPTER, + .usb_ctrl = DEVICE_SPECIFIC, + .download_firmware = lme2510_download_firmware, + .firmware = "dvb-usb-lme2510-lg.fw", + + .size_of_priv = sizeof(struct lme2510_state), + .num_adapters = 1, + .adapter = { + { + .streaming_ctrl = lme2510_streaming_ctrl, + .frontend_attach = dm04_lme2510_frontend_attach, + /* parameter for the MPEG2-data transfer */ + .stream = { + .type = USB_BULK, + .count = 10, + .endpoint = 0x06, + .u = { + .bulk = { + .buffersize = 4096, + + } + } + } + } + }, + .power_ctrl = lme2510_powerup, + .identify_state = lme2510_identify_state, + .i2c_algo = &lme2510_i2c_algo, + .generic_bulk_ctrl_endpoint = 0, + .num_device_descs = 1, + .devices = { + { "DM04 LME2510 DVB-S USB 2.0", + { &lme2510_table[0], NULL }, + }, + + } +}; + +static struct dvb_usb_device_properties lme2510c_properties = { + .caps = DVB_USB_IS_AN_I2C_ADAPTER, + .usb_ctrl = DEVICE_SPECIFIC, + .download_firmware = lme2510_download_firmware, + .firmware = "dvb-usb-lme2510c-s7395.fw", + .size_of_priv = sizeof(struct lme2510_state), + .num_adapters = 1, + .adapter = { + { + .streaming_ctrl = lme2510_streaming_ctrl, + .frontend_attach = dm04_lme2510_frontend_attach, + /* parameter for the MPEG2-data transfer */ + .stream = { + .type = USB_BULK, + .count = 8, + .endpoint = 0x8, + .u = { + .bulk = { + .buffersize = 4096, + + } + } + } + } + }, + .power_ctrl = lme2510_powerup, + .identify_state = lme2510_identify_state, + .i2c_algo = &lme2510_i2c_algo, + .generic_bulk_ctrl_endpoint = 0, + .num_device_descs = 1, + .devices = { + { "DM04 LME2510C USB2.0", + { &lme2510_table[1], NULL }, + }, + } +}; + +void lme2510_exit_int(struct dvb_usb_device *d) +{ + struct lme2510_state *st = d->priv; + if (st->lme_urb != NULL) { + st->i2c_talk_onoff = 0; + st->signal_lock = 0; + st->signal_level = 0; + st->signal_sn = 0; + kfree(st->usb_buffer); + usb_kill_urb(st->lme_urb); + usb_free_coherent(d->udev, 5000, st->buffer, + st->lme_urb->transfer_dma); + info("Interupt Service Stopped"); + ir_input_unregister(d->rc_input_dev); + info("Remote Stopped"); + } + return; +} + +void lme2510_exit(struct usb_interface *intf) +{ + struct dvb_usb_device *d = usb_get_intfdata(intf); + if (d != NULL) { + d->adapter[0].feedcount = 0; + lme2510_exit_int(d); + dvb_usb_device_exit(intf); + } + +} + +static struct usb_driver lme2510_driver = { + .name = "LME2510C_DVBS", + .probe = lme2510_probe, + .disconnect = lme2510_exit, + .id_table = lme2510_table, +}; + +/* module stuff */ +static int __init lme2510_module_init(void) +{ + int result = usb_register(&lme2510_driver); + if (result) { + err("usb_register failed. Error number %d", result); + return result; + } + + return 0; +} + +static void __exit lme2510_module_exit(void) +{ + /* deregister this driver from the USB subsystem */ + usb_deregister(&lme2510_driver); +} + +module_init(lme2510_module_init); +module_exit(lme2510_module_exit); + +MODULE_AUTHOR("Malcolm Priestley "); +MODULE_DESCRIPTION("LM2510(C) DVB-S USB2.0"); +MODULE_VERSION("1.4"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/dvb/dvb-usb/lmedm04.h b/drivers/media/dvb/dvb-usb/lmedm04.h new file mode 100644 index 000000000000..5a66c7ec4511 --- /dev/null +++ b/drivers/media/dvb/dvb-usb/lmedm04.h @@ -0,0 +1,187 @@ +/* DVB USB compliant linux driver for + * + * DM04/QQBOX DVB-S USB BOX LME2510C + SHARP:BS2F7HZ7395 + * LME2510C + LGTDQT-P001F + * + * MVB7395 (LME2510C+SHARP:BS2F7HZ7395) + * SHARP:BS2F7HZ7395 = (STV0288+Sharp IX2505V) + * + * MVB0001F (LME2510C+LGTDQT-P001F) + * LG TDQY - P001F =(TDA8263 + TDA10086H) + * + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 2. + * * + * see Documentation/dvb/README.dvb-usb for more information + */ +#ifndef _DVB_USB_LME2510_H_ +#define _DVB_USB_LME2510_H_ + +/* Streamer & PID + * + * Note: These commands do not actually stop the streaming + * but form some kind of packet filtering/stream count + * or tuning related functions. + * 06 XX + * offset 1 = 00 Enable Streaming + * + * + * PID + * 03 XX XX ----> reg number ---> setting....20 XX + * offset 1 = length + * offset 2 = start of data + * end byte -1 = 20 + * end byte = clear pid always a0, other wise 9c, 9a ?? + * + * RESET (also clears PID filter) + * 3a 01 00 +*/ +#define LME_ST_ON_W {0x06, 0x00} +#define LME_RESET {0x3a, 0x01, 0x00} +#define LME_CLEAR_PID {0x03, 0x02, 0x20, 0xa0} + + +/* LME Power Control + * 07 XX XX + * offset 1 = 01 Power? my device cannot be powered down + * offset 2 = 00=Voltage low 01=Voltage high + */ + +#define LME_VOLTAGE_L {0x07, 0x01, 0x00} +#define LME_VOLTAGE_H {0x07, 0x01, 0x01} + + +/* Initial stv0288 settings for 7395 Frontend */ +static u8 s7395_inittab[] = { + 0x00, 0x11, + 0x01, 0x15, + 0x02, 0x20, + 0x03, 0x8e, + 0x04, 0x8e, + 0x05, 0x12, + 0x06, 0xff, + 0x07, 0x20, + 0x08, 0x00, + 0x09, 0x00, + 0x0a, 0x04, + 0x0b, 0x00, + 0x0c, 0x00, + 0x0d, 0x00, + 0x0e, 0xc1, + 0x0f, 0x54, + 0x10, 0x40, + 0x11, 0x7a, + 0x12, 0x03, + 0x13, 0x48, + 0x14, 0x84, + 0x15, 0xc5, + 0x16, 0xb8, + 0x17, 0x9c, + 0x18, 0x00, + 0x19, 0xa6, + 0x1a, 0x88, + 0x1b, 0x8f, + 0x1c, 0xf0, + 0x1e, 0x80, + 0x20, 0x0b, + 0x21, 0x54, + 0x22, 0xff, + 0x23, 0x01, + 0x24, 0x9a, + 0x25, 0x7f, + 0x26, 0x00, + 0x27, 0x00, + 0x28, 0x46, + 0x29, 0x66, + 0x2a, 0x90, + 0x2b, 0xfa, + 0x2c, 0xd9, + 0x2d, 0x02, + 0x2e, 0xb1, + 0x2f, 0x00, + 0x30, 0x0, + 0x31, 0x1e, + 0x32, 0x14, + 0x33, 0x0f, + 0x34, 0x09, + 0x35, 0x0c, + 0x36, 0x05, + 0x37, 0x2f, + 0x38, 0x16, + 0x39, 0xbd, + 0x3a, 0x0, + 0x3b, 0x13, + 0x3c, 0x11, + 0x3d, 0x30, + 0x3e, 0x00, + 0x3f, 0x00, + 0x40, 0x63, + 0x41, 0x04, + 0x42, 0x60, + 0x43, 0x00, + 0x44, 0x00, + 0x45, 0x00, + 0x46, 0x00, + 0x47, 0x00, + 0x4a, 0x00, + 0x4b, 0xd1, + 0x4c, 0x33, + 0x50, 0x12, + 0x51, 0x36, + 0x52, 0x21, + 0x53, 0x94, + 0x54, 0xb2, + 0x55, 0x29, + 0x56, 0x64, + 0x57, 0x2b, + 0x58, 0x54, + 0x59, 0x86, + 0x5a, 0x00, + 0x5b, 0x9b, + 0x5c, 0x08, + 0x5d, 0x7f, + 0x5e, 0xff, + 0x5f, 0x8d, + 0x70, 0x0, + 0x71, 0x0, + 0x72, 0x0, + 0x74, 0x0, + 0x75, 0x0, + 0x76, 0x0, + 0x81, 0x0, + 0x82, 0x3f, + 0x83, 0x3f, + 0x84, 0x0, + 0x85, 0x0, + 0x88, 0x0, + 0x89, 0x0, + 0x8a, 0x0, + 0x8b, 0x0, + 0x8c, 0x0, + 0x90, 0x0, + 0x91, 0x0, + 0x92, 0x0, + 0x93, 0x0, + 0x94, 0x1c, + 0x97, 0x0, + 0xa0, 0x48, + 0xa1, 0x0, + 0xb0, 0xb8, + 0xb1, 0x3a, + 0xb2, 0x10, + 0xb3, 0x82, + 0xb4, 0x80, + 0xb5, 0x82, + 0xb6, 0x82, + 0xb7, 0x82, + 0xb8, 0x20, + 0xb9, 0x0, + 0xf0, 0x0, + 0xf1, 0x0, + 0xf2, 0xc0, + 0xff, 0xff, +}; + +#endif diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 6c0324eb4914..57281b1008e4 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -96,6 +96,7 @@ void rc_map_init(void); #define RC_MAP_KWORLD_315U "rc-kworld-315u" #define RC_MAP_KWORLD_PLUS_TV_ANALOG "rc-kworld-plus-tv-analog" #define RC_MAP_LIRC "rc-lirc" +#define RC_MAP_LME2510 "rc-lme2510" #define RC_MAP_MANLI "rc-manli" #define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus" #define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere" -- cgit v1.2.3 From 226c0eeaea6732c686a5f4e06f25e5850cd5dd61 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 6 Aug 2010 12:48:00 -0300 Subject: V4L/DVB: videotext: remove this obsolete API Remove the vtx (aka videotext aka teletext) API from the v4l2 core. This API was scheduled for removal in kernel 2.6.35. The vtx device nodes have been superseded by vbi device nodes for many years. No applications exist that use the vtx support. Of the two i2c drivers that actually support this API the saa5249 has been impossible to use for a year now and no known hardware that supports this device exists. The saa5246a is theoretically supported by the old mxb boards, but it never actually worked. In summary: there is no hardware that can use this API and there are no applications actually implementing this API. The vtx support still reserves minors 192-223 and we would really like to reuse those for upcoming new functionality. In the unlikely event that new hardware appears that wants to use the functionality provided by the vtx API, then that functionality should be build around the sliced VBI API instead. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/v4l2-dev.c | 11 +--- include/linux/Kbuild | 1 - include/linux/videotext.h | 125 ----------------------------------------- include/media/v4l2-dev.h | 3 +- 4 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 include/linux/videotext.h (limited to 'include') diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index cb77197d480e..d4a353260c1e 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -81,7 +81,7 @@ static inline unsigned long *devnode_bits(int vfl_type) /* Any types not assigned to fixed minor ranges must be mapped to one single bitmap for the purposes of finding a free node number since all those unassigned types use the same minor range. */ - int idx = (vfl_type > VFL_TYPE_VTX) ? VFL_TYPE_MAX - 1 : vfl_type; + int idx = (vfl_type > VFL_TYPE_RADIO) ? VFL_TYPE_MAX - 1 : vfl_type; return devnode_nums[idx]; } @@ -377,8 +377,6 @@ static int get_index(struct video_device *vdev) * * %VFL_TYPE_GRABBER - A frame grabber * - * %VFL_TYPE_VTX - A teletext device - * * %VFL_TYPE_VBI - Vertical blank data (undecoded) * * %VFL_TYPE_RADIO - A radio card @@ -411,9 +409,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, case VFL_TYPE_GRABBER: name_base = "video"; break; - case VFL_TYPE_VTX: - name_base = "vtx"; - break; case VFL_TYPE_VBI: name_base = "vbi"; break; @@ -451,10 +446,6 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, minor_offset = 64; minor_cnt = 64; break; - case VFL_TYPE_VTX: - minor_offset = 192; - minor_cnt = 32; - break; case VFL_TYPE_VBI: minor_offset = 224; minor_cnt = 32; diff --git a/include/linux/Kbuild b/include/linux/Kbuild index 4e8ea8c8ec1e..38a9f502baef 100644 --- a/include/linux/Kbuild +++ b/include/linux/Kbuild @@ -371,7 +371,6 @@ header-y += veth.h header-y += vhost.h header-y += videodev.h header-y += videodev2.h -header-y += videotext.h header-y += virtio_9p.h header-y += virtio_balloon.h header-y += virtio_blk.h diff --git a/include/linux/videotext.h b/include/linux/videotext.h deleted file mode 100644 index 3e68c8d1c7f7..000000000000 --- a/include/linux/videotext.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef _VTX_H -#define _VTX_H - -/* - * Teletext (=Videotext) hardware decoders using interface /dev/vtx - * Do not confuse with drivers using /dev/vbi which decode videotext by software - * - * Videotext IOCTLs changed in order to use _IO() macros defined in , - * unused tuner IOCTLs cleaned up by - * Michael Geng - * - * Copyright (c) 1994-97 Martin Buck - * Read COPYING for more information - * - */ - - -/* - * Videotext ioctls - */ -#define VTXIOCGETINFO _IOR (0x81, 1, vtx_info_t) -#define VTXIOCCLRPAGE _IOW (0x81, 2, vtx_pagereq_t) -#define VTXIOCCLRFOUND _IOW (0x81, 3, vtx_pagereq_t) -#define VTXIOCPAGEREQ _IOW (0x81, 4, vtx_pagereq_t) -#define VTXIOCGETSTAT _IOW (0x81, 5, vtx_pagereq_t) -#define VTXIOCGETPAGE _IOW (0x81, 6, vtx_pagereq_t) -#define VTXIOCSTOPDAU _IOW (0x81, 7, vtx_pagereq_t) -#define VTXIOCPUTPAGE _IO (0x81, 8) -#define VTXIOCSETDISP _IO (0x81, 9) -#define VTXIOCPUTSTAT _IO (0x81, 10) -#define VTXIOCCLRCACHE _IO (0x81, 11) -#define VTXIOCSETVIRT _IOW (0x81, 12, long) - -/* for compatibility, will go away some day */ -#define VTXIOCGETINFO_OLD 0x7101 /* get version of driver & capabilities of vtx-chipset */ -#define VTXIOCCLRPAGE_OLD 0x7102 /* clear page-buffer */ -#define VTXIOCCLRFOUND_OLD 0x7103 /* clear bits indicating that page was found */ -#define VTXIOCPAGEREQ_OLD 0x7104 /* search for page */ -#define VTXIOCGETSTAT_OLD 0x7105 /* get status of page-buffer */ -#define VTXIOCGETPAGE_OLD 0x7106 /* get contents of page-buffer */ -#define VTXIOCSTOPDAU_OLD 0x7107 /* stop data acquisition unit */ -#define VTXIOCPUTPAGE_OLD 0x7108 /* display page on TV-screen */ -#define VTXIOCSETDISP_OLD 0x7109 /* set TV-mode */ -#define VTXIOCPUTSTAT_OLD 0x710a /* set status of TV-output-buffer */ -#define VTXIOCCLRCACHE_OLD 0x710b /* clear cache on VTX-interface (if avail.) */ -#define VTXIOCSETVIRT_OLD 0x710c /* turn on virtual mode (this disables TV-display) */ - -/* - * Definitions for VTXIOCGETINFO - */ - -#define SAA5243 0 -#define SAA5246 1 -#define SAA5249 2 -#define SAA5248 3 -#define XSTV5346 4 - -typedef struct { - int version_major, version_minor; /* version of driver; if version_major changes, driver */ - /* is not backward compatible!!! CHECK THIS!!! */ - int numpages; /* number of page-buffers of vtx-chipset */ - int cct_type; /* type of vtx-chipset (SAA5243, SAA5246, SAA5248 or - * SAA5249) */ -} -vtx_info_t; - - -/* - * Definitions for VTXIOC{CLRPAGE,CLRFOUND,PAGEREQ,GETSTAT,GETPAGE,STOPDAU,PUTPAGE,SETDISP} - */ - -#define MIN_UNIT (1<<0) -#define MIN_TEN (1<<1) -#define HR_UNIT (1<<2) -#define HR_TEN (1<<3) -#define PG_UNIT (1<<4) -#define PG_TEN (1<<5) -#define PG_HUND (1<<6) -#define PGMASK_MAX (1<<7) -#define PGMASK_PAGE (PG_HUND | PG_TEN | PG_UNIT) -#define PGMASK_HOUR (HR_TEN | HR_UNIT) -#define PGMASK_MINUTE (MIN_TEN | MIN_UNIT) - -typedef struct -{ - int page; /* number of requested page (hexadecimal) */ - int hour; /* requested hour (hexadecimal) */ - int minute; /* requested minute (hexadecimal) */ - int pagemask; /* mask defining which values of the above are set */ - int pgbuf; /* buffer where page will be stored */ - int start; /* start of requested part of page */ - int end; /* end of requested part of page */ - void __user *buffer; /* pointer to beginning of destination buffer */ -} -vtx_pagereq_t; - - -/* - * Definitions for VTXIOC{GETSTAT,PUTSTAT} - */ - -#define VTX_PAGESIZE (40 * 24) -#define VTX_VIRTUALSIZE (40 * 49) - -typedef struct -{ - int pagenum; /* number of page (hexadecimal) */ - int hour; /* hour (hexadecimal) */ - int minute; /* minute (hexadecimal) */ - int charset; /* national charset */ - unsigned delete : 1; /* delete page (C4) */ - unsigned headline : 1; /* insert headline (C5) */ - unsigned subtitle : 1; /* insert subtitle (C6) */ - unsigned supp_header : 1; /* suppress header (C7) */ - unsigned update : 1; /* update page (C8) */ - unsigned inter_seq : 1; /* interrupted sequence (C9) */ - unsigned dis_disp : 1; /* disable/suppress display (C10) */ - unsigned serial : 1; /* serial mode (C11) */ - unsigned notfound : 1; /* /FOUND */ - unsigned pblf : 1; /* PBLF */ - unsigned hamming : 1; /* hamming-error occurred */ -} -vtx_pageinfo_t; - -#endif /* _VTX_H */ diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 1efcacbed01a..8ad4f9f93fe2 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -21,8 +21,7 @@ #define VFL_TYPE_GRABBER 0 #define VFL_TYPE_VBI 1 #define VFL_TYPE_RADIO 2 -#define VFL_TYPE_VTX 3 -#define VFL_TYPE_MAX 4 +#define VFL_TYPE_MAX 3 struct v4l2_ioctl_callbacks; struct video_device; -- cgit v1.2.3 From 008d35f2f5256751a18f1f4aea79e3caf140098d Mon Sep 17 00:00:00 2001 From: Jean-François Moine Date: Mon, 13 Sep 2010 07:04:49 -0300 Subject: V4L/DVB: v4l2: Add illuminator controls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some media devices (microscopes) may have one or many illuminators. This patch makes them controlable by the applications. Acked-by: Hans Verkuil Acked-by: Andy Walls Signed-off-by: Jean-François Moine Signed-off-by: Mauro Carvalho Chehab --- Documentation/DocBook/v4l/controls.xml | 9 ++++++++- drivers/media/video/v4l2-ctrls.c | 4 ++++ include/linux/videodev2.h | 5 ++++- 3 files changed, 16 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/Documentation/DocBook/v4l/controls.xml b/Documentation/DocBook/v4l/controls.xml index 8408caaee276..68c83449d7c9 100644 --- a/Documentation/DocBook/v4l/controls.xml +++ b/Documentation/DocBook/v4l/controls.xml @@ -311,11 +311,18 @@ minimum value disables backlight compensation. bits 8-15 Green color information, bits 16-23 Blue color information and bits 24-31 must be zero. + + V4L2_CID_ILLUMINATORS_1 + V4L2_CID_ILLUMINATORS_2 + boolean + Switch on or off the illuminator 1 or 2 of the device + (usually a microscope). + V4L2_CID_LASTP1 End of the predefined control IDs (currently -V4L2_CID_BG_COLOR + 1). +V4L2_CID_ILLUMINATORS_2 + 1). V4L2_CID_PRIVATE_BASE diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index ea8d32cd425d..9d2502cd03ff 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c @@ -305,6 +305,8 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_ROTATE: return "Rotate"; case V4L2_CID_BG_COLOR: return "Background Color"; case V4L2_CID_CHROMA_GAIN: return "Chroma Gain"; + case V4L2_CID_ILLUMINATORS_1: return "Illuminator 1"; + case V4L2_CID_ILLUMINATORS_2: return "Illuminator 2"; /* MPEG controls */ /* Keep the order of the 'case's the same as in videodev2.h! */ @@ -419,6 +421,8 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, case V4L2_CID_AUDIO_LIMITER_ENABLED: case V4L2_CID_AUDIO_COMPRESSION_ENABLED: case V4L2_CID_PILOT_TONE_ENABLED: + case V4L2_CID_ILLUMINATORS_1: + case V4L2_CID_ILLUMINATORS_2: *type = V4L2_CTRL_TYPE_BOOLEAN; *min = 0; *max = *step = 1; diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 2d5ce17ca472..b06479f63271 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -1047,8 +1047,11 @@ enum v4l2_colorfx { #define V4L2_CID_CHROMA_GAIN (V4L2_CID_BASE+36) +#define V4L2_CID_ILLUMINATORS_1 (V4L2_CID_BASE+37) +#define V4L2_CID_ILLUMINATORS_2 (V4L2_CID_BASE+38) + /* last CID + 1 */ -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+37) +#define V4L2_CID_LASTP1 (V4L2_CID_BASE+39) /* MPEG-class control IDs defined by V4L2 */ #define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900) -- cgit v1.2.3 From 1f2052539666bd8b43ed26c9b1c3687628c49ecc Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Wed, 15 Sep 2010 16:36:07 -0300 Subject: V4L/DVB: v4l: remove obsolete include/media/v4l2-i2c-drv.h file The include/media/v4l2-i2c-drv.h header was used to be able to compile drivers in the v4l-dvb hg repository for legacy kernels (mainly pre-2.6.26) without creating an #ifdef mess. The hg repository dropped support for kernels < 2.6.26 so we can remove this header. All i2c drivers that used it have now been converted to use proper i2c code. The header was a hack, but it did its job well. So I would call this an honorable removal. :-) Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-i2c-drv.h | 80 -------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 include/media/v4l2-i2c-drv.h (limited to 'include') diff --git a/include/media/v4l2-i2c-drv.h b/include/media/v4l2-i2c-drv.h deleted file mode 100644 index 74bf741d1a9b..000000000000 --- a/include/media/v4l2-i2c-drv.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * v4l2-i2c-drv.h - contains I2C handling code that's identical for - * all V4L2 I2C drivers. Use this header if the - * I2C driver is only used by drivers converted - * to the bus-based I2C API. - * - * Copyright (C) 2007 Hans Verkuil - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/* NOTE: the full version of this header is in the v4l-dvb repository - * and allows v4l i2c drivers to be compiled on pre-2.6.26 kernels. - * The version of this header as it appears in the kernel is a stripped - * version (without all the backwards compatibility stuff) and so it - * looks a bit odd. - * - * If you look at the full version then you will understand the reason - * for introducing this header since you really don't want to have all - * the tricky backwards compatibility code in each and every i2c driver. - * - * If the i2c driver will never be compiled for pre-2.6.26 kernels, then - * DO NOT USE this header! Just write it as a regular i2c driver. - */ - -#ifndef __V4L2_I2C_DRV_H__ -#define __V4L2_I2C_DRV_H__ - -#include - -struct v4l2_i2c_driver_data { - const char * const name; - int (*command)(struct i2c_client *client, unsigned int cmd, void *arg); - int (*probe)(struct i2c_client *client, const struct i2c_device_id *id); - int (*remove)(struct i2c_client *client); - int (*suspend)(struct i2c_client *client, pm_message_t state); - int (*resume)(struct i2c_client *client); - const struct i2c_device_id *id_table; -}; - -static struct v4l2_i2c_driver_data v4l2_i2c_data; -static struct i2c_driver v4l2_i2c_driver; - - -/* Bus-based I2C implementation for kernels >= 2.6.26 */ - -static int __init v4l2_i2c_drv_init(void) -{ - v4l2_i2c_driver.driver.name = v4l2_i2c_data.name; - v4l2_i2c_driver.command = v4l2_i2c_data.command; - v4l2_i2c_driver.probe = v4l2_i2c_data.probe; - v4l2_i2c_driver.remove = v4l2_i2c_data.remove; - v4l2_i2c_driver.suspend = v4l2_i2c_data.suspend; - v4l2_i2c_driver.resume = v4l2_i2c_data.resume; - v4l2_i2c_driver.id_table = v4l2_i2c_data.id_table; - return i2c_add_driver(&v4l2_i2c_driver); -} - - -static void __exit v4l2_i2c_drv_cleanup(void) -{ - i2c_del_driver(&v4l2_i2c_driver); -} - -module_init(v4l2_i2c_drv_init); -module_exit(v4l2_i2c_drv_cleanup); - -#endif /* __V4L2_I2C_DRV_H__ */ -- cgit v1.2.3 From c0c46826274a4da5d9e312d7cfd4ca0806c0a358 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Wed, 22 Sep 2010 23:24:04 -0300 Subject: V4L/DVB: bttv: Move PV951 IR to the right driver Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/bt8xx/bttv-i2c.c | 38 --------------- drivers/media/video/bt8xx/bttv-input.c | 84 +++++++++++++++++++++++++++++++--- drivers/media/video/bt8xx/bttv.h | 1 - drivers/media/video/bt8xx/bttvp.h | 13 ++++-- drivers/media/video/ir-kbd-i2c.c | 29 ------------ include/media/ir-kbd-i2c.h | 1 - 6 files changed, 87 insertions(+), 79 deletions(-) (limited to 'include') diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c index 685d6597ee79..d502f4106e56 100644 --- a/drivers/media/video/bt8xx/bttv-i2c.c +++ b/drivers/media/video/bt8xx/bttv-i2c.c @@ -390,41 +390,3 @@ int __devinit init_bttv_i2c(struct bttv *btv) return btv->i2c_rc; } - -/* Instantiate the I2C IR receiver device, if present */ -void __devinit init_bttv_i2c_ir(struct bttv *btv) -{ - if (0 == btv->i2c_rc) { - struct i2c_board_info info; - /* The external IR receiver is at i2c address 0x34 (0x35 for - reads). Future Hauppauge cards will have an internal - receiver at 0x30 (0x31 for reads). In theory, both can be - fitted, and Hauppauge suggest an external overrides an - internal. - - That's why we probe 0x1a (~0x34) first. CB - */ - const unsigned short addr_list[] = { - 0x1a, 0x18, 0x4b, 0x64, 0x30, 0x71, - I2C_CLIENT_END - }; - - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); - } -} - -int __devexit fini_bttv_i2c(struct bttv *btv) -{ - if (0 != btv->i2c_rc) - return 0; - - return i2c_del_adapter(&btv->c.i2c_adap); -} - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c index f68717a4bdec..6bf05a7dc5f9 100644 --- a/drivers/media/video/bt8xx/bttv-input.c +++ b/drivers/media/video/bt8xx/bttv-input.c @@ -245,6 +245,83 @@ static void bttv_ir_stop(struct bttv *btv) } } +/* + * Get_key functions used by I2C remotes + */ + +static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) +{ + unsigned char b; + + /* poll IR chip */ + if (1 != i2c_master_recv(ir->c, &b, 1)) { + dprintk(KERN_INFO DEVNAME ": read error\n"); + return -EIO; + } + + /* ignore 0xaa */ + if (b==0xaa) + return 0; + dprintk(KERN_INFO DEVNAME ": key %02x\n", b); + + *ir_key = b; + *ir_raw = b; + return 1; +} + +/* Instantiate the I2C IR receiver device, if present */ +void __devinit init_bttv_i2c_ir(struct bttv *btv) +{ + const unsigned short addr_list[] = { + 0x1a, 0x18, 0x64, 0x30, 0x71, + I2C_CLIENT_END + }; + struct i2c_board_info info; + + if (0 != btv->i2c_rc) + return; + + memset(&info, 0, sizeof(struct i2c_board_info)); + memset(&btv->init_data, 0, sizeof(btv->init_data)); + strlcpy(info.type, "ir_video", I2C_NAME_SIZE); + + switch (btv->c.type) { + case BTTV_BOARD_PV951: + btv->init_data.name = "PV951"; + btv->init_data.get_key = get_key_pv951; + btv->init_data.ir_codes = RC_MAP_PV951; + btv->init_data.type = IR_TYPE_OTHER; + info.addr = 0x4b; + break; + default: + /* + * The external IR receiver is at i2c address 0x34 (0x35 for + * reads). Future Hauppauge cards will have an internal + * receiver at 0x30 (0x31 for reads). In theory, both can be + * fitted, and Hauppauge suggest an external overrides an + * internal. + * That's why we probe 0x1a (~0x34) first. CB + */ + + i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); + return; + } + + if (btv->init_data.name) + info.platform_data = &btv->init_data; + i2c_new_device(&btv->c.i2c_adap, &info); + + return; +} + +int __devexit fini_bttv_i2c(struct bttv *btv) +{ + if (0 != btv->i2c_rc) + return 0; + + return i2c_del_adapter(&btv->c.i2c_adap); +} + int bttv_input_init(struct bttv *btv) { struct card_ir *ir; @@ -420,10 +497,3 @@ void bttv_input_fini(struct bttv *btv) kfree(btv->remote); btv->remote = NULL; } - - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */ diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h index 3ec2402c6b4a..6fd2a8ebda1e 100644 --- a/drivers/media/video/bt8xx/bttv.h +++ b/drivers/media/video/bt8xx/bttv.h @@ -18,7 +18,6 @@ #include #include #include -#include #include #include diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h index 6cccc2a17eee..d1e26a448ed2 100644 --- a/drivers/media/video/bt8xx/bttvp.h +++ b/drivers/media/video/bt8xx/bttvp.h @@ -42,7 +42,7 @@ #include #include #include - +#include #include "bt848.h" #include "bttv.h" @@ -270,6 +270,12 @@ int bttv_sub_del_devices(struct bttv_core *core); extern int no_overlay; +/* ---------------------------------------------------------- */ +/* bttv-input.c */ + +extern void init_bttv_i2c_ir(struct bttv *btv); +extern int fini_bttv_i2c(struct bttv *btv); + /* ---------------------------------------------------------- */ /* bttv-driver.c */ @@ -279,8 +285,6 @@ extern unsigned int bttv_debug; extern unsigned int bttv_gpio; extern void bttv_gpio_tracking(struct bttv *btv, char *comment); extern int init_bttv_i2c(struct bttv *btv); -extern void init_bttv_i2c_ir(struct bttv *btv); -extern int fini_bttv_i2c(struct bttv *btv); #define bttv_printk if (bttv_verbose) printk #define dprintk if (bttv_debug >= 1) printk @@ -366,6 +370,9 @@ struct bttv { int has_remote; struct card_ir *remote; + /* I2C remote data */ + struct IR_i2c_init_data init_data; + /* locking */ spinlock_t s_lock; struct mutex lock; diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c index ece6e15e4c07..02fbd08112c9 100644 --- a/drivers/media/video/ir-kbd-i2c.c +++ b/drivers/media/video/ir-kbd-i2c.c @@ -146,26 +146,6 @@ static int get_key_pixelview(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) return 1; } -static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) -{ - unsigned char b; - - /* poll IR chip */ - if (1 != i2c_master_recv(ir->c, &b, 1)) { - dprintk(1,"read error\n"); - return -EIO; - } - - /* ignore 0xaa */ - if (b==0xaa) - return 0; - dprintk(2,"key %02x\n", b); - - *ir_key = b; - *ir_raw = b; - return 1; -} - static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) { unsigned char buf[4]; @@ -321,12 +301,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ir_type = IR_TYPE_OTHER; ir_codes = RC_MAP_EMPTY; break; - case 0x4b: - name = "PV951"; - ir->get_key = get_key_pv951; - ir_type = IR_TYPE_OTHER; - ir_codes = RC_MAP_PV951; - break; case 0x18: case 0x1f: case 0x1a: @@ -396,9 +370,6 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) case IR_KBD_GET_KEY_PIXELVIEW: ir->get_key = get_key_pixelview; break; - case IR_KBD_GET_KEY_PV951: - ir->get_key = get_key_pv951; - break; case IR_KBD_GET_KEY_HAUP: ir->get_key = get_key_haup; break; diff --git a/include/media/ir-kbd-i2c.h b/include/media/ir-kbd-i2c.h index 5e96d7a430be..4102f0dd5c40 100644 --- a/include/media/ir-kbd-i2c.h +++ b/include/media/ir-kbd-i2c.h @@ -24,7 +24,6 @@ struct IR_i2c { enum ir_kbd_get_key_fn { IR_KBD_GET_KEY_CUSTOM = 0, IR_KBD_GET_KEY_PIXELVIEW, - IR_KBD_GET_KEY_PV951, IR_KBD_GET_KEY_HAUP, IR_KBD_GET_KEY_KNC1, IR_KBD_GET_KEY_FUSIONHDTV, -- cgit v1.2.3 From c72ba8e6ae7376d20e509a9a54a2dd45fb483fc2 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 23 Sep 2010 01:23:10 -0300 Subject: V4L/DVB: saa7134: get rid of I2C_HW_SAA7134 The only reason for keeping I2C_HW_SAA7134 is to allow setting a per-device polling interval. Just move this info to the platform data, allowing drivers to change it per device, where needed. Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/ir-kbd-i2c.c | 12 +++++------- drivers/media/video/saa7134/saa7134-i2c.c | 1 - drivers/media/video/saa7134/saa7134-input.c | 5 +++++ include/media/ir-kbd-i2c.h | 9 +++++++-- 4 files changed, 17 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c index 91b2c88d4d72..5a000c65ae98 100644 --- a/drivers/media/video/ir-kbd-i2c.c +++ b/drivers/media/video/ir-kbd-i2c.c @@ -259,15 +259,9 @@ static void ir_key_poll(struct IR_i2c *ir) static void ir_work(struct work_struct *work) { struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work); - int polling_interval = 100; - - /* MSI TV@nywhere Plus requires more frequent polling - otherwise it will miss some keypresses */ - if (ir->c->adapter->id == I2C_HW_SAA7134 && ir->c->addr == 0x30) - polling_interval = 50; ir_key_poll(ir); - schedule_delayed_work(&ir->work, msecs_to_jiffies(polling_interval)); + schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling_interval)); } /* ----------------------------------------------------------------------- */ @@ -292,6 +286,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ir->c = client; ir->input = input_dev; + ir->polling_interval = DEFAULT_POLLING_INTERVAL; i2c_set_clientdata(client, ir); switch(addr) { @@ -343,6 +338,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) if (init_data->type) ir_type = init_data->type; + if (init_data->polling_interval) + ir->polling_interval = init_data->polling_interval; + switch (init_data->internal_get_key_func) { case IR_KBD_GET_KEY_CUSTOM: /* The bridge driver provided us its own function */ diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c index da41b6b1e64a..2d3f6d265bbf 100644 --- a/drivers/media/video/saa7134/saa7134-i2c.c +++ b/drivers/media/video/saa7134/saa7134-i2c.c @@ -328,7 +328,6 @@ static struct i2c_algorithm saa7134_algo = { static struct i2c_adapter saa7134_adap_template = { .owner = THIS_MODULE, .name = "saa7134", - .id = I2C_HW_SAA7134, .algo = &saa7134_algo, }; diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c index 0b336ca6d55b..52a1ee5aefd0 100644 --- a/drivers/media/video/saa7134/saa7134-input.c +++ b/drivers/media/video/saa7134/saa7134-input.c @@ -959,6 +959,11 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev) dev->init_data.name = "MSI TV@nywhere Plus"; dev->init_data.get_key = get_key_msi_tvanywhere_plus; dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS; + /* + * MSI TV@nyware Plus requires more frequent polling + * otherwise it will miss some keypresses + */ + dev->init_data.polling_interval = 50; info.addr = 0x30; /* MSI TV@nywhere Plus controller doesn't seem to respond to probes unless we read something from diff --git a/include/media/ir-kbd-i2c.h b/include/media/ir-kbd-i2c.h index 4102f0dd5c40..557c676ab7dc 100644 --- a/include/media/ir-kbd-i2c.h +++ b/include/media/ir-kbd-i2c.h @@ -3,6 +3,8 @@ #include +#define DEFAULT_POLLING_INTERVAL 100 /* ms */ + struct IR_i2c; struct IR_i2c { @@ -15,6 +17,8 @@ struct IR_i2c { /* Used to avoid fast repeating */ unsigned char old; + u32 polling_interval; /* in ms */ + struct delayed_work work; char name[32]; char phys[32]; @@ -34,8 +38,9 @@ enum ir_kbd_get_key_fn { /* Can be passed when instantiating an ir_video i2c device */ struct IR_i2c_init_data { char *ir_codes; - const char *name; - u64 type; /* IR_TYPE_RC5, etc */ + const char *name; + u64 type; /* IR_TYPE_RC5, etc */ + u32 polling_interval; /* 0 means DEFAULT_POLLING_INTERVAL */ /* * Specify either a function pointer or a value indicating one of * ir_kbd_i2c's internal get_key functions -- cgit v1.2.3 From ee08940531193ccce680ca3c2f17ecc497c4bb67 Mon Sep 17 00:00:00 2001 From: Jarod Wilson Date: Wed, 15 Sep 2010 15:31:12 -0300 Subject: V4L/DVB: IR: export ir_keyup so imon driver can use it directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The imon driver currently reimplements its own version of ir_keyup (along with key release timer functionality also already present in the core IR code). A follow-up imon patch will make use of ir_keyup and the IR stack's key release code. Trivial extraction from David Härdeman's pending rc-core merge and device interface abstraction patchset to facilitate merging a patch based on his imon input dev split patch ahead of the larger churn, which is slated for post-2.6.37-rc1 (after Dmitry's large keycode patches are merged in mainline). Signed-off-by: Jarod Wilson Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/ir-keytable.c | 3 ++- include/media/ir-core.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/drivers/media/IR/ir-keytable.c b/drivers/media/IR/ir-keytable.c index 7961d59f5cac..59510cd33419 100644 --- a/drivers/media/IR/ir-keytable.c +++ b/drivers/media/IR/ir-keytable.c @@ -285,7 +285,7 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table); * This routine is used to signal that a key has been released on the * remote control. It reports a keyup input event via input_report_key(). */ -static void ir_keyup(struct ir_input_dev *ir) +void ir_keyup(struct ir_input_dev *ir) { if (!ir->keypressed) return; @@ -295,6 +295,7 @@ static void ir_keyup(struct ir_input_dev *ir) input_sync(ir->input_dev); ir->keypressed = false; } +EXPORT_SYMBOL_GPL(ir_keyup); /** * ir_timer_keyup() - generates a keyup event after a timeout diff --git a/include/media/ir-core.h b/include/media/ir-core.h index eb7fddf8f607..4dd43d44ec5e 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h @@ -157,6 +157,7 @@ void ir_input_unregister(struct input_dev *input_dev); void ir_repeat(struct input_dev *dev); void ir_keydown(struct input_dev *dev, int scancode, u8 toggle); +void ir_keyup(struct ir_input_dev *ir); u32 ir_g_keycode_from_table(struct input_dev *input_dev, u32 scancode); /* From ir-raw-event.c */ -- cgit v1.2.3 From c29fcff3daafbf46d64a543c1950bbd206ad8c1c Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 26 Sep 2010 08:20:13 -0300 Subject: V4L/DVB: v4l2-dev: remove get_unmapped_area The get_unmapped_area file operation is unused. Remove. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/v4l2-dev.c | 18 ------------------ include/media/v4l2-dev.h | 2 -- 2 files changed, 20 deletions(-) (limited to 'include') diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index f069c61cdf68..5a54eabd4c42 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -236,23 +236,6 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return ret; } -#ifdef CONFIG_MMU -#define v4l2_get_unmapped_area NULL -#else -static unsigned long v4l2_get_unmapped_area(struct file *filp, - unsigned long addr, unsigned long len, unsigned long pgoff, - unsigned long flags) -{ - struct video_device *vdev = video_devdata(filp); - - if (!vdev->fops->get_unmapped_area) - return -ENOSYS; - if (!video_is_registered(vdev)) - return -ENODEV; - return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); -} -#endif - static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) { struct video_device *vdev = video_devdata(filp); @@ -309,7 +292,6 @@ static const struct file_operations v4l2_fops = { .read = v4l2_read, .write = v4l2_write, .open = v4l2_open, - .get_unmapped_area = v4l2_get_unmapped_area, .mmap = v4l2_mmap, .unlocked_ioctl = v4l2_ioctl, #ifdef CONFIG_COMPAT diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 8ad4f9f93fe2..ba236ff35c8a 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -41,8 +41,6 @@ struct v4l2_file_operations { unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*ioctl) (struct file *, unsigned int, unsigned long); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); - unsigned long (*get_unmapped_area) (struct file *, unsigned long, - unsigned long, unsigned long, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct file *); int (*release) (struct file *); -- cgit v1.2.3 From ee6869afc922a9849979e49bb3bbcad794872fcb Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 26 Sep 2010 08:47:38 -0300 Subject: V4L/DVB: v4l2: add core serialization lock Drivers can optionally set a pointer to a mutex in struct video_device. The core will use that to lock before calling open, read, write, unlocked_ioctl, poll, mmap or release. Updated the documentation as well and ensure that v4l2-event knows about the lock: it will unlock it before doing a blocking wait on an event and relock it afterwards. Ensure that the 'video_is_registered' check is done when the lock is held: a typical disconnect will take the lock as well before unregistering the device nodes, so to prevent race conditions the video_is_registered check should also be done with the lock held. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- Documentation/video4linux/v4l2-framework.txt | 20 ++++++++ drivers/media/video/v4l2-dev.c | 76 +++++++++++++++++++++------- drivers/media/video/v4l2-event.c | 9 +++- include/media/v4l2-dev.h | 3 ++ 4 files changed, 89 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/Documentation/video4linux/v4l2-framework.txt b/Documentation/video4linux/v4l2-framework.txt index 9b1d81c26b7d..a128e012a45c 100644 --- a/Documentation/video4linux/v4l2-framework.txt +++ b/Documentation/video4linux/v4l2-framework.txt @@ -453,6 +453,10 @@ You should also set these fields: - ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance (highly recommended to use this and it might become compulsory in the future!), then set this to your v4l2_ioctl_ops struct. +- lock: leave to NULL if you want to do all the locking in the driver. + Otherwise you give it a pointer to a struct mutex_lock and before any + of the v4l2_file_operations is called this lock will be taken by the + core and released afterwards. - parent: you only set this if v4l2_device was registered with NULL as the parent device struct. This only happens in cases where one hardware device has multiple PCI devices that all share the same v4l2_device core. @@ -469,6 +473,22 @@ If you use v4l2_ioctl_ops, then you should set either .unlocked_ioctl or The v4l2_file_operations struct is a subset of file_operations. The main difference is that the inode argument is omitted since it is never used. +v4l2_file_operations and locking +-------------------------------- + +You can set a pointer to a mutex_lock in struct video_device. Usually this +will be either a top-level mutex or a mutex per device node. If you want +finer-grained locking then you have to set it to NULL and do you own locking. + +If a lock is specified then all file operations will be serialized on that +lock. If you use videobuf then you must pass the same lock to the videobuf +queue initialize function: if videobuf has to wait for a frame to arrive, then +it will temporarily unlock the lock and relock it afterwards. If your driver +also waits in the code, then you should do the same to allow other processes +to access the device node while the first process is waiting for something. + +The implementation of a hotplug disconnect should also take the lock before +calling v4l2_device_disconnect and video_unregister_device. video_device registration ------------------------- diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 5a54eabd4c42..a7702e3d149c 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c @@ -187,33 +187,50 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf, size_t sz, loff_t *off) { struct video_device *vdev = video_devdata(filp); + int ret = -EIO; if (!vdev->fops->read) return -EINVAL; - if (!video_is_registered(vdev)) - return -EIO; - return vdev->fops->read(filp, buf, sz, off); + if (vdev->lock) + mutex_lock(vdev->lock); + if (video_is_registered(vdev)) + ret = vdev->fops->read(filp, buf, sz, off); + if (vdev->lock) + mutex_unlock(vdev->lock); + return ret; } static ssize_t v4l2_write(struct file *filp, const char __user *buf, size_t sz, loff_t *off) { struct video_device *vdev = video_devdata(filp); + int ret = -EIO; if (!vdev->fops->write) return -EINVAL; - if (!video_is_registered(vdev)) - return -EIO; - return vdev->fops->write(filp, buf, sz, off); + if (vdev->lock) + mutex_lock(vdev->lock); + if (video_is_registered(vdev)) + ret = vdev->fops->write(filp, buf, sz, off); + if (vdev->lock) + mutex_unlock(vdev->lock); + return ret; } static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll) { struct video_device *vdev = video_devdata(filp); + int ret = DEFAULT_POLLMASK; - if (!vdev->fops->poll || !video_is_registered(vdev)) - return DEFAULT_POLLMASK; - return vdev->fops->poll(filp, poll); + if (!vdev->fops->poll) + return ret; + if (vdev->lock) + mutex_lock(vdev->lock); + if (video_is_registered(vdev)) + ret = vdev->fops->poll(filp, poll); + if (vdev->lock) + mutex_unlock(vdev->lock); + return ret; } static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) @@ -224,7 +241,11 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (!vdev->fops->ioctl) return -ENOTTY; if (vdev->fops->unlocked_ioctl) { + if (vdev->lock) + mutex_lock(vdev->lock); ret = vdev->fops->unlocked_ioctl(filp, cmd, arg); + if (vdev->lock) + mutex_unlock(vdev->lock); } else if (vdev->fops->ioctl) { /* TODO: convert all drivers to unlocked_ioctl */ lock_kernel(); @@ -239,10 +260,17 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) { struct video_device *vdev = video_devdata(filp); + int ret = -ENODEV; - if (!vdev->fops->mmap || !video_is_registered(vdev)) - return -ENODEV; - return vdev->fops->mmap(filp, vm); + if (!vdev->fops->mmap) + return ret; + if (vdev->lock) + mutex_lock(vdev->lock); + if (video_is_registered(vdev)) + ret = vdev->fops->mmap(filp, vm); + if (vdev->lock) + mutex_unlock(vdev->lock); + return ret; } /* Override for the open function */ @@ -254,17 +282,24 @@ static int v4l2_open(struct inode *inode, struct file *filp) /* Check if the video device is available */ mutex_lock(&videodev_lock); vdev = video_devdata(filp); - /* return ENODEV if the video device has been removed - already or if it is not registered anymore. */ - if (vdev == NULL || !video_is_registered(vdev)) { + /* return ENODEV if the video device has already been removed. */ + if (vdev == NULL) { mutex_unlock(&videodev_lock); return -ENODEV; } /* and increase the device refcount */ video_get(vdev); mutex_unlock(&videodev_lock); - if (vdev->fops->open) - ret = vdev->fops->open(filp); + if (vdev->fops->open) { + if (vdev->lock) + mutex_lock(vdev->lock); + if (video_is_registered(vdev)) + ret = vdev->fops->open(filp); + else + ret = -ENODEV; + if (vdev->lock) + mutex_unlock(vdev->lock); + } /* decrease the refcount in case of an error */ if (ret) @@ -278,8 +313,13 @@ static int v4l2_release(struct inode *inode, struct file *filp) struct video_device *vdev = video_devdata(filp); int ret = 0; - if (vdev->fops->release) + if (vdev->fops->release) { + if (vdev->lock) + mutex_lock(vdev->lock); vdev->fops->release(filp); + if (vdev->lock) + mutex_unlock(vdev->lock); + } /* decrease the refcount unconditionally since the release() return value is ignored. */ diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c index de74ce07b5e2..69fd343d4774 100644 --- a/drivers/media/video/v4l2-event.c +++ b/drivers/media/video/v4l2-event.c @@ -134,15 +134,22 @@ int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event, if (nonblocking) return __v4l2_event_dequeue(fh, event); + /* Release the vdev lock while waiting */ + if (fh->vdev->lock) + mutex_unlock(fh->vdev->lock); + do { ret = wait_event_interruptible(events->wait, events->navailable != 0); if (ret < 0) - return ret; + break; ret = __v4l2_event_dequeue(fh, event); } while (ret == -ENOENT); + if (fh->vdev->lock) + mutex_lock(fh->vdev->lock); + return ret; } EXPORT_SYMBOL_GPL(v4l2_event_dequeue); diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index ba236ff35c8a..15802a067a12 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -94,6 +94,9 @@ struct video_device /* ioctl callbacks */ const struct v4l2_ioctl_ops *ioctl_ops; + + /* serialization lock */ + struct mutex *lock; }; /* dev to video-device */ -- cgit v1.2.3 From 97397687886aa8ecd4ec603fab9e70e970c11597 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Mon, 20 Sep 2010 17:24:30 -0300 Subject: V4L/DVB: videobuf: prepare to make locking optional in videobuf Currently videobuf uses the vb_lock mutex to lock its data structures. But this locking will (optionally) move into the v4l2 core, which means that in that case vb_lock shouldn't be used since the external lock is already held. Prepare for this by adding a pointer to such an external mutex and don't lock if that pointer is set. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/v4l2-mem2mem.c | 8 ++-- drivers/media/video/videobuf-core.c | 64 +++++++++++++++---------------- drivers/media/video/videobuf-dma-contig.c | 4 +- drivers/media/video/videobuf-dma-sg.c | 4 +- drivers/media/video/videobuf-vmalloc.c | 4 +- include/media/videobuf-core.h | 13 +++++++ 6 files changed, 55 insertions(+), 42 deletions(-) (limited to 'include') diff --git a/drivers/media/video/v4l2-mem2mem.c b/drivers/media/video/v4l2-mem2mem.c index f45f9405ea39..ac832a28e18e 100644 --- a/drivers/media/video/v4l2-mem2mem.c +++ b/drivers/media/video/v4l2-mem2mem.c @@ -421,8 +421,8 @@ unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, src_q = v4l2_m2m_get_src_vq(m2m_ctx); dst_q = v4l2_m2m_get_dst_vq(m2m_ctx); - mutex_lock(&src_q->vb_lock); - mutex_lock(&dst_q->vb_lock); + videobuf_queue_lock(src_q); + videobuf_queue_lock(dst_q); if (src_q->streaming && !list_empty(&src_q->stream)) src_vb = list_first_entry(&src_q->stream, @@ -450,8 +450,8 @@ unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, } end: - mutex_unlock(&dst_q->vb_lock); - mutex_unlock(&src_q->vb_lock); + videobuf_queue_unlock(dst_q); + videobuf_queue_unlock(src_q); return rc; } EXPORT_SYMBOL_GPL(v4l2_m2m_poll); diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c index ce1595bef629..2930665910b7 100644 --- a/drivers/media/video/videobuf-core.c +++ b/drivers/media/video/videobuf-core.c @@ -350,9 +350,9 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b, int videobuf_mmap_free(struct videobuf_queue *q) { int ret; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); ret = __videobuf_free(q); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return ret; } EXPORT_SYMBOL_GPL(videobuf_mmap_free); @@ -407,9 +407,9 @@ int videobuf_mmap_setup(struct videobuf_queue *q, enum v4l2_memory memory) { int ret; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); ret = __videobuf_mmap_setup(q, bcount, bsize, memory); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return ret; } EXPORT_SYMBOL_GPL(videobuf_mmap_setup); @@ -432,7 +432,7 @@ int videobuf_reqbufs(struct videobuf_queue *q, return -EINVAL; } - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); if (req->type != q->type) { dprintk(1, "reqbufs: queue type invalid\n"); retval = -EINVAL; @@ -469,7 +469,7 @@ int videobuf_reqbufs(struct videobuf_queue *q, retval = 0; done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } EXPORT_SYMBOL_GPL(videobuf_reqbufs); @@ -478,7 +478,7 @@ int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) { int ret = -EINVAL; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); if (unlikely(b->type != q->type)) { dprintk(1, "querybuf: Wrong type.\n"); goto done; @@ -496,7 +496,7 @@ int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b) ret = 0; done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return ret; } EXPORT_SYMBOL_GPL(videobuf_querybuf); @@ -513,7 +513,7 @@ int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b) if (b->memory == V4L2_MEMORY_MMAP) down_read(¤t->mm->mmap_sem); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); retval = -EBUSY; if (q->reading) { dprintk(1, "qbuf: Reading running...\n"); @@ -605,7 +605,7 @@ int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b) wake_up_interruptible_sync(&q->wait); done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); if (b->memory == V4L2_MEMORY_MMAP) up_read(¤t->mm->mmap_sem); @@ -635,14 +635,14 @@ checks: dprintk(2, "next_buffer: waiting on buffer\n"); /* Drop lock to avoid deadlock with qbuf */ - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); /* Checking list_empty and streaming is safe without * locks because we goto checks to validate while * holding locks before proceeding */ retval = wait_event_interruptible(q->wait, !list_empty(&q->stream) || !q->streaming); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); if (retval) goto done; @@ -687,7 +687,7 @@ int videobuf_dqbuf(struct videobuf_queue *q, MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); memset(b, 0, sizeof(*b)); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); retval = stream_next_buffer(q, &buf, nonblocking); if (retval < 0) { @@ -713,7 +713,7 @@ int videobuf_dqbuf(struct videobuf_queue *q, buf->state = VIDEOBUF_IDLE; b->flags &= ~V4L2_BUF_FLAG_DONE; done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } EXPORT_SYMBOL_GPL(videobuf_dqbuf); @@ -724,7 +724,7 @@ int videobuf_streamon(struct videobuf_queue *q) unsigned long flags = 0; int retval; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); retval = -EBUSY; if (q->reading) goto done; @@ -740,7 +740,7 @@ int videobuf_streamon(struct videobuf_queue *q) wake_up_interruptible_sync(&q->wait); done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } EXPORT_SYMBOL_GPL(videobuf_streamon); @@ -760,9 +760,9 @@ int videobuf_streamoff(struct videobuf_queue *q) { int retval; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); retval = __videobuf_streamoff(q); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } @@ -868,7 +868,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q, MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); q->ops->buf_setup(q, &nbufs, &size); @@ -938,7 +938,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q, } done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } EXPORT_SYMBOL_GPL(videobuf_read_one); @@ -999,9 +999,9 @@ int videobuf_read_start(struct videobuf_queue *q) { int rc; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); rc = __videobuf_read_start(q); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return rc; } @@ -1009,15 +1009,15 @@ EXPORT_SYMBOL_GPL(videobuf_read_start); void videobuf_read_stop(struct videobuf_queue *q) { - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); __videobuf_read_stop(q); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); } EXPORT_SYMBOL_GPL(videobuf_read_stop); void videobuf_stop(struct videobuf_queue *q) { - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); if (q->streaming) __videobuf_streamoff(q); @@ -1025,7 +1025,7 @@ void videobuf_stop(struct videobuf_queue *q) if (q->reading) __videobuf_read_stop(q); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); } EXPORT_SYMBOL_GPL(videobuf_stop); @@ -1039,7 +1039,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q, MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); dprintk(2, "%s\n", __func__); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); retval = -EBUSY; if (q->streaming) goto done; @@ -1097,7 +1097,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q, } done: - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return retval; } EXPORT_SYMBOL_GPL(videobuf_read_stream); @@ -1109,7 +1109,7 @@ unsigned int videobuf_poll_stream(struct file *file, struct videobuf_buffer *buf = NULL; unsigned int rc = 0; - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); if (q->streaming) { if (!list_empty(&q->stream)) buf = list_entry(q->stream.next, @@ -1147,7 +1147,7 @@ unsigned int videobuf_poll_stream(struct file *file, } } } - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return rc; } EXPORT_SYMBOL_GPL(videobuf_poll_stream); @@ -1164,7 +1164,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma) return -EINVAL; } - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); for (i = 0; i < VIDEO_MAX_FRAME; i++) { struct videobuf_buffer *buf = q->bufs[i]; @@ -1174,7 +1174,7 @@ int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma) break; } } - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); return rc; } diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c index 6ff9e4bac3ea..047054f79601 100644 --- a/drivers/media/video/videobuf-dma-contig.c +++ b/drivers/media/video/videobuf-dma-contig.c @@ -63,7 +63,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) struct videobuf_dma_contig_memory *mem; dev_dbg(q->dev, "munmap %p q=%p\n", map, q); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); /* We need first to cancel streams, before unmapping */ if (q->streaming) @@ -103,7 +103,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) kfree(map); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); } } diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c index 2ad0bc252b0e..515ae887ffcf 100644 --- a/drivers/media/video/videobuf-dma-sg.c +++ b/drivers/media/video/videobuf-dma-sg.c @@ -358,7 +358,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) map->count--; if (0 == map->count) { dprintk(1, "munmap %p q=%p\n", map, q); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); for (i = 0; i < VIDEO_MAX_FRAME; i++) { if (NULL == q->bufs[i]) continue; @@ -374,7 +374,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) q->bufs[i]->baddr = 0; q->ops->buf_release(q, q->bufs[i]); } - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); kfree(map); } return; diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c index e7fe31d54f07..91348b3170ff 100644 --- a/drivers/media/video/videobuf-vmalloc.c +++ b/drivers/media/video/videobuf-vmalloc.c @@ -75,7 +75,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) struct videobuf_vmalloc_memory *mem; dprintk(1, "munmap %p q=%p\n", map, q); - mutex_lock(&q->vb_lock); + videobuf_queue_lock(q); /* We need first to cancel streams, before unmapping */ if (q->streaming) @@ -114,7 +114,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma) kfree(map); - mutex_unlock(&q->vb_lock); + videobuf_queue_unlock(q); } return; diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h index f2c41cebf453..f5eb2cbf3002 100644 --- a/include/media/videobuf-core.h +++ b/include/media/videobuf-core.h @@ -139,6 +139,7 @@ struct videobuf_qtype_ops { struct videobuf_queue { struct mutex vb_lock; + struct mutex *ext_lock; spinlock_t *irqlock; struct device *dev; @@ -167,6 +168,18 @@ struct videobuf_queue { void *priv_data; }; +static inline void videobuf_queue_lock(struct videobuf_queue *q) +{ + if (!q->ext_lock) + mutex_lock(&q->vb_lock); +} + +static inline void videobuf_queue_unlock(struct videobuf_queue *q) +{ + if (!q->ext_lock) + mutex_unlock(&q->vb_lock); +} + int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr); int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, struct v4l2_framebuffer *fbuf); -- cgit v1.2.3 From 08bff03ed697a583612b62a6ac566bd5bce98012 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Mon, 20 Sep 2010 17:39:46 -0300 Subject: V4L/DVB: videobuf: add ext_lock argument to the queue init functions Add an ext_lock argument to the videobuf init functions. This allows drivers to pass the vdev->lock pointer (or any other externally held lock) to videobuf. For now all drivers just pass NULL. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/common/saa7146_vbi.c | 2 +- drivers/media/common/saa7146_video.c | 2 +- drivers/media/video/au0828/au0828-video.c | 4 ++-- drivers/media/video/bt8xx/bttv-driver.c | 4 ++-- drivers/media/video/cx231xx/cx231xx-video.c | 6 ++++-- drivers/media/video/cx23885/cx23885-417.c | 2 +- drivers/media/video/cx23885/cx23885-dvb.c | 2 +- drivers/media/video/cx23885/cx23885-video.c | 2 +- drivers/media/video/cx88/cx88-blackbird.c | 2 +- drivers/media/video/cx88/cx88-dvb.c | 2 +- drivers/media/video/cx88/cx88-video.c | 4 ++-- drivers/media/video/em28xx/em28xx-video.c | 4 ++-- drivers/media/video/s2255drv.c | 2 +- drivers/media/video/saa7134/saa7134-dvb.c | 2 +- drivers/media/video/saa7134/saa7134-empress.c | 2 +- drivers/media/video/saa7134/saa7134-video.c | 4 ++-- drivers/media/video/videobuf-core.c | 4 +++- drivers/media/video/videobuf-dma-contig.c | 5 +++-- drivers/media/video/videobuf-dma-sg.c | 5 +++-- drivers/media/video/videobuf-vmalloc.c | 5 +++-- drivers/media/video/vivi.c | 2 +- drivers/media/video/zr364xx.c | 2 +- drivers/staging/cx25821/cx25821-video.c | 2 +- drivers/staging/tm6000/tm6000-video.c | 2 +- include/media/videobuf-core.h | 3 ++- include/media/videobuf-dma-contig.h | 3 ++- include/media/videobuf-dma-sg.h | 3 ++- include/media/videobuf-vmalloc.h | 3 ++- 28 files changed, 48 insertions(+), 37 deletions(-) (limited to 'include') diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c index 8224c301d050..2d4533ab22b7 100644 --- a/drivers/media/common/saa7146_vbi.c +++ b/drivers/media/common/saa7146_vbi.c @@ -412,7 +412,7 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file) V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, // FIXME: does this really work? sizeof(struct saa7146_buf), - file); + file, NULL); init_timer(&fh->vbi_read_timeout); fh->vbi_read_timeout.function = vbi_read_timeout; diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c index a212a91a30f0..741c5732b430 100644 --- a/drivers/media/common/saa7146_video.c +++ b/drivers/media/common/saa7146_video.c @@ -1386,7 +1386,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct saa7146_buf), - file); + file, NULL); return 0; } diff --git a/drivers/media/video/au0828/au0828-video.c b/drivers/media/video/au0828/au0828-video.c index 7989a7ba7c40..162fd5f9d448 100644 --- a/drivers/media/video/au0828/au0828-video.c +++ b/drivers/media/video/au0828/au0828-video.c @@ -965,7 +965,7 @@ static int au0828_v4l2_open(struct file *filp) NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, - sizeof(struct au0828_buffer), fh); + sizeof(struct au0828_buffer), fh, NULL); /* VBI Setup */ dev->vbi_width = 720; @@ -974,7 +974,7 @@ static int au0828_v4l2_open(struct file *filp) NULL, &dev->slock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, - sizeof(struct au0828_buffer), fh); + sizeof(struct au0828_buffer), fh, NULL); return ret; diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index 69a8ad24c0b3..3da6e80e1041 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c @@ -3318,13 +3318,13 @@ static int bttv_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct bttv_buffer), - fh); + fh, NULL); videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops, &btv->c.pci->dev, &btv->s_lock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, sizeof(struct bttv_buffer), - fh); + fh, NULL); set_tvnorm(btv,btv->tvnorm); set_input(btv, btv->input, btv->tvnorm); diff --git a/drivers/media/video/cx231xx/cx231xx-video.c b/drivers/media/video/cx231xx/cx231xx-video.c index e76014561aa7..b638c4ed3f2e 100644 --- a/drivers/media/video/cx231xx/cx231xx-video.c +++ b/drivers/media/video/cx231xx/cx231xx-video.c @@ -2008,7 +2008,8 @@ static int cx231xx_v4l2_open(struct file *filp) videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, NULL, &dev->video_mode.slock, fh->type, V4L2_FIELD_INTERLACED, - sizeof(struct cx231xx_buffer), fh); + sizeof(struct cx231xx_buffer), + fh, NULL); if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { /* Set the required alternate setting VBI interface works in Bulk mode only */ @@ -2017,7 +2018,8 @@ static int cx231xx_v4l2_open(struct file *filp) videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, NULL, &dev->vbi_mode.slock, fh->type, V4L2_FIELD_SEQ_TB, - sizeof(struct cx231xx_buffer), fh); + sizeof(struct cx231xx_buffer), + fh, NULL); } mutex_unlock(&dev->lock); diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c index abd64e89f60f..6628e07a8093 100644 --- a/drivers/media/video/cx23885/cx23885-417.c +++ b/drivers/media/video/cx23885/cx23885-417.c @@ -1591,7 +1591,7 @@ static int mpeg_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct cx23885_buffer), - fh); + fh, NULL); unlock_kernel(); return 0; diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c index 0674ea1bf863..5958cb882e93 100644 --- a/drivers/media/video/cx23885/cx23885-dvb.c +++ b/drivers/media/video/cx23885/cx23885-dvb.c @@ -1071,7 +1071,7 @@ int cx23885_dvb_register(struct cx23885_tsport *port) videobuf_queue_sg_init(&fe0->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP, - sizeof(struct cx23885_buffer), port); + sizeof(struct cx23885_buffer), port, NULL); } err = dvb_register(port); if (err != 0) diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c index 5aadc1d1956e..3173cc69ac61 100644 --- a/drivers/media/video/cx23885/cx23885-video.c +++ b/drivers/media/video/cx23885/cx23885-video.c @@ -758,7 +758,7 @@ static int video_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct cx23885_buffer), - fh); + fh, NULL); dprintk(1, "post videobuf_queue_init()\n"); diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c index ec3299585434..ac885f49313c 100644 --- a/drivers/media/video/cx88/cx88-blackbird.c +++ b/drivers/media/video/cx88/cx88-blackbird.c @@ -1094,7 +1094,7 @@ static int mpeg_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct cx88_buffer), - fh); + fh, NULL); /* FIXME: locking against other video device */ cx88_set_scale(dev->core, dev->width, dev->height, diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c index e24fd8d711d8..a037e925ceb9 100644 --- a/drivers/media/video/cx88/cx88-dvb.c +++ b/drivers/media/video/cx88/cx88-dvb.c @@ -1576,7 +1576,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP, sizeof(struct cx88_buffer), - dev); + dev, NULL); /* init struct videobuf_dvb */ fe->dvb.name = dev->core->name; } diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c index 2da9117b138e..19c64a7d0985 100644 --- a/drivers/media/video/cx88/cx88-video.c +++ b/drivers/media/video/cx88/cx88-video.c @@ -793,13 +793,13 @@ static int video_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct cx88_buffer), - fh); + fh, NULL); videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops, &dev->pci->dev, &dev->slock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, sizeof(struct cx88_buffer), - fh); + fh, NULL); if (fh->radio) { dprintk(1,"video_open: setting radio device\n"); diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c index 95a4b60a1eda..a0627cdb706b 100644 --- a/drivers/media/video/em28xx/em28xx-video.c +++ b/drivers/media/video/em28xx/em28xx-video.c @@ -2182,13 +2182,13 @@ static int em28xx_v4l2_open(struct file *filp) videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops, NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, field, - sizeof(struct em28xx_buffer), fh); + sizeof(struct em28xx_buffer), fh, NULL); videobuf_queue_vmalloc_init(&fh->vb_vbiq, &em28xx_vbi_qops, NULL, &dev->slock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, - sizeof(struct em28xx_buffer), fh); + sizeof(struct em28xx_buffer), fh, NULL); mutex_unlock(&dev->lock); diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c index 8f7434182bc3..f5a46c458717 100644 --- a/drivers/media/video/s2255drv.c +++ b/drivers/media/video/s2255drv.c @@ -1817,7 +1817,7 @@ static int s2255_open(struct file *file) NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, - sizeof(struct s2255_buffer), fh); + sizeof(struct s2255_buffer), fh, NULL); return 0; } diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c index f26fe7661a1d..beb95e21d109 100644 --- a/drivers/media/video/saa7134/saa7134-dvb.c +++ b/drivers/media/video/saa7134/saa7134-dvb.c @@ -1111,7 +1111,7 @@ static int dvb_init(struct saa7134_dev *dev) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_ALTERNATE, sizeof(struct saa7134_buf), - dev); + dev, NULL); switch (dev->board) { case SAA7134_BOARD_PINNACLE_300I_DVBT_PAL: diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c index e763f9fd0133..1467a30a434f 100644 --- a/drivers/media/video/saa7134/saa7134-empress.c +++ b/drivers/media/video/saa7134/saa7134-empress.c @@ -542,7 +542,7 @@ static int empress_init(struct saa7134_dev *dev) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_ALTERNATE, sizeof(struct saa7134_buf), - dev); + dev, NULL); empress_signal_update(&dev->empress_workqueue); return 0; diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c index 645224cfd887..fae5e97a3eb2 100644 --- a/drivers/media/video/saa7134/saa7134-video.c +++ b/drivers/media/video/saa7134/saa7134-video.c @@ -1366,13 +1366,13 @@ static int video_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, sizeof(struct saa7134_buf), - fh); + fh, NULL); videobuf_queue_sg_init(&fh->vbi, &saa7134_vbi_qops, &dev->pci->dev, &dev->slock, V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_SEQ_TB, sizeof(struct saa7134_buf), - fh); + fh, NULL); saa7134_pgtable_alloc(dev->pci,&fh->pt_cap); saa7134_pgtable_alloc(dev->pci,&fh->pt_vbi); diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c index 2930665910b7..a32ef8eafc01 100644 --- a/drivers/media/video/videobuf-core.c +++ b/drivers/media/video/videobuf-core.c @@ -125,11 +125,13 @@ void videobuf_queue_core_init(struct videobuf_queue *q, enum v4l2_field field, unsigned int msize, void *priv, - struct videobuf_qtype_ops *int_ops) + struct videobuf_qtype_ops *int_ops, + struct mutex *ext_lock) { BUG_ON(!q); memset(q, 0, sizeof(*q)); q->irqlock = irqlock; + q->ext_lock = ext_lock; q->dev = dev; q->type = type; q->field = field; diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c index 047054f79601..4d0a723b744b 100644 --- a/drivers/media/video/videobuf-dma-contig.c +++ b/drivers/media/video/videobuf-dma-contig.c @@ -349,10 +349,11 @@ void videobuf_queue_dma_contig_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv) + void *priv, + struct mutex *ext_lock) { videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, - priv, &qops); + priv, &qops, ext_lock); } EXPORT_SYMBOL_GPL(videobuf_queue_dma_contig_init); diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c index 515ae887ffcf..359f2f3fdc77 100644 --- a/drivers/media/video/videobuf-dma-sg.c +++ b/drivers/media/video/videobuf-dma-sg.c @@ -654,10 +654,11 @@ void videobuf_queue_sg_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv) + void *priv, + struct mutex *ext_lock) { videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, - priv, &sg_ops); + priv, &sg_ops, ext_lock); } EXPORT_SYMBOL_GPL(videobuf_queue_sg_init); diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c index 91348b3170ff..df142580e44c 100644 --- a/drivers/media/video/videobuf-vmalloc.c +++ b/drivers/media/video/videobuf-vmalloc.c @@ -304,10 +304,11 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv) + void *priv, + struct mutex *ext_lock) { videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, - priv, &qops); + priv, &qops, ext_lock); } EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init); diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index e17b6fee046b..547f5e546c9c 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -1176,7 +1176,7 @@ static int __init vivi_create_instance(int inst) videobuf_queue_vmalloc_init(&dev->vb_vidq, &vivi_video_qops, NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, - sizeof(struct vivi_buffer), dev); + sizeof(struct vivi_buffer), dev, NULL); /* init video dma queues */ INIT_LIST_HEAD(&dev->vidq.active); diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c index 616c61fb3493..7dfb01e9930e 100644 --- a/drivers/media/video/zr364xx.c +++ b/drivers/media/video/zr364xx.c @@ -1304,7 +1304,7 @@ static int zr364xx_open(struct file *file) NULL, &cam->slock, cam->type, V4L2_FIELD_NONE, - sizeof(struct zr364xx_buffer), cam); + sizeof(struct zr364xx_buffer), cam, NULL); /* Added some delay here, since opening/closing the camera quickly, * like Ekiga does during its startup, can crash the webcam diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c index 6fff985358a6..e7f1d5778cec 100644 --- a/drivers/staging/cx25821/cx25821-video.c +++ b/drivers/staging/cx25821/cx25821-video.c @@ -856,7 +856,7 @@ static int video_open(struct file *file) &dev->pci->dev, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED, - sizeof(struct cx25821_buffer), fh); + sizeof(struct cx25821_buffer), fh, NULL); dprintk(1, "post videobuf_queue_init()\n"); unlock_kernel(); diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c index ce0a089a0771..4c22c6584940 100644 --- a/drivers/staging/tm6000/tm6000-video.c +++ b/drivers/staging/tm6000/tm6000-video.c @@ -1300,7 +1300,7 @@ static int tm6000_open(struct file *file) NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, - sizeof(struct tm6000_buffer),fh); + sizeof(struct tm6000_buffer), fh, NULL); return 0; } diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h index f5eb2cbf3002..9a4194557e4a 100644 --- a/include/media/videobuf-core.h +++ b/include/media/videobuf-core.h @@ -198,7 +198,8 @@ void videobuf_queue_core_init(struct videobuf_queue *q, enum v4l2_field field, unsigned int msize, void *priv, - struct videobuf_qtype_ops *int_ops); + struct videobuf_qtype_ops *int_ops, + struct mutex *ext_lock); int videobuf_queue_is_busy(struct videobuf_queue *q); void videobuf_queue_cancel(struct videobuf_queue *q); diff --git a/include/media/videobuf-dma-contig.h b/include/media/videobuf-dma-contig.h index ebaa9bc1ee8d..f0ed82543d9f 100644 --- a/include/media/videobuf-dma-contig.h +++ b/include/media/videobuf-dma-contig.h @@ -23,7 +23,8 @@ void videobuf_queue_dma_contig_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv); + void *priv, + struct mutex *ext_lock); dma_addr_t videobuf_to_dma_contig(struct videobuf_buffer *buf); void videobuf_dma_contig_free(struct videobuf_queue *q, diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h index aa4ebb42a565..1c647e8148c4 100644 --- a/include/media/videobuf-dma-sg.h +++ b/include/media/videobuf-dma-sg.h @@ -103,7 +103,8 @@ void videobuf_queue_sg_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv); + void *priv, + struct mutex *ext_lock); #endif /* _VIDEOBUF_DMA_SG_H */ diff --git a/include/media/videobuf-vmalloc.h b/include/media/videobuf-vmalloc.h index e19403c18dae..486a97efdb56 100644 --- a/include/media/videobuf-vmalloc.h +++ b/include/media/videobuf-vmalloc.h @@ -36,7 +36,8 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue *q, enum v4l2_buf_type type, enum v4l2_field field, unsigned int msize, - void *priv); + void *priv, + struct mutex *ext_lock); void *videobuf_to_vmalloc(struct videobuf_buffer *buf); -- cgit v1.2.3 From 0e0809a58869e3e422985f868ad5e0da1fc0ba85 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Sun, 26 Sep 2010 09:01:26 -0300 Subject: V4L/DVB: videobuf: add queue argument to videobuf_waiton() videobuf_waiton() must unlock and relock ext_lock if it has to wait. For that to happen it needs the videobuf_queue pointer. Don't attempt to unlock/relock q->ext_lock unless it was locked in the first place. vb->state has to be protected by a spinlock to be safe. This patch is based on code from Mauro Carvalho Chehab . [mchehab@redhat.com: add extra argument to a few missing places] Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/common/saa7146_fops.c | 2 +- drivers/media/video/bt8xx/bttv-risc.c | 2 +- drivers/media/video/cx23885/cx23885-core.c | 2 +- drivers/media/video/cx88/cx88-core.c | 2 +- drivers/media/video/fsl-viu.c | 2 +- drivers/media/video/mem2mem_testdev.c | 2 +- drivers/media/video/mx1_camera.c | 2 +- drivers/media/video/mx2_camera.c | 2 +- drivers/media/video/mx3_camera.c | 2 +- drivers/media/video/omap24xxcam.c | 2 +- drivers/media/video/pxa_camera.c | 2 +- drivers/media/video/saa7134/saa7134-core.c | 2 +- drivers/media/video/sh_mobile_ceu_camera.c | 2 +- drivers/media/video/sh_vou.c | 2 +- drivers/media/video/tlg2300/pd-video.c | 4 +-- drivers/media/video/videobuf-core.c | 47 +++++++++++++++++++++--------- drivers/media/video/videobuf-dvb.c | 2 +- drivers/staging/cx25821/cx25821-core.c | 2 +- drivers/staging/dt3155v4l/dt3155v4l.c | 8 ++--- include/media/videobuf-core.h | 3 +- 20 files changed, 58 insertions(+), 36 deletions(-) (limited to 'include') diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c index 4da2a54cb8bd..e3fedc60fe77 100644 --- a/drivers/media/common/saa7146_fops.c +++ b/drivers/media/common/saa7146_fops.c @@ -56,7 +56,7 @@ void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q, BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb,0,0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); buf->vb.state = VIDEOBUF_NEEDS_INIT; diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c index 0fa9f39f37a3..9b57d091da48 100644 --- a/drivers/media/video/bt8xx/bttv-risc.c +++ b/drivers/media/video/bt8xx/bttv-risc.c @@ -582,7 +582,7 @@ bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb,0,0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); btcx_riscmem_free(btv->c.pci,&buf->bottom); diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c index f6b62e7398af..2a34e955dad2 100644 --- a/drivers/media/video/cx23885/cx23885-core.c +++ b/drivers/media/video/cx23885/cx23885-core.c @@ -1221,7 +1221,7 @@ void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf) struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb, 0, 0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c index e46dd7ed63ce..2e145f0a5fd9 100644 --- a/drivers/media/video/cx88/cx88-core.c +++ b/drivers/media/video/cx88/cx88-core.c @@ -217,7 +217,7 @@ cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf) struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb,0,0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); diff --git a/drivers/media/video/fsl-viu.c b/drivers/media/video/fsl-viu.c index 0b318bed4d52..211e83963a46 100644 --- a/drivers/media/video/fsl-viu.c +++ b/drivers/media/video/fsl-viu.c @@ -426,7 +426,7 @@ static void free_buffer(struct videobuf_queue *vq, struct viu_buf *buf) BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb, 0, 0); + videobuf_waiton(vq, &buf->vb, 0, 0); if (vq->int_ops && vq->int_ops->vaddr) vaddr = vq->int_ops->vaddr(vb); diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c index a7210d981388..3b19f5b25a72 100644 --- a/drivers/media/video/mem2mem_testdev.c +++ b/drivers/media/video/mem2mem_testdev.c @@ -848,7 +848,7 @@ static void queue_init(void *priv, struct videobuf_queue *vq, videobuf_queue_vmalloc_init(vq, &m2mtest_qops, ctx->dev->v4l2_dev.dev, &ctx->dev->irqlock, type, V4L2_FIELD_NONE, - sizeof(struct m2mtest_buffer), priv); + sizeof(struct m2mtest_buffer), priv, NULL); } diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c index 5c17f9ec3d7c..e8a5ffcb6f06 100644 --- a/drivers/media/video/mx1_camera.c +++ b/drivers/media/video/mx1_camera.c @@ -161,7 +161,7 @@ static void free_buffer(struct videobuf_queue *vq, struct mx1_buffer *buf) * This waits until this buffer is out of danger, i.e., until it is no * longer in STATE_QUEUED or STATE_ACTIVE */ - videobuf_waiton(vb, 0, 0); + videobuf_waiton(vq, vb, 0, 0); videobuf_dma_contig_free(vq, vb); vb->state = VIDEOBUF_NEEDS_INIT; diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c index b6ea67221d1d..38d09474da13 100644 --- a/drivers/media/video/mx2_camera.c +++ b/drivers/media/video/mx2_camera.c @@ -463,7 +463,7 @@ static void free_buffer(struct videobuf_queue *vq, struct mx2_buffer *buf) * This waits until this buffer is out of danger, i.e., until it is no * longer in STATE_QUEUED or STATE_ACTIVE */ - videobuf_waiton(vb, 0, 0); + videobuf_waiton(vq, vb, 0, 0); videobuf_dma_contig_free(vq, vb); dev_dbg(&icd->dev, "%s freed\n", __func__); diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c index a9be14c23912..a13076969e5a 100644 --- a/drivers/media/video/mx3_camera.c +++ b/drivers/media/video/mx3_camera.c @@ -185,7 +185,7 @@ static void free_buffer(struct videobuf_queue *vq, struct mx3_camera_buffer *buf * This waits until this buffer is out of danger, i.e., until it is no * longer in STATE_QUEUED or STATE_ACTIVE */ - videobuf_waiton(vb, 0, 0); + videobuf_waiton(vq, vb, 0, 0); if (txd) { ichan = to_idmac_chan(txd->chan); async_tx_ack(txd); diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c index 926a5aa6f7f8..13c09f5fa875 100644 --- a/drivers/media/video/omap24xxcam.c +++ b/drivers/media/video/omap24xxcam.c @@ -420,7 +420,7 @@ static void omap24xxcam_vbq_release(struct videobuf_queue *vbq, struct videobuf_dmabuf *dma = videobuf_to_dma(vb); /* wait for buffer, especially to get out of the sgdma queue */ - videobuf_waiton(vb, 0, 0); + videobuf_waiton(vbq, vb, 0, 0); if (vb->memory == V4L2_MEMORY_MMAP) { dma_unmap_sg(vbq->dev, dma->sglist, dma->sglen, dma->direction); diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c index 9de7d59916bd..109ba99ae121 100644 --- a/drivers/media/video/pxa_camera.c +++ b/drivers/media/video/pxa_camera.c @@ -275,7 +275,7 @@ static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf) * This waits until this buffer is out of danger, i.e., until it is no * longer in STATE_QUEUED or STATE_ACTIVE */ - videobuf_waiton(&buf->vb, 0, 0); + videobuf_waiton(vq, &buf->vb, 0, 0); videobuf_dma_unmap(vq->dev, dma); videobuf_dma_free(dma); diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c index 40bc635e8a3f..c424c4574d49 100644 --- a/drivers/media/video/saa7134/saa7134-core.c +++ b/drivers/media/video/saa7134/saa7134-core.c @@ -255,7 +255,7 @@ void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf) struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb,0,0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); buf->vb.state = VIDEOBUF_NEEDS_INIT; diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c index 2b24bd0de3ad..39211628d427 100644 --- a/drivers/media/video/sh_mobile_ceu_camera.c +++ b/drivers/media/video/sh_mobile_ceu_camera.c @@ -245,7 +245,7 @@ static void free_buffer(struct videobuf_queue *vq, if (in_interrupt()) BUG(); - videobuf_waiton(&buf->vb, 0, 0); + videobuf_waiton(vq, &buf->vb, 0, 0); videobuf_dma_contig_free(vq, &buf->vb); dev_dbg(dev, "%s freed\n", __func__); buf->vb.state = VIDEOBUF_NEEDS_INIT; diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c index d394187eb701..d3acd02a1632 100644 --- a/drivers/media/video/sh_vou.c +++ b/drivers/media/video/sh_vou.c @@ -230,7 +230,7 @@ static void free_buffer(struct videobuf_queue *vq, struct videobuf_buffer *vb) BUG_ON(in_interrupt()); /* Wait until this buffer is no longer in STATE_QUEUED or STATE_ACTIVE */ - videobuf_waiton(vb, 0, 0); + videobuf_waiton(vq, vb, 0, 0); videobuf_dma_contig_free(vq, vb); vb->state = VIDEOBUF_NEEDS_INIT; } diff --git a/drivers/media/video/tlg2300/pd-video.c b/drivers/media/video/tlg2300/pd-video.c index d0cc012f7ae6..a1ffe18640fe 100644 --- a/drivers/media/video/tlg2300/pd-video.c +++ b/drivers/media/video/tlg2300/pd-video.c @@ -1434,7 +1434,7 @@ static int pd_video_open(struct file *file) V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED,/* video is interlacd */ sizeof(struct videobuf_buffer),/*it's enough*/ - front); + front, NULL); } else if (vfd->vfl_type == VFL_TYPE_VBI && !(pd->state & POSEIDON_STATE_VBI)) { front = kzalloc(sizeof(struct front_face), GFP_KERNEL); @@ -1451,7 +1451,7 @@ static int pd_video_open(struct file *file) V4L2_BUF_TYPE_VBI_CAPTURE, V4L2_FIELD_NONE, /* vbi is NONE mode */ sizeof(struct videobuf_buffer), - front); + front, NULL); } else { /* maybe add FM support here */ log("other "); diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c index a32ef8eafc01..8979f91fa8e5 100644 --- a/drivers/media/video/videobuf-core.c +++ b/drivers/media/video/videobuf-core.c @@ -73,25 +73,46 @@ struct videobuf_buffer *videobuf_alloc_vb(struct videobuf_queue *q) } EXPORT_SYMBOL_GPL(videobuf_alloc_vb); -#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\ - vb->state != VIDEOBUF_QUEUED) -int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr) +static int is_state_active_or_queued(struct videobuf_queue *q, struct videobuf_buffer *vb) { + unsigned long flags; + bool rc; + + spin_lock_irqsave(q->irqlock, flags); + rc = vb->state != VIDEOBUF_ACTIVE && vb->state != VIDEOBUF_QUEUED; + spin_unlock_irqrestore(q->irqlock, flags); + return rc; +}; + +int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb, + int non_blocking, int intr) +{ + bool is_ext_locked; + int ret = 0; + MAGIC_CHECK(vb->magic, MAGIC_BUFFER); if (non_blocking) { - if (WAITON_CONDITION) + if (is_state_active_or_queued(q, vb)) return 0; - else - return -EAGAIN; + return -EAGAIN; } + is_ext_locked = q->ext_lock && mutex_is_locked(q->ext_lock); + + /* Release vdev lock to prevent this wait from blocking outside access to + the device. */ + if (is_ext_locked) + mutex_unlock(q->ext_lock); if (intr) - return wait_event_interruptible(vb->done, WAITON_CONDITION); + ret = wait_event_interruptible(vb->done, is_state_active_or_queued(q, vb)); else - wait_event(vb->done, WAITON_CONDITION); + wait_event(vb->done, is_state_active_or_queued(q, vb)); + /* Relock */ + if (is_ext_locked) + mutex_lock(q->ext_lock); - return 0; + return ret; } EXPORT_SYMBOL_GPL(videobuf_waiton); @@ -671,7 +692,7 @@ static int stream_next_buffer(struct videobuf_queue *q, goto done; buf = list_entry(q->stream.next, struct videobuf_buffer, stream); - retval = videobuf_waiton(buf, nonblocking, 1); + retval = videobuf_waiton(q, buf, nonblocking, 1); if (retval < 0) goto done; @@ -799,7 +820,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q, spin_lock_irqsave(q->irqlock, flags); q->ops->buf_queue(q, q->read_buf); spin_unlock_irqrestore(q->irqlock, flags); - retval = videobuf_waiton(q->read_buf, 0, 0); + retval = videobuf_waiton(q, q->read_buf, 0, 0); if (0 == retval) { CALL(q, sync, q, q->read_buf); if (VIDEOBUF_ERROR == q->read_buf->state) @@ -911,7 +932,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q, } /* wait until capture is done */ - retval = videobuf_waiton(q->read_buf, nonblocking, 1); + retval = videobuf_waiton(q, q->read_buf, nonblocking, 1); if (0 != retval) goto done; @@ -1061,7 +1082,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q, list_del(&q->read_buf->stream); q->read_off = 0; } - rc = videobuf_waiton(q->read_buf, nonblocking, 1); + rc = videobuf_waiton(q, q->read_buf, nonblocking, 1); if (rc < 0) { if (0 == retval) retval = rc; diff --git a/drivers/media/video/videobuf-dvb.c b/drivers/media/video/videobuf-dvb.c index 3f76398968b8..3de7c7e4402d 100644 --- a/drivers/media/video/videobuf-dvb.c +++ b/drivers/media/video/videobuf-dvb.c @@ -57,7 +57,7 @@ static int videobuf_dvb_thread(void *data) buf = list_entry(dvb->dvbq.stream.next, struct videobuf_buffer, stream); list_del(&buf->stream); - err = videobuf_waiton(buf,0,1); + err = videobuf_waiton(&dvb->dvbq, buf, 0, 1); /* no more feeds left or stop_feed() asked us to quit */ if (0 == dvb->nfeeds) diff --git a/drivers/staging/cx25821/cx25821-core.c b/drivers/staging/cx25821/cx25821-core.c index c487c19256b9..03391f413397 100644 --- a/drivers/staging/cx25821/cx25821-core.c +++ b/drivers/staging/cx25821/cx25821-core.c @@ -1319,7 +1319,7 @@ void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf) struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); BUG_ON(in_interrupt()); - videobuf_waiton(&buf->vb, 0, 0); + videobuf_waiton(q, &buf->vb, 0, 0); videobuf_dma_unmap(q->dev, dma); videobuf_dma_free(dma); btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); diff --git a/drivers/staging/dt3155v4l/dt3155v4l.c b/drivers/staging/dt3155v4l/dt3155v4l.c index fd48b38e797c..b996697e7eb2 100644 --- a/drivers/staging/dt3155v4l/dt3155v4l.c +++ b/drivers/staging/dt3155v4l/dt3155v4l.c @@ -293,7 +293,7 @@ static void dt3155_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) { if (vb->state == VIDEOBUF_ACTIVE) - videobuf_waiton(vb, 0, 0); /* FIXME: cannot be interrupted */ + videobuf_waiton(q, vb, 0, 0); /* FIXME: cannot be interrupted */ videobuf_dma_contig_free(q, vb); vb->state = VIDEOBUF_NEEDS_INIT; } @@ -440,7 +440,7 @@ dt3155_open(struct file *filp) videobuf_queue_dma_contig_init(pd->vidq, &vbq_ops, &pd->pdev->dev, &pd->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, - sizeof(struct videobuf_buffer), pd); + sizeof(struct videobuf_buffer), pd, NULL); /* disable all irqs, clear all irq flags */ iowrite32(FLD_START | FLD_END_EVEN | FLD_END_ODD, pd->regs + INT_CSR); @@ -494,7 +494,7 @@ dt3155_release(struct file *filp) tmp = pd->curr_buf; spin_unlock_irqrestore(&pd->lock, flags); if (tmp) - videobuf_waiton(tmp, 0, 1); /* block, interruptible */ + videobuf_waiton(pd->vidq, tmp, 0, 1); /* block, interruptible */ dt3155_stop_acq(pd); videobuf_stop(pd->vidq); pd->acq_fp = NULL; @@ -603,7 +603,7 @@ dt3155_ioc_streamoff(struct file *filp, void *p, enum v4l2_buf_type type) tmp = pd->curr_buf; spin_unlock_irqrestore(&pd->lock, flags); if (tmp) - videobuf_waiton(tmp, 0, 1); /* block, interruptible */ + videobuf_waiton(pd->vidq, tmp, 0, 1); /* block, interruptible */ return ret; } diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h index 9a4194557e4a..1d3835fc26be 100644 --- a/include/media/videobuf-core.h +++ b/include/media/videobuf-core.h @@ -180,7 +180,8 @@ static inline void videobuf_queue_unlock(struct videobuf_queue *q) mutex_unlock(&q->vb_lock); } -int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr); +int videobuf_waiton(struct videobuf_queue *q, struct videobuf_buffer *vb, + int non_blocking, int intr); int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, struct v4l2_framebuffer *fbuf); -- cgit v1.2.3 From 79c6ff93c74e793ccceb464ee3698478c812ce79 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 27 Aug 2010 13:41:44 -0300 Subject: V4L/DVB: V4L2: add a generic function to find the nearest discrete format to the required one Many video drivers implement a fixed set of frame formats and thus face a task of finding the best match for a user-requested format. Implementing this in a generic function has also an advantage, that different drivers with similar supported format sets will select the same format for the user, which improves consistency across drivers. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/v4l2-common.c | 24 ++++++++++++++++++++++++ include/linux/videodev2.h | 8 ++++++++ 2 files changed, 32 insertions(+) (limited to 'include') diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 8ee1179be926..31ae1a138613 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c @@ -676,3 +676,27 @@ int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info) return 0; } EXPORT_SYMBOL_GPL(v4l_fill_dv_preset_info); + +struct v4l2_frmsize_discrete *v4l2_find_nearest_format(struct v4l2_discrete_probe *probe, + s32 width, s32 height) +{ + int i; + u32 error, min_error = UINT_MAX; + struct v4l2_frmsize_discrete *size, *best = NULL; + + if (!probe) + return best; + + for (i = 0, size = probe->sizes; i < probe->num_sizes; i++, size++) { + error = abs(size->width - width) + abs(size->height - height); + if (error < min_error) { + min_error = error; + best = size; + } + if (!error) + break; + } + + return best; +} +EXPORT_SYMBOL_GPL(v4l2_find_nearest_format); diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index b06479f63271..957d5b093847 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -397,6 +397,14 @@ struct v4l2_frmsize_discrete { __u32 height; /* Frame height [pixel] */ }; +struct v4l2_discrete_probe { + const struct v4l2_frmsize_discrete *sizes; + int num_sizes; +}; + +struct v4l2_frmsize_discrete *v4l2_find_nearest_format(struct v4l2_discrete_probe *probe, + s32 width, s32 height); + struct v4l2_frmsize_stepwise { __u32 min_width; /* Minimum frame width [pixel] */ __u32 max_width; /* Maximum frame width [pixel] */ -- cgit v1.2.3 From 57bee29d6e8cf721864fa47a18366bee5ff24f21 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 17 Aug 2010 14:29:51 -0300 Subject: V4L/DVB: soc-camera: allow only one video queue per device Multiple user-space application instances can open the same video device, but it only makes sense for one of them to manage the videobuffer queue and set video format of the device. Restrict soc-camera respectively. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/mx1_camera.c | 8 +- drivers/media/video/mx3_camera.c | 6 +- drivers/media/video/pxa_camera.c | 8 +- drivers/media/video/sh_mobile_ceu_camera.c | 8 +- drivers/media/video/soc_camera.c | 178 ++++++++++++++--------------- include/media/soc_camera.h | 9 +- 6 files changed, 107 insertions(+), 110 deletions(-) (limited to 'include') diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c index e8a5ffcb6f06..adc72c4a9f08 100644 --- a/drivers/media/video/mx1_camera.c +++ b/drivers/media/video/mx1_camera.c @@ -638,7 +638,7 @@ static int mx1_camera_try_fmt(struct soc_camera_device *icd, return 0; } -static int mx1_camera_reqbufs(struct soc_camera_file *icf, +static int mx1_camera_reqbufs(struct soc_camera_device *icd, struct v4l2_requestbuffers *p) { int i; @@ -650,7 +650,7 @@ static int mx1_camera_reqbufs(struct soc_camera_file *icf, * it hadn't triggered */ for (i = 0; i < p->count; i++) { - struct mx1_buffer *buf = container_of(icf->vb_vidq.bufs[i], + struct mx1_buffer *buf = container_of(icd->vb_vidq.bufs[i], struct mx1_buffer, vb); buf->inwork = 0; INIT_LIST_HEAD(&buf->vb.queue); @@ -661,10 +661,10 @@ static int mx1_camera_reqbufs(struct soc_camera_file *icf, static unsigned int mx1_camera_poll(struct file *file, poll_table *pt) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; struct mx1_buffer *buf; - buf = list_entry(icf->vb_vidq.stream.next, struct mx1_buffer, + buf = list_entry(icd->vb_vidq.stream.next, struct mx1_buffer, vb.stream); poll_wait(file, &buf->vb.done, pt); diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c index a13076969e5a..d020388d29ca 100644 --- a/drivers/media/video/mx3_camera.c +++ b/drivers/media/video/mx3_camera.c @@ -976,7 +976,7 @@ static int mx3_camera_try_fmt(struct soc_camera_device *icd, return ret; } -static int mx3_camera_reqbufs(struct soc_camera_file *icf, +static int mx3_camera_reqbufs(struct soc_camera_device *icd, struct v4l2_requestbuffers *p) { return 0; @@ -984,9 +984,9 @@ static int mx3_camera_reqbufs(struct soc_camera_file *icf, static unsigned int mx3_camera_poll(struct file *file, poll_table *pt) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; - return videobuf_poll_stream(file, &icf->vb_vidq, pt); + return videobuf_poll_stream(file, &icd->vb_vidq, pt); } static int mx3_camera_querycap(struct soc_camera_host *ici, diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c index 109ba99ae121..7ffa525019d4 100644 --- a/drivers/media/video/pxa_camera.c +++ b/drivers/media/video/pxa_camera.c @@ -1539,7 +1539,7 @@ static int pxa_camera_try_fmt(struct soc_camera_device *icd, return ret; } -static int pxa_camera_reqbufs(struct soc_camera_file *icf, +static int pxa_camera_reqbufs(struct soc_camera_device *icd, struct v4l2_requestbuffers *p) { int i; @@ -1551,7 +1551,7 @@ static int pxa_camera_reqbufs(struct soc_camera_file *icf, * it hadn't triggered */ for (i = 0; i < p->count; i++) { - struct pxa_buffer *buf = container_of(icf->vb_vidq.bufs[i], + struct pxa_buffer *buf = container_of(icd->vb_vidq.bufs[i], struct pxa_buffer, vb); buf->inwork = 0; INIT_LIST_HEAD(&buf->vb.queue); @@ -1562,10 +1562,10 @@ static int pxa_camera_reqbufs(struct soc_camera_file *icf, static unsigned int pxa_camera_poll(struct file *file, poll_table *pt) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; struct pxa_buffer *buf; - buf = list_entry(icf->vb_vidq.stream.next, struct pxa_buffer, + buf = list_entry(icd->vb_vidq.stream.next, struct pxa_buffer, vb.stream); poll_wait(file, &buf->vb.done, pt); diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c index 39211628d427..cbc997d591bf 100644 --- a/drivers/media/video/sh_mobile_ceu_camera.c +++ b/drivers/media/video/sh_mobile_ceu_camera.c @@ -1726,7 +1726,7 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd, return ret; } -static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf, +static int sh_mobile_ceu_reqbufs(struct soc_camera_device *icd, struct v4l2_requestbuffers *p) { int i; @@ -1740,7 +1740,7 @@ static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf, for (i = 0; i < p->count; i++) { struct sh_mobile_ceu_buffer *buf; - buf = container_of(icf->vb_vidq.bufs[i], + buf = container_of(icd->vb_vidq.bufs[i], struct sh_mobile_ceu_buffer, vb); INIT_LIST_HEAD(&buf->vb.queue); } @@ -1750,10 +1750,10 @@ static int sh_mobile_ceu_reqbufs(struct soc_camera_file *icf, static unsigned int sh_mobile_ceu_poll(struct file *file, poll_table *pt) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; struct sh_mobile_ceu_buffer *buf; - buf = list_entry(icf->vb_vidq.stream.next, + buf = list_entry(icd->vb_vidq.stream.next, struct sh_mobile_ceu_buffer, vb.stream); poll_wait(file, &buf->vb.done, pt); diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c index a55d6dc4c6bd..6876fdcbf8d7 100644 --- a/drivers/media/video/soc_camera.c +++ b/drivers/media/video/soc_camera.c @@ -92,8 +92,7 @@ EXPORT_SYMBOL(soc_camera_apply_sensor_flags); static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); WARN_ON(priv != file->private_data); @@ -105,8 +104,7 @@ static int soc_camera_try_fmt_vid_cap(struct file *file, void *priv, static int soc_camera_enum_input(struct file *file, void *priv, struct v4l2_input *inp) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; int ret = 0; if (inp->index != 0) @@ -141,8 +139,7 @@ static int soc_camera_s_input(struct file *file, void *priv, unsigned int i) static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); return v4l2_subdev_call(sd, core, s_std, *a); @@ -152,47 +149,59 @@ static int soc_camera_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p) { int ret; - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); WARN_ON(priv != file->private_data); - ret = videobuf_reqbufs(&icf->vb_vidq, p); + if (icd->streamer && icd->streamer != file) + return -EBUSY; + + ret = videobuf_reqbufs(&icd->vb_vidq, p); if (ret < 0) return ret; - return ici->ops->reqbufs(icf, p); + ret = ici->ops->reqbufs(icd, p); + if (!ret && !icd->streamer) + icd->streamer = file; + + return ret; } static int soc_camera_querybuf(struct file *file, void *priv, struct v4l2_buffer *p) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; WARN_ON(priv != file->private_data); - return videobuf_querybuf(&icf->vb_vidq, p); + return videobuf_querybuf(&icd->vb_vidq, p); } static int soc_camera_qbuf(struct file *file, void *priv, struct v4l2_buffer *p) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; WARN_ON(priv != file->private_data); - return videobuf_qbuf(&icf->vb_vidq, p); + if (icd->streamer != file) + return -EBUSY; + + return videobuf_qbuf(&icd->vb_vidq, p); } static int soc_camera_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p) { - struct soc_camera_file *icf = file->private_data; + struct soc_camera_device *icd = file->private_data; WARN_ON(priv != file->private_data); - return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK); + if (icd->streamer != file) + return -EBUSY; + + return videobuf_dqbuf(&icd->vb_vidq, p, file->f_flags & O_NONBLOCK); } /* Always entered with .video_lock held */ @@ -280,10 +289,9 @@ static void soc_camera_free_user_formats(struct soc_camera_device *icd) ((x) >> 24) & 0xff /* Called with .vb_lock held, or from the first open(2), see comment there */ -static int soc_camera_set_fmt(struct soc_camera_file *icf, +static int soc_camera_set_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { - struct soc_camera_device *icd = icf->icd; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct v4l2_pix_format *pix = &f->fmt.pix; int ret; @@ -309,7 +317,7 @@ static int soc_camera_set_fmt(struct soc_camera_file *icf, icd->user_width = pix->width; icd->user_height = pix->height; icd->colorspace = pix->colorspace; - icf->vb_vidq.field = + icd->vb_vidq.field = icd->field = pix->field; if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) @@ -331,7 +339,6 @@ static int soc_camera_open(struct file *file) dev); struct soc_camera_link *icl = to_soc_camera_link(icd); struct soc_camera_host *ici; - struct soc_camera_file *icf; int ret; if (!icd->ops) @@ -340,14 +347,9 @@ static int soc_camera_open(struct file *file) ici = to_soc_camera_host(icd->dev.parent); - icf = vmalloc(sizeof(*icf)); - if (!icf) - return -ENOMEM; - if (!try_module_get(ici->ops->owner)) { dev_err(&icd->dev, "Couldn't lock capture bus driver.\n"); - ret = -EINVAL; - goto emgi; + return -EINVAL; } /* @@ -356,7 +358,6 @@ static int soc_camera_open(struct file *file) */ mutex_lock(&icd->video_lock); - icf->icd = icd; icd->use_count++; /* Now we really have to activate the camera */ @@ -401,15 +402,15 @@ static int soc_camera_open(struct file *file) * apart from someone else calling open() simultaneously, but * .video_lock is protecting us against it. */ - ret = soc_camera_set_fmt(icf, &f); + ret = soc_camera_set_fmt(icd, &f); if (ret < 0) goto esfmt; } - file->private_data = icf; + file->private_data = icd; dev_dbg(&icd->dev, "camera device open\n"); - ici->ops->init_videobuf(&icf->vb_vidq, icd); + ici->ops->init_videobuf(&icd->vb_vidq, icd); mutex_unlock(&icd->video_lock); @@ -430,15 +431,13 @@ epower: icd->use_count--; mutex_unlock(&icd->video_lock); module_put(ici->ops->owner); -emgi: - vfree(icf); + return ret; } static int soc_camera_close(struct file *file) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); mutex_lock(&icd->video_lock); @@ -455,12 +454,13 @@ static int soc_camera_close(struct file *file) icl->power(icd->pdev, 0); } + if (icd->streamer == file) + icd->streamer = NULL; + mutex_unlock(&icd->video_lock); module_put(ici->ops->owner); - vfree(icf); - dev_dbg(&icd->dev, "camera device close\n"); return 0; @@ -469,8 +469,7 @@ static int soc_camera_close(struct file *file) static ssize_t soc_camera_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; int err = -EINVAL; dev_err(&icd->dev, "camera device read not implemented\n"); @@ -480,13 +479,15 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf, static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; int err; dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma); - err = videobuf_mmap_mapper(&icf->vb_vidq, vma); + if (icd->streamer != file) + return -EBUSY; + + err = videobuf_mmap_mapper(&icd->vb_vidq, vma); dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n", (unsigned long)vma->vm_start, @@ -498,11 +499,13 @@ static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma) static unsigned int soc_camera_poll(struct file *file, poll_table *pt) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); - if (list_empty(&icf->vb_vidq.stream)) { + if (icd->streamer != file) + return -EBUSY; + + if (list_empty(&icd->vb_vidq.stream)) { dev_err(&icd->dev, "Trying to poll with no queued buffers!\n"); return POLLERR; } @@ -523,24 +526,29 @@ static struct v4l2_file_operations soc_camera_fops = { static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; int ret; WARN_ON(priv != file->private_data); - mutex_lock(&icf->vb_vidq.vb_lock); + if (icd->streamer && icd->streamer != file) + return -EBUSY; - if (icf->vb_vidq.bufs[0]) { + mutex_lock(&icd->vb_vidq.vb_lock); + + if (icd->vb_vidq.bufs[0]) { dev_err(&icd->dev, "S_FMT denied: queue initialised\n"); ret = -EBUSY; goto unlock; } - ret = soc_camera_set_fmt(icf, f); + ret = soc_camera_set_fmt(icd, f); + + if (!ret && !icd->streamer) + icd->streamer = file; unlock: - mutex_unlock(&icf->vb_vidq.vb_lock); + mutex_unlock(&icd->vb_vidq.vb_lock); return ret; } @@ -548,8 +556,7 @@ unlock: static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv, struct v4l2_fmtdesc *f) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; const struct soc_mbus_pixelfmt *format; WARN_ON(priv != file->private_data); @@ -568,15 +575,14 @@ static int soc_camera_enum_fmt_vid_cap(struct file *file, void *priv, static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_pix_format *pix = &f->fmt.pix; WARN_ON(priv != file->private_data); pix->width = icd->user_width; pix->height = icd->user_height; - pix->field = icf->vb_vidq.field; + pix->field = icd->vb_vidq.field; pix->pixelformat = icd->current_fmt->host_fmt->fourcc; pix->bytesperline = soc_mbus_bytes_per_line(pix->width, icd->current_fmt->host_fmt); @@ -592,8 +598,7 @@ static int soc_camera_g_fmt_vid_cap(struct file *file, void *priv, static int soc_camera_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); WARN_ON(priv != file->private_data); @@ -605,8 +610,7 @@ static int soc_camera_querycap(struct file *file, void *priv, static int soc_camera_streamon(struct file *file, void *priv, enum v4l2_buf_type i) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); int ret; @@ -615,12 +619,15 @@ static int soc_camera_streamon(struct file *file, void *priv, if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; + if (icd->streamer != file) + return -EBUSY; + mutex_lock(&icd->video_lock); v4l2_subdev_call(sd, video, s_stream, 1); /* This calls buf_queue from host driver's videobuf_queue_ops */ - ret = videobuf_streamon(&icf->vb_vidq); + ret = videobuf_streamon(&icd->vb_vidq); mutex_unlock(&icd->video_lock); @@ -630,8 +637,7 @@ static int soc_camera_streamon(struct file *file, void *priv, static int soc_camera_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); WARN_ON(priv != file->private_data); @@ -639,13 +645,16 @@ static int soc_camera_streamoff(struct file *file, void *priv, if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; + if (icd->streamer != file) + return -EBUSY; + mutex_lock(&icd->video_lock); /* * This calls buf_release from host driver's videobuf_queue_ops for all * remaining buffers. When the last buffer is freed, stop capture */ - videobuf_streamoff(&icf->vb_vidq); + videobuf_streamoff(&icd->vb_vidq); v4l2_subdev_call(sd, video, s_stream, 0); @@ -657,8 +666,7 @@ static int soc_camera_streamoff(struct file *file, void *priv, static int soc_camera_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *qc) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); int i; @@ -689,8 +697,7 @@ static int soc_camera_queryctrl(struct file *file, void *priv, static int soc_camera_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct v4l2_subdev *sd = soc_camera_to_subdev(icd); int ret; @@ -709,8 +716,7 @@ static int soc_camera_g_ctrl(struct file *file, void *priv, static int soc_camera_s_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct v4l2_subdev *sd = soc_camera_to_subdev(icd); int ret; @@ -729,8 +735,7 @@ static int soc_camera_s_ctrl(struct file *file, void *priv, static int soc_camera_cropcap(struct file *file, void *fh, struct v4l2_cropcap *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); return ici->ops->cropcap(icd, a); @@ -739,14 +744,13 @@ static int soc_camera_cropcap(struct file *file, void *fh, static int soc_camera_g_crop(struct file *file, void *fh, struct v4l2_crop *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); int ret; - mutex_lock(&icf->vb_vidq.vb_lock); + mutex_lock(&icd->vb_vidq.vb_lock); ret = ici->ops->get_crop(icd, a); - mutex_unlock(&icf->vb_vidq.vb_lock); + mutex_unlock(&icd->vb_vidq.vb_lock); return ret; } @@ -759,8 +763,7 @@ static int soc_camera_g_crop(struct file *file, void *fh, static int soc_camera_s_crop(struct file *file, void *fh, struct v4l2_crop *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct v4l2_rect *rect = &a->c; struct v4l2_crop current_crop; @@ -773,7 +776,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, rect->width, rect->height, rect->left, rect->top); /* Cropping is allowed during a running capture, guard consistency */ - mutex_lock(&icf->vb_vidq.vb_lock); + mutex_lock(&icd->vb_vidq.vb_lock); /* If get_crop fails, we'll let host and / or client drivers decide */ ret = ici->ops->get_crop(icd, ¤t_crop); @@ -782,7 +785,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, if (ret < 0) { dev_err(&icd->dev, "S_CROP denied: getting current crop failed\n"); - } else if (icf->vb_vidq.bufs[0] && + } else if (icd->vb_vidq.bufs[0] && (a->c.width != current_crop.c.width || a->c.height != current_crop.c.height)) { dev_err(&icd->dev, @@ -792,7 +795,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, ret = ici->ops->set_crop(icd, a); } - mutex_unlock(&icf->vb_vidq.vb_lock); + mutex_unlock(&icd->vb_vidq.vb_lock); return ret; } @@ -800,8 +803,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, static int soc_camera_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); if (ici->ops->get_parm) @@ -813,8 +815,7 @@ static int soc_camera_g_parm(struct file *file, void *fh, static int soc_camera_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); if (ici->ops->set_parm) @@ -826,8 +827,7 @@ static int soc_camera_s_parm(struct file *file, void *fh, static int soc_camera_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *id) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); return v4l2_subdev_call(sd, core, g_chip_ident, id); @@ -837,8 +837,7 @@ static int soc_camera_g_chip_ident(struct file *file, void *fh, static int soc_camera_g_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); return v4l2_subdev_call(sd, core, g_register, reg); @@ -847,8 +846,7 @@ static int soc_camera_g_register(struct file *file, void *fh, static int soc_camera_s_register(struct file *file, void *fh, struct v4l2_dbg_register *reg) { - struct soc_camera_file *icf = file->private_data; - struct soc_camera_device *icd = icf->icd; + struct soc_camera_device *icd = file->private_data; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); return v4l2_subdev_call(sd, core, s_register, reg); diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h index 2ce957301f77..86e3631764ef 100644 --- a/include/media/soc_camera.h +++ b/include/media/soc_camera.h @@ -21,6 +21,8 @@ extern struct bus_type soc_camera_bus_type; +struct file; + struct soc_camera_device { struct list_head list; struct device dev; @@ -41,10 +43,7 @@ struct soc_camera_device { /* soc_camera.c private count. Only accessed with .video_lock held */ int use_count; struct mutex video_lock; /* Protects device data */ -}; - -struct soc_camera_file { - struct soc_camera_device *icd; + struct file *streamer; /* stream owner */ struct videobuf_queue vb_vidq; }; @@ -79,7 +78,7 @@ struct soc_camera_host_ops { int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); void (*init_videobuf)(struct videobuf_queue *, struct soc_camera_device *); - int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *); + int (*reqbufs)(struct soc_camera_device *, struct v4l2_requestbuffers *); int (*querycap)(struct soc_camera_host *, struct v4l2_capability *); int (*set_bus_param)(struct soc_camera_device *, __u32); int (*get_ctrl)(struct soc_camera_device *, struct v4l2_control *); -- cgit v1.2.3 From 3fd8e647eaa76a1eb5bdd0fcecf49364a089b71d Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Thu, 30 Sep 2010 09:29:37 -0300 Subject: V4L/DVB: v4l2-common: Move v4l2_find_nearest_format from videodev2.h to v4l2-common.h This function is an internal API and belongs in v4l2-common.h, not videodev.h. The return pointer and probe argument should be const as well. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/v4l2-common.c | 7 ++++--- include/linux/videodev2.h | 8 -------- include/media/v4l2-common.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 31ae1a138613..cef80dab1a0d 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c @@ -677,12 +677,13 @@ int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info) } EXPORT_SYMBOL_GPL(v4l_fill_dv_preset_info); -struct v4l2_frmsize_discrete *v4l2_find_nearest_format(struct v4l2_discrete_probe *probe, - s32 width, s32 height) +const struct v4l2_frmsize_discrete *v4l2_find_nearest_format( + const struct v4l2_discrete_probe *probe, + s32 width, s32 height) { int i; u32 error, min_error = UINT_MAX; - struct v4l2_frmsize_discrete *size, *best = NULL; + const struct v4l2_frmsize_discrete *size, *best = NULL; if (!probe) return best; diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index 957d5b093847..b06479f63271 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -397,14 +397,6 @@ struct v4l2_frmsize_discrete { __u32 height; /* Frame height [pixel] */ }; -struct v4l2_discrete_probe { - const struct v4l2_frmsize_discrete *sizes; - int num_sizes; -}; - -struct v4l2_frmsize_discrete *v4l2_find_nearest_format(struct v4l2_discrete_probe *probe, - s32 width, s32 height); - struct v4l2_frmsize_stepwise { __u32 min_width; /* Minimum frame width [pixel] */ __u32 max_width; /* Maximum frame width [pixel] */ diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index 98b32645e5a7..41dd480e45f1 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -232,4 +232,14 @@ void v4l_bound_align_image(unsigned int *w, unsigned int wmin, unsigned int hmax, unsigned int halign, unsigned int salign); int v4l_fill_dv_preset_info(u32 preset, struct v4l2_dv_enum_preset *info); + +struct v4l2_discrete_probe { + const struct v4l2_frmsize_discrete *sizes; + int num_sizes; +}; + +const struct v4l2_frmsize_discrete *v4l2_find_nearest_format( + const struct v4l2_discrete_probe *probe, + s32 width, s32 height); + #endif /* V4L2_COMMON_H_ */ -- cgit v1.2.3 From 22c00854f3db563427527a8f71c20bd3943b13e0 Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Thu, 30 Sep 2010 16:55:07 -0300 Subject: [media] lirc: Make struct file_operations pointer const struct file_operations was made const in the drivers, but not in struct lirc_driver: drivers/staging/lirc/lirc_it87.c:365: warning: initialization discards qualifiers from pointer target type drivers/staging/lirc/lirc_parallel.c:571: warning: initialization discards qualifiers from pointer target type drivers/staging/lirc/lirc_serial.c:1073: warning: initialization discards qualifiers from pointer target type drivers/staging/lirc/lirc_sir.c:482: warning: initialization discards qualifiers from pointer target type drivers/staging/lirc/lirc_zilog.c:1284: warning: assignment discards qualifiers from pointer target type Signed-off-by: Geert Uytterhoeven Acked-by: Jarod Wilson Signed-off-by: Mauro Carvalho Chehab --- include/media/lirc_dev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h index b1f60663cb39..71a896e7b208 100644 --- a/include/media/lirc_dev.h +++ b/include/media/lirc_dev.h @@ -139,7 +139,7 @@ struct lirc_driver { struct lirc_buffer *rbuf; int (*set_use_inc) (void *data); void (*set_use_dec) (void *data); - struct file_operations *fops; + const struct file_operations *fops; struct device *dev; struct module *owner; }; -- cgit v1.2.3 From 68617b31b39fdfd7920d55710994755e7259b16b Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Thu, 7 Oct 2010 21:56:48 -0300 Subject: [media] TerraTec remote controller keytable TerraTec slim remote, 7 rows, 4 columns. Uses NEC extended 0x02bd. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-terratec-slim.c | 79 +++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 81 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-terratec-slim.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index f755b21eef1a..1f85989d5af3 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -65,6 +65,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-streamzap.o \ rc-tbs-nec.o \ rc-terratec-cinergy-xs.o \ + rc-terratec-slim.o \ rc-tevii-nec.o \ rc-tt-1500.o \ rc-videomate-s350.o \ diff --git a/drivers/media/IR/keymaps/rc-terratec-slim.c b/drivers/media/IR/keymaps/rc-terratec-slim.c new file mode 100644 index 000000000000..70b08fe64079 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-terratec-slim.c @@ -0,0 +1,79 @@ +/* + * TerraTec remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* TerraTec slim remote, 7 rows, 4 columns. */ +/* Uses NEC extended 0x02bd. */ +static struct ir_scancode terratec_slim[] = { + { 0x02bd00, KEY_1 }, + { 0x02bd01, KEY_2 }, + { 0x02bd02, KEY_3 }, + { 0x02bd03, KEY_4 }, + { 0x02bd04, KEY_5 }, + { 0x02bd05, KEY_6 }, + { 0x02bd06, KEY_7 }, + { 0x02bd07, KEY_8 }, + { 0x02bd08, KEY_9 }, + { 0x02bd09, KEY_0 }, + { 0x02bd0a, KEY_MUTE }, + { 0x02bd0b, KEY_ZOOM }, /* symbol: PIP or zoom ? */ + { 0x02bd0e, KEY_VOLUMEDOWN }, + { 0x02bd0f, KEY_PLAYPAUSE }, + { 0x02bd10, KEY_RIGHT }, + { 0x02bd11, KEY_LEFT }, + { 0x02bd12, KEY_UP }, + { 0x02bd13, KEY_DOWN }, + { 0x02bd15, KEY_OK }, + { 0x02bd16, KEY_STOP }, + { 0x02bd17, KEY_CAMERA }, /* snapshot */ + { 0x02bd18, KEY_CHANNELUP }, + { 0x02bd19, KEY_RECORD }, + { 0x02bd1a, KEY_CHANNELDOWN }, + { 0x02bd1c, KEY_ESC }, + { 0x02bd1f, KEY_VOLUMEUP }, + { 0x02bd44, KEY_EPG }, + { 0x02bd45, KEY_POWER2 }, /* [red power button] */ +}; + +static struct rc_keymap terratec_slim_map = { + .map = { + .scan = terratec_slim, + .size = ARRAY_SIZE(terratec_slim), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_TERRATEC_SLIM, + } +}; + +static int __init init_rc_map_terratec_slim(void) +{ + return ir_register_map(&terratec_slim_map); +} + +static void __exit exit_rc_map_terratec_slim(void) +{ + ir_unregister_map(&terratec_slim_map); +} + +module_init(init_rc_map_terratec_slim) +module_exit(exit_rc_map_terratec_slim) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 57281b1008e4..5ba78f588bc6 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -122,6 +122,7 @@ void rc_map_init(void); #define RC_MAP_STREAMZAP "rc-streamzap" #define RC_MAP_TBS_NEC "rc-tbs-nec" #define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" +#define RC_MAP_TERRATEC_SLIM "rc-terratec-slim" #define RC_MAP_TEVII_NEC "rc-tevii-nec" #define RC_MAP_TT_1500 "rc-tt-1500" #define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350" -- cgit v1.2.3 From 76ba9c4d50c66ae43f2694c6ad652ddd4c3be000 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 06:56:46 -0300 Subject: [media] MSI DIGIVOX mini III remote controller keytable MSI DIGIVOX mini III remote controller. Uses NEC extended 0x61d6. This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote since rc-kworld-315u.c lacks NEC extended address byte. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-msi-digivox.c | 85 +++++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 87 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-msi-digivox.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 1f85989d5af3..2ad99ba21c8e 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -41,6 +41,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-lirc.o \ rc-lme2510.o \ rc-manli.o \ + rc-msi-digivox.o \ rc-msi-tvanywhere.o \ rc-msi-tvanywhere-plus.o \ rc-nebula.o \ diff --git a/drivers/media/IR/keymaps/rc-msi-digivox.c b/drivers/media/IR/keymaps/rc-msi-digivox.c new file mode 100644 index 000000000000..3ba314052689 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-msi-digivox.c @@ -0,0 +1,85 @@ +/* + * MSI DIGIVOX mini III remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* MSI DIGIVOX mini III */ +/* Uses NEC extended 0x61d6. */ +/* This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote + since rc-kworld-315u.c lacks NEC extended address byte. */ +static struct ir_scancode msi_digivox[] = { + { 0x61d601, KEY_VIDEO }, /* Source */ + { 0x61d602, KEY_3 }, + { 0x61d603, KEY_POWER2 }, /* ShutDown */ + { 0x61d604, KEY_1 }, + { 0x61d605, KEY_5 }, + { 0x61d606, KEY_6 }, + { 0x61d607, KEY_CHANNELDOWN }, /* CH- */ + { 0x61d608, KEY_2 }, + { 0x61d609, KEY_CHANNELUP }, /* CH+ */ + { 0x61d60a, KEY_9 }, + { 0x61d60b, KEY_ZOOM }, /* Zoom */ + { 0x61d60c, KEY_7 }, + { 0x61d60d, KEY_8 }, + { 0x61d60e, KEY_VOLUMEUP }, /* Vol+ */ + { 0x61d60f, KEY_4 }, + { 0x61d610, KEY_ESC }, /* [back up arrow] */ + { 0x61d611, KEY_0 }, + { 0x61d612, KEY_OK }, /* [enter arrow] */ + { 0x61d613, KEY_VOLUMEDOWN }, /* Vol- */ + { 0x61d614, KEY_RECORD }, /* Rec */ + { 0x61d615, KEY_STOP }, /* Stop */ + { 0x61d616, KEY_PLAY }, /* Play */ + { 0x61d617, KEY_MUTE }, /* Mute */ + { 0x61d618, KEY_UP }, + { 0x61d619, KEY_DOWN }, + { 0x61d61a, KEY_LEFT }, + { 0x61d61b, KEY_RIGHT }, + { 0x61d61c, KEY_RED }, + { 0x61d61d, KEY_GREEN }, + { 0x61d61e, KEY_YELLOW }, + { 0x61d61f, KEY_BLUE }, + { 0x61d643, KEY_POWER }, /* [red power button] */ +}; + +static struct rc_keymap msi_digivox_map = { + .map = { + .scan = msi_digivox, + .size = ARRAY_SIZE(msi_digivox), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_MSI_DIGIVOX, + } +}; + +static int __init init_rc_map_msi_digivox(void) +{ + return ir_register_map(&msi_digivox_map); +} + +static void __exit exit_rc_map_msi_digivox(void) +{ + ir_unregister_map(&msi_digivox_map); +} + +module_init(init_rc_map_msi_digivox) +module_exit(exit_rc_map_msi_digivox) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 5ba78f588bc6..cc636a4349ef 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -98,6 +98,7 @@ void rc_map_init(void); #define RC_MAP_LIRC "rc-lirc" #define RC_MAP_LME2510 "rc-lme2510" #define RC_MAP_MANLI "rc-manli" +#define RC_MAP_MSI_DIGIVOX "rc-msi-digivox" #define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus" #define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere" #define RC_MAP_NEBULA "rc-nebula" -- cgit v1.2.3 From a3d34e6ac362dafdb7aa0c3438b105c7822cdcd1 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 07:36:54 -0300 Subject: [media] TrekStor DVB-T USB Stick remote controller Imported from af9015.h. Initial keytable was from Marc Schneider Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-trekstor.c | 80 ++++++++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 82 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-trekstor.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 2ad99ba21c8e..2493e91fe38e 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -68,6 +68,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-terratec-cinergy-xs.o \ rc-terratec-slim.o \ rc-tevii-nec.o \ + rc-trekstor.o \ rc-tt-1500.o \ rc-videomate-s350.o \ rc-videomate-tv-pvr.o \ diff --git a/drivers/media/IR/keymaps/rc-trekstor.c b/drivers/media/IR/keymaps/rc-trekstor.c new file mode 100644 index 000000000000..91092caca452 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-trekstor.c @@ -0,0 +1,80 @@ +/* + * TrekStor remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* TrekStor DVB-T USB Stick remote controller. */ +/* Imported from af9015.h. + Initial keytable was from Marc Schneider */ +static struct ir_scancode trekstor[] = { + { 0x0084, KEY_0 }, + { 0x0085, KEY_MUTE }, /* Mute */ + { 0x0086, KEY_HOMEPAGE }, /* Home */ + { 0x0087, KEY_UP }, /* Up */ + { 0x0088, KEY_OK }, /* OK */ + { 0x0089, KEY_RIGHT }, /* Right */ + { 0x008a, KEY_FASTFORWARD }, /* Fast forward */ + { 0x008b, KEY_VOLUMEUP }, /* Volume + */ + { 0x008c, KEY_DOWN }, /* Down */ + { 0x008d, KEY_PLAY }, /* Play/Pause */ + { 0x008e, KEY_STOP }, /* Stop */ + { 0x008f, KEY_EPG }, /* Info/EPG */ + { 0x0090, KEY_7 }, + { 0x0091, KEY_4 }, + { 0x0092, KEY_1 }, + { 0x0093, KEY_CHANNELDOWN }, /* Channel - */ + { 0x0094, KEY_8 }, + { 0x0095, KEY_5 }, + { 0x0096, KEY_2 }, + { 0x0097, KEY_CHANNELUP }, /* Channel + */ + { 0x0098, KEY_9 }, + { 0x0099, KEY_6 }, + { 0x009a, KEY_3 }, + { 0x009b, KEY_VOLUMEDOWN }, /* Volume - */ + { 0x009c, KEY_TV }, /* TV */ + { 0x009d, KEY_RECORD }, /* Record */ + { 0x009e, KEY_REWIND }, /* Rewind */ + { 0x009f, KEY_LEFT }, /* Left */ +}; + +static struct rc_keymap trekstor_map = { + .map = { + .scan = trekstor, + .size = ARRAY_SIZE(trekstor), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_TREKSTOR, + } +}; + +static int __init init_rc_map_trekstor(void) +{ + return ir_register_map(&trekstor_map); +} + +static void __exit exit_rc_map_trekstor(void) +{ + ir_unregister_map(&trekstor_map); +} + +module_init(init_rc_map_trekstor) +module_exit(exit_rc_map_trekstor) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index cc636a4349ef..8251d201ea31 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -125,6 +125,7 @@ void rc_map_init(void); #define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" #define RC_MAP_TERRATEC_SLIM "rc-terratec-slim" #define RC_MAP_TEVII_NEC "rc-tevii-nec" +#define RC_MAP_TREKSTOR "rc-trekstor" #define RC_MAP_TT_1500 "rc-tt-1500" #define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350" #define RC_MAP_VIDEOMATE_TV_PVR "rc-videomate-tv-pvr" -- cgit v1.2.3 From ff533801bd9fa91fc61053900fd40b10132427c0 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 08:24:00 -0300 Subject: [media] Digittrade DVB-T USB Stick remote controller keytable Digittrade DVB-T USB Stick remote controller. Imported from af9015.h. Initial keytable was from Alain Kalker Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-digittrade.c | 82 ++++++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 84 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-digittrade.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 2493e91fe38e..f016d5d99eaf 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-cinergy.o \ rc-dib0700-nec.o \ rc-dib0700-rc5.o \ + rc-digittrade.o \ rc-dm1105-nec.o \ rc-dntv-live-dvb-t.o \ rc-dntv-live-dvbt-pro.o \ diff --git a/drivers/media/IR/keymaps/rc-digittrade.c b/drivers/media/IR/keymaps/rc-digittrade.c new file mode 100644 index 000000000000..5dece78e19c5 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-digittrade.c @@ -0,0 +1,82 @@ +/* + * Digittrade DVB-T USB Stick remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* Digittrade DVB-T USB Stick remote controller. */ +/* Imported from af9015.h. + Initial keytable was from Alain Kalker */ + +/* Digittrade DVB-T USB Stick */ +static struct ir_scancode digittrade[] = { + { 0x0000, KEY_9 }, + { 0x0001, KEY_EPG }, /* EPG */ + { 0x0002, KEY_VOLUMEDOWN }, /* Vol Dn */ + { 0x0003, KEY_TEXT }, /* TELETEXT */ + { 0x0004, KEY_8 }, + { 0x0005, KEY_MUTE }, /* MUTE */ + { 0x0006, KEY_POWER2 }, /* POWER */ + { 0x0009, KEY_ZOOM }, /* FULLSCREEN */ + { 0x000a, KEY_RECORD }, /* RECORD */ + { 0x000d, KEY_SUBTITLE }, /* SUBTITLE */ + { 0x000e, KEY_STOP }, /* STOP */ + { 0x0010, KEY_OK }, /* RETURN */ + { 0x0011, KEY_2 }, + { 0x0012, KEY_4 }, + { 0x0015, KEY_3 }, + { 0x0016, KEY_5 }, + { 0x0017, KEY_CHANNELDOWN }, /* Ch Dn */ + { 0x0019, KEY_CHANNELUP }, /* CH Up */ + { 0x001a, KEY_PAUSE }, /* PAUSE */ + { 0x001b, KEY_1 }, + { 0x001d, KEY_AUDIO }, /* DUAL SOUND */ + { 0x001e, KEY_PLAY }, /* PLAY */ + { 0x001f, KEY_CAMERA }, /* SNAPSHOT */ + { 0x0040, KEY_VOLUMEUP }, /* Vol Up */ + { 0x0048, KEY_7 }, + { 0x004c, KEY_6 }, + { 0x004d, KEY_PLAYPAUSE }, /* TIMESHIFT */ + { 0x0054, KEY_0 }, +}; + +static struct rc_keymap digittrade_map = { + .map = { + .scan = digittrade, + .size = ARRAY_SIZE(digittrade), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_DIGITTRADE, + } +}; + +static int __init init_rc_map_digittrade(void) +{ + return ir_register_map(&digittrade_map); +} + +static void __exit exit_rc_map_digittrade(void) +{ + ir_unregister_map(&digittrade_map); +} + +module_init(init_rc_map_digittrade) +module_exit(exit_rc_map_digittrade) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 8251d201ea31..2e06835da238 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -72,6 +72,7 @@ void rc_map_init(void); #define RC_MAP_CINERGY "rc-cinergy" #define RC_MAP_DIB0700_NEC_TABLE "rc-dib0700-nec" #define RC_MAP_DIB0700_RC5_TABLE "rc-dib0700-rc5" +#define RC_MAP_DIGITTRADE "rc-digittrade" #define RC_MAP_DM1105_NEC "rc-dm1105-nec" #define RC_MAP_DNTV_LIVE_DVBT_PRO "rc-dntv-live-dvbt-pro" #define RC_MAP_DNTV_LIVE_DVB_T "rc-dntv-live-dvb-t" -- cgit v1.2.3 From ae54a699c3d625ae2b4f87350ecb97ba034a656b Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 10:59:48 -0300 Subject: [media] AverMedia RM-KS remote controller keytable Imported from af9015.h. Initial keytable was from Jose Alberto Reguero and Felipe Morales Moreno Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-avermedia-rm-ks.c | 79 +++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 81 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-avermedia-rm-ks.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index f016d5d99eaf..743a57f85ac3 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-avermedia-dvbt.o \ rc-avermedia-m135a.o \ rc-avermedia-m733a-rm-k6.o \ + rc-avermedia-rm-ks.o \ rc-avertv-303.o \ rc-behold.o \ rc-behold-columbus.o \ diff --git a/drivers/media/IR/keymaps/rc-avermedia-rm-ks.c b/drivers/media/IR/keymaps/rc-avermedia-rm-ks.c new file mode 100644 index 000000000000..9ee60906c861 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-avermedia-rm-ks.c @@ -0,0 +1,79 @@ +/* + * AverMedia RM-KS remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* Initial keytable is from Jose Alberto Reguero + and Felipe Morales Moreno */ +/* FIXME: mappings are not 100% correct? */ +static struct ir_scancode avermedia_rm_ks[] = { + { 0x0501, KEY_POWER2 }, + { 0x0502, KEY_CHANNELUP }, + { 0x0503, KEY_CHANNELDOWN }, + { 0x0504, KEY_VOLUMEUP }, + { 0x0505, KEY_VOLUMEDOWN }, + { 0x0506, KEY_MUTE }, + { 0x0507, KEY_RIGHT }, + { 0x0508, KEY_PROG1 }, + { 0x0509, KEY_1 }, + { 0x050a, KEY_2 }, + { 0x050b, KEY_3 }, + { 0x050c, KEY_4 }, + { 0x050d, KEY_5 }, + { 0x050e, KEY_6 }, + { 0x050f, KEY_7 }, + { 0x0510, KEY_8 }, + { 0x0511, KEY_9 }, + { 0x0512, KEY_0 }, + { 0x0513, KEY_AUDIO }, + { 0x0515, KEY_EPG }, + { 0x0516, KEY_PLAY }, + { 0x0517, KEY_RECORD }, + { 0x0518, KEY_STOP }, + { 0x051c, KEY_BACK }, + { 0x051d, KEY_FORWARD }, + { 0x054d, KEY_LEFT }, + { 0x0556, KEY_ZOOM }, +}; + +static struct rc_keymap avermedia_rm_ks_map = { + .map = { + .scan = avermedia_rm_ks, + .size = ARRAY_SIZE(avermedia_rm_ks), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_AVERMEDIA_RM_KS, + } +}; + +static int __init init_rc_map_avermedia_rm_ks(void) +{ + return ir_register_map(&avermedia_rm_ks_map); +} + +static void __exit exit_rc_map_avermedia_rm_ks(void) +{ + ir_unregister_map(&avermedia_rm_ks_map); +} + +module_init(init_rc_map_avermedia_rm_ks) +module_exit(exit_rc_map_avermedia_rm_ks) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 2e06835da238..db1f9885ed7b 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -63,6 +63,7 @@ void rc_map_init(void); #define RC_MAP_AVERMEDIA_DVBT "rc-avermedia-dvbt" #define RC_MAP_AVERMEDIA_M135A "rc-avermedia-m135a" #define RC_MAP_AVERMEDIA_M733A_RM_K6 "rc-avermedia-m733a-rm-k6" +#define RC_MAP_AVERMEDIA_RM_KS "rc-avermedia-rm-ks" #define RC_MAP_AVERMEDIA "rc-avermedia" #define RC_MAP_AVERTV_303 "rc-avertv-303" #define RC_MAP_BEHOLD_COLUMBUS "rc-behold-columbus" -- cgit v1.2.3 From a7a177877cbfa0de15410a4d00984bdb2aaf4ea6 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 16:08:13 -0300 Subject: [media] LeadTek Y04G0051 remote controller keytable Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-leadtek-y04g0051.c | 99 ++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 101 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-leadtek-y04g0051.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 743a57f85ac3..c5436637ffde 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -40,6 +40,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-kaiomy.o \ rc-kworld-315u.o \ rc-kworld-plus-tv-analog.o \ + rc-leadtek-y04g0051.o \ rc-lirc.o \ rc-lme2510.o \ rc-manli.o \ diff --git a/drivers/media/IR/keymaps/rc-leadtek-y04g0051.c b/drivers/media/IR/keymaps/rc-leadtek-y04g0051.c new file mode 100644 index 000000000000..7521315fd876 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-leadtek-y04g0051.c @@ -0,0 +1,99 @@ +/* + * LeadTek Y04G0051 remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +static struct ir_scancode leadtek_y04g0051[] = { + { 0x0300, KEY_POWER2 }, + { 0x0303, KEY_SCREEN }, + { 0x0304, KEY_RIGHT }, + { 0x0305, KEY_1 }, + { 0x0306, KEY_2 }, + { 0x0307, KEY_3 }, + { 0x0308, KEY_LEFT }, + { 0x0309, KEY_4 }, + { 0x030a, KEY_5 }, + { 0x030b, KEY_6 }, + { 0x030c, KEY_UP }, + { 0x030d, KEY_7 }, + { 0x030e, KEY_8 }, + { 0x030f, KEY_9 }, + { 0x0310, KEY_DOWN }, + { 0x0311, KEY_AGAIN }, + { 0x0312, KEY_0 }, + { 0x0313, KEY_OK }, /* 1st ok */ + { 0x0314, KEY_MUTE }, + { 0x0316, KEY_OK }, /* 2nd ok */ + { 0x031e, KEY_VIDEO }, /* 2nd video */ + { 0x031b, KEY_AUDIO }, + { 0x031f, KEY_TEXT }, + { 0x0340, KEY_SLEEP }, + { 0x0341, KEY_DOT }, + { 0x0342, KEY_REWIND }, + { 0x0343, KEY_PLAY }, + { 0x0344, KEY_FASTFORWARD }, + { 0x0345, KEY_TIME }, + { 0x0346, KEY_STOP }, /* 2nd stop */ + { 0x0347, KEY_RECORD }, + { 0x0348, KEY_CAMERA }, + { 0x0349, KEY_ESC }, + { 0x034a, KEY_NEW }, + { 0x034b, KEY_RED }, + { 0x034c, KEY_GREEN }, + { 0x034d, KEY_YELLOW }, + { 0x034e, KEY_BLUE }, + { 0x034f, KEY_MENU }, + { 0x0350, KEY_STOP }, /* 1st stop */ + { 0x0351, KEY_CHANNEL }, + { 0x0352, KEY_VIDEO }, /* 1st video */ + { 0x0353, KEY_EPG }, + { 0x0354, KEY_PREVIOUS }, + { 0x0355, KEY_NEXT }, + { 0x0356, KEY_TV }, + { 0x035a, KEY_VOLUMEDOWN }, + { 0x035b, KEY_CHANNELUP }, + { 0x035e, KEY_VOLUMEUP }, + { 0x035f, KEY_CHANNELDOWN }, +}; + +static struct rc_keymap leadtek_y04g0051_map = { + .map = { + .scan = leadtek_y04g0051, + .size = ARRAY_SIZE(leadtek_y04g0051), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_LEADTEK_Y04G0051, + } +}; + +static int __init init_rc_map_leadtek_y04g0051(void) +{ + return ir_register_map(&leadtek_y04g0051_map); +} + +static void __exit exit_rc_map_leadtek_y04g0051(void) +{ + ir_unregister_map(&leadtek_y04g0051_map); +} + +module_init(init_rc_map_leadtek_y04g0051) +module_exit(exit_rc_map_leadtek_y04g0051) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index db1f9885ed7b..a4c2343f7d34 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -97,6 +97,7 @@ void rc_map_init(void); #define RC_MAP_KAIOMY "rc-kaiomy" #define RC_MAP_KWORLD_315U "rc-kworld-315u" #define RC_MAP_KWORLD_PLUS_TV_ANALOG "rc-kworld-plus-tv-analog" +#define RC_MAP_LEADTEK_Y04G0051 "rc-leadtek-y04g0051" #define RC_MAP_LIRC "rc-lirc" #define RC_MAP_LME2510 "rc-lme2510" #define RC_MAP_MANLI "rc-manli" -- cgit v1.2.3 From 3f37fcedb2a104ba9d70a5a9c4c89abe4ef075d6 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 17:31:59 -0300 Subject: [media] TwinHan AzureWave AD-TU700(704J) remote controller Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c | 102 +++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 104 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index c5436637ffde..ee6b6774255f 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-avermedia-m733a-rm-k6.o \ rc-avermedia-rm-ks.o \ rc-avertv-303.o \ + rc-azurewave-ad-tu700.o \ rc-behold.o \ rc-behold-columbus.o \ rc-budget-ci-old.o \ diff --git a/drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c b/drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c new file mode 100644 index 000000000000..e0876147d471 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-azurewave-ad-tu700.c @@ -0,0 +1,102 @@ +/* + * TwinHan AzureWave AD-TU700(704J) remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +static struct ir_scancode azurewave_ad_tu700[] = { + { 0x0000, KEY_TAB }, /* Tab */ + { 0x0001, KEY_2 }, + { 0x0002, KEY_CHANNELDOWN }, + { 0x0003, KEY_1 }, + { 0x0004, KEY_MENU }, /* Record List */ + { 0x0005, KEY_CHANNELUP }, + { 0x0006, KEY_3 }, + { 0x0007, KEY_SLEEP }, /* Hibernate */ + { 0x0008, KEY_VIDEO }, /* A/V */ + { 0x0009, KEY_4 }, + { 0x000a, KEY_VOLUMEDOWN }, + { 0x000c, KEY_CANCEL }, /* Cancel */ + { 0x000d, KEY_7 }, + { 0x000e, KEY_AGAIN }, /* Recall */ + { 0x000f, KEY_TEXT }, /* Teletext */ + { 0x0010, KEY_MUTE }, + { 0x0011, KEY_RECORD }, + { 0x0012, KEY_FASTFORWARD }, /* FF >> */ + { 0x0013, KEY_BACK }, /* Back */ + { 0x0014, KEY_PLAY }, + { 0x0015, KEY_0 }, + { 0x0016, KEY_POWER2 }, /* [red power button] */ + { 0x0017, KEY_FAVORITES }, /* Favorite List */ + { 0x0018, KEY_RED }, + { 0x0019, KEY_8 }, + { 0x001a, KEY_STOP }, + { 0x001b, KEY_9 }, + { 0x001c, KEY_EPG }, /* Info/EPG */ + { 0x001d, KEY_5 }, + { 0x001e, KEY_VOLUMEUP }, + { 0x001f, KEY_6 }, + { 0x0040, KEY_REWIND }, /* FR << */ + { 0x0041, KEY_PREVIOUS }, /* Replay */ + { 0x0042, KEY_NEXT }, /* Skip */ + { 0x0043, KEY_SUBTITLE }, /* Subtitle / CC */ + { 0x0045, KEY_KPPLUS }, /* Zoom+ */ + { 0x0046, KEY_KPMINUS }, /* Zoom- */ + { 0x0047, KEY_NEW }, /* PIP */ + { 0x0048, KEY_INFO }, /* Preview */ + { 0x0049, KEY_MODE }, /* L/R */ + { 0x004a, KEY_CLEAR }, /* Clear */ + { 0x004b, KEY_UP }, /* up arrow */ + { 0x004c, KEY_PAUSE }, + { 0x004d, KEY_ZOOM }, /* Full Screen */ + { 0x004e, KEY_LEFT }, /* left arrow */ + { 0x004f, KEY_OK }, /* Enter / ok */ + { 0x0050, KEY_LANGUAGE }, /* SAP */ + { 0x0051, KEY_DOWN }, /* down arrow */ + { 0x0052, KEY_RIGHT }, /* right arrow */ + { 0x0053, KEY_GREEN }, + { 0x0054, KEY_CAMERA }, /* Capture */ + { 0x005e, KEY_YELLOW }, + { 0x005f, KEY_BLUE }, +}; + +static struct rc_keymap azurewave_ad_tu700_map = { + .map = { + .scan = azurewave_ad_tu700, + .size = ARRAY_SIZE(azurewave_ad_tu700), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_AZUREWAVE_AD_TU700, + } +}; + +static int __init init_rc_map_azurewave_ad_tu700(void) +{ + return ir_register_map(&azurewave_ad_tu700_map); +} + +static void __exit exit_rc_map_azurewave_ad_tu700(void) +{ + ir_unregister_map(&azurewave_ad_tu700_map); +} + +module_init(init_rc_map_azurewave_ad_tu700) +module_exit(exit_rc_map_azurewave_ad_tu700) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index a4c2343f7d34..3d281a7b3cee 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -66,6 +66,7 @@ void rc_map_init(void); #define RC_MAP_AVERMEDIA_RM_KS "rc-avermedia-rm-ks" #define RC_MAP_AVERMEDIA "rc-avermedia" #define RC_MAP_AVERTV_303 "rc-avertv-303" +#define RC_MAP_AZUREWAVE_AD_TU700 "rc-azurewave-ad-tu700" #define RC_MAP_BEHOLD_COLUMBUS "rc-behold-columbus" #define RC_MAP_BEHOLD "rc-behold" #define RC_MAP_BUDGET_CI_OLD "rc-budget-ci-old" -- cgit v1.2.3 From ad7fac348470b6b2ac0b4579e3bdb6da5a6166e0 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 18:54:13 -0300 Subject: [media] A-Link DTU(m) remote controller Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-alink-dtu-m.c | 68 +++++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 70 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-alink-dtu-m.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index ee6b6774255f..3a44b6765d04 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ + rc-alink-dtu-m.o \ rc-apac-viewcomp.o \ rc-asus-pc39.o \ rc-ati-tv-wonder-hd-600.o \ diff --git a/drivers/media/IR/keymaps/rc-alink-dtu-m.c b/drivers/media/IR/keymaps/rc-alink-dtu-m.c new file mode 100644 index 000000000000..6888ea2e4b91 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-alink-dtu-m.c @@ -0,0 +1,68 @@ +/* + * A-Link DTU(m) remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* A-Link DTU(m) slim remote, 6 rows, 3 columns. */ +static struct ir_scancode alink_dtu_m[] = { + { 0x0800, KEY_VOLUMEUP }, + { 0x0801, KEY_1 }, + { 0x0802, KEY_3 }, + { 0x0803, KEY_7 }, + { 0x0804, KEY_9 }, + { 0x0805, KEY_ZOOM }, /* [two windows + corner arrows] */ + { 0x0806, KEY_0 }, + { 0x0807, KEY_CHANNEL }, /* JUMP */ + { 0x080d, KEY_5 }, + { 0x080f, KEY_2 }, + { 0x0812, KEY_POWER2 }, + { 0x0814, KEY_CHANNELUP }, + { 0x0816, KEY_VOLUMEDOWN }, + { 0x0818, KEY_6 }, + { 0x081a, KEY_MUTE }, + { 0x081b, KEY_8 }, + { 0x081c, KEY_4 }, + { 0x081d, KEY_CHANNELDOWN }, +}; + +static struct rc_keymap alink_dtu_m_map = { + .map = { + .scan = alink_dtu_m, + .size = ARRAY_SIZE(alink_dtu_m), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_ALINK_DTU_M, + } +}; + +static int __init init_rc_map_alink_dtu_m(void) +{ + return ir_register_map(&alink_dtu_m_map); +} + +static void __exit exit_rc_map_alink_dtu_m(void) +{ + ir_unregister_map(&alink_dtu_m_map); +} + +module_init(init_rc_map_alink_dtu_m) +module_exit(exit_rc_map_alink_dtu_m) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 3d281a7b3cee..ddad3dad8690 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -55,6 +55,7 @@ void rc_map_init(void); /* Names of the several keytables defined in-kernel */ #define RC_MAP_ADSTECH_DVB_T_PCI "rc-adstech-dvb-t-pci" +#define RC_MAP_ALINK_DTU_M "rc-alink-dtu-m" #define RC_MAP_APAC_VIEWCOMP "rc-apac-viewcomp" #define RC_MAP_ASUS_PC39 "rc-asus-pc39" #define RC_MAP_ATI_TV_WONDER_HD_600 "rc-ati-tv-wonder-hd-600" -- cgit v1.2.3 From c12d2f746b34baf9e97cae06a8757dc6be387e62 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 19:12:58 -0300 Subject: [media] MSI DIGIVOX mini II remote controller Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-msi-digivox-ii.c | 67 ++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 69 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-msi-digivox-ii.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 3a44b6765d04..c3a8ab875a74 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-lme2510.o \ rc-manli.o \ rc-msi-digivox.o \ + rc-msi-digivox-ii.o \ rc-msi-tvanywhere.o \ rc-msi-tvanywhere-plus.o \ rc-nebula.o \ diff --git a/drivers/media/IR/keymaps/rc-msi-digivox-ii.c b/drivers/media/IR/keymaps/rc-msi-digivox-ii.c new file mode 100644 index 000000000000..67237fbf9e4b --- /dev/null +++ b/drivers/media/IR/keymaps/rc-msi-digivox-ii.c @@ -0,0 +1,67 @@ +/* + * MSI DIGIVOX mini II remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +static struct ir_scancode msi_digivox_ii[] = { + { 0x0002, KEY_2 }, + { 0x0003, KEY_UP }, /* up */ + { 0x0004, KEY_3 }, + { 0x0005, KEY_CHANNELDOWN }, + { 0x0008, KEY_5 }, + { 0x0009, KEY_0 }, + { 0x000b, KEY_8 }, + { 0x000d, KEY_DOWN }, /* down */ + { 0x0010, KEY_9 }, + { 0x0011, KEY_7 }, + { 0x0014, KEY_VOLUMEUP }, + { 0x0015, KEY_CHANNELUP }, + { 0x0016, KEY_OK }, + { 0x0017, KEY_POWER2 }, + { 0x001a, KEY_1 }, + { 0x001c, KEY_4 }, + { 0x001d, KEY_6 }, + { 0x001f, KEY_VOLUMEDOWN }, +}; + +static struct rc_keymap msi_digivox_ii_map = { + .map = { + .scan = msi_digivox_ii, + .size = ARRAY_SIZE(msi_digivox_ii), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_MSI_DIGIVOX_II, + } +}; + +static int __init init_rc_map_msi_digivox_ii(void) +{ + return ir_register_map(&msi_digivox_ii_map); +} + +static void __exit exit_rc_map_msi_digivox_ii(void) +{ + ir_unregister_map(&msi_digivox_ii_map); +} + +module_init(init_rc_map_msi_digivox_ii) +module_exit(exit_rc_map_msi_digivox_ii) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index ddad3dad8690..b31992323c24 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -104,6 +104,7 @@ void rc_map_init(void); #define RC_MAP_LME2510 "rc-lme2510" #define RC_MAP_MANLI "rc-manli" #define RC_MAP_MSI_DIGIVOX "rc-msi-digivox" +#define RC_MAP_MSI_DIGIVOX_II "rc-msi-digivox-ii" #define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus" #define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere" #define RC_MAP_NEBULA "rc-nebula" -- cgit v1.2.3 From 860d1e29205860ebab539e41011e765e1bc417a1 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 20:19:23 -0300 Subject: [media] rename rc-msi-digivox.c -> rc-msi-digivox-iii.c Rename remote controller driver I added earlier. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 2 +- drivers/media/IR/keymaps/rc-msi-digivox-iii.c | 85 +++++++++++++++++++++++++++ drivers/media/IR/keymaps/rc-msi-digivox.c | 85 --------------------------- include/media/rc-map.h | 2 +- 4 files changed, 87 insertions(+), 87 deletions(-) create mode 100644 drivers/media/IR/keymaps/rc-msi-digivox-iii.c delete mode 100644 drivers/media/IR/keymaps/rc-msi-digivox.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index c3a8ab875a74..8053b20474fe 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -46,8 +46,8 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-lirc.o \ rc-lme2510.o \ rc-manli.o \ - rc-msi-digivox.o \ rc-msi-digivox-ii.o \ + rc-msi-digivox-iii.o \ rc-msi-tvanywhere.o \ rc-msi-tvanywhere-plus.o \ rc-nebula.o \ diff --git a/drivers/media/IR/keymaps/rc-msi-digivox-iii.c b/drivers/media/IR/keymaps/rc-msi-digivox-iii.c new file mode 100644 index 000000000000..8ea3960347c3 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-msi-digivox-iii.c @@ -0,0 +1,85 @@ +/* + * MSI DIGIVOX mini III remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* MSI DIGIVOX mini III */ +/* Uses NEC extended 0x61d6. */ +/* This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote + since rc-kworld-315u.c lacks NEC extended address byte. */ +static struct ir_scancode msi_digivox_iii[] = { + { 0x61d601, KEY_VIDEO }, /* Source */ + { 0x61d602, KEY_3 }, + { 0x61d603, KEY_POWER2 }, /* ShutDown */ + { 0x61d604, KEY_1 }, + { 0x61d605, KEY_5 }, + { 0x61d606, KEY_6 }, + { 0x61d607, KEY_CHANNELDOWN }, /* CH- */ + { 0x61d608, KEY_2 }, + { 0x61d609, KEY_CHANNELUP }, /* CH+ */ + { 0x61d60a, KEY_9 }, + { 0x61d60b, KEY_ZOOM }, /* Zoom */ + { 0x61d60c, KEY_7 }, + { 0x61d60d, KEY_8 }, + { 0x61d60e, KEY_VOLUMEUP }, /* Vol+ */ + { 0x61d60f, KEY_4 }, + { 0x61d610, KEY_ESC }, /* [back up arrow] */ + { 0x61d611, KEY_0 }, + { 0x61d612, KEY_OK }, /* [enter arrow] */ + { 0x61d613, KEY_VOLUMEDOWN }, /* Vol- */ + { 0x61d614, KEY_RECORD }, /* Rec */ + { 0x61d615, KEY_STOP }, /* Stop */ + { 0x61d616, KEY_PLAY }, /* Play */ + { 0x61d617, KEY_MUTE }, /* Mute */ + { 0x61d618, KEY_UP }, + { 0x61d619, KEY_DOWN }, + { 0x61d61a, KEY_LEFT }, + { 0x61d61b, KEY_RIGHT }, + { 0x61d61c, KEY_RED }, + { 0x61d61d, KEY_GREEN }, + { 0x61d61e, KEY_YELLOW }, + { 0x61d61f, KEY_BLUE }, + { 0x61d643, KEY_POWER }, /* [red power button] */ +}; + +static struct rc_keymap msi_digivox_iii_map = { + .map = { + .scan = msi_digivox_iii, + .size = ARRAY_SIZE(msi_digivox_iii), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_MSI_DIGIVOX_III, + } +}; + +static int __init init_rc_map_msi_digivox_iii(void) +{ + return ir_register_map(&msi_digivox_iii_map); +} + +static void __exit exit_rc_map_msi_digivox_iii(void) +{ + ir_unregister_map(&msi_digivox_iii_map); +} + +module_init(init_rc_map_msi_digivox_iii) +module_exit(exit_rc_map_msi_digivox_iii) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/drivers/media/IR/keymaps/rc-msi-digivox.c b/drivers/media/IR/keymaps/rc-msi-digivox.c deleted file mode 100644 index 3ba314052689..000000000000 --- a/drivers/media/IR/keymaps/rc-msi-digivox.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * MSI DIGIVOX mini III remote controller keytable - * - * Copyright (C) 2010 Antti Palosaari - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include - -/* MSI DIGIVOX mini III */ -/* Uses NEC extended 0x61d6. */ -/* This remote seems to be same as rc-kworld-315u.c. Anyhow, add new remote - since rc-kworld-315u.c lacks NEC extended address byte. */ -static struct ir_scancode msi_digivox[] = { - { 0x61d601, KEY_VIDEO }, /* Source */ - { 0x61d602, KEY_3 }, - { 0x61d603, KEY_POWER2 }, /* ShutDown */ - { 0x61d604, KEY_1 }, - { 0x61d605, KEY_5 }, - { 0x61d606, KEY_6 }, - { 0x61d607, KEY_CHANNELDOWN }, /* CH- */ - { 0x61d608, KEY_2 }, - { 0x61d609, KEY_CHANNELUP }, /* CH+ */ - { 0x61d60a, KEY_9 }, - { 0x61d60b, KEY_ZOOM }, /* Zoom */ - { 0x61d60c, KEY_7 }, - { 0x61d60d, KEY_8 }, - { 0x61d60e, KEY_VOLUMEUP }, /* Vol+ */ - { 0x61d60f, KEY_4 }, - { 0x61d610, KEY_ESC }, /* [back up arrow] */ - { 0x61d611, KEY_0 }, - { 0x61d612, KEY_OK }, /* [enter arrow] */ - { 0x61d613, KEY_VOLUMEDOWN }, /* Vol- */ - { 0x61d614, KEY_RECORD }, /* Rec */ - { 0x61d615, KEY_STOP }, /* Stop */ - { 0x61d616, KEY_PLAY }, /* Play */ - { 0x61d617, KEY_MUTE }, /* Mute */ - { 0x61d618, KEY_UP }, - { 0x61d619, KEY_DOWN }, - { 0x61d61a, KEY_LEFT }, - { 0x61d61b, KEY_RIGHT }, - { 0x61d61c, KEY_RED }, - { 0x61d61d, KEY_GREEN }, - { 0x61d61e, KEY_YELLOW }, - { 0x61d61f, KEY_BLUE }, - { 0x61d643, KEY_POWER }, /* [red power button] */ -}; - -static struct rc_keymap msi_digivox_map = { - .map = { - .scan = msi_digivox, - .size = ARRAY_SIZE(msi_digivox), - .ir_type = IR_TYPE_NEC, - .name = RC_MAP_MSI_DIGIVOX, - } -}; - -static int __init init_rc_map_msi_digivox(void) -{ - return ir_register_map(&msi_digivox_map); -} - -static void __exit exit_rc_map_msi_digivox(void) -{ - ir_unregister_map(&msi_digivox_map); -} - -module_init(init_rc_map_msi_digivox) -module_exit(exit_rc_map_msi_digivox) - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index b31992323c24..f9fe29afe3df 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -103,8 +103,8 @@ void rc_map_init(void); #define RC_MAP_LIRC "rc-lirc" #define RC_MAP_LME2510 "rc-lme2510" #define RC_MAP_MANLI "rc-manli" -#define RC_MAP_MSI_DIGIVOX "rc-msi-digivox" #define RC_MAP_MSI_DIGIVOX_II "rc-msi-digivox-ii" +#define RC_MAP_MSI_DIGIVOX_III "rc-msi-digivox-iii" #define RC_MAP_MSI_TVANYWHERE_PLUS "rc-msi-tvanywhere-plus" #define RC_MAP_MSI_TVANYWHERE "rc-msi-tvanywhere" #define RC_MAP_NEBULA "rc-nebula" -- cgit v1.2.3 From 20d747b4c44ba1a5c8604a88dc898260a2a3bcf8 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Mon, 11 Oct 2010 20:25:44 -0300 Subject: [media] Total Media In Hand remote controller Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-total-media-in-hand.c | 85 +++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 87 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-total-media-in-hand.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 8053b20474fe..11688dd740ca 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -74,6 +74,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-terratec-cinergy-xs.o \ rc-terratec-slim.o \ rc-tevii-nec.o \ + rc-total-media-in-hand.o \ rc-trekstor.o \ rc-tt-1500.o \ rc-videomate-s350.o \ diff --git a/drivers/media/IR/keymaps/rc-total-media-in-hand.c b/drivers/media/IR/keymaps/rc-total-media-in-hand.c new file mode 100644 index 000000000000..fd1985763781 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-total-media-in-hand.c @@ -0,0 +1,85 @@ +/* + * Total Media In Hand remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +/* Uses NEC extended 0x02bd */ +static struct ir_scancode total_media_in_hand[] = { + { 0x02bd00, KEY_1 }, + { 0x02bd01, KEY_2 }, + { 0x02bd02, KEY_3 }, + { 0x02bd03, KEY_4 }, + { 0x02bd04, KEY_5 }, + { 0x02bd05, KEY_6 }, + { 0x02bd06, KEY_7 }, + { 0x02bd07, KEY_8 }, + { 0x02bd08, KEY_9 }, + { 0x02bd09, KEY_0 }, + { 0x02bd0a, KEY_MUTE }, + { 0x02bd0b, KEY_CYCLEWINDOWS }, /* yellow, [min / max] */ + { 0x02bd0c, KEY_VIDEO }, /* TV / AV */ + { 0x02bd0e, KEY_VOLUMEDOWN }, + { 0x02bd0f, KEY_TIME }, /* TimeShift */ + { 0x02bd10, KEY_RIGHT }, /* right arrow */ + { 0x02bd11, KEY_LEFT }, /* left arrow */ + { 0x02bd12, KEY_UP }, /* up arrow */ + { 0x02bd13, KEY_DOWN }, /* down arrow */ + { 0x02bd14, KEY_POWER2 }, /* [red] */ + { 0x02bd15, KEY_OK }, /* OK */ + { 0x02bd16, KEY_STOP }, + { 0x02bd17, KEY_CAMERA }, /* Snapshot */ + { 0x02bd18, KEY_CHANNELUP }, + { 0x02bd19, KEY_RECORD }, + { 0x02bd1a, KEY_CHANNELDOWN }, + { 0x02bd1c, KEY_ESC }, /* Esc */ + { 0x02bd1e, KEY_PLAY }, + { 0x02bd1f, KEY_VOLUMEUP }, + { 0x02bd40, KEY_PAUSE }, + { 0x02bd41, KEY_FASTFORWARD }, /* FF >> */ + { 0x02bd42, KEY_REWIND }, /* FR << */ + { 0x02bd43, KEY_ZOOM }, /* [window + mouse pointer] */ + { 0x02bd44, KEY_SHUFFLE }, /* Shuffle */ + { 0x02bd45, KEY_INFO }, /* [red (I)] */ +}; + +static struct rc_keymap total_media_in_hand_map = { + .map = { + .scan = total_media_in_hand, + .size = ARRAY_SIZE(total_media_in_hand), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_TOTAL_MEDIA_IN_HAND, + } +}; + +static int __init init_rc_map_total_media_in_hand(void) +{ + return ir_register_map(&total_media_in_hand_map); +} + +static void __exit exit_rc_map_total_media_in_hand(void) +{ + ir_unregister_map(&total_media_in_hand_map); +} + +module_init(init_rc_map_total_media_in_hand) +module_exit(exit_rc_map_total_media_in_hand) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index f9fe29afe3df..d1bff027297e 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -131,6 +131,7 @@ void rc_map_init(void); #define RC_MAP_TERRATEC_CINERGY_XS "rc-terratec-cinergy-xs" #define RC_MAP_TERRATEC_SLIM "rc-terratec-slim" #define RC_MAP_TEVII_NEC "rc-tevii-nec" +#define RC_MAP_TOTAL_MEDIA_IN_HAND "rc-total-media-in-hand" #define RC_MAP_TREKSTOR "rc-trekstor" #define RC_MAP_TT_1500 "rc-tt-1500" #define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350" -- cgit v1.2.3 From be1f985ffa49467f604318182616678b3e5184fd Mon Sep 17 00:00:00 2001 From: Jarod Wilson Date: Fri, 8 Oct 2010 17:24:21 -0300 Subject: [media] IR/lirc: further ioctl portability fixups >From Joris van Rantwijk : I tested lirc_serial and found that it works fine. Except the LIRC ioctls do not work in my 64-bit-kernel/32-bit-user setup. I added compat_ioctl entries in the drivers to fix this. While doing so, I noticed inconsistencies in the argument type of the LIRC ioctls. All ioctls are declared in lirc.h as having argument type __u32, however there are a few places where the driver calls get_user/put_user with an unsigned long argument. The patch below changes lirc_dev and lirc_serial to use __u32 for all ioctl arguments, and adds compat_ioctl entries. It should probably also be done in the other low-level drivers, but I don't have hardware to test those. I've dropped the .compat_ioctl addition from Joris' original patch, as I swear the non-compat definition should now work for both 32-bit and 64-bit userspace. Technically, I think we still need/want a in getting a reply to you). Reported-by: Joris van Rantwijk Signed-off-by: Jarod Wilson Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/ir-lirc-codec.c | 10 +++++----- drivers/media/IR/lirc_dev.c | 14 +++++++------- include/media/lirc_dev.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c index e63f757d5d72..c6d5b3eb1325 100644 --- a/drivers/media/IR/ir-lirc-codec.c +++ b/drivers/media/IR/ir-lirc-codec.c @@ -102,7 +102,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, struct ir_input_dev *ir_dev; int ret = 0; void *drv_data; - unsigned long val = 0; + __u32 val = 0; lirc = lirc_get_pdata(filep); if (!lirc) @@ -115,7 +115,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, drv_data = ir_dev->props->priv; if (_IOC_DIR(cmd) & _IOC_WRITE) { - ret = get_user(val, (unsigned long *)arg); + ret = get_user(val, (__u32 *)arg); if (ret) return ret; } @@ -135,14 +135,14 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, /* TX settings */ case LIRC_SET_TRANSMITTER_MASK: if (ir_dev->props->s_tx_mask) - ret = ir_dev->props->s_tx_mask(drv_data, (u32)val); + ret = ir_dev->props->s_tx_mask(drv_data, val); else return -EINVAL; break; case LIRC_SET_SEND_CARRIER: if (ir_dev->props->s_tx_carrier) - ir_dev->props->s_tx_carrier(drv_data, (u32)val); + ir_dev->props->s_tx_carrier(drv_data, val); else return -EINVAL; break; @@ -212,7 +212,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, } if (_IOC_DIR(cmd) & _IOC_READ) - ret = put_user(val, (unsigned long *)arg); + ret = put_user(val, (__u32 *)arg); return ret; } diff --git a/drivers/media/IR/lirc_dev.c b/drivers/media/IR/lirc_dev.c index 0572053a7944..e4e4d99725e6 100644 --- a/drivers/media/IR/lirc_dev.c +++ b/drivers/media/IR/lirc_dev.c @@ -524,7 +524,7 @@ EXPORT_SYMBOL(lirc_dev_fop_poll); long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - unsigned long mode; + __u32 mode; int result = 0; struct irctl *ir = file->private_data; @@ -541,7 +541,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) switch (cmd) { case LIRC_GET_FEATURES: - result = put_user(ir->d.features, (unsigned long *)arg); + result = put_user(ir->d.features, (__u32 *)arg); break; case LIRC_GET_REC_MODE: if (!(ir->d.features & LIRC_CAN_REC_MASK)) { @@ -551,7 +551,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) result = put_user(LIRC_REC2MODE (ir->d.features & LIRC_CAN_REC_MASK), - (unsigned long *)arg); + (__u32 *)arg); break; case LIRC_SET_REC_MODE: if (!(ir->d.features & LIRC_CAN_REC_MASK)) { @@ -559,7 +559,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) break; } - result = get_user(mode, (unsigned long *)arg); + result = get_user(mode, (__u32 *)arg); if (!result && !(LIRC_MODE2REC(mode) & ir->d.features)) result = -EINVAL; /* @@ -568,7 +568,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) */ break; case LIRC_GET_LENGTH: - result = put_user(ir->d.code_length, (unsigned long *)arg); + result = put_user(ir->d.code_length, (__u32 *)arg); break; case LIRC_GET_MIN_TIMEOUT: if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || @@ -577,7 +577,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) break; } - result = put_user(ir->d.min_timeout, (unsigned long *)arg); + result = put_user(ir->d.min_timeout, (__u32 *)arg); break; case LIRC_GET_MAX_TIMEOUT: if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || @@ -586,7 +586,7 @@ long lirc_dev_fop_ioctl(struct file *file, unsigned int cmd, unsigned long arg) break; } - result = put_user(ir->d.max_timeout, (unsigned long *)arg); + result = put_user(ir->d.max_timeout, (__u32 *)arg); break; default: result = -EINVAL; diff --git a/include/media/lirc_dev.h b/include/media/lirc_dev.h index 71a896e7b208..54780a560d0e 100644 --- a/include/media/lirc_dev.h +++ b/include/media/lirc_dev.h @@ -125,10 +125,10 @@ static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf, struct lirc_driver { char name[40]; int minor; - unsigned long code_length; + __u32 code_length; unsigned int buffer_size; /* in chunks holding one code each */ int sample_rate; - unsigned long features; + __u32 features; unsigned int chunk_size; -- cgit v1.2.3 From 0915d559a062f8f1034cf160f4af060df47dd0a3 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Tue, 3 Aug 2010 07:57:47 -0300 Subject: [media] v4l2-mediabus: Add pixelcodes for BGR565 formats Signed-off-by: Sascha Hauer Acked-by: Robert Jarzmik Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-mediabus.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/media/v4l2-mediabus.h b/include/media/v4l2-mediabus.h index 7e923fe3db04..8e6559838ae3 100644 --- a/include/media/v4l2-mediabus.h +++ b/include/media/v4l2-mediabus.h @@ -38,6 +38,8 @@ enum v4l2_mbus_pixelcode { V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE, V4L2_MBUS_FMT_RGB565_2X8_LE, V4L2_MBUS_FMT_RGB565_2X8_BE, + V4L2_MBUS_FMT_BGR565_2X8_LE, + V4L2_MBUS_FMT_BGR565_2X8_BE, V4L2_MBUS_FMT_SBGGR8_1X8, V4L2_MBUS_FMT_SBGGR10_1X10, V4L2_MBUS_FMT_GREY8_1X8, -- cgit v1.2.3 From bdc621fcedf031426551caed4e7517603690fad1 Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Thu, 30 Sep 2010 08:35:49 -0300 Subject: [media] SoC Camera: add driver for OMAP1 camera interface This is a V4L2 driver for TI OMAP1 SoC camera interface. Both videobuf-dma versions are supported, contig and sg, selectable with a module option. The former uses less processing power, but often fails to allocate contignuous buffer memory. The latter is free of this problem, but generates tens of DMA interrupts per frame. If contig memory allocation ever fails, the driver falls back to sg automatically on next open, but still can be switched back to contig manually. Both paths work stable for me, even under heavy load, on my OMAP1510 based Amstrad Delta videophone, that is the oldest, least powerfull OMAP1 implementation. The interface generally works in pass-through mode. Since input data byte endianess can be swapped, it provides up to two v4l2 pixel formats per each of several soc_mbus formats that have their swapped endian counterparts. Boards using this driver can provide it with the following platform data: - if and what freqency clock is expected by an on-board camera sensor, - what is the maximum pixel clock that should be accepted from the sensor, - what is the polarity of the sensor provided pixel clock, - if the interface GPIO line is connected to a sensor reset/powerdown input and what is the input polarity. Created and tested against linux-2.6.36-rc5 on Amstrad Delta. Signed-off-by: Janusz Krzysztofik Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/Kconfig | 8 + drivers/media/video/Makefile | 1 + drivers/media/video/omap1_camera.c | 1702 ++++++++++++++++++++++++++++++++++++ include/media/omap1_camera.h | 35 + 4 files changed, 1746 insertions(+) create mode 100644 drivers/media/video/omap1_camera.c create mode 100644 include/media/omap1_camera.h (limited to 'include') diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 27b728fce7a7..b89d0fda40fc 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -822,6 +822,14 @@ config VIDEO_SH_MOBILE_CEU ---help--- This is a v4l2 driver for the SuperH Mobile CEU Interface +config VIDEO_OMAP1 + tristate "OMAP1 Camera Interface driver" + depends on VIDEO_DEV && ARCH_OMAP1 && SOC_CAMERA + select VIDEOBUF_DMA_CONTIG + select VIDEOBUF_DMA_SG + ---help--- + This is a v4l2 driver for the TI OMAP1 camera interface + config VIDEO_OMAP2 tristate "OMAP2 Camera Capture Interface driver" depends on VIDEO_DEV && ARCH_OMAP2 diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 118196c06fcd..557ad1f3aeb4 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -157,6 +157,7 @@ obj-$(CONFIG_VIDEO_MX3) += mx3_camera.o obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2) += sh_mobile_csi2.o obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o +obj-$(CONFIG_VIDEO_OMAP1) += omap1_camera.o obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) += s5p-fimc/ obj-$(CONFIG_ARCH_DAVINCI) += davinci/ diff --git a/drivers/media/video/omap1_camera.c b/drivers/media/video/omap1_camera.c new file mode 100644 index 000000000000..7c30e62b50db --- /dev/null +++ b/drivers/media/video/omap1_camera.c @@ -0,0 +1,1702 @@ +/* + * V4L2 SoC Camera driver for OMAP1 Camera Interface + * + * Copyright (C) 2010, Janusz Krzysztofik + * + * Based on V4L2 Driver for i.MXL/i.MXL camera (CSI) host + * Copyright (C) 2008, Paulius Zaleckas + * Copyright (C) 2009, Darius Augulis + * + * Based on PXA SoC camera driver + * Copyright (C) 2006, Sascha Hauer, Pengutronix + * Copyright (C) 2008, Guennadi Liakhovetski + * + * Hardware specific bits initialy based on former work by Matt Callow + * drivers/media/video/omap/omap1510cam.c + * Copyright (C) 2006 Matt Callow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + + +#define DRIVER_NAME "omap1-camera" +#define VERSION_CODE KERNEL_VERSION(0, 0, 1) + + +/* + * --------------------------------------------------------------------------- + * OMAP1 Camera Interface registers + * --------------------------------------------------------------------------- + */ + +#define REG_CTRLCLOCK 0x00 +#define REG_IT_STATUS 0x04 +#define REG_MODE 0x08 +#define REG_STATUS 0x0C +#define REG_CAMDATA 0x10 +#define REG_GPIO 0x14 +#define REG_PEAK_COUNTER 0x18 + +/* CTRLCLOCK bit shifts */ +#define LCLK_EN BIT(7) +#define DPLL_EN BIT(6) +#define MCLK_EN BIT(5) +#define CAMEXCLK_EN BIT(4) +#define POLCLK BIT(3) +#define FOSCMOD_SHIFT 0 +#define FOSCMOD_MASK (0x7 << FOSCMOD_SHIFT) +#define FOSCMOD_12MHz 0x0 +#define FOSCMOD_6MHz 0x2 +#define FOSCMOD_9_6MHz 0x4 +#define FOSCMOD_24MHz 0x5 +#define FOSCMOD_8MHz 0x6 + +/* IT_STATUS bit shifts */ +#define DATA_TRANSFER BIT(5) +#define FIFO_FULL BIT(4) +#define H_DOWN BIT(3) +#define H_UP BIT(2) +#define V_DOWN BIT(1) +#define V_UP BIT(0) + +/* MODE bit shifts */ +#define RAZ_FIFO BIT(18) +#define EN_FIFO_FULL BIT(17) +#define EN_NIRQ BIT(16) +#define THRESHOLD_SHIFT 9 +#define THRESHOLD_MASK (0x7f << THRESHOLD_SHIFT) +#define DMA BIT(8) +#define EN_H_DOWN BIT(7) +#define EN_H_UP BIT(6) +#define EN_V_DOWN BIT(5) +#define EN_V_UP BIT(4) +#define ORDERCAMD BIT(3) + +#define IRQ_MASK (EN_V_UP | EN_V_DOWN | EN_H_UP | EN_H_DOWN | \ + EN_NIRQ | EN_FIFO_FULL) + +/* STATUS bit shifts */ +#define HSTATUS BIT(1) +#define VSTATUS BIT(0) + +/* GPIO bit shifts */ +#define CAM_RST BIT(0) + +/* end of OMAP1 Camera Interface registers */ + + +#define SOCAM_BUS_FLAGS (SOCAM_MASTER | \ + SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | \ + SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \ + SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8) + + +#define FIFO_SIZE ((THRESHOLD_MASK >> THRESHOLD_SHIFT) + 1) +#define FIFO_SHIFT __fls(FIFO_SIZE) + +#define DMA_BURST_SHIFT (1 + OMAP_DMA_DATA_BURST_4) +#define DMA_BURST_SIZE (1 << DMA_BURST_SHIFT) + +#define DMA_ELEMENT_SHIFT OMAP_DMA_DATA_TYPE_S32 +#define DMA_ELEMENT_SIZE (1 << DMA_ELEMENT_SHIFT) + +#define DMA_FRAME_SHIFT_CONTIG (FIFO_SHIFT - 1) +#define DMA_FRAME_SHIFT_SG DMA_BURST_SHIFT + +#define DMA_FRAME_SHIFT(x) ((x) == OMAP1_CAM_DMA_CONTIG ? \ + DMA_FRAME_SHIFT_CONTIG : \ + DMA_FRAME_SHIFT_SG) +#define DMA_FRAME_SIZE(x) (1 << DMA_FRAME_SHIFT(x)) +#define DMA_SYNC OMAP_DMA_SYNC_FRAME +#define THRESHOLD_LEVEL DMA_FRAME_SIZE + + +#define MAX_VIDEO_MEM 4 /* arbitrary video memory limit in MB */ + + +/* + * Structures + */ + +/* buffer for one video frame */ +struct omap1_cam_buf { + struct videobuf_buffer vb; + enum v4l2_mbus_pixelcode code; + int inwork; + struct scatterlist *sgbuf; + int sgcount; + int bytes_left; + enum videobuf_state result; +}; + +struct omap1_cam_dev { + struct soc_camera_host soc_host; + struct soc_camera_device *icd; + struct clk *clk; + + unsigned int irq; + void __iomem *base; + + int dma_ch; + + struct omap1_cam_platform_data *pdata; + struct resource *res; + unsigned long pflags; + unsigned long camexclk; + + struct list_head capture; + + /* lock used to protect videobuf */ + spinlock_t lock; + + /* Pointers to DMA buffers */ + struct omap1_cam_buf *active; + struct omap1_cam_buf *ready; + + enum omap1_cam_vb_mode vb_mode; + int (*mmap_mapper)(struct videobuf_queue *q, + struct videobuf_buffer *buf, + struct vm_area_struct *vma); + + u32 reg_cache[0]; +}; + + +static void cam_write(struct omap1_cam_dev *pcdev, u16 reg, u32 val) +{ + pcdev->reg_cache[reg / sizeof(u32)] = val; + __raw_writel(val, pcdev->base + reg); +} + +static u32 cam_read(struct omap1_cam_dev *pcdev, u16 reg, bool from_cache) +{ + return !from_cache ? __raw_readl(pcdev->base + reg) : + pcdev->reg_cache[reg / sizeof(u32)]; +} + +#define CAM_READ(pcdev, reg) \ + cam_read(pcdev, REG_##reg, false) +#define CAM_WRITE(pcdev, reg, val) \ + cam_write(pcdev, REG_##reg, val) +#define CAM_READ_CACHE(pcdev, reg) \ + cam_read(pcdev, REG_##reg, true) + +/* + * Videobuf operations + */ +static int omap1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, + unsigned int *size) +{ + struct soc_camera_device *icd = vq->priv_data; + int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, + icd->current_fmt->host_fmt); + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + + if (bytes_per_line < 0) + return bytes_per_line; + + *size = bytes_per_line * icd->user_height; + + if (!*count || *count < OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode)) + *count = OMAP1_CAMERA_MIN_BUF_COUNT(pcdev->vb_mode); + + if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024) + *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size; + + dev_dbg(icd->dev.parent, + "%s: count=%d, size=%d\n", __func__, *count, *size); + + return 0; +} + +static void free_buffer(struct videobuf_queue *vq, struct omap1_cam_buf *buf, + enum omap1_cam_vb_mode vb_mode) +{ + struct videobuf_buffer *vb = &buf->vb; + + BUG_ON(in_interrupt()); + + videobuf_waiton(vb, 0, 0); + + if (vb_mode == OMAP1_CAM_DMA_CONTIG) { + videobuf_dma_contig_free(vq, vb); + } else { + struct soc_camera_device *icd = vq->priv_data; + struct device *dev = icd->dev.parent; + struct videobuf_dmabuf *dma = videobuf_to_dma(vb); + + videobuf_dma_unmap(dev, dma); + videobuf_dma_free(dma); + } + + vb->state = VIDEOBUF_NEEDS_INIT; +} + +static int omap1_videobuf_prepare(struct videobuf_queue *vq, + struct videobuf_buffer *vb, enum v4l2_field field) +{ + struct soc_camera_device *icd = vq->priv_data; + struct omap1_cam_buf *buf = container_of(vb, struct omap1_cam_buf, vb); + int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, + icd->current_fmt->host_fmt); + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + int ret; + + if (bytes_per_line < 0) + return bytes_per_line; + + WARN_ON(!list_empty(&vb->queue)); + + BUG_ON(NULL == icd->current_fmt); + + buf->inwork = 1; + + if (buf->code != icd->current_fmt->code || vb->field != field || + vb->width != icd->user_width || + vb->height != icd->user_height) { + buf->code = icd->current_fmt->code; + vb->width = icd->user_width; + vb->height = icd->user_height; + vb->field = field; + vb->state = VIDEOBUF_NEEDS_INIT; + } + + vb->size = bytes_per_line * vb->height; + + if (vb->baddr && vb->bsize < vb->size) { + ret = -EINVAL; + goto out; + } + + if (vb->state == VIDEOBUF_NEEDS_INIT) { + ret = videobuf_iolock(vq, vb, NULL); + if (ret) + goto fail; + + vb->state = VIDEOBUF_PREPARED; + } + buf->inwork = 0; + + return 0; +fail: + free_buffer(vq, buf, pcdev->vb_mode); +out: + buf->inwork = 0; + return ret; +} + +static void set_dma_dest_params(int dma_ch, struct omap1_cam_buf *buf, + enum omap1_cam_vb_mode vb_mode) +{ + dma_addr_t dma_addr; + unsigned int block_size; + + if (vb_mode == OMAP1_CAM_DMA_CONTIG) { + dma_addr = videobuf_to_dma_contig(&buf->vb); + block_size = buf->vb.size; + } else { + if (WARN_ON(!buf->sgbuf)) { + buf->result = VIDEOBUF_ERROR; + return; + } + dma_addr = sg_dma_address(buf->sgbuf); + if (WARN_ON(!dma_addr)) { + buf->sgbuf = NULL; + buf->result = VIDEOBUF_ERROR; + return; + } + block_size = sg_dma_len(buf->sgbuf); + if (WARN_ON(!block_size)) { + buf->sgbuf = NULL; + buf->result = VIDEOBUF_ERROR; + return; + } + if (unlikely(buf->bytes_left < block_size)) + block_size = buf->bytes_left; + if (WARN_ON(dma_addr & (DMA_FRAME_SIZE(vb_mode) * + DMA_ELEMENT_SIZE - 1))) { + dma_addr = ALIGN(dma_addr, DMA_FRAME_SIZE(vb_mode) * + DMA_ELEMENT_SIZE); + block_size &= ~(DMA_FRAME_SIZE(vb_mode) * + DMA_ELEMENT_SIZE - 1); + } + buf->bytes_left -= block_size; + buf->sgcount++; + } + + omap_set_dma_dest_params(dma_ch, + OMAP_DMA_PORT_EMIFF, OMAP_DMA_AMODE_POST_INC, dma_addr, 0, 0); + omap_set_dma_transfer_params(dma_ch, + OMAP_DMA_DATA_TYPE_S32, DMA_FRAME_SIZE(vb_mode), + block_size >> (DMA_FRAME_SHIFT(vb_mode) + DMA_ELEMENT_SHIFT), + DMA_SYNC, 0, 0); +} + +static struct omap1_cam_buf *prepare_next_vb(struct omap1_cam_dev *pcdev) +{ + struct omap1_cam_buf *buf; + + /* + * If there is already a buffer pointed out by the pcdev->ready, + * (re)use it, otherwise try to fetch and configure a new one. + */ + buf = pcdev->ready; + if (!buf) { + if (list_empty(&pcdev->capture)) + return buf; + buf = list_entry(pcdev->capture.next, + struct omap1_cam_buf, vb.queue); + buf->vb.state = VIDEOBUF_ACTIVE; + pcdev->ready = buf; + list_del_init(&buf->vb.queue); + } + + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, we can safely enter next buffer parameters + * into the DMA programming register set after the DMA + * has already been activated on the previous buffer + */ + set_dma_dest_params(pcdev->dma_ch, buf, pcdev->vb_mode); + } else { + /* + * In SG mode, the above is not safe since there are probably + * a bunch of sgbufs from previous sglist still pending. + * Instead, mark the sglist fresh for the upcoming + * try_next_sgbuf(). + */ + buf->sgbuf = NULL; + } + + return buf; +} + +static struct scatterlist *try_next_sgbuf(int dma_ch, struct omap1_cam_buf *buf) +{ + struct scatterlist *sgbuf; + + if (likely(buf->sgbuf)) { + /* current sglist is active */ + if (unlikely(!buf->bytes_left)) { + /* indicate sglist complete */ + sgbuf = NULL; + } else { + /* process next sgbuf */ + sgbuf = sg_next(buf->sgbuf); + if (WARN_ON(!sgbuf)) { + buf->result = VIDEOBUF_ERROR; + } else if (WARN_ON(!sg_dma_len(sgbuf))) { + sgbuf = NULL; + buf->result = VIDEOBUF_ERROR; + } + } + buf->sgbuf = sgbuf; + } else { + /* sglist is fresh, initialize it before using */ + struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb); + + sgbuf = dma->sglist; + if (!(WARN_ON(!sgbuf))) { + buf->sgbuf = sgbuf; + buf->sgcount = 0; + buf->bytes_left = buf->vb.size; + buf->result = VIDEOBUF_DONE; + } + } + if (sgbuf) + /* + * Put our next sgbuf parameters (address, size) + * into the DMA programming register set. + */ + set_dma_dest_params(dma_ch, buf, OMAP1_CAM_DMA_SG); + + return sgbuf; +} + +static void start_capture(struct omap1_cam_dev *pcdev) +{ + struct omap1_cam_buf *buf = pcdev->active; + u32 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK); + u32 mode = CAM_READ_CACHE(pcdev, MODE) & ~EN_V_DOWN; + + if (WARN_ON(!buf)) + return; + + /* + * Enable start of frame interrupt, which we will use for activating + * our end of frame watchdog when capture actually starts. + */ + mode |= EN_V_UP; + + if (unlikely(ctrlclock & LCLK_EN)) + /* stop pixel clock before FIFO reset */ + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN); + /* reset FIFO */ + CAM_WRITE(pcdev, MODE, mode | RAZ_FIFO); + + omap_start_dma(pcdev->dma_ch); + + if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) { + /* + * In SG mode, it's a good moment for fetching next sgbuf + * from the current sglist and, if available, already putting + * its parameters into the DMA programming register set. + */ + try_next_sgbuf(pcdev->dma_ch, buf); + } + + /* (re)enable pixel clock */ + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock | LCLK_EN); + /* release FIFO reset */ + CAM_WRITE(pcdev, MODE, mode); +} + +static void suspend_capture(struct omap1_cam_dev *pcdev) +{ + u32 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK); + + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN); + omap_stop_dma(pcdev->dma_ch); +} + +static void disable_capture(struct omap1_cam_dev *pcdev) +{ + u32 mode = CAM_READ_CACHE(pcdev, MODE); + + CAM_WRITE(pcdev, MODE, mode & ~(IRQ_MASK | DMA)); +} + +static void omap1_videobuf_queue(struct videobuf_queue *vq, + struct videobuf_buffer *vb) +{ + struct soc_camera_device *icd = vq->priv_data; + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + struct omap1_cam_buf *buf; + u32 mode; + + list_add_tail(&vb->queue, &pcdev->capture); + vb->state = VIDEOBUF_QUEUED; + + if (pcdev->active) { + /* + * Capture in progress, so don't touch pcdev->ready even if + * empty. Since the transfer of the DMA programming register set + * content to the DMA working register set is done automatically + * by the DMA hardware, this can pretty well happen while we + * are keeping the lock here. Levae fetching it from the queue + * to be done when a next DMA interrupt occures instead. + */ + return; + } + + WARN_ON(pcdev->ready); + + buf = prepare_next_vb(pcdev); + if (WARN_ON(!buf)) + return; + + pcdev->active = buf; + pcdev->ready = NULL; + + dev_dbg(icd->dev.parent, + "%s: capture not active, setup FIFO, start DMA\n", __func__); + mode = CAM_READ_CACHE(pcdev, MODE) & ~THRESHOLD_MASK; + mode |= THRESHOLD_LEVEL(pcdev->vb_mode) << THRESHOLD_SHIFT; + CAM_WRITE(pcdev, MODE, mode | EN_FIFO_FULL | DMA); + + if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) { + /* + * In SG mode, the above prepare_next_vb() didn't actually + * put anything into the DMA programming register set, + * so we have to do it now, before activating DMA. + */ + try_next_sgbuf(pcdev->dma_ch, buf); + } + + start_capture(pcdev); +} + +static void omap1_videobuf_release(struct videobuf_queue *vq, + struct videobuf_buffer *vb) +{ + struct omap1_cam_buf *buf = + container_of(vb, struct omap1_cam_buf, vb); + struct soc_camera_device *icd = vq->priv_data; + struct device *dev = icd->dev.parent; + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + + switch (vb->state) { + case VIDEOBUF_DONE: + dev_dbg(dev, "%s (done)\n", __func__); + break; + case VIDEOBUF_ACTIVE: + dev_dbg(dev, "%s (active)\n", __func__); + break; + case VIDEOBUF_QUEUED: + dev_dbg(dev, "%s (queued)\n", __func__); + break; + case VIDEOBUF_PREPARED: + dev_dbg(dev, "%s (prepared)\n", __func__); + break; + default: + dev_dbg(dev, "%s (unknown %d)\n", __func__, vb->state); + break; + } + + free_buffer(vq, buf, pcdev->vb_mode); +} + +static void videobuf_done(struct omap1_cam_dev *pcdev, + enum videobuf_state result) +{ + struct omap1_cam_buf *buf = pcdev->active; + struct videobuf_buffer *vb; + struct device *dev = pcdev->icd->dev.parent; + + if (WARN_ON(!buf)) { + suspend_capture(pcdev); + disable_capture(pcdev); + return; + } + + if (result == VIDEOBUF_ERROR) + suspend_capture(pcdev); + + vb = &buf->vb; + if (waitqueue_active(&vb->done)) { + if (!pcdev->ready && result != VIDEOBUF_ERROR) { + /* + * No next buffer has been entered into the DMA + * programming register set on time (could be done only + * while the previous DMA interurpt was processed, not + * later), so the last DMA block, be it a whole buffer + * if in CONTIG or its last sgbuf if in SG mode, is + * about to be reused by the just autoreinitialized DMA + * engine, and overwritten with next frame data. Best we + * can do is stopping the capture as soon as possible, + * hopefully before the next frame start. + */ + suspend_capture(pcdev); + } + vb->state = result; + do_gettimeofday(&vb->ts); + if (result != VIDEOBUF_ERROR) + vb->field_count++; + wake_up(&vb->done); + + /* shift in next buffer */ + buf = pcdev->ready; + pcdev->active = buf; + pcdev->ready = NULL; + + if (!buf) { + /* + * No next buffer was ready on time (see above), so + * indicate error condition to force capture restart or + * stop, depending on next buffer already queued or not. + */ + result = VIDEOBUF_ERROR; + prepare_next_vb(pcdev); + + buf = pcdev->ready; + pcdev->active = buf; + pcdev->ready = NULL; + } + } else if (pcdev->ready) { + /* + * In both CONTIG and SG mode, the DMA engine has possibly + * been already autoreinitialized with the preprogrammed + * pcdev->ready buffer. We can either accept this fact + * and just swap the buffers, or provoke an error condition + * and restart capture. The former seems less intrusive. + */ + dev_dbg(dev, "%s: nobody waiting on videobuf, swap with next\n", + __func__); + pcdev->active = pcdev->ready; + + if (pcdev->vb_mode == OMAP1_CAM_DMA_SG) { + /* + * In SG mode, we have to make sure that the buffer we + * are putting back into the pcdev->ready is marked + * fresh. + */ + buf->sgbuf = NULL; + } + pcdev->ready = buf; + + buf = pcdev->active; + } else { + /* + * No next buffer has been entered into + * the DMA programming register set on time. + */ + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, the DMA engine has already been + * reinitialized with the current buffer. Best we can do + * is not touching it. + */ + dev_dbg(dev, + "%s: nobody waiting on videobuf, reuse it\n", + __func__); + } else { + /* + * In SG mode, the DMA engine has just been + * autoreinitialized with the last sgbuf from the + * current list. Restart capture in order to transfer + * next frame start into the first sgbuf, not the last + * one. + */ + if (result != VIDEOBUF_ERROR) { + suspend_capture(pcdev); + result = VIDEOBUF_ERROR; + } + } + } + + if (!buf) { + dev_dbg(dev, "%s: no more videobufs, stop capture\n", __func__); + disable_capture(pcdev); + return; + } + + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, the current buffer parameters had already + * been entered into the DMA programming register set while the + * buffer was fetched with prepare_next_vb(), they may have also + * been transfered into the runtime set and already active if + * the DMA still running. + */ + } else { + /* In SG mode, extra steps are required */ + if (result == VIDEOBUF_ERROR) + /* make sure we (re)use sglist from start on error */ + buf->sgbuf = NULL; + + /* + * In any case, enter the next sgbuf parameters into the DMA + * programming register set. They will be used either during + * nearest DMA autoreinitialization or, in case of an error, + * on DMA startup below. + */ + try_next_sgbuf(pcdev->dma_ch, buf); + } + + if (result == VIDEOBUF_ERROR) { + dev_dbg(dev, "%s: videobuf error; reset FIFO, restart DMA\n", + __func__); + start_capture(pcdev); + /* + * In SG mode, the above also resulted in the next sgbuf + * parameters being entered into the DMA programming register + * set, making them ready for next DMA autoreinitialization. + */ + } + + /* + * Finally, try fetching next buffer. + * In CONTIG mode, it will also enter it into the DMA programming + * register set, making it ready for next DMA autoreinitialization. + */ + prepare_next_vb(pcdev); +} + +static void dma_isr(int channel, unsigned short status, void *data) +{ + struct omap1_cam_dev *pcdev = data; + struct omap1_cam_buf *buf = pcdev->active; + unsigned long flags; + + spin_lock_irqsave(&pcdev->lock, flags); + + if (WARN_ON(!buf)) { + suspend_capture(pcdev); + disable_capture(pcdev); + goto out; + } + + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, assume we have just managed to collect the + * whole frame, hopefully before our end of frame watchdog is + * triggered. Then, all we have to do is disabling the watchdog + * for this frame, and calling videobuf_done() with success + * indicated. + */ + CAM_WRITE(pcdev, MODE, + CAM_READ_CACHE(pcdev, MODE) & ~EN_V_DOWN); + videobuf_done(pcdev, VIDEOBUF_DONE); + } else { + /* + * In SG mode, we have to process every sgbuf from the current + * sglist, one after another. + */ + if (buf->sgbuf) { + /* + * Current sglist not completed yet, try fetching next + * sgbuf, hopefully putting it into the DMA programming + * register set, making it ready for next DMA + * autoreinitialization. + */ + try_next_sgbuf(pcdev->dma_ch, buf); + if (buf->sgbuf) + goto out; + + /* + * No more sgbufs left in the current sglist. This + * doesn't mean that the whole videobuffer is already + * complete, but only that the last sgbuf from the + * current sglist is about to be filled. It will be + * ready on next DMA interrupt, signalled with the + * buf->sgbuf set back to NULL. + */ + if (buf->result != VIDEOBUF_ERROR) { + /* + * Video frame collected without errors so far, + * we can prepare for collecting a next one + * as soon as DMA gets autoreinitialized + * after the current (last) sgbuf is completed. + */ + buf = prepare_next_vb(pcdev); + if (!buf) + goto out; + + try_next_sgbuf(pcdev->dma_ch, buf); + goto out; + } + } + /* end of videobuf */ + videobuf_done(pcdev, buf->result); + } + +out: + spin_unlock_irqrestore(&pcdev->lock, flags); +} + +static irqreturn_t cam_isr(int irq, void *data) +{ + struct omap1_cam_dev *pcdev = data; + struct device *dev = pcdev->icd->dev.parent; + struct omap1_cam_buf *buf = pcdev->active; + u32 it_status; + unsigned long flags; + + it_status = CAM_READ(pcdev, IT_STATUS); + if (!it_status) + return IRQ_NONE; + + spin_lock_irqsave(&pcdev->lock, flags); + + if (WARN_ON(!buf)) { + dev_warn(dev, "%s: unhandled camera interrupt, status == " + "%#x\n", __func__, it_status); + suspend_capture(pcdev); + disable_capture(pcdev); + goto out; + } + + if (unlikely(it_status & FIFO_FULL)) { + dev_warn(dev, "%s: FIFO overflow\n", __func__); + + } else if (it_status & V_DOWN) { + /* end of video frame watchdog */ + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, the watchdog is disabled with + * successful DMA end of block interrupt, and reenabled + * on next frame start. If we get here, there is nothing + * to check, we must be out of sync. + */ + } else { + if (buf->sgcount == 2) { + /* + * If exactly 2 sgbufs from the next sglist have + * been programmed into the DMA engine (the + * frist one already transfered into the DMA + * runtime register set, the second one still + * in the programming set), then we are in sync. + */ + goto out; + } + } + dev_notice(dev, "%s: unexpected end of video frame\n", + __func__); + + } else if (it_status & V_UP) { + u32 mode; + + if (pcdev->vb_mode == OMAP1_CAM_DMA_CONTIG) { + /* + * In CONTIG mode, we need this interrupt every frame + * in oredr to reenable our end of frame watchdog. + */ + mode = CAM_READ_CACHE(pcdev, MODE); + } else { + /* + * In SG mode, the below enabled end of frame watchdog + * is kept on permanently, so we can turn this one shot + * setup off. + */ + mode = CAM_READ_CACHE(pcdev, MODE) & ~EN_V_UP; + } + + if (!(mode & EN_V_DOWN)) { + /* (re)enable end of frame watchdog interrupt */ + mode |= EN_V_DOWN; + } + CAM_WRITE(pcdev, MODE, mode); + goto out; + + } else { + dev_warn(dev, "%s: unhandled camera interrupt, status == %#x\n", + __func__, it_status); + goto out; + } + + videobuf_done(pcdev, VIDEOBUF_ERROR); +out: + spin_unlock_irqrestore(&pcdev->lock, flags); + return IRQ_HANDLED; +} + +static struct videobuf_queue_ops omap1_videobuf_ops = { + .buf_setup = omap1_videobuf_setup, + .buf_prepare = omap1_videobuf_prepare, + .buf_queue = omap1_videobuf_queue, + .buf_release = omap1_videobuf_release, +}; + + +/* + * SOC Camera host operations + */ + +static void sensor_reset(struct omap1_cam_dev *pcdev, bool reset) +{ + /* apply/release camera sensor reset if requested by platform data */ + if (pcdev->pflags & OMAP1_CAMERA_RST_HIGH) + CAM_WRITE(pcdev, GPIO, reset); + else if (pcdev->pflags & OMAP1_CAMERA_RST_LOW) + CAM_WRITE(pcdev, GPIO, !reset); +} + +/* + * The following two functions absolutely depend on the fact, that + * there can be only one camera on OMAP1 camera sensor interface + */ +static int omap1_cam_add_device(struct soc_camera_device *icd) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + u32 ctrlclock; + + if (pcdev->icd) + return -EBUSY; + + clk_enable(pcdev->clk); + + /* setup sensor clock */ + ctrlclock = CAM_READ(pcdev, CTRLCLOCK); + ctrlclock &= ~(CAMEXCLK_EN | MCLK_EN | DPLL_EN); + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock); + + ctrlclock &= ~FOSCMOD_MASK; + switch (pcdev->camexclk) { + case 6000000: + ctrlclock |= CAMEXCLK_EN | FOSCMOD_6MHz; + break; + case 8000000: + ctrlclock |= CAMEXCLK_EN | FOSCMOD_8MHz | DPLL_EN; + break; + case 9600000: + ctrlclock |= CAMEXCLK_EN | FOSCMOD_9_6MHz | DPLL_EN; + break; + case 12000000: + ctrlclock |= CAMEXCLK_EN | FOSCMOD_12MHz; + break; + case 24000000: + ctrlclock |= CAMEXCLK_EN | FOSCMOD_24MHz | DPLL_EN; + default: + break; + } + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~DPLL_EN); + + /* enable internal clock */ + ctrlclock |= MCLK_EN; + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock); + + sensor_reset(pcdev, false); + + pcdev->icd = icd; + + dev_dbg(icd->dev.parent, "OMAP1 Camera driver attached to camera %d\n", + icd->devnum); + return 0; +} + +static void omap1_cam_remove_device(struct soc_camera_device *icd) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + u32 ctrlclock; + + BUG_ON(icd != pcdev->icd); + + suspend_capture(pcdev); + disable_capture(pcdev); + + sensor_reset(pcdev, true); + + /* disable and release system clocks */ + ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK); + ctrlclock &= ~(MCLK_EN | DPLL_EN | CAMEXCLK_EN); + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock); + + ctrlclock = (ctrlclock & ~FOSCMOD_MASK) | FOSCMOD_12MHz; + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock); + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock | MCLK_EN); + + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~MCLK_EN); + + clk_disable(pcdev->clk); + + pcdev->icd = NULL; + + dev_dbg(icd->dev.parent, + "OMAP1 Camera driver detached from camera %d\n", icd->devnum); +} + +/* Duplicate standard formats based on host capability of byte swapping */ +static const struct soc_mbus_pixelfmt omap1_cam_formats[] = { + [V4L2_MBUS_FMT_UYVY8_2X8] = { + .fourcc = V4L2_PIX_FMT_YUYV, + .name = "YUYV", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_VYUY8_2X8] = { + .fourcc = V4L2_PIX_FMT_YVYU, + .name = "YVYU", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_YUYV8_2X8] = { + .fourcc = V4L2_PIX_FMT_UYVY, + .name = "UYVY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_YVYU8_2X8] = { + .fourcc = V4L2_PIX_FMT_VYUY, + .name = "VYUY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE] = { + .fourcc = V4L2_PIX_FMT_RGB555, + .name = "RGB555", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE] = { + .fourcc = V4L2_PIX_FMT_RGB555X, + .name = "RGB555X", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_RGB565_2X8_BE] = { + .fourcc = V4L2_PIX_FMT_RGB565, + .name = "RGB565", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, + [V4L2_MBUS_FMT_RGB565_2X8_LE] = { + .fourcc = V4L2_PIX_FMT_RGB565X, + .name = "RGB565X", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_BE, + }, +}; + +static int omap1_cam_get_formats(struct soc_camera_device *icd, + unsigned int idx, struct soc_camera_format_xlate *xlate) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct device *dev = icd->dev.parent; + int formats = 0, ret; + enum v4l2_mbus_pixelcode code; + const struct soc_mbus_pixelfmt *fmt; + + ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code); + if (ret < 0) + /* No more formats */ + return 0; + + fmt = soc_mbus_get_fmtdesc(code); + if (!fmt) { + dev_err(dev, "%s: invalid format code #%d: %d\n", __func__, + idx, code); + return 0; + } + + /* Check support for the requested bits-per-sample */ + if (fmt->bits_per_sample != 8) + return 0; + + switch (code) { + case V4L2_MBUS_FMT_YUYV8_2X8: + case V4L2_MBUS_FMT_YVYU8_2X8: + case V4L2_MBUS_FMT_UYVY8_2X8: + case V4L2_MBUS_FMT_VYUY8_2X8: + case V4L2_MBUS_FMT_RGB555_2X8_PADHI_BE: + case V4L2_MBUS_FMT_RGB555_2X8_PADHI_LE: + case V4L2_MBUS_FMT_RGB565_2X8_BE: + case V4L2_MBUS_FMT_RGB565_2X8_LE: + formats++; + if (xlate) { + xlate->host_fmt = &omap1_cam_formats[code]; + xlate->code = code; + xlate++; + dev_dbg(dev, "%s: providing format %s " + "as byte swapped code #%d\n", __func__, + omap1_cam_formats[code].name, code); + } + default: + if (xlate) + dev_dbg(dev, "%s: providing format %s " + "in pass-through mode\n", __func__, + fmt->name); + } + formats++; + if (xlate) { + xlate->host_fmt = fmt; + xlate->code = code; + xlate++; + } + + return formats; +} + +static bool is_dma_aligned(s32 bytes_per_line, unsigned int height, + enum omap1_cam_vb_mode vb_mode) +{ + int size = bytes_per_line * height; + + return IS_ALIGNED(bytes_per_line, DMA_ELEMENT_SIZE) && + IS_ALIGNED(size, DMA_FRAME_SIZE(vb_mode) * DMA_ELEMENT_SIZE); +} + +static int dma_align(int *width, int *height, + const struct soc_mbus_pixelfmt *fmt, + enum omap1_cam_vb_mode vb_mode, bool enlarge) +{ + s32 bytes_per_line = soc_mbus_bytes_per_line(*width, fmt); + + if (bytes_per_line < 0) + return bytes_per_line; + + if (!is_dma_aligned(bytes_per_line, *height, vb_mode)) { + unsigned int pxalign = __fls(bytes_per_line / *width); + unsigned int salign = DMA_FRAME_SHIFT(vb_mode) + + DMA_ELEMENT_SHIFT - pxalign; + unsigned int incr = enlarge << salign; + + v4l_bound_align_image(width, 1, *width + incr, 0, + height, 1, *height + incr, 0, salign); + return 0; + } + return 1; +} + +#define subdev_call_with_sense(pcdev, dev, icd, sd, function, args...) \ +({ \ + struct soc_camera_sense sense = { \ + .master_clock = pcdev->camexclk, \ + .pixel_clock_max = 0, \ + }; \ + int __ret; \ + \ + if (pcdev->pdata) \ + sense.pixel_clock_max = pcdev->pdata->lclk_khz_max * 1000; \ + icd->sense = &sense; \ + __ret = v4l2_subdev_call(sd, video, function, ##args); \ + icd->sense = NULL; \ + \ + if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { \ + if (sense.pixel_clock > sense.pixel_clock_max) { \ + dev_err(dev, "%s: pixel clock %lu " \ + "set by the camera too high!\n", \ + __func__, sense.pixel_clock); \ + __ret = -EINVAL; \ + } \ + } \ + __ret; \ +}) + +static int set_mbus_format(struct omap1_cam_dev *pcdev, struct device *dev, + struct soc_camera_device *icd, struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf, + const struct soc_camera_format_xlate *xlate) +{ + s32 bytes_per_line; + int ret = subdev_call_with_sense(pcdev, dev, icd, sd, s_mbus_fmt, mf); + + if (ret < 0) { + dev_err(dev, "%s: s_mbus_fmt failed\n", __func__); + return ret; + } + + if (mf->code != xlate->code) { + dev_err(dev, "%s: unexpected pixel code change\n", __func__); + return -EINVAL; + } + + bytes_per_line = soc_mbus_bytes_per_line(mf->width, xlate->host_fmt); + if (bytes_per_line < 0) { + dev_err(dev, "%s: soc_mbus_bytes_per_line() failed\n", + __func__); + return bytes_per_line; + } + + if (!is_dma_aligned(bytes_per_line, mf->height, pcdev->vb_mode)) { + dev_err(dev, "%s: resulting geometry %ux%u not DMA aligned\n", + __func__, mf->width, mf->height); + return -EINVAL; + } + return 0; +} + +static int omap1_cam_set_crop(struct soc_camera_device *icd, + struct v4l2_crop *crop) +{ + struct v4l2_rect *rect = &crop->c; + const struct soc_camera_format_xlate *xlate = icd->current_fmt; + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + struct device *dev = icd->dev.parent; + struct v4l2_mbus_framefmt mf; + int ret; + + ret = subdev_call_with_sense(pcdev, dev, icd, sd, s_crop, crop); + if (ret < 0) { + dev_warn(dev, "%s: failed to crop to %ux%u@%u:%u\n", __func__, + rect->width, rect->height, rect->left, rect->top); + return ret; + } + + ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf); + if (ret < 0) { + dev_warn(dev, "%s: failed to fetch current format\n", __func__); + return ret; + } + + ret = dma_align(&mf.width, &mf.height, xlate->host_fmt, pcdev->vb_mode, + false); + if (ret < 0) { + dev_err(dev, "%s: failed to align %ux%u %s with DMA\n", + __func__, mf.width, mf.height, + xlate->host_fmt->name); + return ret; + } + + if (!ret) { + /* sensor returned geometry not DMA aligned, trying to fix */ + ret = set_mbus_format(pcdev, dev, icd, sd, &mf, xlate); + if (ret < 0) { + dev_err(dev, "%s: failed to set format\n", __func__); + return ret; + } + } + + icd->user_width = mf.width; + icd->user_height = mf.height; + + return 0; +} + +static int omap1_cam_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate; + struct device *dev = icd->dev.parent; + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_mbus_framefmt mf; + int ret; + + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (!xlate) { + dev_warn(dev, "%s: format %#x not found\n", __func__, + pix->pixelformat); + return -EINVAL; + } + + mf.width = pix->width; + mf.height = pix->height; + mf.field = pix->field; + mf.colorspace = pix->colorspace; + mf.code = xlate->code; + + ret = dma_align(&mf.width, &mf.height, xlate->host_fmt, pcdev->vb_mode, + true); + if (ret < 0) { + dev_err(dev, "%s: failed to align %ux%u %s with DMA\n", + __func__, pix->width, pix->height, + xlate->host_fmt->name); + return ret; + } + + ret = set_mbus_format(pcdev, dev, icd, sd, &mf, xlate); + if (ret < 0) { + dev_err(dev, "%s: failed to set format\n", __func__); + return ret; + } + + pix->width = mf.width; + pix->height = mf.height; + pix->field = mf.field; + pix->colorspace = mf.colorspace; + icd->current_fmt = xlate; + + return 0; +} + +static int omap1_cam_try_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_mbus_framefmt mf; + int ret; + /* TODO: limit to mx1 hardware capabilities */ + + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (!xlate) { + dev_warn(icd->dev.parent, "Format %#x not found\n", + pix->pixelformat); + return -EINVAL; + } + + mf.width = pix->width; + mf.height = pix->height; + mf.field = pix->field; + mf.colorspace = pix->colorspace; + mf.code = xlate->code; + + /* limit to sensor capabilities */ + ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf); + if (ret < 0) + return ret; + + pix->width = mf.width; + pix->height = mf.height; + pix->field = mf.field; + pix->colorspace = mf.colorspace; + + return 0; +} + +static bool sg_mode; + +/* + * Local mmap_mapper wrapper, + * used for detecting videobuf-dma-contig buffer allocation failures + * and switching to videobuf-dma-sg automatically for future attempts. + */ +static int omap1_cam_mmap_mapper(struct videobuf_queue *q, + struct videobuf_buffer *buf, + struct vm_area_struct *vma) +{ + struct soc_camera_device *icd = q->priv_data; + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + int ret; + + ret = pcdev->mmap_mapper(q, buf, vma); + + if (ret == -ENOMEM) + sg_mode = true; + + return ret; +} + +static void omap1_cam_init_videobuf(struct videobuf_queue *q, + struct soc_camera_device *icd) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + + if (!sg_mode) + videobuf_queue_dma_contig_init(q, &omap1_videobuf_ops, + icd->dev.parent, &pcdev->lock, + V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, + sizeof(struct omap1_cam_buf), icd); + else + videobuf_queue_sg_init(q, &omap1_videobuf_ops, + icd->dev.parent, &pcdev->lock, + V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, + sizeof(struct omap1_cam_buf), icd); + + /* use videobuf mode (auto)selected with the module parameter */ + pcdev->vb_mode = sg_mode ? OMAP1_CAM_DMA_SG : OMAP1_CAM_DMA_CONTIG; + + /* + * Ensure we substitute the videobuf-dma-contig version of the + * mmap_mapper() callback with our own wrapper, used for switching + * automatically to videobuf-dma-sg on buffer allocation failure. + */ + if (!sg_mode && q->int_ops->mmap_mapper != omap1_cam_mmap_mapper) { + pcdev->mmap_mapper = q->int_ops->mmap_mapper; + q->int_ops->mmap_mapper = omap1_cam_mmap_mapper; + } +} + +static int omap1_cam_reqbufs(struct soc_camera_file *icf, + struct v4l2_requestbuffers *p) +{ + int i; + + /* + * This is for locking debugging only. I removed spinlocks and now I + * check whether .prepare is ever called on a linked buffer, or whether + * a dma IRQ can occur for an in-work or unlinked buffer. Until now + * it hadn't triggered + */ + for (i = 0; i < p->count; i++) { + struct omap1_cam_buf *buf = container_of(icf->vb_vidq.bufs[i], + struct omap1_cam_buf, vb); + buf->inwork = 0; + INIT_LIST_HEAD(&buf->vb.queue); + } + + return 0; +} + +static int omap1_cam_querycap(struct soc_camera_host *ici, + struct v4l2_capability *cap) +{ + /* cap->name is set by the friendly caller:-> */ + strlcpy(cap->card, "OMAP1 Camera", sizeof(cap->card)); + cap->version = VERSION_CODE; + cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + + return 0; +} + +static int omap1_cam_set_bus_param(struct soc_camera_device *icd, + __u32 pixfmt) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct omap1_cam_dev *pcdev = ici->priv; + struct device *dev = icd->dev.parent; + const struct soc_camera_format_xlate *xlate; + const struct soc_mbus_pixelfmt *fmt; + unsigned long camera_flags, common_flags; + u32 ctrlclock, mode; + int ret; + + camera_flags = icd->ops->query_bus_param(icd); + + common_flags = soc_camera_bus_param_compatible(camera_flags, + SOCAM_BUS_FLAGS); + if (!common_flags) + return -EINVAL; + + /* Make choices, possibly based on platform configuration */ + if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && + (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { + if (!pcdev->pdata || + pcdev->pdata->flags & OMAP1_CAMERA_LCLK_RISING) + common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; + else + common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; + } + + ret = icd->ops->set_bus_param(icd, common_flags); + if (ret < 0) + return ret; + + ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK); + if (ctrlclock & LCLK_EN) + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN); + + if (common_flags & SOCAM_PCLK_SAMPLE_RISING) { + dev_dbg(dev, "CTRLCLOCK_REG |= POLCLK\n"); + ctrlclock |= POLCLK; + } else { + dev_dbg(dev, "CTRLCLOCK_REG &= ~POLCLK\n"); + ctrlclock &= ~POLCLK; + } + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN); + + if (ctrlclock & LCLK_EN) + CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock); + + /* select bus endianess */ + xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); + fmt = xlate->host_fmt; + + mode = CAM_READ(pcdev, MODE) & ~(RAZ_FIFO | IRQ_MASK | DMA); + if (fmt->order == SOC_MBUS_ORDER_LE) { + dev_dbg(dev, "MODE_REG &= ~ORDERCAMD\n"); + CAM_WRITE(pcdev, MODE, mode & ~ORDERCAMD); + } else { + dev_dbg(dev, "MODE_REG |= ORDERCAMD\n"); + CAM_WRITE(pcdev, MODE, mode | ORDERCAMD); + } + + return 0; +} + +static unsigned int omap1_cam_poll(struct file *file, poll_table *pt) +{ + struct soc_camera_file *icf = file->private_data; + struct omap1_cam_buf *buf; + + buf = list_entry(icf->vb_vidq.stream.next, struct omap1_cam_buf, + vb.stream); + + poll_wait(file, &buf->vb.done, pt); + + if (buf->vb.state == VIDEOBUF_DONE || + buf->vb.state == VIDEOBUF_ERROR) + return POLLIN | POLLRDNORM; + + return 0; +} + +static struct soc_camera_host_ops omap1_host_ops = { + .owner = THIS_MODULE, + .add = omap1_cam_add_device, + .remove = omap1_cam_remove_device, + .get_formats = omap1_cam_get_formats, + .set_crop = omap1_cam_set_crop, + .set_fmt = omap1_cam_set_fmt, + .try_fmt = omap1_cam_try_fmt, + .init_videobuf = omap1_cam_init_videobuf, + .reqbufs = omap1_cam_reqbufs, + .querycap = omap1_cam_querycap, + .set_bus_param = omap1_cam_set_bus_param, + .poll = omap1_cam_poll, +}; + +static int __init omap1_cam_probe(struct platform_device *pdev) +{ + struct omap1_cam_dev *pcdev; + struct resource *res; + struct clk *clk; + void __iomem *base; + unsigned int irq; + int err = 0; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + irq = platform_get_irq(pdev, 0); + if (!res || (int)irq <= 0) { + err = -ENODEV; + goto exit; + } + + clk = clk_get(&pdev->dev, "armper_ck"); + if (IS_ERR(clk)) { + err = PTR_ERR(clk); + goto exit; + } + + pcdev = kzalloc(sizeof(*pcdev) + resource_size(res), GFP_KERNEL); + if (!pcdev) { + dev_err(&pdev->dev, "Could not allocate pcdev\n"); + err = -ENOMEM; + goto exit_put_clk; + } + + pcdev->res = res; + pcdev->clk = clk; + + pcdev->pdata = pdev->dev.platform_data; + pcdev->pflags = pcdev->pdata->flags; + + if (pcdev->pdata) + pcdev->camexclk = pcdev->pdata->camexclk_khz * 1000; + + switch (pcdev->camexclk) { + case 6000000: + case 8000000: + case 9600000: + case 12000000: + case 24000000: + break; + default: + dev_warn(&pdev->dev, + "Incorrect sensor clock frequency %ld kHz, " + "should be one of 0, 6, 8, 9.6, 12 or 24 MHz, " + "please correct your platform data\n", + pcdev->pdata->camexclk_khz); + pcdev->camexclk = 0; + case 0: + dev_info(&pdev->dev, + "Not providing sensor clock\n"); + } + + INIT_LIST_HEAD(&pcdev->capture); + spin_lock_init(&pcdev->lock); + + /* + * Request the region. + */ + if (!request_mem_region(res->start, resource_size(res), DRIVER_NAME)) { + err = -EBUSY; + goto exit_kfree; + } + + base = ioremap(res->start, resource_size(res)); + if (!base) { + err = -ENOMEM; + goto exit_release; + } + pcdev->irq = irq; + pcdev->base = base; + + sensor_reset(pcdev, true); + + err = omap_request_dma(OMAP_DMA_CAMERA_IF_RX, DRIVER_NAME, + dma_isr, (void *)pcdev, &pcdev->dma_ch); + if (err < 0) { + dev_err(&pdev->dev, "Can't request DMA for OMAP1 Camera\n"); + err = -EBUSY; + goto exit_iounmap; + } + dev_dbg(&pdev->dev, "got DMA channel %d\n", pcdev->dma_ch); + + /* preconfigure DMA */ + omap_set_dma_src_params(pcdev->dma_ch, OMAP_DMA_PORT_TIPB, + OMAP_DMA_AMODE_CONSTANT, res->start + REG_CAMDATA, + 0, 0); + omap_set_dma_dest_burst_mode(pcdev->dma_ch, OMAP_DMA_DATA_BURST_4); + /* setup DMA autoinitialization */ + omap_dma_link_lch(pcdev->dma_ch, pcdev->dma_ch); + + err = request_irq(pcdev->irq, cam_isr, 0, DRIVER_NAME, pcdev); + if (err) { + dev_err(&pdev->dev, "Camera interrupt register failed\n"); + goto exit_free_dma; + } + + pcdev->soc_host.drv_name = DRIVER_NAME; + pcdev->soc_host.ops = &omap1_host_ops; + pcdev->soc_host.priv = pcdev; + pcdev->soc_host.v4l2_dev.dev = &pdev->dev; + pcdev->soc_host.nr = pdev->id; + + err = soc_camera_host_register(&pcdev->soc_host); + if (err) + goto exit_free_irq; + + dev_info(&pdev->dev, "OMAP1 Camera Interface driver loaded\n"); + + return 0; + +exit_free_irq: + free_irq(pcdev->irq, pcdev); +exit_free_dma: + omap_free_dma(pcdev->dma_ch); +exit_iounmap: + iounmap(base); +exit_release: + release_mem_region(res->start, resource_size(res)); +exit_kfree: + kfree(pcdev); +exit_put_clk: + clk_put(clk); +exit: + return err; +} + +static int __exit omap1_cam_remove(struct platform_device *pdev) +{ + struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); + struct omap1_cam_dev *pcdev = container_of(soc_host, + struct omap1_cam_dev, soc_host); + struct resource *res; + + free_irq(pcdev->irq, pcdev); + + omap_free_dma(pcdev->dma_ch); + + soc_camera_host_unregister(soc_host); + + iounmap(pcdev->base); + + res = pcdev->res; + release_mem_region(res->start, resource_size(res)); + + kfree(pcdev); + + clk_put(pcdev->clk); + + dev_info(&pdev->dev, "OMAP1 Camera Interface driver unloaded\n"); + + return 0; +} + +static struct platform_driver omap1_cam_driver = { + .driver = { + .name = DRIVER_NAME, + }, + .probe = omap1_cam_probe, + .remove = __exit_p(omap1_cam_remove), +}; + +static int __init omap1_cam_init(void) +{ + return platform_driver_register(&omap1_cam_driver); +} +module_init(omap1_cam_init); + +static void __exit omap1_cam_exit(void) +{ + platform_driver_unregister(&omap1_cam_driver); +} +module_exit(omap1_cam_exit); + +module_param(sg_mode, bool, 0644); +MODULE_PARM_DESC(sg_mode, "videobuf mode, 0: dma-contig (default), 1: dma-sg"); + +MODULE_DESCRIPTION("OMAP1 Camera Interface driver"); +MODULE_AUTHOR("Janusz Krzysztofik "); +MODULE_LICENSE("GPL v2"); +MODULE_ALIAS("platform:" DRIVER_NAME); diff --git a/include/media/omap1_camera.h b/include/media/omap1_camera.h new file mode 100644 index 000000000000..819767cf04d4 --- /dev/null +++ b/include/media/omap1_camera.h @@ -0,0 +1,35 @@ +/* + * Header for V4L2 SoC Camera driver for OMAP1 Camera Interface + * + * Copyright (C) 2010, Janusz Krzysztofik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __MEDIA_OMAP1_CAMERA_H_ +#define __MEDIA_OMAP1_CAMERA_H_ + +#include + +#define OMAP1_CAMERA_IOSIZE 0x1c + +enum omap1_cam_vb_mode { + OMAP1_CAM_DMA_CONTIG = 0, + OMAP1_CAM_DMA_SG, +}; + +#define OMAP1_CAMERA_MIN_BUF_COUNT(x) ((x) == OMAP1_CAM_DMA_CONTIG ? 3 : 2) + +struct omap1_cam_platform_data { + unsigned long camexclk_khz; + unsigned long lclk_khz_max; + unsigned long flags; +}; + +#define OMAP1_CAMERA_LCLK_RISING BIT(0) +#define OMAP1_CAMERA_RST_LOW BIT(1) +#define OMAP1_CAMERA_RST_HIGH BIT(2) + +#endif /* __MEDIA_OMAP1_CAMERA_H_ */ -- cgit v1.2.3 From 2f6e2404799ad610317157b73169c109788da0b0 Mon Sep 17 00:00:00 2001 From: Janusz Krzysztofik Date: Tue, 5 Oct 2010 11:52:45 -0300 Subject: [media] SoC Camera: add driver for OV6650 sensor This patch provides a V4L2 SoC Camera driver for OV6650 camera sensor, found on OMAP1 SoC based Amstrad Delta videophone. Since I have no experience with camera sensors, and the sensor documentation I was able to find was not very comprehensive, I left most settings at their default (reset) values, except for: - those required for proper mediabus parameters and picture geometry and format setup, - those used by controls. Resulting picture quality may be far from perfect, but better than nothing. In order to be able to get / set the sensor frame rate from userspace, I decided to provide two not yet SoC camera supported operations, g_parm and s_parm. These can be used after applying patch 4/6 from this series, "SoC Camera: add support for g_parm / s_parm operations". Created and tested against linux-2.6.36-rc5 on Amstrad Delta. Signed-off-by: Janusz Krzysztofik Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/Kconfig | 6 + drivers/media/video/Makefile | 1 + drivers/media/video/ov6650.c | 1225 +++++++++++++++++++++++++++++++++++++++ include/media/v4l2-chip-ident.h | 1 + 4 files changed, 1233 insertions(+) create mode 100644 drivers/media/video/ov6650.c (limited to 'include') diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index b89d0fda40fc..31d8a2bc3203 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -767,6 +767,12 @@ config SOC_CAMERA_PLATFORM help This is a generic SoC camera platform driver, useful for testing +config SOC_CAMERA_OV6650 + tristate "ov6650 sensor support" + depends on SOC_CAMERA && I2C + ---help--- + This is a V4L2 SoC camera driver for the OmniVision OV6650 sensor + config SOC_CAMERA_OV772X tristate "ov772x camera support" depends on SOC_CAMERA && I2C diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 557ad1f3aeb4..134f616f7a38 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -77,6 +77,7 @@ obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o obj-$(CONFIG_SOC_CAMERA_MT9T031) += mt9t031.o obj-$(CONFIG_SOC_CAMERA_MT9T112) += mt9t112.o obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o +obj-$(CONFIG_SOC_CAMERA_OV6650) += ov6650.o obj-$(CONFIG_SOC_CAMERA_OV772X) += ov772x.o obj-$(CONFIG_SOC_CAMERA_OV9640) += ov9640.o obj-$(CONFIG_SOC_CAMERA_RJ54N1) += rj54n1cb0c.o diff --git a/drivers/media/video/ov6650.c b/drivers/media/video/ov6650.c new file mode 100644 index 000000000000..b7cfeab0948c --- /dev/null +++ b/drivers/media/video/ov6650.c @@ -0,0 +1,1225 @@ +/* + * V4L2 SoC Camera driver for OmniVision OV6650 Camera Sensor + * + * Copyright (C) 2010 Janusz Krzysztofik + * + * Based on OmniVision OV96xx Camera Driver + * Copyright (C) 2009 Marek Vasut + * + * Based on ov772x camera driver: + * Copyright (C) 2008 Renesas Solutions Corp. + * Kuninori Morimoto + * + * Based on ov7670 and soc_camera_platform driver, + * Copyright 2006-7 Jonathan Corbet + * Copyright (C) 2008 Magnus Damm + * Copyright (C) 2008, Guennadi Liakhovetski + * + * Hardware specific bits initialy based on former work by Matt Callow + * drivers/media/video/omap/sensor_ov6650.c + * Copyright (C) 2006 Matt Callow + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +#include +#include + + +/* Register definitions */ +#define REG_GAIN 0x00 /* range 00 - 3F */ +#define REG_BLUE 0x01 +#define REG_RED 0x02 +#define REG_SAT 0x03 /* [7:4] saturation [0:3] reserved */ +#define REG_HUE 0x04 /* [7:6] rsrvd [5] hue en [4:0] hue */ + +#define REG_BRT 0x06 + +#define REG_PIDH 0x0a +#define REG_PIDL 0x0b + +#define REG_AECH 0x10 +#define REG_CLKRC 0x11 /* Data Format and Internal Clock */ + /* [7:6] Input system clock (MHz)*/ + /* 00=8, 01=12, 10=16, 11=24 */ + /* [5:0]: Internal Clock Pre-Scaler */ +#define REG_COMA 0x12 /* [7] Reset */ +#define REG_COMB 0x13 +#define REG_COMC 0x14 +#define REG_COMD 0x15 +#define REG_COML 0x16 +#define REG_HSTRT 0x17 +#define REG_HSTOP 0x18 +#define REG_VSTRT 0x19 +#define REG_VSTOP 0x1a +#define REG_PSHFT 0x1b +#define REG_MIDH 0x1c +#define REG_MIDL 0x1d +#define REG_HSYNS 0x1e +#define REG_HSYNE 0x1f +#define REG_COME 0x20 +#define REG_YOFF 0x21 +#define REG_UOFF 0x22 +#define REG_VOFF 0x23 +#define REG_AEW 0x24 +#define REG_AEB 0x25 +#define REG_COMF 0x26 +#define REG_COMG 0x27 +#define REG_COMH 0x28 +#define REG_COMI 0x29 + +#define REG_FRARL 0x2b +#define REG_COMJ 0x2c +#define REG_COMK 0x2d +#define REG_AVGY 0x2e +#define REG_REF0 0x2f +#define REG_REF1 0x30 +#define REG_REF2 0x31 +#define REG_FRAJH 0x32 +#define REG_FRAJL 0x33 +#define REG_FACT 0x34 +#define REG_L1AEC 0x35 +#define REG_AVGU 0x36 +#define REG_AVGV 0x37 + +#define REG_SPCB 0x60 +#define REG_SPCC 0x61 +#define REG_GAM1 0x62 +#define REG_GAM2 0x63 +#define REG_GAM3 0x64 +#define REG_SPCD 0x65 + +#define REG_SPCE 0x68 +#define REG_ADCL 0x69 + +#define REG_RMCO 0x6c +#define REG_GMCO 0x6d +#define REG_BMCO 0x6e + + +/* Register bits, values, etc. */ +#define OV6650_PIDH 0x66 /* high byte of product ID number */ +#define OV6650_PIDL 0x50 /* low byte of product ID number */ +#define OV6650_MIDH 0x7F /* high byte of mfg ID */ +#define OV6650_MIDL 0xA2 /* low byte of mfg ID */ + +#define DEF_GAIN 0x00 +#define DEF_BLUE 0x80 +#define DEF_RED 0x80 + +#define SAT_SHIFT 4 +#define SAT_MASK (0xf << SAT_SHIFT) +#define SET_SAT(x) (((x) << SAT_SHIFT) & SAT_MASK) + +#define HUE_EN BIT(5) +#define HUE_MASK 0x1f +#define DEF_HUE 0x10 +#define SET_HUE(x) (HUE_EN | ((x) & HUE_MASK)) + +#define DEF_AECH 0x4D + +#define CLKRC_6MHz 0x00 +#define CLKRC_12MHz 0x40 +#define CLKRC_16MHz 0x80 +#define CLKRC_24MHz 0xc0 +#define CLKRC_DIV_MASK 0x3f +#define GET_CLKRC_DIV(x) (((x) & CLKRC_DIV_MASK) + 1) + +#define COMA_RESET BIT(7) +#define COMA_QCIF BIT(5) +#define COMA_RAW_RGB BIT(4) +#define COMA_RGB BIT(3) +#define COMA_BW BIT(2) +#define COMA_WORD_SWAP BIT(1) +#define COMA_BYTE_SWAP BIT(0) +#define DEF_COMA 0x00 + +#define COMB_FLIP_V BIT(7) +#define COMB_FLIP_H BIT(5) +#define COMB_BAND_FILTER BIT(4) +#define COMB_AWB BIT(2) +#define COMB_AGC BIT(1) +#define COMB_AEC BIT(0) +#define DEF_COMB 0x5f + +#define COML_ONE_CHANNEL BIT(7) + +#define DEF_HSTRT 0x24 +#define DEF_HSTOP 0xd4 +#define DEF_VSTRT 0x04 +#define DEF_VSTOP 0x94 + +#define COMF_HREF_LOW BIT(4) + +#define COMJ_PCLK_RISING BIT(4) +#define COMJ_VSYNC_HIGH BIT(0) + +/* supported resolutions */ +#define W_QCIF (DEF_HSTOP - DEF_HSTRT) +#define W_CIF (W_QCIF << 1) +#define H_QCIF (DEF_VSTOP - DEF_VSTRT) +#define H_CIF (H_QCIF << 1) + +#define FRAME_RATE_MAX 30 + + +struct ov6650_reg { + u8 reg; + u8 val; +}; + +struct ov6650 { + struct v4l2_subdev subdev; + + int gain; + int blue; + int red; + int saturation; + int hue; + int brightness; + int exposure; + int gamma; + int aec; + bool vflip; + bool hflip; + bool awb; + bool agc; + bool half_scale; /* scale down output by 2 */ + struct v4l2_rect rect; /* sensor cropping window */ + unsigned long pclk_limit; /* from host */ + unsigned long pclk_max; /* from resolution and format */ + struct v4l2_fract tpf; /* as requested with s_parm */ + enum v4l2_mbus_pixelcode code; + enum v4l2_colorspace colorspace; +}; + + +static enum v4l2_mbus_pixelcode ov6650_codes[] = { + V4L2_MBUS_FMT_YUYV8_2X8, + V4L2_MBUS_FMT_UYVY8_2X8, + V4L2_MBUS_FMT_YVYU8_2X8, + V4L2_MBUS_FMT_VYUY8_2X8, + V4L2_MBUS_FMT_SBGGR8_1X8, + V4L2_MBUS_FMT_GREY8_1X8, +}; + +static const struct v4l2_queryctrl ov6650_controls[] = { + { + .id = V4L2_CID_AUTOGAIN, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "AGC", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 1, + }, + { + .id = V4L2_CID_GAIN, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Gain", + .minimum = 0, + .maximum = 0x3f, + .step = 1, + .default_value = DEF_GAIN, + }, + { + .id = V4L2_CID_AUTO_WHITE_BALANCE, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "AWB", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 1, + }, + { + .id = V4L2_CID_BLUE_BALANCE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Blue", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = DEF_BLUE, + }, + { + .id = V4L2_CID_RED_BALANCE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Red", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = DEF_RED, + }, + { + .id = V4L2_CID_SATURATION, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Saturation", + .minimum = 0, + .maximum = 0xf, + .step = 1, + .default_value = 0x8, + }, + { + .id = V4L2_CID_HUE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Hue", + .minimum = 0, + .maximum = HUE_MASK, + .step = 1, + .default_value = DEF_HUE, + }, + { + .id = V4L2_CID_BRIGHTNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Brightness", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = 0x80, + }, + { + .id = V4L2_CID_EXPOSURE_AUTO, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "AEC", + .minimum = 0, + .maximum = 3, + .step = 1, + .default_value = 0, + }, + { + .id = V4L2_CID_EXPOSURE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Exposure", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = DEF_AECH, + }, + { + .id = V4L2_CID_GAMMA, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Gamma", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = 0x12, + }, + { + .id = V4L2_CID_VFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "Flip Vertically", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 0, + }, + { + .id = V4L2_CID_HFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "Flip Horizontally", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 0, + }, +}; + +/* read a register */ +static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val) +{ + int ret; + u8 data = reg; + struct i2c_msg msg = { + .addr = client->addr, + .flags = 0, + .len = 1, + .buf = &data, + }; + + ret = i2c_transfer(client->adapter, &msg, 1); + if (ret < 0) + goto err; + + msg.flags = I2C_M_RD; + ret = i2c_transfer(client->adapter, &msg, 1); + if (ret < 0) + goto err; + + *val = data; + return 0; + +err: + dev_err(&client->dev, "Failed reading register 0x%02x!\n", reg); + return ret; +} + +/* write a register */ +static int ov6650_reg_write(struct i2c_client *client, u8 reg, u8 val) +{ + int ret; + unsigned char data[2] = { reg, val }; + struct i2c_msg msg = { + .addr = client->addr, + .flags = 0, + .len = 2, + .buf = data, + }; + + ret = i2c_transfer(client->adapter, &msg, 1); + udelay(100); + + if (ret < 0) { + dev_err(&client->dev, "Failed writing register 0x%02x!\n", reg); + return ret; + } + return 0; +} + + +/* Read a register, alter its bits, write it back */ +static int ov6650_reg_rmw(struct i2c_client *client, u8 reg, u8 set, u8 mask) +{ + u8 val; + int ret; + + ret = ov6650_reg_read(client, reg, &val); + if (ret) { + dev_err(&client->dev, + "[Read]-Modify-Write of register 0x%02x failed!\n", + reg); + return ret; + } + + val &= ~mask; + val |= set; + + ret = ov6650_reg_write(client, reg, val); + if (ret) + dev_err(&client->dev, + "Read-Modify-[Write] of register 0x%02x failed!\n", + reg); + + return ret; +} + +static struct ov6650 *to_ov6650(const struct i2c_client *client) +{ + return container_of(i2c_get_clientdata(client), struct ov6650, subdev); +} + +/* Start/Stop streaming from the device */ +static int ov6650_s_stream(struct v4l2_subdev *sd, int enable) +{ + return 0; +} + +/* Alter bus settings on camera side */ +static int ov6650_set_bus_param(struct soc_camera_device *icd, + unsigned long flags) +{ + struct soc_camera_link *icl = to_soc_camera_link(icd); + struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); + int ret; + + flags = soc_camera_apply_sensor_flags(icl, flags); + + if (flags & SOCAM_PCLK_SAMPLE_RISING) + ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0); + else + ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING); + if (ret) + return ret; + + if (flags & SOCAM_HSYNC_ACTIVE_LOW) + ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0); + else + ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW); + if (ret) + return ret; + + if (flags & SOCAM_VSYNC_ACTIVE_HIGH) + ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0); + else + ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH); + + return ret; +} + +/* Request bus settings on camera side */ +static unsigned long ov6650_query_bus_param(struct soc_camera_device *icd) +{ + struct soc_camera_link *icl = to_soc_camera_link(icd); + + unsigned long flags = SOCAM_MASTER | + SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | + SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW | + SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | + SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8; + + return soc_camera_apply_sensor_flags(icl, flags); +} + +/* Get status of additional camera capabilities */ +static int ov6650_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + uint8_t reg; + int ret = 0; + + switch (ctrl->id) { + case V4L2_CID_AUTOGAIN: + ctrl->value = priv->agc; + break; + case V4L2_CID_GAIN: + if (priv->agc) { + ret = ov6650_reg_read(client, REG_GAIN, ®); + ctrl->value = reg; + } else { + ctrl->value = priv->gain; + } + break; + case V4L2_CID_AUTO_WHITE_BALANCE: + ctrl->value = priv->awb; + break; + case V4L2_CID_BLUE_BALANCE: + if (priv->awb) { + ret = ov6650_reg_read(client, REG_BLUE, ®); + ctrl->value = reg; + } else { + ctrl->value = priv->blue; + } + break; + case V4L2_CID_RED_BALANCE: + if (priv->awb) { + ret = ov6650_reg_read(client, REG_RED, ®); + ctrl->value = reg; + } else { + ctrl->value = priv->red; + } + break; + case V4L2_CID_SATURATION: + ctrl->value = priv->saturation; + break; + case V4L2_CID_HUE: + ctrl->value = priv->hue; + break; + case V4L2_CID_BRIGHTNESS: + ctrl->value = priv->brightness; + break; + case V4L2_CID_EXPOSURE_AUTO: + ctrl->value = priv->aec; + break; + case V4L2_CID_EXPOSURE: + if (priv->aec) { + ret = ov6650_reg_read(client, REG_AECH, ®); + ctrl->value = reg; + } else { + ctrl->value = priv->exposure; + } + break; + case V4L2_CID_GAMMA: + ctrl->value = priv->gamma; + break; + case V4L2_CID_VFLIP: + ctrl->value = priv->vflip; + break; + case V4L2_CID_HFLIP: + ctrl->value = priv->hflip; + break; + } + return ret; +} + +/* Set status of additional camera capabilities */ +static int ov6650_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + int ret = 0; + + switch (ctrl->id) { + case V4L2_CID_AUTOGAIN: + ret = ov6650_reg_rmw(client, REG_COMB, + ctrl->value ? COMB_AGC : 0, COMB_AGC); + if (!ret) + priv->agc = ctrl->value; + break; + case V4L2_CID_GAIN: + ret = ov6650_reg_write(client, REG_GAIN, ctrl->value); + if (!ret) + priv->gain = ctrl->value; + break; + case V4L2_CID_AUTO_WHITE_BALANCE: + ret = ov6650_reg_rmw(client, REG_COMB, + ctrl->value ? COMB_AWB : 0, COMB_AWB); + if (!ret) + priv->awb = ctrl->value; + break; + case V4L2_CID_BLUE_BALANCE: + ret = ov6650_reg_write(client, REG_BLUE, ctrl->value); + if (!ret) + priv->blue = ctrl->value; + break; + case V4L2_CID_RED_BALANCE: + ret = ov6650_reg_write(client, REG_RED, ctrl->value); + if (!ret) + priv->red = ctrl->value; + break; + case V4L2_CID_SATURATION: + ret = ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->value), + SAT_MASK); + if (!ret) + priv->saturation = ctrl->value; + break; + case V4L2_CID_HUE: + ret = ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->value), + HUE_MASK); + if (!ret) + priv->hue = ctrl->value; + break; + case V4L2_CID_BRIGHTNESS: + ret = ov6650_reg_write(client, REG_BRT, ctrl->value); + if (!ret) + priv->brightness = ctrl->value; + break; + case V4L2_CID_EXPOSURE_AUTO: + switch (ctrl->value) { + case V4L2_EXPOSURE_AUTO: + ret = ov6650_reg_rmw(client, REG_COMB, COMB_AEC, 0); + break; + default: + ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_AEC); + break; + } + if (!ret) + priv->aec = ctrl->value; + break; + case V4L2_CID_EXPOSURE: + ret = ov6650_reg_write(client, REG_AECH, ctrl->value); + if (!ret) + priv->exposure = ctrl->value; + break; + case V4L2_CID_GAMMA: + ret = ov6650_reg_write(client, REG_GAM1, ctrl->value); + if (!ret) + priv->gamma = ctrl->value; + break; + case V4L2_CID_VFLIP: + ret = ov6650_reg_rmw(client, REG_COMB, + ctrl->value ? COMB_FLIP_V : 0, COMB_FLIP_V); + if (!ret) + priv->vflip = ctrl->value; + break; + case V4L2_CID_HFLIP: + ret = ov6650_reg_rmw(client, REG_COMB, + ctrl->value ? COMB_FLIP_H : 0, COMB_FLIP_H); + if (!ret) + priv->hflip = ctrl->value; + break; + } + + return ret; +} + +/* Get chip identification */ +static int ov6650_g_chip_ident(struct v4l2_subdev *sd, + struct v4l2_dbg_chip_ident *id) +{ + id->ident = V4L2_IDENT_OV6650; + id->revision = 0; + + return 0; +} + +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int ov6650_get_register(struct v4l2_subdev *sd, + struct v4l2_dbg_register *reg) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + int ret; + u8 val; + + if (reg->reg & ~0xff) + return -EINVAL; + + reg->size = 1; + + ret = ov6650_reg_read(client, reg->reg, &val); + if (!ret) + reg->val = (__u64)val; + + return ret; +} + +static int ov6650_set_register(struct v4l2_subdev *sd, + struct v4l2_dbg_register *reg) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + + if (reg->reg & ~0xff || reg->val & ~0xff) + return -EINVAL; + + return ov6650_reg_write(client, reg->reg, reg->val); +} +#endif + +static int ov6650_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + + a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + a->c = priv->rect; + + return 0; +} + +static int ov6650_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + struct v4l2_rect *rect = &a->c; + int ret; + + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + rect->left = ALIGN(rect->left, 2); + rect->width = ALIGN(rect->width, 2); + rect->top = ALIGN(rect->top, 2); + rect->height = ALIGN(rect->height, 2); + soc_camera_limit_side(&rect->left, &rect->width, + DEF_HSTRT << 1, 2, W_CIF); + soc_camera_limit_side(&rect->top, &rect->height, + DEF_VSTRT << 1, 2, H_CIF); + + ret = ov6650_reg_write(client, REG_HSTRT, rect->left >> 1); + if (!ret) { + priv->rect.left = rect->left; + ret = ov6650_reg_write(client, REG_HSTOP, + (rect->left + rect->width) >> 1); + } + if (!ret) { + priv->rect.width = rect->width; + ret = ov6650_reg_write(client, REG_VSTRT, rect->top >> 1); + } + if (!ret) { + priv->rect.top = rect->top; + ret = ov6650_reg_write(client, REG_VSTOP, + (rect->top + rect->height) >> 1); + } + if (!ret) + priv->rect.height = rect->height; + + return ret; +} + +static int ov6650_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) +{ + if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + a->bounds.left = DEF_HSTRT << 1; + a->bounds.top = DEF_VSTRT << 1; + a->bounds.width = W_CIF; + a->bounds.height = H_CIF; + a->defrect = a->bounds; + a->pixelaspect.numerator = 1; + a->pixelaspect.denominator = 1; + + return 0; +} + +static int ov6650_g_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + + mf->width = priv->rect.width >> priv->half_scale; + mf->height = priv->rect.height >> priv->half_scale; + mf->code = priv->code; + mf->colorspace = priv->colorspace; + mf->field = V4L2_FIELD_NONE; + + return 0; +} + +static bool is_unscaled_ok(int width, int height, struct v4l2_rect *rect) +{ + return (width > rect->width >> 1 || height > rect->height >> 1); +} + +static u8 to_clkrc(struct v4l2_fract *timeperframe, + unsigned long pclk_limit, unsigned long pclk_max) +{ + unsigned long pclk; + + if (timeperframe->numerator && timeperframe->denominator) + pclk = pclk_max * timeperframe->denominator / + (FRAME_RATE_MAX * timeperframe->numerator); + else + pclk = pclk_max; + + if (pclk_limit && pclk_limit < pclk) + pclk = pclk_limit; + + return (pclk_max - 1) / pclk; +} + +/* set the format we will capture in */ +static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct soc_camera_device *icd = client->dev.platform_data; + struct soc_camera_sense *sense = icd->sense; + struct ov6650 *priv = to_ov6650(client); + bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); + struct v4l2_crop a = { + .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, + .c = { + .left = priv->rect.left + (priv->rect.width >> 1) - + (mf->width >> (1 - half_scale)), + .top = priv->rect.top + (priv->rect.height >> 1) - + (mf->height >> (1 - half_scale)), + .width = mf->width << half_scale, + .height = mf->height << half_scale, + }, + }; + enum v4l2_mbus_pixelcode code = mf->code; + unsigned long mclk, pclk; + u8 coma_set = 0, coma_mask = 0, coml_set, coml_mask, clkrc; + int ret; + + /* select color matrix configuration for given color encoding */ + switch (code) { + case V4L2_MBUS_FMT_GREY8_1X8: + dev_dbg(&client->dev, "pixel format GREY8_1X8\n"); + coma_mask |= COMA_RGB | COMA_WORD_SWAP | COMA_BYTE_SWAP; + coma_set |= COMA_BW; + break; + case V4L2_MBUS_FMT_YUYV8_2X8: + dev_dbg(&client->dev, "pixel format YUYV8_2X8_LE\n"); + coma_mask |= COMA_RGB | COMA_BW | COMA_BYTE_SWAP; + coma_set |= COMA_WORD_SWAP; + break; + case V4L2_MBUS_FMT_YVYU8_2X8: + dev_dbg(&client->dev, "pixel format YVYU8_2X8_LE (untested)\n"); + coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP | + COMA_BYTE_SWAP; + break; + case V4L2_MBUS_FMT_UYVY8_2X8: + dev_dbg(&client->dev, "pixel format YUYV8_2X8_BE\n"); + if (half_scale) { + coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP; + coma_set |= COMA_BYTE_SWAP; + } else { + coma_mask |= COMA_RGB | COMA_BW; + coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP; + } + break; + case V4L2_MBUS_FMT_VYUY8_2X8: + dev_dbg(&client->dev, "pixel format YVYU8_2X8_BE (untested)\n"); + if (half_scale) { + coma_mask |= COMA_RGB | COMA_BW; + coma_set |= COMA_BYTE_SWAP | COMA_WORD_SWAP; + } else { + coma_mask |= COMA_RGB | COMA_BW | COMA_WORD_SWAP; + coma_set |= COMA_BYTE_SWAP; + } + break; + case V4L2_MBUS_FMT_SBGGR8_1X8: + dev_dbg(&client->dev, "pixel format SBGGR8_1X8 (untested)\n"); + coma_mask |= COMA_BW | COMA_BYTE_SWAP | COMA_WORD_SWAP; + coma_set |= COMA_RAW_RGB | COMA_RGB; + break; + case 0: + break; + default: + dev_err(&client->dev, "Pixel format not handled: 0x%x\n", code); + return -EINVAL; + } + priv->code = code; + + if (code == V4L2_MBUS_FMT_GREY8_1X8 || + code == V4L2_MBUS_FMT_SBGGR8_1X8) { + coml_mask = COML_ONE_CHANNEL; + coml_set = 0; + priv->pclk_max = 4000000; + } else { + coml_mask = 0; + coml_set = COML_ONE_CHANNEL; + priv->pclk_max = 8000000; + } + + if (code == V4L2_MBUS_FMT_SBGGR8_1X8) + priv->colorspace = V4L2_COLORSPACE_SRGB; + else if (code != 0) + priv->colorspace = V4L2_COLORSPACE_JPEG; + + if (half_scale) { + dev_dbg(&client->dev, "max resolution: QCIF\n"); + coma_set |= COMA_QCIF; + priv->pclk_max /= 2; + } else { + dev_dbg(&client->dev, "max resolution: CIF\n"); + coma_mask |= COMA_QCIF; + } + priv->half_scale = half_scale; + + if (sense) { + if (sense->master_clock == 8000000) { + dev_dbg(&client->dev, "8MHz input clock\n"); + clkrc = CLKRC_6MHz; + } else if (sense->master_clock == 12000000) { + dev_dbg(&client->dev, "12MHz input clock\n"); + clkrc = CLKRC_12MHz; + } else if (sense->master_clock == 16000000) { + dev_dbg(&client->dev, "16MHz input clock\n"); + clkrc = CLKRC_16MHz; + } else if (sense->master_clock == 24000000) { + dev_dbg(&client->dev, "24MHz input clock\n"); + clkrc = CLKRC_24MHz; + } else { + dev_err(&client->dev, + "unspported input clock, check platform data\n"); + return -EINVAL; + } + mclk = sense->master_clock; + priv->pclk_limit = sense->pixel_clock_max; + } else { + clkrc = CLKRC_24MHz; + mclk = 24000000; + priv->pclk_limit = 0; + dev_dbg(&client->dev, "using default 24MHz input clock\n"); + } + + clkrc |= to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max); + + pclk = priv->pclk_max / GET_CLKRC_DIV(clkrc); + dev_dbg(&client->dev, "pixel clock divider: %ld.%ld\n", + mclk / pclk, 10 * mclk % pclk / pclk); + + ret = ov6650_s_crop(sd, &a); + if (!ret) + ret = ov6650_reg_rmw(client, REG_COMA, coma_set, coma_mask); + if (!ret) + ret = ov6650_reg_write(client, REG_CLKRC, clkrc); + if (!ret) + ret = ov6650_reg_rmw(client, REG_COML, coml_set, coml_mask); + + if (!ret) { + mf->colorspace = priv->colorspace; + mf->width = priv->rect.width >> half_scale; + mf->height = priv->rect.height >> half_scale; + } + + return ret; +} + +static int ov6650_try_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + + if (is_unscaled_ok(mf->width, mf->height, &priv->rect)) + v4l_bound_align_image(&mf->width, 2, W_CIF, 1, + &mf->height, 2, H_CIF, 1, 0); + + mf->field = V4L2_FIELD_NONE; + + switch (mf->code) { + case V4L2_MBUS_FMT_Y10_1X10: + mf->code = V4L2_MBUS_FMT_GREY8_1X8; + case V4L2_MBUS_FMT_GREY8_1X8: + case V4L2_MBUS_FMT_YVYU8_2X8: + case V4L2_MBUS_FMT_YUYV8_2X8: + case V4L2_MBUS_FMT_VYUY8_2X8: + case V4L2_MBUS_FMT_UYVY8_2X8: + mf->colorspace = V4L2_COLORSPACE_JPEG; + break; + default: + mf->code = V4L2_MBUS_FMT_SBGGR8_1X8; + case V4L2_MBUS_FMT_SBGGR8_1X8: + mf->colorspace = V4L2_COLORSPACE_SRGB; + break; + } + + return 0; +} + +static int ov6650_enum_fmt(struct v4l2_subdev *sd, unsigned int index, + enum v4l2_mbus_pixelcode *code) +{ + if (index >= ARRAY_SIZE(ov6650_codes)) + return -EINVAL; + + *code = ov6650_codes[index]; + return 0; +} + +static int ov6650_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + struct v4l2_captureparm *cp = &parms->parm.capture; + + if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + memset(cp, 0, sizeof(*cp)); + cp->capability = V4L2_CAP_TIMEPERFRAME; + cp->timeperframe.numerator = GET_CLKRC_DIV(to_clkrc(&priv->tpf, + priv->pclk_limit, priv->pclk_max)); + cp->timeperframe.denominator = FRAME_RATE_MAX; + + dev_dbg(&client->dev, "Frame interval: %u/%u s\n", + cp->timeperframe.numerator, cp->timeperframe.denominator); + + return 0; +} + +static int ov6650_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct ov6650 *priv = to_ov6650(client); + struct v4l2_captureparm *cp = &parms->parm.capture; + struct v4l2_fract *tpf = &cp->timeperframe; + int div, ret; + u8 clkrc; + + if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + if (cp->extendedmode != 0) + return -EINVAL; + + if (tpf->numerator == 0 || tpf->denominator == 0) + div = 1; /* Reset to full rate */ + else + div = (tpf->numerator * FRAME_RATE_MAX) / tpf->denominator; + + if (div == 0) + div = 1; + else if (div > GET_CLKRC_DIV(CLKRC_DIV_MASK)) + div = GET_CLKRC_DIV(CLKRC_DIV_MASK); + + /* + * Keep result to be used as tpf limit + * for subseqent clock divider calculations + */ + priv->tpf.numerator = div; + priv->tpf.denominator = FRAME_RATE_MAX; + + clkrc = to_clkrc(&priv->tpf, priv->pclk_limit, priv->pclk_max); + + ret = ov6650_reg_rmw(client, REG_CLKRC, clkrc, CLKRC_DIV_MASK); + if (!ret) { + tpf->numerator = GET_CLKRC_DIV(clkrc); + tpf->denominator = FRAME_RATE_MAX; + } + + return ret; +} + +/* Soft reset the camera. This has nothing to do with the RESET pin! */ +static int ov6650_reset(struct i2c_client *client) +{ + int ret; + + dev_dbg(&client->dev, "reset\n"); + + ret = ov6650_reg_rmw(client, REG_COMA, COMA_RESET, 0); + if (ret) + dev_err(&client->dev, + "An error occured while entering soft reset!\n"); + + return ret; +} + +/* program default register values */ +static int ov6650_prog_dflt(struct i2c_client *client) +{ + int ret; + + dev_dbg(&client->dev, "initializing\n"); + + ret = ov6650_reg_write(client, REG_COMA, 0); /* ~COMA_RESET */ + if (!ret) + ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_BAND_FILTER); + + return ret; +} + +static int ov6650_video_probe(struct soc_camera_device *icd, + struct i2c_client *client) +{ + u8 pidh, pidl, midh, midl; + int ret = 0; + + /* + * check and show product ID and manufacturer ID + */ + ret = ov6650_reg_read(client, REG_PIDH, &pidh); + if (!ret) + ret = ov6650_reg_read(client, REG_PIDL, &pidl); + if (!ret) + ret = ov6650_reg_read(client, REG_MIDH, &midh); + if (!ret) + ret = ov6650_reg_read(client, REG_MIDL, &midl); + + if (ret) + return ret; + + if ((pidh != OV6650_PIDH) || (pidl != OV6650_PIDL)) { + dev_err(&client->dev, "Product ID error 0x%02x:0x%02x\n", + pidh, pidl); + return -ENODEV; + } + + dev_info(&client->dev, + "ov6650 Product ID 0x%02x:0x%02x Manufacturer ID 0x%02x:0x%02x\n", + pidh, pidl, midh, midl); + + ret = ov6650_reset(client); + if (!ret) + ret = ov6650_prog_dflt(client); + + return ret; +} + +static struct soc_camera_ops ov6650_ops = { + .set_bus_param = ov6650_set_bus_param, + .query_bus_param = ov6650_query_bus_param, + .controls = ov6650_controls, + .num_controls = ARRAY_SIZE(ov6650_controls), +}; + +static struct v4l2_subdev_core_ops ov6650_core_ops = { + .g_ctrl = ov6650_g_ctrl, + .s_ctrl = ov6650_s_ctrl, + .g_chip_ident = ov6650_g_chip_ident, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = ov6650_get_register, + .s_register = ov6650_set_register, +#endif +}; + +static struct v4l2_subdev_video_ops ov6650_video_ops = { + .s_stream = ov6650_s_stream, + .g_mbus_fmt = ov6650_g_fmt, + .s_mbus_fmt = ov6650_s_fmt, + .try_mbus_fmt = ov6650_try_fmt, + .enum_mbus_fmt = ov6650_enum_fmt, + .cropcap = ov6650_cropcap, + .g_crop = ov6650_g_crop, + .s_crop = ov6650_s_crop, + .g_parm = ov6650_g_parm, + .s_parm = ov6650_s_parm, +}; + +static struct v4l2_subdev_ops ov6650_subdev_ops = { + .core = &ov6650_core_ops, + .video = &ov6650_video_ops, +}; + +/* + * i2c_driver function + */ +static int ov6650_probe(struct i2c_client *client, + const struct i2c_device_id *did) +{ + struct ov6650 *priv; + struct soc_camera_device *icd = client->dev.platform_data; + struct soc_camera_link *icl; + int ret; + + if (!icd) { + dev_err(&client->dev, "Missing soc-camera data!\n"); + return -EINVAL; + } + + icl = to_soc_camera_link(icd); + if (!icl) { + dev_err(&client->dev, "Missing platform_data for driver\n"); + return -EINVAL; + } + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) { + dev_err(&client->dev, + "Failed to allocate memory for private data!\n"); + return -ENOMEM; + } + + v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops); + + icd->ops = &ov6650_ops; + + priv->rect.left = DEF_HSTRT << 1; + priv->rect.top = DEF_VSTRT << 1; + priv->rect.width = W_CIF; + priv->rect.height = H_CIF; + priv->half_scale = false; + priv->code = V4L2_MBUS_FMT_YUYV8_2X8; + priv->colorspace = V4L2_COLORSPACE_JPEG; + + ret = ov6650_video_probe(icd, client); + + if (ret) { + icd->ops = NULL; + i2c_set_clientdata(client, NULL); + kfree(priv); + } + + return ret; +} + +static int ov6650_remove(struct i2c_client *client) +{ + struct ov6650 *priv = to_ov6650(client); + + i2c_set_clientdata(client, NULL); + kfree(priv); + return 0; +} + +static const struct i2c_device_id ov6650_id[] = { + { "ov6650", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, ov6650_id); + +static struct i2c_driver ov6650_i2c_driver = { + .driver = { + .name = "ov6650", + }, + .probe = ov6650_probe, + .remove = ov6650_remove, + .id_table = ov6650_id, +}; + +static int __init ov6650_module_init(void) +{ + return i2c_add_driver(&ov6650_i2c_driver); +} + +static void __exit ov6650_module_exit(void) +{ + i2c_del_driver(&ov6650_i2c_driver); +} + +module_init(ov6650_module_init); +module_exit(ov6650_module_exit); + +MODULE_DESCRIPTION("SoC Camera driver for OmniVision OV6650"); +MODULE_AUTHOR("Janusz Krzysztofik "); +MODULE_LICENSE("GPL v2"); diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h index 21b4428c12ab..1c612b4703a1 100644 --- a/include/media/v4l2-chip-ident.h +++ b/include/media/v4l2-chip-ident.h @@ -70,6 +70,7 @@ enum { V4L2_IDENT_OV9655 = 255, V4L2_IDENT_SOI968 = 256, V4L2_IDENT_OV9640 = 257, + V4L2_IDENT_OV6650 = 258, /* module saa7146: reserved range 300-309 */ V4L2_IDENT_SAA7146 = 300, -- cgit v1.2.3 From 32e1f777274b0e642a8af381a4e07d7858506f37 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Tue, 5 Oct 2010 12:32:41 -0300 Subject: [media] V4L: add IMX074 sensor chip ID Chip identification register contains the value 0x74. Signed-off-by: Guennadi Liakhovetski Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-chip-ident.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h index 1c612b4703a1..aeb4ff9c6140 100644 --- a/include/media/v4l2-chip-ident.h +++ b/include/media/v4l2-chip-ident.h @@ -38,6 +38,9 @@ enum { /* module tvaudio: reserved range 50-99 */ V4L2_IDENT_TVAUDIO = 50, /* A tvaudio chip, unknown which it is exactly */ + /* Sony IMX074 */ + V4L2_IDENT_IMX074 = 74, + /* module saa7110: just ident 100 */ V4L2_IDENT_SAA7110 = 100, -- cgit v1.2.3 From 5f3cc4474cdeab3ee44962fd752baec24e8fecec Mon Sep 17 00:00:00 2001 From: Sylwester Nawrocki Date: Thu, 7 Oct 2010 10:06:16 -0300 Subject: [media] s5p-fimc: Add camera capture support Add a video device driver per each FIMC entity to support the camera capture input mode. Video capture node is registered only if CCD sensor data is provided through driver's platfrom data and board setup code. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Reviewed-by: Marek Szyprowski Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/s5p-fimc/Makefile | 2 +- drivers/media/video/s5p-fimc/fimc-capture.c | 819 ++++++++++++++++++++++++++++ drivers/media/video/s5p-fimc/fimc-core.c | 563 +++++++++++++------ drivers/media/video/s5p-fimc/fimc-core.h | 205 ++++++- drivers/media/video/s5p-fimc/fimc-reg.c | 173 +++++- include/media/s3c_fimc.h | 60 ++ 6 files changed, 1630 insertions(+), 192 deletions(-) create mode 100644 drivers/media/video/s5p-fimc/fimc-capture.c create mode 100644 include/media/s3c_fimc.h (limited to 'include') diff --git a/drivers/media/video/s5p-fimc/Makefile b/drivers/media/video/s5p-fimc/Makefile index 0d9d54132ecc..7ea1b1403b1e 100644 --- a/drivers/media/video/s5p-fimc/Makefile +++ b/drivers/media/video/s5p-fimc/Makefile @@ -1,3 +1,3 @@ obj-$(CONFIG_VIDEO_SAMSUNG_S5P_FIMC) := s5p-fimc.o -s5p-fimc-y := fimc-core.o fimc-reg.o +s5p-fimc-y := fimc-core.o fimc-reg.o fimc-capture.o diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c new file mode 100644 index 000000000000..e8f13d3e2df1 --- /dev/null +++ b/drivers/media/video/s5p-fimc/fimc-capture.c @@ -0,0 +1,819 @@ +/* + * Samsung S5P SoC series camera interface (camera capture) driver + * + * Copyright (c) 2010 Samsung Electronics Co., Ltd + * Author: Sylwester Nawrocki, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "fimc-core.h" + +static struct v4l2_subdev *fimc_subdev_register(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *isp_info) +{ + struct i2c_adapter *i2c_adap; + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; + struct v4l2_subdev *sd = NULL; + + i2c_adap = i2c_get_adapter(isp_info->i2c_bus_num); + if (!i2c_adap) + return ERR_PTR(-ENOMEM); + + sd = v4l2_i2c_new_subdev_board(&vid_cap->v4l2_dev, i2c_adap, + MODULE_NAME, isp_info->board_info, NULL); + if (!sd) { + v4l2_err(&vid_cap->v4l2_dev, "failed to acquire subdev\n"); + return NULL; + } + + v4l2_info(&vid_cap->v4l2_dev, "subdevice %s registered successfuly\n", + isp_info->board_info->type); + + return sd; +} + +static void fimc_subdev_unregister(struct fimc_dev *fimc) +{ + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; + struct i2c_client *client; + + if (vid_cap->input_index < 0) + return; /* Subdevice already released or not registered. */ + + if (vid_cap->sd) { + v4l2_device_unregister_subdev(vid_cap->sd); + client = v4l2_get_subdevdata(vid_cap->sd); + i2c_unregister_device(client); + i2c_put_adapter(client->adapter); + vid_cap->sd = NULL; + } + + vid_cap->input_index = -1; +} + +/** + * fimc_subdev_attach - attach v4l2_subdev to camera host interface + * + * @fimc: FIMC device information + * @index: index to the array of available subdevices, + * -1 for full array search or non negative value + * to select specific subdevice + */ +static int fimc_subdev_attach(struct fimc_dev *fimc, int index) +{ + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; + struct s3c_platform_fimc *pdata = fimc->pdata; + struct s3c_fimc_isp_info *isp_info; + struct v4l2_subdev *sd; + int i; + + for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i) { + isp_info = pdata->isp_info[i]; + + if (!isp_info || (index >= 0 && i != index)) + continue; + + sd = fimc_subdev_register(fimc, isp_info); + if (sd) { + vid_cap->sd = sd; + vid_cap->input_index = i; + + return 0; + } + } + + vid_cap->input_index = -1; + vid_cap->sd = NULL; + v4l2_err(&vid_cap->v4l2_dev, "fimc%d: sensor attach failed\n", + fimc->id); + return -ENODEV; +} + +static int fimc_isp_subdev_init(struct fimc_dev *fimc, int index) +{ + struct s3c_fimc_isp_info *isp_info; + int ret; + + ret = fimc_subdev_attach(fimc, index); + if (ret) + return ret; + + isp_info = fimc->pdata->isp_info[fimc->vid_cap.input_index]; + ret = fimc_hw_set_camera_polarity(fimc, isp_info); + if (!ret) { + ret = v4l2_subdev_call(fimc->vid_cap.sd, core, + s_power, 1); + if (!ret) + return ret; + } + + fimc_subdev_unregister(fimc); + err("ISP initialization failed: %d", ret); + return ret; +} + +/* + * At least one buffer on the pending_buf_q queue is required. + * Locking: The caller holds fimc->slock spinlock. + */ +int fimc_vid_cap_buf_queue(struct fimc_dev *fimc, + struct fimc_vid_buffer *fimc_vb) +{ + struct fimc_vid_cap *cap = &fimc->vid_cap; + struct fimc_ctx *ctx = cap->ctx; + int ret = 0; + + BUG_ON(!fimc || !fimc_vb); + + ret = fimc_prepare_addr(ctx, fimc_vb, &ctx->d_frame, + &fimc_vb->paddr); + if (ret) + return ret; + + if (test_bit(ST_CAPT_STREAM, &fimc->state)) { + fimc_pending_queue_add(cap, fimc_vb); + } else { + /* Setup the buffer directly for processing. */ + int buf_id = (cap->reqbufs_count == 1) ? -1 : cap->buf_index; + fimc_hw_set_output_addr(fimc, &fimc_vb->paddr, buf_id); + + fimc_vb->index = cap->buf_index; + active_queue_add(cap, fimc_vb); + + if (++cap->buf_index >= FIMC_MAX_OUT_BUFS) + cap->buf_index = 0; + } + return ret; +} + +static int fimc_stop_capture(struct fimc_dev *fimc) +{ + unsigned long flags; + struct fimc_vid_cap *cap; + int ret; + + cap = &fimc->vid_cap; + + if (!fimc_capture_active(fimc)) + return 0; + + spin_lock_irqsave(&fimc->slock, flags); + set_bit(ST_CAPT_SHUT, &fimc->state); + fimc_deactivate_capture(fimc); + spin_unlock_irqrestore(&fimc->slock, flags); + + wait_event_timeout(fimc->irq_queue, + test_bit(ST_CAPT_SHUT, &fimc->state), + FIMC_SHUTDOWN_TIMEOUT); + + ret = v4l2_subdev_call(cap->sd, video, s_stream, 0); + if (ret) + v4l2_err(&fimc->vid_cap.v4l2_dev, "s_stream(0) failed\n"); + + spin_lock_irqsave(&fimc->slock, flags); + fimc->state &= ~(1 << ST_CAPT_RUN | 1 << ST_CAPT_PEND | + 1 << ST_CAPT_STREAM); + + fimc->vid_cap.active_buf_cnt = 0; + spin_unlock_irqrestore(&fimc->slock, flags); + + dbg("state: 0x%lx", fimc->state); + return 0; +} + +static int fimc_capture_open(struct file *file) +{ + struct fimc_dev *fimc = video_drvdata(file); + int ret = 0; + + dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); + + /* Return if the corresponding video mem2mem node is already opened. */ + if (fimc_m2m_active(fimc)) + return -EBUSY; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + if (++fimc->vid_cap.refcnt == 1) { + ret = fimc_isp_subdev_init(fimc, -1); + if (ret) { + fimc->vid_cap.refcnt--; + ret = -EIO; + } + } + + file->private_data = fimc->vid_cap.ctx; + + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_capture_close(struct file *file) +{ + struct fimc_dev *fimc = video_drvdata(file); + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + dbg("pid: %d, state: 0x%lx", task_pid_nr(current), fimc->state); + + if (--fimc->vid_cap.refcnt == 0) { + fimc_stop_capture(fimc); + + videobuf_stop(&fimc->vid_cap.vbq); + videobuf_mmap_free(&fimc->vid_cap.vbq); + + v4l2_err(&fimc->vid_cap.v4l2_dev, "releasing ISP\n"); + v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0); + fimc_subdev_unregister(fimc); + } + + mutex_unlock(&fimc->lock); + return 0; +} + +static unsigned int fimc_capture_poll(struct file *file, + struct poll_table_struct *wait) +{ + struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + int ret; + + if (mutex_lock_interruptible(&fimc->lock)) + return POLLERR; + + ret = videobuf_poll_stream(file, &cap->vbq, wait); + mutex_unlock(&fimc->lock); + + return ret; +} + +static int fimc_capture_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + int ret; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + ret = videobuf_mmap_mapper(&cap->vbq, vma); + mutex_unlock(&fimc->lock); + + return ret; +} + +/* video device file operations */ +static const struct v4l2_file_operations fimc_capture_fops = { + .owner = THIS_MODULE, + .open = fimc_capture_open, + .release = fimc_capture_close, + .poll = fimc_capture_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = fimc_capture_mmap, +}; + +static int fimc_vidioc_querycap_capture(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; + + strncpy(cap->driver, fimc->pdev->name, sizeof(cap->driver) - 1); + strncpy(cap->card, fimc->pdev->name, sizeof(cap->card) - 1); + cap->bus_info[0] = 0; + cap->version = KERNEL_VERSION(1, 0, 0); + cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_CAPTURE; + + return 0; +} + +/* Synchronize formats of the camera interface input and attached sensor. */ +static int sync_capture_fmt(struct fimc_ctx *ctx) +{ + struct fimc_frame *frame = &ctx->s_frame; + struct fimc_dev *fimc = ctx->fimc_dev; + struct v4l2_mbus_framefmt *fmt = &fimc->vid_cap.fmt; + int ret; + + fmt->width = ctx->d_frame.o_width; + fmt->height = ctx->d_frame.o_height; + + ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_mbus_fmt, fmt); + if (ret == -ENOIOCTLCMD) { + err("s_mbus_fmt failed"); + return ret; + } + dbg("w: %d, h: %d, code= %d", fmt->width, fmt->height, fmt->code); + + frame->fmt = find_mbus_format(fmt, FMT_FLAGS_CAM); + if (!frame->fmt) { + err("fimc source format not found\n"); + return -EINVAL; + } + + frame->f_width = fmt->width; + frame->f_height = fmt->height; + frame->width = fmt->width; + frame->height = fmt->height; + frame->o_width = fmt->width; + frame->o_height = fmt->height; + frame->offs_h = 0; + frame->offs_v = 0; + + return 0; +} + +static int fimc_cap_s_fmt(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_frame *frame; + struct v4l2_pix_format *pix; + int ret; + + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + ret = fimc_vidioc_try_fmt(file, priv, f); + if (ret) + return ret; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + if (fimc_capture_active(fimc)) { + ret = -EBUSY; + goto sf_unlock; + } + + frame = &ctx->d_frame; + + pix = &f->fmt.pix; + frame->fmt = find_format(f, FMT_FLAGS_M2M | FMT_FLAGS_CAM); + if (!frame->fmt) { + err("fimc target format not found\n"); + ret = -EINVAL; + goto sf_unlock; + } + + /* Output DMA frame pixel size and offsets. */ + frame->f_width = pix->bytesperline * 8 / frame->fmt->depth; + frame->f_height = pix->height; + frame->width = pix->width; + frame->height = pix->height; + frame->o_width = pix->width; + frame->o_height = pix->height; + frame->size = (pix->width * pix->height * frame->fmt->depth) >> 3; + frame->offs_h = 0; + frame->offs_v = 0; + + ret = sync_capture_fmt(ctx); + + ctx->state |= (FIMC_PARAMS | FIMC_DST_FMT); + +sf_unlock: + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_enum_input(struct file *file, void *priv, + struct v4l2_input *i) +{ + struct fimc_ctx *ctx = priv; + struct s3c_platform_fimc *pldata = ctx->fimc_dev->pdata; + struct s3c_fimc_isp_info *isp_info; + + if (i->index >= FIMC_MAX_CAMIF_CLIENTS) + return -EINVAL; + + isp_info = pldata->isp_info[i->index]; + if (isp_info == NULL) + return -EINVAL; + + i->type = V4L2_INPUT_TYPE_CAMERA; + strncpy(i->name, isp_info->board_info->type, 32); + return 0; +} + +static int fimc_cap_s_input(struct file *file, void *priv, + unsigned int i) +{ + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + struct s3c_platform_fimc *pdata = fimc->pdata; + int ret; + + if (fimc_capture_active(ctx->fimc_dev)) + return -EBUSY; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + if (i >= FIMC_MAX_CAMIF_CLIENTS || !pdata->isp_info[i]) { + ret = -EINVAL; + goto si_unlock; + } + + if (fimc->vid_cap.sd) { + ret = v4l2_subdev_call(fimc->vid_cap.sd, core, s_power, 0); + if (ret) + err("s_power failed: %d", ret); + } + + /* Release the attached sensor subdevice. */ + fimc_subdev_unregister(fimc); + + ret = fimc_isp_subdev_init(fimc, i); + +si_unlock: + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_g_input(struct file *file, void *priv, + unsigned int *i) +{ + struct fimc_ctx *ctx = priv; + struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; + + *i = cap->input_index; + return 0; +} + +static int fimc_cap_streamon(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct s3c_fimc_isp_info *isp_info; + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + int ret = -EBUSY; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + if (fimc_capture_active(fimc) || !fimc->vid_cap.sd) + goto s_unlock; + + if (!(ctx->state & FIMC_DST_FMT)) { + v4l2_err(&fimc->vid_cap.v4l2_dev, "Format is not set\n"); + ret = -EINVAL; + goto s_unlock; + } + + ret = v4l2_subdev_call(fimc->vid_cap.sd, video, s_stream, 1); + if (ret && ret != -ENOIOCTLCMD) + goto s_unlock; + + ret = fimc_prepare_config(ctx, ctx->state); + if (ret) + goto s_unlock; + + isp_info = fimc->pdata->isp_info[fimc->vid_cap.input_index]; + fimc_hw_set_camera_type(fimc, isp_info); + fimc_hw_set_camera_source(fimc, isp_info); + fimc_hw_set_camera_offset(fimc, &ctx->s_frame); + + if (ctx->state & FIMC_PARAMS) { + ret = fimc_set_scaler_info(ctx); + if (ret) { + err("Scaler setup error"); + goto s_unlock; + } + fimc_hw_set_input_path(ctx); + fimc_hw_set_scaler(ctx); + fimc_hw_set_target_format(ctx); + fimc_hw_set_rotation(ctx); + fimc_hw_set_effect(ctx); + } + + fimc_hw_set_output_path(ctx); + fimc_hw_set_out_dma(ctx); + + INIT_LIST_HEAD(&fimc->vid_cap.pending_buf_q); + INIT_LIST_HEAD(&fimc->vid_cap.active_buf_q); + fimc->vid_cap.active_buf_cnt = 0; + fimc->vid_cap.frame_count = 0; + + set_bit(ST_CAPT_PEND, &fimc->state); + ret = videobuf_streamon(&fimc->vid_cap.vbq); + +s_unlock: + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_streamoff(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + unsigned long flags; + int ret; + + spin_lock_irqsave(&fimc->slock, flags); + if (!fimc_capture_running(fimc) && !fimc_capture_pending(fimc)) { + spin_unlock_irqrestore(&fimc->slock, flags); + dbg("state: 0x%lx", fimc->state); + return -EINVAL; + } + spin_unlock_irqrestore(&fimc->slock, flags); + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + fimc_stop_capture(fimc); + ret = videobuf_streamoff(&cap->vbq); + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_reqbufs(struct file *file, void *priv, + struct v4l2_requestbuffers *reqbufs) +{ + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + int ret; + + if (fimc_capture_active(ctx->fimc_dev)) + return -EBUSY; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + ret = videobuf_reqbufs(&cap->vbq, reqbufs); + if (!ret) + cap->reqbufs_count = reqbufs->count; + + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_querybuf(struct file *file, void *priv, + struct v4l2_buffer *buf) +{ + struct fimc_ctx *ctx = priv; + struct fimc_vid_cap *cap = &ctx->fimc_dev->vid_cap; + + if (fimc_capture_active(ctx->fimc_dev)) + return -EBUSY; + + return videobuf_querybuf(&cap->vbq, buf); +} + +static int fimc_cap_qbuf(struct file *file, void *priv, + struct v4l2_buffer *buf) +{ + struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + int ret; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + ret = videobuf_qbuf(&cap->vbq, buf); + + mutex_unlock(&fimc->lock); + return ret; +} + +static int fimc_cap_dqbuf(struct file *file, void *priv, + struct v4l2_buffer *buf) +{ + struct fimc_ctx *ctx = priv; + int ret; + + if (mutex_lock_interruptible(&ctx->fimc_dev->lock)) + return -ERESTARTSYS; + + ret = videobuf_dqbuf(&ctx->fimc_dev->vid_cap.vbq, buf, + file->f_flags & O_NONBLOCK); + + mutex_unlock(&ctx->fimc_dev->lock); + return ret; +} + +static int fimc_cap_s_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct fimc_ctx *ctx = priv; + int ret = -EINVAL; + + if (mutex_lock_interruptible(&ctx->fimc_dev->lock)) + return -ERESTARTSYS; + + /* Allow any controls but 90/270 rotation while streaming */ + if (!fimc_capture_active(ctx->fimc_dev) || + ctrl->id != V4L2_CID_ROTATE || + (ctrl->value != 90 && ctrl->value != 270)) { + ret = check_ctrl_val(ctx, ctrl); + if (!ret) { + ret = fimc_s_ctrl(ctx, ctrl); + if (!ret) + ctx->state |= FIMC_PARAMS; + } + } + if (ret == -EINVAL) + ret = v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd, + core, s_ctrl, ctrl); + + mutex_unlock(&ctx->fimc_dev->lock); + return ret; +} + +static int fimc_cap_s_crop(struct file *file, void *fh, + struct v4l2_crop *cr) +{ + struct fimc_frame *f; + struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; + int ret = -EINVAL; + + if (fimc_capture_active(fimc)) + return -EBUSY; + + ret = fimc_try_crop(ctx, cr); + if (ret) + return ret; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + if (!(ctx->state & FIMC_DST_FMT)) { + v4l2_err(&fimc->vid_cap.v4l2_dev, + "Capture color format not set\n"); + goto sc_unlock; + } + + f = &ctx->s_frame; + /* Check for the pixel scaling ratio when cropping input image. */ + ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame); + if (ret) { + v4l2_err(&fimc->vid_cap.v4l2_dev, "Out of the scaler range"); + } else { + ret = 0; + f->offs_h = cr->c.left; + f->offs_v = cr->c.top; + f->width = cr->c.width; + f->height = cr->c.height; + } + +sc_unlock: + mutex_unlock(&fimc->lock); + return ret; +} + + +static const struct v4l2_ioctl_ops fimc_capture_ioctl_ops = { + .vidioc_querycap = fimc_vidioc_querycap_capture, + + .vidioc_enum_fmt_vid_cap = fimc_vidioc_enum_fmt, + .vidioc_try_fmt_vid_cap = fimc_vidioc_try_fmt, + .vidioc_s_fmt_vid_cap = fimc_cap_s_fmt, + .vidioc_g_fmt_vid_cap = fimc_vidioc_g_fmt, + + .vidioc_reqbufs = fimc_cap_reqbufs, + .vidioc_querybuf = fimc_cap_querybuf, + + .vidioc_qbuf = fimc_cap_qbuf, + .vidioc_dqbuf = fimc_cap_dqbuf, + + .vidioc_streamon = fimc_cap_streamon, + .vidioc_streamoff = fimc_cap_streamoff, + + .vidioc_queryctrl = fimc_vidioc_queryctrl, + .vidioc_g_ctrl = fimc_vidioc_g_ctrl, + .vidioc_s_ctrl = fimc_cap_s_ctrl, + + .vidioc_g_crop = fimc_vidioc_g_crop, + .vidioc_s_crop = fimc_cap_s_crop, + .vidioc_cropcap = fimc_vidioc_cropcap, + + .vidioc_enum_input = fimc_cap_enum_input, + .vidioc_s_input = fimc_cap_s_input, + .vidioc_g_input = fimc_cap_g_input, +}; + +int fimc_register_capture_device(struct fimc_dev *fimc) +{ + struct v4l2_device *v4l2_dev = &fimc->vid_cap.v4l2_dev; + struct video_device *vfd; + struct fimc_vid_cap *vid_cap; + struct fimc_ctx *ctx; + struct v4l2_format f; + int ret; + + ctx = kzalloc(sizeof *ctx, GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->fimc_dev = fimc; + ctx->in_path = FIMC_CAMERA; + ctx->out_path = FIMC_DMA; + ctx->state = FIMC_CTX_CAP; + + f.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24; + ctx->d_frame.fmt = find_format(&f, FMT_FLAGS_M2M); + + if (!v4l2_dev->name[0]) + snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), + "%s.capture", dev_name(&fimc->pdev->dev)); + + ret = v4l2_device_register(NULL, v4l2_dev); + if (ret) + goto err_info; + + vfd = video_device_alloc(); + if (!vfd) { + v4l2_err(v4l2_dev, "Failed to allocate video device\n"); + goto err_v4l2_reg; + } + + snprintf(vfd->name, sizeof(vfd->name), "%s:cap", + dev_name(&fimc->pdev->dev)); + + vfd->fops = &fimc_capture_fops; + vfd->ioctl_ops = &fimc_capture_ioctl_ops; + vfd->minor = -1; + vfd->release = video_device_release; + video_set_drvdata(vfd, fimc); + + vid_cap = &fimc->vid_cap; + vid_cap->vfd = vfd; + vid_cap->active_buf_cnt = 0; + vid_cap->reqbufs_count = 0; + vid_cap->refcnt = 0; + /* The default color format for image sensor. */ + vid_cap->fmt.code = V4L2_MBUS_FMT_YUYV8_2X8; + + INIT_LIST_HEAD(&vid_cap->pending_buf_q); + INIT_LIST_HEAD(&vid_cap->active_buf_q); + spin_lock_init(&ctx->slock); + vid_cap->ctx = ctx; + + videobuf_queue_dma_contig_init(&vid_cap->vbq, &fimc_qops, + vid_cap->v4l2_dev.dev, &fimc->irqlock, + V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, + sizeof(struct fimc_vid_buffer), (void *)ctx); + + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1); + if (ret) { + v4l2_err(v4l2_dev, "Failed to register video device\n"); + goto err_vd_reg; + } + + v4l2_info(v4l2_dev, + "FIMC capture driver registered as /dev/video%d\n", + vfd->num); + + return 0; + +err_vd_reg: + video_device_release(vfd); +err_v4l2_reg: + v4l2_device_unregister(v4l2_dev); +err_info: + dev_err(&fimc->pdev->dev, "failed to install\n"); + return ret; +} + +void fimc_unregister_capture_device(struct fimc_dev *fimc) +{ + struct fimc_vid_cap *capture = &fimc->vid_cap; + + if (capture->vfd) + video_unregister_device(capture->vfd); + + kfree(capture->ctx); +} diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c index 23cc054bd7b1..5168a9a5d821 100644 --- a/drivers/media/video/s5p-fimc/fimc-core.c +++ b/drivers/media/video/s5p-fimc/fimc-core.c @@ -1,7 +1,7 @@ /* * S5P camera interface (video postprocessor) driver * - * Copyright (c) 2010 Samsung Electronics + * Copyright (c) 2010 Samsung Electronics Co., Ltd * * Sylwester Nawrocki, * @@ -38,85 +38,102 @@ static struct fimc_fmt fimc_formats[] = { .depth = 16, .color = S5P_FIMC_RGB565, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_BE, + .flags = FMT_FLAGS_M2M, }, { .name = "BGR666", .fourcc = V4L2_PIX_FMT_BGR666, .depth = 32, .color = S5P_FIMC_RGB666, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .flags = FMT_FLAGS_M2M, }, { .name = "XRGB-8-8-8-8, 24 bpp", .fourcc = V4L2_PIX_FMT_RGB24, .depth = 32, .color = S5P_FIMC_RGB888, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .flags = FMT_FLAGS_M2M, }, { .name = "YUV 4:2:2 packed, YCbYCr", .fourcc = V4L2_PIX_FMT_YUYV, .depth = 16, .color = S5P_FIMC_YCBYCR422, .buff_cnt = 1, - .planes_cnt = 1 - }, { + .planes_cnt = 1, + .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8, + .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, + }, { .name = "YUV 4:2:2 packed, CbYCrY", .fourcc = V4L2_PIX_FMT_UYVY, .depth = 16, .color = S5P_FIMC_CBYCRY422, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8, + .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, }, { .name = "YUV 4:2:2 packed, CrYCbY", .fourcc = V4L2_PIX_FMT_VYUY, .depth = 16, .color = S5P_FIMC_CRYCBY422, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8, + .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, }, { .name = "YUV 4:2:2 packed, YCrYCb", .fourcc = V4L2_PIX_FMT_YVYU, .depth = 16, .color = S5P_FIMC_YCRYCB422, .buff_cnt = 1, - .planes_cnt = 1 + .planes_cnt = 1, + .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8, + .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, }, { .name = "YUV 4:2:2 planar, Y/Cb/Cr", .fourcc = V4L2_PIX_FMT_YUV422P, .depth = 12, .color = S5P_FIMC_YCBCR422, .buff_cnt = 1, - .planes_cnt = 3 + .planes_cnt = 3, + .flags = FMT_FLAGS_M2M, }, { .name = "YUV 4:2:2 planar, Y/CbCr", .fourcc = V4L2_PIX_FMT_NV16, .depth = 16, .color = S5P_FIMC_YCBCR422, .buff_cnt = 1, - .planes_cnt = 2 + .planes_cnt = 2, + .flags = FMT_FLAGS_M2M, }, { .name = "YUV 4:2:2 planar, Y/CrCb", .fourcc = V4L2_PIX_FMT_NV61, .depth = 16, .color = S5P_FIMC_RGB565, .buff_cnt = 1, - .planes_cnt = 2 + .planes_cnt = 2, + .flags = FMT_FLAGS_M2M, }, { .name = "YUV 4:2:0 planar, YCbCr", .fourcc = V4L2_PIX_FMT_YUV420, .depth = 12, .color = S5P_FIMC_YCBCR420, .buff_cnt = 1, - .planes_cnt = 3 + .planes_cnt = 3, + .flags = FMT_FLAGS_M2M, }, { .name = "YUV 4:2:0 planar, Y/CbCr", .fourcc = V4L2_PIX_FMT_NV12, .depth = 12, .color = S5P_FIMC_YCBCR420, .buff_cnt = 1, - .planes_cnt = 2 - } + .planes_cnt = 2, + .flags = FMT_FLAGS_M2M, + }, }; static struct v4l2_queryctrl fimc_ctrls[] = { @@ -156,7 +173,7 @@ static struct v4l2_queryctrl *get_ctrl(int id) return NULL; } -static int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f) +int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f) { if (r->width > f->width) { if (f->width > (r->width * SCALER_MAX_HRATIO)) @@ -199,7 +216,7 @@ static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift) return 0; } -static int fimc_set_scaler_info(struct fimc_ctx *ctx) +int fimc_set_scaler_info(struct fimc_ctx *ctx) { struct fimc_scaler *sc = &ctx->scaler; struct fimc_frame *s_frame = &ctx->s_frame; @@ -259,6 +276,51 @@ static int fimc_set_scaler_info(struct fimc_ctx *ctx) return 0; } +static void fimc_capture_handler(struct fimc_dev *fimc) +{ + struct fimc_vid_cap *cap = &fimc->vid_cap; + struct fimc_vid_buffer *v_buf = NULL; + + if (!list_empty(&cap->active_buf_q)) { + v_buf = active_queue_pop(cap); + fimc_buf_finish(fimc, v_buf); + } + + if (test_and_clear_bit(ST_CAPT_SHUT, &fimc->state)) { + wake_up(&fimc->irq_queue); + return; + } + + if (!list_empty(&cap->pending_buf_q)) { + + v_buf = pending_queue_pop(cap); + fimc_hw_set_output_addr(fimc, &v_buf->paddr, cap->buf_index); + v_buf->index = cap->buf_index; + + dbg("hw ptr: %d, sw ptr: %d", + fimc_hw_get_frame_index(fimc), cap->buf_index); + + spin_lock(&fimc->irqlock); + v_buf->vb.state = VIDEOBUF_ACTIVE; + spin_unlock(&fimc->irqlock); + + /* Move the buffer to the capture active queue */ + active_queue_add(cap, v_buf); + + dbg("next frame: %d, done frame: %d", + fimc_hw_get_frame_index(fimc), v_buf->index); + + if (++cap->buf_index >= FIMC_MAX_OUT_BUFS) + cap->buf_index = 0; + + } else if (test_and_clear_bit(ST_CAPT_STREAM, &fimc->state) && + cap->active_buf_cnt <= 1) { + fimc_deactivate_capture(fimc); + } + + dbg("frame: %d, active_buf_cnt= %d", + fimc_hw_get_frame_index(fimc), cap->active_buf_cnt); +} static irqreturn_t fimc_isr(int irq, void *priv) { @@ -285,6 +347,16 @@ static irqreturn_t fimc_isr(int irq, void *priv) spin_unlock(&fimc->irqlock); v4l2_m2m_job_finish(fimc->m2m.m2m_dev, ctx->m2m_ctx); } + goto isr_unlock; + + } + + if (test_bit(ST_CAPT_RUN, &fimc->state)) + fimc_capture_handler(fimc); + + if (test_and_clear_bit(ST_CAPT_PEND, &fimc->state)) { + set_bit(ST_CAPT_RUN, &fimc->state); + wake_up(&fimc->irq_queue); } isr_unlock: @@ -424,7 +496,7 @@ static void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f) * * Return: 0 if dimensions are valid or non zero otherwise. */ -static int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags) +int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags) { struct fimc_frame *s_frame, *d_frame; struct fimc_vid_buffer *buf = NULL; @@ -513,9 +585,9 @@ static void fimc_dma_run(void *priv) if (ctx->state & FIMC_PARAMS) fimc_hw_set_out_dma(ctx); - ctx->state = 0; fimc_activate_capture(ctx); + ctx->state &= (FIMC_CTX_M2M | FIMC_CTX_CAP); fimc_hw_activate_input_dma(fimc, true); dma_unlock: @@ -598,10 +670,31 @@ static void fimc_buf_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) { struct fimc_ctx *ctx = vq->priv_data; - v4l2_m2m_buf_queue(ctx->m2m_ctx, vq, vb); + struct fimc_dev *fimc = ctx->fimc_dev; + struct fimc_vid_cap *cap = &fimc->vid_cap; + unsigned long flags; + + dbg("ctx: %p, ctx->state: 0x%x", ctx, ctx->state); + + if ((ctx->state & FIMC_CTX_M2M) && ctx->m2m_ctx) { + v4l2_m2m_buf_queue(ctx->m2m_ctx, vq, vb); + } else if (ctx->state & FIMC_CTX_CAP) { + spin_lock_irqsave(&fimc->slock, flags); + fimc_vid_cap_buf_queue(fimc, (struct fimc_vid_buffer *)vb); + + dbg("fimc->cap.active_buf_cnt: %d", + fimc->vid_cap.active_buf_cnt); + + if (cap->active_buf_cnt >= cap->reqbufs_count || + cap->active_buf_cnt >= FIMC_MAX_OUT_BUFS) { + if (!test_and_set_bit(ST_CAPT_STREAM, &fimc->state)) + fimc_activate_capture(ctx); + } + spin_unlock_irqrestore(&fimc->slock, flags); + } } -static struct videobuf_queue_ops fimc_qops = { +struct videobuf_queue_ops fimc_qops = { .buf_setup = fimc_buf_setup, .buf_prepare = fimc_buf_prepare, .buf_queue = fimc_buf_queue, @@ -624,7 +717,7 @@ static int fimc_m2m_querycap(struct file *file, void *priv, return 0; } -static int fimc_m2m_enum_fmt(struct file *file, void *priv, +int fimc_vidioc_enum_fmt(struct file *file, void *priv, struct v4l2_fmtdesc *f) { struct fimc_fmt *fmt; @@ -635,109 +728,139 @@ static int fimc_m2m_enum_fmt(struct file *file, void *priv, fmt = &fimc_formats[f->index]; strncpy(f->description, fmt->name, sizeof(f->description) - 1); f->pixelformat = fmt->fourcc; + return 0; } -static int fimc_m2m_g_fmt(struct file *file, void *priv, struct v4l2_format *f) +int fimc_vidioc_g_fmt(struct file *file, void *priv, struct v4l2_format *f) { struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; struct fimc_frame *frame; frame = ctx_get_frame(ctx, f->type); if (IS_ERR(frame)) return PTR_ERR(frame); + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + f->fmt.pix.width = frame->width; f->fmt.pix.height = frame->height; f->fmt.pix.field = V4L2_FIELD_NONE; f->fmt.pix.pixelformat = frame->fmt->fourcc; + mutex_unlock(&fimc->lock); return 0; } -static struct fimc_fmt *find_format(struct v4l2_format *f) +struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask) { struct fimc_fmt *fmt; unsigned int i; for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) { fmt = &fimc_formats[i]; - if (fmt->fourcc == f->fmt.pix.pixelformat) + if (fmt->fourcc == f->fmt.pix.pixelformat && + (fmt->flags & mask)) break; } - if (i == ARRAY_SIZE(fimc_formats)) - return NULL; - return fmt; + return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt; } -static int fimc_m2m_try_fmt(struct file *file, void *priv, - struct v4l2_format *f) +struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f, + unsigned int mask) { struct fimc_fmt *fmt; - u32 max_width, max_height, mod_x, mod_y; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) { + fmt = &fimc_formats[i]; + if (fmt->mbus_code == f->code && (fmt->flags & mask)) + break; + } + + return (i == ARRAY_SIZE(fimc_formats)) ? NULL : fmt; +} + + +int fimc_vidioc_try_fmt(struct file *file, void *priv, struct v4l2_format *f) +{ struct fimc_ctx *ctx = priv; struct fimc_dev *fimc = ctx->fimc_dev; - struct v4l2_pix_format *pix = &f->fmt.pix; struct samsung_fimc_variant *variant = fimc->variant; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct fimc_fmt *fmt; + u32 max_width, mod_x, mod_y, mask; + int ret = -EINVAL, is_output = 0; - fmt = find_format(f); - if (!fmt) { - v4l2_err(&fimc->m2m.v4l2_dev, - "Fourcc format (0x%X) invalid.\n", pix->pixelformat); + if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + if (ctx->state & FIMC_CTX_CAP) + return -EINVAL; + is_output = 1; + } else if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { return -EINVAL; } + dbg("w: %d, h: %d, bpl: %d", + pix->width, pix->height, pix->bytesperline); + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + mask = is_output ? FMT_FLAGS_M2M : FMT_FLAGS_M2M | FMT_FLAGS_CAM; + fmt = find_format(f, mask); + if (!fmt) { + v4l2_err(&fimc->m2m.v4l2_dev, "Fourcc format (0x%X) invalid.\n", + pix->pixelformat); + goto tf_out; + } + if (pix->field == V4L2_FIELD_ANY) pix->field = V4L2_FIELD_NONE; else if (V4L2_FIELD_NONE != pix->field) - return -EINVAL; + goto tf_out; - if (f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) { + if (is_output) { max_width = variant->scaler_dis_w; - max_height = variant->scaler_dis_w; - mod_x = variant->min_inp_pixsize; - mod_y = variant->min_inp_pixsize; - } else if (f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { - max_width = variant->out_rot_dis_w; - max_height = variant->out_rot_dis_w; - mod_x = variant->min_out_pixsize; - mod_y = variant->min_out_pixsize; + mod_x = ffs(variant->min_inp_pixsize) - 1; } else { - err("Wrong stream type (%d)", f->type); - return -EINVAL; + max_width = variant->out_rot_dis_w; + mod_x = ffs(variant->min_out_pixsize) - 1; } - dbg("max_w= %d, max_h= %d", max_width, max_height); - - if (pix->height > max_height) - pix->height = max_height; - if (pix->width > max_width) - pix->width = max_width; - if (tiled_fmt(fmt)) { - mod_x = 64; /* 64x32 tile */ - mod_y = 32; + mod_x = 6; /* 64 x 32 pixels tile */ + mod_y = 5; + } else { + if (fimc->id == 1 && fimc->variant->pix_hoff) + mod_y = fimc_fmt_is_rgb(fmt->color) ? 0 : 1; + else + mod_y = mod_x; } - dbg("mod_x= 0x%X, mod_y= 0x%X", mod_x, mod_y); + dbg("mod_x: %d, mod_y: %d, max_w: %d", mod_x, mod_y, max_width); - pix->width = (pix->width == 0) ? mod_x : ALIGN(pix->width, mod_x); - pix->height = (pix->height == 0) ? mod_y : ALIGN(pix->height, mod_y); + v4l_bound_align_image(&pix->width, 16, max_width, mod_x, + &pix->height, 8, variant->scaler_dis_w, mod_y, 0); if (pix->bytesperline == 0 || - pix->bytesperline * 8 / fmt->depth > pix->width) + (pix->bytesperline * 8 / fmt->depth) > pix->width) pix->bytesperline = (pix->width * fmt->depth) >> 3; if (pix->sizeimage == 0) pix->sizeimage = pix->height * pix->bytesperline; - dbg("pix->bytesperline= %d, fmt->depth= %d", - pix->bytesperline, fmt->depth); + dbg("w: %d, h: %d, bpl: %d, depth: %d", + pix->width, pix->height, pix->bytesperline, fmt->depth); - return 0; -} + ret = 0; +tf_out: + mutex_unlock(&fimc->lock); + return ret; +} static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f) { @@ -750,9 +873,7 @@ static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f) unsigned long flags; int ret = 0; - BUG_ON(!ctx); - - ret = fimc_m2m_try_fmt(file, priv, f); + ret = fimc_vidioc_try_fmt(file, priv, f); if (ret) return ret; @@ -785,7 +906,7 @@ static int fimc_m2m_s_fmt(struct file *file, void *priv, struct v4l2_format *f) spin_unlock_irqrestore(&ctx->slock, flags); pix = &f->fmt.pix; - frame->fmt = find_format(f); + frame->fmt = find_format(f, FMT_FLAGS_M2M); if (!frame->fmt) { ret = -EINVAL; goto sf_out; @@ -857,21 +978,33 @@ static int fimc_m2m_streamoff(struct file *file, void *priv, return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type); } -int fimc_m2m_queryctrl(struct file *file, void *priv, +int fimc_vidioc_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *qc) { + struct fimc_ctx *ctx = priv; struct v4l2_queryctrl *c; + c = get_ctrl(qc->id); - if (!c) - return -EINVAL; - *qc = *c; - return 0; + if (c) { + *qc = *c; + return 0; + } + + if (ctx->state & FIMC_CTX_CAP) + return v4l2_subdev_call(ctx->fimc_dev->vid_cap.sd, + core, queryctrl, qc); + return -EINVAL; } -int fimc_m2m_g_ctrl(struct file *file, void *priv, +int fimc_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctrl) { struct fimc_ctx *ctx = priv; + struct fimc_dev *fimc = ctx->fimc_dev; + int ret = 0; + + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; switch (ctrl->id) { case V4L2_CID_HFLIP: @@ -884,15 +1017,22 @@ int fimc_m2m_g_ctrl(struct file *file, void *priv, ctrl->value = ctx->rotation; break; default: - v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n"); - return -EINVAL; + if (ctx->state & FIMC_CTX_CAP) { + ret = v4l2_subdev_call(fimc->vid_cap.sd, core, + g_ctrl, ctrl); + } else { + v4l2_err(&fimc->m2m.v4l2_dev, + "Invalid control\n"); + ret = -EINVAL; + } } dbg("ctrl->value= %d", ctrl->value); - return 0; + + mutex_unlock(&fimc->lock); + return ret; } -static int check_ctrl_val(struct fimc_ctx *ctx, - struct v4l2_control *ctrl) +int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl) { struct v4l2_queryctrl *c; c = get_ctrl(ctrl->id); @@ -909,22 +1049,23 @@ static int check_ctrl_val(struct fimc_ctx *ctx, return 0; } -int fimc_m2m_s_ctrl(struct file *file, void *priv, - struct v4l2_control *ctrl) +int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl) { - struct fimc_ctx *ctx = priv; struct samsung_fimc_variant *variant = ctx->fimc_dev->variant; + struct fimc_dev *fimc = ctx->fimc_dev; unsigned long flags; - int ret = 0; - ret = check_ctrl_val(ctx, ctrl); - if (ret) - return ret; + if (ctx->rotation != 0 && + (ctrl->id == V4L2_CID_HFLIP || ctrl->id == V4L2_CID_VFLIP)) { + v4l2_err(&fimc->m2m.v4l2_dev, + "Simultaneous flip and rotation is not supported\n"); + return -EINVAL; + } + + spin_lock_irqsave(&ctx->slock, flags); switch (ctrl->id) { case V4L2_CID_HFLIP: - if (ctx->rotation != 0) - return 0; if (ctrl->value) ctx->flip |= FLIP_X_AXIS; else @@ -932,8 +1073,6 @@ int fimc_m2m_s_ctrl(struct file *file, void *priv, break; case V4L2_CID_VFLIP: - if (ctx->rotation != 0) - return 0; if (ctrl->value) ctx->flip |= FLIP_Y_AXIS; else @@ -941,77 +1080,95 @@ int fimc_m2m_s_ctrl(struct file *file, void *priv, break; case V4L2_CID_ROTATE: - if (ctrl->value == 90 || ctrl->value == 270) { - if (ctx->out_path == FIMC_LCDFIFO && - !variant->has_inp_rot) { - return -EINVAL; - } else if (ctx->in_path == FIMC_DMA && - !variant->has_out_rot) { - return -EINVAL; - } + /* Check for the output rotator availability */ + if ((ctrl->value == 90 || ctrl->value == 270) && + (ctx->in_path == FIMC_DMA && !variant->has_out_rot)) { + spin_unlock_irqrestore(&ctx->slock, flags); + return -EINVAL; + } else { + ctx->rotation = ctrl->value; } - ctx->rotation = ctrl->value; - if (ctrl->value == 180) - ctx->flip = FLIP_XY_AXIS; break; default: - v4l2_err(&ctx->fimc_dev->m2m.v4l2_dev, "Invalid control\n"); + spin_unlock_irqrestore(&ctx->slock, flags); + v4l2_err(&fimc->m2m.v4l2_dev, "Invalid control\n"); return -EINVAL; } - spin_lock_irqsave(&ctx->slock, flags); ctx->state |= FIMC_PARAMS; spin_unlock_irqrestore(&ctx->slock, flags); + return 0; } +static int fimc_m2m_s_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct fimc_ctx *ctx = priv; + int ret = 0; + + ret = check_ctrl_val(ctx, ctrl); + if (ret) + return ret; + + ret = fimc_s_ctrl(ctx, ctrl); + return 0; +} -static int fimc_m2m_cropcap(struct file *file, void *fh, - struct v4l2_cropcap *cr) +int fimc_vidioc_cropcap(struct file *file, void *fh, + struct v4l2_cropcap *cr) { struct fimc_frame *frame; struct fimc_ctx *ctx = fh; + struct fimc_dev *fimc = ctx->fimc_dev; frame = ctx_get_frame(ctx, cr->type); if (IS_ERR(frame)) return PTR_ERR(frame); - cr->bounds.left = 0; - cr->bounds.top = 0; - cr->bounds.width = frame->f_width; - cr->bounds.height = frame->f_height; - cr->defrect.left = frame->offs_h; - cr->defrect.top = frame->offs_v; - cr->defrect.width = frame->o_width; - cr->defrect.height = frame->o_height; + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + cr->bounds.left = 0; + cr->bounds.top = 0; + cr->bounds.width = frame->f_width; + cr->bounds.height = frame->f_height; + cr->defrect = cr->bounds; + + mutex_unlock(&fimc->lock); return 0; } -static int fimc_m2m_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) +int fimc_vidioc_g_crop(struct file *file, void *fh, struct v4l2_crop *cr) { struct fimc_frame *frame; struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; frame = ctx_get_frame(ctx, cr->type); if (IS_ERR(frame)) return PTR_ERR(frame); + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + cr->c.left = frame->offs_h; cr->c.top = frame->offs_v; cr->c.width = frame->width; cr->c.height = frame->height; + mutex_unlock(&fimc->lock); return 0; } -static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) +int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr) { - struct fimc_ctx *ctx = file->private_data; struct fimc_dev *fimc = ctx->fimc_dev; - unsigned long flags; struct fimc_frame *f; - u32 min_size; - int ret = 0; + u32 min_size, halign; + + f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ? + &ctx->s_frame : &ctx->d_frame; if (cr->c.top < 0 || cr->c.left < 0) { v4l2_err(&fimc->m2m.v4l2_dev, @@ -1019,66 +1176,98 @@ static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) return -EINVAL; } - if (cr->c.width <= 0 || cr->c.height <= 0) { - v4l2_err(&fimc->m2m.v4l2_dev, - "crop width and height must be greater than 0\n"); - return -EINVAL; - } - f = ctx_get_frame(ctx, cr->type); if (IS_ERR(f)) return PTR_ERR(f); - /* Adjust to required pixel boundary. */ - min_size = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ? - fimc->variant->min_inp_pixsize : fimc->variant->min_out_pixsize; + min_size = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) + ? fimc->variant->min_inp_pixsize + : fimc->variant->min_out_pixsize; - cr->c.width = round_down(cr->c.width, min_size); - cr->c.height = round_down(cr->c.height, min_size); - cr->c.left = round_down(cr->c.left + 1, min_size); - cr->c.top = round_down(cr->c.top + 1, min_size); - - if ((cr->c.left + cr->c.width > f->o_width) - || (cr->c.top + cr->c.height > f->o_height)) { - v4l2_err(&fimc->m2m.v4l2_dev, "Error in S_CROP params\n"); - return -EINVAL; + if (ctx->state & FIMC_CTX_M2M) { + if (fimc->id == 1 && fimc->variant->pix_hoff) + halign = fimc_fmt_is_rgb(f->fmt->color) ? 0 : 1; + else + halign = ffs(min_size) - 1; + /* there are more strict aligment requirements at camera interface */ + } else { + min_size = 16; + halign = 4; } + v4l_bound_align_image(&cr->c.width, min_size, f->o_width, + ffs(min_size) - 1, + &cr->c.height, min_size, f->o_height, + halign, 64/(ALIGN(f->fmt->depth, 8))); + + /* adjust left/top if cropping rectangle is out of bounds */ + if (cr->c.left + cr->c.width > f->o_width) + cr->c.left = f->o_width - cr->c.width; + if (cr->c.top + cr->c.height > f->o_height) + cr->c.top = f->o_height - cr->c.height; + + cr->c.left = round_down(cr->c.left, min_size); + cr->c.top = round_down(cr->c.top, + ctx->state & FIMC_CTX_M2M ? 8 : 16); + + dbg("l:%d, t:%d, w:%d, h:%d, f_w: %d, f_h: %d", + cr->c.left, cr->c.top, cr->c.width, cr->c.height, + f->f_width, f->f_height); + + return 0; +} + + +static int fimc_m2m_s_crop(struct file *file, void *fh, struct v4l2_crop *cr) +{ + struct fimc_ctx *ctx = file->private_data; + struct fimc_dev *fimc = ctx->fimc_dev; + unsigned long flags; + struct fimc_frame *f; + int ret; + + ret = fimc_try_crop(ctx, cr); + if (ret) + return ret; + + f = (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ? + &ctx->s_frame : &ctx->d_frame; + spin_lock_irqsave(&ctx->slock, flags); - if ((ctx->state & FIMC_SRC_FMT) && (ctx->state & FIMC_DST_FMT)) { - /* Check for the pixel scaling ratio when cropping input img. */ + if (~ctx->state & (FIMC_SRC_FMT | FIMC_DST_FMT)) { + /* Check to see if scaling ratio is within supported range */ if (cr->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) ret = fimc_check_scaler_ratio(&cr->c, &ctx->d_frame); - else if (cr->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + else ret = fimc_check_scaler_ratio(&cr->c, &ctx->s_frame); - if (ret) { spin_unlock_irqrestore(&ctx->slock, flags); - v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range"); + v4l2_err(&fimc->m2m.v4l2_dev, "Out of scaler range"); return -EINVAL; } } ctx->state |= FIMC_PARAMS; - spin_unlock_irqrestore(&ctx->slock, flags); f->offs_h = cr->c.left; f->offs_v = cr->c.top; - f->width = cr->c.width; + f->width = cr->c.width; f->height = cr->c.height; + + spin_unlock_irqrestore(&ctx->slock, flags); return 0; } static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = { .vidioc_querycap = fimc_m2m_querycap, - .vidioc_enum_fmt_vid_cap = fimc_m2m_enum_fmt, - .vidioc_enum_fmt_vid_out = fimc_m2m_enum_fmt, + .vidioc_enum_fmt_vid_cap = fimc_vidioc_enum_fmt, + .vidioc_enum_fmt_vid_out = fimc_vidioc_enum_fmt, - .vidioc_g_fmt_vid_cap = fimc_m2m_g_fmt, - .vidioc_g_fmt_vid_out = fimc_m2m_g_fmt, + .vidioc_g_fmt_vid_cap = fimc_vidioc_g_fmt, + .vidioc_g_fmt_vid_out = fimc_vidioc_g_fmt, - .vidioc_try_fmt_vid_cap = fimc_m2m_try_fmt, - .vidioc_try_fmt_vid_out = fimc_m2m_try_fmt, + .vidioc_try_fmt_vid_cap = fimc_vidioc_try_fmt, + .vidioc_try_fmt_vid_out = fimc_vidioc_try_fmt, .vidioc_s_fmt_vid_cap = fimc_m2m_s_fmt, .vidioc_s_fmt_vid_out = fimc_m2m_s_fmt, @@ -1092,13 +1281,13 @@ static const struct v4l2_ioctl_ops fimc_m2m_ioctl_ops = { .vidioc_streamon = fimc_m2m_streamon, .vidioc_streamoff = fimc_m2m_streamoff, - .vidioc_queryctrl = fimc_m2m_queryctrl, - .vidioc_g_ctrl = fimc_m2m_g_ctrl, + .vidioc_queryctrl = fimc_vidioc_queryctrl, + .vidioc_g_ctrl = fimc_vidioc_g_ctrl, .vidioc_s_ctrl = fimc_m2m_s_ctrl, - .vidioc_g_crop = fimc_m2m_g_crop, + .vidioc_g_crop = fimc_vidioc_g_crop, .vidioc_s_crop = fimc_m2m_s_crop, - .vidioc_cropcap = fimc_m2m_cropcap + .vidioc_cropcap = fimc_vidioc_cropcap }; @@ -1120,11 +1309,23 @@ static int fimc_m2m_open(struct file *file) struct fimc_ctx *ctx = NULL; int err = 0; - mutex_lock(&fimc->lock); + if (mutex_lock_interruptible(&fimc->lock)) + return -ERESTARTSYS; + + dbg("pid: %d, state: 0x%lx, refcnt: %d", + task_pid_nr(current), fimc->state, fimc->vid_cap.refcnt); + + /* + * Return if the corresponding video capture node + * is already opened. + */ + if (fimc->vid_cap.refcnt > 0) { + mutex_unlock(&fimc->lock); + return -EBUSY; + } + fimc->m2m.refcnt++; set_bit(ST_OUTDMA_RUN, &fimc->state); - mutex_unlock(&fimc->lock); - ctx = kzalloc(sizeof *ctx, GFP_KERNEL); if (!ctx) @@ -1135,8 +1336,8 @@ static int fimc_m2m_open(struct file *file) /* Default color format */ ctx->s_frame.fmt = &fimc_formats[0]; ctx->d_frame.fmt = &fimc_formats[0]; - /* per user process device context initialization */ - ctx->state = 0; + /* Setup the device context for mem2mem mode. */ + ctx->state = FIMC_CTX_M2M; ctx->flags = 0; ctx->in_path = FIMC_DMA; ctx->out_path = FIMC_DMA; @@ -1147,6 +1348,8 @@ static int fimc_m2m_open(struct file *file) err = PTR_ERR(ctx->m2m_ctx); kfree(ctx); } + + mutex_unlock(&fimc->lock); return err; } @@ -1155,11 +1358,16 @@ static int fimc_m2m_release(struct file *file) struct fimc_ctx *ctx = file->private_data; struct fimc_dev *fimc = ctx->fimc_dev; + mutex_lock(&fimc->lock); + + dbg("pid: %d, state: 0x%lx, refcnt= %d", + task_pid_nr(current), fimc->state, fimc->m2m.refcnt); + v4l2_m2m_ctx_release(ctx->m2m_ctx); kfree(ctx); - mutex_lock(&fimc->lock); if (--fimc->m2m.refcnt <= 0) clear_bit(ST_OUTDMA_RUN, &fimc->state); + mutex_unlock(&fimc->lock); return 0; } @@ -1168,6 +1376,7 @@ static unsigned int fimc_m2m_poll(struct file *file, struct poll_table_struct *wait) { struct fimc_ctx *ctx = file->private_data; + return v4l2_m2m_poll(file, ctx->m2m_ctx, wait); } @@ -1175,6 +1384,7 @@ static unsigned int fimc_m2m_poll(struct file *file, static int fimc_m2m_mmap(struct file *file, struct vm_area_struct *vma) { struct fimc_ctx *ctx = file->private_data; + return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma); } @@ -1322,9 +1532,11 @@ static int fimc_probe(struct platform_device *pdev) fimc->id = pdev->id; fimc->variant = drv_data->variant[fimc->id]; fimc->pdev = pdev; + fimc->pdata = pdev->dev.platform_data; fimc->state = ST_IDLE; spin_lock_init(&fimc->irqlock); + init_waitqueue_head(&fimc->irq_queue); spin_lock_init(&fimc->slock); mutex_init(&fimc->lock); @@ -1354,6 +1566,7 @@ static int fimc_probe(struct platform_device *pdev) ret = fimc_clk_get(fimc); if (ret) goto err_regs_unmap; + clk_set_rate(fimc->clock[0], drv_data->lclk_frequency); res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (!res) { @@ -1375,11 +1588,27 @@ static int fimc_probe(struct platform_device *pdev) if (ret) goto err_irq; + /* At least one camera sensor is required to register capture node */ + if (fimc->pdata) { + int i; + for (i = 0; i < FIMC_MAX_CAMIF_CLIENTS; ++i) + if (fimc->pdata->isp_info[i]) + break; + + if (i < FIMC_MAX_CAMIF_CLIENTS) { + ret = fimc_register_capture_device(fimc); + if (ret) + goto err_m2m; + } + } + dev_dbg(&pdev->dev, "%s(): fimc-%d registered successfully\n", __func__, fimc->id); return 0; +err_m2m: + fimc_unregister_m2m_device(fimc); err_irq: free_irq(fimc->irq, fimc); err_clk: @@ -1404,6 +1633,8 @@ static int __devexit fimc_remove(struct platform_device *pdev) fimc_hw_reset(fimc); fimc_unregister_m2m_device(fimc); + fimc_unregister_capture_device(fimc); + fimc_clk_release(fimc); iounmap(fimc->regs); release_resource(fimc->regs_res); @@ -1474,7 +1705,8 @@ static struct samsung_fimc_driverdata fimc_drvdata_s5p = { [1] = &fimc01_variant_s5p, [2] = &fimc2_variant_s5p, }, - .devs_cnt = 3 + .devs_cnt = 3, + .lclk_frequency = 133000000UL, }; static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = { @@ -1483,7 +1715,8 @@ static struct samsung_fimc_driverdata fimc_drvdata_s5pv210 = { [1] = &fimc01_variant_s5pv210, [2] = &fimc2_variant_s5pv210, }, - .devs_cnt = 3 + .devs_cnt = 3, + .lclk_frequency = 166000000UL, }; static struct platform_device_id fimc_driver_ids[] = { @@ -1524,6 +1757,6 @@ static void __exit fimc_exit(void) module_init(fimc_init); module_exit(fimc_exit); -MODULE_AUTHOR("Sylwester Nawrocki, s.nawrocki@samsung.com"); -MODULE_DESCRIPTION("S3C/S5P FIMC (video postprocessor) driver"); +MODULE_AUTHOR("Sylwester Nawrocki "); +MODULE_DESCRIPTION("S5P FIMC camera host interface/video postprocessor driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/video/s5p-fimc/fimc-core.h b/drivers/media/video/s5p-fimc/fimc-core.h index 5aeb3efbd457..ce0a6b8a7d54 100644 --- a/drivers/media/video/s5p-fimc/fimc-core.h +++ b/drivers/media/video/s5p-fimc/fimc-core.h @@ -11,10 +11,14 @@ #ifndef FIMC_CORE_H_ #define FIMC_CORE_H_ +/*#define DEBUG*/ + #include #include #include #include +#include +#include #include #include "regs-fimc.h" @@ -28,6 +32,8 @@ #define dbg(fmt, args...) #endif +/* Time to wait for next frame VSYNC interrupt while stopping operation. */ +#define FIMC_SHUTDOWN_TIMEOUT ((100*HZ)/1000) #define NUM_FIMC_CLOCKS 2 #define MODULE_NAME "s5p-fimc" #define FIMC_MAX_DEVS 3 @@ -36,19 +42,41 @@ #define SCALER_MAX_VRATIO 64 #define DMA_MIN_SIZE 8 -enum { +/* FIMC device state flags */ +enum fimc_dev_flags { + /* for m2m node */ ST_IDLE, ST_OUTDMA_RUN, ST_M2M_PEND, + /* for capture node */ + ST_CAPT_PEND, + ST_CAPT_RUN, + ST_CAPT_STREAM, + ST_CAPT_SHUT, }; #define fimc_m2m_active(dev) test_bit(ST_OUTDMA_RUN, &(dev)->state) #define fimc_m2m_pending(dev) test_bit(ST_M2M_PEND, &(dev)->state) +#define fimc_capture_running(dev) test_bit(ST_CAPT_RUN, &(dev)->state) +#define fimc_capture_pending(dev) test_bit(ST_CAPT_PEND, &(dev)->state) + +#define fimc_capture_active(dev) \ + (test_bit(ST_CAPT_RUN, &(dev)->state) || \ + test_bit(ST_CAPT_PEND, &(dev)->state)) + +#define fimc_capture_streaming(dev) \ + test_bit(ST_CAPT_STREAM, &(dev)->state) + +#define fimc_buf_finish(dev, vid_buf) do { \ + spin_lock(&(dev)->irqlock); \ + (vid_buf)->vb.state = VIDEOBUF_DONE; \ + spin_unlock(&(dev)->irqlock); \ + wake_up(&(vid_buf)->vb.done); \ +} while (0) + enum fimc_datapath { - FIMC_ITU_CAM_A, - FIMC_ITU_CAM_B, - FIMC_MIPI_CAM, + FIMC_CAMERA, FIMC_DMA, FIMC_LCDFIFO, FIMC_WRITEBACK @@ -123,20 +151,25 @@ enum fimc_color_fmt { /** * struct fimc_fmt - the driver's internal color format data + * @mbus_code: Media Bus pixel code, -1 if not applicable * @name: format description - * @fourcc: the fourcc code for this format + * @fourcc: the fourcc code for this format, 0 if not applicable * @color: the corresponding fimc_color_fmt - * @depth: number of bits per pixel + * @depth: driver's private 'number of bits per pixel' * @buff_cnt: number of physically non-contiguous data planes * @planes_cnt: number of physically contiguous data planes */ struct fimc_fmt { + enum v4l2_mbus_pixelcode mbus_code; char *name; u32 fourcc; u32 color; - u32 depth; u16 buff_cnt; u16 planes_cnt; + u16 depth; + u16 flags; +#define FMT_FLAGS_CAM (1 << 0) +#define FMT_FLAGS_M2M (1 << 1) }; /** @@ -220,10 +253,14 @@ struct fimc_addr { /** * struct fimc_vid_buffer - the driver's video buffer - * @vb: v4l videobuf buffer + * @vb: v4l videobuf buffer + * @paddr: precalculated physical address set + * @index: buffer index for the output DMA engine */ struct fimc_vid_buffer { struct videobuf_buffer vb; + struct fimc_addr paddr; + int index; }; /** @@ -273,6 +310,40 @@ struct fimc_m2m_device { int refcnt; }; +/** + * struct fimc_vid_cap - camera capture device information + * @ctx: hardware context data + * @vfd: video device node for camera capture mode + * @v4l2_dev: v4l2_device struct to manage subdevs + * @sd: pointer to camera sensor subdevice currently in use + * @fmt: Media Bus format configured at selected image sensor + * @pending_buf_q: the pending buffer queue head + * @active_buf_q: the queue head of buffers scheduled in hardware + * @vbq: the capture am video buffer queue + * @active_buf_cnt: number of video buffers scheduled in hardware + * @buf_index: index for managing the output DMA buffers + * @frame_count: the frame counter for statistics + * @reqbufs_count: the number of buffers requested in REQBUFS ioctl + * @input_index: input (camera sensor) index + * @refcnt: driver's private reference counter + */ +struct fimc_vid_cap { + struct fimc_ctx *ctx; + struct video_device *vfd; + struct v4l2_device v4l2_dev; + struct v4l2_subdev *sd; + struct v4l2_mbus_framefmt fmt; + struct list_head pending_buf_q; + struct list_head active_buf_q; + struct videobuf_queue vbq; + int active_buf_cnt; + int buf_index; + unsigned int frame_count; + unsigned int reqbufs_count; + int input_index; + int refcnt; +}; + /** * struct samsung_fimc_variant - camera interface variant information * @@ -308,10 +379,12 @@ struct samsung_fimc_variant { * * @variant: the variant information for this driver. * @dev_cnt: number of fimc sub-devices available in SoC + * @lclk_frequency: fimc bus clock frequency */ struct samsung_fimc_driverdata { struct samsung_fimc_variant *variant[FIMC_MAX_DEVS]; - int devs_cnt; + unsigned long lclk_frequency; + int devs_cnt; }; struct fimc_ctx; @@ -322,19 +395,23 @@ struct fimc_ctx; * @slock: the spinlock protecting this data structure * @lock: the mutex protecting this data structure * @pdev: pointer to the FIMC platform device + * @pdata: pointer to the device platform data * @id: FIMC device index (0..2) * @clock[]: the clocks required for FIMC operation * @regs: the mapped hardware registers * @regs_res: the resource claimed for IO registers * @irq: interrupt number of the FIMC subdevice * @irqlock: spinlock protecting videobuffer queue + * @irq_queue: * @m2m: memory-to-memory V4L2 device information - * @state: the FIMC device state flags + * @vid_cap: camera capture device information + * @state: flags used to synchronize m2m and capture mode operation */ struct fimc_dev { spinlock_t slock; struct mutex lock; struct platform_device *pdev; + struct s3c_platform_fimc *pdata; struct samsung_fimc_variant *variant; int id; struct clk *clock[NUM_FIMC_CLOCKS]; @@ -342,7 +419,9 @@ struct fimc_dev { struct resource *regs_res; int irq; spinlock_t irqlock; + wait_queue_head_t irq_queue; struct fimc_m2m_device m2m; + struct fimc_vid_cap vid_cap; unsigned long state; }; @@ -387,6 +466,7 @@ struct fimc_ctx { struct v4l2_m2m_ctx *m2m_ctx; }; +extern struct videobuf_queue_ops fimc_qops; static inline int tiled_fmt(struct fimc_fmt *fmt) { @@ -433,7 +513,10 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx, struct fimc_frame *frame; if (V4L2_BUF_TYPE_VIDEO_OUTPUT == type) { - frame = &ctx->s_frame; + if (ctx->state & FIMC_CTX_M2M) + frame = &ctx->s_frame; + else + return ERR_PTR(-EINVAL); } else if (V4L2_BUF_TYPE_VIDEO_CAPTURE == type) { frame = &ctx->d_frame; } else { @@ -445,6 +528,13 @@ static inline struct fimc_frame *ctx_get_frame(struct fimc_ctx *ctx, return frame; } +static inline u32 fimc_hw_get_frame_index(struct fimc_dev *dev) +{ + u32 reg = readl(dev->regs + S5P_CISTATUS); + return (reg & S5P_CISTATUS_FRAMECNT_MASK) >> + S5P_CISTATUS_FRAMECNT_SHIFT; +} + /* -----------------------------------------------------*/ /* fimc-reg.c */ void fimc_hw_reset(struct fimc_dev *fimc); @@ -462,6 +552,52 @@ void fimc_hw_set_output_path(struct fimc_ctx *ctx); void fimc_hw_set_input_addr(struct fimc_dev *fimc, struct fimc_addr *paddr); void fimc_hw_set_output_addr(struct fimc_dev *fimc, struct fimc_addr *paddr, int index); +int fimc_hw_set_camera_source(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam); +int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f); +int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam); +int fimc_hw_set_camera_type(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam); + +/* -----------------------------------------------------*/ +/* fimc-core.c */ +int fimc_vidioc_enum_fmt(struct file *file, void *priv, + struct v4l2_fmtdesc *f); +int fimc_vidioc_g_fmt(struct file *file, void *priv, + struct v4l2_format *f); +int fimc_vidioc_try_fmt(struct file *file, void *priv, + struct v4l2_format *f); +int fimc_vidioc_g_crop(struct file *file, void *fh, + struct v4l2_crop *cr); +int fimc_vidioc_cropcap(struct file *file, void *fh, + struct v4l2_cropcap *cr); +int fimc_vidioc_queryctrl(struct file *file, void *priv, + struct v4l2_queryctrl *qc); +int fimc_vidioc_g_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl); + +int fimc_try_crop(struct fimc_ctx *ctx, struct v4l2_crop *cr); +int check_ctrl_val(struct fimc_ctx *ctx, struct v4l2_control *ctrl); +int fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_control *ctrl); + +struct fimc_fmt *find_format(struct v4l2_format *f, unsigned int mask); +struct fimc_fmt *find_mbus_format(struct v4l2_mbus_framefmt *f, + unsigned int mask); + +int fimc_check_scaler_ratio(struct v4l2_rect *r, struct fimc_frame *f); +int fimc_set_scaler_info(struct fimc_ctx *ctx); +int fimc_prepare_config(struct fimc_ctx *ctx, u32 flags); +int fimc_prepare_addr(struct fimc_ctx *ctx, struct fimc_vid_buffer *buf, + struct fimc_frame *frame, struct fimc_addr *paddr); + +/* -----------------------------------------------------*/ +/* fimc-capture.c */ +int fimc_register_capture_device(struct fimc_dev *fimc); +void fimc_unregister_capture_device(struct fimc_dev *fimc); +int fimc_sensor_sd_init(struct fimc_dev *fimc, int index); +int fimc_vid_cap_buf_queue(struct fimc_dev *fimc, + struct fimc_vid_buffer *fimc_vb); /* Locking: the caller holds fimc->slock */ static inline void fimc_activate_capture(struct fimc_ctx *ctx) @@ -478,4 +614,51 @@ static inline void fimc_deactivate_capture(struct fimc_dev *fimc) fimc_hw_en_lastirq(fimc, false); } +/* + * Add video buffer to the active buffers queue. + * The caller holds irqlock spinlock. + */ +static inline void active_queue_add(struct fimc_vid_cap *vid_cap, + struct fimc_vid_buffer *buf) +{ + buf->vb.state = VIDEOBUF_ACTIVE; + list_add_tail(&buf->vb.queue, &vid_cap->active_buf_q); + vid_cap->active_buf_cnt++; +} + +/* + * Pop a video buffer from the capture active buffers queue + * Locking: Need to be called with dev->slock held. + */ +static inline struct fimc_vid_buffer * +active_queue_pop(struct fimc_vid_cap *vid_cap) +{ + struct fimc_vid_buffer *buf; + buf = list_entry(vid_cap->active_buf_q.next, + struct fimc_vid_buffer, vb.queue); + list_del(&buf->vb.queue); + vid_cap->active_buf_cnt--; + return buf; +} + +/* Add video buffer to the capture pending buffers queue */ +static inline void fimc_pending_queue_add(struct fimc_vid_cap *vid_cap, + struct fimc_vid_buffer *buf) +{ + buf->vb.state = VIDEOBUF_QUEUED; + list_add_tail(&buf->vb.queue, &vid_cap->pending_buf_q); +} + +/* Add video buffer to the capture pending buffers queue */ +static inline struct fimc_vid_buffer * +pending_queue_pop(struct fimc_vid_cap *vid_cap) +{ + struct fimc_vid_buffer *buf; + buf = list_entry(vid_cap->pending_buf_q.next, + struct fimc_vid_buffer, vb.queue); + list_del(&buf->vb.queue); + return buf; +} + + #endif /* FIMC_CORE_H_ */ diff --git a/drivers/media/video/s5p-fimc/fimc-reg.c b/drivers/media/video/s5p-fimc/fimc-reg.c index 95adc8464693..511631a2e5c3 100644 --- a/drivers/media/video/s5p-fimc/fimc-reg.c +++ b/drivers/media/video/s5p-fimc/fimc-reg.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "fimc-core.h" @@ -176,6 +177,15 @@ static void fimc_hw_set_out_dma_size(struct fimc_ctx *ctx) cfg = S5P_ORIG_SIZE_HOR(frame->f_width); cfg |= S5P_ORIG_SIZE_VER(frame->f_height); writel(cfg, dev->regs + S5P_ORGOSIZE); + + /* Select color space conversion equation (HD/SD size).*/ + cfg = readl(dev->regs + S5P_CIGCTRL); + if (frame->f_width >= 1280) /* HD */ + cfg |= S5P_CIGCTRL_CSC_ITU601_709; + else /* SD */ + cfg &= ~S5P_CIGCTRL_CSC_ITU601_709; + writel(cfg, dev->regs + S5P_CIGCTRL); + } void fimc_hw_set_out_dma(struct fimc_ctx *ctx) @@ -231,19 +241,12 @@ static void fimc_hw_en_autoload(struct fimc_dev *dev, int enable) void fimc_hw_en_lastirq(struct fimc_dev *dev, int enable) { - unsigned long flags; - u32 cfg; - - spin_lock_irqsave(&dev->slock, flags); - - cfg = readl(dev->regs + S5P_CIOCTRL); + u32 cfg = readl(dev->regs + S5P_CIOCTRL); if (enable) cfg |= S5P_CIOCTRL_LASTIRQ_ENABLE; else cfg &= ~S5P_CIOCTRL_LASTIRQ_ENABLE; writel(cfg, dev->regs + S5P_CIOCTRL); - - spin_unlock_irqrestore(&dev->slock, flags); } static void fimc_hw_set_prescaler(struct fimc_ctx *ctx) @@ -325,14 +328,18 @@ void fimc_hw_set_scaler(struct fimc_ctx *ctx) void fimc_hw_en_capture(struct fimc_ctx *ctx) { struct fimc_dev *dev = ctx->fimc_dev; - u32 cfg; - cfg = readl(dev->regs + S5P_CIIMGCPT); - /* One shot mode for output DMA or freerun for FIFO. */ - if (ctx->out_path == FIMC_DMA) - cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE; - else - cfg &= ~S5P_CIIMGCPT_CPT_FREN_ENABLE; + u32 cfg = readl(dev->regs + S5P_CIIMGCPT); + + if (ctx->out_path == FIMC_DMA) { + /* one shot mode */ + cfg |= S5P_CIIMGCPT_CPT_FREN_ENABLE | S5P_CIIMGCPT_IMGCPTEN; + } else { + /* Continous frame capture mode (freerun). */ + cfg &= ~(S5P_CIIMGCPT_CPT_FREN_ENABLE | + S5P_CIIMGCPT_CPT_FRMOD_CNT); + cfg |= S5P_CIIMGCPT_IMGCPTEN; + } if (ctx->scaler.enabled) cfg |= S5P_CIIMGCPT_IMGCPTEN_SC; @@ -523,3 +530,139 @@ void fimc_hw_set_output_addr(struct fimc_dev *dev, i, paddr->y, paddr->cb, paddr->cr); } while (index == -1 && ++i < FIMC_MAX_OUT_BUFS); } + +int fimc_hw_set_camera_polarity(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam) +{ + u32 cfg = readl(fimc->regs + S5P_CIGCTRL); + + cfg &= ~(S5P_CIGCTRL_INVPOLPCLK | S5P_CIGCTRL_INVPOLVSYNC | + S5P_CIGCTRL_INVPOLHREF | S5P_CIGCTRL_INVPOLHSYNC); + + if (cam->flags & FIMC_CLK_INV_PCLK) + cfg |= S5P_CIGCTRL_INVPOLPCLK; + + if (cam->flags & FIMC_CLK_INV_VSYNC) + cfg |= S5P_CIGCTRL_INVPOLVSYNC; + + if (cam->flags & FIMC_CLK_INV_HREF) + cfg |= S5P_CIGCTRL_INVPOLHREF; + + if (cam->flags & FIMC_CLK_INV_HSYNC) + cfg |= S5P_CIGCTRL_INVPOLHSYNC; + + writel(cfg, fimc->regs + S5P_CIGCTRL); + + return 0; +} + +int fimc_hw_set_camera_source(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam) +{ + struct fimc_frame *f = &fimc->vid_cap.ctx->s_frame; + u32 cfg = 0; + + if (cam->bus_type == FIMC_ITU_601 || cam->bus_type == FIMC_ITU_656) { + + switch (fimc->vid_cap.fmt.code) { + case V4L2_MBUS_FMT_YUYV8_2X8: + cfg = S5P_CISRCFMT_ORDER422_YCBYCR; + break; + case V4L2_MBUS_FMT_YVYU8_2X8: + cfg = S5P_CISRCFMT_ORDER422_YCRYCB; + break; + case V4L2_MBUS_FMT_VYUY8_2X8: + cfg = S5P_CISRCFMT_ORDER422_CRYCBY; + break; + case V4L2_MBUS_FMT_UYVY8_2X8: + cfg = S5P_CISRCFMT_ORDER422_CBYCRY; + break; + default: + err("camera image format not supported: %d", + fimc->vid_cap.fmt.code); + return -EINVAL; + } + + if (cam->bus_type == FIMC_ITU_601) { + if (cam->bus_width == 8) { + cfg |= S5P_CISRCFMT_ITU601_8BIT; + } else if (cam->bus_width == 16) { + cfg |= S5P_CISRCFMT_ITU601_16BIT; + } else { + err("invalid bus width: %d", cam->bus_width); + return -EINVAL; + } + } /* else defaults to ITU-R BT.656 8-bit */ + } + + cfg |= S5P_CISRCFMT_HSIZE(f->o_width) | S5P_CISRCFMT_VSIZE(f->o_height); + writel(cfg, fimc->regs + S5P_CISRCFMT); + return 0; +} + + +int fimc_hw_set_camera_offset(struct fimc_dev *fimc, struct fimc_frame *f) +{ + u32 hoff2, voff2; + + u32 cfg = readl(fimc->regs + S5P_CIWDOFST); + + cfg &= ~(S5P_CIWDOFST_HOROFF_MASK | S5P_CIWDOFST_VEROFF_MASK); + cfg |= S5P_CIWDOFST_OFF_EN | + S5P_CIWDOFST_HOROFF(f->offs_h) | + S5P_CIWDOFST_VEROFF(f->offs_v); + + writel(cfg, fimc->regs + S5P_CIWDOFST); + + /* See CIWDOFSTn register description in the datasheet for details. */ + hoff2 = f->o_width - f->width - f->offs_h; + voff2 = f->o_height - f->height - f->offs_v; + cfg = S5P_CIWDOFST2_HOROFF(hoff2) | S5P_CIWDOFST2_VEROFF(voff2); + + writel(cfg, fimc->regs + S5P_CIWDOFST2); + return 0; +} + +int fimc_hw_set_camera_type(struct fimc_dev *fimc, + struct s3c_fimc_isp_info *cam) +{ + u32 cfg, tmp; + struct fimc_vid_cap *vid_cap = &fimc->vid_cap; + + cfg = readl(fimc->regs + S5P_CIGCTRL); + + /* Select ITU B interface, disable Writeback path and test pattern. */ + cfg &= ~(S5P_CIGCTRL_TESTPAT_MASK | S5P_CIGCTRL_SELCAM_ITU_A | + S5P_CIGCTRL_SELCAM_MIPI | S5P_CIGCTRL_CAMIF_SELWB | + S5P_CIGCTRL_SELCAM_MIPI_A); + + if (cam->bus_type == FIMC_MIPI_CSI2) { + cfg |= S5P_CIGCTRL_SELCAM_MIPI; + + if (cam->mux_id == 0) + cfg |= S5P_CIGCTRL_SELCAM_MIPI_A; + + /* TODO: add remaining supported formats. */ + if (vid_cap->fmt.code == V4L2_MBUS_FMT_VYUY8_2X8) { + tmp = S5P_CSIIMGFMT_YCBCR422_8BIT; + } else { + err("camera image format not supported: %d", + vid_cap->fmt.code); + return -EINVAL; + } + writel(tmp | (0x1 << 8), fimc->regs + S5P_CSIIMGFMT); + + } else if (cam->bus_type == FIMC_ITU_601 || + cam->bus_type == FIMC_ITU_656) { + if (cam->mux_id == 0) /* ITU-A, ITU-B: 0, 1 */ + cfg |= S5P_CIGCTRL_SELCAM_ITU_A; + } else if (cam->bus_type == FIMC_LCD_WB) { + cfg |= S5P_CIGCTRL_CAMIF_SELWB; + } else { + err("invalid camera bus type selected\n"); + return -EINVAL; + } + writel(cfg, fimc->regs + S5P_CIGCTRL); + + return 0; +} diff --git a/include/media/s3c_fimc.h b/include/media/s3c_fimc.h new file mode 100644 index 000000000000..ca1b6738e4a4 --- /dev/null +++ b/include/media/s3c_fimc.h @@ -0,0 +1,60 @@ +/* + * Samsung S5P SoC camera interface driver header + * + * Copyright (c) 2010 Samsung Electronics Co., Ltd + * Author: Sylwester Nawrocki, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef S3C_FIMC_H_ +#define S3C_FIMC_H_ + +enum cam_bus_type { + FIMC_ITU_601 = 1, + FIMC_ITU_656, + FIMC_MIPI_CSI2, + FIMC_LCD_WB, /* FIFO link from LCD mixer */ +}; + +#define FIMC_CLK_INV_PCLK (1 << 0) +#define FIMC_CLK_INV_VSYNC (1 << 1) +#define FIMC_CLK_INV_HREF (1 << 2) +#define FIMC_CLK_INV_HSYNC (1 << 3) + +struct i2c_board_info; + +/** + * struct s3c_fimc_isp_info - image sensor information required for host + * interace configuration. + * + * @board_info: pointer to I2C subdevice's board info + * @bus_type: determines bus type, MIPI, ITU-R BT.601 etc. + * @i2c_bus_num: i2c control bus id the sensor is attached to + * @mux_id: FIMC camera interface multiplexer index (separate for MIPI and ITU) + * @bus_width: camera data bus width in bits + * @flags: flags defining bus signals polarity inversion (High by default) + */ +struct s3c_fimc_isp_info { + struct i2c_board_info *board_info; + enum cam_bus_type bus_type; + u16 i2c_bus_num; + u16 mux_id; + u16 bus_width; + u16 flags; +}; + + +#define FIMC_MAX_CAMIF_CLIENTS 2 + +/** + * struct s3c_platform_fimc - camera host interface platform data + * + * @isp_info: properties of camera sensor required for host interface setup + */ +struct s3c_platform_fimc { + struct s3c_fimc_isp_info *isp_info[FIMC_MAX_CAMIF_CLIENTS]; +}; +#endif /* S3C_FIMC_H_ */ -- cgit v1.2.3 From 3e9c2b8477059c3ae39ed9373fddd23e4c754acc Mon Sep 17 00:00:00 2001 From: Sylwester Nawrocki Date: Mon, 11 Oct 2010 13:33:57 -0300 Subject: [media] Add driver for Siliconfile SR030PC30 VGA camera Add an I2C/v4l2-subdev driver for Siliconfile SR030PC30 VGA camera sensor with Image Signal Processor. SR030PC30 is the low resolution camera sensor on Samsung Aquila boards. Signed-off-by: Sylwester Nawrocki Signed-off-by: Kyungmin Park Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/Kconfig | 6 + drivers/media/video/Makefile | 1 + drivers/media/video/sr030pc30.c | 893 ++++++++++++++++++++++++++++++++++++++++ include/media/sr030pc30.h | 21 + 4 files changed, 921 insertions(+) create mode 100644 drivers/media/video/sr030pc30.c create mode 100644 include/media/sr030pc30.h (limited to 'include') diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 8db8c6fd6fb1..2d4226710ed5 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -706,6 +706,12 @@ config VIDEO_CAFE_CCIC CMOS camera controller. This is the controller found on first- generation OLPC systems. +config VIDEO_SR030PC30 + tristate "SR030PC30 VGA camera sensor support" + depends on I2C && VIDEO_V4L2 + ---help--- + This driver supports SR030PC30 VGA camera from Siliconfile + config SOC_CAMERA tristate "SoC camera support" depends on VIDEO_V4L2 && HAS_DMA && I2C diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 4f0952a758da..d5e49ddbf9dd 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -71,6 +71,7 @@ obj-$(CONFIG_VIDEO_OV7670) += ov7670.o obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o obj-$(CONFIG_VIDEO_MT9V011) += mt9v011.o +obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o obj-$(CONFIG_SOC_CAMERA_IMX074) += imx074.o obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c new file mode 100644 index 000000000000..f82e1f30988b --- /dev/null +++ b/drivers/media/video/sr030pc30.c @@ -0,0 +1,893 @@ +/* + * Driver for SiliconFile SR030PC30 VGA (1/10-Inch) Image Sensor with ISP + * + * Copyright (C) 2010 Samsung Electronics Co., Ltd + * Author: Sylwester Nawrocki, s.nawrocki@samsung.com + * + * Based on original driver authored by Dongsoo Nathaniel Kim + * and HeungJun Kim . + * + * Based on mt9v011 Micron Digital Image Sensor driver + * Copyright (c) 2009 Mauro Carvalho Chehab (mchehab@redhat.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +static int debug; +module_param(debug, int, 0644); + +#define MODULE_NAME "SR030PC30" + +/* + * Register offsets within a page + * b15..b8 - page id, b7..b0 - register address + */ +#define POWER_CTRL_REG 0x0001 +#define PAGEMODE_REG 0x03 +#define DEVICE_ID_REG 0x0004 +#define NOON010PC30_ID 0x86 +#define SR030PC30_ID 0x8C +#define VDO_CTL1_REG 0x0010 +#define SUBSAMPL_NONE_VGA 0 +#define SUBSAMPL_QVGA 0x10 +#define SUBSAMPL_QQVGA 0x20 +#define VDO_CTL2_REG 0x0011 +#define SYNC_CTL_REG 0x0012 +#define WIN_ROWH_REG 0x0020 +#define WIN_ROWL_REG 0x0021 +#define WIN_COLH_REG 0x0022 +#define WIN_COLL_REG 0x0023 +#define WIN_HEIGHTH_REG 0x0024 +#define WIN_HEIGHTL_REG 0x0025 +#define WIN_WIDTHH_REG 0x0026 +#define WIN_WIDTHL_REG 0x0027 +#define HBLANKH_REG 0x0040 +#define HBLANKL_REG 0x0041 +#define VSYNCH_REG 0x0042 +#define VSYNCL_REG 0x0043 +/* page 10 */ +#define ISP_CTL_REG(n) (0x1010 + (n)) +#define YOFS_REG 0x1040 +#define DARK_YOFS_REG 0x1041 +#define AG_ABRTH_REG 0x1050 +#define SAT_CTL_REG 0x1060 +#define BSAT_REG 0x1061 +#define RSAT_REG 0x1062 +#define AG_SAT_TH_REG 0x1063 +/* page 11 */ +#define ZLPF_CTRL_REG 0x1110 +#define ZLPF_CTRL2_REG 0x1112 +#define ZLPF_AGH_THR_REG 0x1121 +#define ZLPF_THR_REG 0x1160 +#define ZLPF_DYN_THR_REG 0x1160 +/* page 12 */ +#define YCLPF_CTL1_REG 0x1240 +#define YCLPF_CTL2_REG 0x1241 +#define YCLPF_THR_REG 0x1250 +#define BLPF_CTL_REG 0x1270 +#define BLPF_THR1_REG 0x1274 +#define BLPF_THR2_REG 0x1275 +/* page 14 - Lens Shading Compensation */ +#define LENS_CTRL_REG 0x1410 +#define LENS_XCEN_REG 0x1420 +#define LENS_YCEN_REG 0x1421 +#define LENS_R_COMP_REG 0x1422 +#define LENS_G_COMP_REG 0x1423 +#define LENS_B_COMP_REG 0x1424 +/* page 15 - Color correction */ +#define CMC_CTL_REG 0x1510 +#define CMC_OFSGH_REG 0x1514 +#define CMC_OFSGL_REG 0x1516 +#define CMC_SIGN_REG 0x1517 +/* Color correction coefficients */ +#define CMC_COEF_REG(n) (0x1530 + (n)) +/* Color correction offset coefficients */ +#define CMC_OFS_REG(n) (0x1540 + (n)) +/* page 16 - Gamma correction */ +#define GMA_CTL_REG 0x1610 +/* Gamma correction coefficients 0.14 */ +#define GMA_COEF_REG(n) (0x1630 + (n)) +/* page 20 - Auto Exposure */ +#define AE_CTL1_REG 0x2010 +#define AE_CTL2_REG 0x2011 +#define AE_FRM_CTL_REG 0x2020 +#define AE_FINE_CTL_REG(n) (0x2028 + (n)) +#define EXP_TIMEH_REG 0x2083 +#define EXP_TIMEM_REG 0x2084 +#define EXP_TIMEL_REG 0x2085 +#define EXP_MMINH_REG 0x2086 +#define EXP_MMINL_REG 0x2087 +#define EXP_MMAXH_REG 0x2088 +#define EXP_MMAXM_REG 0x2089 +#define EXP_MMAXL_REG 0x208A +/* page 22 - Auto White Balance */ +#define AWB_CTL1_REG 0x2210 +#define AWB_ENABLE 0x80 +#define AWB_CTL2_REG 0x2211 +#define MWB_ENABLE 0x01 +/* RGB gain control (manual WB) when AWB_CTL1[7]=0 */ +#define AWB_RGAIN_REG 0x2280 +#define AWB_GGAIN_REG 0x2281 +#define AWB_BGAIN_REG 0x2282 +#define AWB_RMAX_REG 0x2283 +#define AWB_RMIN_REG 0x2284 +#define AWB_BMAX_REG 0x2285 +#define AWB_BMIN_REG 0x2286 +/* R, B gain range in bright light conditions */ +#define AWB_RMAXB_REG 0x2287 +#define AWB_RMINB_REG 0x2288 +#define AWB_BMAXB_REG 0x2289 +#define AWB_BMINB_REG 0x228A +/* manual white balance, when AWB_CTL2[0]=1 */ +#define MWB_RGAIN_REG 0x22B2 +#define MWB_BGAIN_REG 0x22B3 +/* the token to mark an array end */ +#define REG_TERM 0xFFFF + +/* Minimum and maximum exposure time in ms */ +#define EXPOS_MIN_MS 1 +#define EXPOS_MAX_MS 125 + +struct sr030pc30_info { + struct v4l2_subdev sd; + const struct sr030pc30_platform_data *pdata; + const struct sr030pc30_format *curr_fmt; + const struct sr030pc30_frmsize *curr_win; + unsigned int auto_wb:1; + unsigned int auto_exp:1; + unsigned int hflip:1; + unsigned int vflip:1; + unsigned int sleep:1; + unsigned int exposure; + u8 blue_balance; + u8 red_balance; + u8 i2c_reg_page; +}; + +struct sr030pc30_format { + enum v4l2_mbus_pixelcode code; + enum v4l2_colorspace colorspace; + u16 ispctl1_reg; +}; + +struct sr030pc30_frmsize { + u16 width; + u16 height; + int vid_ctl1; +}; + +struct i2c_regval { + u16 addr; + u16 val; +}; + +static const struct v4l2_queryctrl sr030pc30_ctrl[] = { + { + .id = V4L2_CID_AUTO_WHITE_BALANCE, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "Auto White Balance", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 1, + }, { + .id = V4L2_CID_RED_BALANCE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Red Balance", + .minimum = 0, + .maximum = 127, + .step = 1, + .default_value = 64, + .flags = 0, + }, { + .id = V4L2_CID_BLUE_BALANCE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Blue Balance", + .minimum = 0, + .maximum = 127, + .step = 1, + .default_value = 64, + }, { + .id = V4L2_CID_EXPOSURE_AUTO, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Auto Exposure", + .minimum = 0, + .maximum = 1, + .step = 1, + .default_value = 1, + }, { + .id = V4L2_CID_EXPOSURE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Exposure", + .minimum = EXPOS_MIN_MS, + .maximum = EXPOS_MAX_MS, + .step = 1, + .default_value = 1, + }, { + } +}; + +/* supported resolutions */ +static const struct sr030pc30_frmsize sr030pc30_sizes[] = { + { + .width = 640, + .height = 480, + .vid_ctl1 = SUBSAMPL_NONE_VGA, + }, { + .width = 320, + .height = 240, + .vid_ctl1 = SUBSAMPL_QVGA, + }, { + .width = 160, + .height = 120, + .vid_ctl1 = SUBSAMPL_QQVGA, + }, +}; + +/* supported pixel formats */ +static const struct sr030pc30_format sr030pc30_formats[] = { + { + .code = V4L2_MBUS_FMT_YUYV8_2X8, + .colorspace = V4L2_COLORSPACE_JPEG, + .ispctl1_reg = 0x03, + }, { + .code = V4L2_MBUS_FMT_YVYU8_2X8, + .colorspace = V4L2_COLORSPACE_JPEG, + .ispctl1_reg = 0x02, + }, { + .code = V4L2_MBUS_FMT_VYUY8_2X8, + .colorspace = V4L2_COLORSPACE_JPEG, + .ispctl1_reg = 0, + }, { + .code = V4L2_MBUS_FMT_UYVY8_2X8, + .colorspace = V4L2_COLORSPACE_JPEG, + .ispctl1_reg = 0x01, + }, { + .code = V4L2_MBUS_FMT_RGB565_2X8_BE, + .colorspace = V4L2_COLORSPACE_JPEG, + .ispctl1_reg = 0x40, + }, +}; + +static const struct i2c_regval sr030pc30_base_regs[] = { + /* Window size and position within pixel matrix */ + { WIN_ROWH_REG, 0x00 }, { WIN_ROWL_REG, 0x06 }, + { WIN_COLH_REG, 0x00 }, { WIN_COLL_REG, 0x06 }, + { WIN_HEIGHTH_REG, 0x01 }, { WIN_HEIGHTL_REG, 0xE0 }, + { WIN_WIDTHH_REG, 0x02 }, { WIN_WIDTHL_REG, 0x80 }, + { HBLANKH_REG, 0x01 }, { HBLANKL_REG, 0x50 }, + { VSYNCH_REG, 0x00 }, { VSYNCL_REG, 0x14 }, + { SYNC_CTL_REG, 0 }, + /* Color corection and saturation */ + { ISP_CTL_REG(0), 0x30 }, { YOFS_REG, 0x80 }, + { DARK_YOFS_REG, 0x04 }, { AG_ABRTH_REG, 0x78 }, + { SAT_CTL_REG, 0x1F }, { BSAT_REG, 0x90 }, + { AG_SAT_TH_REG, 0xF0 }, { 0x1064, 0x80 }, + { CMC_CTL_REG, 0x03 }, { CMC_OFSGH_REG, 0x3C }, + { CMC_OFSGL_REG, 0x2C }, { CMC_SIGN_REG, 0x2F }, + { CMC_COEF_REG(0), 0xCB }, { CMC_OFS_REG(0), 0x87 }, + { CMC_COEF_REG(1), 0x61 }, { CMC_OFS_REG(1), 0x18 }, + { CMC_COEF_REG(2), 0x16 }, { CMC_OFS_REG(2), 0x91 }, + { CMC_COEF_REG(3), 0x23 }, { CMC_OFS_REG(3), 0x94 }, + { CMC_COEF_REG(4), 0xCE }, { CMC_OFS_REG(4), 0x9f }, + { CMC_COEF_REG(5), 0x2B }, { CMC_OFS_REG(5), 0x33 }, + { CMC_COEF_REG(6), 0x01 }, { CMC_OFS_REG(6), 0x00 }, + { CMC_COEF_REG(7), 0x34 }, { CMC_OFS_REG(7), 0x94 }, + { CMC_COEF_REG(8), 0x75 }, { CMC_OFS_REG(8), 0x14 }, + /* Color corection coefficients */ + { GMA_CTL_REG, 0x03 }, { GMA_COEF_REG(0), 0x00 }, + { GMA_COEF_REG(1), 0x19 }, { GMA_COEF_REG(2), 0x26 }, + { GMA_COEF_REG(3), 0x3B }, { GMA_COEF_REG(4), 0x5D }, + { GMA_COEF_REG(5), 0x79 }, { GMA_COEF_REG(6), 0x8E }, + { GMA_COEF_REG(7), 0x9F }, { GMA_COEF_REG(8), 0xAF }, + { GMA_COEF_REG(9), 0xBD }, { GMA_COEF_REG(10), 0xCA }, + { GMA_COEF_REG(11), 0xDD }, { GMA_COEF_REG(12), 0xEC }, + { GMA_COEF_REG(13), 0xF7 }, { GMA_COEF_REG(14), 0xFF }, + /* Noise reduction, Z-LPF, YC-LPF and BLPF filters setup */ + { ZLPF_CTRL_REG, 0x99 }, { ZLPF_CTRL2_REG, 0x0E }, + { ZLPF_AGH_THR_REG, 0x29 }, { ZLPF_THR_REG, 0x0F }, + { ZLPF_DYN_THR_REG, 0x63 }, { YCLPF_CTL1_REG, 0x23 }, + { YCLPF_CTL2_REG, 0x3B }, { YCLPF_THR_REG, 0x05 }, + { BLPF_CTL_REG, 0x1D }, { BLPF_THR1_REG, 0x05 }, + { BLPF_THR2_REG, 0x04 }, + /* Automatic white balance */ + { AWB_CTL1_REG, 0xFB }, { AWB_CTL2_REG, 0x26 }, + { AWB_RMAX_REG, 0x54 }, { AWB_RMIN_REG, 0x2B }, + { AWB_BMAX_REG, 0x57 }, { AWB_BMIN_REG, 0x29 }, + { AWB_RMAXB_REG, 0x50 }, { AWB_RMINB_REG, 0x43 }, + { AWB_BMAXB_REG, 0x30 }, { AWB_BMINB_REG, 0x22 }, + /* Auto exposure */ + { AE_CTL1_REG, 0x8C }, { AE_CTL2_REG, 0x04 }, + { AE_FRM_CTL_REG, 0x01 }, { AE_FINE_CTL_REG(0), 0x3F }, + { AE_FINE_CTL_REG(1), 0xA3 }, { AE_FINE_CTL_REG(3), 0x34 }, + /* Lens shading compensation */ + { LENS_CTRL_REG, 0x01 }, { LENS_XCEN_REG, 0x80 }, + { LENS_YCEN_REG, 0x70 }, { LENS_R_COMP_REG, 0x53 }, + { LENS_G_COMP_REG, 0x40 }, { LENS_B_COMP_REG, 0x3e }, + { REG_TERM, 0 }, +}; + +static inline struct sr030pc30_info *to_sr030pc30(struct v4l2_subdev *sd) +{ + return container_of(sd, struct sr030pc30_info, sd); +} + +static inline int set_i2c_page(struct sr030pc30_info *info, + struct i2c_client *client, unsigned int reg) +{ + int ret; + u32 page = reg >> 8 & 0xFF; + + if (info->i2c_reg_page != page && (reg & 0xFF) != 0x03) { + ret = i2c_smbus_write_byte_data(client, PAGEMODE_REG, page); + if (!ret) + info->i2c_reg_page = page; + } + return ret; +} + +static int cam_i2c_read(struct v4l2_subdev *sd, u32 reg_addr) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct sr030pc30_info *info = to_sr030pc30(sd); + + int ret = set_i2c_page(info, client, reg_addr); + if (!ret) + ret = i2c_smbus_read_byte_data(client, reg_addr & 0xFF); + return ret; +} + +static int cam_i2c_write(struct v4l2_subdev *sd, u32 reg_addr, u32 val) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct sr030pc30_info *info = to_sr030pc30(sd); + + int ret = set_i2c_page(info, client, reg_addr); + if (!ret) + ret = i2c_smbus_write_byte_data( + client, reg_addr & 0xFF, val); + return ret; +} + +static inline int sr030pc30_bulk_write_reg(struct v4l2_subdev *sd, + const struct i2c_regval *msg) +{ + while (msg->addr != REG_TERM) { + int ret = cam_i2c_write(sd, msg->addr, msg->val); + if (ret) + return ret; + msg++; + } + return 0; +} + +/* Device reset and sleep mode control */ +static int sr030pc30_pwr_ctrl(struct v4l2_subdev *sd, + bool reset, bool sleep) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + u8 reg = sleep ? 0xF1 : 0xF0; + int ret = 0; + + if (reset) + ret = cam_i2c_write(sd, POWER_CTRL_REG, reg | 0x02); + if (!ret) { + ret = cam_i2c_write(sd, POWER_CTRL_REG, reg); + if (!ret) { + info->sleep = sleep; + if (reset) + info->i2c_reg_page = -1; + } + } + return ret; +} + +static inline int sr030pc30_enable_autoexposure(struct v4l2_subdev *sd, int on) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + /* auto anti-flicker is also enabled here */ + int ret = cam_i2c_write(sd, AE_CTL1_REG, on ? 0xDC : 0x0C); + if (!ret) + info->auto_exp = on; + return ret; +} + +static int sr030pc30_set_exposure(struct v4l2_subdev *sd, int value) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + unsigned long expos = value * info->pdata->clk_rate / (8 * 1000); + + int ret = cam_i2c_write(sd, EXP_TIMEH_REG, expos >> 16 & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_TIMEM_REG, expos >> 8 & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_TIMEL_REG, expos & 0xFF); + if (!ret) { /* Turn off AE */ + info->exposure = value; + ret = sr030pc30_enable_autoexposure(sd, 0); + } + return ret; +} + +/* Automatic white balance control */ +static int sr030pc30_enable_autowhitebalance(struct v4l2_subdev *sd, int on) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + int ret = cam_i2c_write(sd, AWB_CTL2_REG, on ? 0x2E : 0x2F); + if (!ret) + ret = cam_i2c_write(sd, AWB_CTL1_REG, on ? 0xFB : 0x7B); + if (!ret) + info->auto_wb = on; + + return ret; +} + +static int sr030pc30_set_flip(struct v4l2_subdev *sd) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + s32 reg = cam_i2c_read(sd, VDO_CTL2_REG); + if (reg < 0) + return reg; + + reg &= 0x7C; + if (info->hflip) + reg |= 0x01; + if (info->vflip) + reg |= 0x02; + return cam_i2c_write(sd, VDO_CTL2_REG, reg | 0x80); +} + +/* Configure resolution, color format and image flip */ +static int sr030pc30_set_params(struct v4l2_subdev *sd) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + int ret; + + if (!info->curr_win) + return -EINVAL; + + /* Configure the resolution through subsampling */ + ret = cam_i2c_write(sd, VDO_CTL1_REG, + info->curr_win->vid_ctl1); + + if (!ret && info->curr_fmt) + ret = cam_i2c_write(sd, ISP_CTL_REG(0), + info->curr_fmt->ispctl1_reg); + if (!ret) + ret = sr030pc30_set_flip(sd); + + return ret; +} + +/* Find nearest matching image pixel size. */ +static int sr030pc30_try_frame_size(struct v4l2_mbus_framefmt *mf) +{ + unsigned int min_err = ~0; + int i = ARRAY_SIZE(sr030pc30_sizes); + const struct sr030pc30_frmsize *fsize = &sr030pc30_sizes[0], + *match = NULL; + while (i--) { + int err = abs(fsize->width - mf->width) + + abs(fsize->height - mf->height); + if (err < min_err) { + min_err = err; + match = fsize; + } + fsize++; + } + if (match) { + mf->width = match->width; + mf->height = match->height; + return 0; + } + return -EINVAL; +} + +static int sr030pc30_queryctrl(struct v4l2_subdev *sd, + struct v4l2_queryctrl *qc) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(sr030pc30_ctrl); i++) + if (qc->id == sr030pc30_ctrl[i].id) { + *qc = sr030pc30_ctrl[i]; + v4l2_dbg(1, debug, sd, "%s id: %d\n", + __func__, qc->id); + return 0; + } + + return -EINVAL; +} + +static inline int sr030pc30_set_bluebalance(struct v4l2_subdev *sd, int value) +{ + int ret = cam_i2c_write(sd, MWB_BGAIN_REG, value); + if (!ret) + to_sr030pc30(sd)->blue_balance = value; + return ret; +} + +static inline int sr030pc30_set_redbalance(struct v4l2_subdev *sd, int value) +{ + int ret = cam_i2c_write(sd, MWB_RGAIN_REG, value); + if (!ret) + to_sr030pc30(sd)->red_balance = value; + return ret; +} + +static int sr030pc30_s_ctrl(struct v4l2_subdev *sd, + struct v4l2_control *ctrl) +{ + int i, ret = 0; + + for (i = 0; i < ARRAY_SIZE(sr030pc30_ctrl); i++) + if (ctrl->id == sr030pc30_ctrl[i].id) + break; + + if (i == ARRAY_SIZE(sr030pc30_ctrl)) + return -EINVAL; + + if (ctrl->value < sr030pc30_ctrl[i].minimum || + ctrl->value > sr030pc30_ctrl[i].maximum) + return -ERANGE; + + v4l2_dbg(1, debug, sd, "%s: ctrl_id: %d, value: %d\n", + __func__, ctrl->id, ctrl->value); + + switch (ctrl->id) { + case V4L2_CID_AUTO_WHITE_BALANCE: + sr030pc30_enable_autowhitebalance(sd, ctrl->value); + break; + case V4L2_CID_BLUE_BALANCE: + ret = sr030pc30_set_bluebalance(sd, ctrl->value); + break; + case V4L2_CID_RED_BALANCE: + ret = sr030pc30_set_redbalance(sd, ctrl->value); + break; + case V4L2_CID_EXPOSURE_AUTO: + sr030pc30_enable_autoexposure(sd, + ctrl->value == V4L2_EXPOSURE_AUTO); + break; + case V4L2_CID_EXPOSURE: + ret = sr030pc30_set_exposure(sd, ctrl->value); + break; + default: + return -EINVAL; + } + + return ret; +} + +static int sr030pc30_g_ctrl(struct v4l2_subdev *sd, + struct v4l2_control *ctrl) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + v4l2_dbg(1, debug, sd, "%s: id: %d\n", __func__, ctrl->id); + + switch (ctrl->id) { + case V4L2_CID_AUTO_WHITE_BALANCE: + ctrl->value = info->auto_wb; + break; + case V4L2_CID_BLUE_BALANCE: + ctrl->value = info->blue_balance; + break; + case V4L2_CID_RED_BALANCE: + ctrl->value = info->red_balance; + break; + case V4L2_CID_EXPOSURE_AUTO: + ctrl->value = info->auto_exp; + break; + case V4L2_CID_EXPOSURE: + ctrl->value = info->exposure; + break; + default: + return -EINVAL; + } + return 0; +} + +static int sr030pc30_enum_fmt(struct v4l2_subdev *sd, unsigned int index, + enum v4l2_mbus_pixelcode *code) +{ + if (!code || index >= ARRAY_SIZE(sr030pc30_formats)) + return -EINVAL; + + *code = sr030pc30_formats[index].code; + return 0; +} + +static int sr030pc30_g_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + int ret; + + if (!mf) + return -EINVAL; + + if (!info->curr_win || !info->curr_fmt) { + ret = sr030pc30_set_params(sd); + if (ret) + return ret; + } + + mf->width = info->curr_win->width; + mf->height = info->curr_win->height; + mf->code = info->curr_fmt->code; + mf->colorspace = info->curr_fmt->colorspace; + mf->field = V4L2_FIELD_NONE; + + return 0; +} + +/* Return nearest media bus frame format. */ +static const struct sr030pc30_format *try_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + int i = ARRAY_SIZE(sr030pc30_formats); + + sr030pc30_try_frame_size(mf); + + while (i--) + if (mf->code == sr030pc30_formats[i].code) + break; + + mf->code = sr030pc30_formats[i].code; + + return &sr030pc30_formats[i]; +} + +/* Return nearest media bus frame format. */ +static int sr030pc30_try_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + if (!sd || !mf) + return -EINVAL; + + try_fmt(sd, mf); + return 0; +} + +static int sr030pc30_s_fmt(struct v4l2_subdev *sd, + struct v4l2_mbus_framefmt *mf) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + if (!sd || !mf) + return -EINVAL; + + info->curr_fmt = try_fmt(sd, mf); + + return sr030pc30_set_params(sd); +} + +static int sr030pc30_base_config(struct v4l2_subdev *sd) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + int ret; + unsigned long expmin, expmax; + + ret = sr030pc30_bulk_write_reg(sd, sr030pc30_base_regs); + if (!ret) { + info->curr_fmt = &sr030pc30_formats[0]; + info->curr_win = &sr030pc30_sizes[0]; + ret = sr030pc30_set_params(sd); + } + if (!ret) + ret = sr030pc30_pwr_ctrl(sd, false, false); + + if (!ret && !info->pdata) + return ret; + + expmin = EXPOS_MIN_MS * info->pdata->clk_rate / (8 * 1000); + expmax = EXPOS_MAX_MS * info->pdata->clk_rate / (8 * 1000); + + v4l2_dbg(1, debug, sd, "%s: expmin= %lx, expmax= %lx", __func__, + expmin, expmax); + + /* Setting up manual exposure time range */ + ret = cam_i2c_write(sd, EXP_MMINH_REG, expmin >> 8 & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_MMINL_REG, expmin & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_MMAXH_REG, expmax >> 16 & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_MMAXM_REG, expmax >> 8 & 0xFF); + if (!ret) + ret = cam_i2c_write(sd, EXP_MMAXL_REG, expmax & 0xFF); + + return ret; +} + +static int sr030pc30_s_config(struct v4l2_subdev *sd, + int irq, void *platform_data) +{ + struct sr030pc30_info *info = to_sr030pc30(sd); + + info->pdata = platform_data; + return 0; +} + +static int sr030pc30_s_stream(struct v4l2_subdev *sd, int enable) +{ + return 0; +} + +static int sr030pc30_s_power(struct v4l2_subdev *sd, int on) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct sr030pc30_info *info = to_sr030pc30(sd); + const struct sr030pc30_platform_data *pdata = info->pdata; + int ret; + + if (WARN(pdata == NULL, "No platform data!")) + return -ENOMEM; + + /* + * Put sensor into power sleep mode before switching off + * power and disabling MCLK. + */ + if (!on) + sr030pc30_pwr_ctrl(sd, false, true); + + /* set_power controls sensor's power and clock */ + if (pdata->set_power) { + ret = pdata->set_power(&client->dev, on); + if (ret) + return ret; + } + + if (on) { + ret = sr030pc30_base_config(sd); + } else { + info->curr_win = NULL; + info->curr_fmt = NULL; + } + + return ret; +} + +static const struct v4l2_subdev_core_ops sr030pc30_core_ops = { + .s_config = sr030pc30_s_config, + .s_power = sr030pc30_s_power, + .queryctrl = sr030pc30_queryctrl, + .s_ctrl = sr030pc30_s_ctrl, + .g_ctrl = sr030pc30_g_ctrl, +}; + +static const struct v4l2_subdev_video_ops sr030pc30_video_ops = { + .s_stream = sr030pc30_s_stream, + .g_mbus_fmt = sr030pc30_g_fmt, + .s_mbus_fmt = sr030pc30_s_fmt, + .try_mbus_fmt = sr030pc30_try_fmt, + .enum_mbus_fmt = sr030pc30_enum_fmt, +}; + +static const struct v4l2_subdev_ops sr030pc30_ops = { + .core = &sr030pc30_core_ops, + .video = &sr030pc30_video_ops, +}; + +/* + * Detect sensor type. Return 0 if SR030PC30 was detected + * or -ENODEV otherwise. + */ +static int sr030pc30_detect(struct i2c_client *client) +{ + const struct sr030pc30_platform_data *pdata + = client->dev.platform_data; + int ret; + + /* Enable sensor's power and clock */ + if (pdata->set_power) { + ret = pdata->set_power(&client->dev, 1); + if (ret) + return ret; + } + + ret = i2c_smbus_read_byte_data(client, DEVICE_ID_REG); + + if (pdata->set_power) + pdata->set_power(&client->dev, 0); + + if (ret < 0) { + dev_err(&client->dev, "%s: I2C read failed\n", __func__); + return ret; + } + + return ret == SR030PC30_ID ? 0 : -ENODEV; +} + + +static int sr030pc30_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct sr030pc30_info *info; + struct v4l2_subdev *sd; + const struct sr030pc30_platform_data *pdata + = client->dev.platform_data; + int ret; + + if (!pdata) { + dev_err(&client->dev, "No platform data!"); + return -EIO; + } + + ret = sr030pc30_detect(client); + if (ret) + return ret; + + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + sd = &info->sd; + strcpy(sd->name, MODULE_NAME); + info->pdata = client->dev.platform_data; + + v4l2_i2c_subdev_init(sd, client, &sr030pc30_ops); + + info->i2c_reg_page = -1; + info->hflip = 1; + info->auto_exp = 1; + info->exposure = 30; + + return 0; +} + +static int sr030pc30_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct sr030pc30_info *info = to_sr030pc30(sd); + + v4l2_device_unregister_subdev(sd); + kfree(info); + return 0; +} + +static const struct i2c_device_id sr030pc30_id[] = { + { MODULE_NAME, 0 }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, sr030pc30_id); + + +static struct i2c_driver sr030pc30_i2c_driver = { + .driver = { + .name = MODULE_NAME + }, + .probe = sr030pc30_probe, + .remove = sr030pc30_remove, + .id_table = sr030pc30_id, +}; + +static int __init sr030pc30_init(void) +{ + return i2c_add_driver(&sr030pc30_i2c_driver); +} + +static void __exit sr030pc30_exit(void) +{ + i2c_del_driver(&sr030pc30_i2c_driver); +} + +module_init(sr030pc30_init); +module_exit(sr030pc30_exit); + +MODULE_DESCRIPTION("Siliconfile SR030PC30 camera driver"); +MODULE_AUTHOR("Sylwester Nawrocki "); +MODULE_LICENSE("GPL"); diff --git a/include/media/sr030pc30.h b/include/media/sr030pc30.h new file mode 100644 index 000000000000..6f901a653ba2 --- /dev/null +++ b/include/media/sr030pc30.h @@ -0,0 +1,21 @@ +/* + * Driver header for SR030PC30 camera sensor + * + * Copyright (c) 2010 Samsung Electronics, Co. Ltd + * Contact: Sylwester Nawrocki + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef SR030PC30_H +#define SR030PC30_H + +struct sr030pc30_platform_data { + unsigned long clk_rate; /* master clock frequency in Hz */ + int (*set_power)(struct device *dev, int on); +}; + +#endif /* SR030PC30_H */ -- cgit v1.2.3 From 111ac84a80199654db55c06e2565d4ab343c135d Mon Sep 17 00:00:00 2001 From: Sergey Ivanov <123kash@gmail.com> Date: Mon, 9 Aug 2010 10:18:32 -0300 Subject: [media] Twinhan 1027 + IR Port support Patch add support of TwinHan 1027 DVB-S card. Refreshed version of https://patchwork.kernel.org/patch/79753/ patch. (adapted for the new IR system), still works. DVB-S support come from a patch originally authored by Manu Abraham (abraham.manu@gmail.com). IR Port support were added by Sergey. Cc: Manu Abraham Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-twinhan1027.c | 87 +++++++++++++++++++++++++++++++ drivers/media/video/cx88/cx88-cards.c | 23 ++++++++ drivers/media/video/cx88/cx88-dvb.c | 61 ++++++++++++++++++---- drivers/media/video/cx88/cx88-input.c | 6 +++ drivers/media/video/cx88/cx88.h | 1 + include/media/rc-map.h | 1 + 7 files changed, 171 insertions(+), 9 deletions(-) create mode 100644 drivers/media/IR/keymaps/rc-twinhan1027.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 11688dd740ca..6083453f4715 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -77,6 +77,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-total-media-in-hand.o \ rc-trekstor.o \ rc-tt-1500.o \ + rc-twinhan1027.o \ rc-videomate-s350.o \ rc-videomate-tv-pvr.o \ rc-winfast.o \ diff --git a/drivers/media/IR/keymaps/rc-twinhan1027.c b/drivers/media/IR/keymaps/rc-twinhan1027.c new file mode 100644 index 000000000000..0b5d356c2d84 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-twinhan1027.c @@ -0,0 +1,87 @@ +#include + +static struct ir_scancode twinhan_vp1027[] = { + { 0x16, KEY_POWER2 }, + { 0x17, KEY_FAVORITES }, + { 0x0f, KEY_TEXT }, + { 0x48, KEY_INFO}, + { 0x1c, KEY_EPG }, + { 0x04, KEY_LIST }, + + { 0x03, KEY_1 }, + { 0x01, KEY_2 }, + { 0x06, KEY_3 }, + { 0x09, KEY_4 }, + { 0x1d, KEY_5 }, + { 0x1f, KEY_6 }, + { 0x0d, KEY_7 }, + { 0x19, KEY_8 }, + { 0x1b, KEY_9 }, + { 0x15, KEY_0 }, + + { 0x0c, KEY_CANCEL }, + { 0x4a, KEY_CLEAR }, + { 0x13, KEY_BACKSPACE }, + { 0x00, KEY_TAB }, + + { 0x4b, KEY_UP }, + { 0x51, KEY_DOWN }, + { 0x4e, KEY_LEFT }, + { 0x52, KEY_RIGHT }, + { 0x4f, KEY_ENTER }, + + { 0x1e, KEY_VOLUMEUP }, + { 0x0a, KEY_VOLUMEDOWN }, + { 0x02, KEY_CHANNELDOWN }, + { 0x05, KEY_CHANNELUP }, + { 0x11, KEY_RECORD }, + + { 0x14, KEY_PLAY }, + { 0x4c, KEY_PAUSE }, + { 0x1a, KEY_STOP }, + { 0x40, KEY_REWIND }, + { 0x12, KEY_FASTFORWARD }, + { 0x41, KEY_PREVIOUSSONG }, + { 0x42, KEY_NEXTSONG }, + { 0x54, KEY_SAVE }, + { 0x50, KEY_LANGUAGE }, + { 0x47, KEY_MEDIA }, + { 0x4d, KEY_SCREEN }, + { 0x43, KEY_SUBTITLE }, + { 0x10, KEY_MUTE }, + { 0x49, KEY_AUDIO }, + { 0x07, KEY_SLEEP }, + { 0x08, KEY_VIDEO }, + { 0x0e, KEY_AGAIN }, + { 0x45, KEY_EQUAL }, + { 0x46, KEY_MINUS }, + { 0x18, KEY_RED }, + { 0x53, KEY_GREEN }, + { 0x5e, KEY_YELLOW }, + { 0x5f, KEY_BLUE }, +}; + +static struct rc_keymap twinhan_vp1027_map = { + .map = { + .scan = twinhan_vp1027, + .size = ARRAY_SIZE(twinhan_vp1027), + .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ + .name = RC_MAP_TWINHAN_VP1027_DVBS, + } +}; + +static int __init init_rc_map_twinhan_vp1027(void) +{ + return ir_register_map(&twinhan_vp1027_map); +} + +static void __exit exit_rc_map_twinhan_vp1027(void) +{ + ir_unregister_map(&twinhan_vp1027_map); +} + +module_init(init_rc_map_twinhan_vp1027) +module_exit(exit_rc_map_twinhan_vp1027) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Sergey Ivanov <123kash@gmail.com>"); diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c index 97672cb49b51..f220fa2e10d8 100644 --- a/drivers/media/video/cx88/cx88-cards.c +++ b/drivers/media/video/cx88/cx88-cards.c @@ -2104,6 +2104,18 @@ static const struct cx88_board cx88_boards[] = { } }, .mpeg = CX88_MPEG_DVB, }, + [CX88_BOARD_TWINHAN_VP1027_DVBS] = { + .name = "Twinhan VP-1027 DVB-S", + .tuner_type = TUNER_ABSENT, + .radio_type = UNSET, + .tuner_addr = ADDR_UNSET, + .radio_addr = ADDR_UNSET, + .input = {{ + .type = CX88_VMUX_DVB, + .vmux = 0, + } }, + .mpeg = CX88_MPEG_DVB, + }, }; /* ------------------------------------------------------------------ */ @@ -2576,6 +2588,10 @@ static const struct cx88_subid cx88_subids[] = { .subvendor = 0xb034, .subdevice = 0x3034, .card = CX88_BOARD_PROF_7301, + }, { + .subvendor = 0x1822, + .subdevice = 0x0023, + .card = CX88_BOARD_TWINHAN_VP1027_DVBS, }, }; @@ -3070,6 +3086,13 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core) cx_set(MO_GP1_IO, 0x10); mdelay(50); break; + + case CX88_BOARD_TWINHAN_VP1027_DVBS: + cx_write(MO_GP0_IO, 0x00003230); + cx_write(MO_GP0_IO, 0x00003210); + msleep(1); + cx_write(MO_GP0_IO, 0x00001230); + break; } } diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c index a037e925ceb9..367a653f4c95 100644 --- a/drivers/media/video/cx88/cx88-dvb.c +++ b/drivers/media/video/cx88/cx88-dvb.c @@ -56,6 +56,7 @@ #include "stv0900.h" #include "stb6100.h" #include "stb6100_proc.h" +#include "mb86a16.h" MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); MODULE_AUTHOR("Chris Pascoe "); @@ -250,6 +251,10 @@ static const struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = { .if2 = 45600, }; +static struct mb86a16_config twinhan_vp1027 = { + .demod_address = 0x08, +}; + #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe) { @@ -429,15 +434,41 @@ static int tevii_dvbs_set_voltage(struct dvb_frontend *fe, cx_set(MO_GP0_IO, 0x6040); switch (voltage) { - case SEC_VOLTAGE_13: - cx_clear(MO_GP0_IO, 0x20); - break; - case SEC_VOLTAGE_18: - cx_set(MO_GP0_IO, 0x20); - break; - case SEC_VOLTAGE_OFF: - cx_clear(MO_GP0_IO, 0x20); - break; + case SEC_VOLTAGE_13: + cx_clear(MO_GP0_IO, 0x20); + break; + case SEC_VOLTAGE_18: + cx_set(MO_GP0_IO, 0x20); + break; + case SEC_VOLTAGE_OFF: + cx_clear(MO_GP0_IO, 0x20); + break; + } + + if (core->prev_set_voltage) + return core->prev_set_voltage(fe, voltage); + return 0; +} + +static int vp1027_set_voltage(struct dvb_frontend *fe, + fe_sec_voltage_t voltage) +{ + struct cx8802_dev *dev = fe->dvb->priv; + struct cx88_core *core = dev->core; + + switch (voltage) { + case SEC_VOLTAGE_13: + dprintk(1, "LNB SEC Voltage=13\n"); + cx_write(MO_GP0_IO, 0x00001220); + break; + case SEC_VOLTAGE_18: + dprintk(1, "LNB SEC Voltage=18\n"); + cx_write(MO_GP0_IO, 0x00001222); + break; + case SEC_VOLTAGE_OFF: + dprintk(1, "LNB Voltage OFF\n"); + cx_write(MO_GP0_IO, 0x00001230); + break; } if (core->prev_set_voltage) @@ -1416,6 +1447,18 @@ static int dvb_register(struct cx8802_dev *dev) } break; + case CX88_BOARD_TWINHAN_VP1027_DVBS: + dev->ts_gen_cntrl = 0x00; + fe0->dvb.frontend = dvb_attach(mb86a16_attach, + &twinhan_vp1027, + &core->i2c_adap); + if (fe0->dvb.frontend) { + core->prev_set_voltage = + fe0->dvb.frontend->ops.set_voltage; + fe0->dvb.frontend->ops.set_voltage = + vp1027_set_voltage; + } + break; default: printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c index d52ce0e3bec9..fc777bc6e716 100644 --- a/drivers/media/video/cx88/cx88-input.c +++ b/drivers/media/video/cx88/cx88-input.c @@ -405,6 +405,11 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) ir->mask_keycode = 0x7e; ir->polling = 100; /* ms */ break; + case CX88_BOARD_TWINHAN_VP1027_DVBS: + ir_codes = RC_MAP_TWINHAN_VP1027_DVBS; + ir_type = IR_TYPE_NEC; + ir->sampling = 0xff00; /* address */ + break; } if (NULL == ir_codes) { @@ -530,6 +535,7 @@ void cx88_ir_irq(struct cx88_core *core) case CX88_BOARD_PROF_7300: case CX88_BOARD_PROF_7301: case CX88_BOARD_PROF_6200: + case CX88_BOARD_TWINHAN_VP1027_DVBS: ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4); if (ircode == 0xffffffff) { /* decoding error */ diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h index 127118f4b650..c9981e77416a 100644 --- a/drivers/media/video/cx88/cx88.h +++ b/drivers/media/video/cx88/cx88.h @@ -239,6 +239,7 @@ extern const struct sram_channel const cx88_sram_channels[]; #define CX88_BOARD_WINFAST_DTV2000H_J 82 #define CX88_BOARD_PROF_7301 83 #define CX88_BOARD_SAMSUNG_SMT_7020 84 +#define CX88_BOARD_TWINHAN_VP1027_DVBS 85 enum cx88_itype { CX88_VMUX_COMPOSITE1 = 1, diff --git a/include/media/rc-map.h b/include/media/rc-map.h index d1bff027297e..74a00a93dcf1 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -134,6 +134,7 @@ void rc_map_init(void); #define RC_MAP_TOTAL_MEDIA_IN_HAND "rc-total-media-in-hand" #define RC_MAP_TREKSTOR "rc-trekstor" #define RC_MAP_TT_1500 "rc-tt-1500" +#define RC_MAP_TWINHAN_VP1027_DVBS "rc-twinhan1027" #define RC_MAP_VIDEOMATE_S350 "rc-videomate-s350" #define RC_MAP_VIDEOMATE_TV_PVR "rc-videomate-tv-pvr" #define RC_MAP_WINFAST "rc-winfast" -- cgit v1.2.3 From 44a81550410ada5b30f0a611d9446dc9cbf4cb59 Mon Sep 17 00:00:00 2001 From: Matti Aaltonen Date: Thu, 7 Oct 2010 10:16:11 -0300 Subject: [media] V4L2: Add seek spacing and RDS CAP bits Add spacing field to v4l2_hw_freq_seek. Add V4L2_TUNER_CAP_RDS_BLOCK_IO, which indicates that the tuner/ transmitter if capable of transmitting/receiving RDS blocks. Add V4L2_TUNER_CAP_RDS_CONTROLS capability, which indicates that the RDS data is handled as values of predefined controls like radio text, program ID and so on. Signed-off-by: Matti J. Aaltonen Acked-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/linux/videodev2.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h index b06479f63271..5f6f47044abf 100644 --- a/include/linux/videodev2.h +++ b/include/linux/videodev2.h @@ -1368,6 +1368,8 @@ struct v4l2_modulator { #define V4L2_TUNER_CAP_SAP 0x0020 #define V4L2_TUNER_CAP_LANG1 0x0040 #define V4L2_TUNER_CAP_RDS 0x0080 +#define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100 +#define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200 /* Flags for the 'rxsubchans' field */ #define V4L2_TUNER_SUB_MONO 0x0001 @@ -1397,7 +1399,8 @@ struct v4l2_hw_freq_seek { enum v4l2_tuner_type type; __u32 seek_upward; __u32 wrap_around; - __u32 reserved[8]; + __u32 spacing; + __u32 reserved[7]; }; /* -- cgit v1.2.3 From 4651918a4afdd49bdea21d2f919b189ef17a6399 Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Sat, 16 Oct 2010 19:56:28 -0300 Subject: [media] IR: extend ir_raw_event and do refactoring Add new event types for timeout & carrier report Move timeout handling from ir_raw_event_store_with_filter to ir-lirc-codec, where it is really needed. Now lirc bridge ensures proper gap handling. Extend lirc bridge for carrier & timeout reports Note: all new ir_raw_event variables now should be initialized like that: DEFINE_IR_RAW_EVENT(ev); To clean an existing event, use init_ir_raw_event(&ev); Signed-off-by: Maxim Levitsky Acked-by: Jarod Wilson Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/ene_ir.c | 4 +- drivers/media/IR/ir-core-priv.h | 13 +++- drivers/media/IR/ir-jvc-decoder.c | 5 +- drivers/media/IR/ir-lirc-codec.c | 128 ++++++++++++++++++++++++----------- drivers/media/IR/ir-nec-decoder.c | 5 +- drivers/media/IR/ir-raw-event.c | 45 +++++------- drivers/media/IR/ir-rc5-decoder.c | 5 +- drivers/media/IR/ir-rc5-sz-decoder.c | 5 +- drivers/media/IR/ir-rc6-decoder.c | 5 +- drivers/media/IR/ir-sony-decoder.c | 5 +- drivers/media/IR/mceusb.c | 3 +- drivers/media/IR/nuvoton-cir.c | 5 +- drivers/media/IR/streamzap.c | 6 +- include/media/ir-core.h | 40 +++++++++-- 14 files changed, 181 insertions(+), 93 deletions(-) (limited to 'include') diff --git a/drivers/media/IR/ene_ir.c b/drivers/media/IR/ene_ir.c index f5beea04906a..0795872ff5de 100644 --- a/drivers/media/IR/ene_ir.c +++ b/drivers/media/IR/ene_ir.c @@ -697,7 +697,7 @@ static irqreturn_t ene_isr(int irq, void *data) unsigned long flags; irqreturn_t retval = IRQ_NONE; struct ene_device *dev = (struct ene_device *)data; - struct ir_raw_event ev; + DEFINE_IR_RAW_EVENT(ev); spin_lock_irqsave(&dev->hw_lock, flags); @@ -898,7 +898,7 @@ static int ene_set_learning_mode(void *data, int enable) } /* outside interface: enable or disable idle mode */ -static void ene_rx_set_idle(void *data, int idle) +static void ene_rx_set_idle(void *data, bool idle) { struct ene_device *dev = (struct ene_device *)data; diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index 6830580ae4db..81c936bd793f 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h @@ -88,6 +88,12 @@ struct ir_raw_event_ctrl { struct ir_input_dev *ir_dev; struct lirc_driver *drv; int carrier_low; + + ktime_t gap_start; + u64 gap_duration; + bool gap; + bool send_timeout_reports; + } lirc; }; @@ -115,9 +121,14 @@ static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration) ev->duration -= duration; } +/* Returns true if event is normal pulse/space event */ +static inline bool is_timing_event(struct ir_raw_event ev) +{ + return !ev.carrier_report && !ev.reset; +} + #define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000) #define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space") -#define IS_RESET(ev) (ev.duration == 0) /* * Routines from ir-sysfs.c - Meant to be called only internally inside * ir-core diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c index 77a89c4de014..63dca6e5458b 100644 --- a/drivers/media/IR/ir-jvc-decoder.c +++ b/drivers/media/IR/ir-jvc-decoder.c @@ -50,8 +50,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/ir-lirc-codec.c b/drivers/media/IR/ir-lirc-codec.c index 20ac9a4ce522..1d9c6b0fd0ea 100644 --- a/drivers/media/IR/ir-lirc-codec.c +++ b/drivers/media/IR/ir-lirc-codec.c @@ -32,6 +32,7 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev) { struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); + struct lirc_codec *lirc = &ir_dev->raw->lirc; int sample; if (!(ir_dev->raw->enabled_protocols & IR_TYPE_LIRC)) @@ -40,21 +41,57 @@ static int ir_lirc_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!ir_dev->raw->lirc.drv || !ir_dev->raw->lirc.drv->rbuf) return -EINVAL; - if (IS_RESET(ev)) + /* Packet start */ + if (ev.reset) return 0; - IR_dprintk(2, "LIRC data transfer started (%uus %s)\n", - TO_US(ev.duration), TO_STR(ev.pulse)); + /* Carrier reports */ + if (ev.carrier_report) { + sample = LIRC_FREQUENCY(ev.carrier); + + /* Packet end */ + } else if (ev.timeout) { + + if (lirc->gap) + return 0; + + lirc->gap_start = ktime_get(); + lirc->gap = true; + lirc->gap_duration = ev.duration; + + if (!lirc->send_timeout_reports) + return 0; + + sample = LIRC_TIMEOUT(ev.duration / 1000); - sample = ev.duration / 1000; - if (ev.pulse) - sample |= PULSE_BIT; + /* Normal sample */ + } else { + + if (lirc->gap) { + int gap_sample; + + lirc->gap_duration += ktime_to_ns(ktime_sub(ktime_get(), + lirc->gap_start)); + + /* Convert to ms and cap by LIRC_VALUE_MASK */ + do_div(lirc->gap_duration, 1000); + lirc->gap_duration = min(lirc->gap_duration, + (u64)LIRC_VALUE_MASK); + + gap_sample = LIRC_SPACE(lirc->gap_duration); + lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, + (unsigned char *) &gap_sample); + lirc->gap = false; + } + + sample = ev.pulse ? LIRC_PULSE(ev.duration / 1000) : + LIRC_SPACE(ev.duration / 1000); + } lirc_buffer_write(ir_dev->raw->lirc.drv->rbuf, (unsigned char *) &sample); wake_up(&ir_dev->raw->lirc.drv->rbuf->wait_poll); - return 0; } @@ -102,7 +139,7 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, struct ir_input_dev *ir_dev; int ret = 0; void *drv_data; - __u32 val = 0; + __u32 val = 0, tmp; lirc = lirc_get_pdata(filep); if (!lirc) @@ -130,22 +167,20 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, case LIRC_SET_SEND_MODE: if (val != (LIRC_MODE_PULSE & LIRC_CAN_SEND_MASK)) return -EINVAL; - break; + return 0; /* TX settings */ case LIRC_SET_TRANSMITTER_MASK: - if (ir_dev->props->s_tx_mask) - ret = ir_dev->props->s_tx_mask(drv_data, val); - else + if (!ir_dev->props->s_tx_mask) return -EINVAL; - break; + + return ir_dev->props->s_tx_mask(drv_data, val); case LIRC_SET_SEND_CARRIER: - if (ir_dev->props->s_tx_carrier) - ir_dev->props->s_tx_carrier(drv_data, val); - else + if (!ir_dev->props->s_tx_carrier) return -EINVAL; - break; + + return ir_dev->props->s_tx_carrier(drv_data, val); case LIRC_SET_SEND_DUTY_CYCLE: if (!ir_dev->props->s_tx_duty_cycle) @@ -154,39 +189,42 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, if (val <= 0 || val >= 100) return -EINVAL; - ir_dev->props->s_tx_duty_cycle(ir_dev->props->priv, val); - break; + return ir_dev->props->s_tx_duty_cycle(drv_data, val); /* RX settings */ case LIRC_SET_REC_CARRIER: - if (ir_dev->props->s_rx_carrier_range) - ret = ir_dev->props->s_rx_carrier_range( - ir_dev->props->priv, - ir_dev->raw->lirc.carrier_low, val); - else + if (!ir_dev->props->s_rx_carrier_range) return -ENOSYS; - if (!ret) - ir_dev->raw->lirc.carrier_low = 0; - break; + if (val <= 0) + return -EINVAL; + + return ir_dev->props->s_rx_carrier_range(drv_data, + ir_dev->raw->lirc.carrier_low, val); case LIRC_SET_REC_CARRIER_RANGE: - if (val >= 0) - ir_dev->raw->lirc.carrier_low = val; - break; + if (val <= 0) + return -EINVAL; + ir_dev->raw->lirc.carrier_low = val; + return 0; case LIRC_GET_REC_RESOLUTION: val = ir_dev->props->rx_resolution; break; case LIRC_SET_WIDEBAND_RECEIVER: - if (ir_dev->props->s_learning_mode) - return ir_dev->props->s_learning_mode( - ir_dev->props->priv, !!val); - else + if (!ir_dev->props->s_learning_mode) return -ENOSYS; + return ir_dev->props->s_learning_mode(drv_data, !!val); + + case LIRC_SET_MEASURE_CARRIER_MODE: + if (!ir_dev->props->s_carrier_report) + return -ENOSYS; + + return ir_dev->props->s_carrier_report(drv_data, !!val); + /* Generic timeout support */ case LIRC_GET_MIN_TIMEOUT: if (!ir_dev->props->max_timeout) @@ -201,10 +239,20 @@ static long ir_lirc_ioctl(struct file *filep, unsigned int cmd, break; case LIRC_SET_REC_TIMEOUT: - if (val < ir_dev->props->min_timeout || - val > ir_dev->props->max_timeout) - return -EINVAL; - ir_dev->props->timeout = val * 1000; + if (!ir_dev->props->max_timeout) + return -ENOSYS; + + tmp = val * 1000; + + if (tmp < ir_dev->props->min_timeout || + tmp > ir_dev->props->max_timeout) + return -EINVAL; + + ir_dev->props->timeout = tmp; + break; + + case LIRC_SET_REC_TIMEOUT_REPORTS: + lirc->send_timeout_reports = !!val; break; default: @@ -280,6 +328,10 @@ static int ir_lirc_register(struct input_dev *input_dev) if (ir_dev->props->s_learning_mode) features |= LIRC_CAN_USE_WIDEBAND_RECEIVER; + if (ir_dev->props->s_carrier_report) + features |= LIRC_CAN_MEASURE_CARRIER; + + if (ir_dev->props->max_timeout) features |= LIRC_CAN_SET_REC_TIMEOUT; diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c index d597421d6547..70993f79c8a2 100644 --- a/drivers/media/IR/ir-nec-decoder.c +++ b/drivers/media/IR/ir-nec-decoder.c @@ -54,8 +54,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index 119b567feeab..0d59ef7d1014 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c @@ -174,7 +174,7 @@ int ir_raw_event_store_with_filter(struct input_dev *input_dev, if (ir->idle && !ev->pulse) return 0; else if (ir->idle) - ir_raw_event_set_idle(input_dev, 0); + ir_raw_event_set_idle(input_dev, false); if (!raw->this_ev.duration) { raw->this_ev = *ev; @@ -187,48 +187,35 @@ int ir_raw_event_store_with_filter(struct input_dev *input_dev, /* Enter idle mode if nessesary */ if (!ev->pulse && ir->props->timeout && - raw->this_ev.duration >= ir->props->timeout) - ir_raw_event_set_idle(input_dev, 1); + raw->this_ev.duration >= ir->props->timeout) { + ir_raw_event_set_idle(input_dev, true); + } return 0; } EXPORT_SYMBOL_GPL(ir_raw_event_store_with_filter); -void ir_raw_event_set_idle(struct input_dev *input_dev, int idle) +/** + * ir_raw_event_set_idle() - hint the ir core if device is receiving + * IR data or not + * @input_dev: the struct input_dev device descriptor + * @idle: the hint value + */ +void ir_raw_event_set_idle(struct input_dev *input_dev, bool idle) { struct ir_input_dev *ir = input_get_drvdata(input_dev); struct ir_raw_event_ctrl *raw = ir->raw; - ktime_t now; - u64 delta; - if (!ir->props) + if (!ir->props || !ir->raw) return; - if (!ir->raw) - goto out; + IR_dprintk(2, "%s idle mode\n", idle ? "enter" : "leave"); if (idle) { - IR_dprintk(2, "enter idle mode\n"); - raw->last_event = ktime_get(); - } else { - IR_dprintk(2, "exit idle mode\n"); - - now = ktime_get(); - delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event)); - - WARN_ON(raw->this_ev.pulse); - - raw->this_ev.duration = - min(raw->this_ev.duration + delta, - (u64)IR_MAX_DURATION); - + raw->this_ev.timeout = true; ir_raw_event_store(input_dev, &raw->this_ev); - - if (raw->this_ev.duration == IR_MAX_DURATION) - ir_raw_event_reset(input_dev); - - raw->this_ev.duration = 0; + init_ir_raw_event(&raw->this_ev); } -out: + if (ir->props->s_idle) ir->props->s_idle(ir->props->priv, idle); ir->idle = idle; diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c index df4770d978ad..572ed4ca8c68 100644 --- a/drivers/media/IR/ir-rc5-decoder.c +++ b/drivers/media/IR/ir-rc5-decoder.c @@ -55,8 +55,9 @@ static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/ir-rc5-sz-decoder.c b/drivers/media/IR/ir-rc5-sz-decoder.c index 68f11d6acd5b..7c413501a3f7 100644 --- a/drivers/media/IR/ir-rc5-sz-decoder.c +++ b/drivers/media/IR/ir-rc5-sz-decoder.c @@ -51,8 +51,9 @@ static int ir_rc5_sz_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5_SZ)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/IR/ir-rc6-decoder.c index f1624b8279bc..d25da91f44ff 100644 --- a/drivers/media/IR/ir-rc6-decoder.c +++ b/drivers/media/IR/ir-rc6-decoder.c @@ -85,8 +85,9 @@ static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c index b9074f07c7a0..2d15730822bc 100644 --- a/drivers/media/IR/ir-sony-decoder.c +++ b/drivers/media/IR/ir-sony-decoder.c @@ -48,8 +48,9 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY)) return 0; - if (IS_RESET(ev)) { - data->state = STATE_INACTIVE; + if (!is_timing_event(ev)) { + if (ev.reset) + data->state = STATE_INACTIVE; return 0; } diff --git a/drivers/media/IR/mceusb.c b/drivers/media/IR/mceusb.c index bc620e10ef77..6825da5771f6 100644 --- a/drivers/media/IR/mceusb.c +++ b/drivers/media/IR/mceusb.c @@ -660,7 +660,7 @@ static int mceusb_set_tx_carrier(void *priv, u32 carrier) static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) { - struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; + DEFINE_IR_RAW_EVENT(rawir); int i, start_index = 0; u8 hdr = MCE_CONTROL_HEADER; @@ -997,6 +997,7 @@ static int __devinit mceusb_dev_probe(struct usb_interface *intf, ir->len_in = maxp; ir->flags.microsoft_gen1 = is_microsoft_gen1; ir->flags.tx_mask_inverted = tx_mask_inverted; + init_ir_raw_event(&ir->rawir); /* Saving usb interface data for use by the transmitter routine */ ir->usb_ep_in = ep_in; diff --git a/drivers/media/IR/nuvoton-cir.c b/drivers/media/IR/nuvoton-cir.c index 2f0f78078b57..301be53aee85 100644 --- a/drivers/media/IR/nuvoton-cir.c +++ b/drivers/media/IR/nuvoton-cir.c @@ -586,7 +586,7 @@ static void nvt_dump_rx_buf(struct nvt_dev *nvt) */ static void nvt_process_rx_ir_data(struct nvt_dev *nvt) { - struct ir_raw_event rawir = { .pulse = false, .duration = 0 }; + DEFINE_IR_RAW_EVENT(rawir); unsigned int count; u32 carrier; u8 sample; @@ -622,6 +622,8 @@ static void nvt_process_rx_ir_data(struct nvt_dev *nvt) } rawir.duration += nvt->rawir.duration; + + init_ir_raw_event(&nvt->rawir); nvt->rawir.duration = 0; nvt->rawir.pulse = rawir.pulse; @@ -1016,6 +1018,7 @@ static int nvt_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id) spin_lock_init(&nvt->nvt_lock); spin_lock_init(&nvt->tx.lock); + init_ir_raw_event(&nvt->rawir); ret = -EBUSY; /* now claim resources */ diff --git a/drivers/media/IR/streamzap.c b/drivers/media/IR/streamzap.c index 86a4f68feea4..548381c35bfd 100644 --- a/drivers/media/IR/streamzap.c +++ b/drivers/media/IR/streamzap.c @@ -146,7 +146,7 @@ static void sz_push(struct streamzap_ir *sz, struct ir_raw_event rawir) static void sz_push_full_pulse(struct streamzap_ir *sz, unsigned char value) { - struct ir_raw_event rawir; + DEFINE_IR_RAW_EVENT(rawir); if (sz->idle) { long deltv; @@ -193,7 +193,7 @@ static void sz_push_half_pulse(struct streamzap_ir *sz, static void sz_push_full_space(struct streamzap_ir *sz, unsigned char value) { - struct ir_raw_event rawir; + DEFINE_IR_RAW_EVENT(rawir); rawir.pulse = false; rawir.duration = ((int) value) * SZ_RESOLUTION; @@ -270,7 +270,7 @@ static void streamzap_callback(struct urb *urb) break; case FullSpace: if (sz->buf_in[i] == SZ_TIMEOUT) { - struct ir_raw_event rawir; + DEFINE_IR_RAW_EVENT(rawir); rawir.pulse = false; rawir.duration = timeout; diff --git a/include/media/ir-core.h b/include/media/ir-core.h index 4dd43d44ec5e..6dc37fae6606 100644 --- a/include/media/ir-core.h +++ b/include/media/ir-core.h @@ -60,6 +60,7 @@ enum rc_driver_type { * @s_idle: optional: enable/disable hardware idle mode, upon which, device doesn't interrupt host until it sees IR pulses * @s_learning_mode: enable wide band receiver used for learning + * @s_carrier_report: enable carrier reports */ struct ir_dev_props { enum rc_driver_type driver_type; @@ -82,8 +83,9 @@ struct ir_dev_props { int (*s_tx_duty_cycle)(void *priv, u32 duty_cycle); int (*s_rx_carrier_range)(void *priv, u32 min, u32 max); int (*tx_ir)(void *priv, int *txbuf, u32 n); - void (*s_idle)(void *priv, int enable); + void (*s_idle)(void *priv, bool enable); int (*s_learning_mode)(void *priv, int enable); + int (*s_carrier_report) (void *priv, int enable); }; struct ir_input_dev { @@ -163,22 +165,48 @@ u32 ir_g_keycode_from_table(struct input_dev *input_dev, u32 scancode); /* From ir-raw-event.c */ struct ir_raw_event { - unsigned pulse:1; - unsigned duration:31; + union { + u32 duration; + + struct { + u32 carrier; + u8 duty_cycle; + }; + }; + + unsigned pulse:1; + unsigned reset:1; + unsigned timeout:1; + unsigned carrier_report:1; }; -#define IR_MAX_DURATION 0x7FFFFFFF /* a bit more than 2 seconds */ +#define DEFINE_IR_RAW_EVENT(event) \ + struct ir_raw_event event = { \ + { .duration = 0 } , \ + .pulse = 0, \ + .reset = 0, \ + .timeout = 0, \ + .carrier_report = 0 } + +static inline void init_ir_raw_event(struct ir_raw_event *ev) +{ + memset(ev, 0, sizeof(*ev)); +} + +#define IR_MAX_DURATION 0xFFFFFFFF /* a bit more than 4 seconds */ void ir_raw_event_handle(struct input_dev *input_dev); int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev); int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type); int ir_raw_event_store_with_filter(struct input_dev *input_dev, struct ir_raw_event *ev); -void ir_raw_event_set_idle(struct input_dev *input_dev, int idle); +void ir_raw_event_set_idle(struct input_dev *input_dev, bool idle); static inline void ir_raw_event_reset(struct input_dev *input_dev) { - struct ir_raw_event ev = { .pulse = false, .duration = 0 }; + DEFINE_IR_RAW_EVENT(ev); + ev.reset = true; + ir_raw_event_store(input_dev, &ev); ir_raw_event_handle(input_dev); } -- cgit v1.2.3 From 024fafbac36b176d978ccd0fb1cae1fbc38c7fee Mon Sep 17 00:00:00 2001 From: Jonathan Corbet Date: Tue, 19 Oct 2010 21:32:11 -0300 Subject: [media] Add the via framebuffer camera controller driver Add a driver for the video capture port on VIA integrated chipsets. This version has a remaining OLPCism or two and expects to be talking to an ov7670; those can be improved as the need arises. This work was supported by the One Laptop Per Child project. Thanks to Laurent Pinchart for a number of useful comments. Cc: Florian Tobias Schandinat Signed-off-by: Jonathan Corbet Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/Kconfig | 10 + drivers/media/video/Makefile | 2 + drivers/media/video/via-camera.c | 1474 ++++++++++++++++++++++++++++++++++++++ drivers/media/video/via-camera.h | 93 +++ drivers/video/via/accel.c | 2 +- drivers/video/via/via-core.c | 16 +- include/linux/via-core.h | 4 +- include/media/v4l2-chip-ident.h | 4 + 8 files changed, 1601 insertions(+), 4 deletions(-) create mode 100644 drivers/media/video/via-camera.c create mode 100644 drivers/media/video/via-camera.h (limited to 'include') diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index 2d4226710ed5..0efbb29a1a08 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig @@ -712,6 +712,16 @@ config VIDEO_SR030PC30 ---help--- This driver supports SR030PC30 VGA camera from Siliconfile +config VIDEO_VIA_CAMERA + tristate "VIAFB camera controller support" + depends on FB_VIA + select VIDEOBUF_DMA_SG + select VIDEO_OV7670 + help + Driver support for the integrated camera controller in VIA + Chrome9 chipsets. Currently only tested on OLPC xo-1.5 systems + with ov7670 sensors. + config SOC_CAMERA tristate "SoC camera support" depends on VIDEO_V4L2 && HAS_DMA && I2C diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index d5e49ddbf9dd..af79d476a4c8 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile @@ -122,6 +122,8 @@ obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o +obj-$(CONFIG_VIDEO_VIA_CAMERA) += via-camera.o + obj-$(CONFIG_USB_DABUSB) += dabusb.o obj-$(CONFIG_USB_SE401) += se401.o obj-$(CONFIG_USB_ZR364XX) += zr364xx.o diff --git a/drivers/media/video/via-camera.c b/drivers/media/video/via-camera.c new file mode 100644 index 000000000000..02a21bccae18 --- /dev/null +++ b/drivers/media/video/via-camera.c @@ -0,0 +1,1474 @@ +/* + * Driver for the VIA Chrome integrated camera controller. + * + * Copyright 2009,2010 Jonathan Corbet + * Distributable under the terms of the GNU General Public License, version 2 + * + * This work was supported by the One Laptop Per Child project + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "via-camera.h" + +MODULE_AUTHOR("Jonathan Corbet "); +MODULE_DESCRIPTION("VIA framebuffer-based camera controller driver"); +MODULE_LICENSE("GPL"); + +static int flip_image; +module_param(flip_image, bool, 0444); +MODULE_PARM_DESC(flip_image, + "If set, the sensor will be instructed to flip the image " + "vertically."); + +#ifdef CONFIG_OLPC_XO_1_5 +static int override_serial; +module_param(override_serial, bool, 0444); +MODULE_PARM_DESC(override_serial, + "The camera driver will normally refuse to load if " + "the XO 1.5 serial port is enabled. Set this option " + "to force the issue."); +#endif + +/* + * Basic window sizes. + */ +#define VGA_WIDTH 640 +#define VGA_HEIGHT 480 +#define QCIF_WIDTH 176 +#define QCIF_HEIGHT 144 + +/* + * The structure describing our camera. + */ +enum viacam_opstate { S_IDLE = 0, S_RUNNING = 1 }; + +struct via_camera { + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct v4l2_subdev *sensor; + struct platform_device *platdev; + struct viafb_dev *viadev; + struct mutex lock; + enum viacam_opstate opstate; + unsigned long flags; + struct pm_qos_request_list qos_request; + /* + * GPIO info for power/reset management + */ + int power_gpio; + int reset_gpio; + /* + * I/O memory stuff. + */ + void __iomem *mmio; /* Where the registers live */ + void __iomem *fbmem; /* Frame buffer memory */ + u32 fb_offset; /* Reserved memory offset (FB) */ + /* + * Capture buffers and related. The controller supports + * up to three, so that's what we have here. These buffers + * live in frame buffer memory, so we don't call them "DMA". + */ + unsigned int cb_offsets[3]; /* offsets into fb mem */ + u8 *cb_addrs[3]; /* Kernel-space addresses */ + int n_cap_bufs; /* How many are we using? */ + int next_buf; + struct videobuf_queue vb_queue; + struct list_head buffer_queue; /* prot. by reg_lock */ + /* + * User tracking. + */ + int users; + struct file *owner; + /* + * Video format information. sensor_format is kept in a form + * that we can use to pass to the sensor. We always run the + * sensor in VGA resolution, though, and let the controller + * downscale things if need be. So we keep the "real* + * dimensions separately. + */ + struct v4l2_pix_format sensor_format; + struct v4l2_pix_format user_format; + enum v4l2_mbus_pixelcode mbus_code; +}; + +/* + * Yes, this is a hack, but there's only going to be one of these + * on any system we know of. + */ +static struct via_camera *via_cam_info; + +/* + * Flag values, manipulated with bitops + */ +#define CF_DMA_ACTIVE 0 /* A frame is incoming */ +#define CF_CONFIG_NEEDED 1 /* Must configure hardware */ + + +/* + * Nasty ugly v4l2 boilerplate. + */ +#define sensor_call(cam, optype, func, args...) \ + v4l2_subdev_call(cam->sensor, optype, func, ##args) + +/* + * Debugging and related. + */ +#define cam_err(cam, fmt, arg...) \ + dev_err(&(cam)->platdev->dev, fmt, ##arg); +#define cam_warn(cam, fmt, arg...) \ + dev_warn(&(cam)->platdev->dev, fmt, ##arg); +#define cam_dbg(cam, fmt, arg...) \ + dev_dbg(&(cam)->platdev->dev, fmt, ##arg); + +/* + * Format handling. This is ripped almost directly from Hans's changes + * to cafe_ccic.c. It's a little unfortunate; until this change, we + * didn't need to know anything about the format except its byte depth; + * now this information must be managed at this level too. + */ +static struct via_format { + __u8 *desc; + __u32 pixelformat; + int bpp; /* Bytes per pixel */ + enum v4l2_mbus_pixelcode mbus_code; +} via_formats[] = { + { + .desc = "YUYV 4:2:2", + .pixelformat = V4L2_PIX_FMT_YUYV, + .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8, + .bpp = 2, + }, + { + .desc = "RGB 565", + .pixelformat = V4L2_PIX_FMT_RGB565, + .mbus_code = V4L2_MBUS_FMT_RGB565_2X8_LE, + .bpp = 2, + }, + /* RGB444 and Bayer should be doable, but have never been + tested with this driver. */ +}; +#define N_VIA_FMTS ARRAY_SIZE(via_formats) + +static struct via_format *via_find_format(u32 pixelformat) +{ + unsigned i; + + for (i = 0; i < N_VIA_FMTS; i++) + if (via_formats[i].pixelformat == pixelformat) + return via_formats + i; + /* Not found? Then return the first format. */ + return via_formats; +} + + +/*--------------------------------------------------------------------------*/ +/* + * Sensor power/reset management. This piece is OLPC-specific for + * sure; other configurations will have things connected differently. + */ +static int via_sensor_power_setup(struct via_camera *cam) +{ + int ret; + + cam->power_gpio = viafb_gpio_lookup("VGPIO3"); + cam->reset_gpio = viafb_gpio_lookup("VGPIO2"); + if (cam->power_gpio < 0 || cam->reset_gpio < 0) { + dev_err(&cam->platdev->dev, "Unable to find GPIO lines\n"); + return -EINVAL; + } + ret = gpio_request(cam->power_gpio, "viafb-camera"); + if (ret) { + dev_err(&cam->platdev->dev, "Unable to request power GPIO\n"); + return ret; + } + ret = gpio_request(cam->reset_gpio, "viafb-camera"); + if (ret) { + dev_err(&cam->platdev->dev, "Unable to request reset GPIO\n"); + gpio_free(cam->power_gpio); + return ret; + } + gpio_direction_output(cam->power_gpio, 0); + gpio_direction_output(cam->reset_gpio, 0); + return 0; +} + +/* + * Power up the sensor and perform the reset dance. + */ +static void via_sensor_power_up(struct via_camera *cam) +{ + gpio_set_value(cam->power_gpio, 1); + gpio_set_value(cam->reset_gpio, 0); + msleep(20); /* Probably excessive */ + gpio_set_value(cam->reset_gpio, 1); + msleep(20); +} + +static void via_sensor_power_down(struct via_camera *cam) +{ + gpio_set_value(cam->power_gpio, 0); + gpio_set_value(cam->reset_gpio, 0); +} + + +static void via_sensor_power_release(struct via_camera *cam) +{ + via_sensor_power_down(cam); + gpio_free(cam->power_gpio); + gpio_free(cam->reset_gpio); +} + +/* --------------------------------------------------------------------------*/ +/* Sensor ops */ + +/* + * Manage the ov7670 "flip" bit, which needs special help. + */ +static int viacam_set_flip(struct via_camera *cam) +{ + struct v4l2_control ctrl; + + memset(&ctrl, 0, sizeof(ctrl)); + ctrl.id = V4L2_CID_VFLIP; + ctrl.value = flip_image; + return sensor_call(cam, core, s_ctrl, &ctrl); +} + +/* + * Configure the sensor. It's up to the caller to ensure + * that the camera is in the correct operating state. + */ +static int viacam_configure_sensor(struct via_camera *cam) +{ + struct v4l2_mbus_framefmt mbus_fmt; + int ret; + + v4l2_fill_mbus_format(&mbus_fmt, &cam->sensor_format, cam->mbus_code); + ret = sensor_call(cam, core, init, 0); + if (ret == 0) + ret = sensor_call(cam, video, s_mbus_fmt, &mbus_fmt); + /* + * OV7670 does weird things if flip is set *before* format... + */ + if (ret == 0) + ret = viacam_set_flip(cam); + return ret; +} + + + +/* --------------------------------------------------------------------------*/ +/* + * Some simple register accessors; they assume that the lock is held. + * + * Should we want to support the second capture engine, we could + * hide the register difference by adding 0x1000 to registers in the + * 0x300-350 range. + */ +static inline void viacam_write_reg(struct via_camera *cam, + int reg, int value) +{ + iowrite32(value, cam->mmio + reg); +} + +static inline int viacam_read_reg(struct via_camera *cam, int reg) +{ + return ioread32(cam->mmio + reg); +} + +static inline void viacam_write_reg_mask(struct via_camera *cam, + int reg, int value, int mask) +{ + int tmp = viacam_read_reg(cam, reg); + + tmp = (tmp & ~mask) | (value & mask); + viacam_write_reg(cam, reg, tmp); +} + + +/* --------------------------------------------------------------------------*/ +/* Interrupt management and handling */ + +static irqreturn_t viacam_quick_irq(int irq, void *data) +{ + struct via_camera *cam = data; + irqreturn_t ret = IRQ_NONE; + int icv; + + /* + * All we do here is to clear the interrupts and tell + * the handler thread to wake up. + */ + spin_lock(&cam->viadev->reg_lock); + icv = viacam_read_reg(cam, VCR_INTCTRL); + if (icv & VCR_IC_EAV) { + icv |= VCR_IC_EAV|VCR_IC_EVBI|VCR_IC_FFULL; + viacam_write_reg(cam, VCR_INTCTRL, icv); + ret = IRQ_WAKE_THREAD; + } + spin_unlock(&cam->viadev->reg_lock); + return ret; +} + +/* + * Find the next videobuf buffer which has somebody waiting on it. + */ +static struct videobuf_buffer *viacam_next_buffer(struct via_camera *cam) +{ + unsigned long flags; + struct videobuf_buffer *buf = NULL; + + spin_lock_irqsave(&cam->viadev->reg_lock, flags); + if (cam->opstate != S_RUNNING) + goto out; + if (list_empty(&cam->buffer_queue)) + goto out; + buf = list_entry(cam->buffer_queue.next, struct videobuf_buffer, queue); + if (!waitqueue_active(&buf->done)) {/* Nobody waiting */ + buf = NULL; + goto out; + } + list_del(&buf->queue); + buf->state = VIDEOBUF_ACTIVE; +out: + spin_unlock_irqrestore(&cam->viadev->reg_lock, flags); + return buf; +} + +/* + * The threaded IRQ handler. + */ +static irqreturn_t viacam_irq(int irq, void *data) +{ + int bufn; + struct videobuf_buffer *vb; + struct via_camera *cam = data; + struct videobuf_dmabuf *vdma; + + /* + * If there is no place to put the data frame, don't bother + * with anything else. + */ + vb = viacam_next_buffer(cam); + if (vb == NULL) + goto done; + /* + * Figure out which buffer we just completed. + */ + bufn = (viacam_read_reg(cam, VCR_INTCTRL) & VCR_IC_ACTBUF) >> 3; + bufn -= 1; + if (bufn < 0) + bufn = cam->n_cap_bufs - 1; + /* + * Copy over the data and let any waiters know. + */ + vdma = videobuf_to_dma(vb); + viafb_dma_copy_out_sg(cam->cb_offsets[bufn], vdma->sglist, vdma->sglen); + vb->state = VIDEOBUF_DONE; + vb->size = cam->user_format.sizeimage; + wake_up(&vb->done); +done: + return IRQ_HANDLED; +} + + +/* + * These functions must mess around with the general interrupt + * control register, which is relevant to much more than just the + * camera. Nothing else uses interrupts, though, as of this writing. + * Should that situation change, we'll have to improve support at + * the via-core level. + */ +static void viacam_int_enable(struct via_camera *cam) +{ + viacam_write_reg(cam, VCR_INTCTRL, + VCR_IC_INTEN|VCR_IC_EAV|VCR_IC_EVBI|VCR_IC_FFULL); + viafb_irq_enable(VDE_I_C0AVEN); +} + +static void viacam_int_disable(struct via_camera *cam) +{ + viafb_irq_disable(VDE_I_C0AVEN); + viacam_write_reg(cam, VCR_INTCTRL, 0); +} + + + +/* --------------------------------------------------------------------------*/ +/* Controller operations */ + +/* + * Set up our capture buffers in framebuffer memory. + */ +static int viacam_ctlr_cbufs(struct via_camera *cam) +{ + int nbuf = cam->viadev->camera_fbmem_size/cam->sensor_format.sizeimage; + int i; + unsigned int offset; + + /* + * See how many buffers we can work with. + */ + if (nbuf >= 3) { + cam->n_cap_bufs = 3; + viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_3BUFS, + VCR_CI_3BUFS); + } else if (nbuf == 2) { + cam->n_cap_bufs = 2; + viacam_write_reg_mask(cam, VCR_CAPINTC, 0, VCR_CI_3BUFS); + } else { + cam_warn(cam, "Insufficient frame buffer memory\n"); + return -ENOMEM; + } + /* + * Set them up. + */ + offset = cam->fb_offset; + for (i = 0; i < cam->n_cap_bufs; i++) { + cam->cb_offsets[i] = offset; + cam->cb_addrs[i] = cam->fbmem + offset; + viacam_write_reg(cam, VCR_VBUF1 + i*4, offset & VCR_VBUF_MASK); + offset += cam->sensor_format.sizeimage; + } + return 0; +} + +/* + * Set the scaling register for downscaling the image. + * + * This register works like this... Vertical scaling is enabled + * by bit 26; if that bit is set, downscaling is controlled by the + * value in bits 16:25. Those bits are divided by 1024 to get + * the scaling factor; setting just bit 25 thus cuts the height + * in half. + * + * Horizontal scaling works about the same, but it's enabled by + * bit 11, with bits 0:10 giving the numerator of a fraction + * (over 2048) for the scaling value. + * + * This function is naive in that, if the user departs from + * the 3x4 VGA scaling factor, the image will distort. We + * could work around that if it really seemed important. + */ +static void viacam_set_scale(struct via_camera *cam) +{ + unsigned int avscale; + int sf; + + if (cam->user_format.width == VGA_WIDTH) + avscale = 0; + else { + sf = (cam->user_format.width*2048)/VGA_WIDTH; + avscale = VCR_AVS_HEN | sf; + } + if (cam->user_format.height < VGA_HEIGHT) { + sf = (1024*cam->user_format.height)/VGA_HEIGHT; + avscale |= VCR_AVS_VEN | (sf << 16); + } + viacam_write_reg(cam, VCR_AVSCALE, avscale); +} + + +/* + * Configure image-related information into the capture engine. + */ +static void viacam_ctlr_image(struct via_camera *cam) +{ + int cicreg; + + /* + * Disable clock before messing with stuff - from the via + * sample driver. + */ + viacam_write_reg(cam, VCR_CAPINTC, ~(VCR_CI_ENABLE|VCR_CI_CLKEN)); + /* + * Set up the controller for VGA resolution, modulo magic + * offsets from the via sample driver. + */ + viacam_write_reg(cam, VCR_HORRANGE, 0x06200120); + viacam_write_reg(cam, VCR_VERTRANGE, 0x01de0000); + viacam_set_scale(cam); + /* + * Image size info. + */ + viacam_write_reg(cam, VCR_MAXDATA, + (cam->sensor_format.height << 16) | + (cam->sensor_format.bytesperline >> 3)); + viacam_write_reg(cam, VCR_MAXVBI, 0); + viacam_write_reg(cam, VCR_VSTRIDE, + cam->user_format.bytesperline & VCR_VS_STRIDE); + /* + * Set up the capture interface control register, + * everything but the "go" bit. + * + * The FIFO threshold is a bit of a magic number; 8 is what + * VIA's sample code uses. + */ + cicreg = VCR_CI_CLKEN | + 0x08000000 | /* FIFO threshold */ + VCR_CI_FLDINV | /* OLPC-specific? */ + VCR_CI_VREFINV | /* OLPC-specific? */ + VCR_CI_DIBOTH | /* Capture both fields */ + VCR_CI_CCIR601_8; + if (cam->n_cap_bufs == 3) + cicreg |= VCR_CI_3BUFS; + /* + * YUV formats need different byte swapping than RGB. + */ + if (cam->user_format.pixelformat == V4L2_PIX_FMT_YUYV) + cicreg |= VCR_CI_YUYV; + else + cicreg |= VCR_CI_UYVY; + viacam_write_reg(cam, VCR_CAPINTC, cicreg); +} + + +static int viacam_config_controller(struct via_camera *cam) +{ + int ret; + unsigned long flags; + + spin_lock_irqsave(&cam->viadev->reg_lock, flags); + ret = viacam_ctlr_cbufs(cam); + if (!ret) + viacam_ctlr_image(cam); + spin_unlock_irqrestore(&cam->viadev->reg_lock, flags); + clear_bit(CF_CONFIG_NEEDED, &cam->flags); + return ret; +} + +/* + * Make it start grabbing data. + */ +static void viacam_start_engine(struct via_camera *cam) +{ + spin_lock_irq(&cam->viadev->reg_lock); + cam->next_buf = 0; + viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_ENABLE, VCR_CI_ENABLE); + viacam_int_enable(cam); + (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ + cam->opstate = S_RUNNING; + spin_unlock_irq(&cam->viadev->reg_lock); +} + + +static void viacam_stop_engine(struct via_camera *cam) +{ + spin_lock_irq(&cam->viadev->reg_lock); + viacam_int_disable(cam); + viacam_write_reg_mask(cam, VCR_CAPINTC, 0, VCR_CI_ENABLE); + (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ + cam->opstate = S_IDLE; + spin_unlock_irq(&cam->viadev->reg_lock); +} + + +/* --------------------------------------------------------------------------*/ +/* Videobuf callback ops */ + +/* + * buffer_setup. The purpose of this one would appear to be to tell + * videobuf how big a single image is. It's also evidently up to us + * to put some sort of limit on the maximum number of buffers allowed. + */ +static int viacam_vb_buf_setup(struct videobuf_queue *q, + unsigned int *count, unsigned int *size) +{ + struct via_camera *cam = q->priv_data; + + *size = cam->user_format.sizeimage; + if (*count == 0 || *count > 6) /* Arbitrary number */ + *count = 6; + return 0; +} + +/* + * Prepare a buffer. + */ +static int viacam_vb_buf_prepare(struct videobuf_queue *q, + struct videobuf_buffer *vb, enum v4l2_field field) +{ + struct via_camera *cam = q->priv_data; + + vb->size = cam->user_format.sizeimage; + vb->width = cam->user_format.width; /* bytesperline???? */ + vb->height = cam->user_format.height; + vb->field = field; + if (vb->state == VIDEOBUF_NEEDS_INIT) { + int ret = videobuf_iolock(q, vb, NULL); + if (ret) + return ret; + } + vb->state = VIDEOBUF_PREPARED; + return 0; +} + +/* + * We've got a buffer to put data into. + * + * FIXME: check for a running engine and valid buffers? + */ +static void viacam_vb_buf_queue(struct videobuf_queue *q, + struct videobuf_buffer *vb) +{ + struct via_camera *cam = q->priv_data; + + /* + * Note that videobuf holds the lock when it calls + * us, so we need not (indeed, cannot) take it here. + */ + vb->state = VIDEOBUF_QUEUED; + list_add_tail(&vb->queue, &cam->buffer_queue); +} + +/* + * Free a buffer. + */ +static void viacam_vb_buf_release(struct videobuf_queue *q, + struct videobuf_buffer *vb) +{ + struct via_camera *cam = q->priv_data; + + videobuf_dma_unmap(&cam->platdev->dev, videobuf_to_dma(vb)); + videobuf_dma_free(videobuf_to_dma(vb)); + vb->state = VIDEOBUF_NEEDS_INIT; +} + +static const struct videobuf_queue_ops viacam_vb_ops = { + .buf_setup = viacam_vb_buf_setup, + .buf_prepare = viacam_vb_buf_prepare, + .buf_queue = viacam_vb_buf_queue, + .buf_release = viacam_vb_buf_release, +}; + +/* --------------------------------------------------------------------------*/ +/* File operations */ + +static int viacam_open(struct file *filp) +{ + struct via_camera *cam = video_drvdata(filp); + + filp->private_data = cam; + /* + * Note the new user. If this is the first one, we'll also + * need to power up the sensor. + */ + mutex_lock(&cam->lock); + if (cam->users == 0) { + int ret = viafb_request_dma(); + + if (ret) { + mutex_unlock(&cam->lock); + return ret; + } + via_sensor_power_up(cam); + set_bit(CF_CONFIG_NEEDED, &cam->flags); + /* + * Hook into videobuf. Evidently this cannot fail. + */ + videobuf_queue_sg_init(&cam->vb_queue, &viacam_vb_ops, + &cam->platdev->dev, &cam->viadev->reg_lock, + V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, + sizeof(struct videobuf_buffer), cam, NULL); + } + (cam->users)++; + mutex_unlock(&cam->lock); + return 0; +} + +static int viacam_release(struct file *filp) +{ + struct via_camera *cam = video_drvdata(filp); + + mutex_lock(&cam->lock); + (cam->users)--; + /* + * If the "owner" is closing, shut down any ongoing + * operations. + */ + if (filp == cam->owner) { + videobuf_stop(&cam->vb_queue); + /* + * We don't hold the spinlock here, but, if release() + * is being called by the owner, nobody else will + * be changing the state. And an extra stop would + * not hurt anyway. + */ + if (cam->opstate != S_IDLE) + viacam_stop_engine(cam); + cam->owner = NULL; + } + /* + * Last one out needs to turn out the lights. + */ + if (cam->users == 0) { + videobuf_mmap_free(&cam->vb_queue); + via_sensor_power_down(cam); + viafb_release_dma(); + } + mutex_unlock(&cam->lock); + return 0; +} + +/* + * Read a frame from the device. + */ +static ssize_t viacam_read(struct file *filp, char __user *buffer, + size_t len, loff_t *pos) +{ + struct via_camera *cam = video_drvdata(filp); + int ret; + + mutex_lock(&cam->lock); + /* + * Enforce the V4l2 "only one owner gets to read data" rule. + */ + if (cam->owner && cam->owner != filp) { + ret = -EBUSY; + goto out_unlock; + } + cam->owner = filp; + /* + * Do we need to configure the hardware? + */ + if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { + ret = viacam_configure_sensor(cam); + if (!ret) + ret = viacam_config_controller(cam); + if (ret) + goto out_unlock; + } + /* + * Fire up the capture engine, then have videobuf do + * the heavy lifting. Someday it would be good to avoid + * stopping and restarting the engine each time. + */ + INIT_LIST_HEAD(&cam->buffer_queue); + viacam_start_engine(cam); + ret = videobuf_read_stream(&cam->vb_queue, buffer, len, pos, 0, + filp->f_flags & O_NONBLOCK); + viacam_stop_engine(cam); + /* videobuf_stop() ?? */ + +out_unlock: + mutex_unlock(&cam->lock); + return ret; +} + + +static unsigned int viacam_poll(struct file *filp, struct poll_table_struct *pt) +{ + struct via_camera *cam = video_drvdata(filp); + + return videobuf_poll_stream(filp, &cam->vb_queue, pt); +} + + +static int viacam_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct via_camera *cam = video_drvdata(filp); + + return videobuf_mmap_mapper(&cam->vb_queue, vma); +} + + + +static const struct v4l2_file_operations viacam_fops = { + .owner = THIS_MODULE, + .open = viacam_open, + .release = viacam_release, + .read = viacam_read, + .poll = viacam_poll, + .mmap = viacam_mmap, + .unlocked_ioctl = video_ioctl2, +}; + +/*----------------------------------------------------------------------------*/ +/* + * The long list of v4l2 ioctl ops + */ + +static int viacam_g_chip_ident(struct file *file, void *priv, + struct v4l2_dbg_chip_ident *ident) +{ + struct via_camera *cam = priv; + + ident->ident = V4L2_IDENT_NONE; + ident->revision = 0; + if (v4l2_chip_match_host(&ident->match)) { + ident->ident = V4L2_IDENT_VIA_VX855; + return 0; + } + return sensor_call(cam, core, g_chip_ident, ident); +} + +/* + * Control ops are passed through to the sensor. + */ +static int viacam_queryctrl(struct file *filp, void *priv, + struct v4l2_queryctrl *qc) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, core, queryctrl, qc); + mutex_unlock(&cam->lock); + return ret; +} + + +static int viacam_g_ctrl(struct file *filp, void *priv, + struct v4l2_control *ctrl) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, core, g_ctrl, ctrl); + mutex_unlock(&cam->lock); + return ret; +} + + +static int viacam_s_ctrl(struct file *filp, void *priv, + struct v4l2_control *ctrl) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, core, s_ctrl, ctrl); + mutex_unlock(&cam->lock); + return ret; +} + +/* + * Only one input. + */ +static int viacam_enum_input(struct file *filp, void *priv, + struct v4l2_input *input) +{ + if (input->index != 0) + return -EINVAL; + + input->type = V4L2_INPUT_TYPE_CAMERA; + input->std = V4L2_STD_ALL; /* Not sure what should go here */ + strcpy(input->name, "Camera"); + return 0; +} + +static int viacam_g_input(struct file *filp, void *priv, unsigned int *i) +{ + *i = 0; + return 0; +} + +static int viacam_s_input(struct file *filp, void *priv, unsigned int i) +{ + if (i != 0) + return -EINVAL; + return 0; +} + +static int viacam_s_std(struct file *filp, void *priv, v4l2_std_id *std) +{ + return 0; +} + +/* + * Video format stuff. Here is our default format until + * user space messes with things. + */ +static const struct v4l2_pix_format viacam_def_pix_format = { + .width = VGA_WIDTH, + .height = VGA_HEIGHT, + .pixelformat = V4L2_PIX_FMT_YUYV, + .field = V4L2_FIELD_NONE, + .bytesperline = VGA_WIDTH * 2, + .sizeimage = VGA_WIDTH * VGA_HEIGHT * 2, +}; + +static const enum v4l2_mbus_pixelcode via_def_mbus_code = V4L2_MBUS_FMT_YUYV8_2X8; + +static int viacam_enum_fmt_vid_cap(struct file *filp, void *priv, + struct v4l2_fmtdesc *fmt) +{ + if (fmt->index >= N_VIA_FMTS) + return -EINVAL; + strlcpy(fmt->description, via_formats[fmt->index].desc, + sizeof(fmt->description)); + fmt->pixelformat = via_formats[fmt->index].pixelformat; + return 0; +} + +/* + * Figure out proper image dimensions, but always force the + * sensor to VGA. + */ +static void viacam_fmt_pre(struct v4l2_pix_format *userfmt, + struct v4l2_pix_format *sensorfmt) +{ + *sensorfmt = *userfmt; + if (userfmt->width < QCIF_WIDTH || userfmt->height < QCIF_HEIGHT) { + userfmt->width = QCIF_WIDTH; + userfmt->height = QCIF_HEIGHT; + } + if (userfmt->width > VGA_WIDTH || userfmt->height > VGA_HEIGHT) { + userfmt->width = VGA_WIDTH; + userfmt->height = VGA_HEIGHT; + } + sensorfmt->width = VGA_WIDTH; + sensorfmt->height = VGA_HEIGHT; +} + +static void viacam_fmt_post(struct v4l2_pix_format *userfmt, + struct v4l2_pix_format *sensorfmt) +{ + struct via_format *f = via_find_format(userfmt->pixelformat); + + sensorfmt->bytesperline = sensorfmt->width * f->bpp; + sensorfmt->sizeimage = sensorfmt->height * sensorfmt->bytesperline; + userfmt->pixelformat = sensorfmt->pixelformat; + userfmt->field = sensorfmt->field; + userfmt->bytesperline = 2 * userfmt->width; + userfmt->sizeimage = userfmt->bytesperline * userfmt->height; +} + + +/* + * The real work of figuring out a workable format. + */ +static int viacam_do_try_fmt(struct via_camera *cam, + struct v4l2_pix_format *upix, struct v4l2_pix_format *spix) +{ + int ret; + struct v4l2_mbus_framefmt mbus_fmt; + struct via_format *f = via_find_format(upix->pixelformat); + + upix->pixelformat = f->pixelformat; + viacam_fmt_pre(upix, spix); + v4l2_fill_mbus_format(&mbus_fmt, upix, f->mbus_code); + ret = sensor_call(cam, video, try_mbus_fmt, &mbus_fmt); + v4l2_fill_pix_format(spix, &mbus_fmt); + viacam_fmt_post(upix, spix); + return ret; +} + + + +static int viacam_try_fmt_vid_cap(struct file *filp, void *priv, + struct v4l2_format *fmt) +{ + struct via_camera *cam = priv; + struct v4l2_format sfmt; + int ret; + + mutex_lock(&cam->lock); + ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); + mutex_unlock(&cam->lock); + return ret; +} + + +static int viacam_g_fmt_vid_cap(struct file *filp, void *priv, + struct v4l2_format *fmt) +{ + struct via_camera *cam = priv; + + mutex_lock(&cam->lock); + fmt->fmt.pix = cam->user_format; + mutex_unlock(&cam->lock); + return 0; +} + +static int viacam_s_fmt_vid_cap(struct file *filp, void *priv, + struct v4l2_format *fmt) +{ + struct via_camera *cam = priv; + int ret; + struct v4l2_format sfmt; + struct via_format *f = via_find_format(fmt->fmt.pix.pixelformat); + + /* + * Camera must be idle or we can't mess with the + * video setup. + */ + mutex_lock(&cam->lock); + if (cam->opstate != S_IDLE) { + ret = -EBUSY; + goto out; + } + /* + * Let the sensor code look over and tweak the + * requested formatting. + */ + ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); + if (ret) + goto out; + /* + * OK, let's commit to the new format. + */ + cam->user_format = fmt->fmt.pix; + cam->sensor_format = sfmt.fmt.pix; + cam->mbus_code = f->mbus_code; + ret = viacam_configure_sensor(cam); + if (!ret) + ret = viacam_config_controller(cam); +out: + mutex_unlock(&cam->lock); + return ret; +} + +static int viacam_querycap(struct file *filp, void *priv, + struct v4l2_capability *cap) +{ + strcpy(cap->driver, "via-camera"); + strcpy(cap->card, "via-camera"); + cap->version = 1; + cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; + return 0; +} + +/* + * Streaming operations - pure videobuf stuff. + */ +static int viacam_reqbufs(struct file *filp, void *priv, + struct v4l2_requestbuffers *rb) +{ + struct via_camera *cam = priv; + + return videobuf_reqbufs(&cam->vb_queue, rb); +} + +static int viacam_querybuf(struct file *filp, void *priv, + struct v4l2_buffer *buf) +{ + struct via_camera *cam = priv; + + return videobuf_querybuf(&cam->vb_queue, buf); +} + +static int viacam_qbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) +{ + struct via_camera *cam = priv; + + return videobuf_qbuf(&cam->vb_queue, buf); +} + +static int viacam_dqbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) +{ + struct via_camera *cam = priv; + + return videobuf_dqbuf(&cam->vb_queue, buf, filp->f_flags & O_NONBLOCK); +} + +static int viacam_streamon(struct file *filp, void *priv, enum v4l2_buf_type t) +{ + struct via_camera *cam = priv; + int ret = 0; + + if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + mutex_lock(&cam->lock); + if (cam->opstate != S_IDLE) { + ret = -EBUSY; + goto out; + } + /* + * Enforce the V4l2 "only one owner gets to read data" rule. + */ + if (cam->owner && cam->owner != filp) { + ret = -EBUSY; + goto out; + } + cam->owner = filp; + /* + * Configure things if need be. + */ + if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { + ret = viacam_configure_sensor(cam); + if (ret) + goto out; + ret = viacam_config_controller(cam); + if (ret) + goto out; + } + /* + * If the CPU goes into C3, the DMA transfer gets corrupted and + * users start filing unsightly bug reports. Put in a "latency" + * requirement which will keep the CPU out of the deeper sleep + * states. + */ + pm_qos_add_request(&cam->qos_request, PM_QOS_CPU_DMA_LATENCY, 50); + /* + * Fire things up. + */ + INIT_LIST_HEAD(&cam->buffer_queue); + ret = videobuf_streamon(&cam->vb_queue); + if (!ret) + viacam_start_engine(cam); +out: + mutex_unlock(&cam->lock); + return ret; +} + +static int viacam_streamoff(struct file *filp, void *priv, enum v4l2_buf_type t) +{ + struct via_camera *cam = priv; + int ret; + + if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + mutex_lock(&cam->lock); + if (cam->opstate != S_RUNNING) { + ret = -EINVAL; + goto out; + } + pm_qos_remove_request(&cam->qos_request); + viacam_stop_engine(cam); + /* + * Videobuf will recycle all of the outstanding buffers, but + * we should be sure we don't retain any references to + * any of them. + */ + ret = videobuf_streamoff(&cam->vb_queue); + INIT_LIST_HEAD(&cam->buffer_queue); +out: + mutex_unlock(&cam->lock); + return ret; +} + +#ifdef CONFIG_VIDEO_V4L1_COMPAT +static int viacam_vidiocgmbuf(struct file *filp, void *priv, + struct video_mbuf *mbuf) +{ + struct via_camera *cam = priv; + + return videobuf_cgmbuf(&cam->vb_queue, mbuf, 6); +} +#endif + +/* G/S_PARM */ + +static int viacam_g_parm(struct file *filp, void *priv, + struct v4l2_streamparm *parm) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, video, g_parm, parm); + mutex_unlock(&cam->lock); + parm->parm.capture.readbuffers = cam->n_cap_bufs; + return ret; +} + +static int viacam_s_parm(struct file *filp, void *priv, + struct v4l2_streamparm *parm) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, video, s_parm, parm); + mutex_unlock(&cam->lock); + parm->parm.capture.readbuffers = cam->n_cap_bufs; + return ret; +} + +static int viacam_enum_framesizes(struct file *filp, void *priv, + struct v4l2_frmsizeenum *sizes) +{ + if (sizes->index != 0) + return -EINVAL; + sizes->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; + sizes->stepwise.min_width = QCIF_WIDTH; + sizes->stepwise.min_height = QCIF_HEIGHT; + sizes->stepwise.max_width = VGA_WIDTH; + sizes->stepwise.max_height = VGA_HEIGHT; + sizes->stepwise.step_width = sizes->stepwise.step_height = 1; + return 0; +} + +static int viacam_enum_frameintervals(struct file *filp, void *priv, + struct v4l2_frmivalenum *interval) +{ + struct via_camera *cam = priv; + int ret; + + mutex_lock(&cam->lock); + ret = sensor_call(cam, video, enum_frameintervals, interval); + mutex_unlock(&cam->lock); + return ret; +} + + + +static const struct v4l2_ioctl_ops viacam_ioctl_ops = { + .vidioc_g_chip_ident = viacam_g_chip_ident, + .vidioc_queryctrl = viacam_queryctrl, + .vidioc_g_ctrl = viacam_g_ctrl, + .vidioc_s_ctrl = viacam_s_ctrl, + .vidioc_enum_input = viacam_enum_input, + .vidioc_g_input = viacam_g_input, + .vidioc_s_input = viacam_s_input, + .vidioc_s_std = viacam_s_std, + .vidioc_enum_fmt_vid_cap = viacam_enum_fmt_vid_cap, + .vidioc_try_fmt_vid_cap = viacam_try_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = viacam_g_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = viacam_s_fmt_vid_cap, + .vidioc_querycap = viacam_querycap, + .vidioc_reqbufs = viacam_reqbufs, + .vidioc_querybuf = viacam_querybuf, + .vidioc_qbuf = viacam_qbuf, + .vidioc_dqbuf = viacam_dqbuf, + .vidioc_streamon = viacam_streamon, + .vidioc_streamoff = viacam_streamoff, + .vidioc_g_parm = viacam_g_parm, + .vidioc_s_parm = viacam_s_parm, + .vidioc_enum_framesizes = viacam_enum_framesizes, + .vidioc_enum_frameintervals = viacam_enum_frameintervals, +#ifdef CONFIG_VIDEO_V4L1_COMPAT + .vidiocgmbuf = viacam_vidiocgmbuf, +#endif +}; + +/*----------------------------------------------------------------------------*/ + +/* + * Power management. + */ + +/* + * Setup stuff. + */ + +static struct video_device viacam_v4l_template = { + .name = "via-camera", + .minor = -1, + .tvnorms = V4L2_STD_NTSC_M, + .current_norm = V4L2_STD_NTSC_M, + .fops = &viacam_fops, + .ioctl_ops = &viacam_ioctl_ops, + .release = video_device_release_empty, /* Check this */ +}; + + +static __devinit int viacam_probe(struct platform_device *pdev) +{ + int ret; + struct i2c_adapter *sensor_adapter; + struct viafb_dev *viadev = pdev->dev.platform_data; + + /* + * Note that there are actually two capture channels on + * the device. We only deal with one for now. That + * is encoded here; nothing else assumes it's dealing with + * a unique capture device. + */ + struct via_camera *cam; + + /* + * Ensure that frame buffer memory has been set aside for + * this purpose. As an arbitrary limit, refuse to work + * with less than two frames of VGA 16-bit data. + * + * If we ever support the second port, we'll need to set + * aside more memory. + */ + if (viadev->camera_fbmem_size < (VGA_HEIGHT*VGA_WIDTH*4)) { + printk(KERN_ERR "viacam: insufficient FB memory reserved\n"); + return -ENOMEM; + } + if (viadev->engine_mmio == NULL) { + printk(KERN_ERR "viacam: No I/O memory, so no pictures\n"); + return -ENOMEM; + } + /* + * Basic structure initialization. + */ + cam = kzalloc (sizeof(struct via_camera), GFP_KERNEL); + if (cam == NULL) + return -ENOMEM; + via_cam_info = cam; + cam->platdev = pdev; + cam->viadev = viadev; + cam->users = 0; + cam->owner = NULL; + cam->opstate = S_IDLE; + cam->user_format = cam->sensor_format = viacam_def_pix_format; + mutex_init(&cam->lock); + INIT_LIST_HEAD(&cam->buffer_queue); + cam->mmio = viadev->engine_mmio; + cam->fbmem = viadev->fbmem; + cam->fb_offset = viadev->camera_fbmem_offset; + cam->flags = 1 << CF_CONFIG_NEEDED; + cam->mbus_code = via_def_mbus_code; + /* + * Tell V4L that we exist. + */ + ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev); + if (ret) { + dev_err(&pdev->dev, "Unable to register v4l2 device\n"); + return ret; + } + /* + * Convince the system that we can do DMA. + */ + pdev->dev.dma_mask = &viadev->pdev->dma_mask; + dma_set_mask(&pdev->dev, 0xffffffff); + /* + * Fire up the capture port. The write to 0x78 looks purely + * OLPCish; any system will need to tweak 0x1e. + */ + via_write_reg_mask(VIASR, 0x78, 0, 0x80); + via_write_reg_mask(VIASR, 0x1e, 0xc0, 0xc0); + /* + * Get the sensor powered up. + */ + ret = via_sensor_power_setup(cam); + if (ret) + goto out_unregister; + via_sensor_power_up(cam); + + /* + * See if we can't find it on the bus. The VIA_PORT_31 assumption + * is OLPC-specific. 0x42 assumption is ov7670-specific. + */ + sensor_adapter = viafb_find_i2c_adapter(VIA_PORT_31); + cam->sensor = v4l2_i2c_new_subdev(&cam->v4l2_dev, sensor_adapter, + "ov7670", "ov7670", 0x42 >> 1, NULL); + if (cam->sensor == NULL) { + dev_err(&pdev->dev, "Unable to find the sensor!\n"); + ret = -ENODEV; + goto out_power_down; + } + /* + * Get the IRQ. + */ + viacam_int_disable(cam); + ret = request_threaded_irq(viadev->pdev->irq, viacam_quick_irq, + viacam_irq, IRQF_SHARED, "via-camera", cam); + if (ret) + goto out_power_down; + /* + * Tell V4l2 that we exist. + */ + cam->vdev = viacam_v4l_template; + cam->vdev.v4l2_dev = &cam->v4l2_dev; + ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); + if (ret) + goto out_irq; + video_set_drvdata(&cam->vdev, cam); + + /* Power the sensor down until somebody opens the device */ + via_sensor_power_down(cam); + return 0; + +out_irq: + free_irq(viadev->pdev->irq, cam); +out_power_down: + via_sensor_power_release(cam); +out_unregister: + v4l2_device_unregister(&cam->v4l2_dev); + return ret; +} + +static __devexit int viacam_remove(struct platform_device *pdev) +{ + struct via_camera *cam = via_cam_info; + struct viafb_dev *viadev = pdev->dev.platform_data; + + video_unregister_device(&cam->vdev); + v4l2_device_unregister(&cam->v4l2_dev); + free_irq(viadev->pdev->irq, cam); + via_sensor_power_release(cam); + via_cam_info = NULL; + return 0; +} + + +static struct platform_driver viacam_driver = { + .driver = { + .name = "viafb-camera", + }, + .probe = viacam_probe, + .remove = viacam_remove, +}; + + +#ifdef CONFIG_OLPC_XO_1_5 +/* + * The OLPC folks put the serial port on the same pin as + * the camera. They also get grumpy if we break the + * serial port and keep them from using it. So we have + * to check the serial enable bit and not step on it. + */ +#define VIACAM_SERIAL_DEVFN 0x88 +#define VIACAM_SERIAL_CREG 0x46 +#define VIACAM_SERIAL_BIT 0x40 + +static __devinit int viacam_check_serial_port(void) +{ + struct pci_bus *pbus = pci_find_bus(0, 0); + u8 cbyte; + + pci_bus_read_config_byte(pbus, VIACAM_SERIAL_DEVFN, + VIACAM_SERIAL_CREG, &cbyte); + if ((cbyte & VIACAM_SERIAL_BIT) == 0) + return 0; /* Not enabled */ + if (override_serial == 0) { + printk(KERN_NOTICE "Via camera: serial port is enabled, " \ + "refusing to load.\n"); + printk(KERN_NOTICE "Specify override_serial=1 to force " \ + "module loading.\n"); + return -EBUSY; + } + printk(KERN_NOTICE "Via camera: overriding serial port\n"); + pci_bus_write_config_byte(pbus, VIACAM_SERIAL_DEVFN, + VIACAM_SERIAL_CREG, cbyte & ~VIACAM_SERIAL_BIT); + return 0; +} +#endif + + + + +static int viacam_init(void) +{ +#ifdef CONFIG_OLPC_XO_1_5 + if (viacam_check_serial_port()) + return -EBUSY; +#endif + return platform_driver_register(&viacam_driver); +} +module_init(viacam_init); + +static void viacam_exit(void) +{ + platform_driver_unregister(&viacam_driver); +} +module_exit(viacam_exit); diff --git a/drivers/media/video/via-camera.h b/drivers/media/video/via-camera.h new file mode 100644 index 000000000000..b12a4b3d616f --- /dev/null +++ b/drivers/media/video/via-camera.h @@ -0,0 +1,93 @@ +/* + * VIA Camera register definitions. + */ +#define VCR_INTCTRL 0x300 /* Capture interrupt control */ +#define VCR_IC_EAV 0x0001 /* End of active video status */ +#define VCR_IC_EVBI 0x0002 /* End of VBI status */ +#define VCR_IC_FBOTFLD 0x0004 /* "flipping" Bottom field is active */ +#define VCR_IC_ACTBUF 0x0018 /* Active video buffer */ +#define VCR_IC_VSYNC 0x0020 /* 0 = VB, 1 = active video */ +#define VCR_IC_BOTFLD 0x0040 /* Bottom field is active */ +#define VCR_IC_FFULL 0x0080 /* FIFO full */ +#define VCR_IC_INTEN 0x0100 /* End of active video int. enable */ +#define VCR_IC_VBIINT 0x0200 /* End of VBI int enable */ +#define VCR_IC_VBIBUF 0x0400 /* Current VBI buffer */ + +#define VCR_TSC 0x308 /* Transport stream control */ +#define VCR_TSC_ENABLE 0x000001 /* Transport stream input enable */ +#define VCR_TSC_DROPERR 0x000002 /* Drop error packets */ +#define VCR_TSC_METHOD 0x00000c /* DMA method (non-functional) */ +#define VCR_TSC_COUNT 0x07fff0 /* KByte or packet count */ +#define VCR_TSC_CBMODE 0x080000 /* Change buffer by byte count */ +#define VCR_TSC_PSSIG 0x100000 /* Packet starting signal disable */ +#define VCR_TSC_BE 0x200000 /* MSB first (serial mode) */ +#define VCR_TSC_SERIAL 0x400000 /* Serial input (0 = parallel) */ + +#define VCR_CAPINTC 0x310 /* Capture interface control */ +#define VCR_CI_ENABLE 0x00000001 /* Capture enable */ +#define VCR_CI_BSS 0x00000002 /* WTF "bit stream selection" */ +#define VCR_CI_3BUFS 0x00000004 /* 1 = 3 buffers, 0 = 2 buffers */ +#define VCR_CI_VIPEN 0x00000008 /* VIP enable */ +#define VCR_CI_CCIR601_8 0 /* CCIR601 input stream, 8 bit */ +#define VCR_CI_CCIR656_8 0x00000010 /* ... CCIR656, 8 bit */ +#define VCR_CI_CCIR601_16 0x00000020 /* ... CCIR601, 16 bit */ +#define VCR_CI_CCIR656_16 0x00000030 /* ... CCIR656, 16 bit */ +#define VCR_CI_HDMODE 0x00000040 /* CCIR656-16 hdr decode mode; 1=16b */ +#define VCR_CI_BSWAP 0x00000080 /* Swap bytes (16-bit) */ +#define VCR_CI_YUYV 0 /* Byte order 0123 */ +#define VCR_CI_UYVY 0x00000100 /* Byte order 1032 */ +#define VCR_CI_YVYU 0x00000200 /* Byte order 0321 */ +#define VCR_CI_VYUY 0x00000300 /* Byte order 3012 */ +#define VCR_CI_VIPTYPE 0x00000400 /* VIP type */ +#define VCR_CI_IFSEN 0x00000800 /* Input field signal enable */ +#define VCR_CI_DIODD 0 /* De-interlace odd, 30fps */ +#define VCR_CI_DIEVEN 0x00001000 /* ...even field, 30fps */ +#define VCR_CI_DIBOTH 0x00002000 /* ...both fields, 60fps */ +#define VCR_CI_DIBOTH30 0x00003000 /* ...both fields, 30fps interlace */ +#define VCR_CI_CONVTYPE 0x00004000 /* 4:2:2 to 4:4:4; 1 = interpolate */ +#define VCR_CI_CFC 0x00008000 /* Capture flipping control */ +#define VCR_CI_FILTER 0x00070000 /* Horiz filter mode select + 000 = none + 001 = 2 tap + 010 = 3 tap + 011 = 4 tap + 100 = 5 tap */ +#define VCR_CI_CLKINV 0x00080000 /* Input CLK inverted */ +#define VCR_CI_VREFINV 0x00100000 /* VREF inverted */ +#define VCR_CI_HREFINV 0x00200000 /* HREF inverted */ +#define VCR_CI_FLDINV 0x00400000 /* Field inverted */ +#define VCR_CI_CLKPIN 0x00800000 /* Capture clock pin */ +#define VCR_CI_THRESH 0x0f000000 /* Capture fifo threshold */ +#define VCR_CI_HRLE 0x10000000 /* Positive edge of HREF */ +#define VCR_CI_VRLE 0x20000000 /* Positive edge of VREF */ +#define VCR_CI_OFLDINV 0x40000000 /* Field output inverted */ +#define VCR_CI_CLKEN 0x80000000 /* Capture clock enable */ + +#define VCR_HORRANGE 0x314 /* Active video horizontal range */ +#define VCR_VERTRANGE 0x318 /* Active video vertical range */ +#define VCR_AVSCALE 0x31c /* Active video scaling control */ +#define VCR_AVS_HEN 0x00000800 /* Horizontal scale enable */ +#define VCR_AVS_VEN 0x04000000 /* Vertical enable */ +#define VCR_VBIHOR 0x320 /* VBI Data horizontal range */ +#define VCR_VBIVERT 0x324 /* VBI data vertical range */ +#define VCR_VBIBUF1 0x328 /* First VBI buffer */ +#define VCR_VBISTRIDE 0x32c /* VBI stride */ +#define VCR_ANCDATACNT 0x330 /* Ancillary data count setting */ +#define VCR_MAXDATA 0x334 /* Active data count of active video */ +#define VCR_MAXVBI 0x338 /* Maximum data count of VBI */ +#define VCR_CAPDATA 0x33c /* Capture data count */ +#define VCR_VBUF1 0x340 /* First video buffer */ +#define VCR_VBUF2 0x344 /* Second video buffer */ +#define VCR_VBUF3 0x348 /* Third video buffer */ +#define VCR_VBUF_MASK 0x1ffffff0 /* Bits 28:4 */ +#define VCR_VBIBUF2 0x34c /* Second VBI buffer */ +#define VCR_VSTRIDE 0x350 /* Stride of video + coring control */ +#define VCR_VS_STRIDE_SHIFT 4 +#define VCR_VS_STRIDE 0x00001ff0 /* Stride (8-byte units) */ +#define VCR_VS_CCD 0x007f0000 /* Coring compare data */ +#define VCR_VS_COREEN 0x00800000 /* Coring enable */ +#define VCR_TS0ERR 0x354 /* TS buffer 0 error indicator */ +#define VCR_TS1ERR 0x358 /* TS buffer 0 error indicator */ +#define VCR_TS2ERR 0x35c /* TS buffer 0 error indicator */ + +/* Add 0x1000 for the second capture engine registers */ diff --git a/drivers/video/via/accel.c b/drivers/video/via/accel.c index e44893ea590d..04bec058569c 100644 --- a/drivers/video/via/accel.c +++ b/drivers/video/via/accel.c @@ -370,7 +370,7 @@ int viafb_init_engine(struct fb_info *info) viapar->shared->vq_vram_addr = viapar->fbmem_free; viapar->fbmem_used += VQ_SIZE; -#if defined(CONFIG_FB_VIA_CAMERA) || defined(CONFIG_FB_VIA_CAMERA_MODULE) +#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE) /* * Set aside a chunk of framebuffer memory for the camera * driver. Someday this driver probably needs a proper allocator diff --git a/drivers/video/via/via-core.c b/drivers/video/via/via-core.c index 66f403033111..27d7260d4f50 100644 --- a/drivers/video/via/via-core.c +++ b/drivers/video/via/via-core.c @@ -94,6 +94,13 @@ void viafb_irq_disable(u32 mask) EXPORT_SYMBOL_GPL(viafb_irq_disable); /* ---------------------------------------------------------------------- */ +/* + * Currently, the camera driver is the only user of the DMA code, so we + * only compile it in if the camera driver is being built. Chances are, + * most viafb systems will not need to have this extra code for a while. + * As soon as another user comes long, the ifdef can be removed. + */ +#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE) /* * Access to the DMA engine. This currently provides what the camera * driver needs (i.e. outgoing only) but is easily expandable if need @@ -322,7 +329,7 @@ int viafb_dma_copy_out_sg(unsigned int offset, struct scatterlist *sg, int nsg) return 0; } EXPORT_SYMBOL_GPL(viafb_dma_copy_out_sg); - +#endif /* CONFIG_VIDEO_VIA_CAMERA */ /* ---------------------------------------------------------------------- */ /* @@ -507,7 +514,12 @@ static struct viafb_subdev_info { }, { .name = "viafb-i2c", - } + }, +#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE) + { + .name = "viafb-camera", + }, +#endif }; #define N_SUBDEVS ARRAY_SIZE(viafb_subdevs) diff --git a/include/linux/via-core.h b/include/linux/via-core.h index 7ffb521e1a7a..38bffd8ccca5 100644 --- a/include/linux/via-core.h +++ b/include/linux/via-core.h @@ -81,7 +81,7 @@ struct viafb_dev { unsigned long fbmem_start; long fbmem_len; void __iomem *fbmem; -#if defined(CONFIG_FB_VIA_CAMERA) || defined(CONFIG_FB_VIA_CAMERA_MODULE) +#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE) long camera_fbmem_offset; long camera_fbmem_size; #endif @@ -138,6 +138,7 @@ void viafb_irq_disable(u32 mask); #define VDE_I_LVDSSIEN 0x40000000 /* LVDS Sense enable */ #define VDE_I_ENABLE 0x80000000 /* Global interrupt enable */ +#if defined(CONFIG_VIDEO_VIA_CAMERA) || defined(CONFIG_VIDEO_VIA_CAMERA_MODULE) /* * DMA management. */ @@ -172,6 +173,7 @@ int viafb_dma_copy_out_sg(unsigned int offset, struct scatterlist *sg, int nsg); */ #define VGA_WIDTH 640 #define VGA_HEIGHT 480 +#endif /* CONFIG_VIDEO_VIA_CAMERA */ /* * Indexed port operations. Note that these are all multi-op diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h index aeb4ff9c6140..51e89f2267b8 100644 --- a/include/media/v4l2-chip-ident.h +++ b/include/media/v4l2-chip-ident.h @@ -115,6 +115,10 @@ enum { V4L2_IDENT_VPX3216B = 3216, V4L2_IDENT_VPX3220A = 3220, + /* VX855 just ident 3409 */ + /* Other via devs could use 3314, 3324, 3327, 3336, 3364, 3353 */ + V4L2_IDENT_VIA_VX855 = 3409, + /* module tvp5150 */ V4L2_IDENT_TVP5150 = 5150, -- cgit v1.2.3 From 4ae871088a9ddead041c9e91e01435e4ed5dda08 Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Sun, 17 Oct 2010 16:16:13 -0300 Subject: [media] Anysee remote controller Anysee remote controller keytable. Uses NEC address 0x08. Signed-off-by: Antti Palosaari Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-anysee.c | 93 ++++++++++++++++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 95 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-anysee.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 6083453f4715..0b88b6563b66 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -1,5 +1,6 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-alink-dtu-m.o \ + rc-anysee.o \ rc-apac-viewcomp.o \ rc-asus-pc39.o \ rc-ati-tv-wonder-hd-600.o \ diff --git a/drivers/media/IR/keymaps/rc-anysee.c b/drivers/media/IR/keymaps/rc-anysee.c new file mode 100644 index 000000000000..30d70498cfed --- /dev/null +++ b/drivers/media/IR/keymaps/rc-anysee.c @@ -0,0 +1,93 @@ +/* + * Anysee remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +static struct ir_scancode anysee[] = { + { 0x0800, KEY_0 }, + { 0x0801, KEY_1 }, + { 0x0802, KEY_2 }, + { 0x0803, KEY_3 }, + { 0x0804, KEY_4 }, + { 0x0805, KEY_5 }, + { 0x0806, KEY_6 }, + { 0x0807, KEY_7 }, + { 0x0808, KEY_8 }, + { 0x0809, KEY_9 }, + { 0x080a, KEY_POWER2 }, /* [red power button] */ + { 0x080b, KEY_VIDEO }, /* [*] MODE */ + { 0x080c, KEY_CHANNEL }, /* [symbol counterclockwise arrow] */ + { 0x080d, KEY_NEXT }, /* [>>|] */ + { 0x080e, KEY_MENU }, /* MENU */ + { 0x080f, KEY_EPG }, /* [EPG] */ + { 0x0810, KEY_CLEAR }, /* EXIT */ + { 0x0811, KEY_CHANNELUP }, + { 0x0812, KEY_VOLUMEDOWN }, + { 0x0813, KEY_VOLUMEUP }, + { 0x0814, KEY_CHANNELDOWN }, + { 0x0815, KEY_OK }, + { 0x0816, KEY_RADIO }, /* [symbol TV/radio] */ + { 0x0817, KEY_INFO }, /* [i] */ + { 0x0818, KEY_PREVIOUS }, /* [|<<] */ + { 0x0819, KEY_FAVORITES }, /* FAV. */ + { 0x081a, KEY_SUBTITLE }, /* Subtitle */ + { 0x081b, KEY_CAMERA }, /* [symbol camera] */ + { 0x081c, KEY_YELLOW }, + { 0x081d, KEY_RED }, + { 0x081e, KEY_LANGUAGE }, /* [symbol Second Audio Program] */ + { 0x081f, KEY_GREEN }, + { 0x0820, KEY_SLEEP }, /* Sleep */ + { 0x0821, KEY_SCREEN }, /* 16:9 / 4:3 */ + { 0x0822, KEY_ZOOM }, /* SIZE */ + { 0x0824, KEY_FN }, /* [F1] */ + { 0x0825, KEY_FN }, /* [F2] */ + { 0x0842, KEY_MUTE }, /* symbol mute */ + { 0x0844, KEY_BLUE }, + { 0x0847, KEY_TEXT }, /* TEXT */ + { 0x0848, KEY_STOP }, + { 0x0849, KEY_RECORD }, + { 0x0850, KEY_PLAY }, + { 0x0851, KEY_PAUSE }, +}; + +static struct rc_keymap anysee_map = { + .map = { + .scan = anysee, + .size = ARRAY_SIZE(anysee), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_ANYSEE, + } +}; + +static int __init init_rc_map_anysee(void) +{ + return ir_register_map(&anysee_map); +} + +static void __exit exit_rc_map_anysee(void) +{ + ir_unregister_map(&anysee_map); +} + +module_init(init_rc_map_anysee) +module_exit(exit_rc_map_anysee) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 74a00a93dcf1..2241655570c1 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -56,6 +56,7 @@ void rc_map_init(void); #define RC_MAP_ADSTECH_DVB_T_PCI "rc-adstech-dvb-t-pci" #define RC_MAP_ALINK_DTU_M "rc-alink-dtu-m" +#define RC_MAP_ANYSEE "rc-anysee" #define RC_MAP_APAC_VIEWCOMP "rc-apac-viewcomp" #define RC_MAP_ASUS_PC39 "rc-asus-pc39" #define RC_MAP_ATI_TV_WONDER_HD_600 "rc-ati-tv-wonder-hd-600" -- cgit v1.2.3 From 2334e7902e4ff3d61b5dd808858f2ac3e276a551 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 24 Sep 2010 08:39:19 -0300 Subject: [media] sh_vou: Don't use module names to load I2C modules With the v4l2_i2c_new_subdev* functions now supporting loading modules based on modaliases, remove the module names hardcoded in platform data and pass a NULL module name to those functions. All corresponding I2C modules have been checked, and all of them include a module aliases table with names corresponding to what the sh_vou platform data uses. Signed-off-by: Laurent Pinchart Signed-off-by: Mauro Carvalho Chehab --- arch/sh/boards/mach-ecovec24/setup.c | 1 - arch/sh/boards/mach-se/7724/setup.c | 1 - drivers/media/video/sh_vou.c | 2 +- include/media/sh_vou.h | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) (limited to 'include') diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c index 1d7b495a7db4..4a9fa5d38540 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -793,7 +793,6 @@ static struct sh_vou_pdata sh_vou_pdata = { .flags = SH_VOU_HSYNC_LOW | SH_VOU_VSYNC_LOW, .board_info = &ak8813, .i2c_adap = 0, - .module_name = "ak881x", }; static struct resource sh_vou_resources[] = { diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c index 552ebd9ba82b..8cc1d7295d85 100644 --- a/arch/sh/boards/mach-se/7724/setup.c +++ b/arch/sh/boards/mach-se/7724/setup.c @@ -550,7 +550,6 @@ static struct sh_vou_pdata sh_vou_pdata = { .flags = SH_VOU_HSYNC_LOW | SH_VOU_VSYNC_LOW, .board_info = &ak8813, .i2c_adap = 0, - .module_name = "ak881x", }; static struct resource sh_vou_resources[] = { diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c index 195ac8651160..0f4906136b8f 100644 --- a/drivers/media/video/sh_vou.c +++ b/drivers/media/video/sh_vou.c @@ -1406,7 +1406,7 @@ static int __devinit sh_vou_probe(struct platform_device *pdev) goto ereset; subdev = v4l2_i2c_new_subdev_board(&vou_dev->v4l2_dev, i2c_adap, - vou_pdata->module_name, vou_pdata->board_info, NULL); + NULL, vou_pdata->board_info, NULL); if (!subdev) { ret = -ENOMEM; goto ei2cnd; diff --git a/include/media/sh_vou.h b/include/media/sh_vou.h index a3ef30242b00..ec3ba9a597a2 100644 --- a/include/media/sh_vou.h +++ b/include/media/sh_vou.h @@ -28,7 +28,6 @@ struct sh_vou_pdata { int i2c_adap; struct i2c_board_info *board_info; unsigned long flags; - char *module_name; }; #endif -- cgit v1.2.3 From fcb9757333df37cf4a7feccef7ef6f5300643864 Mon Sep 17 00:00:00 2001 From: lawrence rust Date: Mon, 18 Oct 2010 07:06:02 -0300 Subject: [media] Nova-S-Plus audio line input This patch adds audio DMA capture and ALSA mixer elements for the line input jack of the Hauppauge Nova-S-plus DVB-S PCI card. The Nova-S-plus has a WM8775 ADC that is currently not detected. This patch enables this chip and exports volume, balance mute and ALC elements for ALSA mixer controls. [mchehab@redhat.com: Fix CodingStyle issues] Signed-off-by: Lawrence Rust Signed-off-by: Mauro Carvalho Chehab --- drivers/media/video/cx88/cx88-alsa.c | 99 ++++++++++++++++++++++++++++---- drivers/media/video/cx88/cx88-cards.c | 7 +++ drivers/media/video/cx88/cx88-video.c | 27 ++++++++- drivers/media/video/cx88/cx88.h | 6 +- drivers/media/video/wm8775.c | 104 +++++++++++++++++++++------------- include/media/wm8775.h | 3 + 6 files changed, 192 insertions(+), 54 deletions(-) (limited to 'include') diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c index 54b7fcd469a8..4aaa47c0eabf 100644 --- a/drivers/media/video/cx88/cx88-alsa.c +++ b/drivers/media/video/cx88/cx88-alsa.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "cx88.h" #include "cx88-reg.h" @@ -586,26 +587,47 @@ static int snd_cx88_volume_put(struct snd_kcontrol *kcontrol, int left, right, v, b; int changed = 0; u32 old; + struct v4l2_control client_ctl; + + /* Pass volume & balance onto any WM8775 */ + if (value->value.integer.value[0] >= value->value.integer.value[1]) { + v = value->value.integer.value[0] << 10; + b = value->value.integer.value[0] ? + (0x8000 * value->value.integer.value[1]) / value->value.integer.value[0] : + 0x8000; + } else { + v = value->value.integer.value[1] << 10; + b = value->value.integer.value[1] ? + 0xffff - (0x8000 * value->value.integer.value[0]) / value->value.integer.value[1] : + 0x8000; + } + client_ctl.value = v; + client_ctl.id = V4L2_CID_AUDIO_VOLUME; + call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); + + client_ctl.value = b; + client_ctl.id = V4L2_CID_AUDIO_BALANCE; + call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); left = value->value.integer.value[0] & 0x3f; right = value->value.integer.value[1] & 0x3f; b = right - left; if (b < 0) { - v = 0x3f - left; - b = (-b) | 0x40; + v = 0x3f - left; + b = (-b) | 0x40; } else { - v = 0x3f - right; + v = 0x3f - right; } /* Do we really know this will always be called with IRQs on? */ spin_lock_irq(&chip->reg_lock); old = cx_read(AUD_VOL_CTL); if (v != (old & 0x3f)) { - cx_write(AUD_VOL_CTL, (old & ~0x3f) | v); - changed = 1; + cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, (old & ~0x3f) | v); + changed = 1; } - if (cx_read(AUD_BAL_CTL) != b) { - cx_write(AUD_BAL_CTL, b); - changed = 1; + if ((cx_read(AUD_BAL_CTL) & 0x7f) != b) { + cx_write(AUD_BAL_CTL, b); + changed = 1; } spin_unlock_irq(&chip->reg_lock); @@ -618,7 +640,7 @@ static const struct snd_kcontrol_new snd_cx88_volume = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, - .name = "Playback Volume", + .name = "Analog-TV Volume", .info = snd_cx88_volume_info, .get = snd_cx88_volume_get, .put = snd_cx88_volume_put, @@ -649,7 +671,14 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol, vol = cx_read(AUD_VOL_CTL); if (value->value.integer.value[0] != !(vol & bit)) { vol ^= bit; - cx_write(AUD_VOL_CTL, vol); + cx_swrite(SHADOW_AUD_VOL_CTL, AUD_VOL_CTL, vol); + /* Pass mute onto any WM8775 */ + if ((1<<6) == bit) { + struct v4l2_control client_ctl; + client_ctl.value = 0 != (vol & bit); + client_ctl.id = V4L2_CID_AUDIO_MUTE; + call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); + } ret = 1; } spin_unlock_irq(&chip->reg_lock); @@ -658,7 +687,7 @@ static int snd_cx88_switch_put(struct snd_kcontrol *kcontrol, static const struct snd_kcontrol_new snd_cx88_dac_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Playback Switch", + .name = "Audio-Out Switch", .info = snd_ctl_boolean_mono_info, .get = snd_cx88_switch_get, .put = snd_cx88_switch_put, @@ -667,13 +696,49 @@ static const struct snd_kcontrol_new snd_cx88_dac_switch = { static const struct snd_kcontrol_new snd_cx88_source_switch = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, - .name = "Capture Switch", + .name = "Analog-TV Switch", .info = snd_ctl_boolean_mono_info, .get = snd_cx88_switch_get, .put = snd_cx88_switch_put, .private_value = (1<<6), }; +static int snd_cx88_alc_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) +{ + snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); + struct cx88_core *core = chip->core; + struct v4l2_control client_ctl; + + client_ctl.id = V4L2_CID_AUDIO_LOUDNESS; + call_hw(core, WM8775_GID, core, g_ctrl, &client_ctl); + value->value.integer.value[0] = client_ctl.value ? 1 : 0; + + return 0; +} + +static int snd_cx88_alc_put(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *value) +{ + snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); + struct cx88_core *core = chip->core; + struct v4l2_control client_ctl; + + client_ctl.value = 0 != value->value.integer.value[0]; + client_ctl.id = V4L2_CID_AUDIO_LOUDNESS; + call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); + + return 0; +} + +static struct snd_kcontrol_new snd_cx88_alc_switch = { + .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .name = "Line-In ALC Switch", + .info = snd_ctl_boolean_mono_info, + .get = snd_cx88_alc_get, + .put = snd_cx88_alc_put, +}; + /**************************************************************************** Basic Flow for Sound Devices ****************************************************************************/ @@ -795,6 +860,7 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci, { struct snd_card *card; snd_cx88_card_t *chip; + struct v4l2_subdev *sd; int err; if (devno >= SNDRV_CARDS) @@ -830,6 +896,15 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci, if (err < 0) goto error; + /* If there's a wm8775 then add a Line-In ALC switch */ + list_for_each_entry(sd, &chip->core->v4l2_dev.subdevs, list) { + if (WM8775_GID == sd->grp_id) { + snd_ctl_add(card, snd_ctl_new1(&snd_cx88_alc_switch, + chip)); + break; + } + } + strcpy (card->driver, "CX88x"); sprintf(card->shortname, "Conexant CX%x", pci->device); sprintf(card->longname, "%s at %#llx", diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c index 7bfe330a8167..b26fcba8600c 100644 --- a/drivers/media/video/cx88/cx88-cards.c +++ b/drivers/media/video/cx88/cx88-cards.c @@ -970,15 +970,22 @@ static const struct cx88_board cx88_boards[] = { .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, + .audio_chip = V4L2_IDENT_WM8775, .input = {{ .type = CX88_VMUX_DVB, .vmux = 0, + /* 2: Line-In */ + .audioroute = 2, },{ .type = CX88_VMUX_COMPOSITE1, .vmux = 1, + /* 2: Line-In */ + .audioroute = 2, },{ .type = CX88_VMUX_SVIDEO, .vmux = 2, + /* 2: Line-In */ + .audioroute = 2, }}, .mpeg = CX88_MPEG_DVB, }, diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c index e3cff585215d..d2f159daa8b5 100644 --- a/drivers/media/video/cx88/cx88-video.c +++ b/drivers/media/video/cx88/cx88-video.c @@ -41,6 +41,7 @@ #include "cx88.h" #include #include +#include MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); MODULE_AUTHOR("Gerd Knorr [SuSE Labs]"); @@ -977,6 +978,7 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl) const struct cx88_ctrl *c = NULL; u32 value,mask; int i; + struct v4l2_control client_ctl; for (i = 0; i < CX8800_CTLS; i++) { if (cx8800_ctls[i].v.id == ctl->id) { @@ -990,6 +992,27 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl) ctl->value = c->v.minimum; if (ctl->value > c->v.maximum) ctl->value = c->v.maximum; + + /* Pass changes onto any WM8775 */ + client_ctl.id = ctl->id; + switch (ctl->id) { + case V4L2_CID_AUDIO_MUTE: + client_ctl.value = ctl->value; + break; + case V4L2_CID_AUDIO_VOLUME: + client_ctl.value = (ctl->value) ? + (0x90 + ctl->value) << 8 : 0; + break; + case V4L2_CID_AUDIO_BALANCE: + client_ctl.value = ctl->value << 9; + break; + default: + client_ctl.id = 0; + break; + } + if (client_ctl.id) + call_hw(core, WM8775_GID, core, s_ctrl, &client_ctl); + mask=c->mask; switch (ctl->id) { case V4L2_CID_AUDIO_BALANCE: @@ -1536,7 +1559,9 @@ static int radio_queryctrl (struct file *file, void *priv, if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1) return -EINVAL; - if (c->id == V4L2_CID_AUDIO_MUTE) { + if (c->id == V4L2_CID_AUDIO_MUTE || + c->id == V4L2_CID_AUDIO_VOLUME || + c->id == V4L2_CID_AUDIO_BALANCE) { for (i = 0; i < CX8800_CTLS; i++) { if (cx8800_ctls[i].v.id == c->id) break; diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h index c9981e77416a..e8c732e7ae4f 100644 --- a/drivers/media/video/cx88/cx88.h +++ b/drivers/media/video/cx88/cx88.h @@ -398,17 +398,19 @@ static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev) return container_of(v4l2_dev, struct cx88_core, v4l2_dev); } -#define call_all(core, o, f, args...) \ +#define call_hw(core, grpid, o, f, args...) \ do { \ if (!core->i2c_rc) { \ if (core->gate_ctrl) \ core->gate_ctrl(core, 1); \ - v4l2_device_call_all(&core->v4l2_dev, 0, o, f, ##args); \ + v4l2_device_call_all(&core->v4l2_dev, grpid, o, f, ##args); \ if (core->gate_ctrl) \ core->gate_ctrl(core, 0); \ } \ } while (0) +#define call_all(core, o, f, args...) call_hw(core, 0, o, f, ##args) + struct cx8800_dev; struct cx8802_dev; diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c index fe8ef6419f83..135525649086 100644 --- a/drivers/media/video/wm8775.c +++ b/drivers/media/video/wm8775.c @@ -35,6 +35,7 @@ #include #include #include +#include MODULE_DESCRIPTION("wm8775 driver"); MODULE_AUTHOR("Ulf Eklund, Hans Verkuil"); @@ -50,10 +51,16 @@ enum { TOT_REGS }; +#define ALC_HOLD 0x85 /* R17: use zero cross detection, ALC hold time 42.6 ms */ +#define ALC_EN 0x100 /* R17: ALC enable */ + struct wm8775_state { struct v4l2_subdev sd; struct v4l2_ctrl_handler hdl; struct v4l2_ctrl *mute; + struct v4l2_ctrl *vol; + struct v4l2_ctrl *bal; + struct v4l2_ctrl *loud; u8 input; /* Last selected input (0-0xf) */ }; @@ -85,6 +92,30 @@ static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val) return -1; } +static void wm8775_set_audio(struct v4l2_subdev *sd, int quietly) +{ + struct wm8775_state *state = to_state(sd); + u8 vol_l, vol_r; + int muted = 0 != state->mute->val; + u16 volume = (u16)state->vol->val; + u16 balance = (u16)state->bal->val; + + /* normalize ( 65535 to 0 -> 255 to 0 (+24dB to -103dB) ) */ + vol_l = (min(65536 - balance, 32768) * volume) >> 23; + vol_r = (min(balance, (u16)32768) * volume) >> 23; + + /* Mute */ + if (muted || quietly) + wm8775_write(sd, R21, 0x0c0 | state->input); + + wm8775_write(sd, R14, vol_l | 0x100); /* 0x100= Left channel ADC zero cross enable */ + wm8775_write(sd, R15, vol_r | 0x100); /* 0x100= Right channel ADC zero cross enable */ + + /* Un-mute */ + if (!muted) + wm8775_write(sd, R21, state->input); +} + static int wm8775_s_routing(struct v4l2_subdev *sd, u32 input, u32 output, u32 config) { @@ -102,25 +133,26 @@ static int wm8775_s_routing(struct v4l2_subdev *sd, state->input = input; if (!v4l2_ctrl_g_ctrl(state->mute)) return 0; - wm8775_write(sd, R21, 0x0c0); - wm8775_write(sd, R14, 0x1d4); - wm8775_write(sd, R15, 0x1d4); - wm8775_write(sd, R21, 0x100 + state->input); + if (!v4l2_ctrl_g_ctrl(state->vol)) + return 0; + if (!v4l2_ctrl_g_ctrl(state->bal)) + return 0; + wm8775_set_audio(sd, 1); return 0; } static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl) { struct v4l2_subdev *sd = to_sd(ctrl); - struct wm8775_state *state = to_state(sd); switch (ctrl->id) { case V4L2_CID_AUDIO_MUTE: - wm8775_write(sd, R21, 0x0c0); - wm8775_write(sd, R14, 0x1d4); - wm8775_write(sd, R15, 0x1d4); - if (!ctrl->val) - wm8775_write(sd, R21, 0x100 + state->input); + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_BALANCE: + wm8775_set_audio(sd, 0); + return 0; + case V4L2_CID_AUDIO_LOUDNESS: + wm8775_write(sd, R17, (ctrl->val ? ALC_EN : 0) | ALC_HOLD); return 0; } return -EINVAL; @@ -144,16 +176,7 @@ static int wm8775_log_status(struct v4l2_subdev *sd) static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) { - struct wm8775_state *state = to_state(sd); - - /* If I remove this, then it can happen that I have no - sound the first time I tune from static to a valid channel. - It's difficult to reproduce and is almost certainly related - to the zero cross detect circuit. */ - wm8775_write(sd, R21, 0x0c0); - wm8775_write(sd, R14, 0x1d4); - wm8775_write(sd, R15, 0x1d4); - wm8775_write(sd, R21, 0x100 + state->input); + wm8775_set_audio(sd, 0); return 0; } @@ -203,6 +226,7 @@ static int wm8775_probe(struct i2c_client *client, { struct wm8775_state *state; struct v4l2_subdev *sd; + int err; /* Check if the adapter supports the needed features */ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) @@ -216,15 +240,21 @@ static int wm8775_probe(struct i2c_client *client, return -ENOMEM; sd = &state->sd; v4l2_i2c_subdev_init(sd, client, &wm8775_ops); + sd->grp_id = WM8775_GID; /* subdev group id */ state->input = 2; - v4l2_ctrl_handler_init(&state->hdl, 1); + v4l2_ctrl_handler_init(&state->hdl, 4); state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops, V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0); + state->vol = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops, + V4L2_CID_AUDIO_VOLUME, 0, 65535, (65535+99)/100, 0xCF00); /* 0dB*/ + state->bal = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops, + V4L2_CID_AUDIO_BALANCE, 0, 65535, (65535+99)/100, 32768); + state->loud = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops, + V4L2_CID_AUDIO_LOUDNESS, 0, 1, 1, 1); sd->ctrl_handler = &state->hdl; - if (state->hdl.error) { - int err = state->hdl.error; - + err = state->hdl.error; + if (err) { v4l2_ctrl_handler_free(&state->hdl); kfree(state); return err; @@ -236,29 +266,25 @@ static int wm8775_probe(struct i2c_client *client, wm8775_write(sd, R23, 0x000); /* Disable zero cross detect timeout */ wm8775_write(sd, R7, 0x000); - /* Left justified, 24-bit mode */ - wm8775_write(sd, R11, 0x021); + /* HPF enable, I2S mode, 24-bit */ + wm8775_write(sd, R11, 0x022); /* Master mode, clock ratio 256fs */ wm8775_write(sd, R12, 0x102); /* Powered up */ wm8775_write(sd, R13, 0x000); - /* ADC gain +2.5dB, enable zero cross */ - wm8775_write(sd, R14, 0x1d4); - /* ADC gain +2.5dB, enable zero cross */ - wm8775_write(sd, R15, 0x1d4); - /* ALC Stereo, ALC target level -1dB FS max gain +8dB */ - wm8775_write(sd, R16, 0x1bf); - /* Enable gain control, use zero cross detection, - ALC hold time 42.6 ms */ - wm8775_write(sd, R17, 0x185); + /* ALC stereo, ALC target level -5dB FS, ALC max gain +8dB */ + wm8775_write(sd, R16, 0x1bb); + /* Set ALC mode and hold time */ + wm8775_write(sd, R17, (state->loud->val ? ALC_EN : 0) | ALC_HOLD); /* ALC gain ramp up delay 34 s, ALC gain ramp down delay 33 ms */ wm8775_write(sd, R18, 0x0a2); /* Enable noise gate, threshold -72dBfs */ wm8775_write(sd, R19, 0x005); - /* Transient window 4ms, lower PGA gain limit -1dB */ - wm8775_write(sd, R20, 0x07a); - /* LRBOTH = 1, use input 2. */ - wm8775_write(sd, R21, 0x102); + /* Transient window 4ms, ALC min gain -5dB */ + wm8775_write(sd, R20, 0x0fb); + + wm8775_set_audio(sd, 1); /* set volume/mute/mux */ + return 0; } diff --git a/include/media/wm8775.h b/include/media/wm8775.h index 60739c5a23ae..a1c4d417dfa2 100644 --- a/include/media/wm8775.h +++ b/include/media/wm8775.h @@ -32,4 +32,7 @@ #define WM8775_AIN3 4 #define WM8775_AIN4 8 +/* subdev group ID */ +#define WM8775_GID (1 << 0) + #endif -- cgit v1.2.3 From 64fb58092e025235dc7fdcebeffee1516c79464d Mon Sep 17 00:00:00 2001 From: Antti Palosaari Date: Fri, 22 Oct 2010 20:23:31 -0300 Subject: [media] DigitalNow TinyTwin remote controller Signed-off-by: Antti Palosaari Cc: Renura Enterprises Pty Ltd Signed-off-by: Mauro Carvalho Chehab --- drivers/media/IR/keymaps/Makefile | 1 + drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c | 98 +++++++++++++++++++++++ include/media/rc-map.h | 1 + 3 files changed, 100 insertions(+) create mode 100644 drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c (limited to 'include') diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile index 0b88b6563b66..3194d391bbd4 100644 --- a/drivers/media/IR/keymaps/Makefile +++ b/drivers/media/IR/keymaps/Makefile @@ -20,6 +20,7 @@ obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \ rc-cinergy.o \ rc-dib0700-nec.o \ rc-dib0700-rc5.o \ + rc-digitalnow-tinytwin.o \ rc-digittrade.o \ rc-dm1105-nec.o \ rc-dntv-live-dvb-t.o \ diff --git a/drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c b/drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c new file mode 100644 index 000000000000..63e469e2dd21 --- /dev/null +++ b/drivers/media/IR/keymaps/rc-digitalnow-tinytwin.c @@ -0,0 +1,98 @@ +/* + * DigitalNow TinyTwin remote controller keytable + * + * Copyright (C) 2010 Antti Palosaari + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +static struct ir_scancode digitalnow_tinytwin[] = { + { 0x0000, KEY_MUTE }, /* [symbol speaker] */ + { 0x0001, KEY_VOLUMEUP }, + { 0x0002, KEY_POWER2 }, /* TV [power button] */ + { 0x0003, KEY_2 }, + { 0x0004, KEY_3 }, + { 0x0005, KEY_4 }, + { 0x0006, KEY_6 }, + { 0x0007, KEY_7 }, + { 0x0008, KEY_8 }, + { 0x0009, KEY_NUMERIC_STAR }, /* [*] */ + { 0x000a, KEY_0 }, + { 0x000b, KEY_NUMERIC_POUND }, /* [#] */ + { 0x000c, KEY_RIGHT }, /* [right arrow] */ + { 0x000d, KEY_HOMEPAGE }, /* [symbol home] Start */ + { 0x000e, KEY_RED }, /* [red] Videos */ + { 0x0010, KEY_POWER }, /* PC [power button] */ + { 0x0011, KEY_YELLOW }, /* [yellow] Pictures */ + { 0x0012, KEY_DOWN }, /* [down arrow] */ + { 0x0013, KEY_GREEN }, /* [green] Music */ + { 0x0014, KEY_CYCLEWINDOWS }, /* BACK */ + { 0x0015, KEY_FAVORITES }, /* MORE */ + { 0x0016, KEY_UP }, /* [up arrow] */ + { 0x0017, KEY_LEFT }, /* [left arrow] */ + { 0x0018, KEY_OK }, /* OK */ + { 0x0019, KEY_BLUE }, /* [blue] MyTV */ + { 0x001a, KEY_REWIND }, /* REW [<<] */ + { 0x001b, KEY_PLAY }, /* PLAY */ + { 0x001c, KEY_5 }, + { 0x001d, KEY_9 }, + { 0x001e, KEY_VOLUMEDOWN }, + { 0x001f, KEY_1 }, + { 0x0040, KEY_STOP }, /* STOP */ + { 0x0042, KEY_PAUSE }, /* PAUSE */ + { 0x0043, KEY_SCREEN }, /* Aspect */ + { 0x0044, KEY_FORWARD }, /* FWD [>>] */ + { 0x0045, KEY_NEXT }, /* SKIP */ + { 0x0048, KEY_RECORD }, /* RECORD */ + { 0x0049, KEY_VIDEO }, /* RTV */ + { 0x004a, KEY_EPG }, /* Guide */ + { 0x004b, KEY_CHANNELUP }, + { 0x004c, KEY_HELP }, /* Help */ + { 0x004d, KEY_RADIO }, /* Radio */ + { 0x004f, KEY_CHANNELDOWN }, + { 0x0050, KEY_DVD }, /* DVD */ + { 0x0051, KEY_AUDIO }, /* Audio */ + { 0x0052, KEY_TITLE }, /* Title */ + { 0x0053, KEY_NEW }, /* [symbol PIP?] */ + { 0x0057, KEY_MENU }, /* Mouse */ + { 0x005a, KEY_PREVIOUS }, /* REPLAY */ +}; + +static struct rc_keymap digitalnow_tinytwin_map = { + .map = { + .scan = digitalnow_tinytwin, + .size = ARRAY_SIZE(digitalnow_tinytwin), + .ir_type = IR_TYPE_NEC, + .name = RC_MAP_DIGITALNOW_TINYTWIN, + } +}; + +static int __init init_rc_map_digitalnow_tinytwin(void) +{ + return ir_register_map(&digitalnow_tinytwin_map); +} + +static void __exit exit_rc_map_digitalnow_tinytwin(void) +{ + ir_unregister_map(&digitalnow_tinytwin_map); +} + +module_init(init_rc_map_digitalnow_tinytwin) +module_exit(exit_rc_map_digitalnow_tinytwin) + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Antti Palosaari "); diff --git a/include/media/rc-map.h b/include/media/rc-map.h index 2241655570c1..25883cfc3118 100644 --- a/include/media/rc-map.h +++ b/include/media/rc-map.h @@ -76,6 +76,7 @@ void rc_map_init(void); #define RC_MAP_CINERGY "rc-cinergy" #define RC_MAP_DIB0700_NEC_TABLE "rc-dib0700-nec" #define RC_MAP_DIB0700_RC5_TABLE "rc-dib0700-rc5" +#define RC_MAP_DIGITALNOW_TINYTWIN "rc-digitalnow-tinytwin" #define RC_MAP_DIGITTRADE "rc-digittrade" #define RC_MAP_DM1105_NEC "rc-dm1105-nec" #define RC_MAP_DNTV_LIVE_DVBT_PRO "rc-dntv-live-dvbt-pro" -- cgit v1.2.3