Commit 0ab6e1c3 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (10729): zoran: convert to v4l2_device/v4l2_subdev.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 35631dcc
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#ifndef _BUZ_H_ #ifndef _BUZ_H_
#define _BUZ_H_ #define _BUZ_H_
#include <media/v4l2-device.h>
struct zoran_requestbuffers { struct zoran_requestbuffers {
unsigned long count; /* Number of buffers for MJPEG grabbing */ unsigned long count; /* Number of buffers for MJPEG grabbing */
unsigned long size; /* Size PER BUFFER in bytes */ unsigned long size; /* Size PER BUFFER in bytes */
...@@ -339,7 +341,12 @@ struct zoran_fh { ...@@ -339,7 +341,12 @@ struct zoran_fh {
struct card_info { struct card_info {
enum card_type type; enum card_type type;
char name[32]; char name[32];
u16 i2c_decoder, i2c_encoder; /* I2C types */ const char *i2c_decoder; /* i2c decoder device */
const char *mod_decoder; /* i2c decoder module */
const unsigned short *addrs_decoder;
const char *i2c_encoder; /* i2c encoder device */
const char *mod_encoder; /* i2c encoder module */
const unsigned short *addrs_encoder;
u16 video_vfe, video_codec; /* videocodec types */ u16 video_vfe, video_codec; /* videocodec types */
u16 audio_chip; /* audio type */ u16 audio_chip; /* audio type */
...@@ -370,14 +377,15 @@ struct card_info { ...@@ -370,14 +377,15 @@ struct card_info {
}; };
struct zoran { struct zoran {
struct v4l2_device v4l2_dev;
struct video_device *video_dev; struct video_device *video_dev;
struct i2c_adapter i2c_adapter; /* */ struct i2c_adapter i2c_adapter; /* */
struct i2c_algo_bit_data i2c_algo; /* */ struct i2c_algo_bit_data i2c_algo; /* */
u32 i2cbr; u32 i2cbr;
struct i2c_client *decoder; /* video decoder i2c client */ struct v4l2_subdev *decoder; /* video decoder sub-device */
struct i2c_client *encoder; /* video encoder i2c client */ struct v4l2_subdev *encoder; /* video encoder sub-device */
struct videocodec *codec; /* video codec */ struct videocodec *codec; /* video codec */
struct videocodec *vfe; /* video front end */ struct videocodec *vfe; /* video front end */
...@@ -481,6 +489,11 @@ struct zoran { ...@@ -481,6 +489,11 @@ struct zoran {
wait_queue_head_t test_q; wait_queue_head_t test_q;
}; };
static inline struct zoran *to_zoran(struct v4l2_device *v4l2_dev)
{
return container_of(v4l2_dev, struct zoran, v4l2_dev);
}
/* There was something called _ALPHA_BUZ that used the PCI address instead of /* There was something called _ALPHA_BUZ that used the PCI address instead of
* the kernel iomapped address for btread/btwrite. */ * the kernel iomapped address for btread/btwrite. */
#define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr)) #define btwrite(dat,adr) writel((dat), zr->zr36057_mem+(adr))
......
This diff is collapsed.
...@@ -36,15 +36,12 @@ ...@@ -36,15 +36,12 @@
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/i2c-algo-bit.h> #include <linux/i2c-algo-bit.h>
#include <linux/videodev.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/sem.h> #include <linux/sem.h>
#include <linux/pci.h> #include <linux/pci.h>
#include <linux/video_decoder.h>
#include <linux/video_encoder.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/wait.h> #include <linux/wait.h>
...@@ -1000,9 +997,9 @@ zr36057_enable_jpg (struct zoran *zr, ...@@ -1000,9 +997,9 @@ zr36057_enable_jpg (struct zoran *zr,
* the video bus direction set to input. * the video bus direction set to input.
*/ */
set_videobus_dir(zr, 0); set_videobus_dir(zr, 0);
decoder_command(zr, VIDIOC_STREAMON, 0); decoder_call(zr, video, s_stream, 1);
route.input = 0; route.input = 0;
encoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); encoder_call(zr, video, s_routing, &route);
/* Take the JPEG codec and the VFE out of sleep */ /* Take the JPEG codec and the VFE out of sleep */
jpeg_codec_sleep(zr, 0); jpeg_codec_sleep(zr, 0);
...@@ -1048,10 +1045,10 @@ zr36057_enable_jpg (struct zoran *zr, ...@@ -1048,10 +1045,10 @@ zr36057_enable_jpg (struct zoran *zr,
/* In motion decompression mode, the decoder output must be disabled, and /* In motion decompression mode, the decoder output must be disabled, and
* the video bus direction set to output. * the video bus direction set to output.
*/ */
decoder_command(zr, VIDIOC_STREAMOFF, 0); decoder_call(zr, video, s_stream, 0);
set_videobus_dir(zr, 1); set_videobus_dir(zr, 1);
route.input = 1; route.input = 1;
encoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); encoder_call(zr, video, s_routing, &route);
/* Take the JPEG codec and the VFE out of sleep */ /* Take the JPEG codec and the VFE out of sleep */
jpeg_codec_sleep(zr, 0); jpeg_codec_sleep(zr, 0);
...@@ -1095,9 +1092,9 @@ zr36057_enable_jpg (struct zoran *zr, ...@@ -1095,9 +1092,9 @@ zr36057_enable_jpg (struct zoran *zr,
jpeg_codec_sleep(zr, 1); jpeg_codec_sleep(zr, 1);
zr36057_adjust_vfe(zr, mode); zr36057_adjust_vfe(zr, mode);
decoder_command(zr, VIDIOC_STREAMON, 0); decoder_call(zr, video, s_stream, 1);
route.input = 0; route.input = 0;
encoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); encoder_call(zr, video, s_routing, &route);
dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr)); dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
break; break;
...@@ -1210,7 +1207,7 @@ static void zoran_restart(struct zoran *zr) ...@@ -1210,7 +1207,7 @@ static void zoran_restart(struct zoran *zr)
int status = 0, mode; int status = 0, mode;
if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
decoder_command(zr, VIDIOC_INT_G_INPUT_STATUS, &status); decoder_call(zr, video, g_input_status, &status);
mode = CODEC_DO_COMPRESSION; mode = CODEC_DO_COMPRESSION;
} else { } else {
status = V4L2_IN_ST_NO_SIGNAL; status = V4L2_IN_ST_NO_SIGNAL;
...@@ -1590,14 +1587,14 @@ zoran_init_hardware (struct zoran *zr) ...@@ -1590,14 +1587,14 @@ zoran_init_hardware (struct zoran *zr)
route.input = zr->card.input[zr->input].muxsel; route.input = zr->card.input[zr->input].muxsel;
decoder_command(zr, VIDIOC_INT_INIT, NULL); decoder_call(zr, core, init, 0);
decoder_command(zr, VIDIOC_S_STD, &zr->norm); decoder_s_std(zr, zr->norm);
decoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); decoder_s_routing(zr, &route);
encoder_command(zr, VIDIOC_INT_INIT, NULL); encoder_call(zr, core, init, 0);
encoder_command(zr, VIDIOC_INT_S_STD_OUTPUT, &zr->norm); encoder_call(zr, video, s_std_output, zr->norm);
route.input = 0; route.input = 0;
encoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); encoder_call(zr, video, s_routing, &route);
/* toggle JPEG codec sleep to sync PLL */ /* toggle JPEG codec sleep to sync PLL */
jpeg_codec_sleep(zr, 1); jpeg_codec_sleep(zr, 1);
...@@ -1662,37 +1659,30 @@ zr36057_init_vfe (struct zoran *zr) ...@@ -1662,37 +1659,30 @@ zr36057_init_vfe (struct zoran *zr)
* Interface to decoder and encoder chips using i2c bus * Interface to decoder and encoder chips using i2c bus
*/ */
int int decoder_s_std(struct zoran *zr, v4l2_std_id std)
decoder_command (struct zoran *zr,
int cmd,
void *data)
{ {
if (zr->decoder == NULL) int res;
return -EIO;
if (zr->card.type == LML33 &&
(cmd == VIDIOC_S_STD || cmd == VIDIOC_INT_S_VIDEO_ROUTING)) {
int res;
// Bt819 needs to reset its FIFO buffer using #FRST pin and /* Bt819 needs to reset its FIFO buffer using #FRST pin and
// LML33 card uses GPIO(7) for that. LML33 card uses GPIO(7) for that. */
if (zr->card.type == LML33)
GPIO(zr, 7, 0); GPIO(zr, 7, 0);
res = zr->decoder->driver->command(zr->decoder, cmd, data); res = decoder_call(zr, tuner, s_std, std);
// Pull #FRST high. if (zr->card.type == LML33)
GPIO(zr, 7, 1); GPIO(zr, 7, 1); /* Pull #FRST high. */
return res; return res;
} else
return zr->decoder->driver->command(zr->decoder, cmd,
data);
} }
int int decoder_s_routing(struct zoran *zr, struct v4l2_routing *route)
encoder_command (struct zoran *zr,
int cmd,
void *data)
{ {
if (zr->encoder == NULL) int res;
return -1;
return zr->encoder->driver->command(zr->encoder, cmd, data); /* Bt819 needs to reset its FIFO buffer using #FRST pin and
LML33 card uses GPIO(7) for that. */
if (zr->card.type == LML33)
GPIO(zr, 7, 0);
res = decoder_call(zr, video, s_routing, route);
if (zr->card.type == LML33)
GPIO(zr, 7, 1); /* Pull #FRST high. */
return res;
} }
...@@ -87,11 +87,12 @@ extern int jpg_bufsize; ...@@ -87,11 +87,12 @@ extern int jpg_bufsize;
extern int pass_through; extern int pass_through;
/* i2c */ /* i2c */
extern int decoder_command(struct zoran *zr, #define decoder_call(zr, o, f, args...) \
int cmd, v4l2_subdev_call(zr->decoder, o, f, ##args)
void *data); #define encoder_call(zr, o, f, args...) \
extern int encoder_command(struct zoran *zr, v4l2_subdev_call(zr->encoder, o, f, ##args)
int cmd,
void *data); int decoder_s_std(struct zoran *zr, v4l2_std_id std);
int decoder_s_routing(struct zoran *zr, struct v4l2_routing *route);
#endif /* __ZORAN_DEVICE_H__ */ #endif /* __ZORAN_DEVICE_H__ */
...@@ -963,10 +963,6 @@ static int zoran_open(struct file *file) ...@@ -963,10 +963,6 @@ static int zoran_open(struct file *file)
lock_kernel(); lock_kernel();
/* see fs/device.c - the kernel already locks during open(),
* so locking ourselves only causes deadlocks */
/*mutex_lock(&zr->resource_lock);*/
if (zr->user >= 2048) { if (zr->user >= 2048) {
dprintk(1, KERN_ERR "%s: too many users (%d) on device\n", dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
ZR_DEVNAME(zr), zr->user); ZR_DEVNAME(zr), zr->user);
...@@ -974,32 +970,6 @@ static int zoran_open(struct file *file) ...@@ -974,32 +970,6 @@ static int zoran_open(struct file *file)
goto fail_unlock; goto fail_unlock;
} }
if (!zr->decoder) {
dprintk(1,
KERN_ERR "%s: no TV decoder loaded for device!\n",
ZR_DEVNAME(zr));
res = -EIO;
goto fail_unlock;
}
if (!try_module_get(zr->decoder->driver->driver.owner)) {
dprintk(1,
KERN_ERR
"%s: failed to grab ownership of video decoder\n",
ZR_DEVNAME(zr));
res = -EIO;
goto fail_unlock;
}
if (zr->encoder &&
!try_module_get(zr->encoder->driver->driver.owner)) {
dprintk(1,
KERN_ERR
"%s: failed to grab ownership of video encoder\n",
ZR_DEVNAME(zr));
res = -EIO;
goto fail_decoder;
}
/* now, create the open()-specific file_ops struct */ /* now, create the open()-specific file_ops struct */
fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL); fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
if (!fh) { if (!fh) {
...@@ -1008,7 +978,7 @@ static int zoran_open(struct file *file) ...@@ -1008,7 +978,7 @@ static int zoran_open(struct file *file)
"%s: zoran_open() - allocation of zoran_fh failed\n", "%s: zoran_open() - allocation of zoran_fh failed\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
res = -ENOMEM; res = -ENOMEM;
goto fail_encoder; goto fail_unlock;
} }
/* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
* on norm-change! */ * on norm-change! */
...@@ -1047,11 +1017,6 @@ static int zoran_open(struct file *file) ...@@ -1047,11 +1017,6 @@ static int zoran_open(struct file *file)
fail_fh: fail_fh:
kfree(fh); kfree(fh);
fail_encoder:
if (zr->encoder)
module_put(zr->encoder->driver->driver.owner);
fail_decoder:
module_put(zr->decoder->driver->driver.owner);
fail_unlock: fail_unlock:
unlock_kernel(); unlock_kernel();
...@@ -1104,8 +1069,8 @@ zoran_close(struct file *file) ...@@ -1104,8 +1069,8 @@ zoran_close(struct file *file)
if (!pass_through) { /* Switch to color bar */ if (!pass_through) { /* Switch to color bar */
struct v4l2_routing route = { 2, 0 }; struct v4l2_routing route = { 2, 0 };
decoder_command(zr, VIDIOC_STREAMOFF, 0); decoder_call(zr, video, s_stream, 0);
encoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); encoder_call(zr, video, s_routing, &route);
} }
} }
...@@ -1113,13 +1078,6 @@ zoran_close(struct file *file) ...@@ -1113,13 +1078,6 @@ zoran_close(struct file *file)
kfree(fh->overlay_mask); kfree(fh->overlay_mask);
kfree(fh); kfree(fh);
/* release locks on the i2c modules */
module_put(zr->decoder->driver->driver.owner);
if (zr->encoder)
module_put(zr->encoder->driver->driver.owner);
/*mutex_unlock(&zr->resource_lock);*/
dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr)); dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
return 0; return 0;
...@@ -1567,20 +1525,20 @@ zoran_set_norm (struct zoran *zr, ...@@ -1567,20 +1525,20 @@ zoran_set_norm (struct zoran *zr,
int status = 0; int status = 0;
v4l2_std_id std = 0; v4l2_std_id std = 0;
decoder_command(zr, VIDIOC_QUERYSTD, &std); decoder_call(zr, video, querystd, &std);
decoder_command(zr, VIDIOC_S_STD, &std); decoder_s_std(zr, std);
/* let changes come into effect */ /* let changes come into effect */
ssleep(2); ssleep(2);
decoder_command(zr, VIDIOC_INT_G_INPUT_STATUS, &status); decoder_call(zr, video, g_input_status, &status);
if (status & V4L2_IN_ST_NO_SIGNAL) { if (status & V4L2_IN_ST_NO_SIGNAL) {
dprintk(1, dprintk(1,
KERN_ERR KERN_ERR
"%s: set_norm() - no norm detected\n", "%s: set_norm() - no norm detected\n",
ZR_DEVNAME(zr)); ZR_DEVNAME(zr));
/* reset norm */ /* reset norm */
decoder_command(zr, VIDIOC_S_STD, &zr->norm); decoder_s_std(zr, zr->norm);
return -EIO; return -EIO;
} }
...@@ -1599,8 +1557,8 @@ zoran_set_norm (struct zoran *zr, ...@@ -1599,8 +1557,8 @@ zoran_set_norm (struct zoran *zr,
if (on) if (on)
zr36057_overlay(zr, 0); zr36057_overlay(zr, 0);
decoder_command(zr, VIDIOC_S_STD, &norm); decoder_s_std(zr, norm);
encoder_command(zr, VIDIOC_INT_S_STD_OUTPUT, &norm); encoder_call(zr, video, s_std_output, norm);
if (on) if (on)
zr36057_overlay(zr, 1); zr36057_overlay(zr, 1);
...@@ -1641,7 +1599,7 @@ zoran_set_input (struct zoran *zr, ...@@ -1641,7 +1599,7 @@ zoran_set_input (struct zoran *zr,
route.input = zr->card.input[input].muxsel; route.input = zr->card.input[input].muxsel;
zr->input = input; zr->input = input;
decoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); decoder_s_routing(zr, &route);
return 0; return 0;
} }
...@@ -1886,18 +1844,18 @@ jpgreqbuf_unlock_and_return: ...@@ -1886,18 +1844,18 @@ jpgreqbuf_unlock_and_return:
goto gstat_unlock_and_return; goto gstat_unlock_and_return;
} }
decoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); decoder_s_routing(zr, &route);
/* sleep 1 second */ /* sleep 1 second */
ssleep(1); ssleep(1);
/* Get status of video decoder */ /* Get status of video decoder */
decoder_command(zr, VIDIOC_QUERYSTD, &norm); decoder_call(zr, video, querystd, &norm);
decoder_command(zr, VIDIOC_INT_G_INPUT_STATUS, &status); decoder_call(zr, video, g_input_status, &status);
/* restore previous input and norm */ /* restore previous input and norm */
route.input = zr->card.input[zr->input].muxsel; route.input = zr->card.input[zr->input].muxsel;
decoder_command(zr, VIDIOC_INT_S_VIDEO_ROUTING, &route); decoder_s_routing(zr, &route);
gstat_unlock_and_return: gstat_unlock_and_return:
mutex_unlock(&zr->resource_lock); mutex_unlock(&zr->resource_lock);
...@@ -2836,7 +2794,7 @@ static int zoran_queryctrl(struct file *file, void *__fh, ...@@ -2836,7 +2794,7 @@ static int zoran_queryctrl(struct file *file, void *__fh,
ctrl->id > V4L2_CID_HUE) ctrl->id > V4L2_CID_HUE)
return -EINVAL; return -EINVAL;
decoder_command(zr, VIDIOC_QUERYCTRL, ctrl); decoder_call(zr, core, queryctrl, ctrl);
return 0; return 0;
} }
...@@ -2852,7 +2810,7 @@ static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl ...@@ -2852,7 +2810,7 @@ static int zoran_g_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl
return -EINVAL; return -EINVAL;
mutex_lock(&zr->resource_lock); mutex_lock(&zr->resource_lock);
decoder_command(zr, VIDIOC_G_CTRL, ctrl); decoder_call(zr, core, g_ctrl, ctrl);
mutex_unlock(&zr->resource_lock); mutex_unlock(&zr->resource_lock);
return 0; return 0;
...@@ -2869,7 +2827,7 @@ static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl ...@@ -2869,7 +2827,7 @@ static int zoran_s_ctrl(struct file *file, void *__fh, struct v4l2_control *ctrl
return -EINVAL; return -EINVAL;
mutex_lock(&zr->resource_lock); mutex_lock(&zr->resource_lock);
decoder_command(zr, VIDIOC_S_CTRL, ctrl); decoder_call(zr, core, s_ctrl, ctrl);
mutex_unlock(&zr->resource_lock); mutex_unlock(&zr->resource_lock);
return 0; return 0;
...@@ -2924,7 +2882,7 @@ static int zoran_enum_input(struct file *file, void *__fh, ...@@ -2924,7 +2882,7 @@ static int zoran_enum_input(struct file *file, void *__fh,
/* Get status of video decoder */ /* Get status of video decoder */
mutex_lock(&zr->resource_lock); mutex_lock(&zr->resource_lock);
decoder_command(zr, VIDIOC_INT_G_INPUT_STATUS, &inp->status); decoder_call(zr, video, g_input_status, &inp->status);
mutex_unlock(&zr->resource_lock); mutex_unlock(&zr->resource_lock);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment