diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2007-09-14 04:03:17 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-01-25 16:01:27 -0500 |
commit | 6235168db8ed96c587e566be0dd72a77ca212693 (patch) | |
tree | a81902aab6e6b08dd28bc15ac617eb39b848b701 | |
parent | 2b14e0314631bac6388c4501f3103ab5af22c0f0 (diff) |
V4L/DVB (6464): tlv320aic23b: convert to bus-based I2C API
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
-rw-r--r-- | drivers/media/video/tlv320aic23b.c | 71 |
1 files changed, 13 insertions, 58 deletions
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c index 76b2e96429d9..0282f385bbdf 100644 --- a/drivers/media/video/tlv320aic23b.c +++ b/drivers/media/video/tlv320aic23b.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/i2c-id.h> | 31 | #include <linux/i2c-id.h> |
32 | #include <linux/videodev.h> | 32 | #include <linux/videodev.h> |
33 | #include <media/v4l2-common.h> | 33 | #include <media/v4l2-common.h> |
34 | #include <media/v4l2-i2c-drv-legacy.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"); |
@@ -126,31 +127,18 @@ static int tlv320aic23b_command(struct i2c_client *client, unsigned int cmd, | |||
126 | * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' | 127 | * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' |
127 | */ | 128 | */ |
128 | 129 | ||
129 | static struct i2c_driver i2c_driver; | 130 | static int tlv320aic23b_probe(struct i2c_client *client) |
130 | |||
131 | static int tlv320aic23b_attach(struct i2c_adapter *adapter, int address, int kind) | ||
132 | { | 131 | { |
133 | struct i2c_client *client; | ||
134 | struct tlv320aic23b_state *state; | 132 | struct tlv320aic23b_state *state; |
135 | 133 | ||
136 | /* Check if the adapter supports the needed features */ | 134 | /* Check if the adapter supports the needed features */ |
137 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 135 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
138 | return 0; | 136 | return 0; |
139 | 137 | ||
140 | client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); | 138 | v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name); |
141 | if (client == 0) | ||
142 | return -ENOMEM; | ||
143 | |||
144 | client->addr = address; | ||
145 | client->adapter = adapter; | ||
146 | client->driver = &i2c_driver; | ||
147 | snprintf(client->name, sizeof(client->name) - 1, "tlv320aic23b"); | ||
148 | |||
149 | v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); | ||
150 | 139 | ||
151 | state = kmalloc(sizeof(struct tlv320aic23b_state), GFP_KERNEL); | 140 | state = kmalloc(sizeof(struct tlv320aic23b_state), GFP_KERNEL); |
152 | if (state == NULL) { | 141 | if (state == NULL) { |
153 | kfree(client); | ||
154 | return -ENOMEM; | 142 | return -ENOMEM; |
155 | } | 143 | } |
156 | state->muted = 0; | 144 | state->muted = 0; |
@@ -163,55 +151,22 @@ static int tlv320aic23b_attach(struct i2c_adapter *adapter, int address, int kin | |||
163 | tlv320aic23b_write(client, 0, 0x119); /* set gain on both channels to +3.0 dB */ | 151 | tlv320aic23b_write(client, 0, 0x119); /* set gain on both channels to +3.0 dB */ |
164 | tlv320aic23b_write(client, 8, 0x000); /* set sample rate to 48 kHz */ | 152 | tlv320aic23b_write(client, 8, 0x000); /* set sample rate to 48 kHz */ |
165 | tlv320aic23b_write(client, 9, 0x001); /* activate digital interface */ | 153 | tlv320aic23b_write(client, 9, 0x001); /* activate digital interface */ |
166 | |||
167 | i2c_attach_client(client); | ||
168 | |||
169 | return 0; | 154 | return 0; |
170 | } | 155 | } |
171 | 156 | ||
172 | static int tlv320aic23b_probe(struct i2c_adapter *adapter) | 157 | static int tlv320aic23b_remove(struct i2c_client *client) |
173 | { | 158 | { |
174 | if (adapter->class & I2C_CLASS_TV_ANALOG) | 159 | kfree(i2c_get_clientdata(client)); |
175 | return i2c_probe(adapter, &addr_data, tlv320aic23b_attach); | ||
176 | return 0; | ||
177 | } | ||
178 | |||
179 | static int tlv320aic23b_detach(struct i2c_client *client) | ||
180 | { | ||
181 | int err; | ||
182 | |||
183 | err = i2c_detach_client(client); | ||
184 | if (err) { | ||
185 | return err; | ||
186 | } | ||
187 | kfree(client); | ||
188 | |||
189 | return 0; | 160 | return 0; |
190 | } | 161 | } |
191 | 162 | ||
192 | /* ----------------------------------------------------------------------- */ | 163 | /* ----------------------------------------------------------------------- */ |
193 | 164 | ||
194 | /* i2c implementation */ | ||
195 | static struct i2c_driver i2c_driver = { | ||
196 | .driver = { | ||
197 | .name = "tlv320aic23b", | ||
198 | }, | ||
199 | .id = I2C_DRIVERID_TLV320AIC23B, | ||
200 | .attach_adapter = tlv320aic23b_probe, | ||
201 | .detach_client = tlv320aic23b_detach, | ||
202 | .command = tlv320aic23b_command, | ||
203 | }; | ||
204 | |||
205 | 165 | ||
206 | static int __init tlv320aic23b_init_module(void) | 166 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
207 | { | 167 | .name = "tlv320aic23b", |
208 | return i2c_add_driver(&i2c_driver); | 168 | .driverid = I2C_DRIVERID_TLV320AIC23B, |
209 | } | 169 | .command = tlv320aic23b_command, |
210 | 170 | .probe = tlv320aic23b_probe, | |
211 | static void __exit tlv320aic23b_cleanup_module(void) | 171 | .remove = tlv320aic23b_remove, |
212 | { | 172 | }; |
213 | i2c_del_driver(&i2c_driver); | ||
214 | } | ||
215 | |||
216 | module_init(tlv320aic23b_init_module); | ||
217 | module_exit(tlv320aic23b_cleanup_module); | ||