FreeBSD kernel sound device code
i2s.c File Reference
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/bus.h>
#include <sys/malloc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <machine/dbdma.h>
#include <machine/intr_machdep.h>
#include <machine/resource.h>
#include <machine/bus.h>
#include <machine/pio.h>
#include <sys/rman.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/sound/pcm/sound.h>
#include <dev/sound/macio/aoa.h>
#include <powerpc/powermac/macgpiovar.h>
Include dependency graph for i2s.c:

Go to the source code of this file.

Data Structures

struct  i2s_softc
 
struct  aoagpio_softc
 
struct  gpio_match
 
struct  i2s_clksrc
 

Macros

#define GPIO_CTRL_EXTINT_SET
 
#define I2S_INT   0x00
 
#define I2S_FORMAT   0x10
 
#define I2S_FRAMECOUNT   0x40
 
#define I2S_FRAMEMATCH   0x50
 
#define I2S_WORDSIZE   0x60
 
#define I2S_INT_CLKSTOPPEND   0x01000000 /* clock-stop interrupt pending */
 
#define CLKSRC_49MHz   0x80000000 /* Use 49152000Hz Osc. */
 
#define CLKSRC_45MHz   0x40000000 /* Use 45158400Hz Osc. */
 
#define CLKSRC_18MHz   0x00000000 /* Use 18432000Hz Osc. */
 
#define MCLK_DIV_MASK   0x1f000000 /* MCLK = SRC / DIV */
 
#define SCLK_DIV_MASK   0x00f00000 /* SCLK = MCLK / DIV */
 
#define SCLK_MASTER   0x00080000 /* Master mode */
 
#define SCLK_SLAVE   0x00000000 /* Slave mode */
 
#define SERIAL_FORMAT   0x00070000
 
#define SERIAL_SONY   0x00000000
 
#define SERIAL_64x   0x00010000
 
#define SERIAL_32x   0x00020000
 
#define SERIAL_DAV   0x00040000
 
#define SERIAL_SILICON   0x00050000
 
#define INPUT_STEREO   (2 << 24)
 
#define INPUT_MONO   (1 << 24)
 
#define INPUT_16BIT   (0 << 16)
 
#define INPUT_24BIT   (3 << 16)
 
#define OUTPUT_STEREO   (2 << 8)
 
#define OUTPUT_MONO   (1 << 8)
 
#define OUTPUT_16BIT   (0 << 0)
 
#define OUTPUT_24BIT   (3 << 0)
 
#define MCLK_FS   256
 
#define NCLKS   3
 
#define reset_active   0
 
#define RESET_SETUP_TIME   5000
 
#define RESET_HOLD_TIME   20000
 
#define RESET_RELEASE_TIME   10000
 
#define AMP_ACTIVE   0 /* XXX OF */
 
#define HEADPHONE_ACTIVE   0 /* XXX OF */
 
#define LINEOUT_ACTIVE   0 /* XXX OF */
 
#define MUTE_CONTROL(xxx, yyy)
 

Enumerations

enum  gpio_ctrl {
  AMP_MUTE , HEADPHONE_MUTE , LINEOUT_MUTE , AUDIO_HW_RESET ,
  HEADPHONE_DETECT , LINEOUT_DETECT , GPIO_CTRL_NUM
}
 

Functions

static int i2s_probe (device_t)
 
static int i2s_attach (device_t)
 
static void i2s_postattach (void *)
 
static int i2s_setup (struct i2s_softc *, u_int, u_int, u_int)
 
static void i2s_mute_headphone (struct i2s_softc *, int)
 
static void i2s_mute_lineout (struct i2s_softc *, int)
 
static void i2s_mute_speaker (struct i2s_softc *, int)
 
static void i2s_set_outputs (void *, u_int)
 
 DRIVER_MODULE (pcm_i2s, macio, pcm_i2s_driver, pcm_devclass, 0, 0)
 
 MODULE_DEPEND (pcm_i2s, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER)
 
static int aoagpio_probe (device_t)
 
