FreeBSD kernel sound device code
snapper.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/iicbus/iicbus.h>
#include <dev/iicbus/iiconf.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/sound/pcm/sound.h>
#include "mixer_if.h"
Include dependency graph for snapper.c:

Go to the source code of this file.

Data Structures

struct  snapper_softc
 
struct  snapper_reg
 

Macros

#define SNAPPER_IICADDR   0x6a /* Hard-coded I2C slave addr */
 
#define SNAPPER_MCR1   0x01 /* Main control register 1 (1byte) */
 
#define SNAPPER_DRC   0x02 /* Dynamic range compression (6bytes) */
 
#define SNAPPER_VOLUME   0x04 /* Volume (6bytes) */
 
#define SNAPPER_TREBLE   0x05 /* Treble control (1byte) */
 
#define SNAPPER_BASS   0x06 /* Bass control (1byte) */
 
#define SNAPPER_MIXER_L   0x07 /* Mixer left gain (9bytes) */
 
#define SNAPPER_MIXER_R   0x08 /* Mixer right gain (9bytes) */
 
#define SNAPPER_LB0   0x0a /* Left biquad 0 (15bytes) */
 
#define SNAPPER_LB1   0x0b /* Left biquad 1 (15bytes) */
 
#define SNAPPER_LB2   0x0c /* Left biquad 2 (15bytes) */
 
#define SNAPPER_LB3   0x0d /* Left biquad 3 (15bytes) */
 
#define SNAPPER_LB4   0x0e /* Left biquad 4 (15bytes) */
 
#define SNAPPER_LB5   0x0f /* Left biquad 5 (15bytes) */
 
#define SNAPPER_LB6   0x10 /* Left biquad 6 (15bytes) */
 
#define SNAPPER_RB0   0x13 /* Right biquad 0 (15bytes) */
 
#define SNAPPER_RB1   0x14 /* Right biquad 1 (15bytes) */
 
#define SNAPPER_RB2   0x15 /* Right biquad 2 (15bytes) */
 
#define SNAPPER_RB3   0x16 /* Right biquad 3 (15bytes) */
 
#define SNAPPER_RB4   0x17 /* Right biquad 4 (15bytes) */
 
#define SNAPPER_RB5   0x18 /* Right biquad 5 (15bytes) */
 
#define SNAPPER_RB6   0x19 /* Right biquad 6 (15bytes) */
 
#define SNAPPER_LLB   0x21 /* Left loudness biquad (15bytes) */
 
#define SNAPPER_RLB   0x22 /* Right loudness biquad (15bytes) */
 
#define SNAPPER_LLB_GAIN   0x23 /* Left loudness biquad gain (3bytes) */
 
#define SNAPPER_RLB_GAIN   0x24 /* Right loudness biquad gain (3bytes) */
 
#define SNAPPER_ACR   0x40 /* Analog control register (1byte) */
 
#define SNAPPER_MCR2   0x43 /* Main control register 2 (1byte) */
 
#define SNAPPER_MCR1_FL   0x80 /* Fast load */
 
#define SNAPPER_MCR1_SC   0x40 /* SCLK frequency */
 
#define SNAPPER_MCR1_SC_32   0x00 /* 32fs */
 
#define SNAPPER_MCR1_SC_64   0x40 /* 64fs */
 
#define SNAPPER_MCR1_SM   0x30 /* Output serial port mode */
 
#define SNAPPER_MCR1_SM_L   0x00 /* Left justified */
 
#define SNAPPER_MCR1_SM_R   0x10 /* Right justified */
 
#define SNAPPER_MCR1_SM_I2S   0x20 /* I2S */
 
#define SNAPPER_MCR1_W   0x03 /* Serial port word length */
 
#define SNAPPER_MCR1_W_16   0x00 /* 16 bit */
 
#define SNAPPER_MCR1_W_18   0x01 /* 18 bit */
 
#define SNAPPER_MCR1_W_20   0x02 /* 20 bit */
 
#define SNAPPER_MCR1_W_24   0x03 /* 24 bit */
 
#define SNAPPER_MCR2_DL   0x80 /* Download */
 
#define SNAPPER_MCR2_AP   0x02 /* All pass mode */
 
#define SNAPPER_ACR_ADM   0x80 /* ADC output mode */
 
#define SNAPPER_ACR_LRB   0x40 /* Select B input */
 
#define SNAPPER_ACR_DM   0x0c /* De-emphasis control */
 
#define SNAPPER_ACR_DM_OFF   0x00 /* off */
 
