Skip to content

Commit 154867c

Browse files
dgreidtiwai
authored andcommitted
ALSA: hda - Move codec create to hda_controller
Codec creation and stream initialization can be shared between hda_intel and hda platform drivers. Move it and the static functions it depends on to hda_controller.c. Signed-off-by: Dylan Reid <dgreid@chromium.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent f0b1df8 commit 154867c

3 files changed

Lines changed: 235 additions & 248 deletions

File tree

‎sound/pci/hda/hda_controller.c‎

Lines changed: 227 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/interrupt.h>
2626
#include <linux/kernel.h>
2727
#include <linux/module.h>
28+
#include <linux/pm_runtime.h>
2829
#include <linux/slab.h>
2930
#include <sound/core.h>
3031
#include <sound/initval.h>
@@ -1022,7 +1023,6 @@ int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
10221023
pcm->dev = &codec->dev;
10231024
return 0;
10241025
}
1025-
EXPORT_SYMBOL_GPL(azx_attach_pcm_stream);
10261026

10271027
/*
10281028
* CORB / RIRB interface
@@ -1380,7 +1380,7 @@ static unsigned int azx_single_get_response(struct hda_bus *bus,
13801380
*/
13811381

13821382
/* send a command */
1383-
int azx_send_cmd(struct hda_bus *bus, unsigned int val)
1383+
static int azx_send_cmd(struct hda_bus *bus, unsigned int val)
13841384
{
13851385
struct azx *chip = bus->private_data;
13861386

@@ -1395,7 +1395,7 @@ int azx_send_cmd(struct hda_bus *bus, unsigned int val)
13951395
EXPORT_SYMBOL_GPL(azx_send_cmd);
13961396

13971397
/* get a response */
1398-
unsigned int azx_get_response(struct hda_bus *bus,
1398+
static unsigned int azx_get_response(struct hda_bus *bus,
13991399
unsigned int addr)
14001400
{
14011401
struct azx *chip = bus->private_data;
@@ -1420,9 +1420,9 @@ azx_get_dsp_loader_dev(struct azx *chip)
14201420
return &chip->azx_dev[chip->playback_index_offset];
14211421
}
14221422

1423-
int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1424-
unsigned int byte_size,
1425-
struct snd_dma_buffer *bufp)
1423+
static int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
1424+
unsigned int byte_size,
1425+
struct snd_dma_buffer *bufp)
14261426
{
14271427
u32 *bdl;
14281428
struct azx *chip = bus->private_data;
@@ -1480,9 +1480,8 @@ int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
14801480
dsp_unlock(azx_dev);
14811481
return err;
14821482
}
1483-
EXPORT_SYMBOL_GPL(azx_load_dsp_prepare);
14841483

1485-
void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
1484+
static void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
14861485
{
14871486
struct azx *chip = bus->private_data;
14881487
struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
@@ -1493,10 +1492,9 @@ void azx_load_dsp_trigger(struct hda_bus *bus, bool start)
14931492
azx_stream_stop(chip, azx_dev);
14941493
azx_dev->running = start;
14951494
}
1496-
EXPORT_SYMBOL_GPL(azx_load_dsp_trigger);
14971495

1498-
void azx_load_dsp_cleanup(struct hda_bus *bus,
1499-
struct snd_dma_buffer *dmab)
1496+
static void azx_load_dsp_cleanup(struct hda_bus *bus,
1497+
struct snd_dma_buffer *dmab)
15001498
{
15011499
struct azx *chip = bus->private_data;
15021500
struct azx_dev *azx_dev = azx_get_dsp_loader_dev(chip);
@@ -1523,7 +1521,6 @@ void azx_load_dsp_cleanup(struct hda_bus *bus,
15231521
spin_unlock_irq(&chip->reg_lock);
15241522
dsp_unlock(azx_dev);
15251523
}
1526-
EXPORT_SYMBOL_GPL(azx_load_dsp_cleanup);
15271524
#endif /* CONFIG_SND_HDA_DSP_LOADER */
15281525

15291526
int azx_alloc_stream_pages(struct azx *chip)
@@ -1746,6 +1743,7 @@ void azx_stop_chip(struct azx *chip)
17461743

17471744
chip->initialized = 0;
17481745
}
1746+
EXPORT_SYMBOL_GPL(azx_stop_chip);
17491747

