Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa9ae5e authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab
Browse files

V4L/DVB: wm8775: convert to the new control framework

parent f6e114ee
Loading
Loading
Loading
Loading
+50 −29
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@
#include <linux/videodev2.h>
#include <linux/videodev2.h>
#include <media/v4l2-device.h>
#include <media/v4l2-device.h>
#include <media/v4l2-chip-ident.h>
#include <media/v4l2-chip-ident.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-i2c-drv.h>
#include <media/v4l2-i2c-drv.h>


MODULE_DESCRIPTION("wm8775 driver");
MODULE_DESCRIPTION("wm8775 driver");
@@ -53,8 +54,9 @@ enum {


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


static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
@@ -62,6 +64,11 @@ static inline struct wm8775_state *to_state(struct v4l2_subdev *sd)
	return container_of(sd, struct wm8775_state, 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)
static int wm8775_write(struct v4l2_subdev *sd, int reg, u16 val)
{
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -95,7 +102,7 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
		return -EINVAL;
		return -EINVAL;
	}
	}
	state->input = input;
	state->input = input;
	if (state->muted)
	if (!v4l2_ctrl_g_ctrl(state->mute))
		return 0;
		return 0;
	wm8775_write(sd, R21, 0x0c0);
	wm8775_write(sd, R21, 0x0c0);
	wm8775_write(sd, R14, 0x1d4);
	wm8775_write(sd, R14, 0x1d4);
@@ -104,30 +111,22 @@ static int wm8775_s_routing(struct v4l2_subdev *sd,
	return 0;
	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);
	struct wm8775_state *state = to_state(sd);


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


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


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


@@ -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 = {
static const struct v4l2_subdev_core_ops wm8775_core_ops = {
	.log_status = wm8775_log_status,
	.log_status = wm8775_log_status,
	.g_chip_ident = wm8775_g_chip_ident,
	.g_chip_ident = wm8775_g_chip_ident,
	.g_ctrl = wm8775_g_ctrl,
	.g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
	.s_ctrl = wm8775_s_ctrl,
	.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 = {
static const struct v4l2_subdev_tuner_ops wm8775_tuner_ops = {
@@ -205,13 +213,24 @@ static int wm8775_probe(struct i2c_client *client,
	v4l_info(client, "chip found @ 0x%02x (%s)\n",
	v4l_info(client, "chip found @ 0x%02x (%s)\n",
			client->addr << 1, client->adapter->name);
			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)
	if (state == NULL)
		return -ENOMEM;
		return -ENOMEM;
	sd = &state->sd;
	sd = &state->sd;
	v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
	v4l2_i2c_subdev_init(sd, client, &wm8775_ops);
	state->input = 2;
	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 */
	/* Initialize wm8775 */


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


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