#define SNAPPER_ACR_DM_48   0x04 /* fs = 48kHz */
 
#define SNAPPER_ACR_DM_44   0x08 /* fs = 44.1kHz */
 
#define SNAPPER_ACR_INP   0x02 /* Analog input select */
 
#define SNAPPER_ACR_INP_A   0x00 /* A */
 
#define SNAPPER_ACR_INP_B   0x02 /* B */
 
#define SNAPPER_ACR_APD   0x01 /* Analog power down */
 

Functions

static int snapper_probe (device_t)
 
static int snapper_attach (device_t)
 
static int snapper_init (struct snd_mixer *m)
 
static int snapper_uninit (struct snd_mixer *m)
 
static int snapper_reinit (struct snd_mixer *m)
 
static int snapper_set (struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
 
static u_int32_t snapper_setrecsrc (struct snd_mixer *m, u_int32_t src)
 
 DRIVER_MODULE (snapper, iicbus, snapper_driver, snapper_devclass, 0, 0)
 
 MODULE_VERSION (snapper, 1)
 
 MODULE_DEPEND (snapper, iicbus, 1, 1, 1)
 
 MIXER_DECLARE (snapper_mixer)
 
static int snapper_write (struct snapper_softc *sc, uint8_t reg, const void *data)
 

Variables

kobj_class_t i2s_mixer_class
 
device_t i2s_mixer
 
static device_method_t snapper_methods []
 
static driver_t snapper_driver
 
static devclass_t snapper_devclass
 
static kobj_method_t snapper_mixer_methods []
 
static const struct snapper_reg snapper_initdata
 
static const char snapper_regsize []
 
static u_int snapper_volume_table [100]
 

Macro Definition Documentation

◆ SNAPPER_ACR

#define SNAPPER_ACR   0x40 /* Analog control register (1byte) */

Definition at line 164 of file snapper.c.

◆ SNAPPER_ACR_ADM

#define SNAPPER_ACR_ADM   0x80 /* ADC output mode */

Definition at line 181 of file snapper.c.

◆ SNAPPER_ACR_APD

#define SNAPPER_ACR_APD   0x01 /* Analog power down */

Definition at line 190 of file snapper.c.

◆ SNAPPER_ACR_DM

#define SNAPPER_ACR_DM   0x0c /* De-emphasis control */

Definition at line 183 of file snapper.c.

◆ SNAPPER_ACR_DM_44

#define SNAPPER_ACR_DM_44   0x08 /* fs = 44.1kHz */

Definition at line 186 of file snapper.c.

◆ SNAPPER_ACR_DM_48

#define SNAPPER_ACR_DM_48   0x04 /* fs = 48kHz */

Definition at line 185 of file snapper.c.

◆ SNAPPER_ACR_DM_OFF

#define SNAPPER_ACR_DM_OFF   0x00 /* off */

Definition at line 184 of file snapper.c.

◆ SNAPPER_ACR_INP

#define SNAPPER_ACR_INP   0x02 /* Analog input select */

Definition at line 187 of file snapper.c.

◆ SNAPPER_ACR_INP_A

#define SNAPPER_ACR_INP_A   0x00 /* A */

Definition at line 188 of file snapper.c.

◆ SNAPPER_ACR_INP_B

#define SNAPPER_ACR_INP_B   0x02 /* B */

Definition at line 189 of file snapper.c.

◆ SNAPPER_ACR_LRB

#define SNAPPER_ACR_LRB   0x40 /* Select B input */

Definition at line 182 of file snapper.c.

◆ SNAPPER_BASS

#define SNAPPER_BASS   0x06 /* Bass control (1byte) */

Definition at line 143 of file snapper.c.

◆ SNAPPER_DRC

#define SNAPPER_DRC   0x02 /* Dynamic range compression (6bytes) */

Definition at line 140 of file snapper.c.

◆ SNAPPER_IICADDR

#define SNAPPER_IICADDR   0x6a /* Hard-coded I2C slave addr */

Definition at line 136 of file snapper.c.

◆ SNAPPER_LB0

#define SNAPPER_LB0   0x0a /* Left biquad 0 (15bytes) */

Definition at line 146 of file snapper.c.

◆ SNAPPER_LB1

#define SNAPPER_LB1   0x0b /* Left biquad 1 (15bytes) */

Definition at line 147 of file snapper.c.

◆ SNAPPER_LB2

#define SNAPPER_LB2   0x0c /* Left biquad 2 (15bytes) */

Definition at line 148 of file snapper.c.

◆ SNAPPER_LB3

#define SNAPPER_LB3   0x0d /* Left biquad 3 (15bytes) */

Definition at line 149 of file snapper.c.

◆ SNAPPER_LB4

#define SNAPPER_LB4   0x0e /* Left biquad 4 (15bytes) */

Definition at line 150 of file snapper.c.

◆ SNAPPER_LB5

#define SNAPPER_LB5   0x0f /* Left biquad 5 (15bytes) */

Definition at line 151 of file snapper.c.

◆ SNAPPER_LB6

#define SNAPPER_LB6   0x10 /* Left biquad 6 (15bytes) */

Definition at line 152 of file snapper.c.

◆ SNAPPER_LLB

#define SNAPPER_LLB   0x21 /* Left loudness biquad (15bytes) */

Definition at line 160 of file snapper.c.

◆ SNAPPER_LLB_GAIN

#define SNAPPER_LLB_GAIN   0x23 /* Left loudness biquad gain (3bytes) */

Definition at line 162 of file snapper.c.

◆ SNAPPER_MCR1

#define SNAPPER_MCR1   0x01 /* Main control register 1 (1byte) */

Definition at line 139 of file snapper.c.

◆ SNAPPER_MCR1_FL

#define SNAPPER_MCR1_FL   0x80 /* Fast load */

Definition at line 166 of file snapper.c.

◆ SNAPPER_MCR1_SC

#define SNAPPER_MCR1_SC   0x40 /* SCLK frequency */

Definition at line 167 of file snapper.c.

◆ SNAPPER_MCR1_SC_32

#define SNAPPER_MCR1_SC_32   0x00 /* 32fs */

Definition at line 168 of file snapper.c.

◆ SNAPPER_MCR1_SC_64

#define SNAPPER_MCR1_SC_64   0x40 /* 64fs */

Definition at line 169 of file snapper.c.

◆ SNAPPER_MCR1_SM

#define SNAPPER_MCR1_SM   0x30 /* Output serial port mode */

Definition at line 170 of file snapper.c.

◆ SNAPPER_MCR1_SM_I2S

#define SNAPPER_MCR1_SM_I2S   0x20 /* I2S */

Definition at line 173 of file snapper.c.

◆ SNAPPER_MCR1_SM_L

#define SNAPPER_MCR1_SM_L   0x00 /* Left justified */

Definition at line 171 of file snapper.c.

◆ SNAPPER_MCR1_SM_R

#define SNAPPER_MCR1_SM_R   0x10 /* Right justified */

Definition at line 172 of file snapper.c.

◆ SNAPPER_MCR1_W

#define SNAPPER_MCR1_W   0x03 /* Serial port word length */

Definition at line 174 of file snapper.c.

◆ SNAPPER_MCR1_W_16

#define SNAPPER_MCR1_W_16   0x00 /* 16 bit */

Definition at line 175 of file snapper.c.

◆ SNAPPER_MCR1_W_18

#define SNAPPER_MCR1_W_18   0x01 /* 18 bit */

Definition at line 176 of file snapper.c.

◆ SNAPPER_MCR1_W_20

#define SNAPPER_MCR1_W_20   0x02 /* 20 bit */

Definition at line 177 of file snapper.c.

◆ SNAPPER_MCR1_W_24

#define SNAPPER_MCR1_W_24   0x03 /* 24 bit */

Definition at line 178 of file snapper.c.

◆ SNAPPER_MCR2

#define SNAPPER_MCR2   0x43 /* Main control register 2 (1byte) */

Definition at line 165 of file snapper.c.

◆ SNAPPER_MCR2_AP

#define SNAPPER_MCR2_AP   0x02 /* All pass mode */

Definition at line 180 of file snapper.c.

◆ SNAPPER_MCR2_DL

#define SNAPPER_MCR2_DL   0x80 /* Download */

Definition at line 179 of file snapper.c.

◆ SNAPPER_MIXER_L

#define SNAPPER_MIXER_L   0x07 /* Mixer left gain (9bytes) */

Definition at line 144 of file snapper.c.

◆ SNAPPER_MIXER_R

#define SNAPPER_MIXER_R   0x08 /* Mixer right gain (9bytes) */

Definition at line 145 of file snapper.c.

◆ SNAPPER_RB0

#define SNAPPER_RB0   0x13 /* Right biquad 0 (15bytes) */

Definition at line 153 of file snapper.c.

◆ SNAPPER_RB1

#define SNAPPER_RB1   0x14 /* Right biquad 1 (15bytes) */

Definition at line 154 of file snapper.c.

◆ SNAPPER_RB2

#define SNAPPER_RB2   0x15 /* Right biquad 2 (15bytes) */

Definition at line 155 of file snapper.c.

◆ SNAPPER_RB3

#define SNAPPER_RB3   0x16 /* Right biquad 3 (15bytes) */

Definition at line 156 of file snapper.c.

◆ SNAPPER_RB4

#define SNAPPER_RB4   0x17 /* Right biquad 4 (15bytes) */

Definition at line 157 of file snapper.c.

◆ SNAPPER_RB5

#define SNAPPER_RB5   0x18 /* Right biquad 5 (15bytes) */

Definition at line 158 of file snapper.c.

◆ SNAPPER_RB6

#define SNAPPER_RB6   0x19 /* Right biquad 6 (15bytes) */

Definition at line 159 of file snapper.c.

◆ SNAPPER_RLB

#define SNAPPER_RLB   0x22 /* Right loudness biquad (15bytes) */

Definition at line 161 of file snapper.c.

◆ SNAPPER_RLB_GAIN

#define SNAPPER_RLB_GAIN   0x24 /* Right loudness biquad gain (3bytes) */

Definition at line 163 of file snapper.c.

◆ SNAPPER_TREBLE

#define SNAPPER_TREBLE   0x05 /* Treble control (1byte) */

Definition at line 142 of file snapper.c.

◆ SNAPPER_VOLUME

#define SNAPPER_VOLUME   0x04 /* Volume (6bytes) */

Definition at line 141 of file snapper.c.

Function Documentation

◆ DRIVER_MODULE()

DRIVER_MODULE ( snapper  ,
iicbus  ,
snapper_driver  ,
snapper_devclass  ,
,
 
)

◆ MIXER_DECLARE()

MIXER_DECLARE ( snapper_mixer  )

◆ MODULE_DEPEND()

MODULE_DEPEND ( snapper  ,
iicbus  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( snapper  ,
 
)

◆ snapper_attach()

static int snapper_attach ( device_t  dev)
static

Definition at line 369 of file snapper.c.

References dev, i2s_mixer, i2s_mixer_class, snapper_softc::sc_addr, and snapper_softc::sc_dev.

◆ snapper_init()

◆ snapper_probe()

static int snapper_probe ( device_t  dev)
static

Definition at line 345 of file snapper.c.

References dev, name, and SNAPPER_IICADDR.

◆ snapper_reinit()

static int snapper_reinit ( struct snd_mixer m)
static

Definition at line 433 of file snapper.c.

◆ snapper_set()

static int snapper_set ( struct snd_mixer m,
unsigned  dev,
unsigned  left,
unsigned  right 
)
static

Definition at line 439 of file snapper.c.

References dev, left, m, mix_getdevinfo(), mixer_get_lock(), r, reg, right, SNAPPER_VOLUME, snapper_volume_table, and snapper_write().

Here is the call graph for this function:

◆ snapper_setrecsrc()

static u_int32_t snapper_setrecsrc ( struct snd_mixer m,
u_int32_t  src 
)
static

Definition at line 488 of file snapper.c.

◆ snapper_uninit()

static int snapper_uninit ( struct snd_mixer m)
static

Definition at line 427 of file snapper.c.

◆ snapper_write()

static int snapper_write ( struct snapper_softc sc,
uint8_t  reg,
const void *  data 
)
static

Definition at line 324 of file snapper.c.

References buf, data, reg, snapper_softc::sc_addr, snapper_softc::sc_dev, size, and snapper_regsize.

Referenced by snapper_init(), and snapper_set().

Here is the caller graph for this function:

Variable Documentation

◆ i2s_mixer

device_t i2s_mixer
extern

Definition at line 108 of file i2s.c.

Referenced by snapper_attach().

◆ i2s_mixer_class

kobj_class_t i2s_mixer_class
extern

Definition at line 107 of file i2s.c.

Referenced by snapper_attach().

◆ snapper_devclass

devclass_t snapper_devclass
static

Definition at line 119 of file snapper.c.

◆ snapper_driver

driver_t snapper_driver
static
Initial value:
= {
"snapper",
sizeof(struct snapper_softc)
}
static device_method_t snapper_methods[]
Definition: snapper.c:107

Definition at line 114 of file snapper.c.

◆ snapper_initdata

const struct snapper_reg snapper_initdata
static
Initial value:
= {
{ 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0 },
{ 0x72 },
{ 0x72 },
{ 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0 },
{ 0, 0, 0 },
}
#define SNAPPER_MCR1_W_16
Definition: snapper.c:175
#define SNAPPER_MCR1_SC_64
Definition: snapper.c:169
#define SNAPPER_MCR1_SM_I2S
Definition: snapper.c:173
#define SNAPPER_ACR_ADM
Definition: snapper.c:181
#define SNAPPER_MCR2_AP
Definition: snapper.c:180
#define SNAPPER_ACR_LRB
Definition: snapper.c:182
#define SNAPPER_ACR_INP_B
Definition: snapper.c:189

Definition at line 222 of file snapper.c.

Referenced by snapper_init().

◆ snapper_methods

device_method_t snapper_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, snapper_probe),
DEVMETHOD(device_attach, snapper_attach),
{ 0, 0 }
}
static int snapper_attach(device_t)
Definition: snapper.c:369
static int snapper_probe(device_t)
Definition: snapper.c:345

