aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_ca0132.c
diff options
context:
space:
mode:
authorIan Minett <ian_minett@creativelabs.com>2012-09-20 23:29:18 -0400
committerTakashi Iwai <tiwai@suse.de>2012-11-28 02:47:18 -0500
commitd5c21b88e8df0701f33eaa33ef33601d8314a4f4 (patch)
treeea3d890ba6e85cd12745690f4cd92ade07368846 /sound/pci/hda/patch_ca0132.c
parentc3b4eea26208b8e247ece9d3a9ec8b2eab48c464 (diff)
ALSA: hda - Add comments and descriptions to CA0132 functions
Add comments and descriptions to functions. Bump dsp_free_ports() to below dsp_allocate_ports_format() to group the alloc functions together for commenting. Signed-off-by: Ian Minett <ian_minett@creativelabs.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_ca0132.c')
-rw-r--r--sound/pci/hda/patch_ca0132.c180
1 files changed, 163 insertions, 17 deletions
diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c
index 4d8a7edfd308..a7b216ea9df3 100644
--- a/sound/pci/hda/patch_ca0132.c
+++ b/sound/pci/hda/patch_ca0132.c
@@ -519,6 +519,9 @@ static int chipio_write_data(struct hda_codec *codec, unsigned int data)
519 return res; 519 return res;
520} 520}
521 521
522/*
523 * Write multiple data through the vendor widget -- NOT protected by the Mutex!
524 */
522static int chipio_write_data_multiple(struct hda_codec *codec, 525static int chipio_write_data_multiple(struct hda_codec *codec,
523 const u32 *data, 526 const u32 *data,
524 unsigned int count) 527 unsigned int count)
@@ -588,6 +591,10 @@ exit:
588 return err; 591 return err;
589} 592}
590 593
594/*
595 * Write multiple values to the given address through the chip I/O widget.
596 * protected by the Mutex
597 */
591static int chipio_write_multiple(struct hda_codec *codec, 598static int chipio_write_multiple(struct hda_codec *codec,
592 u32 chip_addx, 599 u32 chip_addx,
593 const u32 *data, 600 const u32 *data,
@@ -634,6 +641,9 @@ exit:
634 return err; 641 return err;
635} 642}
636 643
644/*
645 * Set chip control flags through the chip I/O widget.
646 */
637static void chipio_set_control_flag(struct hda_codec *codec, 647static void chipio_set_control_flag(struct hda_codec *codec,
638 enum control_flag_id flag_id, 648 enum control_flag_id flag_id,
639 bool flag_state) 649 bool flag_state)
@@ -647,6 +657,9 @@ static void chipio_set_control_flag(struct hda_codec *codec,
647 VENDOR_CHIPIO_FLAG_SET, val); 657 VENDOR_CHIPIO_FLAG_SET, val);
648} 658}
649 659
660/*
661 * Set chip parameters through the chip I/O widget.
662 */
650static void chipio_set_control_param(struct hda_codec *codec, 663static void chipio_set_control_param(struct hda_codec *codec,
651 enum control_param_id param_id, int param_val) 664 enum control_param_id param_id, int param_val)
652{ 665{
@@ -671,6 +684,9 @@ static void chipio_set_control_param(struct hda_codec *codec,
671 } 684 }
672} 685}
673 686
687/*
688 * Set sampling rate of the connection point.
689 */
674static void chipio_set_conn_rate(struct hda_codec *codec, 690static void chipio_set_conn_rate(struct hda_codec *codec,
675 int connid, enum ca0132_sample_rate rate) 691 int connid, enum ca0132_sample_rate rate)
676{ 692{
@@ -679,6 +695,9 @@ static void chipio_set_conn_rate(struct hda_codec *codec,
679 rate); 695 rate);
680} 696}
681 697
698/*
699 * Enable clocks.
700 */
682static void chipio_enable_clocks(struct hda_codec *codec) 701static void chipio_enable_clocks(struct hda_codec *codec)
683{ 702{
684 struct ca0132_spec *spec = codec->spec; 703 struct ca0132_spec *spec = codec->spec;
@@ -718,6 +737,9 @@ static int dspio_send(struct hda_codec *codec, unsigned int reg,
718 return -EIO; 737 return -EIO;
719} 738}
720 739
740/*
741 * Wait for DSP to be ready for commands
742 */
721static void dspio_write_wait(struct hda_codec *codec) 743static void dspio_write_wait(struct hda_codec *codec)
722{ 744{
723 int cur_val, prv_val; 745 int cur_val, prv_val;
@@ -734,6 +756,9 @@ static void dspio_write_wait(struct hda_codec *codec)
734 } while (cur_val && (cur_val == prv_val) && --retry); 756 } while (cur_val && (cur_val == prv_val) && --retry);
735} 757}
736 758
759/*
760 * Write SCP data to DSP
761 */
737static int dspio_write(struct hda_codec *codec, unsigned int scp_data) 762static int dspio_write(struct hda_codec *codec, unsigned int scp_data)
738{ 763{
739 struct ca0132_spec *spec = codec->spec; 764 struct ca0132_spec *spec = codec->spec;
@@ -762,6 +787,9 @@ error:
762 -EIO : 0; 787 -EIO : 0;
763} 788}
764 789
790/*
791 * Write multiple SCP data to DSP
792 */
765static int dspio_write_multiple(struct hda_codec *codec, 793static int dspio_write_multiple(struct hda_codec *codec,
766 unsigned int *buffer, unsigned int size) 794 unsigned int *buffer, unsigned int size)
767{ 795{
@@ -782,6 +810,9 @@ static int dspio_write_multiple(struct hda_codec *codec,
782 return status; 810 return status;
783} 811}
784 812
813/*
814 * Construct the SCP header using corresponding fields
815 */
785static inline unsigned int 816static inline unsigned int
786make_scp_header(unsigned int target_id, unsigned int source_id, 817make_scp_header(unsigned int target_id, unsigned int source_id,
787 unsigned int get_flag, unsigned int req, 818 unsigned int get_flag, unsigned int req,
@@ -802,6 +833,9 @@ make_scp_header(unsigned int target_id, unsigned int source_id,
802 return header; 833 return header;
803} 834}
804 835
836/*
837 * Extract corresponding fields from SCP header
838 */
805static inline void 839static inline void
806extract_scp_header(unsigned int header, 840extract_scp_header(unsigned int header,
807 unsigned int *target_id, unsigned int *source_id, 841 unsigned int *target_id, unsigned int *source_id,
@@ -835,6 +869,9 @@ struct scp_msg {
835 unsigned int data[SCP_MAX_DATA_WORDS]; 869 unsigned int data[SCP_MAX_DATA_WORDS];
836}; 870};
837 871
872/*
873 * Send SCP message to DSP
874 */
838static int dspio_send_scp_message(struct hda_codec *codec, 875static int dspio_send_scp_message(struct hda_codec *codec,
839 unsigned char *send_buf, 876 unsigned char *send_buf,
840 unsigned int send_buf_size, 877 unsigned int send_buf_size,
@@ -912,6 +949,19 @@ static int dspio_send_scp_message(struct hda_codec *codec,
912 return status; 949 return status;
913} 950}
914 951
952/**
953 * Prepare and send the SCP message to DSP
954 * @codec: the HDA codec
955 * @mod_id: ID of the DSP module to send the command
956 * @req: ID of request to send to the DSP module
957 * @dir: SET or GET
958 * @data: pointer to the data to send with the request, request specific
959 * @len: length of the data, in bytes
960 * @reply: point to the buffer to hold data returned for a reply
961 * @reply_len: length of the reply buffer returned from GET
962 *
963 * Returns zero or a negative error code.
964 */
915static int dspio_scp(struct hda_codec *codec, 965static int dspio_scp(struct hda_codec *codec,
916 int mod_id, int req, int dir, void *data, unsigned int len, 966 int mod_id, int req, int dir, void *data, unsigned int len,
917 void *reply, unsigned int *reply_len) 967 void *reply, unsigned int *reply_len)
@@ -988,6 +1038,9 @@ static int dspio_scp(struct hda_codec *codec,
988 return status; 1038 return status;
989} 1039}
990 1040
1041/*
1042 * Allocate a DSP DMA channel via an SCP message
1043 */
991static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan) 1044static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
992{ 1045{
993 int status = 0; 1046 int status = 0;
@@ -1013,6 +1066,9 @@ static int dspio_alloc_dma_chan(struct hda_codec *codec, unsigned int *dma_chan)
1013 return status; 1066 return status;
1014} 1067}
1015 1068
1069/*
1070 * Free a DSP DMA via an SCP message
1071 */
1016static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan) 1072static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1017{ 1073{
1018 int status = 0; 1074 int status = 0;
@@ -1035,7 +1091,7 @@ static int dspio_free_dma_chan(struct hda_codec *codec, unsigned int dma_chan)
1035} 1091}
1036 1092
1037/* 1093/*
1038 * CA0132 DSP access stuffs 1094 * (Re)start the DSP
1039 */ 1095 */
1040static int dsp_set_run_state(struct hda_codec *codec) 1096static int dsp_set_run_state(struct hda_codec *codec)
1041{ 1097{
@@ -1069,6 +1125,9 @@ static int dsp_set_run_state(struct hda_codec *codec)
1069 return 0; 1125 return 0;
1070} 1126}
1071 1127
1128/*
1129 * Reset the DSP
1130 */
1072static int dsp_reset(struct hda_codec *codec) 1131static int dsp_reset(struct hda_codec *codec)
1073{ 1132{
1074 unsigned int res; 1133 unsigned int res;
@@ -1088,6 +1147,9 @@ static int dsp_reset(struct hda_codec *codec)
1088 return 0; 1147 return 0;
1089} 1148}
1090 1149
1150/*
1151 * Convert chip address to DSP address
1152 */
1091static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx, 1153static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
1092 bool *code, bool *yram) 1154 bool *code, bool *yram)
1093{ 1155{
@@ -1106,6 +1168,9 @@ static unsigned int dsp_chip_to_dsp_addx(unsigned int chip_addx,
1106 return (unsigned int)INVALID_CHIP_ADDRESS; 1168 return (unsigned int)INVALID_CHIP_ADDRESS;
1107} 1169}
1108 1170
1171/*
1172 * Check if the DSP DMA is active
1173 */
1109static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan) 1174static bool dsp_is_dma_active(struct hda_codec *codec, unsigned int dma_chan)
1110{ 1175{
1111 unsigned int dma_chnlstart_reg; 1176 unsigned int dma_chnlstart_reg;
@@ -1226,6 +1291,9 @@ static int dsp_dma_setup_common(struct hda_codec *codec,
1226 return 0; 1291 return 0;
1227} 1292}
1228 1293
1294/*
1295 * Setup the DSP DMA per-transfer-specific registers
1296 */
1229static int dsp_dma_setup(struct hda_codec *codec, 1297static int dsp_dma_setup(struct hda_codec *codec,
1230 unsigned int chip_addx, 1298 unsigned int chip_addx,
1231 unsigned int count, 1299 unsigned int count,
@@ -1314,6 +1382,9 @@ static int dsp_dma_setup(struct hda_codec *codec,
1314 return 0; 1382 return 0;
1315} 1383}
1316 1384
1385/*
1386 * Start the DSP DMA
1387 */
1317static int dsp_dma_start(struct hda_codec *codec, 1388static int dsp_dma_start(struct hda_codec *codec,
1318 unsigned int dma_chan, bool ovly) 1389 unsigned int dma_chan, bool ovly)
1319{ 1390{
@@ -1347,6 +1418,9 @@ static int dsp_dma_start(struct hda_codec *codec,
1347 return status; 1418 return status;
1348} 1419}
1349 1420
1421/*
1422 * Stop the DSP DMA
1423 */
1350static int dsp_dma_stop(struct hda_codec *codec, 1424static int dsp_dma_stop(struct hda_codec *codec,
1351 unsigned int dma_chan, bool ovly) 1425 unsigned int dma_chan, bool ovly)
1352{ 1426{
@@ -1379,6 +1453,17 @@ static int dsp_dma_stop(struct hda_codec *codec,
1379 return status; 1453 return status;
1380} 1454}
1381 1455
1456/**
1457 * Allocate router ports
1458 *
1459 * @codec: the HDA codec
1460 * @num_chans: number of channels in the stream
1461 * @ports_per_channel: number of ports per channel
1462 * @start_device: start device
1463 * @port_map: pointer to the port list to hold the allocated ports
1464 *
1465 * Returns zero or a negative error code.
1466 */
1382static int dsp_allocate_router_ports(struct hda_codec *codec, 1467static int dsp_allocate_router_ports(struct hda_codec *codec,
1383 unsigned int num_chans, 1468 unsigned int num_chans,
1384 unsigned int ports_per_channel, 1469 unsigned int ports_per_channel,
@@ -1417,6 +1502,9 @@ static int dsp_allocate_router_ports(struct hda_codec *codec,
1417 return (res < 0) ? res : 0; 1502 return (res < 0) ? res : 0;
1418} 1503}
1419 1504
1505/*
1506 * Free router ports
1507 */
1420static int dsp_free_router_ports(struct hda_codec *codec) 1508static int dsp_free_router_ports(struct hda_codec *codec)
1421{ 1509{
1422 int status = 0; 1510 int status = 0;
@@ -1434,6 +1522,9 @@ static int dsp_free_router_ports(struct hda_codec *codec)
1434 return status; 1522 return status;
1435} 1523}
1436 1524
1525/*
1526 * Allocate DSP ports for the download stream
1527 */
1437static int dsp_allocate_ports(struct hda_codec *codec, 1528static int dsp_allocate_ports(struct hda_codec *codec,
1438 unsigned int num_chans, 1529 unsigned int num_chans,
1439 unsigned int rate_multi, unsigned int *port_map) 1530 unsigned int rate_multi, unsigned int *port_map)
@@ -1455,22 +1546,6 @@ static int dsp_allocate_ports(struct hda_codec *codec,
1455 return status; 1546 return status;
1456} 1547}
1457 1548
1458static int dsp_free_ports(struct hda_codec *codec)
1459{
1460 int status;
1461
1462 snd_printdd(KERN_INFO " dsp_free_ports() -- begin");
1463
1464 status = dsp_free_router_ports(codec);
1465 if (status < 0) {
1466 snd_printdd(KERN_ERR "free router ports fail");
1467 return status;
1468 }
1469 snd_printdd(KERN_INFO " dsp_free_ports() -- complete");
1470
1471 return status;
1472}
1473
1474static int dsp_allocate_ports_format(struct hda_codec *codec, 1549static int dsp_allocate_ports_format(struct hda_codec *codec,
1475 const unsigned short fmt, 1550 const unsigned short fmt,
1476 unsigned int *port_map) 1551 unsigned int *port_map)
@@ -1495,6 +1570,25 @@ static int dsp_allocate_ports_format(struct hda_codec *codec,
1495} 1570}
1496 1571
1497/* 1572/*
1573 * free DSP ports
1574 */
1575static int dsp_free_ports(struct hda_codec *codec)
1576{
1577 int status;
1578
1579 snd_printdd(KERN_INFO " dsp_free_ports() -- begin");
1580
1581 status = dsp_free_router_ports(codec);
1582 if (status < 0) {
1583 snd_printdd(KERN_ERR "free router ports fail");
1584 return status;
1585 }
1586 snd_printdd(KERN_INFO " dsp_free_ports() -- complete");
1587
1588 return status;
1589}
1590
1591/*
1498 * HDA DMA engine stuffs for DSP code download 1592 * HDA DMA engine stuffs for DSP code download
1499 */ 1593 */
1500struct dma_engine { 1594struct dma_engine {
@@ -1528,6 +1622,9 @@ static int dma_convert_to_hda_format(
1528 return 0; 1622 return 0;
1529} 1623}
1530 1624
1625/*
1626 * Reset DMA for DSP download
1627 */
1531static int dma_reset(struct dma_engine *dma) 1628static int dma_reset(struct dma_engine *dma)
1532{ 1629{
1533 struct hda_codec *codec = dma->codec; 1630 struct hda_codec *codec = dma->codec;
@@ -1642,6 +1739,11 @@ static const struct dsp_image_seg *get_next_seg_ptr(
1642 */ 1739 */
1643#define INVALID_DMA_CHANNEL (~0UL) 1740#define INVALID_DMA_CHANNEL (~0UL)
1644 1741
1742/*
1743 * Program a list of address/data pairs via the ChipIO widget.
1744 * The segment data is in the format of successive pairs of words.
1745 * These are repeated as indicated by the segment's count field.
1746 */
1645static int dspxfr_hci_write(struct hda_codec *codec, 1747static int dspxfr_hci_write(struct hda_codec *codec,
1646 const struct dsp_image_seg *fls) 1748 const struct dsp_image_seg *fls)
1647{ 1749{
@@ -1668,6 +1770,21 @@ static int dspxfr_hci_write(struct hda_codec *codec,
1668 return 0; 1770 return 0;
1669} 1771}
1670 1772
1773/**
1774 * Write a block of data into DSP code or data RAM using pre-allocated
1775 * DMA engine.
1776 *
1777 * @codec: the HDA codec
1778 * @fls: pointer to a fast load image
1779 * @reloc: Relocation address for loading single-segment overlays, or 0 for
1780 * no relocation
1781 * @dma_engine: pointer to DMA engine to be used for DSP download
1782 * @dma_chan: The number of DMA channels used for DSP download
1783 * @port_map_mask: port mapping
1784 * @ovly: TRUE if overlay format is required
1785 *
1786 * Returns zero or a negative error code.
1787 */
1671static int dspxfr_one_seg(struct hda_codec *codec, 1788static int dspxfr_one_seg(struct hda_codec *codec,
1672 const struct dsp_image_seg *fls, 1789 const struct dsp_image_seg *fls,
1673 unsigned int reloc, 1790 unsigned int reloc,
@@ -1836,6 +1953,18 @@ static int dspxfr_one_seg(struct hda_codec *codec,
1836 return status; 1953 return status;
1837} 1954}
1838 1955
1956/**
1957 * Write the entire DSP image of a DSP code/data overlay to DSP memories
1958 *
1959 * @codec: the HDA codec
1960 * @fls_data: pointer to a fast load image
1961 * @reloc: Relocation address for loading single-segment overlays, or 0 for
1962 * no relocation
1963 * @format: format of the stream used for DSP download
1964 * @ovly: TRUE if overlay format is required
1965 *
1966 * Returns zero or a negative error code.
1967 */
1839static int dspxfr_image(struct hda_codec *codec, 1968static int dspxfr_image(struct hda_codec *codec,
1840 const struct dsp_image_seg *fls_data, 1969 const struct dsp_image_seg *fls_data,
1841 unsigned int reloc, struct hda_stream_format *format, 1970 unsigned int reloc, struct hda_stream_format *format,
@@ -1970,6 +2099,23 @@ static void dspload_post_setup(struct hda_codec *codec)
1970 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002); 2099 chipio_write(codec, XRAM_XRAM_INST_OFFSET(0x29), 0x00000002);
1971} 2100}
1972 2101
2102/**
2103 * Download DSP from a DSP Image Fast Load structure. This structure is a
2104 * linear, non-constant sized element array of structures, each of which
2105 * contain the count of the data to be loaded, the data itself, and the
2106 * corresponding starting chip address of the starting data location.
2107 *
2108 * @codec: the HDA codec
2109 * @fls: pointer to a fast load image
2110 * @ovly: TRUE if overlay format is required
2111 * @reloc: Relocation address for loading single-segment overlays, or 0 for
2112 * no relocation
2113 * @autostart: TRUE if DSP starts after loading; ignored if ovly is TRUE
2114 * @router_chans: number of audio router channels to be allocated (0 means use
2115 * internal defaults; max is 32)
2116 *
2117 * Returns zero or a negative error code.
2118 */
1973static int dspload_image(struct hda_codec *codec, 2119static int dspload_image(struct hda_codec *codec,
1974 const struct dsp_image_seg *fls, 2120 const struct dsp_image_seg *fls,
1975 bool ovly, 2121 bool ovly,