Commit 79dda75a authored by Takashi Iwai's avatar Takashi Iwai

ALSA: x86: Pass snd_intelhad object to helpers

For reducing the global variable reference, keep snd_intelhad object
in the context and pass it to each helper.  It's a preliminary change
for further cleanup.

This also includes the simplification of the probe procedure: the LPE
platform driver directly gets the created snd_intelhad object by
hdmi_audio_probe(), and passes it to each helper and destructor,
hdmi_audio_remove().  The hdmi_audio_probe() function doesn't call the
back-registration any longer, which is fairly useless.  The LPE
platform driver initializes the stuff instead at the right place, and
calls the wq after the object creation in the probe function itself.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 6f9ecc76
This diff is collapsed.
......@@ -39,6 +39,8 @@
#include <sound/pcm.h>
#include "intel_hdmi_lpe_audio.h"
struct platform_device;
#define PCM_INDEX 0
#define MAX_PB_STREAMS 1
#define MAX_CAP_STREAMS 0
......@@ -168,13 +170,19 @@ void snd_intelhad_handle_underrun(struct snd_intelhad *intelhaddata);
/* Register access functions */
int had_get_hwstate(struct snd_intelhad *intelhaddata);
int had_get_caps(enum had_caps_list query_element, void *capabilties);
int had_set_caps(enum had_caps_list set_element, void *capabilties);
int had_read_register(u32 reg_addr, u32 *data);
int had_write_register(u32 reg_addr, u32 data);
int had_read_modify(u32 reg_addr, u32 data, u32 mask);
int hdmi_audio_probe(void *devptr);
int hdmi_audio_remove(void *pdev);
int had_get_caps(struct snd_intelhad *intelhaddata,
enum had_caps_list query_element, void *capabilties);
int had_set_caps(struct snd_intelhad *intelhaddata,
enum had_caps_list set_element, void *capabilties);
int had_read_register(struct snd_intelhad *intelhaddata,
u32 reg_addr, u32 *data);
int had_write_register(struct snd_intelhad *intelhaddata,
u32 reg_addr, u32 data);
int had_read_modify(struct snd_intelhad *intelhaddata,
u32 reg_addr, u32 data, u32 mask);
int hdmi_audio_probe(struct platform_device *devptr,
struct snd_intelhad **had_ret);
int hdmi_audio_remove(struct snd_intelhad *intelhaddata);
#endif /* _INTEL_HDMI_AUDIO_ */
......@@ -137,8 +137,8 @@ int hdmi_audio_suspend(void *haddata)
* caps = HDMI_AUDIO_UNDERRUN | HDMI_AUDIO_BUFFER_DONE;
*/
caps = HDMI_AUDIO_BUFFER_DONE;
had_set_caps(HAD_SET_DISABLE_AUDIO_INT, &caps);
had_set_caps(HAD_SET_DISABLE_AUDIO, NULL);
had_set_caps(intelhaddata, HAD_SET_DISABLE_AUDIO_INT, &caps);
had_set_caps(intelhaddata, HAD_SET_DISABLE_AUDIO, NULL);
pr_debug("Exit:%s", __func__);
return retval;
}
......@@ -187,8 +187,8 @@ int hdmi_audio_resume(void *haddata)
* caps = HDMI_AUDIO_UNDERRUN | HDMI_AUDIO_BUFFER_DONE;
*/
caps = HDMI_AUDIO_BUFFER_DONE;
retval = had_set_caps(HAD_SET_ENABLE_AUDIO_INT, &caps);
retval = had_set_caps(HAD_SET_ENABLE_AUDIO, NULL);
retval = had_set_caps(intelhaddata, HAD_SET_ENABLE_AUDIO_INT, &caps);
retval = had_set_caps(intelhaddata, HAD_SET_ENABLE_AUDIO, NULL);
pr_debug("Exit:%s", __func__);
return retval;
}
......@@ -221,11 +221,12 @@ static inline int had_chk_intrmiss(struct snd_intelhad *intelhaddata,
buf_size = intelhaddata->buf_info[j].buf_size;
buf_addr = intelhaddata->buf_info[j].buf_addr;
had_write_register(AUD_BUF_A_LENGTH +
(j * HAD_REG_WIDTH), buf_size);
had_write_register(
AUD_BUF_A_ADDR+(j * HAD_REG_WIDTH),
(buf_addr | BIT(0) | BIT(1)));
had_write_register(intelhaddata,
AUD_BUF_A_LENGTH +
(j * HAD_REG_WIDTH), buf_size);
had_write_register(intelhaddata,
AUD_BUF_A_ADDR+(j * HAD_REG_WIDTH),
(buf_addr | BIT(0) | BIT(1)));
}
buf_id = buf_id % 4;
spin_lock_irqsave(&intelhaddata->had_spinlock, flag_irqs);
......@@ -300,14 +301,17 @@ int had_process_buffer_done(struct snd_intelhad *intelhaddata)
}
/*Reprogram the registers with addr and length*/
had_write_register(AUD_BUF_A_LENGTH +
(buf_id * HAD_REG_WIDTH), buf_size);
had_write_register(AUD_BUF_A_ADDR+(buf_id * HAD_REG_WIDTH),
intelhaddata->buf_info[buf_id].buf_addr|
BIT(0) | BIT(1));
had_read_register(AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH),
&len);
had_write_register(intelhaddata,
AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH),
buf_size);
had_write_register(intelhaddata,
AUD_BUF_A_ADDR + (buf_id * HAD_REG_WIDTH),
intelhaddata->buf_info[buf_id].buf_addr |
BIT(0) | BIT(1));
had_read_register(intelhaddata,
AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH),
&len);
pr_debug("%s:Enabled buf[%d]\n", __func__, buf_id);
/* In case of actual data,
......@@ -427,8 +431,10 @@ int had_process_hot_unplug(struct snd_intelhad *intelhaddata)
} else {
/* Disable Audio */
caps = HDMI_AUDIO_BUFFER_DONE;
retval = had_set_caps(HAD_SET_DISABLE_AUDIO_INT, &caps);
retval = had_set_caps(HAD_SET_DISABLE_AUDIO, NULL);
retval = had_set_caps(intelhaddata, HAD_SET_DISABLE_AUDIO_INT,
&caps);
retval = had_set_caps(intelhaddata, HAD_SET_DISABLE_AUDIO,
NULL);
snd_intelhad_enable_audio(
intelhaddata->stream_info.had_substream, 0);
}
......
......@@ -45,7 +45,7 @@ struct hdmi_lpe_audio_ctx {
int irq;
void __iomem *mmio_start;
had_event_call_back had_event_callbacks;
void *had_pvt_data;
struct snd_intelhad *had;
int tmds_clock_speed;
bool dp_output;
int link_rate;
......@@ -103,7 +103,7 @@ bool mid_hdmi_audio_is_busy(void *ddev)
}
hdmi_audio_event.type = HAD_EVENT_QUERY_IS_AUDIO_BUSY;
hdmi_audio_busy = hdmi_audio_query(ctx->had_pvt_data, hdmi_audio_event);
hdmi_audio_busy = hdmi_audio_query(ctx->had, hdmi_audio_event);
return hdmi_audio_busy != 0;
}
......@@ -119,8 +119,7 @@ void mid_hdmi_audio_signal_event(enum had_event_type event)
* event handlers to avoid races
*/
if (ctx->had_event_callbacks)
(*ctx->had_event_callbacks)(event,
ctx->had_pvt_data);
(*ctx->had_event_callbacks)(event, ctx->had);
}
/*
......@@ -276,27 +275,6 @@ static void _had_wq(struct work_struct *work)
mid_hdmi_audio_signal_event(HAD_EVENT_HOT_PLUG);
}
int mid_hdmi_audio_register(void *had_data)
{
struct hdmi_lpe_audio_ctx *ctx;
ctx = platform_get_drvdata(hlpe_pdev);
dev_dbg(&hlpe_pdev->dev, "%s: called\n", __func__);
ctx->had_pvt_data = had_data;
/* The Audio driver is loading now and we need to notify
* it if there is an HDMI device attached
*/
INIT_WORK(&ctx->hdmi_audio_wq, _had_wq);
dev_dbg(&hlpe_pdev->dev, "%s: Scheduling HDMI audio work queue\n",
__func__);
schedule_work(&ctx->hdmi_audio_wq);
return 0;
}
static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
{
u32 audio_stat, audio_reg;
......@@ -460,6 +438,7 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
dev_dbg(&hlpe_pdev->dev, "hdmi lpe audio: irq num = %d\n", irq);
ctx->mmio_start = mmio_start;
ctx->tmds_clock_speed = DIS_SAMPLE_RATE_148_5;
INIT_WORK(&ctx->hdmi_audio_wq, _had_wq);
if (pci_dev_present(cherryview_ids))
dev_dbg(&hlpe_pdev->dev, "%s: Cherrytrail LPE - Detected\n",
......@@ -483,9 +462,16 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, ctx);
ret = hdmi_audio_probe((void *)pdev);
ret = hdmi_audio_probe(pdev, &ctx->had);
dev_dbg(&hlpe_pdev->dev, "hdmi lpe audio: setting pin eld notify callback\n");
/* The Audio driver is loading now and we need to notify
* it if there is an HDMI device attached
*/
dev_dbg(&hlpe_pdev->dev, "%s: Scheduling HDMI audio work queue\n",
__func__);
schedule_work(&ctx->hdmi_audio_wq);
spin_lock_irqsave(&pdata->lpe_audio_slock, flag_irq);
pdata->notify_audio_lpe = notify_audio_lpe;
if (pdata->notify_pending) {
......@@ -507,14 +493,13 @@ static int hdmi_lpe_audio_probe(struct platform_device *pdev)
*/
static int hdmi_lpe_audio_remove(struct platform_device *pdev)
{
struct hdmi_lpe_audio_ctx *ctx;
struct hdmi_lpe_audio_ctx *ctx = platform_get_drvdata(pdev);
dev_dbg(&hlpe_pdev->dev, "Enter %s\n", __func__);
hdmi_audio_remove(pdev);
hdmi_audio_remove(ctx->had);
/* get context, release resources */
ctx = platform_get_drvdata(pdev);
/* release resources */
iounmap(ctx->mmio_start);
free_irq(ctx->irq, NULL);
kfree(ctx);
......@@ -529,7 +514,7 @@ static int hdmi_lpe_audio_suspend(struct platform_device *pdev,
dev_dbg(&pdev->dev, "%s: hlpe_state %d", __func__, hlpe_state);
/* HDMI is not connected, assuming audio device is suspended already */
if (hlpe_state != hdmi_connector_status_disconnected)
hdmi_audio_suspend(ctx->had_pvt_data);
hdmi_audio_suspend(ctx->had);
return 0;
}
......@@ -540,7 +525,7 @@ static int hdmi_lpe_audio_resume(struct platform_device *pdev)
dev_dbg(&pdev->dev, "%s: hlpe_state %d", __func__, hlpe_state);
/* HDMI is not connected, there is no need to resume audio device */
if (hlpe_state != hdmi_connector_status_disconnected)
hdmi_audio_resume(ctx->had_pvt_data);
hdmi_audio_resume(ctx->had);
return 0;
}
......
......@@ -648,7 +648,6 @@ struct hdmi_audio_event {
bool mid_hdmi_audio_is_busy(void *dev);
void mid_hdmi_audio_signal_event(enum had_event_type event);
int mid_hdmi_audio_setup(had_event_call_back audio_callbacks);
int mid_hdmi_audio_register(void *had_data);
int mid_hdmi_audio_read(u32 reg, u32 *val);
int mid_hdmi_audio_write(u32 reg, u32 val);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment