History log of /openbsd-current/sys/arch/macppc/dev/i2s.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.39 22-May-2024 jsg

remove prototypes with no matching function and externs with no var


# 1.38 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.37 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.36 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


# 1.35 15-Oct-2022 jsg

ansi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@


# 1.38 14-Apr-2024 jsg

with empty body loops, put final semicolon on a new line for readability
ok bluhm@ jca@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.37 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.36 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


# 1.35 15-Oct-2022 jsg

ansi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@


# 1.37 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.36 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


# 1.35 15-Oct-2022 jsg

ansi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@


# 1.36 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


# 1.35 15-Oct-2022 jsg

ansi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@


# 1.35 15-Oct-2022 jsg

ansi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.34 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


# 1.33 30-Aug-2016 ratchov

Properly set "msb" and "bps" fields for both play and rec directions.
Fixes "audio0: different play and record parameters ... " errors, and
probably other unreported errors.

help and ok landry@


Revision tags: OPENBSD_6_0_BASE
# 1.32 26-Jun-2016 mglocker

Oups, remove '#define I2S_DEBUG' again.


# 1.31 26-Jun-2016 mglocker

Make i2s compile with I2S_DEBUG; %x -> %p.


Revision tags: OPENBSD_5_9_BASE
# 1.30 08-Sep-2015 deraadt

sizes for free(); ok semarie


Revision tags: OPENBSD_5_8_BASE
# 1.29 17-Jul-2015 mpi

Make sound cards work on older PowerMacs.

On such machines the device-tree contains absolute addresses for the
various sound buttons and the hardware was not properly initiliazed.

Problem reported and fix tested by Fabian Fr��d��rick.


# 1.28 03-Jun-2015 mpi

Check for the correct bit in the interrupts property of the device-tree
to determin if interrupts should be established as edge/level triggered.

Fix audio interrupts on U4 systems. On such systems the "interrupts"
fields in the device-tree has more bits set and cannot be compared to
0.


# 1.27 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


# 1.26 07-Apr-2015 mpi

Mark audio interrupt handlers as MPSAFE, they already grab the right
mutex when necessary.

ok kettenis@, ratchov@


# 1.25 24-Mar-2015 mpi

Work around broken device-tree in PowerMac7,2 and PowerMac7,3 (K2 systems)
and get the correct offsets from the "i2s" node. Also explicitly enable
the clock in FCR1 as the firmware does not do it on such machine.

Still not enough to get the sound working in such systems but get rid of
the annoying "i2s_set_rate: timeout" message during boot and plugging an
headphone is now correctly detected.


Revision tags: OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.24 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_4_BASE OPENBSD_5_5_BASE
# 1.23 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.22 07-Jun-2011 mpi

Make use of macobio_* methods to manage the i2s GPIOs, remove the customs
gpio_* methods and move the remaining global variables in the softc.

ok ratchov@, krw@


# 1.21 15-May-2011 mpi

Unify various gpio access using methods that take an offset relative to the
mac-io bus base address. Needed by upcoming dfs(4) support.

On some Apple machines, the openfirmware returns a gpio offset relative to
the gpio controller (generaly at 0x50). These offsets should be corrected
to be relative to the bus base address.

looks fine to kettenis@, ok miod@


# 1.20 05-May-2011 jasper

add support for muting the master channel on i2s based cards, this allows the
"mute" key on keyboards to function too.
tested by kettenis on aoa(4) and snapper(4) by me.

from Martin Pieuchot
ok kettenis@ ratchov@


# 1.19 04-May-2011 jasper

fix volume up and down using the keyboard keys

from Martin Pieuchot
ok ratchov@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.18 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.17 07-Nov-2008 todd

different fix for pr5883 than proposed by the submitter, found when glancing
at apple code
go ahead drahn@


# 1.16 05-Nov-2008 jakemsr

return an error when trying to get stereo values from a mono
control. makes mixerctl(1) output more sensible.

ok drahn, todd


# 1.15 30-Oct-2008 todd

patches for macppc to remove more EINVAL returns in the audio code
tested by me, from ratchov@, please commit ratchov@


# 1.14 29-Oct-2008 deraadt

come on -- this was not even test compiled


# 1.13 29-Oct-2008 jakemsr

native default parameters for i2s devices instead of 8kHz
mulaw mono, which few can even do.

"Please just get this in." brad@


# 1.12 24-Aug-2008 todd

o implement proper volume control table based on chipset docs
o attempt to make record work (but silence for now)
from drahn@, ok maja@, drahn@


Revision tags: OPENBSD_4_3_BASE OPENBSD_4_4_BASE
# 1.11 11-Dec-2007 jakemsr

remove support for 8kHz sample rates. not all i2s based audio
devices support 8kHz sample rates, and there is insufficient
code to enable it properly on the devices that do support 8kHz.

fixes "evil sound" problem reported by ajacoutot@ and jdixon@.

ok deanna@, ratchov@, ajacoutot@


# 1.10 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


# 1.9 17-Sep-2007 krw

Only the most obvious bzero() -> M_ZERO changes. No cast changes, no
MALLOC/FREE, etc. Just adding M_ZERO to malloc() and deleting an
immediately adjacent bzero().


Revision tags: OPENBSD_4_2_BASE
# 1.8 22-Apr-2007 deraadt

better interrupt names for vmstat -iz; ok miod gwk


# 1.7 21-Apr-2007 gwk

Add blinkenlights(4) a driver to control the 16 leds found on the front
panel of the Xserve G4 and G5. The leds will provide an indication of the
system load slowing as the load climbs, and system health e.g. no
lights means its dead or in DDB.

Split some of the shared registers and clock divisors from i2s into
i2sreg.h while there nuke some evil C++ style comments.
Man page to follow shortly.

ok deraadt


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.6 08-Jan-2006 kettenis

Don't provide bass and treble mixer controls if the underlying hardware doesn't
provide these. Put them in the outputs class.
ok joris@


# 1.5 11-Dec-2005 kettenis

Fix mixer for machines that have lineout and/or don't have headphone.
ok joris@


# 1.4 19-Nov-2005 kettenis

Get device resources from soundbus node instead of i2s node. This makes sound
work on the iMac G5, and should work on older systems too.
tested by cloder@, miod@; ok brad@


# 1.3 17-Nov-2005 brad

fix mixer control names.

i2s.c diff from Tsubai Masanari's CVS repo.

ok joris@


# 1.2 31-Oct-2005 joris

- add needed bass & treble glue in i2s;
- add support for bass & treble in snapper;

ok drahn@


# 1.1 26-Oct-2005 joris

add an i2s framework, which can be reused in new audio drivers
for macppc, as most modern Apple machines have i2s-based audio.

also let snapper use i2s.c right away;

tested by Antoine Jacoutot, drahn@ and kettenis@
"yes, commit!" drahn@, ok kettenis@