17501748
/*
17511749
* interrupt handler
@@ -1812,5 +1810,222 @@ irqreturn_t azx_interrupt(int irq, void *dev_id)
18121810
}
18131811
EXPORT_SYMBOL_GPL(azx_interrupt);
18141812

1813+
/*
1814+
* Codec initerface
1815+
*/
1816+
1817+
/*
1818+
* Probe the given codec address
1819+
*/
1820+
static int probe_codec(struct azx *chip, int addr)
1821+
{
1822+
unsigned int cmd = (addr << 28) | (AC_NODE_ROOT << 20) |
1823+
(AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
1824+
unsigned int res;
1825+
1826+
mutex_lock(&chip->bus->cmd_mutex);
1827+
chip->probing = 1;
1828+
azx_send_cmd(chip->bus, cmd);
1829+
res = azx_get_response(chip->bus, addr);
1830+
chip->probing = 0;
1831+
mutex_unlock(&chip->bus->cmd_mutex);
1832+
if (res == -1)
1833+
return -EIO;
1834+
dev_dbg(chip->card->dev, "codec #%d probed OK\n", addr);
1835+
return 0;
1836+
}
1837+
1838+
static void azx_bus_reset(struct hda_bus *bus)
1839+
{
1840+
struct azx *chip = bus->private_data;
1841+
1842+
bus->in_reset = 1;
1843+
azx_stop_chip(chip);
1844+
azx_init_chip(chip, 1);
1845+
#ifdef CONFIG_PM
1846+
if (chip->initialized) {
1847+
struct azx_pcm *p;
1848+
list_for_each_entry(p, &chip->pcm_list, list)
1849+
snd_pcm_suspend_all(p->pcm);
1850+
snd_hda_suspend(chip->bus);
1851+
snd_hda_resume(chip->bus);
1852+
}
1853+
#endif
1854+
bus->in_reset = 0;
1855+
}
1856+
1857+
#ifdef CONFIG_PM
1858+
/* power-up/down the controller */
1859+
static void azx_power_notify(struct hda_bus *bus, bool power_up)
1860+
{
1861+
struct azx *chip = bus->private_data;
1862+
1863+
if (!(chip->driver_caps & AZX_DCAPS_PM_RUNTIME))
1864+
return;
1865+
1866+
if (power_up)
1867+
pm_runtime_get_sync(chip->card->dev);
1868+
else
1869+
pm_runtime_put_sync(chip->card->dev);
1870+
}
1871+
#endif
1872+
1873+
static int get_jackpoll_interval(struct azx *chip)
1874+
{
1875+
int i;
1876+
unsigned int j;
1877+
1878+
if (!chip->jackpoll_ms)
1879+
return 0;
1880+
1881+
i = chip->jackpoll_ms[chip->dev_index];
1882+
if (i == 0)
1883+
return 0;
1884+
if (i < 50 || i > 60000)
1885+
j = 0;
1886+
else
1887+
j = msecs_to_jiffies(i);
1888+
if (j == 0)
1889+
dev_warn(chip->card->dev,
1890+
"jackpoll_ms value out of range: %d\n", i);
1891+
return j;
1892+
}
1893+
1894+
/* Codec initialization */
1895+
int azx_codec_create(struct azx *chip, const char *model,
1896+
unsigned int max_slots,
1897+
int *power_save_to)
1898+
{
1899+
struct hda_bus_template bus_temp;
1900+
int c, codecs, err;
1901+
1902+
memset(&bus_temp, 0, sizeof(bus_temp));
1903+
bus_temp.private_data = chip;
1904+
bus_temp.modelname = model;
1905+
bus_temp.pci = chip->pci;
1906+
bus_temp.ops.command = azx_send_cmd;
1907+
bus_temp.ops.get_response = azx_get_response;
1908+
bus_temp.ops.attach_pcm = azx_attach_pcm_stream;
1909+
bus_temp.ops.bus_reset = azx_bus_reset;
1910+
#ifdef CONFIG_PM
1911+
bus_temp.power_save = power_save_to;
1912+
bus_temp.ops.pm_notify = azx_power_notify;
1913+
#endif
1914+
#ifdef CONFIG_SND_HDA_DSP_LOADER
1915+
bus_temp.ops.load_dsp_prepare = azx_load_dsp_prepare;
1916+
bus_temp.ops.load_dsp_trigger = azx_load_dsp_trigger;
1917+
bus_temp.ops.load_dsp_cleanup = azx_load_dsp_cleanup;
1918+
#endif
1919+
1920+
err = snd_hda_bus_new(chip->card, &bus_temp, &chip->bus);
1921+
if (err < 0)
1922+
return err;
1923+
1924+
if (chip->driver_caps & AZX_DCAPS_RIRB_DELAY) {
1925+
dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
1926+
chip->bus->needs_damn_long_delay = 1;
1927+
}
1928+
1929+
codecs = 0;
1930+
if (!max_slots)
1931+
max_slots = AZX_DEFAULT_CODECS;
1932+
1933+
/* First try to probe all given codec slots */
1934+
for (c = 0; c < max_slots; c++) {
1935+
if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1936+
if (probe_codec(chip, c) < 0) {
1937+
/* Some BIOSen give you wrong codec addresses
1938+
* that don't exist
1939+
*/
1940+
dev_warn(chip->card->dev,
1941+
"Codec #%d probe error; disabling it...\n", c);
1942+
chip->codec_mask &= ~(1 << c);
1943+
/* More badly, accessing to a non-existing
1944+
* codec often screws up the controller chip,
1945+
* and disturbs the further communications.
1946+
* Thus if an error occurs during probing,
1947+
* better to reset the controller chip to
1948+
* get back to the sanity state.
1949+
*/
1950+
azx_stop_chip(chip);
1951+
azx_init_chip(chip, 1);
1952+
}
1953+
}
1954+
}
1955+
1956+
/* AMD chipsets often cause the communication stalls upon certain
1957+
* sequence like the pin-detection. It seems that forcing the synced
1958+
* access works around the stall. Grrr...
1959+
*/
1960+
if (chip->driver_caps & AZX_DCAPS_SYNC_WRITE) {
1961+
dev_dbg(chip->card->dev, "Enable sync_write for stable communication\n");
1962+
chip->bus->sync_write = 1;
1963+
chip->bus->allow_bus_reset = 1;
1964+
}
1965+
1966+
/* Then create codec instances */
1967+
for (c = 0; c < max_slots; c++) {
1968+
if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1969+
struct hda_codec *codec;
1970+
err = snd_hda_codec_new(chip->bus, c, &codec);
1971+
if (err < 0)
1972+
continue;
1973+
codec->jackpoll_interval = get_jackpoll_interval(chip);
1974+
codec->beep_mode = chip->beep_mode;
1975+
codecs++;
1976+
}
1977+
}
1978+
if (!codecs) {
1979+
dev_err(chip->card->dev, "no codecs initialized\n");
1980+
return -ENXIO;
1981+
}
1982+
return 0;
1983+
}
1984+
EXPORT_SYMBOL_GPL(azx_codec_create);
1985+
1986+
/* configure each codec instance */
1987+
int azx_codec_configure(struct azx *chip)
1988+
{
1989+
struct hda_codec *codec;
1990+
list_for_each_entry(codec, &chip->bus->codec_list, list) {
1991+
snd_hda_codec_configure(codec);
1992+
}
1993+
return 0;
1994+
}
1995+
EXPORT_SYMBOL_GPL(azx_codec_configure);
1996+
1997+
/* mixer creation - all stuff is implemented in hda module */
1998+
int azx_mixer_create(struct azx *chip)
1999+
{
2000+
return snd_hda_build_controls(chip->bus);
2001+
}
2002+
EXPORT_SYMBOL_GPL(azx_mixer_create);
2003+
2004+
2005+
/* initialize SD streams */
2006+
int azx_init_stream(struct azx *chip)
2007+
{
2008+
int i;
2009+
2010+
/* initialize each stream (aka device)
2011+
* assign the starting bdl address to each stream (device)
2012+
* and initialize
2013+
*/
2014+
for (i = 0; i < chip->num_streams; i++) {
2015+
struct azx_dev *azx_dev = &chip->azx_dev[i];
2016+
azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
2017+
/* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
2018+
azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
2019+
/* int mask: SDI0=0x01, SDI1=0x02, ... SDO3=0x80 */
2020+
azx_dev->sd_int_sta_mask = 1 << i;
2021+
/* stream tag: must be non-zero and unique */
2022+
azx_dev->index = i;
2023+
azx_dev->stream_tag = i + 1;
2024+
}
2025+
2026+
return 0;
2027+
}
2028+
EXPORT_SYMBOL_GPL(azx_init_stream);
2029+
18152030
MODULE_LICENSE("GPL");
18162031
MODULE_DESCRIPTION("Common HDA driver funcitons");

