diff options
author | Takashi Iwai <tiwai@suse.de> | 2012-06-15 08:34:42 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-06-15 08:36:20 -0400 |
commit | d0b1252dd11549103a97a13aca25737b084c5618 (patch) | |
tree | ac1306034046d1b94e54856dfdb534f0973d2e96 /sound/pci | |
parent | 4f0110ced1b5d61e6df4871f6f800a9d3678bf26 (diff) |
ALSA: hda - Use common codes for ATI, Nvidia and VIA simple codecs
The code refactoring using the same helper functions for sharing the
codes among ATI, Nvidia and VIA simple_hdmi* stuff. Except for that
spec->pcm_playback is no longer pointer, the functionality doesn't
change.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci')
-rw-r--r-- | sound/pci/hda/patch_hdmi.c | 191 |
1 files changed, 65 insertions, 126 deletions
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c index c9d0c98bbe86..6bf784fc8d6d 100644 --- a/sound/pci/hda/patch_hdmi.c +++ b/sound/pci/hda/patch_hdmi.c | |||
@@ -85,7 +85,7 @@ struct hdmi_spec { | |||
85 | * Non-generic ATI/NVIDIA specific | 85 | * Non-generic ATI/NVIDIA specific |
86 | */ | 86 | */ |
87 | struct hda_multi_out multiout; | 87 | struct hda_multi_out multiout; |
88 | const struct hda_pcm_stream *pcm_playback; | 88 | struct hda_pcm_stream pcm_playback; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
@@ -1367,8 +1367,7 @@ static int simple_playback_build_pcms(struct hda_codec *codec) | |||
1367 | info->name = get_hdmi_pcm_name(i); | 1367 | info->name = get_hdmi_pcm_name(i); |
1368 | info->pcm_type = HDA_PCM_TYPE_HDMI; | 1368 | info->pcm_type = HDA_PCM_TYPE_HDMI; |
1369 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; | 1369 | pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK]; |
1370 | snd_BUG_ON(!spec->pcm_playback); | 1370 | *pstr = spec->pcm_playback; |
1371 | *pstr = *spec->pcm_playback; | ||
1372 | pstr->nid = spec->cvts[i].cvt_nid; | 1371 | pstr->nid = spec->cvts[i].cvt_nid; |
1373 | if (pstr->channels_max <= 2 && chans && chans <= 16) | 1372 | if (pstr->channels_max <= 2 && chans && chans <= 16) |
1374 | pstr->channels_max = chans; | 1373 | pstr->channels_max = chans; |
@@ -1560,6 +1559,49 @@ static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |||
1560 | stream_tag, format, substream); | 1559 | stream_tag, format, substream); |
1561 | } | 1560 | } |
1562 | 1561 | ||
1562 | static const struct hda_pcm_stream simple_pcm_playback = { | ||
1563 | .substreams = 1, | ||
1564 | .channels_min = 2, | ||
1565 | .channels_max = 2, | ||
1566 | .ops = { | ||
1567 | .open = simple_playback_pcm_open, | ||
1568 | .close = simple_playback_pcm_close, | ||
1569 | .prepare = simple_playback_pcm_prepare | ||
1570 | }, | ||
1571 | }; | ||
1572 | |||
1573 | static const struct hda_codec_ops simple_hdmi_patch_ops = { | ||
1574 | .build_controls = simple_playback_build_controls, | ||
1575 | .build_pcms = simple_playback_build_pcms, | ||
1576 | .init = simple_playback_init, | ||
1577 | .free = simple_playback_free, | ||
1578 | }; | ||
1579 | |||
1580 | static int patch_simple_hdmi(struct hda_codec *codec, | ||
1581 | hda_nid_t cvt_nid, hda_nid_t pin_nid) | ||
1582 | { | ||
1583 | struct hdmi_spec *spec; | ||
1584 | |||
1585 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | ||
1586 | if (!spec) | ||
1587 | return -ENOMEM; | ||
1588 | |||
1589 | codec->spec = spec; | ||
1590 | |||
1591 | spec->multiout.num_dacs = 0; /* no analog */ | ||
1592 | spec->multiout.max_channels = 2; | ||
1593 | spec->multiout.dig_out_nid = cvt_nid; | ||
1594 | spec->num_cvts = 1; | ||
1595 | spec->num_pins = 1; | ||
1596 | spec->cvts[0].cvt_nid = cvt_nid; | ||
1597 | spec->cvts[0].cvt_nid = pin_nid; | ||
1598 | spec->pcm_playback = simple_pcm_playback; | ||
1599 | |||
1600 | codec->patch_ops = simple_hdmi_patch_ops; | ||
1601 | |||
1602 | return 0; | ||
1603 | } | ||
1604 | |||
1563 | static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, | 1605 | static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, |
1564 | int channels) | 1606 | int channels) |
1565 | { | 1607 | { |
@@ -1732,54 +1774,20 @@ static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = { | |||
1732 | }, | 1774 | }, |
1733 | }; | 1775 | }; |
1734 | 1776 | ||
1735 | static const struct hda_pcm_stream nvhdmi_pcm_playback_2ch = { | ||
1736 | .substreams = 1, | ||
1737 | .channels_min = 2, | ||
1738 | .channels_max = 2, | ||
1739 | .nid = nvhdmi_master_con_nid_7x, | ||
1740 | .rates = SUPPORTED_RATES, | ||
1741 | .maxbps = SUPPORTED_MAXBPS, | ||
1742 | .formats = SUPPORTED_FORMATS, | ||
1743 | .ops = { | ||
1744 | .open = simple_playback_pcm_open, | ||
1745 | .close = simple_playback_pcm_close, | ||
1746 | .prepare = simple_playback_pcm_prepare | ||
1747 | }, | ||
1748 | }; | ||
1749 | |||
1750 | static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = { | ||
1751 | .build_controls = simple_playback_build_controls, | ||
1752 | .build_pcms = simple_playback_build_pcms, | ||
1753 | .init = nvhdmi_7x_init, | ||
1754 | .free = simple_playback_free, | ||
1755 | }; | ||
1756 | |||
1757 | static const struct hda_codec_ops nvhdmi_patch_ops_2ch = { | ||
1758 | .build_controls = simple_playback_build_controls, | ||
1759 | .build_pcms = simple_playback_build_pcms, | ||
1760 | .init = nvhdmi_7x_init, | ||
1761 | .free = simple_playback_free, | ||
1762 | }; | ||
1763 | |||
1764 | static int patch_nvhdmi_2ch(struct hda_codec *codec) | 1777 | static int patch_nvhdmi_2ch(struct hda_codec *codec) |
1765 | { | 1778 | { |
1766 | struct hdmi_spec *spec; | 1779 | struct hdmi_spec *spec; |
1780 | int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x, | ||
1781 | nvhdmi_master_pin_nid_7x); | ||
1782 | if (err < 0) | ||
1783 | return err; | ||
1767 | 1784 | ||
1768 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 1785 | codec->patch_ops.init = nvhdmi_7x_init; |
1769 | if (spec == NULL) | 1786 | /* override the PCM rates, etc, as the codec doesn't give full list */ |
1770 | return -ENOMEM; | 1787 | spec = codec->spec; |
1771 | 1788 | spec->pcm_playback.rates = SUPPORTED_RATES; | |
1772 | codec->spec = spec; | 1789 | spec->pcm_playback.maxbps = SUPPORTED_MAXBPS; |
1773 | 1790 | spec->pcm_playback.formats = SUPPORTED_FORMATS; | |
1774 | spec->multiout.num_dacs = 0; /* no analog */ | ||
1775 | spec->multiout.max_channels = 2; | ||
1776 | spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x; | ||
1777 | spec->num_cvts = 1; | ||
1778 | spec->cvts[0].cvt_nid = nvhdmi_master_con_nid_7x; | ||
1779 | spec->pcm_playback = &nvhdmi_pcm_playback_2ch; | ||
1780 | |||
1781 | codec->patch_ops = nvhdmi_patch_ops_2ch; | ||
1782 | |||
1783 | return 0; | 1791 | return 0; |
1784 | } | 1792 | } |
1785 | 1793 | ||
@@ -1787,13 +1795,11 @@ static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) | |||
1787 | { | 1795 | { |
1788 | struct hdmi_spec *spec; | 1796 | struct hdmi_spec *spec; |
1789 | int err = patch_nvhdmi_2ch(codec); | 1797 | int err = patch_nvhdmi_2ch(codec); |
1790 | |||
1791 | if (err < 0) | 1798 | if (err < 0) |
1792 | return err; | 1799 | return err; |
1793 | spec = codec->spec; | 1800 | spec = codec->spec; |
1794 | spec->multiout.max_channels = 8; | 1801 | spec->multiout.max_channels = 8; |
1795 | spec->pcm_playback = &nvhdmi_pcm_playback_8ch_7x; | 1802 | spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x; |
1796 | codec->patch_ops = nvhdmi_patch_ops_8ch_7x; | ||
1797 | 1803 | ||
1798 | /* Initialize the audio infoframe channel mask and checksum to something | 1804 | /* Initialize the audio infoframe channel mask and checksum to something |
1799 | * valid */ | 1805 | * valid */ |
@@ -1837,47 +1843,14 @@ static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo, | |||
1837 | return 0; | 1843 | return 0; |
1838 | } | 1844 | } |
1839 | 1845 | ||
1840 | static const struct hda_pcm_stream atihdmi_pcm_digital_playback = { | ||
1841 | .substreams = 1, | ||
1842 | .channels_min = 2, | ||
1843 | .channels_max = 2, | ||
1844 | .nid = ATIHDMI_CVT_NID, | ||
1845 | .ops = { | ||
1846 | .open = simple_playback_pcm_open, | ||
1847 | .close = simple_playback_pcm_close, | ||
1848 | .prepare = atihdmi_playback_pcm_prepare | ||
1849 | }, | ||
1850 | }; | ||
1851 | |||
1852 | static const struct hda_codec_ops atihdmi_patch_ops = { | ||
1853 | .build_controls = simple_playback_build_controls, | ||
1854 | .build_pcms = simple_playback_build_pcms, | ||
1855 | .init = simple_playback_init, | ||
1856 | .free = simple_playback_free, | ||
1857 | }; | ||
1858 | |||
1859 | |||
1860 | static int patch_atihdmi(struct hda_codec *codec) | 1846 | static int patch_atihdmi(struct hda_codec *codec) |
1861 | { | 1847 | { |
1862 | struct hdmi_spec *spec; | 1848 | struct hdmi_spec *spec; |
1863 | 1849 | int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID); | |
1864 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 1850 | if (err < 0) |
1865 | if (spec == NULL) | 1851 | return err; |
1866 | return -ENOMEM; | 1852 | spec = codec->spec; |
1867 | 1853 | spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare; | |
1868 | codec->spec = spec; | ||
1869 | |||
1870 | spec->multiout.num_dacs = 0; /* no analog */ | ||
1871 | spec->multiout.max_channels = 2; | ||
1872 | spec->multiout.dig_out_nid = ATIHDMI_CVT_NID; | ||
1873 | spec->num_cvts = 1; | ||
1874 | spec->num_pins = 1; | ||
1875 | spec->cvts[0].cvt_nid = ATIHDMI_CVT_NID; | ||
1876 | spec->pins[0].pin_nid = ATIHDMI_PIN_NID; | ||
1877 | spec->pcm_playback = &atihdmi_pcm_digital_playback; | ||
1878 | |||
1879 | codec->patch_ops = atihdmi_patch_ops; | ||
1880 | |||
1881 | return 0; | 1854 | return 0; |
1882 | } | 1855 | } |
1883 | 1856 | ||
@@ -1885,46 +1858,12 @@ static int patch_atihdmi(struct hda_codec *codec) | |||
1885 | #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */ | 1858 | #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */ |
1886 | #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */ | 1859 | #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */ |
1887 | 1860 | ||
1888 | static const struct hda_codec_ops via_hdmi_patch_ops = { | ||
1889 | .build_controls = simple_playback_build_controls, | ||
1890 | .build_pcms = simple_playback_build_pcms, | ||
1891 | .init = simple_playback_init, | ||
1892 | .free = simple_playback_free, | ||
1893 | .unsol_event = simple_hdmi_unsol_event, | ||
1894 | }; | ||
1895 | |||
1896 | static struct hda_pcm_stream via_hdmi_digital_playback = { | ||
1897 | .substreams = 1, | ||
1898 | .channels_min = 2, | ||
1899 | .channels_max = 2, | ||
1900 | .nid = VIAHDMI_CVT_NID, /* NID to query formats and rates*/ | ||
1901 | .ops = { | ||
1902 | .open = simple_playback_pcm_open, | ||
1903 | .close = simple_playback_pcm_close, | ||
1904 | .prepare = simple_playback_pcm_prepare | ||
1905 | }, | ||
1906 | }; | ||
1907 | |||
1908 | static int patch_via_hdmi(struct hda_codec *codec) | 1861 | static int patch_via_hdmi(struct hda_codec *codec) |
1909 | { | 1862 | { |
1910 | struct hdmi_spec *spec; | 1863 | int err = patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID); |
1911 | 1864 | if (err < 0) | |
1912 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 1865 | return err; |
1913 | if (spec == NULL) | 1866 | codec->patch_ops.unsol_event = simple_hdmi_unsol_event; |
1914 | return -ENOMEM; | ||
1915 | |||
1916 | spec->multiout.num_dacs = 0; /* no analog */ | ||
1917 | spec->multiout.max_channels = 2; | ||
1918 | spec->multiout.dig_out_nid = VIAHDMI_CVT_NID; /* pure-digital case */ | ||
1919 | spec->num_cvts = 1; | ||
1920 | spec->num_pins = 1; | ||
1921 | spec->cvts[0].cvt_nid = VIAHDMI_CVT_NID; | ||
1922 | spec->pins[0].pin_nid = VIAHDMI_PIN_NID; | ||
1923 | spec->pcm_playback = &via_hdmi_digital_playback; | ||
1924 | |||
1925 | codec->spec = spec; | ||
1926 | codec->patch_ops = via_hdmi_patch_ops; | ||
1927 | |||
1928 | return 0; | 1867 | return 0; |
1929 | } | 1868 | } |
1930 | 1869 | ||