From patchwork Sun May 16 13:21:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 99950 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4GDKFGG019935 for ; Sun, 16 May 2010 13:20:15 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753015Ab0EPNUN (ORCPT ); Sun, 16 May 2010 09:20:13 -0400 Received: from smtp-vbr7.xs4all.nl ([194.109.24.27]:2835 "EHLO smtp-vbr7.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752403Ab0EPNUM (ORCPT ); Sun, 16 May 2010 09:20:12 -0400 Received: from localhost (cm-84.208.87.21.getinternet.no [84.208.87.21]) by smtp-vbr7.xs4all.nl (8.13.8/8.13.8) with ESMTP id o4GDK7fe058866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 16 May 2010 15:20:11 +0200 (CEST) (envelope-from hverkuil@xs4all.nl) Message-Id: <4b2c3f76171e1c71af0b203745099126b4128dfa.1274015085.git.hverkuil@xs4all.nl> In-Reply-To: References: From: Hans Verkuil Date: Sun, 16 May 2010 15:21:46 +0200 Subject: [PATCH 11/15] [RFCv2] wm8775: convert to the new control framework To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Sun, 16 May 2010 13:20:15 +0000 (UTC) diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c index f1f261a..09a9663 100644 --- a/drivers/media/video/wm8775.c +++ b/drivers/media/video/wm8775.c @@ -34,6 +34,7 @@ #include #include #include +#include #include MODULE_DESCRIPTION("wm8775 driver"); @@ -52,8 +53,9 @@ 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) @@ -61,6 +63,11 @@ 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); @@ -94,7 +101,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); @@ -103,29 +110,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) @@ -139,8 +138,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; } @@ -161,11 +160,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 = { @@ -204,13 +212,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 */ @@ -247,9 +266,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; }