Commit Graph

140 Commits

Author SHA1 Message Date
Arnd Bergmann 4b49f0f7ee ALSA: x86: hdmi: select CONFIG_SND_PCM
The newly added driver uses the PCM helpers and fails to link if they are disabled:

sound/built-in.o: In function `hdmi_lpe_audio_runtime_suspend':
intel_hdmi_audio.c:(.text+0x15906): undefined reference to `snd_pcm_suspend'
sound/built-in.o: In function `had_pcm_hw_params':
intel_hdmi_audio.c:(.text+0x15ac7): undefined reference to `snd_pcm_lib_malloc_pages'
sound/built-in.o: In function `had_pcm_open':
intel_hdmi_audio.c:(.text+0x15d49): undefined reference to `snd_pcm_hw_constraint_integer'

This uses a Kconfig 'select' statement to make sure they are enabled.

Fixes: 5dab11d897 ("ALSA: x86: hdmi: Add audio support for BYT and CHT")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-21 23:39:14 +01:00
Takashi Iwai 0b6b524f39 ALSA: x86: Don't enable runtime PM as default
Unlike HSW and newer, BYT/CHT devices have no fine control of audio
power domain in i915 side.  Since there is little gain by runtime PM
on BYT/CHT, so far, this commit removes the pm_runtime_enable() call
as default.

User who still wants the runtime PM may adjust the corresponding
sysfs files (power/control and power/autosuspend_delay_ms)
appropriately, of course.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-21 22:23:14 +01:00
Takashi Iwai 3002b9fb7c ALSA: x86: Use runtime PM autosuspend
This patch adds a few lines to the driver to use autosuspend for the
runtime PM.  It'll become useful with the combination of the keep-link
feature.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-21 22:17:45 +01:00
Takashi Iwai b1ef30e5ed ALSA: x86: Don't bail out from PCM ops when disconnected
Currently the driver returns -ENODEV when the monitor is disconnected.
But PA alsa module doesn't like this and it starts playing Juliet,
kills itself as if it were a fatal tragedy.

Since we protect the whole read/write at disconnection, just allow the
PCM accesses even during disconnection.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:44 +01:00
Takashi Iwai 2d42c033ae ALSA: x86: Minor code rearrangement
Put the stuff in the right order; notification should be at the end of
the action.

Also dropped a superfluous debug print and incorrect comments.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:44 +01:00
Takashi Iwai be9a2e933e ALSA: x86: Stop the stream when buffer is processed after disconnection
This shouldn't happen, but just to be sure...

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:43 +01:00
Takashi Iwai 28ed125b9a ALSA: x86: Avoid register accesses during disconnection
It seems that accessing registers during disconnection often leads to
the GPU pipe error.  The original driver had a similar check in the
past, but it was lost through refactoring.  Now put a connection check
in the register access functions.

One exception is the irq handler: it still needs to access the raw
register even while disconnected, because it has to read and write to
ACK the irq mask.  Although the irq shouldn't be raised while
disconnected (the stream should have been disabled), let's make it
safer for now.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:43 +01:00
Takashi Iwai a72ccfbad7 ALSA: x86: Don't return an error from chmap ctl at disconnected
It's not wise to return an error at info/get callback when
disconnected, which happens at any time.
The chmap ctl is supposed to fill zero for such a case, instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:43 +01:00
Takashi Iwai 18353192b8 ALSA: x86: Fix memory leak in had_build_channel_allocation_map()
The previously allocated chmap has to be released before setting the
new one.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:42 +01:00
Takashi Iwai 5def90196b ALSA: x86: Use snd_pcm_stop_xrun() for connection / disconnection paths
This seems more friendly to user-space, as it's notified at least as
an error, instead of forcibly moving the PCM state to SETUP out of
sudden.

Moreover, snd_pcm_stop() needs an extra PCM spinlock I forgot, while
snd_pcm_stop_xrun() takes the spinlock by itself.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:42 +01:00
Takashi Iwai b9bacf275c ALSA: x86: Implement jack control
This patch implements a jack interface for notifying HDMI/DP
connection.  PA listens to this, so it can handle the monitor
connection more gracefully.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-16 09:22:42 +01:00
Takashi Iwai df42cb499e ALSA: x86: Drop unused stream.running field
The pcm_stream_info.running field is only set in the PCM trigger
callback but never referred, thus it can be safely removed.