Definition at line 107 of file snapper.c.

◆ snapper_mixer_methods

kobj_method_t snapper_mixer_methods[]
static
Initial value:
= {
KOBJMETHOD(mixer_init, snapper_init),
KOBJMETHOD(mixer_set, snapper_set),
}
#define KOBJMETHOD_END
Definition: midi.c:76
static int mixer_setrecsrc(struct snd_mixer *mixer, u_int32_t src)
Definition: mixer.c:373
int mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
Definition: mixer.c:725
static int mixer_set(struct snd_mixer *m, u_int dev, u_int32_t muted, u_int lev)
Definition: mixer.c:247
int mixer_uninit(device_t dev)
Definition: mixer.c:805
int mixer_reinit(device_t dev)
Definition: mixer.c:860
static int snapper_init(struct snd_mixer *m)
Definition: snapper.c:384
static u_int32_t snapper_setrecsrc(struct snd_mixer *m, u_int32_t src)
Definition: snapper.c:488
static int snapper_reinit(struct snd_mixer *m)
Definition: snapper.c:433
static int snapper_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
Definition: snapper.c:439
static int snapper_uninit(struct snd_mixer *m)
Definition: snapper.c:427

Definition at line 125 of file snapper.c.

◆ snapper_regsize

const char snapper_regsize[]
static

