Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] tlv320aic23b: use control framework

Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
e3d5ef04 4744ebf6

+46 -26
+46 -26
drivers/media/video/tlv320aic23b.c
··· 31 31 #include <linux/i2c.h> 32 32 #include <linux/videodev2.h> 33 33 #include <media/v4l2-device.h> 34 + #include <media/v4l2-ctrls.h> 34 35 35 36 MODULE_DESCRIPTION("tlv320aic23b driver"); 36 37 MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil"); ··· 42 41 43 42 struct tlv320aic23b_state { 44 43 struct v4l2_subdev sd; 45 - u8 muted; 44 + struct v4l2_ctrl_handler hdl; 46 45 }; 47 46 48 47 static inline struct tlv320aic23b_state *to_state(struct v4l2_subdev *sd) 49 48 { 50 49 return container_of(sd, struct tlv320aic23b_state, sd); 50 + } 51 + 52 + static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) 53 + { 54 + return &container_of(ctrl->handler, struct tlv320aic23b_state, hdl)->sd; 51 55 } 52 56 53 57 static int tlv320aic23b_write(struct v4l2_subdev *sd, int reg, u16 val) ··· 91 85 return 0; 92 86 } 93 87 94 - static int tlv320aic23b_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 88 + static int tlv320aic23b_s_ctrl(struct v4l2_ctrl *ctrl) 95 89 { 96 - struct tlv320aic23b_state *state = to_state(sd); 90 + struct v4l2_subdev *sd = to_sd(ctrl); 97 91 98 - if (ctrl->id != V4L2_CID_AUDIO_MUTE) 99 - return -EINVAL; 100 - ctrl->value = state->muted; 101 - return 0; 102 - } 103 - 104 - static int tlv320aic23b_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 105 - { 106 - struct tlv320aic23b_state *state = to_state(sd); 107 - 108 - if (ctrl->id != V4L2_CID_AUDIO_MUTE) 109 - return -EINVAL; 110 - state->muted = ctrl->value; 111 - tlv320aic23b_write(sd, 0, 0x180); /* mute both channels */ 112 - /* set gain on both channels to +3.0 dB */ 113 - if (!state->muted) 114 - tlv320aic23b_write(sd, 0, 0x119); 115 - return 0; 92 + switch (ctrl->id) { 93 + case V4L2_CID_AUDIO_MUTE: 94 + tlv320aic23b_write(sd, 0, 0x180); /* mute both channels */ 95 + /* set gain on both channels to +3.0 dB */ 96 + if (!ctrl->val) 97 + tlv320aic23b_write(sd, 0, 0x119); 98 + return 0; 99 + } 100 + return -EINVAL; 116 101 } 117 102 118 103 static int tlv320aic23b_log_status(struct v4l2_subdev *sd) 119 104 { 120 105 struct tlv320aic23b_state *state = to_state(sd); 121 106 122 - v4l2_info(sd, "Input: %s\n", state->muted ? "muted" : "active"); 107 + v4l2_ctrl_handler_log_status(&state->hdl, sd->name); 123 108 return 0; 124 109 } 125 110 126 111 /* ----------------------------------------------------------------------- */ 127 112 113 + static const struct v4l2_ctrl_ops tlv320aic23b_ctrl_ops = { 114 + .s_ctrl = tlv320aic23b_s_ctrl, 115 + }; 116 + 128 117 static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = { 129 118 .log_status = tlv320aic23b_log_status, 130 - .g_ctrl = tlv320aic23b_g_ctrl, 131 - .s_ctrl = tlv320aic23b_s_ctrl, 119 + .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, 120 + .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, 121 + .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, 122 + .g_ctrl = v4l2_subdev_g_ctrl, 123 + .s_ctrl = v4l2_subdev_s_ctrl, 124 + .queryctrl = v4l2_subdev_queryctrl, 125 + .querymenu = v4l2_subdev_querymenu, 132 126 }; 133 127 134 128 static const struct v4l2_subdev_audio_ops tlv320aic23b_audio_ops = { ··· 167 161 return -ENOMEM; 168 162 sd = &state->sd; 169 163 v4l2_i2c_subdev_init(sd, client, &tlv320aic23b_ops); 170 - state->muted = 0; 171 164 172 165 /* Initialize tlv320aic23b */ 173 166 ··· 182 177 tlv320aic23b_write(sd, 8, 0x000); 183 178 /* activate digital interface */ 184 179 tlv320aic23b_write(sd, 9, 0x001); 180 + 181 + v4l2_ctrl_handler_init(&state->hdl, 1); 182 + v4l2_ctrl_new_std(&state->hdl, &tlv320aic23b_ctrl_ops, 183 + V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0); 184 + sd->ctrl_handler = &state->hdl; 185 + if (state->hdl.error) { 186 + int err = state->hdl.error; 187 + 188 + v4l2_ctrl_handler_free(&state->hdl); 189 + kfree(state); 190 + return err; 191 + } 192 + v4l2_ctrl_handler_setup(&state->hdl); 185 193 return 0; 186 194 } 187 195 188 196 static int tlv320aic23b_remove(struct i2c_client *client) 189 197 { 190 198 struct v4l2_subdev *sd = i2c_get_clientdata(client); 199 + struct tlv320aic23b_state *state = to_state(sd); 191 200 192 201 v4l2_device_unregister_subdev(sd); 193 - kfree(to_state(sd)); 202 + v4l2_ctrl_handler_free(&state->hdl); 203 + kfree(state); 194 204 return 0; 195 205 } 196 206