Also, properly cover the spinlock in both the trigger START and STOP
to protect had_enable_audio() calls.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-13 14:51:13 +01:00
Takashi Iwai e2acecf2c8 ALSA: x86: Handle reset at prepare callback
Currently the driver handles some reset procedure at the trigger STOP
and the underrun functions, where both are executed in the interrupt
context.  Especially the underrun function has a sync-loop to clear
the UNDERRUN status bit, and this is supposed to be one of plausible
causes of GPU hangup.

Since the job to be done in the interrupt handler should be minimum,
we move the reset function out of trigger and underrun, and push it
into the prepare (and hw_free) callbacks instead.  Here a new flag,
need_reset, is introduced to indicate the requirement of the reset
procedure.  This is for avoiding the multiple resets when PCM prepare
is called sequentially.

Also in the UNDERRUN bit-clear sync loop, take a longer pause to be in
the safer side.  Taking a longer delay is no longer a problem now
because we're running in the normal context.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-13 14:48:43 +01:00
Takashi Iwai 3fe2cf7eb2 ALSA: x86: Support S16 format
Now we support S16 PCM format in addition.  For this, we need to set
packet_mode=1 in AUD_CONFIG register.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-10 10:21:47 +01:00
Takashi Iwai 85bd8748ca ALSA: x86: Support S32 format
The hardware has the support for the left-aligned 24bit format in
32bit packet.  This corresponds to S32 format in ALSA.  We need to set
the msbits restriction as well to inform user-space that only MSB
24bit are available.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-10 10:21:45 +01:00
Takashi Iwai e8de9859e4 ALSA: x86: Allow no-period-wakeup setup
In the current implementation, the driver may update the BDs even at
PCM pointer callback.  This allows us to skip the period interrupt
effectively.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-10 10:21:44 +01:00
Takashi Iwai 8d48c0163d ALSA: x86: Allow single period PCM operation
This is an implementation of PCM streaming with only 1 period.
Since the hardware requires the refresh of BDs after each BD
processing finishes, we'd need at least two BDs.  The trick is that
both BDs point to the same content: the address of the PCM buffer
head, and the whole buffer size.  Then it loops over to the whole
buffer again after it finished once.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-10 10:21:42 +01:00
Takashi Iwai a9ebdd0ef2 ALSA: x86: Don't pass SNDRV_PCM_INFO_BATCH flag
The PCM engine on LPE audio isn't like a batch-style process any
longer, but rather it deals with the standard ring buffer.  Remove the
BATCH info flag so that PA can handle the buffer in timer-sched mode.

Similarly, the DOUBLE flag is also superfluous.  Drop both bits.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-10 10:21:41 +01:00
Takashi Iwai 40ce4b5d70 ALSA: x86: Cache AUD_CONFIG register value
At enabling the audio, we modify AUD_CONFIG register bit 0.  So far,
it does read-modify-write procedure with a special hack for the
channel bits due to the silicon bug.  But we can optimize it by
remembering the AUD_CONFIG register value privately.  This simplifies
the things a lot.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 16:27:41 +01:00
Takashi Iwai 77531beeb9 ALSA: x86: Rearrange defines
We have two header files and everything is mixed up chaotically.
Move the chip-specific definitions like the hardware registers to
intel_hdmi_lpe_audio.h, and the rest, the implementation specific
stuff into intel_hdmi_audio.h.

In addition, put some more comments to the register fields, and fix
the incorrect name prefix for AUD_HDMI_STATUS bits, too.

The whole changes are merely a code shuffling, and there is no
functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 15:12:37 +01:00
Arnd Bergmann 1df989242d ALSA: x86: mark hdmi suspend/resume functions as __maybe_unused
The two functions are unused when CONFIG_PM_SLEEP is disabled:

sound/x86/intel_hdmi_audio.c:1633:12: error: 'hdmi_lpe_audio_resume' defined but not used [-Werror=unused-function]
sound/x86/intel_hdmi_audio.c:1622:12: error: 'hdmi_lpe_audio_suspend' defined but not used [-Werror=unused-function]

Marking them as __maybe_unused avoids the warning without introducing an
ugly #ifdef.

Fixes: 182cdf23db ("ALSA: x86: Implement runtime PM")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 15:05:50 +01:00
Takashi Iwai 873ab03575 ALSA: x86: Fix driver name string overflow
The driver sets card->driver name string over its size (16 bytes).
Shorten the name string to fit with it.

Also, set more verbose string to card->shortname and ->longname.
This doesn't have to be identical with card->driver at all.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 12:33:20 +01:00
Takashi Iwai 075a1d46be ALSA: x86: Rename had_enable_audio_int() to had_ack_irqs()
had_enable_audio_int() came from the LPE audio shell set_caps
callback with ENABLE_INT and DISABLE_INT caps.  I interpreted as these
correspond to enabling / disabling the audio interface, but the actual
implementation is only to clear (send ACK) to both BUFFER_DONE and
BUFFER_UNDERRUN interrupts unconditionally.  And, there is no
counterpart, DISABLE_INT, code at all.

For avoiding the further misunderstanding, rename the function to the
more fitting one, had_ack_irqs(), and drop the calls with enable=false
in allover places.  There is no functional changes at all.

After this patch, there is only one caller at the PCM trigger start.
Then it's doubtful whether this call is still really needed or not; I
bet it not, but let's stay in the safer side for now and keep it as
was.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 09:43:01 +01:00
Takashi Iwai 3e21a76ca3 ALSA: x86: Drop suspicious U24 format support
U24 format is declared to be supported by the driver, but this looks
really doubtful, as there is no corresponding code.  Better to drop
it.  This format is very uncommon, so there should be practically no
impact by this change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-07 09:43:01 +01:00
Takashi Iwai e1b239f371 ALSA: x86: Refactor PCM process engine
This is again a big rewrite of the driver; now it touches the code to
process PCM stream transfers.

The most fundamental change is that the driver may support more than
four periods.  Instead of keeping the same index between both the ring
buffer (with the fixed four buffer descriptors) and the PCM buffer
periods, we keep difference indices for both (bd_head and pcm_head
fields).  In addition, when the periods are more than four, we need to
track both head and next indices.  That is, we now have three indices:
bd_head, pcm_head and pcm_filled.

Also, the driver works better for periods < 4, too: the remaining BDs
out of four are marked as invalid, so that the hardware skips those
BDs in its loop.

By this flexibility, we can use even ALSA-lib dmix plugin, which
requires 16 periods as default.

The buffer size could be up to 20bit, so the max buffer size was
increased accordingly.  However, the buffer pre-allocation is kept as
the old value (600kB) as default.  The reason is the limited number of
BDs: since it doesn't suffice for the useful SG page management that
can fit with the usual page allocator like some other drivers, we have
to still allocate continuous pages, hence we shouldn't take too big
memories there.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-06 12:21:10 +01:00
Takashi Iwai b556290f9a ALSA: x86: Unify local function prefix
Use had_ prefix consistently to all local helper functions, as well as
had_pcm_ for PCM ops.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-05 08:49:35 +01:00
Takashi Iwai f4566aa112 ALSA: x86: Minor cleanup of reset buffer procedure
The procedure to reset buffer pointers is performed in two places and
still open-coded.  Simplify the helper function and use it
consistently.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-05 08:49:02 +01:00
Takashi Iwai 83af57dd51 ALSA: x86: Don't check connection in lowlevel accessors
The lowlevel register read/write don't have to be careful about the
connection state.  It should be checked in the caller side instead.
By dropping the check, we can simplify the code, and readability.

