aboutsummaryrefslogtreecommitdiffstats
path: root/sound/i2c/cs8427.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/i2c/cs8427.c')
-rw-r--r--sound/i2c/cs8427.c142
1 files changed, 78 insertions, 64 deletions
diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c
index 1a05cfbdc7c6..9deba80a587c 100644
--- a/sound/i2c/cs8427.c
+++ b/sound/i2c/cs8427.c
@@ -30,7 +30,7 @@
30#include <sound/cs8427.h> 30#include <sound/cs8427.h>
31#include <sound/asoundef.h> 31#include <sound/asoundef.h>
32 32
33static void snd_cs8427_reset(snd_i2c_device_t *cs8427); 33static void snd_cs8427_reset(struct snd_i2c_device *cs8427);
34 34
35MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); 35MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36MODULE_DESCRIPTION("IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic"); 36MODULE_DESCRIPTION("IEC958 (S/PDIF) receiver & transmitter by Cirrus Logic");
@@ -38,22 +38,22 @@ MODULE_LICENSE("GPL");
38 38
39#define CS8427_ADDR (0x20>>1) /* fixed address */ 39#define CS8427_ADDR (0x20>>1) /* fixed address */
40 40
41typedef struct { 41struct cs8427_stream {
42 snd_pcm_substream_t *substream; 42 struct snd_pcm_substream *substream;
43 char hw_status[24]; /* hardware status */ 43 char hw_status[24]; /* hardware status */
44 char def_status[24]; /* default status */ 44 char def_status[24]; /* default status */
45 char pcm_status[24]; /* PCM private status */ 45 char pcm_status[24]; /* PCM private status */
46 char hw_udata[32]; 46 char hw_udata[32];
47 snd_kcontrol_t *pcm_ctl; 47 struct snd_kcontrol *pcm_ctl;
48} cs8427_stream_t; 48};
49 49
50typedef struct { 50struct cs8427 {
51 unsigned char regmap[0x14]; /* map of first 1 + 13 registers */ 51 unsigned char regmap[0x14]; /* map of first 1 + 13 registers */
52 unsigned int rate; 52 unsigned int rate;
53 unsigned int reset_timeout; 53 unsigned int reset_timeout;
54 cs8427_stream_t playback; 54 struct cs8427_stream playback;
55 cs8427_stream_t capture; 55 struct cs8427_stream capture;
56} cs8427_t; 56};
57 57
58static unsigned char swapbits(unsigned char val) 58static unsigned char swapbits(unsigned char val)
59{ 59{
@@ -67,7 +67,8 @@ static unsigned char swapbits(unsigned char val)
67 return res; 67 return res;
68} 68}
69 69
70int snd_cs8427_reg_write(snd_i2c_device_t *device, unsigned char reg, unsigned char val) 70int snd_cs8427_reg_write(struct snd_i2c_device *device, unsigned char reg,
71 unsigned char val)
71{ 72{
72 int err; 73 int err;
73 unsigned char buf[2]; 74 unsigned char buf[2];
@@ -81,7 +82,7 @@ int snd_cs8427_reg_write(snd_i2c_device_t *device, unsigned char reg, unsigned c
81 return 0; 82 return 0;
82} 83}
83 84
84static int snd_cs8427_reg_read(snd_i2c_device_t *device, unsigned char reg) 85static int snd_cs8427_reg_read(struct snd_i2c_device *device, unsigned char reg)
85{ 86{
86 int err; 87 int err;
87 unsigned char buf; 88 unsigned char buf;
@@ -97,28 +98,29 @@ static int snd_cs8427_reg_read(snd_i2c_device_t *device, unsigned char reg)
97 return buf; 98 return buf;
98} 99}
99 100
100static int snd_cs8427_select_corudata(snd_i2c_device_t *device, int udata) 101static int snd_cs8427_select_corudata(struct snd_i2c_device *device, int udata)
101{ 102{
102 cs8427_t *chip = device->private_data; 103 struct cs8427 *chip = device->private_data;
103 int err; 104 int err;
104 105
105 udata = udata ? CS8427_BSEL : 0; 106 udata = udata ? CS8427_BSEL : 0;
106 if (udata != (chip->regmap[CS8427_REG_CSDATABUF] & udata)) { 107 if (udata != (chip->regmap[CS8427_REG_CSDATABUF] & udata)) {
107 chip->regmap[CS8427_REG_CSDATABUF] &= ~CS8427_BSEL; 108 chip->regmap[CS8427_REG_CSDATABUF] &= ~CS8427_BSEL;
108 chip->regmap[CS8427_REG_CSDATABUF] |= udata; 109 chip->regmap[CS8427_REG_CSDATABUF] |= udata;
109 err = snd_cs8427_reg_write(device, CS8427_REG_CSDATABUF, chip->regmap[CS8427_REG_CSDATABUF]); 110 err = snd_cs8427_reg_write(device, CS8427_REG_CSDATABUF,
111 chip->regmap[CS8427_REG_CSDATABUF]);
110 if (err < 0) 112 if (err < 0)
111 return err; 113 return err;
112 } 114 }
113 return 0; 115 return 0;
114} 116}
115 117
116static int snd_cs8427_send_corudata(snd_i2c_device_t *device, 118static int snd_cs8427_send_corudata(struct snd_i2c_device *device,
117 int udata, 119 int udata,
118 unsigned char *ndata, 120 unsigned char *ndata,
119 int count) 121 int count)
120{ 122{
121 cs8427_t *chip = device->private_data; 123 struct cs8427 *chip = device->private_data;
122 char *hw_data = udata ? chip->playback.hw_udata : chip->playback.hw_status; 124 char *hw_data = udata ? chip->playback.hw_udata : chip->playback.hw_status;
123 char data[32]; 125 char data[32];
124 int err, idx; 126 int err, idx;
@@ -133,7 +135,8 @@ static int snd_cs8427_send_corudata(snd_i2c_device_t *device,
133 if (memcmp(hw_data, data, count) == 0) { 135 if (memcmp(hw_data, data, count) == 0) {
134 chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK; 136 chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK;
135 chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | CS8427_EFTUI; 137 chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | CS8427_EFTUI;
136 if ((err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF, chip->regmap[CS8427_REG_UDATABUF])) < 0) 138 if ((err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF,
139 chip->regmap[CS8427_REG_UDATABUF])) < 0)
137 return err; 140 return err;
138 return 0; 141 return 0;
139 } 142 }
@@ -146,15 +149,15 @@ static int snd_cs8427_send_corudata(snd_i2c_device_t *device,
146 return 1; 149 return 1;
147} 150}
148 151
149static void snd_cs8427_free(snd_i2c_device_t *device) 152static void snd_cs8427_free(struct snd_i2c_device *device)
150{ 153{
151 kfree(device->private_data); 154 kfree(device->private_data);
152} 155}
153 156
154int snd_cs8427_create(snd_i2c_bus_t *bus, 157int snd_cs8427_create(struct snd_i2c_bus *bus,
155 unsigned char addr, 158 unsigned char addr,
156 unsigned int reset_timeout, 159 unsigned int reset_timeout,
157 snd_i2c_device_t **r_cs8427) 160 struct snd_i2c_device **r_cs8427)
158{ 161{
159 static unsigned char initvals1[] = { 162 static unsigned char initvals1[] = {
160 CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC, 163 CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC,
@@ -194,11 +197,12 @@ int snd_cs8427_create(snd_i2c_bus_t *bus,
194 CS8427_UD | CS8427_EFTUI | CS8427_DETUI, 197 CS8427_UD | CS8427_EFTUI | CS8427_DETUI,
195 }; 198 };
196 int err; 199 int err;
197 cs8427_t *chip; 200 struct cs8427 *chip;
198 snd_i2c_device_t *device; 201 struct snd_i2c_device *device;
199 unsigned char buf[24]; 202 unsigned char buf[24];
200 203
201 if ((err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7), &device)) < 0) 204 if ((err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7),
205 &device)) < 0)
202 return err; 206 return err;
203 chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL); 207 chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL);
204 if (chip == NULL) { 208 if (chip == NULL) {
@@ -208,9 +212,13 @@ int snd_cs8427_create(snd_i2c_bus_t *bus,
208 device->private_free = snd_cs8427_free; 212 device->private_free = snd_cs8427_free;
209 213
210 snd_i2c_lock(bus); 214 snd_i2c_lock(bus);
211 if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != CS8427_VER8427A) { 215 if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) !=
216 CS8427_VER8427A) {
212 snd_i2c_unlock(bus); 217 snd_i2c_unlock(bus);
213 snd_printk(KERN_ERR "unable to find CS8427 signature (expected 0x%x, read 0x%x), initialization is not completed\n", CS8427_VER8427A, err); 218 snd_printk(KERN_ERR "unable to find CS8427 signature "
219 "(expected 0x%x, read 0x%x),\n",
220 CS8427_VER8427A, err);
221 snd_printk(KERN_ERR " initialization is not completed\n");
214 return -EFAULT; 222 return -EFAULT;
215 } 223 }
216 /* turn off run bit while making changes to configuration */ 224 /* turn off run bit while making changes to configuration */
@@ -279,9 +287,9 @@ int snd_cs8427_create(snd_i2c_bus_t *bus,
279 * put back AES3INPUT. This workaround is described in latest 287 * put back AES3INPUT. This workaround is described in latest
280 * CS8427 datasheet, otherwise TXDSERIAL will not work. 288 * CS8427 datasheet, otherwise TXDSERIAL will not work.
281 */ 289 */
282static void snd_cs8427_reset(snd_i2c_device_t *cs8427) 290static void snd_cs8427_reset(struct snd_i2c_device *cs8427)
283{ 291{
284 cs8427_t *chip; 292 struct cs8427 *chip;
285 unsigned long end_time; 293 unsigned long end_time;
286 int data; 294 int data;
287 295
@@ -289,10 +297,12 @@ static void snd_cs8427_reset(snd_i2c_device_t *cs8427)
289 chip = cs8427->private_data; 297 chip = cs8427->private_data;
290 snd_i2c_lock(cs8427->bus); 298 snd_i2c_lock(cs8427->bus);
291 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK); 299 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK);
292 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); 300 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE,
301 chip->regmap[CS8427_REG_CLOCKSOURCE]);
293 udelay(200); 302 udelay(200);
294 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RUN | CS8427_RXDILRCK; 303 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RUN | CS8427_RXDILRCK;
295 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); 304 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE,
305 chip->regmap[CS8427_REG_CLOCKSOURCE]);
296 udelay(200); 306 udelay(200);
297 snd_i2c_unlock(cs8427->bus); 307 snd_i2c_unlock(cs8427->bus);
298 end_time = jiffies + chip->reset_timeout; 308 end_time = jiffies + chip->reset_timeout;
@@ -307,12 +317,13 @@ static void snd_cs8427_reset(snd_i2c_device_t *cs8427)
307 snd_i2c_lock(cs8427->bus); 317 snd_i2c_lock(cs8427->bus);
308 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK; 318 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~CS8427_RXDMASK;
309 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RXDAES3INPUT; 319 chip->regmap[CS8427_REG_CLOCKSOURCE] |= CS8427_RXDAES3INPUT;
310 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, chip->regmap[CS8427_REG_CLOCKSOURCE]); 320 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE,
321 chip->regmap[CS8427_REG_CLOCKSOURCE]);
311 snd_i2c_unlock(cs8427->bus); 322 snd_i2c_unlock(cs8427->bus);
312} 323}
313 324
314static int snd_cs8427_in_status_info(snd_kcontrol_t *kcontrol, 325static int snd_cs8427_in_status_info(struct snd_kcontrol *kcontrol,
315 snd_ctl_elem_info_t *uinfo) 326 struct snd_ctl_elem_info *uinfo)
316{ 327{
317 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 328 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
318 uinfo->count = 1; 329 uinfo->count = 1;
@@ -321,10 +332,10 @@ static int snd_cs8427_in_status_info(snd_kcontrol_t *kcontrol,
321 return 0; 332 return 0;
322} 333}
323 334
324static int snd_cs8427_in_status_get(snd_kcontrol_t *kcontrol, 335static int snd_cs8427_in_status_get(struct snd_kcontrol *kcontrol,
325 snd_ctl_elem_value_t *ucontrol) 336 struct snd_ctl_elem_value *ucontrol)
326{ 337{
327 snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); 338 struct snd_i2c_device *device = snd_kcontrol_chip(kcontrol);
328 int data; 339 int data;
329 340
330 snd_i2c_lock(device->bus); 341 snd_i2c_lock(device->bus);
@@ -336,18 +347,18 @@ static int snd_cs8427_in_status_get(snd_kcontrol_t *kcontrol,
336 return 0; 347 return 0;
337} 348}
338 349
339static int snd_cs8427_qsubcode_info(snd_kcontrol_t *kcontrol, 350static int snd_cs8427_qsubcode_info(struct snd_kcontrol *kcontrol,
340 snd_ctl_elem_info_t *uinfo) 351 struct snd_ctl_elem_info *uinfo)
341{ 352{
342 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; 353 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
343 uinfo->count = 10; 354 uinfo->count = 10;
344 return 0; 355 return 0;
345} 356}
346 357
347static int snd_cs8427_qsubcode_get(snd_kcontrol_t *kcontrol, 358static int snd_cs8427_qsubcode_get(struct snd_kcontrol *kcontrol,
348 snd_ctl_elem_value_t *ucontrol) 359 struct snd_ctl_elem_value *ucontrol)
349{ 360{
350 snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); 361 struct snd_i2c_device *device = snd_kcontrol_chip(kcontrol);
351 unsigned char reg = CS8427_REG_QSUBCODE; 362 unsigned char reg = CS8427_REG_QSUBCODE;
352 int err; 363 int err;
353 364
@@ -366,18 +377,18 @@ static int snd_cs8427_qsubcode_get(snd_kcontrol_t *kcontrol,
366 return 0; 377 return 0;
367} 378}
368 379
369static int snd_cs8427_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 380static int snd_cs8427_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
370{ 381{
371 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 382 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
372 uinfo->count = 1; 383 uinfo->count = 1;
373 return 0; 384 return 0;
374} 385}
375 386
376static int snd_cs8427_spdif_get(snd_kcontrol_t * kcontrol, 387static int snd_cs8427_spdif_get(struct snd_kcontrol *kcontrol,
377 snd_ctl_elem_value_t * ucontrol) 388 struct snd_ctl_elem_value *ucontrol)
378{ 389{
379 snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); 390 struct snd_i2c_device *device = snd_kcontrol_chip(kcontrol);
380 cs8427_t *chip = device->private_data; 391 struct cs8427 *chip = device->private_data;
381 392
382 snd_i2c_lock(device->bus); 393 snd_i2c_lock(device->bus);
383 memcpy(ucontrol->value.iec958.status, chip->playback.def_status, 24); 394 memcpy(ucontrol->value.iec958.status, chip->playback.def_status, 24);
@@ -385,13 +396,15 @@ static int snd_cs8427_spdif_get(snd_kcontrol_t * kcontrol,
385 return 0; 396 return 0;
386} 397}
387 398
388static int snd_cs8427_spdif_put(snd_kcontrol_t * kcontrol, 399static int snd_cs8427_spdif_put(struct snd_kcontrol *kcontrol,
389 snd_ctl_elem_value_t * ucontrol) 400 struct snd_ctl_elem_value *ucontrol)
390{ 401{
391 snd_i2c_device_t *device = snd_kcontrol_chip(kcontrol); 402 struct snd_i2c_device *device = snd_kcontrol_chip(kcontrol);
392 cs8427_t *chip = device->private_data; 403 struct cs8427 *chip = device->private_data;
393 unsigned char *status = kcontrol->private_value ? chip->playback.pcm_status : chip->playback.def_status; 404 unsigned char *status = kcontrol->private_value ?
394 snd_pcm_runtime_t *runtime = chip->playback.substream ? chip->playback.substream->runtime : NULL; 405 chip->playback.pcm_status : chip->playback.def_status;
406 struct snd_pcm_runtime *runtime = chip->playback.substream ?
407 chip->playback.substream->runtime : NULL;
395 int err, change; 408 int err, change;
396 409
397 snd_i2c_lock(device->bus); 410 snd_i2c_lock(device->bus);
@@ -406,21 +419,22 @@ static int snd_cs8427_spdif_put(snd_kcontrol_t * kcontrol,
406 return change; 419 return change;
407} 420}
408 421
409static int snd_cs8427_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 422static int snd_cs8427_spdif_mask_info(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_info *uinfo)
410{ 424{
411 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 425 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
412 uinfo->count = 1; 426 uinfo->count = 1;
413 return 0; 427 return 0;
414} 428}
415 429
416static int snd_cs8427_spdif_mask_get(snd_kcontrol_t * kcontrol, 430static int snd_cs8427_spdif_mask_get(struct snd_kcontrol *kcontrol,
417 snd_ctl_elem_value_t * ucontrol) 431 struct snd_ctl_elem_value *ucontrol)
418{ 432{
419 memset(ucontrol->value.iec958.status, 0xff, 24); 433 memset(ucontrol->value.iec958.status, 0xff, 24);
420 return 0; 434 return 0;
421} 435}
422 436
423static snd_kcontrol_new_t snd_cs8427_iec958_controls[] = { 437static struct snd_kcontrol_new snd_cs8427_iec958_controls[] = {
424{ 438{
425 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 439 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
426 .info = snd_cs8427_in_status_info, 440 .info = snd_cs8427_in_status_info,
@@ -469,12 +483,12 @@ static snd_kcontrol_new_t snd_cs8427_iec958_controls[] = {
469 .get = snd_cs8427_qsubcode_get 483 .get = snd_cs8427_qsubcode_get
470}}; 484}};
471 485
472int snd_cs8427_iec958_build(snd_i2c_device_t *cs8427, 486int snd_cs8427_iec958_build(struct snd_i2c_device *cs8427,
473 snd_pcm_substream_t *play_substream, 487 struct snd_pcm_substream *play_substream,
474 snd_pcm_substream_t *cap_substream) 488 struct snd_pcm_substream *cap_substream)
475{ 489{
476 cs8427_t *chip = cs8427->private_data; 490 struct cs8427 *chip = cs8427->private_data;
477 snd_kcontrol_t *kctl; 491 struct snd_kcontrol *kctl;
478 unsigned int idx; 492 unsigned int idx;
479 int err; 493 int err;
480 494
@@ -498,9 +512,9 @@ int snd_cs8427_iec958_build(snd_i2c_device_t *cs8427,
498 return 0; 512 return 0;
499} 513}
500 514
501int snd_cs8427_iec958_active(snd_i2c_device_t *cs8427, int active) 515int snd_cs8427_iec958_active(struct snd_i2c_device *cs8427, int active)
502{ 516{
503 cs8427_t *chip; 517 struct cs8427 *chip;
504 518
505 snd_assert(cs8427, return -ENXIO); 519 snd_assert(cs8427, return -ENXIO);
506 chip = cs8427->private_data; 520 chip = cs8427->private_data;
@@ -512,9 +526,9 @@ int snd_cs8427_iec958_active(snd_i2c_device_t *cs8427, int active)
512 return 0; 526 return 0;
513} 527}
514 528
515int snd_cs8427_iec958_pcm(snd_i2c_device_t *cs8427, unsigned int rate) 529int snd_cs8427_iec958_pcm(struct snd_i2c_device *cs8427, unsigned int rate)
516{ 530{
517 cs8427_t *chip; 531 struct cs8427 *chip;
518 char *status; 532 char *status;
519 int err, reset; 533 int err, reset;
520 534