‎sound/pci/hda/hda_controller.h‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "hda_priv.h"
2222

2323
/* PCM setup */
24-
int azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec,
25-
struct hda_pcm *cpcm);
2624
static inline struct azx_dev *get_azx_dev(struct snd_pcm_substream *substream)
2725
{
2826
return substream->runtime->private_data;
@@ -34,30 +32,22 @@ unsigned int azx_get_position(struct azx *chip,
3432
/* Stream control. */
3533
void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev);
3634

37-
#ifdef CONFIG_SND_HDA_DSP_LOADER
38-
int azx_load_dsp_prepare(struct hda_bus *bus, unsigned int format,
39-
unsigned int byte_size,
40-
struct snd_dma_buffer *bufp);
41-
void azx_load_dsp_trigger(struct hda_bus *bus, bool start);
42-
void azx_load_dsp_cleanup(struct hda_bus *bus,
43-
struct snd_dma_buffer *dmab);
44-
#endif
45-
4635
/* Allocation functions. */
4736
int azx_alloc_stream_pages(struct azx *chip);
4837
void azx_free_stream_pages(struct azx *chip);
4938

50-
/*
51-
* CORB / RIRB interface
52-
*/
53-
int azx_send_cmd(struct hda_bus *bus, unsigned int val);
54-
unsigned int azx_get_response(struct hda_bus *bus,
55-
unsigned int addr);
56-
5739
/* Low level azx interface */
5840
void azx_init_chip(struct azx *chip, int full_reset);
5941
void azx_stop_chip(struct azx *chip);
6042
void azx_enter_link_reset(struct azx *chip);
6143
irqreturn_t azx_interrupt(int irq, void *dev_id);
6244

45+
/* Codec interface */
46+
int azx_codec_create(struct azx *chip, const char *model,
47+
unsigned int max_slots,
48+
int *power_save_to);
49+
int azx_codec_configure(struct azx *chip);
50+
int azx_mixer_create(struct azx *chip);
51+
int azx_init_stream(struct azx *chip);
52+
6353
#endif /* __SOUND_HDA_CONTROLLER_H */

0 commit comments

Comments
 (0)