Commit 5b73e98c authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

V4L/DVB (10246): saa6752hs: convert to v4l2_subdev.

Signed-off-by: default avatarHans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent b634a93f
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/videodev2.h> #include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-common.h> #include <media/v4l2-common.h>
#include <media/v4l2-chip-ident.h> #include <media/v4l2-chip-ident.h>
#include <media/v4l2-i2c-drv-legacy.h> #include <media/v4l2-i2c-drv-legacy.h>
...@@ -95,6 +96,7 @@ static const struct v4l2_format v4l2_format_table[] = ...@@ -95,6 +96,7 @@ static const struct v4l2_format v4l2_format_table[] =
}; };
struct saa6752hs_state { struct saa6752hs_state {
struct v4l2_subdev sd;
int chip; int chip;
u32 revision; u32 revision;
int has_ac3; int has_ac3;
...@@ -115,6 +117,11 @@ enum saa6752hs_command { ...@@ -115,6 +117,11 @@ enum saa6752hs_command {
SAA6752HS_COMMAND_MAX SAA6752HS_COMMAND_MAX
}; };
static inline struct saa6752hs_state *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct saa6752hs_state, sd);
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
static u8 PAT[] = { static u8 PAT[] = {
...@@ -360,185 +367,191 @@ static int saa6752hs_set_bitrate(struct i2c_client *client, ...@@ -360,185 +367,191 @@ static int saa6752hs_set_bitrate(struct i2c_client *client,
return 0; return 0;
} }
static void saa6752hs_set_subsampling(struct i2c_client *client,
struct v4l2_format *f)
{
struct saa6752hs_state *h = i2c_get_clientdata(client);
int dist_352, dist_480, dist_720;
/*
FIXME: translate and round width/height into EMPRESS
subsample type:
type | PAL | NTSC static int get_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
--------------------------- struct v4l2_ext_control *ctrl)
SIF | 352x288 | 352x240 {
1/2 D1 | 352x576 | 352x480 switch (ctrl->id) {
2/3 D1 | 480x576 | 480x480 case V4L2_CID_MPEG_STREAM_TYPE:
D1 | 720x576 | 720x480 ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
*/ break;
case V4L2_CID_MPEG_STREAM_PID_PMT:
dist_352 = abs(f->fmt.pix.width - 352); ctrl->value = params->ts_pid_pmt;
dist_480 = abs(f->fmt.pix.width - 480); break;
dist_720 = abs(f->fmt.pix.width - 720); case V4L2_CID_MPEG_STREAM_PID_AUDIO:
if (dist_720 < dist_480) { ctrl->value = params->ts_pid_audio;
f->fmt.pix.width = 720; break;
f->fmt.pix.height = 576; case V4L2_CID_MPEG_STREAM_PID_VIDEO:
h->video_format = SAA6752HS_VF_D1; ctrl->value = params->ts_pid_video;
} break;
else if (dist_480 < dist_352) { case V4L2_CID_MPEG_STREAM_PID_PCR:
f->fmt.pix.width = 480; ctrl->value = params->ts_pid_pcr;
f->fmt.pix.height = 576; break;
h->video_format = SAA6752HS_VF_2_3_D1; case V4L2_CID_MPEG_AUDIO_ENCODING:
} ctrl->value = params->au_encoding;
else { break;
f->fmt.pix.width = 352; case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
if (abs(f->fmt.pix.height - 576) < ctrl->value = params->au_l2_bitrate;
abs(f->fmt.pix.height - 288)) { break;
f->fmt.pix.height = 576; case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
h->video_format = SAA6752HS_VF_1_2_D1; if (!has_ac3)
} return -EINVAL;
else { ctrl->value = params->au_ac3_bitrate;
f->fmt.pix.height = 288; break;
h->video_format = SAA6752HS_VF_SIF; case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
} ctrl->value = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
break;
case V4L2_CID_MPEG_VIDEO_ENCODING:
ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
break;
case V4L2_CID_MPEG_VIDEO_ASPECT:
ctrl->value = params->vi_aspect;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE:
ctrl->value = params->vi_bitrate * 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
ctrl->value = params->vi_bitrate_peak * 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
ctrl->value = params->vi_bitrate_mode;
break;
default:
return -EINVAL;
} }
return 0;
} }
static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params, static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
struct v4l2_ext_control *ctrl, unsigned int cmd) struct v4l2_ext_control *ctrl, int set)
{ {
int old = 0, new; int old = 0, new;
int set = (cmd == VIDIOC_S_EXT_CTRLS);
new = ctrl->value; new = ctrl->value;
switch (ctrl->id) { switch (ctrl->id) {
case V4L2_CID_MPEG_STREAM_TYPE: case V4L2_CID_MPEG_STREAM_TYPE:
old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS; old = V4L2_MPEG_STREAM_TYPE_MPEG2_TS;
if (set && new != old) if (set && new != old)
return -ERANGE; return -ERANGE;
new = old; new = old;
break; break;
case V4L2_CID_MPEG_STREAM_PID_PMT: case V4L2_CID_MPEG_STREAM_PID_PMT:
old = params->ts_pid_pmt; old = params->ts_pid_pmt;
if (set && new > MPEG_PID_MAX) if (set && new > MPEG_PID_MAX)
return -ERANGE; return -ERANGE;
if (new > MPEG_PID_MAX) if (new > MPEG_PID_MAX)
new = MPEG_PID_MAX; new = MPEG_PID_MAX;
params->ts_pid_pmt = new; params->ts_pid_pmt = new;
break; break;
case V4L2_CID_MPEG_STREAM_PID_AUDIO: case V4L2_CID_MPEG_STREAM_PID_AUDIO:
old = params->ts_pid_audio; old = params->ts_pid_audio;
if (set && new > MPEG_PID_MAX) if (set && new > MPEG_PID_MAX)
return -ERANGE; return -ERANGE;
if (new > MPEG_PID_MAX) if (new > MPEG_PID_MAX)
new = MPEG_PID_MAX; new = MPEG_PID_MAX;
params->ts_pid_audio = new; params->ts_pid_audio = new;
break; break;
case V4L2_CID_MPEG_STREAM_PID_VIDEO: case V4L2_CID_MPEG_STREAM_PID_VIDEO:
old = params->ts_pid_video; old = params->ts_pid_video;
if (set && new > MPEG_PID_MAX) if (set && new > MPEG_PID_MAX)
return -ERANGE; return -ERANGE;
if (new > MPEG_PID_MAX) if (new > MPEG_PID_MAX)
new = MPEG_PID_MAX; new = MPEG_PID_MAX;
params->ts_pid_video = new; params->ts_pid_video = new;
break; break;
case V4L2_CID_MPEG_STREAM_PID_PCR: case V4L2_CID_MPEG_STREAM_PID_PCR:
old = params->ts_pid_pcr; old = params->ts_pid_pcr;
if (set && new > MPEG_PID_MAX) if (set && new > MPEG_PID_MAX)
return -ERANGE; return -ERANGE;
if (new > MPEG_PID_MAX) if (new > MPEG_PID_MAX)
new = MPEG_PID_MAX; new = MPEG_PID_MAX;
params->ts_pid_pcr = new; params->ts_pid_pcr = new;
break; break;
case V4L2_CID_MPEG_AUDIO_ENCODING: case V4L2_CID_MPEG_AUDIO_ENCODING:
old = params->au_encoding; old = params->au_encoding;
if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 && if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
(!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3)) (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
return -ERANGE; return -ERANGE;
new = old; new = old;
break; break;
case V4L2_CID_MPEG_AUDIO_L2_BITRATE: case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
old = params->au_l2_bitrate; old = params->au_l2_bitrate;
if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K && if (set && new != V4L2_MPEG_AUDIO_L2_BITRATE_256K &&
new != V4L2_MPEG_AUDIO_L2_BITRATE_384K) new != V4L2_MPEG_AUDIO_L2_BITRATE_384K)
return -ERANGE; return -ERANGE;
if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K) if (new <= V4L2_MPEG_AUDIO_L2_BITRATE_256K)
new = V4L2_MPEG_AUDIO_L2_BITRATE_256K; new = V4L2_MPEG_AUDIO_L2_BITRATE_256K;
else else
new = V4L2_MPEG_AUDIO_L2_BITRATE_384K; new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
params->au_l2_bitrate = new; params->au_l2_bitrate = new;
break; break;
case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
if (!has_ac3) if (!has_ac3)
return -EINVAL;
old = params->au_ac3_bitrate;
if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
return -ERANGE;
if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
else
new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
params->au_ac3_bitrate = new;
break;
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
if (set && new != old)
return -ERANGE;
new = old;
break;
case V4L2_CID_MPEG_VIDEO_ENCODING:
old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
if (set && new != old)
return -ERANGE;
new = old;
break;
case V4L2_CID_MPEG_VIDEO_ASPECT:
old = params->vi_aspect;
if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
new != V4L2_MPEG_VIDEO_ASPECT_4x3)
return -ERANGE;
if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
new = V4L2_MPEG_VIDEO_ASPECT_4x3;
params->vi_aspect = new;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE:
old = params->vi_bitrate * 1000;
new = 1000 * (new / 1000);
if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
return -ERANGE;
if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
params->vi_bitrate = new / 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
old = params->vi_bitrate_peak * 1000;
new = 1000 * (new / 1000);
if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
return -ERANGE;
if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
params->vi_bitrate_peak = new / 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
old = params->vi_bitrate_mode;
params->vi_bitrate_mode = new;
break;
default:
return -EINVAL; return -EINVAL;
old = params->au_ac3_bitrate;
if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
return -ERANGE;
if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
else
new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
params->au_ac3_bitrate = new;
break;
case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
if (set && new != old)
return -ERANGE;
new = old;
break;
case V4L2_CID_MPEG_VIDEO_ENCODING:
old = V4L2_MPEG_VIDEO_ENCODING_MPEG_2;
if (set && new != old)
return -ERANGE;
new = old;
break;
case V4L2_CID_MPEG_VIDEO_ASPECT:
old = params->vi_aspect;
if (set && new != V4L2_MPEG_VIDEO_ASPECT_16x9 &&
new != V4L2_MPEG_VIDEO_ASPECT_4x3)
return -ERANGE;
if (new != V4L2_MPEG_VIDEO_ASPECT_16x9)
new = V4L2_MPEG_VIDEO_ASPECT_4x3;
params->vi_aspect = new;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE:
old = params->vi_bitrate * 1000;
new = 1000 * (new / 1000);
if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
return -ERANGE;
if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
params->vi_bitrate = new / 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
old = params->vi_bitrate_peak * 1000;
new = 1000 * (new / 1000);
if (set && new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
return -ERANGE;
if (new > MPEG_VIDEO_TARGET_BITRATE_MAX * 1000)
new = MPEG_VIDEO_TARGET_BITRATE_MAX * 1000;
params->vi_bitrate_peak = new / 1000;
break;
case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
old = params->vi_bitrate_mode;
params->vi_bitrate_mode = new;
break;
default:
return -EINVAL;
} }
if (cmd == VIDIOC_G_EXT_CTRLS) ctrl->value = new;
ctrl->value = old;
else
ctrl->value = new;
return 0; return 0;
} }
static int saa6752hs_qctrl(struct saa6752hs_state *h,
struct v4l2_queryctrl *qctrl) static int saa6752hs_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qctrl)
{ {
struct saa6752hs_state *h = to_state(sd);
struct saa6752hs_mpeg_params *params = &h->params; struct saa6752hs_mpeg_params *params = &h->params;
int err; int err;
...@@ -610,8 +623,7 @@ static int saa6752hs_qctrl(struct saa6752hs_state *h, ...@@ -610,8 +623,7 @@ static int saa6752hs_qctrl(struct saa6752hs_state *h,
return -EINVAL; return -EINVAL;
} }
static int saa6752hs_qmenu(struct saa6752hs_state *h, static int saa6752hs_querymenu(struct v4l2_subdev *sd, struct v4l2_querymenu *qmenu)
struct v4l2_querymenu *qmenu)
{ {
static const u32 mpeg_audio_encoding[] = { static const u32 mpeg_audio_encoding[] = {
V4L2_MPEG_AUDIO_ENCODING_LAYER_2, V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
...@@ -632,11 +644,12 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h, ...@@ -632,11 +644,12 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h,
V4L2_MPEG_AUDIO_AC3_BITRATE_384K, V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
V4L2_CTRL_MENU_IDS_END V4L2_CTRL_MENU_IDS_END
}; };
struct saa6752hs_state *h = to_state(sd);
struct v4l2_queryctrl qctrl; struct v4l2_queryctrl qctrl;
int err; int err;
qctrl.id = qmenu->id; qctrl.id = qmenu->id;
err = saa6752hs_qctrl(h, &qctrl); err = saa6752hs_queryctrl(sd, &qctrl);
if (err) if (err)
return err; return err;
switch (qmenu->id) { switch (qmenu->id) {
...@@ -656,17 +669,16 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h, ...@@ -656,17 +669,16 @@ static int saa6752hs_qmenu(struct saa6752hs_state *h,
return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL); return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
} }
static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes) static int saa6752hs_init(struct v4l2_subdev *sd, u32 leading_null_bytes)
{ {
unsigned char buf[9], buf2[4]; unsigned char buf[9], buf2[4];
struct saa6752hs_state *h; struct saa6752hs_state *h = to_state(sd);
struct i2c_client *client = v4l2_get_subdevdata(sd);
unsigned size; unsigned size;
u32 crc; u32 crc;
unsigned char localPAT[256]; unsigned char localPAT[256];
unsigned char localPMT[256]; unsigned char localPMT[256];
h = i2c_get_clientdata(client);
/* Set video format - must be done first as it resets other settings */ /* Set video format - must be done first as it resets other settings */
set_reg8(client, 0x41, h->video_format); set_reg8(client, 0x41, h->video_format);
...@@ -762,7 +774,7 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes) ...@@ -762,7 +774,7 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
buf[3] = 0x82; buf[3] = 0x82;
buf[4] = 0xB0; buf[4] = 0xB0;
buf[5] = buf2[0]; buf[5] = buf2[0];
switch(h->params.vi_aspect) { switch (h->params.vi_aspect) {
case V4L2_MPEG_VIDEO_ASPECT_16x9: case V4L2_MPEG_VIDEO_ASPECT_16x9:
buf[6] = buf2[1] | 0x40; buf[6] = buf2[1] | 0x40;
break; break;
...@@ -770,7 +782,6 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes) ...@@ -770,7 +782,6 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
default: default:
buf[6] = buf2[1] & 0xBF; buf[6] = buf2[1] & 0xBF;
break; break;
break;
} }
buf[7] = buf2[2]; buf[7] = buf2[2];
buf[8] = buf2[3]; buf[8] = buf2[3];
...@@ -779,81 +790,167 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes) ...@@ -779,81 +790,167 @@ static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
return 0; return 0;
} }
static int static int saa6752hs_do_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls, int set)
saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
{ {
struct saa6752hs_state *h = i2c_get_clientdata(client); struct saa6752hs_state *h = to_state(sd);
struct v4l2_ext_controls *ctrls = arg;
struct saa6752hs_mpeg_params params; struct saa6752hs_mpeg_params params;
int err = 0;
int i; int i;
switch (cmd) { if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
case VIDIOC_INT_INIT: return -EINVAL;
/* apply settings and start encoder */
saa6752hs_init(client, *(u32 *)arg); params = h->params;
break; for (i = 0; i < ctrls->count; i++) {
case VIDIOC_S_EXT_CTRLS: int err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, set);
if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL; if (err) {
/* fall through */ ctrls->error_idx = i;
case VIDIOC_TRY_EXT_CTRLS: return err;
case VIDIOC_G_EXT_CTRLS:
if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL;
params = h->params;
for (i = 0; i < ctrls->count; i++) {
err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, cmd);
if (err) {
ctrls->error_idx = i;
return err;
}
} }
h->params = params;
break;
case VIDIOC_QUERYCTRL:
return saa6752hs_qctrl(h, arg);
case VIDIOC_QUERYMENU:
return saa6752hs_qmenu(h, arg);
case VIDIOC_G_FMT:
{
struct v4l2_format *f = arg;
if (h->video_format == SAA6752HS_VF_UNKNOWN)
h->video_format = SAA6752HS_VF_D1;
f->fmt.pix.width =
v4l2_format_table[h->video_format].fmt.pix.width;
f->fmt.pix.height =
v4l2_format_table[h->video_format].fmt.pix.height;
break ;
} }
case VIDIOC_S_FMT: if (set)
{ h->params = params;
struct v4l2_format *f = arg; return 0;
}
saa6752hs_set_subsampling(client, f); static int saa6752hs_s_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
break; {
return saa6752hs_do_ext_ctrls(sd, ctrls, 1);
}
static int saa6752hs_try_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
{
return saa6752hs_do_ext_ctrls(sd, ctrls, 0);
}
static int saa6752hs_g_ext_ctrls(struct v4l2_subdev *sd, struct v4l2_ext_controls *ctrls)
{
struct saa6752hs_state *h = to_state(sd);
int i;
if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
return -EINVAL;
for (i = 0; i < ctrls->count; i++) {
int err = get_ctrl(h->has_ac3, &h->params, ctrls->controls + i);
if (err) {
ctrls->error_idx = i;
return err;
}
} }
case VIDIOC_S_STD: return 0;
h->standard = *((v4l2_std_id *) arg); }
break;
case VIDIOC_DBG_G_CHIP_IDENT: static int saa6752hs_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
return v4l2_chip_ident_i2c_client(client, {
arg, h->chip, h->revision); struct saa6752hs_state *h = to_state(sd);
default: if (h->video_format == SAA6752HS_VF_UNKNOWN)
/* nothing */ h->video_format = SAA6752HS_VF_D1;
break; f->fmt.pix.width =
v4l2_format_table[h->video_format].fmt.pix.width;
f->fmt.pix.height =
v4l2_format_table[h->video_format].fmt.pix.height;
return 0;
}
static int saa6752hs_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
{
struct saa6752hs_state *h = to_state(sd);
int dist_352, dist_480, dist_720;
/*
FIXME: translate and round width/height into EMPRESS
subsample type:
type | PAL | NTSC
---------------------------
SIF | 352x288 | 352x240
1/2 D1 | 352x576 | 352x480
2/3 D1 | 480x576 | 480x480
D1 | 720x576 | 720x480
*/
dist_352 = abs(f->fmt.pix.width - 352);
dist_480 = abs(f->fmt.pix.width - 480);
dist_720 = abs(f->fmt.pix.width - 720);
if (dist_720 < dist_480) {
f->fmt.pix.width = 720;
f->fmt.pix.height = 576;
h->video_format = SAA6752HS_VF_D1;
} else if (dist_480 < dist_352) {
f->fmt.pix.width = 480;
f->fmt.pix.height = 576;
h->video_format = SAA6752HS_VF_2_3_D1;
} else {
f->fmt.pix.width = 352;
if (abs(f->fmt.pix.height - 576) <
abs(f->fmt.pix.height - 288)) {
f->fmt.pix.height = 576;
h->video_format = SAA6752HS_VF_1_2_D1;
} else {
f->fmt.pix.height = 288;
h->video_format = SAA6752HS_VF_SIF;
}
} }
return 0;
}
static int saa6752hs_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
{
struct saa6752hs_state *h = to_state(sd);
h->standard = std;
return 0;
}
static int saa6752hs_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
struct saa6752hs_state *h = to_state(sd);
return v4l2_chip_ident_i2c_client(client,
chip, h->chip, h->revision);
}
return err; static int saa6752hs_command(struct i2c_client *client, unsigned cmd, void *arg)
{
return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
} }
/* ----------------------------------------------------------------------- */
static const struct v4l2_subdev_core_ops saa6752hs_core_ops = {
.g_chip_ident = saa6752hs_g_chip_ident,
.init = saa6752hs_init,
.queryctrl = saa6752hs_queryctrl,
.querymenu = saa6752hs_querymenu,
.g_ext_ctrls = saa6752hs_g_ext_ctrls,
.s_ext_ctrls = saa6752hs_s_ext_ctrls,
.try_ext_ctrls = saa6752hs_try_ext_ctrls,
};
static const struct v4l2_subdev_tuner_ops saa6752hs_tuner_ops = {
.s_std = saa6752hs_s_std,
};
static const struct v4l2_subdev_video_ops saa6752hs_video_ops = {
.s_fmt = saa6752hs_s_fmt,
.g_fmt = saa6752hs_g_fmt,
};
static const struct v4l2_subdev_ops saa6752hs_ops = {
.core = &saa6752hs_core_ops,
.tuner = &saa6752hs_tuner_ops,
.video = &saa6752hs_video_ops,
};
static int saa6752hs_probe(struct i2c_client *client, static int saa6752hs_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL); struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
struct v4l2_subdev *sd;
u8 addr = 0x13; u8 addr = 0x13;
u8 data[12]; u8 data[12];
...@@ -861,6 +958,8 @@ static int saa6752hs_probe(struct i2c_client *client, ...@@ -861,6 +958,8 @@ static int saa6752hs_probe(struct i2c_client *client,
client->addr << 1, client->adapter->name); client->addr << 1, client->adapter->name);
if (h == NULL) if (h == NULL)
return -ENOMEM; return -ENOMEM;
sd = &h->sd;
v4l2_i2c_subdev_init(sd, client, &saa6752hs_ops);
i2c_master_send(client, &addr, 1); i2c_master_send(client, &addr, 1);
i2c_master_recv(client, data, sizeof(data)); i2c_master_recv(client, data, sizeof(data));
...@@ -874,14 +973,15 @@ static int saa6752hs_probe(struct i2c_client *client, ...@@ -874,14 +973,15 @@ static int saa6752hs_probe(struct i2c_client *client,
} }
h->params = param_defaults; h->params = param_defaults;
h->standard = 0; /* Assume 625 input lines */ h->standard = 0; /* Assume 625 input lines */
i2c_set_clientdata(client, h);
return 0; return 0;
} }
static int saa6752hs_remove(struct i2c_client *client) static int saa6752hs_remove(struct i2c_client *client)
{ {
kfree(i2c_get_clientdata(client)); struct v4l2_subdev *sd = i2c_get_clientdata(client);
v4l2_device_unregister_subdev(sd);
kfree(to_state(sd));
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