static int aoagpio_attach (device_t)
 
 DRIVER_MODULE (aoagpio, macgpio, aoagpio_driver, aoagpio_devclass, 0, 0)
 
static phandle_t of_find_firstchild_byname (phandle_t, const char *)
 
static void i2s_cint (struct i2s_softc *)
 
static void aoagpio_int (void *cookie)
 
static u_int gpio_read (enum gpio_ctrl ctrl)
 
static void gpio_write (enum gpio_ctrl ctrl, u_int x)
 
static void i2s_audio_hw_reset (struct i2s_softc *sc)
 

Variables

static struct intr_config_hook * i2s_delayed_attach = NULL
 
kobj_class_t i2s_mixer_class = NULL
 
device_t i2s_mixer = NULL
 
static device_method_t pcm_i2s_methods []
 
static driver_t pcm_i2s_driver
 
static device_method_t aoagpio_methods []
 
static driver_t aoagpio_driver
 
static devclass_t aoagpio_devclass
 
static struct aoagpio_softcgpio_ctrls [GPIO_CTRL_NUM]
 
static struct gpio_match gpio_controls []
 
static const struct i2s_clksrc clksrc [NCLKS]
 

Macro Definition Documentation

◆ AMP_ACTIVE

#define AMP_ACTIVE   0 /* XXX OF */

Definition at line 673 of file i2s.c.

◆ CLKSRC_18MHz

#define CLKSRC_18MHz   0x00000000 /* Use 18432000Hz Osc. */

Definition at line 404 of file i2s.c.

◆ CLKSRC_45MHz

#define CLKSRC_45MHz   0x40000000 /* Use 45158400Hz Osc. */

Definition at line 403 of file i2s.c.

◆ CLKSRC_49MHz

#define CLKSRC_49MHz   0x80000000 /* Use 49152000Hz Osc. */

Definition at line 402 of file i2s.c.

◆ GPIO_CTRL_EXTINT_SET

