aboutsummaryrefslogtreecommitdiffstats
path: root/sound/i2c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2006-06-30 09:31:25 -0400
committerJaroslav Kysela <perex@suse.cz>2006-07-12 14:07:42 -0400
commitcc63935f56d1b2486fa17bea63ee3cfc7b9c1304 (patch)
treeb77b643820682e781d2c0641a36aa1299bd2d2fe /sound/i2c
parent7fd37481b1e26edc36a011a3760f10c34fffda37 (diff)
[ALSA] trivial: Code clean up of i2c/cs8427.c
- Fix spaces, wrap lines in 80 columns. - Move EXPORT_SYMBOL() adjacent to each function. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/i2c')
-rw-r--r--sound/i2c/cs8427.c115
1 files changed, 73 insertions, 42 deletions
diff --git a/sound/i2c/cs8427.c b/sound/i2c/cs8427.c
index 700c35b741e3..64388cb8d6e5 100644
--- a/sound/i2c/cs8427.c
+++ b/sound/i2c/cs8427.c
@@ -76,23 +76,28 @@ int snd_cs8427_reg_write(struct snd_i2c_device *device, unsigned char reg,
76 buf[0] = reg & 0x7f; 76 buf[0] = reg & 0x7f;
77 buf[1] = val; 77 buf[1] = val;
78 if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) { 78 if ((err = snd_i2c_sendbytes(device, buf, 2)) != 2) {
79 snd_printk(KERN_ERR "unable to send bytes 0x%02x:0x%02x to CS8427 (%i)\n", buf[0], buf[1], err); 79 snd_printk(KERN_ERR "unable to send bytes 0x%02x:0x%02x "
80 "to CS8427 (%i)\n", buf[0], buf[1], err);
80 return err < 0 ? err : -EIO; 81 return err < 0 ? err : -EIO;
81 } 82 }
82 return 0; 83 return 0;
83} 84}
84 85
86EXPORT_SYMBOL(snd_cs8427_reg_write);
87
85static int snd_cs8427_reg_read(struct snd_i2c_device *device, unsigned char reg) 88static int snd_cs8427_reg_read(struct snd_i2c_device *device, unsigned char reg)
86{ 89{
87 int err; 90 int err;
88 unsigned char buf; 91 unsigned char buf;
89 92
90 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) { 93 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
91 snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg); 94 snd_printk(KERN_ERR "unable to send register 0x%x byte "
95 "to CS8427\n", reg);
92 return err < 0 ? err : -EIO; 96 return err < 0 ? err : -EIO;
93 } 97 }
94 if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) { 98 if ((err = snd_i2c_readbytes(device, &buf, 1)) != 1) {
95 snd_printk(KERN_ERR "unable to read register 0x%x byte from CS8427\n", reg); 99 snd_printk(KERN_ERR "unable to read register 0x%x byte "
100 "from CS8427\n", reg);
96 return err < 0 ? err : -EIO; 101 return err < 0 ? err : -EIO;
97 } 102 }
98 return buf; 103 return buf;
@@ -121,7 +126,8 @@ static int snd_cs8427_send_corudata(struct snd_i2c_device *device,
121 int count) 126 int count)
122{ 127{
123 struct cs8427 *chip = device->private_data; 128 struct cs8427 *chip = device->private_data;
124 char *hw_data = udata ? chip->playback.hw_udata : chip->playback.hw_status; 129 char *hw_data = udata ?
130 chip->playback.hw_udata : chip->playback.hw_status;
125 char data[32]; 131 char data[32];
126 int err, idx; 132 int err, idx;
127 133
@@ -134,11 +140,11 @@ static int snd_cs8427_send_corudata(struct snd_i2c_device *device,
134 memset(data, 0, sizeof(data)); 140 memset(data, 0, sizeof(data));
135 if (memcmp(hw_data, data, count) == 0) { 141 if (memcmp(hw_data, data, count) == 0) {
136 chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK; 142 chip->regmap[CS8427_REG_UDATABUF] &= ~CS8427_UBMMASK;
137 chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS | CS8427_EFTUI; 143 chip->regmap[CS8427_REG_UDATABUF] |= CS8427_UBMZEROS |
138 if ((err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF, 144 CS8427_EFTUI;
139 chip->regmap[CS8427_REG_UDATABUF])) < 0) 145 err = snd_cs8427_reg_write(device, CS8427_REG_UDATABUF,
140 return err; 146 chip->regmap[CS8427_REG_UDATABUF]);
141 return 0; 147 return err < 0 ? err : 0;
142 } 148 }
143 } 149 }
144 data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF; 150 data[0] = CS8427_REG_AUTOINC | CS8427_REG_CORU_DATABUF;
@@ -161,24 +167,32 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
161{ 167{
162 static unsigned char initvals1[] = { 168 static unsigned char initvals1[] = {
163 CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC, 169 CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC,
164 /* CS8427_REG_CONTROL1: RMCK to OMCK, valid PCM audio, disable mutes, TCBL=output */ 170 /* CS8427_REG_CONTROL1: RMCK to OMCK, valid PCM audio, disable mutes,
171 TCBL=output */
165 CS8427_SWCLK | CS8427_TCBLDIR, 172 CS8427_SWCLK | CS8427_TCBLDIR,
166 /* CS8427_REG_CONTROL2: hold last valid audio sample, RMCK=256*Fs, normal stereo operation */ 173 /* CS8427_REG_CONTROL2: hold last valid audio sample, RMCK=256*Fs,
174 normal stereo operation */
167 0x00, 175 0x00,
168 /* CS8427_REG_DATAFLOW: output drivers normal operation, Tx<=serial, Rx=>serial */ 176 /* CS8427_REG_DATAFLOW: output drivers normal operation, Tx<=serial,
177 Rx=>serial */
169 CS8427_TXDSERIAL | CS8427_SPDAES3RECEIVER, 178 CS8427_TXDSERIAL | CS8427_SPDAES3RECEIVER,
170 /* CS8427_REG_CLOCKSOURCE: Run off, CMCK=256*Fs, output time base = OMCK, input time base = 179 /* CS8427_REG_CLOCKSOURCE: Run off, CMCK=256*Fs,
171 recovered input clock, recovered input clock source is ILRCK changed to AES3INPUT (workaround, see snd_cs8427_reset) */ 180 output time base = OMCK, input time base = recovered input clock,
181 recovered input clock source is ILRCK changed to AES3INPUT
182 (workaround, see snd_cs8427_reset) */
172 CS8427_RXDILRCK, 183 CS8427_RXDILRCK,
173 /* CS8427_REG_SERIALINPUT: Serial audio input port data format = I2S, 24-bit, 64*Fsi */ 184 /* CS8427_REG_SERIALINPUT: Serial audio input port data format = I2S,
185 24-bit, 64*Fsi */
174 CS8427_SIDEL | CS8427_SILRPOL, 186 CS8427_SIDEL | CS8427_SILRPOL,
175 /* CS8427_REG_SERIALOUTPUT: Serial audio output port data format = I2S, 24-bit, 64*Fsi */ 187 /* CS8427_REG_SERIALOUTPUT: Serial audio output port data format
188 = I2S, 24-bit, 64*Fsi */
176 CS8427_SODEL | CS8427_SOLRPOL, 189 CS8427_SODEL | CS8427_SOLRPOL,
177 }; 190 };
178 static unsigned char initvals2[] = { 191 static unsigned char initvals2[] = {
179 CS8427_REG_RECVERRMASK | CS8427_REG_AUTOINC, 192 CS8427_REG_RECVERRMASK | CS8427_REG_AUTOINC,
180 /* CS8427_REG_RECVERRMASK: unmask the input PLL clock, V, confidence, biphase, parity status bits */ 193 /* CS8427_REG_RECVERRMASK: unmask the input PLL clock, V, confidence,
181 /* CS8427_UNLOCK | CS8427_V | CS8427_CONF | CS8427_BIP | CS8427_PAR, */ 194 biphase, parity status bits */
195 /* CS8427_UNLOCK | CS8427_V | CS8427_CONF | CS8427_BIP | CS8427_PAR,*/
182 0xff, /* set everything */ 196 0xff, /* set everything */
183 /* CS8427_REG_CSDATABUF: 197 /* CS8427_REG_CSDATABUF:
184 Registers 32-55 window to CS buffer 198 Registers 32-55 window to CS buffer
@@ -201,7 +215,8 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
201 struct snd_i2c_device *device; 215 struct snd_i2c_device *device;
202 unsigned char buf[24]; 216 unsigned char buf[24];
203 217
204 if ((err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7), 218 if ((err = snd_i2c_device_create(bus, "CS8427",
219 CS8427_ADDR | (addr & 7),
205 &device)) < 0) 220 &device)) < 0)
206 return err; 221 return err;
207 chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL); 222 chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -212,8 +227,8 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
212 device->private_free = snd_cs8427_free; 227 device->private_free = snd_cs8427_free;
213 228
214 snd_i2c_lock(bus); 229 snd_i2c_lock(bus);
215 if ((err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER)) != 230 err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER);
216 CS8427_VER8427A) { 231 if (err != CS8427_VER8427A) {
217 snd_i2c_unlock(bus); 232 snd_i2c_unlock(bus);
218 snd_printk(KERN_ERR "unable to find CS8427 signature " 233 snd_printk(KERN_ERR "unable to find CS8427 signature "
219 "(expected 0x%x, read 0x%x),\n", 234 "(expected 0x%x, read 0x%x),\n",
@@ -222,7 +237,8 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
222 return -EFAULT; 237 return -EFAULT;
223 } 238 }
224 /* turn off run bit while making changes to configuration */ 239 /* turn off run bit while making changes to configuration */
225 if ((err = snd_cs8427_reg_write(device, CS8427_REG_CLOCKSOURCE, 0x00)) < 0) 240 err = snd_cs8427_reg_write(device, CS8427_REG_CLOCKSOURCE, 0x00);
241 if (err < 0)
226 goto __fail; 242 goto __fail;
227 /* send initial values */ 243 /* send initial values */
228 memcpy(chip->regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6); 244 memcpy(chip->regmap + (initvals1[0] & 0x7f), initvals1 + 1, 6);
@@ -282,6 +298,8 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
282 return err < 0 ? err : -EIO; 298 return err < 0 ? err : -EIO;
283} 299}
284 300
301EXPORT_SYMBOL(snd_cs8427_create);
302
285/* 303/*
286 * Reset the chip using run bit, also lock PLL using ILRCK and 304 * Reset the chip using run bit, also lock PLL using ILRCK and
287 * put back AES3INPUT. This workaround is described in latest 305 * put back AES3INPUT. This workaround is described in latest
@@ -296,7 +314,8 @@ static void snd_cs8427_reset(struct snd_i2c_device *cs8427)
296 snd_assert(cs8427, return); 314 snd_assert(cs8427, return);
297 chip = cs8427->private_data; 315 chip = cs8427->private_data;
298 snd_i2c_lock(cs8427->bus); 316 snd_i2c_lock(cs8427->bus);
299 if ((chip->regmap[CS8427_REG_CLOCKSOURCE] & CS8427_RXDAES3INPUT) == CS8427_RXDAES3INPUT) /* AES3 bit is set */ 317 if ((chip->regmap[CS8427_REG_CLOCKSOURCE] & CS8427_RXDAES3INPUT) ==
318 CS8427_RXDAES3INPUT) /* AES3 bit is set */
300 aes3input = 1; 319 aes3input = 1;
301 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK); 320 chip->regmap[CS8427_REG_CLOCKSOURCE] &= ~(CS8427_RUN | CS8427_RXDMASK);
302 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE, 321 snd_cs8427_reg_write(cs8427, CS8427_REG_CLOCKSOURCE,
@@ -367,12 +386,15 @@ static int snd_cs8427_qsubcode_get(struct snd_kcontrol *kcontrol,
367 386
368 snd_i2c_lock(device->bus); 387 snd_i2c_lock(device->bus);
369 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) { 388 if ((err = snd_i2c_sendbytes(device, &reg, 1)) != 1) {
370 snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg); 389 snd_printk(KERN_ERR "unable to send register 0x%x byte "
390 "to CS8427\n", reg);
371 snd_i2c_unlock(device->bus); 391 snd_i2c_unlock(device->bus);
372 return err < 0 ? err : -EIO; 392 return err < 0 ? err : -EIO;
373 } 393 }
374 if ((err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10)) != 10) { 394 err = snd_i2c_readbytes(device, ucontrol->value.bytes.data, 10);
375 snd_printk(KERN_ERR "unable to read Q-subcode bytes from CS8427\n"); 395 if (err != 10) {
396 snd_printk(KERN_ERR "unable to read Q-subcode bytes "
397 "from CS8427\n");
376 snd_i2c_unlock(device->bus); 398 snd_i2c_unlock(device->bus);
377 return err < 0 ? err : -EIO; 399 return err < 0 ? err : -EIO;
378 } 400 }
@@ -380,7 +402,8 @@ static int snd_cs8427_qsubcode_get(struct snd_kcontrol *kcontrol,
380 return 0; 402 return 0;
381} 403}
382 404
383static int snd_cs8427_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 405static int snd_cs8427_spdif_info(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_info *uinfo)
384{ 407{
385 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 408 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
386 uinfo->count = 1; 409 uinfo->count = 1;
@@ -413,7 +436,8 @@ static int snd_cs8427_spdif_put(struct snd_kcontrol *kcontrol,
413 snd_i2c_lock(device->bus); 436 snd_i2c_lock(device->bus);
414 change = memcmp(ucontrol->value.iec958.status, status, 24) != 0; 437 change = memcmp(ucontrol->value.iec958.status, status, 24) != 0;
415 memcpy(status, ucontrol->value.iec958.status, 24); 438 memcpy(status, ucontrol->value.iec958.status, 24);
416 if (change && (kcontrol->private_value ? runtime != NULL : runtime == NULL)) { 439 if (change && (kcontrol->private_value ?
440 runtime != NULL : runtime == NULL)) {
417 err = snd_cs8427_send_corudata(device, 0, status, 24); 441 err = snd_cs8427_send_corudata(device, 0, status, 24);
418 if (err < 0) 442 if (err < 0)
419 change = err; 443 change = err;
@@ -442,7 +466,8 @@ static struct snd_kcontrol_new snd_cs8427_iec958_controls[] = {
442 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 466 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
443 .info = snd_cs8427_in_status_info, 467 .info = snd_cs8427_in_status_info,
444 .name = "IEC958 CS8427 Input Status", 468 .name = "IEC958 CS8427 Input Status",
445 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 469 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
470 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
446 .get = snd_cs8427_in_status_get, 471 .get = snd_cs8427_in_status_get,
447 .private_value = 15, 472 .private_value = 15,
448}, 473},
@@ -450,7 +475,8 @@ static struct snd_kcontrol_new snd_cs8427_iec958_controls[] = {
450 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 475 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
451 .info = snd_cs8427_in_status_info, 476 .info = snd_cs8427_in_status_info,
452 .name = "IEC958 CS8427 Error Status", 477 .name = "IEC958 CS8427 Error Status",
453 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 478 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
479 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
454 .get = snd_cs8427_in_status_get, 480 .get = snd_cs8427_in_status_get,
455 .private_value = 16, 481 .private_value = 16,
456}, 482},
@@ -470,7 +496,8 @@ static struct snd_kcontrol_new snd_cs8427_iec958_controls[] = {
470 .private_value = 0 496 .private_value = 0
471}, 497},
472{ 498{
473 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, 499 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
500 SNDRV_CTL_ELEM_ACCESS_INACTIVE),
474 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 501 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
475 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), 502 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
476 .info = snd_cs8427_spdif_info, 503 .info = snd_cs8427_spdif_info,
@@ -482,7 +509,8 @@ static struct snd_kcontrol_new snd_cs8427_iec958_controls[] = {
482 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 509 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
483 .info = snd_cs8427_qsubcode_info, 510 .info = snd_cs8427_qsubcode_info,
484 .name = "IEC958 Q-subcode Capture Default", 511 .name = "IEC958 Q-subcode Capture Default",
485 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 512 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
513 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
486 .get = snd_cs8427_qsubcode_get 514 .get = snd_cs8427_qsubcode_get
487}}; 515}};
488 516
@@ -505,7 +533,8 @@ int snd_cs8427_iec958_build(struct snd_i2c_device *cs8427,
505 err = snd_ctl_add(cs8427->bus->card, kctl); 533 err = snd_ctl_add(cs8427->bus->card, kctl);
506 if (err < 0) 534 if (err < 0)
507 return err; 535 return err;
508 if (!strcmp(kctl->id.name, SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM))) 536 if (! strcmp(kctl->id.name,
537 SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM)))
509 chip->playback.pcm_ctl = kctl; 538 chip->playback.pcm_ctl = kctl;
510 } 539 }
511 540
@@ -515,6 +544,8 @@ int snd_cs8427_iec958_build(struct snd_i2c_device *cs8427,
515 return 0; 544 return 0;
516} 545}
517 546
547EXPORT_SYMBOL(snd_cs8427_iec958_build);
548
518int snd_cs8427_iec958_active(struct snd_i2c_device *cs8427, int active) 549int snd_cs8427_iec958_active(struct snd_i2c_device *cs8427, int active)
519{ 550{
520 struct cs8427 *chip; 551 struct cs8427 *chip;
@@ -522,13 +553,17 @@ int snd_cs8427_iec958_active(struct snd_i2c_device *cs8427, int active)
522 snd_assert(cs8427, return -ENXIO); 553 snd_assert(cs8427, return -ENXIO);
523 chip = cs8427->private_data; 554 chip = cs8427->private_data;
524 if (active) 555 if (active)
525 memcpy(chip->playback.pcm_status, chip->playback.def_status, 24); 556 memcpy(chip->playback.pcm_status,
557 chip->playback.def_status, 24);
526 chip->playback.pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 558 chip->playback.pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
527 snd_ctl_notify(cs8427->bus->card, SNDRV_CTL_EVENT_MASK_VALUE | 559 snd_ctl_notify(cs8427->bus->card,
528 SNDRV_CTL_EVENT_MASK_INFO, &chip->playback.pcm_ctl->id); 560 SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
561 &chip->playback.pcm_ctl->id);
529 return 0; 562 return 0;
530} 563}
531 564
565EXPORT_SYMBOL(snd_cs8427_iec958_active);
566
532int snd_cs8427_iec958_pcm(struct snd_i2c_device *cs8427, unsigned int rate) 567int snd_cs8427_iec958_pcm(struct snd_i2c_device *cs8427, unsigned int rate)
533{ 568{
534 struct cs8427 *chip; 569 struct cs8427 *chip;
@@ -568,6 +603,8 @@ int snd_cs8427_iec958_pcm(struct snd_i2c_device *cs8427, unsigned int rate)
568 return err < 0 ? err : 0; 603 return err < 0 ? err : 0;
569} 604}
570 605
606EXPORT_SYMBOL(snd_cs8427_iec958_pcm);
607
571static int __init alsa_cs8427_module_init(void) 608static int __init alsa_cs8427_module_init(void)
572{ 609{
573 return 0; 610 return 0;
@@ -579,9 +616,3 @@ static void __exit alsa_cs8427_module_exit(void)
579 616
580module_init(alsa_cs8427_module_init) 617module_init(alsa_cs8427_module_init)
581module_exit(alsa_cs8427_module_exit) 618module_exit(alsa_cs8427_module_exit)
582
583EXPORT_SYMBOL(snd_cs8427_create);
584EXPORT_SYMBOL(snd_cs8427_reg_write);
585EXPORT_SYMBOL(snd_cs8427_iec958_build);
586EXPORT_SYMBOL(snd_cs8427_iec958_active);
587EXPORT_SYMBOL(snd_cs8427_iec958_pcm);