This patch also refacors the functions slightly: namely,
- drop the useless always-zero return values
- fold the inline functions to the main accessor functions themselves
- move the DP audio hack for AUD_CONFIG to the caller side
- simplify snd_intelhad_eanble_audio() and drop the unused
  had_read_modify()

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-05 08:47:25 +01:00
Takashi Iwai 412bbe7d5b ALSA: x86: Explicit specify 32bit DMA
LPE audio is capable only up to 32bit address, as it seems.
Then we should limit the DMA addresses accordingly via dma-mapping
API.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-05 08:46:45 +01:00
Takashi Iwai 91b0cb0cc0 ALSA: x86: Rename drv_status to connected
After the rewrite of the runtime PM code, we have only two driver
status: CONNECTED and DISCONNECTED.  So it's clearer to use a boolean
flag, and name it easier one, "connected".

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:38:02 +01:00
Takashi Iwai 73997b050c ALSA: x86: Yet more tidy-up and clean-ups
- Add a few more comments to functions.

- Move the initialization of some PCM state variables to open and
  prepare callbacks, where these are clearer places.

- Remove superfluous NULL checks.

- Get rid of the bogus drv_status change to CONNECTED at close;
  this doesn't make any sense.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:50 +01:00
Takashi Iwai 44684f61b2 ALSA: x86: Simplify comments
It's a stand-alone small driver code, and we don't have to describe
too much formalized comments in kernel-doc style for local functions
at all.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:41 +01:00
Takashi Iwai 36ed34662f ALSA: x86: Set CA bits for DisplayPort too
This is a guess work.  Usually the DP audio info frame is just 8-bit
shifted from HDMI AI, so let's try to put CA in DIP frame 2 [24-31].

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:34 +01:00
Takashi Iwai 4aedb9465f ALSA: x86: Create ELD control element
Like other drivers, expose the ELD bytes via a control element so that
user-space can parse it.

For the simplicity, the code to register the ctl elements is
refactored using an array.  Also, since ELD ctl read copies the bytes
also during disconnection, clear the ELD bytes at hot-unplug, in order
to avoid the leak of the previous bogus ELD.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:23 +01:00
Takashi Iwai 03c3437755 ALSA: x86: Clean up unused defines and inclusions
Many defines and constants are left unused.  Clean them up.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:13 +01:00
Takashi Iwai 7ceba75f21 ALSA: x86: Reduce redundant register field names
Currently each register definition contains the own prefix in the
union struct itself; for example, union aud_ch_status_0 has
status_0_regx and status_0_regval fields.  These are simply
superfluous, since usually the type of the variable is seen in its
declaration or in its name.

In this patch, we cut off these prefixes.  Now all register
definitions have regx and regval fields consistently, instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:37:02 +01:00
Takashi Iwai df0435db1d ALSA: x86: Use the standard ELD bytes definitions
We have some constants defined in drm/drm_edid.h, and clean up our own
definitions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:36:53 +01:00
Takashi Iwai f69bd104b5 ALSA: x86: Move stream status into pcm_stream_info
The only remaining field in struct had_stream_data is stream_type that
holds the current stream status.  Such information fits better in
struct pcm_stream_info, so move it as a boolean "running" field to be
clearer.

This allows us to get rid or had_stream_data definition and
references.

Also, the superfluous status check get removed in a couple of places
where we can call PCM helpers in anyway.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:36:35 +01:00
Takashi Iwai 182cdf23db ALSA: x86: Implement runtime PM
Although the driver has some PM callbacks, it doesn't do it right:
- the suspend callback doesn't handle to suspend the running PCM,
- the runtime PM ops are missing,
- pm_runtime_get_sync() isn't used at the right place.

This patch covers the above and provides the basic runtime PM
functionality.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:36:26 +01:00
Takashi Iwai 313d9f28c1 ALSA: x86: Properly manage PCM substream lifetype
The PCM substream is referred not only in the PCM callbacks but also
in the irq handler and in the hotplug/unplug codes.  The latter code
paths don't take the PCM lock, thus the PCM may be released
unexpectedly while calling PCM helper functions or accessing
pcm->runtime fields.

