snd_ps3.c (112ac808eb8a953dd356bbbc8322fdd6861e2c75) | snd_ps3.c (cb6492e4a4e68281358510f0ffe2b0c4972ec166) |
---|---|
1/* 2 * Audio support for PS3 3 * Copyright (C) 2007 Sony Computer Entertainment Inc. 4 * All rights reserved. 5 * Copyright 2006, 2007 Sony Corporation 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License --- 4 unchanged lines hidden (view full) --- 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 | 1/* 2 * Audio support for PS3 3 * Copyright (C) 2007 Sony Computer Entertainment Inc. 4 * All rights reserved. 5 * Copyright 2006, 2007 Sony Corporation 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License --- 4 unchanged lines hidden (view full) --- 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 |
21#include <linux/dma-mapping.h> 22#include <linux/dmapool.h> |
|
21#include <linux/init.h> | 23#include <linux/init.h> |
22#include <linux/slab.h> 23#include <linux/io.h> | |
24#include <linux/interrupt.h> | 24#include <linux/interrupt.h> |
25#include <linux/io.h> 26#include <linux/slab.h> 27 28#include <sound/asound.h> 29#include <sound/control.h> |
|
25#include <sound/core.h> 26#include <sound/initval.h> | 30#include <sound/core.h> 31#include <sound/initval.h> |
27#include <sound/pcm.h> 28#include <sound/asound.h> | |
29#include <sound/memalloc.h> | 32#include <sound/memalloc.h> |
33#include <sound/pcm.h> |
|
30#include <sound/pcm_params.h> | 34#include <sound/pcm_params.h> |
31#include <sound/control.h> 32#include <linux/dmapool.h> 33#include <linux/dma-mapping.h> 34#include <asm/firmware.h> | 35 |
35#include <asm/dma.h> | 36#include <asm/dma.h> |
37#include <asm/firmware.h> |
|
36#include <asm/lv1call.h> 37#include <asm/ps3.h> 38#include <asm/ps3av.h> 39 | 38#include <asm/lv1call.h> 39#include <asm/ps3.h> 40#include <asm/ps3av.h> 41 |
40#include "snd_ps3_reg.h" | |
41#include "snd_ps3.h" | 42#include "snd_ps3.h" |
43#include "snd_ps3_reg.h" |
|
42 | 44 |
43MODULE_LICENSE("GPL v2"); 44MODULE_DESCRIPTION("PS3 sound driver"); 45MODULE_AUTHOR("Sony Computer Entertainment Inc."); | |
46 | 45 |
47/* module entries */ 48static int __init snd_ps3_init(void); 49static void __exit snd_ps3_exit(void); 50 51/* ALSA snd driver ops */ 52static int snd_ps3_pcm_open(struct snd_pcm_substream *substream); 53static int snd_ps3_pcm_close(struct snd_pcm_substream *substream); 54static int snd_ps3_pcm_prepare(struct snd_pcm_substream *substream); 55static int snd_ps3_pcm_trigger(struct snd_pcm_substream *substream, 56 int cmd); 57static snd_pcm_uframes_t snd_ps3_pcm_pointer(struct snd_pcm_substream 58 *substream); 59static int snd_ps3_pcm_hw_params(struct snd_pcm_substream *substream, 60 struct snd_pcm_hw_params *hw_params); 61static int snd_ps3_pcm_hw_free(struct snd_pcm_substream *substream); 62 63 64/* ps3_system_bus_driver entries */ 65static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev); 66static int snd_ps3_driver_remove(struct ps3_system_bus_device *dev); 67 68/* address setup */ 69static int snd_ps3_map_mmio(void); 70static void snd_ps3_unmap_mmio(void); 71static int snd_ps3_allocate_irq(void); 72static void snd_ps3_free_irq(void); 73static void snd_ps3_audio_set_base_addr(uint64_t ioaddr_start); 74 75/* interrupt handler */ 76static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id); 77 78 79/* set sampling rate/format */ 80static int snd_ps3_set_avsetting(struct snd_pcm_substream *substream); 81/* take effect parameter change */ 82static int snd_ps3_change_avsetting(struct snd_ps3_card_info *card); 83/* initialize avsetting and take it effect */ 84static int snd_ps3_init_avsetting(struct snd_ps3_card_info *card); 85/* setup dma */ 86static int snd_ps3_program_dma(struct snd_ps3_card_info *card, 87 enum snd_ps3_dma_filltype filltype); 88static void snd_ps3_wait_for_dma_stop(struct snd_ps3_card_info *card); 89 90static dma_addr_t v_to_bus(struct snd_ps3_card_info *, void *vaddr, int ch); 91 92 93module_init(snd_ps3_init); 94module_exit(snd_ps3_exit); 95 | |
96/* 97 * global 98 */ 99static struct snd_ps3_card_info the_card; 100 101static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY; 102 103module_param_named(start_delay, snd_ps3_start_delay, uint, 0644); --- 56 unchanged lines hidden (view full) --- 160 .period_bytes_max = PS3_AUDIO_FIFO_STAGE_SIZE * 4, 161 162 .periods_min = 16, 163 .periods_max = 32, /* buffer_size_max/ period_bytes_max */ 164 165 .fifo_size = PS3_AUDIO_FIFO_SIZE 166}; 167 | 46/* 47 * global 48 */ 49static struct snd_ps3_card_info the_card; 50 51static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY; 52 53module_param_named(start_delay, snd_ps3_start_delay, uint, 0644); --- 56 unchanged lines hidden (view full) --- 110 .period_bytes_max = PS3_AUDIO_FIFO_STAGE_SIZE * 4, 111 112 .periods_min = 16, 113 .periods_max = 32, /* buffer_size_max/ period_bytes_max */ 114 115 .fifo_size = PS3_AUDIO_FIFO_SIZE 116}; 117 |
168static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = { 169 .open = snd_ps3_pcm_open, 170 .close = snd_ps3_pcm_close, 171 .prepare = snd_ps3_pcm_prepare, 172 .ioctl = snd_pcm_lib_ioctl, 173 .trigger = snd_ps3_pcm_trigger, 174 .pointer = snd_ps3_pcm_pointer, 175 .hw_params = snd_ps3_pcm_hw_params, 176 .hw_free = snd_ps3_pcm_hw_free 177}; 178 | |
179static int snd_ps3_verify_dma_stop(struct snd_ps3_card_info *card, 180 int count, int force_stop) 181{ 182 int dma_ch, done, retries, stop_forced = 0; 183 uint32_t status; 184 185 for (dma_ch = 0; dma_ch < 8; dma_ch++) { 186 retries = count; --- 177 unchanged lines hidden (view full) --- 364 /* ensure the hardware sees the change */ 365 wmb(); 366 spin_unlock_irqrestore(&card->dma_lock, irqsave); 367 368 return 0; 369} 370 371/* | 118static int snd_ps3_verify_dma_stop(struct snd_ps3_card_info *card, 119 int count, int force_stop) 120{ 121 int dma_ch, done, retries, stop_forced = 0; 122 uint32_t status; 123 124 for (dma_ch = 0; dma_ch < 8; dma_ch++) { 125 retries = count; --- 177 unchanged lines hidden (view full) --- 303 /* ensure the hardware sees the change */ 304 wmb(); 305 spin_unlock_irqrestore(&card->dma_lock, irqsave); 306 307 return 0; 308} 309 310/* |
311 * Interrupt handler 312 */ 313static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id) 314{ 315 316 uint32_t port_intr; 317 int underflow_occured = 0; 318 struct snd_ps3_card_info *card = dev_id; 319 320 if (!card->running) { 321 update_reg(PS3_AUDIO_AX_IS, 0); 322 update_reg(PS3_AUDIO_INTR_0, 0); 323 return IRQ_HANDLED; 324 } 325 326 port_intr = read_reg(PS3_AUDIO_AX_IS); 327 /* 328 *serial buffer empty detected (every 4 times), 329 *program next dma and kick it 330 */ 331 if (port_intr & PS3_AUDIO_AX_IE_ASOBEIE(0)) { 332 write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBEIE(0)); 333 if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) { 334 write_reg(PS3_AUDIO_AX_IS, port_intr); 335 underflow_occured = 1; 336 } 337 if (card->silent) { 338 /* we are still in silent time */ 339 snd_ps3_program_dma(card, 340 (underflow_occured) ? 341 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL : 342 SND_PS3_DMA_FILLTYPE_SILENT_RUNNING); 343 snd_ps3_kick_dma(card); 344 card->silent--; 345 } else { 346 snd_ps3_program_dma(card, 347 (underflow_occured) ? 348 SND_PS3_DMA_FILLTYPE_FIRSTFILL : 349 SND_PS3_DMA_FILLTYPE_RUNNING); 350 snd_ps3_kick_dma(card); 351 snd_pcm_period_elapsed(card->substream); 352 } 353 } else if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) { 354 write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBUIE(0)); 355 /* 356 * serial out underflow, but buffer empty not detected. 357 * in this case, fill fifo with 0 to recover. After 358 * filling dummy data, serial automatically start to 359 * consume them and then will generate normal buffer 360 * empty interrupts. 361 * If both buffer underflow and buffer empty are occured, 362 * it is better to do nomal data transfer than empty one 363 */ 364 snd_ps3_program_dma(card, 365 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 366 snd_ps3_kick_dma(card); 367 snd_ps3_program_dma(card, 368 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 369 snd_ps3_kick_dma(card); 370 } 371 /* clear interrupt cause */ 372 return IRQ_HANDLED; 373}; 374 375/* |
|
372 * audio mute on/off 373 * mute_on : 0 output enabled 374 * 1 mute 375 */ 376static int snd_ps3_mute(int mute_on) 377{ 378 return ps3av_audio_mute(mute_on); 379} 380 381/* | 376 * audio mute on/off 377 * mute_on : 0 output enabled 378 * 1 mute 379 */ 380static int snd_ps3_mute(int mute_on) 381{ 382 return ps3av_audio_mute(mute_on); 383} 384 385/* |
386 * av setting 387 * NOTE: calling this function may generate audio interrupt. 388 */ 389static int snd_ps3_change_avsetting(struct snd_ps3_card_info *card) 390{ 391 int ret, retries, i; 392 pr_debug("%s: start\n", __func__); 393 394 ret = ps3av_set_audio_mode(card->avs.avs_audio_ch, 395 card->avs.avs_audio_rate, 396 card->avs.avs_audio_width, 397 card->avs.avs_audio_format, 398 card->avs.avs_audio_source); 399 /* 400 * Reset the following unwanted settings: 401 */ 402 403 /* disable all 3wire buffers */ 404 update_mask_reg(PS3_AUDIO_AO_3WMCTRL, 405 ~(PS3_AUDIO_AO_3WMCTRL_ASOEN(0) | 406 PS3_AUDIO_AO_3WMCTRL_ASOEN(1) | 407 PS3_AUDIO_AO_3WMCTRL_ASOEN(2) | 408 PS3_AUDIO_AO_3WMCTRL_ASOEN(3)), 409 0); 410 wmb(); /* ensure the hardware sees the change */ 411 /* wait for actually stopped */ 412 retries = 1000; 413 while ((read_reg(PS3_AUDIO_AO_3WMCTRL) & 414 (PS3_AUDIO_AO_3WMCTRL_ASORUN(0) | 415 PS3_AUDIO_AO_3WMCTRL_ASORUN(1) | 416 PS3_AUDIO_AO_3WMCTRL_ASORUN(2) | 417 PS3_AUDIO_AO_3WMCTRL_ASORUN(3))) && 418 --retries) { 419 udelay(1); 420 } 421 422 /* reset buffer pointer */ 423 for (i = 0; i < 4; i++) { 424 update_reg(PS3_AUDIO_AO_3WCTRL(i), 425 PS3_AUDIO_AO_3WCTRL_ASOBRST_RESET); 426 udelay(10); 427 } 428 wmb(); /* ensure the hardware actually start resetting */ 429 430 /* enable 3wire#0 buffer */ 431 update_reg(PS3_AUDIO_AO_3WMCTRL, PS3_AUDIO_AO_3WMCTRL_ASOEN(0)); 432 433 434 /* In 24bit mode,ALSA inserts a zero byte at first byte of per sample */ 435 update_mask_reg(PS3_AUDIO_AO_3WCTRL(0), 436 ~PS3_AUDIO_AO_3WCTRL_ASODF, 437 PS3_AUDIO_AO_3WCTRL_ASODF_LSB); 438 update_mask_reg(PS3_AUDIO_AO_SPDCTRL(0), 439 ~PS3_AUDIO_AO_SPDCTRL_SPODF, 440 PS3_AUDIO_AO_SPDCTRL_SPODF_LSB); 441 /* ensure all the setting above is written back to register */ 442 wmb(); 443 /* avsetting driver altered AX_IE, caller must reset it if you want */ 444 pr_debug("%s: end\n", __func__); 445 return ret; 446} 447 448/* 449 * set sampling rate according to the substream 450 */ 451static int snd_ps3_set_avsetting(struct snd_pcm_substream *substream) 452{ 453 struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream); 454 struct snd_ps3_avsetting_info avs; 455 int ret; 456 457 avs = card->avs; 458 459 pr_debug("%s: called freq=%d width=%d\n", __func__, 460 substream->runtime->rate, 461 snd_pcm_format_width(substream->runtime->format)); 462 463 pr_debug("%s: before freq=%d width=%d\n", __func__, 464 card->avs.avs_audio_rate, card->avs.avs_audio_width); 465 466 /* sample rate */ 467 switch (substream->runtime->rate) { 468 case 44100: 469 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_44K; 470 break; 471 case 48000: 472 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K; 473 break; 474 case 88200: 475 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_88K; 476 break; 477 case 96000: 478 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_96K; 479 break; 480 default: 481 pr_info("%s: invalid rate %d\n", __func__, 482 substream->runtime->rate); 483 return 1; 484 } 485 486 /* width */ 487 switch (snd_pcm_format_width(substream->runtime->format)) { 488 case 16: 489 avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16; 490 break; 491 case 24: 492 avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_24; 493 break; 494 default: 495 pr_info("%s: invalid width %d\n", __func__, 496 snd_pcm_format_width(substream->runtime->format)); 497 return 1; 498 } 499 500 memcpy(avs.avs_cs_info, ps3av_mode_cs_info, 8); 501 502 if (memcmp(&card->avs, &avs, sizeof(avs))) { 503 pr_debug("%s: after freq=%d width=%d\n", __func__, 504 card->avs.avs_audio_rate, card->avs.avs_audio_width); 505 506 card->avs = avs; 507 snd_ps3_change_avsetting(card); 508 ret = 0; 509 } else 510 ret = 1; 511 512 /* check CS non-audio bit and mute accordingly */ 513 if (avs.avs_cs_info[0] & 0x02) 514 ps3av_audio_mute_analog(1); /* mute if non-audio */ 515 else 516 ps3av_audio_mute_analog(0); 517 518 return ret; 519} 520 521/* |
|
382 * PCM operators 383 */ 384static int snd_ps3_pcm_open(struct snd_pcm_substream *substream) 385{ 386 struct snd_pcm_runtime *runtime = substream->runtime; 387 struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream); 388 int pcm_index; 389 --- 8 unchanged lines hidden (view full) --- 398 /* mute off */ 399 snd_ps3_mute(0); /* this function sleep */ 400 401 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 402 PS3_AUDIO_FIFO_STAGE_SIZE * 4 * 2); 403 return 0; 404}; 405 | 522 * PCM operators 523 */ 524static int snd_ps3_pcm_open(struct snd_pcm_substream *substream) 525{ 526 struct snd_pcm_runtime *runtime = substream->runtime; 527 struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream); 528 int pcm_index; 529 --- 8 unchanged lines hidden (view full) --- 538 /* mute off */ 539 snd_ps3_mute(0); /* this function sleep */ 540 541 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 542 PS3_AUDIO_FIFO_STAGE_SIZE * 4 * 2); 543 return 0; 544}; 545 |
546static int snd_ps3_pcm_close(struct snd_pcm_substream *substream) 547{ 548 /* mute on */ 549 snd_ps3_mute(1); 550 return 0; 551}; 552 |
|
406static int snd_ps3_pcm_hw_params(struct snd_pcm_substream *substream, 407 struct snd_pcm_hw_params *hw_params) 408{ 409 size_t size; 410 411 /* alloc transport buffer */ 412 size = params_buffer_bytes(hw_params); 413 snd_pcm_lib_malloc_pages(substream, size); 414 return 0; 415}; 416 | 553static int snd_ps3_pcm_hw_params(struct snd_pcm_substream *substream, 554 struct snd_pcm_hw_params *hw_params) 555{ 556 size_t size; 557 558 /* alloc transport buffer */ 559 size = params_buffer_bytes(hw_params); 560 snd_pcm_lib_malloc_pages(substream, size); 561 return 0; 562}; 563 |
564static int snd_ps3_pcm_hw_free(struct snd_pcm_substream *substream) 565{ 566 int ret; 567 ret = snd_pcm_lib_free_pages(substream); 568 return ret; 569}; 570 |
|
417static int snd_ps3_delay_to_bytes(struct snd_pcm_substream *substream, 418 unsigned int delay_ms) 419{ 420 int ret; 421 int rate ; 422 423 rate = substream->runtime->rate; 424 ret = snd_pcm_format_size(substream->runtime->format, --- 123 unchanged lines hidden (view full) --- 548 } 549 spin_unlock(&card->dma_lock); 550 551 ret = bytes_to_frames(substream->runtime, bytes * 2); 552 553 return ret; 554}; 555 | 571static int snd_ps3_delay_to_bytes(struct snd_pcm_substream *substream, 572 unsigned int delay_ms) 573{ 574 int ret; 575 int rate ; 576 577 rate = substream->runtime->rate; 578 ret = snd_pcm_format_size(substream->runtime->format, --- 123 unchanged lines hidden (view full) --- 702 } 703 spin_unlock(&card->dma_lock); 704 705 ret = bytes_to_frames(substream->runtime, bytes * 2); 706 707 return ret; 708}; 709 |
556static int snd_ps3_pcm_hw_free(struct snd_pcm_substream *substream) 557{ 558 int ret; 559 ret = snd_pcm_lib_free_pages(substream); 560 return ret; 561}; 562 563static int snd_ps3_pcm_close(struct snd_pcm_substream *substream) 564{ 565 /* mute on */ 566 snd_ps3_mute(1); 567 return 0; 568}; 569 570static void snd_ps3_audio_fixup(struct snd_ps3_card_info *card) 571{ 572 /* 573 * avsetting driver seems to never change the followings 574 * so, init them here once 575 */ 576 577 /* no dma interrupt needed */ 578 write_reg(PS3_AUDIO_INTR_EN_0, 0); 579 580 /* use every 4 buffer empty interrupt */ 581 update_mask_reg(PS3_AUDIO_AX_IC, 582 PS3_AUDIO_AX_IC_AASOIMD_MASK, 583 PS3_AUDIO_AX_IC_AASOIMD_EVERY4); 584 585 /* enable 3wire clocks */ 586 update_mask_reg(PS3_AUDIO_AO_3WMCTRL, 587 ~(PS3_AUDIO_AO_3WMCTRL_ASOBCLKD_DISABLED | 588 PS3_AUDIO_AO_3WMCTRL_ASOLRCKD_DISABLED), 589 0); 590 update_reg(PS3_AUDIO_AO_3WMCTRL, 591 PS3_AUDIO_AO_3WMCTRL_ASOPLRCK_DEFAULT); 592} 593 | |
594/* | 710/* |
595 * av setting 596 * NOTE: calling this function may generate audio interrupt. 597 */ 598static int snd_ps3_change_avsetting(struct snd_ps3_card_info *card) 599{ 600 int ret, retries, i; 601 pr_debug("%s: start\n", __func__); 602 603 ret = ps3av_set_audio_mode(card->avs.avs_audio_ch, 604 card->avs.avs_audio_rate, 605 card->avs.avs_audio_width, 606 card->avs.avs_audio_format, 607 card->avs.avs_audio_source); 608 /* 609 * Reset the following unwanted settings: 610 */ 611 612 /* disable all 3wire buffers */ 613 update_mask_reg(PS3_AUDIO_AO_3WMCTRL, 614 ~(PS3_AUDIO_AO_3WMCTRL_ASOEN(0) | 615 PS3_AUDIO_AO_3WMCTRL_ASOEN(1) | 616 PS3_AUDIO_AO_3WMCTRL_ASOEN(2) | 617 PS3_AUDIO_AO_3WMCTRL_ASOEN(3)), 618 0); 619 wmb(); /* ensure the hardware sees the change */ 620 /* wait for actually stopped */ 621 retries = 1000; 622 while ((read_reg(PS3_AUDIO_AO_3WMCTRL) & 623 (PS3_AUDIO_AO_3WMCTRL_ASORUN(0) | 624 PS3_AUDIO_AO_3WMCTRL_ASORUN(1) | 625 PS3_AUDIO_AO_3WMCTRL_ASORUN(2) | 626 PS3_AUDIO_AO_3WMCTRL_ASORUN(3))) && 627 --retries) { 628 udelay(1); 629 } 630 631 /* reset buffer pointer */ 632 for (i = 0; i < 4; i++) { 633 update_reg(PS3_AUDIO_AO_3WCTRL(i), 634 PS3_AUDIO_AO_3WCTRL_ASOBRST_RESET); 635 udelay(10); 636 } 637 wmb(); /* ensure the hardware actually start resetting */ 638 639 /* enable 3wire#0 buffer */ 640 update_reg(PS3_AUDIO_AO_3WMCTRL, PS3_AUDIO_AO_3WMCTRL_ASOEN(0)); 641 642 643 /* In 24bit mode,ALSA inserts a zero byte at first byte of per sample */ 644 update_mask_reg(PS3_AUDIO_AO_3WCTRL(0), 645 ~PS3_AUDIO_AO_3WCTRL_ASODF, 646 PS3_AUDIO_AO_3WCTRL_ASODF_LSB); 647 update_mask_reg(PS3_AUDIO_AO_SPDCTRL(0), 648 ~PS3_AUDIO_AO_SPDCTRL_SPODF, 649 PS3_AUDIO_AO_SPDCTRL_SPODF_LSB); 650 /* ensure all the setting above is written back to register */ 651 wmb(); 652 /* avsetting driver altered AX_IE, caller must reset it if you want */ 653 pr_debug("%s: end\n", __func__); 654 return ret; 655} 656 657static int snd_ps3_init_avsetting(struct snd_ps3_card_info *card) 658{ 659 int ret; 660 pr_debug("%s: start\n", __func__); 661 card->avs.avs_audio_ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2; 662 card->avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K; 663 card->avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16; 664 card->avs.avs_audio_format = PS3AV_CMD_AUDIO_FORMAT_PCM; 665 card->avs.avs_audio_source = PS3AV_CMD_AUDIO_SOURCE_SERIAL; 666 memcpy(card->avs.avs_cs_info, ps3av_mode_cs_info, 8); 667 668 ret = snd_ps3_change_avsetting(card); 669 670 snd_ps3_audio_fixup(card); 671 672 /* to start to generate SPDIF signal, fill data */ 673 snd_ps3_program_dma(card, SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 674 snd_ps3_kick_dma(card); 675 pr_debug("%s: end\n", __func__); 676 return ret; 677} 678 679/* 680 * set sampling rate according to the substream 681 */ 682static int snd_ps3_set_avsetting(struct snd_pcm_substream *substream) 683{ 684 struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream); 685 struct snd_ps3_avsetting_info avs; 686 int ret; 687 688 avs = card->avs; 689 690 pr_debug("%s: called freq=%d width=%d\n", __func__, 691 substream->runtime->rate, 692 snd_pcm_format_width(substream->runtime->format)); 693 694 pr_debug("%s: before freq=%d width=%d\n", __func__, 695 card->avs.avs_audio_rate, card->avs.avs_audio_width); 696 697 /* sample rate */ 698 switch (substream->runtime->rate) { 699 case 44100: 700 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_44K; 701 break; 702 case 48000: 703 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K; 704 break; 705 case 88200: 706 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_88K; 707 break; 708 case 96000: 709 avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_96K; 710 break; 711 default: 712 pr_info("%s: invalid rate %d\n", __func__, 713 substream->runtime->rate); 714 return 1; 715 } 716 717 /* width */ 718 switch (snd_pcm_format_width(substream->runtime->format)) { 719 case 16: 720 avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16; 721 break; 722 case 24: 723 avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_24; 724 break; 725 default: 726 pr_info("%s: invalid width %d\n", __func__, 727 snd_pcm_format_width(substream->runtime->format)); 728 return 1; 729 } 730 731 memcpy(avs.avs_cs_info, ps3av_mode_cs_info, 8); 732 733 if (memcmp(&card->avs, &avs, sizeof(avs))) { 734 pr_debug("%s: after freq=%d width=%d\n", __func__, 735 card->avs.avs_audio_rate, card->avs.avs_audio_width); 736 737 card->avs = avs; 738 snd_ps3_change_avsetting(card); 739 ret = 0; 740 } else 741 ret = 1; 742 743 /* check CS non-audio bit and mute accordingly */ 744 if (avs.avs_cs_info[0] & 0x02) 745 ps3av_audio_mute_analog(1); /* mute if non-audio */ 746 else 747 ps3av_audio_mute_analog(0); 748 749 return ret; 750} 751 752/* | |
753 * SPDIF status bits controls 754 */ 755static int snd_ps3_spdif_mask_info(struct snd_kcontrol *kcontrol, 756 struct snd_ctl_elem_info *uinfo) 757{ 758 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 759 uinfo->count = 1; 760 return 0; --- 49 unchanged lines hidden (view full) --- 810 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 811 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 812 .info = snd_ps3_spdif_mask_info, 813 .get = snd_ps3_spdif_default_get, 814 .put = snd_ps3_spdif_default_put, 815 }, 816}; 817 | 711 * SPDIF status bits controls 712 */ 713static int snd_ps3_spdif_mask_info(struct snd_kcontrol *kcontrol, 714 struct snd_ctl_elem_info *uinfo) 715{ 716 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; 717 uinfo->count = 1; 718 return 0; --- 49 unchanged lines hidden (view full) --- 768 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 769 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), 770 .info = snd_ps3_spdif_mask_info, 771 .get = snd_ps3_spdif_default_get, 772 .put = snd_ps3_spdif_default_put, 773 }, 774}; 775 |
776static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = { 777 .open = snd_ps3_pcm_open, 778 .close = snd_ps3_pcm_close, 779 .ioctl = snd_pcm_lib_ioctl, 780 .hw_params = snd_ps3_pcm_hw_params, 781 .hw_free = snd_ps3_pcm_hw_free, 782 .prepare = snd_ps3_pcm_prepare, 783 .trigger = snd_ps3_pcm_trigger, 784 .pointer = snd_ps3_pcm_pointer, 785}; |
|
818 | 786 |
787 |
|
819static int snd_ps3_map_mmio(void) 820{ 821 the_card.mapped_mmio_vaddr = 822 ioremap(the_card.ps3_dev->m_region->bus_addr, 823 the_card.ps3_dev->m_region->len); 824 825 if (!the_card.mapped_mmio_vaddr) { 826 pr_info("%s: ioremap 0 failed p=%#lx l=%#lx \n", --- 80 unchanged lines hidden (view full) --- 907 (PS3_AUDIO_IOID); 908 909 ret = lv1_gpu_attribute(0x100, 0x007, val, 0, 0); 910 if (ret) 911 pr_info("%s: gpu_attribute failed %d\n", __func__, 912 ret); 913} 914 | 788static int snd_ps3_map_mmio(void) 789{ 790 the_card.mapped_mmio_vaddr = 791 ioremap(the_card.ps3_dev->m_region->bus_addr, 792 the_card.ps3_dev->m_region->len); 793 794 if (!the_card.mapped_mmio_vaddr) { 795 pr_info("%s: ioremap 0 failed p=%#lx l=%#lx \n", --- 80 unchanged lines hidden (view full) --- 876 (PS3_AUDIO_IOID); 877 878 ret = lv1_gpu_attribute(0x100, 0x007, val, 0, 0); 879 if (ret) 880 pr_info("%s: gpu_attribute failed %d\n", __func__, 881 ret); 882} 883 |
884static void snd_ps3_audio_fixup(struct snd_ps3_card_info *card) 885{ 886 /* 887 * avsetting driver seems to never change the followings 888 * so, init them here once 889 */ 890 891 /* no dma interrupt needed */ 892 write_reg(PS3_AUDIO_INTR_EN_0, 0); 893 894 /* use every 4 buffer empty interrupt */ 895 update_mask_reg(PS3_AUDIO_AX_IC, 896 PS3_AUDIO_AX_IC_AASOIMD_MASK, 897 PS3_AUDIO_AX_IC_AASOIMD_EVERY4); 898 899 /* enable 3wire clocks */ 900 update_mask_reg(PS3_AUDIO_AO_3WMCTRL, 901 ~(PS3_AUDIO_AO_3WMCTRL_ASOBCLKD_DISABLED | 902 PS3_AUDIO_AO_3WMCTRL_ASOLRCKD_DISABLED), 903 0); 904 update_reg(PS3_AUDIO_AO_3WMCTRL, 905 PS3_AUDIO_AO_3WMCTRL_ASOPLRCK_DEFAULT); 906} 907 908static int snd_ps3_init_avsetting(struct snd_ps3_card_info *card) 909{ 910 int ret; 911 pr_debug("%s: start\n", __func__); 912 card->avs.avs_audio_ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2; 913 card->avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K; 914 card->avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16; 915 card->avs.avs_audio_format = PS3AV_CMD_AUDIO_FORMAT_PCM; 916 card->avs.avs_audio_source = PS3AV_CMD_AUDIO_SOURCE_SERIAL; 917 memcpy(card->avs.avs_cs_info, ps3av_mode_cs_info, 8); 918 919 ret = snd_ps3_change_avsetting(card); 920 921 snd_ps3_audio_fixup(card); 922 923 /* to start to generate SPDIF signal, fill data */ 924 snd_ps3_program_dma(card, SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 925 snd_ps3_kick_dma(card); 926 pr_debug("%s: end\n", __func__); 927 return ret; 928} 929 |
|
915static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev) 916{ 917 int i, ret; 918 u64 lpar_addr, lpar_size; 919 920 BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1)); 921 BUG_ON(dev->match_id != PS3_MATCH_ID_SOUND); 922 --- 185 unchanged lines hidden (view full) --- 1108 .core = { 1109 .name = SND_PS3_DRIVER_NAME, 1110 .owner = THIS_MODULE, 1111 }, 1112}; 1113 1114 1115/* | 930static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev) 931{ 932 int i, ret; 933 u64 lpar_addr, lpar_size; 934 935 BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1)); 936 BUG_ON(dev->match_id != PS3_MATCH_ID_SOUND); 937 --- 185 unchanged lines hidden (view full) --- 1123 .core = { 1124 .name = SND_PS3_DRIVER_NAME, 1125 .owner = THIS_MODULE, 1126 }, 1127}; 1128 1129 1130/* |
1116 * Interrupt handler 1117 */ 1118static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id) 1119{ 1120 1121 uint32_t port_intr; 1122 int underflow_occured = 0; 1123 struct snd_ps3_card_info *card = dev_id; 1124 1125 if (!card->running) { 1126 update_reg(PS3_AUDIO_AX_IS, 0); 1127 update_reg(PS3_AUDIO_INTR_0, 0); 1128 return IRQ_HANDLED; 1129 } 1130 1131 port_intr = read_reg(PS3_AUDIO_AX_IS); 1132 /* 1133 *serial buffer empty detected (every 4 times), 1134 *program next dma and kick it 1135 */ 1136 if (port_intr & PS3_AUDIO_AX_IE_ASOBEIE(0)) { 1137 write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBEIE(0)); 1138 if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) { 1139 write_reg(PS3_AUDIO_AX_IS, port_intr); 1140 underflow_occured = 1; 1141 } 1142 if (card->silent) { 1143 /* we are still in silent time */ 1144 snd_ps3_program_dma(card, 1145 (underflow_occured) ? 1146 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL : 1147 SND_PS3_DMA_FILLTYPE_SILENT_RUNNING); 1148 snd_ps3_kick_dma(card); 1149 card->silent--; 1150 } else { 1151 snd_ps3_program_dma(card, 1152 (underflow_occured) ? 1153 SND_PS3_DMA_FILLTYPE_FIRSTFILL : 1154 SND_PS3_DMA_FILLTYPE_RUNNING); 1155 snd_ps3_kick_dma(card); 1156 snd_pcm_period_elapsed(card->substream); 1157 } 1158 } else if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) { 1159 write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBUIE(0)); 1160 /* 1161 * serial out underflow, but buffer empty not detected. 1162 * in this case, fill fifo with 0 to recover. After 1163 * filling dummy data, serial automatically start to 1164 * consume them and then will generate normal buffer 1165 * empty interrupts. 1166 * If both buffer underflow and buffer empty are occured, 1167 * it is better to do nomal data transfer than empty one 1168 */ 1169 snd_ps3_program_dma(card, 1170 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 1171 snd_ps3_kick_dma(card); 1172 snd_ps3_program_dma(card, 1173 SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL); 1174 snd_ps3_kick_dma(card); 1175 } 1176 /* clear interrupt cause */ 1177 return IRQ_HANDLED; 1178}; 1179 1180/* | |
1181 * module/subsystem initialize/terminate 1182 */ 1183static int __init snd_ps3_init(void) 1184{ 1185 int ret; 1186 1187 if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) 1188 return -ENXIO; 1189 1190 memset(&the_card, 0, sizeof(the_card)); 1191 spin_lock_init(&the_card.dma_lock); 1192 1193 /* register systembus DRIVER, this calls our probe() func */ 1194 ret = ps3_system_bus_driver_register(&snd_ps3_bus_driver_info); 1195 1196 return ret; 1197} | 1131 * module/subsystem initialize/terminate 1132 */ 1133static int __init snd_ps3_init(void) 1134{ 1135 int ret; 1136 1137 if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) 1138 return -ENXIO; 1139 1140 memset(&the_card, 0, sizeof(the_card)); 1141 spin_lock_init(&the_card.dma_lock); 1142 1143 /* register systembus DRIVER, this calls our probe() func */ 1144 ret = ps3_system_bus_driver_register(&snd_ps3_bus_driver_info); 1145 1146 return ret; 1147} |
1148module_init(snd_ps3_init); |
|
1198 1199static void __exit snd_ps3_exit(void) 1200{ 1201 ps3_system_bus_driver_unregister(&snd_ps3_bus_driver_info); 1202} | 1149 1150static void __exit snd_ps3_exit(void) 1151{ 1152 ps3_system_bus_driver_unregister(&snd_ps3_bus_driver_info); 1153} |
1154module_exit(snd_ps3_exit); |
|
1203 | 1155 |
1156MODULE_LICENSE("GPL v2"); 1157MODULE_DESCRIPTION("PS3 sound driver"); 1158MODULE_AUTHOR("Sony Computer Entertainment Inc."); |
|
1204MODULE_ALIAS(PS3_MODULE_ALIAS_SOUND); | 1159MODULE_ALIAS(PS3_MODULE_ALIAS_SOUND); |