Definition at line 253 of file snapper.c.

Referenced by snapper_write().

◆ snapper_volume_table

u_int snapper_volume_table[100]
static
Initial value:
= {
0x00000148, 0x0000015C, 0x00000171, 0x00000186,
0x0000019E, 0x000001B6, 0x000001D0, 0x000001EB,
0x00000209, 0x00000227, 0x00000248, 0x0000026B,
0x0000028F, 0x000002B6, 0x000002DF, 0x0000030B,
0x00000339, 0x0000036A, 0x0000039E, 0x000003D5,
0x0000040F, 0x0000044C, 0x0000048D, 0x000004D2,
0x0000051C, 0x00000569, 0x000005BB, 0x00000612,
0x0000066E, 0x000006D0, 0x00000737, 0x000007A5,
0x00000818, 0x00000893, 0x00000915, 0x0000099F,
0x00000A31, 0x00000ACC, 0x00000B6F, 0x00000C1D,
0x00000CD5, 0x00000D97, 0x00000E65, 0x00000F40,
0x00001027, 0x0000111C, 0x00001220, 0x00001333,
0x00001456, 0x0000158A, 0x000016D1, 0x0000182B,
0x0000199A, 0x00001B1E, 0x00001CB9, 0x00001E6D,
0x0000203A, 0x00002223, 0x00002429, 0x0000264E,
0x00002893, 0x00002AFA, 0x00002D86, 0x00003039,
0x00003314, 0x0000361B, 0x00003950, 0x00003CB5,
0x0000404E, 0x0000441D, 0x00004827, 0x00004C6D,
0x000050F4, 0x000055C0, 0x00005AD5, 0x00006037,
0x000065EA, 0x00006BF4, 0x0000725A, 0x00007920,
0x0000804E, 0x000087EF, 0x00008FF6, 0x0000987D,
0x0000A186, 0x0000AB19, 0x0000B53C, 0x0000BFF9,
0x0000CB59, 0x0000D766, 0x0000E429, 0x0000F1AE,
0x00010000, 0x00010F2B, 0x00011F3D, 0x00013042,
0x00014249, 0x00015562, 0x0001699C, 0x00017F09
}

Definition at line 295 of file snapper.c.

Referenced by snapper_set().