This patch implements a simple refcount to assure the PCM substream
accessibility while the other codes are accessing.  It needed some
code refactoring in the relevant functions for avoiding the doubly
spinlocks.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:36:13 +01:00
Takashi Iwai 7d9e79869b ALSA: x86: Drop unused fields from pcm_stream_info
The struct pcm_stream_info contains a few unused or useless fields.
str_id is always zero, buffer_ptr is volatile, never read, and sfreq
is nowhere referred.  Kill them.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:35:56 +01:00
Takashi Iwai fa5dfe6a01 ALSA: x86: Drop redundant had_stream_pvt
The had_stream_pvt struct assigned to PCM runtime private data tracks
merely the stream running status, and the very same information is
carried by had_stream->stream_type.  Kill it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:35:42 +01:00
Takashi Iwai 0e9c67d7c8 ALSA: x86: Drop superfluous state field
The state field keeps the connection state and it's basically as same
as drv_status field.  Drop this redundancy.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:35:35 +01:00
Takashi Iwai d0e9b1a23c ALSA: x86: Drop flag_underrun field
The flag_underrun flag is used to indicate to escalate the XRUN
reporting at the next position inquiry, but there is a much simpler
method to achieve it: just call snd_pcm_stop_xrun().

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:35:17 +01:00
Takashi Iwai 8f8d1d7fe0 ALSA: x86: Fix racy access to chmap
The access to chmap can be racy against the hotplug process, where it
recreates the chmap on the fly.  For protecting against it, a mutex is
introduced in this patch.  It's also used for protecting the change /
reference of eld and state fields, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:35:07 +01:00
Takashi Iwai bcce775ca8 ALSA: x86: Remove superfluous irqsave flags
We don't need to use irqsave/irqrestore versions for each spin lock,
but judge the context properly and use the simpler versions.

Also add some (still simplistic) comments to functions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:59 +01:00
Takashi Iwai 4a5ddb2cb1 ALSA: x86: Constfy tables
Some tables can be defined as const.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:52 +01:00
Takashi Iwai 4151ee845a ALSA: x86: Remove _v[12] suffices
Although we dropped the most of the obsoleted *_v1 definitions and
codes, some codes still keep the _v1 or _v2 suffices.  Now they are
ripped off.

The only thing to be done carefully here is the definition of control
offsets.  The original code defines enum hdmi_ctrl_reg_offset_v1 and
a few new elements just for v2 on its top.  After this cleanup, we
remove the old AUD_HDMI_STATUS and AUD_HDMIW_INFOFR definitions and
replace with the v2 values.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:40 +01:00
Takashi Iwai 2e52f5e518 ALSA: x86: Tidy up codes
Clean up codes, fix indentations, correct comments, etc.
No functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:28 +01:00
Takashi Iwai 79f439ea40 ALSA: x86: Drop had_get_hwstate()
The helper function isn't clearer than the plain condition check
"if (drv_status == HDA_DRV_DISCONNECTED)".  By expanding this, the
compiler could even catch the possible uninitialized cases, so we
could fix them, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:17 +01:00
Takashi Iwai caa2a61a70 ALSA: x86: Remove superfluous check at resume
The had_get_hwstate() is identical with drv_status==DISCONECTED, which
was already checked before the call.  And, returning an error at
resume is simply bad.  That is, we should just kill this check.

Also, spewing an error at resume for drv_status!=SUSPENDED is also
annoying, as this is the normal case when the suspend was called
without the monitor connection.  Make it debug, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:09 +01:00
Takashi Iwai 99b2ab9d3a ALSA: x86: Fix sleep-in-atomic via i915 notification
i915 notification is executed in a spinlock, thus it must not sleep;
i.e. we can't use kmalloc with GFP_KERNEL or such.

For making it working properly, move the notification handler in a
work, and handle it gracefully.  We have already such a work, and it
was used just at the start.  This can be re-used in a more generic
hotplug handling.