#define GPIO_CTRL_EXTINT_SET
Value:
((1 << HEADPHONE_DETECT) | \
@ LINEOUT_DETECT
Definition: i2s.c:270
@ HEADPHONE_DETECT
Definition: i2s.c:269

Definition at line 274 of file i2s.c.

◆ HEADPHONE_ACTIVE

#define HEADPHONE_ACTIVE   0 /* XXX OF */

Definition at line 674 of file i2s.c.

◆ I2S_FORMAT

#define I2S_FORMAT   0x10

Definition at line 393 of file i2s.c.

◆ I2S_FRAMECOUNT

#define I2S_FRAMECOUNT   0x40

Definition at line 394 of file i2s.c.

◆ I2S_FRAMEMATCH

#define I2S_FRAMEMATCH   0x50

Definition at line 395 of file i2s.c.

◆ I2S_INT

#define I2S_INT   0x00

Definition at line 392 of file i2s.c.

◆ I2S_INT_CLKSTOPPEND

#define I2S_INT_CLKSTOPPEND   0x01000000 /* clock-stop interrupt pending */

Definition at line 399 of file i2s.c.

◆ I2S_WORDSIZE

#define I2S_WORDSIZE   0x60

Definition at line 396 of file i2s.c.

◆ INPUT_16BIT

#define INPUT_16BIT   (0 << 16)

Definition at line 419 of file i2s.c.

◆ INPUT_24BIT

#define INPUT_24BIT   (3 << 16)

Definition at line 420 of file i2s.c.

◆ INPUT_MONO

#define INPUT_MONO   (1 << 24)

Definition at line 418 of file i2s.c.

◆ INPUT_STEREO

#define INPUT_STEREO   (2 << 24)

Definition at line 417 of file i2s.c.

◆ LINEOUT_ACTIVE

#define LINEOUT_ACTIVE   0 /* XXX OF */

Definition at line 675 of file i2s.c.

◆ MCLK_DIV_MASK

#define MCLK_DIV_MASK   0x1f000000 /* MCLK = SRC / DIV */

Definition at line 405 of file i2s.c.

◆ MCLK_FS

#define MCLK_FS   256

Definition at line 428 of file i2s.c.

◆ MUTE_CONTROL

#define MUTE_CONTROL (   xxx,
  yyy 
)
Value:
static void \
i2s_mute_##xxx(struct i2s_softc *sc, int mute) \
{ \
int x; \
\
if (gpio_ctrls[yyy##_MUTE] == NULL) \
return; \
if (mute) \
x = yyy##_ACTIVE; \
else \
x = ! yyy##_ACTIVE; \
\
if (x != gpio_read(yyy##_MUTE)) \
gpio_write(yyy##_MUTE, x); \
}
static u_int gpio_read(enum gpio_ctrl ctrl)
Definition: i2s.c:601
static struct aoagpio_softc * gpio_ctrls[GPIO_CTRL_NUM]
Definition: i2s.c:278
Definition: i2s.c:87

Definition at line 677 of file i2s.c.

◆ NCLKS

#define NCLKS   3

Definition at line 431 of file i2s.c.

◆ OUTPUT_16BIT

#define OUTPUT_16BIT   (0 << 0)

Definition at line 423 of file i2s.c.

◆ OUTPUT_24BIT

#define OUTPUT_24BIT   (3 << 0)

Definition at line 424 of file i2s.c.

◆ OUTPUT_MONO

#define OUTPUT_MONO   (1 << 8)

Definition at line 422 of file i2s.c.

◆ OUTPUT_STEREO

#define OUTPUT_STEREO   (2 << 8)

Definition at line 421 of file i2s.c.

◆ reset_active

#define reset_active   0

Definition at line 646 of file i2s.c.

◆ RESET_HOLD_TIME

#define RESET_HOLD_TIME   20000

Definition at line 650 of file i2s.c.

◆ RESET_RELEASE_TIME

#define RESET_RELEASE_TIME   10000

Definition at line 651 of file i2s.c.

◆ RESET_SETUP_TIME

#define RESET_SETUP_TIME   5000

Definition at line 649 of file i2s.c.

◆ SCLK_DIV_MASK

#define SCLK_DIV_MASK   0x00f00000 /* SCLK = MCLK / DIV */

Definition at line 406 of file i2s.c.

◆ SCLK_MASTER

#define SCLK_MASTER   0x00080000 /* Master mode */

Definition at line 407 of file i2s.c.

◆ SCLK_SLAVE

#define SCLK_SLAVE   0x00000000 /* Slave mode */

Definition at line 408 of file i2s.c.

◆ SERIAL_32x

#define SERIAL_32x   0x00020000

Definition at line 412 of file i2s.c.

◆ SERIAL_64x

#define SERIAL_64x   0x00010000

Definition at line 411 of file i2s.c.

◆ SERIAL_DAV

#define SERIAL_DAV   0x00040000

Definition at line 413 of file i2s.c.

◆ SERIAL_FORMAT

#define SERIAL_FORMAT   0x00070000

Definition at line 409 of file i2s.c.

◆ SERIAL_SILICON

#define SERIAL_SILICON   0x00050000

Definition at line 414 of file i2s.c.

◆ SERIAL_SONY

#define SERIAL_SONY   0x00000000

Definition at line 410 of file i2s.c.

Enumeration Type Documentation

◆ gpio_ctrl

enum gpio_ctrl
Enumerator
AMP_MUTE 
HEADPHONE_MUTE 
LINEOUT_MUTE 
AUDIO_HW_RESET 
HEADPHONE_DETECT 
LINEOUT_DETECT 
GPIO_CTRL_NUM 

Definition at line 264 of file i2s.c.

Function Documentation

◆ aoagpio_attach()

static int aoagpio_attach ( device_t  gpio)
static

Definition at line 361 of file i2s.c.

References aoagpio_int(), aoagpio_softc::ctrl, DPRINTF, gpio, GPIO_CTRL_EXTINT_SET, irq, r, and rid.

Here is the call graph for this function:

◆ aoagpio_int()

static void aoagpio_int ( void *  cookie)
static

Definition at line 299 of file i2s.c.

References aoagpio_softc::detect_active, aoagpio_softc::i2s, i2s_cint(), and aoagpio_softc::level.

Referenced by aoagpio_attach(), and aoagpio_probe().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ aoagpio_probe()

static int aoagpio_probe ( device_t  gpio)
static

◆ DRIVER_MODULE() [1/2]

DRIVER_MODULE ( aoagpio  ,
macgpio  ,
aoagpio_driver  ,
aoagpio_devclass  ,
,
 
)

◆ DRIVER_MODULE() [2/2]

DRIVER_MODULE ( pcm_i2s  ,
macio  ,
pcm_i2s_driver  ,
pcm_devclass  ,
,
 
)

◆ gpio_read()

static u_int gpio_read ( enum gpio_ctrl  ctrl)
static

Definition at line 601 of file i2s.c.

References aoagpio_softc::ctrl, aoagpio_softc::dev, gpio_ctrls, and GPIO_DATA.

◆ gpio_write()

static void gpio_write ( enum gpio_ctrl  ctrl,
u_int  x 
)
static

Definition at line 612 of file i2s.c.

References aoagpio_softc::ctrl, aoagpio_softc::dev, gpio_ctrls, GPIO_DATA, and reg.

Referenced by i2s_audio_hw_reset().

Here is the caller graph for this function:

◆ i2s_attach()

static int i2s_attach ( device_t  self)
static

◆ i2s_audio_hw_reset()

static void i2s_audio_hw_reset ( struct i2s_softc sc)
static

Definition at line 654 of file i2s.c.

References AUDIO_HW_RESET, DPRINTF, gpio_ctrls, gpio_write(), reset_active, RESET_HOLD_TIME, RESET_RELEASE_TIME, and RESET_SETUP_TIME.

Referenced by i2s_postattach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2s_cint()

static void i2s_cint ( struct i2s_softc sc)
static

Definition at line 628 of file i2s.c.

References gpio_ctrls, HEADPHONE_DETECT, i2s_set_outputs(), aoagpio_softc::level, LINEOUT_DETECT, and mask.

Referenced by aoagpio_int(), and i2s_postattach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2s_mute_headphone()

static void i2s_mute_headphone ( struct i2s_softc ,
int   
)
static

Referenced by i2s_set_outputs().

Here is the caller graph for this function:

◆ i2s_mute_lineout()

static void i2s_mute_lineout ( struct i2s_softc ,
int   
)
static

Referenced by i2s_set_outputs().

Here is the caller graph for this function:

◆ i2s_mute_speaker()

static void i2s_mute_speaker ( struct i2s_softc ,
int   
)
static

Referenced by i2s_set_outputs().

Here is the caller graph for this function:

◆ i2s_postattach()

static void i2s_postattach ( void *  xsc)
static

Definition at line 734 of file i2s.c.

References i2s_softc::aoa, free, GPIO_CTRL_NUM, gpio_ctrls, aoagpio_softc::i2s, i2s_audio_hw_reset(), i2s_cint(), i2s_delayed_attach, i2s_mixer, i2s_mixer_class, mixer_init(), and aoa_softc::sc_dev.

Referenced by i2s_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2s_probe()

static int i2s_probe ( device_t  self)
static

Definition at line 157 of file i2s.c.

References name.

◆ i2s_set_outputs()

static void i2s_set_outputs ( void *  ptr,
u_int  mask 
)
static

Definition at line 699 of file i2s.c.

References DPRINTF, i2s_mute_headphone(), i2s_mute_lineout(), i2s_mute_speaker(), mask, i2s_softc::output_mask, and i2s_softc::port_mtx.

Referenced by i2s_cint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i2s_setup()

static int i2s_setup ( struct i2s_softc sc,
u_int  rate,
u_int  wordsize,
u_int  sclk_fs 
)
static

◆ MODULE_DEPEND()

MODULE_DEPEND ( pcm_i2s  ,
sound  ,
SOUND_MINVER  ,
SOUND_PREFVER  ,
SOUND_MAXVER   
)

◆ of_find_firstchild_byname()

static phandle_t of_find_firstchild_byname ( phandle_t  node,
const char *  req_name 
)
static

Definition at line 584 of file i2s.c.

References n, and name.

Referenced by i2s_attach().

Here is the caller graph for this function:

Variable Documentation

◆ aoagpio_devclass

devclass_t aoagpio_devclass
static

Definition at line 149 of file i2s.c.

◆ aoagpio_driver

driver_t aoagpio_driver
static
Initial value:
= {
"aoagpio",
sizeof(struct aoagpio_softc)
}
static device_method_t aoagpio_methods[]
Definition: i2s.c:129

Definition at line 144 of file i2s.c.

◆ aoagpio_methods

device_method_t aoagpio_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, aoagpio_probe),
DEVMETHOD(device_attach, aoagpio_attach),
{ 0, 0 }
}
static int aoagpio_attach(device_t)
Definition: i2s.c:361
static int aoagpio_probe(device_t)
Definition: i2s.c:316

Definition at line 129 of file i2s.c.

◆ clksrc

const struct i2s_clksrc clksrc[NCLKS]
static
Initial value:
= {
{49152000, CLKSRC_49MHz},
{45158400, CLKSRC_45MHz},
{18432000, CLKSRC_18MHz}
}
#define CLKSRC_45MHz
Definition: i2s.c:403
#define CLKSRC_49MHz
Definition: i2s.c:402
#define CLKSRC_18MHz
Definition: i2s.c:404

Referenced by i2s_setup().

◆ gpio_controls

struct gpio_match gpio_controls[]
static
Initial value:
= {
{"headphone-mute", HEADPHONE_MUTE},
{"lineout-mute", LINEOUT_MUTE},
{"amp-mute", AMP_MUTE},
{"headphone-detect", HEADPHONE_DETECT},
{"lineout-detect", LINEOUT_DETECT},
{"line-output-detect", LINEOUT_DETECT},
{"audio-hw-reset", AUDIO_HW_RESET},
{"hw-reset", AUDIO_HW_RESET},
{NULL, GPIO_CTRL_NUM}
}
@ AMP_MUTE
Definition: i2s.c:265
@ GPIO_CTRL_NUM
Definition: i2s.c:271
@ HEADPHONE_MUTE
Definition: i2s.c:266
@ AUDIO_HW_RESET
Definition: i2s.c:268
@ LINEOUT_MUTE
Definition: i2s.c:267

Referenced by aoagpio_probe().

◆ gpio_ctrls

struct aoagpio_softc* gpio_ctrls[GPIO_CTRL_NUM]
static
Initial value:
=
{NULL, NULL, NULL, NULL, NULL, NULL}

Definition at line 278 of file i2s.c.

Referenced by aoagpio_probe(), gpio_read(), gpio_write(), i2s_audio_hw_reset(), i2s_cint(), and i2s_postattach().

◆ i2s_delayed_attach

struct intr_config_hook* i2s_delayed_attach = NULL
static

Definition at line 105 of file i2s.c.

Referenced by i2s_attach(), and i2s_postattach().

◆ i2s_mixer

device_t i2s_mixer = NULL

Definition at line 108 of file i2s.c.

Referenced by i2s_postattach(), onyx_attach(), snapper_attach(), and tumbler_attach().

◆ i2s_mixer_class

kobj_class_t i2s_mixer_class = NULL

Definition at line 107 of file i2s.c.

Referenced by i2s_postattach(), onyx_attach(), snapper_attach(), and tumbler_attach().

◆ pcm_i2s_driver

driver_t pcm_i2s_driver
static
Initial value:
= {
"pcm",
}
static device_method_t pcm_i2s_methods[]
Definition: i2s.c:110
#define PCM_SOFTC_SIZE
Definition: sound.h:96

Definition at line 117 of file i2s.c.

◆ pcm_i2s_methods

device_method_t pcm_i2s_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, i2s_probe),
DEVMETHOD(device_attach, i2s_attach),
{ 0, 0 }
}
static int i2s_probe(device_t)
Definition: i2s.c:157
static int i2s_attach(device_t)
Definition: i2s.c:188

Definition at line 110 of file i2s.c.