Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 208195
b: refs/heads/master
c: 5aa9ae5
h: refs/heads/master
i:
  208193: 033bf29
  208191: 0456831
v: v3
  • Loading branch information
Hans Verkuil authored and Mauro Carvalho Chehab committed Aug 9, 2010
1 parent 97c6bc2 commit 09473e5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f6e114eed0414fbba9eb73480cd8efdaba96aaa7
refs/heads/master: 5aa9ae5ed5d449a85fbf7aac3d1fdc241c542a79
79 changes: 50 additions & 29 deletions trunk/drivers/media/video/wm8775.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-chip-ident.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-i2c-drv.h>

MODULE_DESCRIPTION("wm8775 driver");
Expand All @@ -53,15 +54,21 @@ enum {

struct wm8775_state {
struct v4l2_subdev sd;
struct v4l2_ctrl_handler hdl;
struct v4l2_ctrl *mute;
u8 input; /* Last selected input (0-0xf) */
u8 muted;
};

static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
{
return container_of(sd, struct wm8775_state, sd);
}

static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
{
return &container_of(ctrl->handler, struct wm8775_state, hdl)->sd;
}

static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val)
{
struct i2c_client *client = v4l2_get_subdevdata(sd);
Expand Down Expand Up @@ -95,7 +102,7 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
return -EINVAL;
}
state->input = input;
if (state->muted)
if (!v4l2_ctrl_g_ctrl(state->mute))
return 0;
wm8775_write(sd, R21, 0x0c0);
wm8775_write(sd, R14, 0x1d4);
Expand All @@ -104,29 +111,21 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
return 0;
}

static int wm8775_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
static int wm8775_s_ctrl(struct v4l2_ctrl *ctrl)
{
struct v4l2_subdev *sd = to_sd(ctrl);
struct wm8775_state *state = to_state(sd);

if (ctrl->id != V4L2_CID_AUDIO_MUTE)
return -EINVAL;
ctrl->value = state->muted;
return 0;
}

static int wm8775_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
struct wm8775_state *state = to_state(sd);

if (ctrl->id != V4L2_CID_AUDIO_MUTE)
return -EINVAL;
state->muted = ctrl->value;
wm8775_write(sd, R21, 0x0c0);
wm8775_write(sd, R14, 0x1d4);
wm8775_write(sd, R15, 0x1d4);
if (!state->muted)
wm8775_write(sd, R21, 0x100 + state->input);
return 0;
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);
return 0;
}
return -EINVAL;
}

static int wm8775_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
Expand All @@ -140,8 +139,8 @@ static int wm8775_log_status(struct v4l2_subdev *sd)
{
struct wm8775_state *state = to_state(sd);

v4l2_info(sd, "Input: %d%s\n", state->input,
state->muted ? " (muted)" : "");
v4l2_info(sd, "Input: %d\n", state->input);
v4l2_ctrl_handler_log_status(&state->hdl, sd->name);
return 0;
}

Expand All @@ -162,11 +161,20 @@ static int wm8775_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *fre

/* ----------------------------------------------------------------------- */

static const struct v4l2_ctrl_ops wm8775_ctrl_ops = {
.s_ctrl = wm8775_s_ctrl,
};

static const struct v4l2_subdev_core_ops wm8775_core_ops = {
.log_status = wm8775_log_status,
.g_chip_ident = wm8775_g_chip_ident,
.g_ctrl = wm8775_g_ctrl,
.s_ctrl = wm8775_s_ctrl,
.g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
.try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
.s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
.g_ctrl = v4l2_subdev_g_ctrl,
.s_ctrl = v4l2_subdev_s_ctrl,
.queryctrl = v4l2_subdev_queryctrl,
.querymenu = v4l2_subdev_querymenu,
};

static const struct v4l2_subdev_tuner_ops wm8775_tuner_ops = {
Expand Down Expand Up @@ -205,13 +213,24 @@ static int wm8775_probe(struct i2c_client *client,
v4l_info(client, "chip found @ 0x%02x (%s)\n",
client->addr << 1, client->adapter->name);

state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL);
state = kzalloc(sizeof(struct wm8775_state), GFP_KERNEL);
if (state == NULL)
return -ENOMEM;
sd = &state->sd;
v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
state->input = 2;
state->muted = 0;

v4l2_ctrl_handler_init(&state->hdl, 1);
state->mute = v4l2_ctrl_new_std(&state->hdl, &wm8775_ctrl_ops,
V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0);
sd->ctrl_handler = &state->hdl;
if (state->hdl.error) {
int err = state->hdl.error;

v4l2_ctrl_handler_free(&state->hdl);
kfree(state);
return err;
}

/* Initialize wm8775 */

Expand Down Expand Up @@ -248,9 +267,11 @@ static int wm8775_probe(struct i2c_client *client,
static int wm8775_remove(struct i2c_client *client)
{
struct v4l2_subdev *sd = i2c_get_clientdata(client);
struct wm8775_state *state = to_state(sd);

v4l2_device_unregister_subdev(sd);
kfree(to_state(sd));
v4l2_ctrl_handler_free(&state->hdl);
kfree(state);
return 0;
}

Expand Down

0 comments on commit 09473e5

Please sign in to comment.