Also, the patch adds the proper call of cancel_work_sync() to the
destructor.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:34:03 +01:00
Takashi Iwai f6a82a0c01 ALSA: x86: Drop superfluous PCM private_free
snd_pcm_lib_preallocate_free_for_all() doesn't have to be called from
each driver as it's called in the PCM core.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:33:55 +01:00
Takashi Iwai e9d65abfa6 ALSA: x86: Drop unused fields from snd_intelhad struct
Also change the flag_underrun to bool to be clearer.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:33:28 +01:00
Takashi Iwai df76df12f1 ALSA: x86: Remove indirect call of snd_pcm_period_elapsed()
Again another indirect call...  Let's straighten it up.
Also define the had_stream field with a proper type instead of a void
pointer.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:33:13 +01:00
Takashi Iwai e29c0f9672 ALSA: x86: Fix for CONFIG_PM=n
The direct access to power.runtime_status is taboo, let's use a helper
macro to avoid the compile error with CONFIG_PM=n.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:32:57 +01:00
Takashi Iwai c75b047624 ALSA: x86: Replace pr_xxx() with dev_xxx()
dev_xxx() helpers give a tidier output in general.

While we're at it, remove many useless debug prints (e.g. the ones at
each function entry), replace some too verbose errors with debugs, and
use WARN_ON() for some serious errors.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:32:22 +01:00
Takashi Iwai 372d855f87 ALSA: x86: Fold intel_hdmi_audio_if.c into main file
As the very last step, we fold intel_hdmi_audio_if.c into the main
file, intel_hdmi_audio.c.  This is merely a cleanup, and no functional
change.

By this move, we can mark all functions and variables as static, which
allows the compiler more optimizations.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:31:54 +01:00
Takashi Iwai da86480974 ALSA: x86: Flatten two abstraction layers
This is the final stage for a big clean-up series.  Here we flatten
the two layers into one.  Formerly, the implementation was split to
HDMI "shell" that talks with the platform device, and HDMI audio part
that communicates via caps and other event handlers.  All these would
be good if there were multiple instantiations or if there were data
protection.  But neither are true in our case.  That said, it'll be
easier to have a flat driver structure in the end.

In this patch, the former struct hdmi_lpe_audio_ctx is forged into the
existing struct snd_intelhad.  The latter has already a few members
that are basically the copy from the former.  Only a few new members
for the lowlevel I/O are added by this change.

Then, the had_get_caps() and had_set_caps() are simply replaced with
the direct calls to copy the data in the struct fields.  Also, the
had_event_handler() calls are replaced with the direct call for each
event as well.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:31:35 +01:00
Takashi Iwai eeb756c5bf ALSA: x86: Drop unused hdmi_audio_query()
It's used nowhere.  Kill it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:31:26 +01:00
Takashi Iwai 36ec0d99bb ALSA: x86: Call snd_card_register() at the end
The card registration should be done at the last stage of the probe
procedure.  Otherwise user-space may access to the device before the
whole initialization is done.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:31:15 +01:00
Takashi Iwai 301cf8a955 ALSA: x86: Check platform_data earlier
Just a minor optimization; check the presence of platform_data earlier
in the probe function before actually starting allocation, which makes
the error path easier.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:31:06 +01:00
Takashi Iwai c415022e48 ALSA: x86: Drop superfluous CHT PCI ID check
Since the config base offset is now set per pipe id, we don't have to
check Cherry Trail PCI IDs any longer.  Currently it's used only for
debug prints.  Let's drop it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:30:58 +01:00
Takashi Iwai 5647aec266 ALSA: x86: Embed snd_intelhad into snd_card
Instead of allocating snd_intelhad struct, use the card's private_data
and embed it.  It simplifies the code a lot.

While we're at it, embed had_stream into snd_intelhad struct instead
of individually allocating, and rename had_pvt_data to a bit more
specific name, had_stream_data.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:30:26 +01:00
Takashi Iwai dae15a9d96 ALSA: x86: Move dma_mask debug print into intel_hdmi_lpe_audio.c
It belongs to the right place.

