diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2010-12-12 06:45:04 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2011-03-21 19:31:50 -0400 |
commit | e3d5ef0410806d94cf58afd87a753ad5932ca8a8 (patch) | |
tree | 909d6136ef0ee7f1d606eafb04d39ebefbe62e9d /drivers/media/video/tlv320aic23b.c | |
parent | 4744ebf631bc9276f7c10e37801f05c8ceea7bab (diff) |
[media] tlv320aic23b: use control framework
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tlv320aic23b.c')
-rw-r--r-- | drivers/media/video/tlv320aic23b.c | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c index dfc4dd7c5097..286ec7e7062a 100644 --- a/drivers/media/video/tlv320aic23b.c +++ b/drivers/media/video/tlv320aic23b.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/i2c.h> | 31 | #include <linux/i2c.h> |
32 | #include <linux/videodev2.h> | 32 | #include <linux/videodev2.h> |
33 | #include <media/v4l2-device.h> | 33 | #include <media/v4l2-device.h> |
34 | #include <media/v4l2-ctrls.h> | ||
34 | 35 | ||
35 | MODULE_DESCRIPTION("tlv320aic23b driver"); | 36 | MODULE_DESCRIPTION("tlv320aic23b driver"); |
36 | MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil"); | 37 | MODULE_AUTHOR("Scott Alfter, Ulf Eklund, Hans Verkuil"); |
@@ -41,7 +42,7 @@ MODULE_LICENSE("GPL"); | |||
41 | 42 | ||
42 | struct tlv320aic23b_state { | 43 | struct tlv320aic23b_state { |
43 | struct v4l2_subdev sd; | 44 | struct v4l2_subdev sd; |
44 | u8 muted; | 45 | struct v4l2_ctrl_handler hdl; |
45 | }; | 46 | }; |
46 | 47 | ||
47 | static inline struct tlv320aic23b_state *to_state(struct v4l2_subdev *sd) | 48 | static inline struct tlv320aic23b_state *to_state(struct v4l2_subdev *sd) |
@@ -49,6 +50,11 @@ static inline struct tlv320aic23b_state *to_state(struct v4l2_subdev *sd) | |||
49 | return container_of(sd, struct tlv320aic23b_state, sd); | 50 | return container_of(sd, struct tlv320aic23b_state, sd); |
50 | } | 51 | } |
51 | 52 | ||
53 | static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl) | ||
54 | { | ||
55 | return &container_of(ctrl->handler, struct tlv320aic23b_state, hdl)->sd; | ||
56 | } | ||
57 | |||
52 | static int tlv320aic23b_write(struct v4l2_subdev *sd, int reg, u16 val) | 58 | static int tlv320aic23b_write(struct v4l2_subdev *sd, int reg, u16 val) |
53 | { | 59 | { |
54 | struct i2c_client *client = v4l2_get_subdevdata(sd); | 60 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
@@ -85,44 +91,44 @@ static int tlv320aic23b_s_clock_freq(struct v4l2_subdev *sd, u32 freq) | |||
85 | return 0; | 91 | return 0; |
86 | } | 92 | } |
87 | 93 | ||
88 | static int tlv320aic23b_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | 94 | static int tlv320aic23b_s_ctrl(struct v4l2_ctrl *ctrl) |
89 | { | ||
90 | struct tlv320aic23b_state *state = to_state(sd); | ||
91 | |||
92 | if (ctrl->id != V4L2_CID_AUDIO_MUTE) | ||
93 | return -EINVAL; | ||
94 | ctrl->value = state->muted; | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | static int tlv320aic23b_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) | ||
99 | { | 95 | { |
100 | struct tlv320aic23b_state *state = to_state(sd); | 96 | struct v4l2_subdev *sd = to_sd(ctrl); |
101 | 97 | ||
102 | if (ctrl->id != V4L2_CID_AUDIO_MUTE) | 98 | switch (ctrl->id) { |
103 | return -EINVAL; | 99 | case V4L2_CID_AUDIO_MUTE: |
104 | state->muted = ctrl->value; | 100 | tlv320aic23b_write(sd, 0, 0x180); /* mute both channels */ |
105 | tlv320aic23b_write(sd, 0, 0x180); /* mute both channels */ | 101 | /* set gain on both channels to +3.0 dB */ |
106 | /* set gain on both channels to +3.0 dB */ | 102 | if (!ctrl->val) |
107 | if (!state->muted) | 103 | tlv320aic23b_write(sd, 0, 0x119); |
108 | tlv320aic23b_write(sd, 0, 0x119); | 104 | return 0; |
109 | return 0; | 105 | } |
106 | return -EINVAL; | ||
110 | } | 107 | } |
111 | 108 | ||
112 | static int tlv320aic23b_log_status(struct v4l2_subdev *sd) | 109 | static int tlv320aic23b_log_status(struct v4l2_subdev *sd) |
113 | { | 110 | { |
114 | struct tlv320aic23b_state *state = to_state(sd); | 111 | struct tlv320aic23b_state *state = to_state(sd); |
115 | 112 | ||
116 | v4l2_info(sd, "Input: %s\n", state->muted ? "muted" : "active"); | 113 | v4l2_ctrl_handler_log_status(&state->hdl, sd->name); |
117 | return 0; | 114 | return 0; |
118 | } | 115 | } |
119 | 116 | ||
120 | /* ----------------------------------------------------------------------- */ | 117 | /* ----------------------------------------------------------------------- */ |
121 | 118 | ||
119 | static const struct v4l2_ctrl_ops tlv320aic23b_ctrl_ops = { | ||
120 | .s_ctrl = tlv320aic23b_s_ctrl, | ||
121 | }; | ||
122 | |||
122 | static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = { | 123 | static const struct v4l2_subdev_core_ops tlv320aic23b_core_ops = { |
123 | .log_status = tlv320aic23b_log_status, | 124 | .log_status = tlv320aic23b_log_status, |
124 | .g_ctrl = tlv320aic23b_g_ctrl, | 125 | .g_ext_ctrls = v4l2_subdev_g_ext_ctrls, |
125 | .s_ctrl = tlv320aic23b_s_ctrl, | 126 | .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, |
127 | .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, | ||
128 | .g_ctrl = v4l2_subdev_g_ctrl, | ||
129 | .s_ctrl = v4l2_subdev_s_ctrl, | ||
130 | .queryctrl = v4l2_subdev_queryctrl, | ||
131 | .querymenu = v4l2_subdev_querymenu, | ||
126 | }; | 132 | }; |
127 | 133 | ||
128 | static const struct v4l2_subdev_audio_ops tlv320aic23b_audio_ops = { | 134 | static const struct v4l2_subdev_audio_ops tlv320aic23b_audio_ops = { |
@@ -161,7 +167,6 @@ static int tlv320aic23b_probe(struct i2c_client *client, | |||
161 | return -ENOMEM; | 167 | return -ENOMEM; |
162 | sd = &state->sd; | 168 | sd = &state->sd; |
163 | v4l2_i2c_subdev_init(sd, client, &tlv320aic23b_ops); | 169 | v4l2_i2c_subdev_init(sd, client, &tlv320aic23b_ops); |
164 | state->muted = 0; | ||
165 | 170 | ||
166 | /* Initialize tlv320aic23b */ | 171 | /* Initialize tlv320aic23b */ |
167 | 172 | ||
@@ -177,15 +182,30 @@ static int tlv320aic23b_probe(struct i2c_client *client, | |||
177 | tlv320aic23b_write(sd, 8, 0x000); | 182 | tlv320aic23b_write(sd, 8, 0x000); |
178 | /* activate digital interface */ | 183 | /* activate digital interface */ |
179 | tlv320aic23b_write(sd, 9, 0x001); | 184 | tlv320aic23b_write(sd, 9, 0x001); |
185 | |||
186 | v4l2_ctrl_handler_init(&state->hdl, 1); | ||
187 | v4l2_ctrl_new_std(&state->hdl, &tlv320aic23b_ctrl_ops, | ||
188 | V4L2_CID_AUDIO_MUTE, 0, 1, 1, 0); | ||
189 | sd->ctrl_handler = &state->hdl; | ||
190 | if (state->hdl.error) { | ||
191 | int err = state->hdl.error; | ||
192 | |||
193 | v4l2_ctrl_handler_free(&state->hdl); | ||
194 | kfree(state); | ||
195 | return err; | ||
196 | } | ||
197 | v4l2_ctrl_handler_setup(&state->hdl); | ||
180 | return 0; | 198 | return 0; |
181 | } | 199 | } |
182 | 200 | ||
183 | static int tlv320aic23b_remove(struct i2c_client *client) | 201 | static int tlv320aic23b_remove(struct i2c_client *client) |
184 | { | 202 | { |
185 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | 203 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
204 | struct tlv320aic23b_state *state = to_state(sd); | ||
186 | 205 | ||
187 | v4l2_device_unregister_subdev(sd); | 206 | v4l2_device_unregister_subdev(sd); |
188 | kfree(to_state(sd)); | 207 | v4l2_ctrl_handler_free(&state->hdl); |
208 | kfree(state); | ||
189 | return 0; | 209 | return 0; |
190 | } | 210 | } |
191 | 211 | ||