And, remove a few sanity checks (e.g. NULL card) and debug prints as
well.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:29:36 +01:00
Takashi Iwai 0e18060f99 ALSA: x86: Drop unused hw_silence field
It's nowhere used.  Let's drop it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:25:43 +01:00
Takashi Iwai 6ddb3ab66f ALSA: x86: Move the global underrun_count to struct snd_intelhad
The last one is in intel_hdmi_audio.c, underrun_count: this can be
embedded in snd_intelhad object.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:25:30 +01:00
Takashi Iwai 7f2e9ab5a2 ALSA: x86: Drop global ELD copy
Similarly like the previous patch, drop the global variable to keep
the ELD copy.  It can be embedded in hdmi_lpe_audio_ctx as well.

And this makes easier to code, it's just a memcpy(), after all.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:25:10 +01:00
Takashi Iwai 055610b002 ALSA: x86: Drop global hlpe_state
Now it's the turn to drop the global hlpe_state variable.  It can be
gracefully embedded in hdmi_lpe_audio_ctx struct.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:24:58 +01:00
Takashi Iwai bf8b24f816 ALSA: x86: Drop the global platform device reference
Instead of referring to the global hlpe_pdev variable, pass the
platform device object to each function properly.  Accessing to the
global object is really ugly and error-prone.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:24:24 +01:00
Takashi Iwai af3e5c9c5d ALSA: x86: Drop unused mid_hdmi_audio_is_busy()
The function is nowhere used.  Kill it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:24:16 +01:00
Takashi Iwai 033e925f68 ALSA: x86: Fix possible stale interrupt calls
Registering the irq handler at the too early place may cause a system
stall because the irq handler may be triggered before the other
initializations.  Move the irq handler registration to the later point.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:23:37 +01:00
Takashi Iwai 437af8f294 ALSA: x86: Call event callback directly
Currently the driver calls the event callback stored in its ctx
pointer, but it's obviously inefficient.  Replace it with the direct
calls.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:23:15 +01:00
Takashi Iwai dd895f2e9b ALSA: x86: Drop useless mutex at probe
had_mutex is (supposedly) used to protect the concurrent calls of
hdmi_audio_probe().  But we may have only one device at most, so it's
utterly useless.  Drop it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:23:04 +01:00
Takashi Iwai 45459d1686 ALSA: x86: Handle the error from hdmi_audio_probe() properly
The error from hdmi_audio_probe() wasn't handled properly, and it may
leave some resources leaked or mapped.  Fix it and also clean up the
error paths.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:22:46 +01:00
Takashi Iwai 79dda75a2c 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: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:22:16 +01:00
Takashi Iwai 6f9ecc76f4 ALSA: x86: Drop snd_intel_had_interface indirect calls
Yet another indirection is killed: at this time, it's
snd_intel_had_interface.  It contains also the name string, but it's
nowhere used, thus we can kill it, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:21:57 +01:00
Takashi Iwai 9eca88c881 ALSA: x86: Replace indirect query_ops with direct calls
Like the previous patch, this replaces the indirect query_ops calls
via direct function calls.  They are only get_caps and set_caps, so
fairly straightforward at this time.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:21:41 +01:00
Takashi Iwai f23df8071b ALSA: x86: Replace indirect register ops with direct calls
Now about the indirect register ops: they are replaced with direct
calls, too.

The read / write / modify ops are simply replaced with the
corresponding functions.  The difference is that we calculate the
offset inside the function now.  So all the had_config_offset
references in the caller side are dropped.  This also simplifies the
DP-audio check in hdmi_audio_write() and hdmi_audio_rmw().

The hdmi_audio_get_register_base is dropped since it's no longer used
when the base address and config offset are referred in the read/write
functions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:21:17 +01:00
Takashi Iwai 76296ef0ec ALSA: x86: Drop indirect calls of had_ops
We have only a single implementation of had_ops, hence there is no
merit to use the indirect calls at all.  Let's replace it with the
direct calls -- which allows the compiler more optimizations.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:20:58 +01:00
Takashi Iwai 4812dcc437 ALSA: x86: Remove v1 ops and structs
The v1 code refers to Medfield/Clovertrail.  It's not used at all in
the current driver, and probably won't be ever.  Let's clean this up,
then we can go to the next stage of cleanup tasks.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 17:20:24 +01:00
Takashi Iwai 716733032a ALSA: x86: Don't set PCM state to DISCONNECTED
Theoretically setting the state to SNDRV_PCM_STATE_DISCONNECTED is
correct.  But, unfortunately, PA gets confused by this action, and it
won't re-probe the device after HDMI/DP is re-plugged.  (It reprobes
only when the card itself is recreated.)

As a workaround, set SNDRV_PCM_STATE_SETUP instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-03 16:20:41 +01:00
Takashi Iwai b1c01f4df2 drm/i915: Pass platform device to LPE audio notifier
This allows the LPE HDMI driver to clean up its global variable
reference.

Also drop to pass the eld pointer because the connection status and
the ELD bytes can be retrieved from the attached pdata.

Acked-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-01 16:22:28 +01:00
Pierre-Louis Bossart 0843e043cf ALSA: x86: Use config base depending on the pipe
Now the pipe that is being used is passed over i915 notification, we
can re-setup the relevant register offset depending on pipe assignments
during hotplug.
This allows playback on single port machines such Zotac Pi330 or
dual-port machines such as Dell Wyse 3040 box

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-01 16:22:25 +01:00
Pierre-Louis Bossart 964ca8083c ALSA: x86: intel_hdmi: add definitions and logic for DP audio
Imported from legacy patches

Note: the new code doesn't assume a modified ELD but
an explicit notification that DP is present. It appears
that the i915 code does change the ELD so we could use
the ELD-based tests to check for DP audio

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-02-01 16:22:24 +01:00
Julia Lawall 0369d6315b ALSA: x86: hdmi: fix returnvar.cocci warnings
Remove unneeded variable used to store return value.

Generated by: scripts/coccinelle/misc/returnvar.cocci

CC: Jerome Anand <jerome.anand@intel.com>
Signed-off-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-25 22:07:38 +01:00
kbuild test robot f0fd4122f0 ALSA: x86: fix resource_size.cocci warnings
sound/x86/intel_hdmi_lpe_audio.c:498:24-27: ERROR: Missing resource_size with res_mmio

 Use resource_size function on resource object
 instead of explicit computation.

Generated by: scripts/coccinelle/api/resource_size.cocci

CC: Jerome Anand <jerome.anand@intel.com>
Signed-off-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-25 14:25:37 +01:00
Jerome Anand 232892fb14 ALSA: x86: hdmi: continue playback even when display resolution changes
When the display resolution changes, the drm disables the
display pipes due to which audio rendering stops. At this
time, we need to ensure the existing audio pointers and
buffers are cleared out so that the playback can restarted
once the display pipe is enabled with a different N/CTS values

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Jerome Anand <jerome.anand@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-25 14:24:19 +01:00
Jerome Anand 5dab11d897 ALSA: x86: hdmi: Add audio support for BYT and CHT
Hdmi audio driver based on the child platform device
created by gfx driver is implemented.
This audio driver is derived from legacy intel
hdmi audio driver.

The interfaces for interaction between gfx and audio
are updated and the driver implementation updated to
derive interrupts in its own address space based on
irq chip framework

The changes to calculate sub-period positions was triggered
by David Henningsson <david.henningsson@canonical.com> and is
accomodated in this patch

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Jerome Anand <jerome.anand@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-25 14:24:08 +01:00
Jerome Anand 287599cf2d ALSA: add Intel HDMI LPE audio driver for BYT/CHT-T
On Baytrail and Cherrytrail, HDaudio may be fused out or disabled
by the BIOS. This driver enables an alternate path to the i915
display registers and DMA.

Although there is no hardware path between i915 display and LPE/SST
audio clusters, this HDMI capability is referred to in the documentation
as "HDMI LPE Audio" so we keep the name for consistency. There is no
hardware path or control dependencies with the LPE/SST DSP functionality.

The hdmi-lpe-audio driver will be probed when the i915 driver creates
a child platform device.

Since this driver is neither SoC nor PCI, a new x86 folder is added
Additional indirections in the code will be cleaned up in the next series
to aid smoother DP integration

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Jerome Anand <jerome.anand@intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2017-01-25 14:23:46 +01:00