#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: snapper.c,v 1.70 2025/09/08 08:06:19 macallan Exp $");
#include <sys/param.h>
#include <sys/audioio.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <dev/audio/audio_if.h>
#include <dev/ofw/openfirm.h>
#include <macppc/dev/dbdma.h>
#include <uvm/uvm_extern.h>
#include <dev/i2c/i2cvar.h>
#include <dev/onewire/onewirevar.h>
#include <machine/autoconf.h>
#include <machine/pio.h>
#include <macppc/dev/deqvar.h>
#include <macppc/dev/obiovar.h>
#include <macppc/dev/i2sreg.h>
#include "opt_snapper.h"
#ifdef SNAPPER_DEBUG
# define DPRINTF printf
#else
# define DPRINTF while (0) printf
#endif
#define SNAPPER_MAXPAGES 16
struct snapper_softc {
device_t sc_dev;
int sc_mode;
#define SNAPPER_IS_TAS3004 0
#define SNAPPER_IS_TAS3001 1
#define SNAPPER_IS_PCM3052 2
#define SNAPPER_IS_CS8416 3
#define SNAPPER_SWVOL 4
int sc_node;
void (*sc_ointr)(void *);
void *sc_oarg;
int sc_opages;
void (*sc_iintr)(void *);
void *sc_iarg;
int sc_ipages;
u_int sc_record_source;
u_int sc_output_mask;
bus_space_tag_t sc_tag;
bus_space_handle_t sc_bsh;
i2c_addr_t sc_deqaddr;
i2c_tag_t sc_i2c;
uint32_t sc_baseaddr;
int sc_rate;
int sc_bitspersample;
u_int sc_swvol_l;
u_int sc_swvol_r;
u_int sc_vol_l;
u_int sc_vol_r;
u_int sc_treble;
u_int sc_bass;
u_int mixer[6];
uint16_t sc_rval;
bus_space_handle_t sc_odmah;
bus_space_handle_t sc_idmah;
dbdma_regmap_t *sc_odma;
dbdma_regmap_t *sc_idma;
unsigned char dbdma_cmdspace[sizeof(struct dbdma_command) * 40 + 15];
struct dbdma_command *sc_odmacmd;
struct dbdma_command *sc_idmacmd;
kmutex_t sc_lock;
kmutex_t sc_intr_lock;
struct onewire_bus sc_ow_bus;
device_t sc_ow_dev;
int sc_ow_data;
};
static int snapper_match(device_t, struct cfdata *, void *);
static void snapper_attach(device_t, device_t, void *);
static void snapper_defer(device_t);
static int snapper_intr(void *);
static int snapper_query_format(void *, audio_format_query_t *);
static int snapper_set_format(void *, int,
const audio_params_t *, const audio_params_t *,
audio_filter_reg_t *, audio_filter_reg_t *);
static int snapper_commit_settings(void *);
static int snapper_round_blocksize(void *, int, int, const audio_params_t *);
static int snapper_halt_output(void *);
static int snapper_halt_input(void *);
static int snapper_getdev(void *, struct audio_device *);
static int snapper_set_port(void *, mixer_ctrl_t *);
static int snapper_get_port(void *, mixer_ctrl_t *);
static int snapper_query_devinfo(void *, mixer_devinfo_t *);
static size_t snapper_round_buffersize(void *, int, size_t);
static int snapper_get_props(void *);
static int snapper_trigger_output(void *, void *, void *, int, void (*)(void *),
void *, const audio_params_t *);
static int snapper_trigger_input(void *, void *, void *, int, void (*)(void *),
void *, const audio_params_t *);
static void snapper_get_locks(void *, kmutex_t **, kmutex_t **);
static void snapper_set_volume(struct snapper_softc *, u_int, u_int);
static int snapper_set_rate(struct snapper_softc *);
static void snapper_set_treble(struct snapper_softc *, u_int);
static void snapper_set_bass(struct snapper_softc *, u_int);
static void snapper_write_mixers(struct snapper_softc *);
static int tas3004_write(struct snapper_softc *, u_int, const void *);
static int gpio_read(bus_size_t);
static void gpio_write(bus_size_t, int);
static void snapper_mute_speaker(struct snapper_softc *, int);
static void snapper_mute_headphone(struct snapper_softc *, int);
static void snapper_mute_lineout(struct snapper_softc *, int);
static int snapper_cint(void *);
static int tas3004_init(struct snapper_softc *);
static void snapper_init(struct snapper_softc *, int);
static void snapper_setup_ow(struct snapper_softc *);
static int snapper_ow_reset(void *);
static int snapper_ow_read_bit(void *);
static void snapper_ow_write_bit(void *, int);
static void snapper_bb_rx(void *);
static void snapper_bb_tx(void *);
static int snapper_bb_get(void *);
static void snapper_bb_set(void *, int);
static const struct onewire_bbops snapper_bbops = {
snapper_bb_rx,
snapper_bb_tx,
snapper_bb_get,
snapper_bb_set
};
static void
snapper_volume(audio_filter_arg_t *arg)
{
struct snapper_softc *sc;
const aint_t *src;
int16_t *dst;
u_int sample_count;
u_int i;
sc = arg->context;
src = arg->src;
dst = arg->dst;
sample_count = arg->count * arg->srcfmt->channels;
for (i = 0; i < sample_count; i++) {
aint2_t l = (aint2_t)(*src++);
l = l * sc->sc_swvol_l / 255;
*dst++ = (aint_t)l;
}
}
static void
snapper_fixphase(audio_filter_arg_t *arg)
{
struct snapper_softc *sc;
const aint_t *src;
aint_t *dst;
u_int i;
sc = arg->context;
src = arg->src;
dst = arg->dst;
for (i = 0; i < arg->count; i++) {
*dst++ = *src++;
*dst++ = sc->sc_rval;
sc->sc_rval = *src++;
}
}
CFATTACH_DECL_NEW(snapper, sizeof(struct snapper_softc), snapper_match,
snapper_attach, NULL, NULL);
const struct audio_hw_if snapper_hw_if = {
.query_format = snapper_query_format,
.set_format = snapper_set_format,
.commit_settings = snapper_commit_settings,
.round_blocksize = snapper_round_blocksize,
.halt_output = snapper_halt_output,
.halt_input = snapper_halt_input,
.getdev = snapper_getdev,
.set_port = snapper_set_port,
.get_port = snapper_get_port,
.query_devinfo = snapper_query_devinfo,
.round_buffersize = snapper_round_buffersize,
.get_props = snapper_get_props,
.trigger_output = snapper_trigger_output,
.trigger_input = snapper_trigger_input,
.get_locks = snapper_get_locks,
};
struct audio_device snapper_device = {
"SNAPPER",
"",
"snapper"
};
#define SNAPPER_BASSTAB_0DB 18
const uint8_t snapper_basstab[] = {
0x96,
0x94,
0x92,
0x90,
0x8e,
0x8c,
0x8a,
0x88,
0x86,
0x84,
0x82,
0x80,
0x7e,
0x7c,
0x7a,
0x78,
0x76,
0x74,
0x72,
0x6f,
0x6d,
0x6a,
0x67,
0x65,
0x62,
0x5f,
0x5b,
0x55,
0x4f,
0x49,
0x43,
0x3b,
0x33,
0x29,
0x1e,
0x11,
0x01,
};
#define SNAPPER_MIXER_GAIN_0DB 36
const uint8_t snapper_mixer_gain[178][3] = {
{ 0x7f, 0x17, 0xaf },
{ 0x77, 0xfb, 0xaa },
{ 0x71, 0x45, 0x75 },
{ 0x6a, 0xef, 0x5d },
{ 0x64, 0xf4, 0x03 },
{ 0x5f, 0x4e, 0x52 },
{ 0x59, 0xf9, 0x80 },
{ 0x54, 0xf1, 0x06 },
{ 0x50, 0x30, 0xa1 },
{ 0x4b, 0xb4, 0x46 },
{ 0x47, 0x78, 0x28 },
{ 0x43, 0x78, 0xb0 },
{ 0x3f, 0xb2, 0x78 },
{ 0x3c, 0x22, 0x4c },
{ 0x38, 0xc5, 0x28 },
{ 0x35, 0x98, 0x2f },
{ 0x32, 0x98, 0xb0 },
{ 0x2f, 0xc4, 0x20 },
{ 0x2d, 0x18, 0x18 },
{ 0x2a, 0x92, 0x54 },
{ 0x28, 0x30, 0xaf },
{ 0x25, 0xf1, 0x25 },
{ 0x23, 0xd1, 0xcd },
{ 0x21, 0xd0, 0xd9 },
{ 0x1f, 0xec, 0x98 },
{ 0x1e, 0x23, 0x6d },
{ 0x1c, 0x73, 0xd5 },
{ 0x1a, 0xdc, 0x61 },
{ 0x19, 0x5b, 0xb8 },
{ 0x17, 0xf0, 0x94 },
{ 0x16, 0x99, 0xc0 },
{ 0x15, 0x56, 0x1a },
{ 0x14, 0x24, 0x8e },
{ 0x13, 0x04, 0x1a },
{ 0x11, 0xf3, 0xc9 },
{ 0x10, 0xf2, 0xb4 },
{ 0x10, 0x00, 0x00 },
{ 0x0f, 0x1a, 0xdf },
{ 0x0e, 0x42, 0x90 },
{ 0x0d, 0x76, 0x5a },
{ 0x0c, 0xb5, 0x91 },
{ 0x0b, 0xff, 0x91 },
{ 0x0b, 0x53, 0xbe },
{ 0x0a, 0xb1, 0x89 },
{ 0x0a, 0x18, 0x66 },
{ 0x09, 0x87, 0xd5 },
{ 0x08, 0xff, 0x59 },
{ 0x08, 0x7e, 0x80 },
{ 0x08, 0x04, 0xdc },
{ 0x07, 0x92, 0x07 },
{ 0x07, 0x25, 0x9d },
{ 0x06, 0xbf, 0x44 },
{ 0x06, 0x5e, 0xa5 },
{ 0x06, 0x03, 0x6e },
{ 0x05, 0xad, 0x50 },
{ 0x05, 0x5c, 0x04 },
{ 0x05, 0x0f, 0x44 },
{ 0x04, 0xc6, 0xd0 },
{ 0x04, 0x82, 0x68 },
{ 0x04, 0x41, 0xd5 },
{ 0x04, 0x04, 0xde },
{ 0x03, 0xcb, 0x50 },
{ 0x03, 0x94, 0xfa },
{ 0x03, 0x61, 0xaf },
{ 0x03, 0x31, 0x42 },
{ 0x03, 0x03, 0x8a },
{ 0x02, 0xd8, 0x62 },
{ 0x02, 0xaf, 0xa3 },
{ 0x02, 0x89, 0x2c },
{ 0x02, 0x64, 0xdb },
{ 0x02, 0x42, 0x93 },
{ 0x02, 0x22, 0x35 },
{ 0x02, 0x03, 0xa7 },
{ 0x01, 0xe6, 0xcf },
{ 0x01, 0xcb, 0x94 },
{ 0x01, 0xb1, 0xde },
{ 0x01, 0x99, 0x99 },
{ 0x01, 0x82, 0xaf },
{ 0x01, 0x6d, 0x0e },
{ 0x01, 0x58, 0xa2 },
{ 0x01, 0x45, 0x5b },
{ 0x01, 0x33, 0x28 },
{ 0x01, 0x21, 0xf9 },
{ 0x01, 0x11, 0xc0 },
{ 0x01, 0x02, 0x70 },
{ 0x00, 0xf3, 0xfb },
{ 0x00, 0xe6, 0x55 },
{ 0x00, 0xd9, 0x73 },
{ 0x00, 0xcd, 0x49 },
{ 0x00, 0xc1, 0xcd },
{ 0x00, 0xb6, 0xf6 },
{ 0x00, 0xac, 0xba },
{ 0x00, 0xa3, 0x10 },
{ 0x00, 0x99, 0xf1 },
{ 0x00, 0x91, 0x54 },
{ 0x00, 0x89, 0x33 },
{ 0x00, 0x81, 0x86 },
{ 0x00, 0x7a, 0x48 },
{ 0x00, 0x73, 0x70 },
{ 0x00, 0x6c, 0xfb },
{ 0x00, 0x66, 0xe3 },
{ 0x00, 0x61, 0x21 },
{ 0x00, 0x5b, 0xb2 },
{ 0x00, 0x56, 0x91 },
{ 0x00, 0x51, 0xb9 },
{ 0x00, 0x4d, 0x27 },
{ 0x00, 0x48, 0xd6 },
{ 0x00, 0x44, 0xc3 },
{ 0x00, 0x40, 0xea },
{ 0x00, 0x3d, 0x49 },
{ 0x00, 0x39, 0xdb },
{ 0x00, 0x36, 0x9e },
{ 0x00, 0x33, 0x90 },
{ 0x00, 0x30, 0xae },
{ 0x00, 0x2d, 0xf5 },
{ 0x00, 0x2b, 0x63 },
{ 0x00, 0x28, 0xf5 },
{ 0x00, 0x26, 0xab },
{ 0x00, 0x24, 0x81 },
{ 0x00, 0x22, 0x76 },
{ 0x00, 0x20, 0x89 },
{ 0x00, 0x1e, 0xb7 },
{ 0x00, 0x1c, 0xff },
{ 0x00, 0x1b, 0x60 },
{ 0x00, 0x19, 0xd8 },
{ 0x00, 0x18, 0x65 },
{ 0x00, 0x17, 0x08 },
{ 0x00, 0x15, 0xbe },
{ 0x00, 0x14, 0x87 },
{ 0x00, 0x13, 0x61 },
{ 0x00, 0x12, 0x4b },
{ 0x00, 0x11, 0x45 },
{ 0x00, 0x10, 0x4e },
{ 0x00, 0x0f, 0x64 },
{ 0x00, 0x0e, 0x88 },
{ 0x00, 0x0d, 0xb8 },
{ 0x00, 0x0c, 0xf3 },
{ 0x00, 0x0c, 0x3a },
{ 0x00, 0x0b, 0x8b },
{ 0x00, 0x0a, 0xe5 },
{ 0x00, 0x0a, 0x49 },
{ 0x00, 0x09, 0xb6 },
{ 0x00, 0x09, 0x2b },
{ 0x00, 0x08, 0xa8 },
{ 0x00, 0x08, 0x2c },
{ 0x00, 0x07, 0xb7 },
{ 0x00, 0x07, 0x48 },
{ 0x00, 0x06, 0xe0 },
{ 0x00, 0x06, 0x7d },
{ 0x00, 0x06, 0x20 },
{ 0x00, 0x05, 0xc9 },
{ 0x00, 0x05, 0x76 },
{ 0x00, 0x05, 0x28 },
{ 0x00, 0x04, 0xde },
{ 0x00, 0x04, 0x98 },
{ 0x00, 0x04, 0x56 },
{ 0x00, 0x04, 0x18 },
{ 0x00, 0x03, 0xdd },
{ 0x00, 0x03, 0xa6 },
{ 0x00, 0x03, 0x72 },
{ 0x00, 0x03, 0x40 },
{ 0x00, 0x03, 0x12 },
{ 0x00, 0x02, 0xe6 },
{ 0x00, 0x02, 0xbc },
{ 0x00, 0x02, 0x95 },
{ 0x00, 0x02, 0x70 },
{ 0x00, 0x02, 0x4d },
{ 0x00, 0x02, 0x2c },
{ 0x00, 0x02, 0x0d },
{ 0x00, 0x01, 0xf0 },
{ 0x00, 0x01, 0xd4 },
{ 0x00, 0x01, 0xba },
{ 0x00, 0x01, 0xa1 },
{ 0x00, 0x01, 0x8a },
{ 0x00, 0x01, 0x74 },
{ 0x00, 0x01, 0x5f },
{ 0x00, 0x01, 0x4b },
{ 0x00, 0x00, 0x00 }
};
static const struct audio_format snapper_formats[] = {
{
.mode = AUMODE_PLAY | AUMODE_RECORD,
.encoding = AUDIO_ENCODING_SLINEAR_BE,
.validbits = 16,
.precision = 16,
.channels = 2,
.channel_mask = AUFMT_STEREO,
.frequency_type = 3,
.frequency = { 32000, 44100, 48000 },
}
};
#define SNAPPER_NFORMATS __arraycount(snapper_formats)
static const struct audio_format tumbler_formats[] = {
{
.mode = AUMODE_PLAY | AUMODE_RECORD,
.encoding = AUDIO_ENCODING_SLINEAR_BE,
.validbits = 16,
.precision = 16,
.channels = 2,
.channel_mask = AUFMT_STEREO,
.frequency_type = 4,
.frequency = { 32000, 44100, 48000, 96000 },
},
};
#define TUMBLER_NFORMATS __arraycount(tumbler_formats)
static const struct audio_format onyx_formats[] = {
{
.mode = AUMODE_PLAY | AUMODE_RECORD,
.encoding = AUDIO_ENCODING_SLINEAR_BE,
.validbits = 16,
.precision = 16,
.channels = 2,
.channel_mask = AUFMT_STEREO,
.frequency_type = 3,
.frequency = { 44100, 48000, 96000 },
},
};
#define ONYX_NFORMATS __arraycount(onyx_formats)
static bus_size_t amp_mute;
static bus_size_t headphone_mute = 0;
static bus_size_t audio_hw_reset;
static bus_size_t headphone_detect = 0;
static bus_size_t lineout_detect = 0;
static bus_size_t lineout_mute= 0;
static bus_size_t owaddr = -1;
static uint8_t headphone_detect_active = 0;
static uint8_t lineout_detect_active = 0;
#define DEQ_MCR1 0x01
#define DEQ_DRC 0x02
#define DEQ_VOLUME 0x04
#define DEQ_TREBLE 0x05
#define DEQ_BASS 0x06
#define DEQ_MIXER_L 0x07
#define DEQ_MIXER_R 0x08
#define DEQ_LB0 0x0a
#define DEQ_LB1 0x0b
#define DEQ_LB2 0x0c
#define DEQ_LB3 0x0d
#define DEQ_LB4 0x0e
#define DEQ_LB5 0x0f
#define DEQ_LB6 0x10
#define DEQ_RB0 0x13
#define DEQ_RB1 0x14
#define DEQ_RB2 0x15
#define DEQ_RB3 0x16
#define DEQ_RB4 0x17
#define DEQ_RB5 0x18
#define DEQ_RB6 0x19
#define DEQ_LLB 0x21
#define DEQ_RLB 0x22
#define DEQ_LLB_GAIN 0x23
#define DEQ_RLB_GAIN 0x24
#define DEQ_ACR 0x40
#define DEQ_MCR2 0x43
#define DEQ_MCR1_FL 0x80
#define DEQ_MCR1_SC 0x40
#define DEQ_MCR1_SC_32 0x00
#define DEQ_MCR1_SC_64 0x40
#define DEQ_MCR1_SM 0x30
#define DEQ_MCR1_SM_L 0x00
#define DEQ_MCR1_SM_R 0x10
#define DEQ_MCR1_SM_I2S 0x20
#define DEQ_MCR1_ISM 0x0c
#define DEQ_MCR1_ISM_L 0x00
#define DEQ_MCR1_ISM_R 0x04
#define DEQ_MCR1_ISM_I2S 0x08
#define DEQ_MCR1_W 0x03
#define DEQ_MCR1_W_16 0x00
#define DEQ_MCR1_W_18 0x01
#define DEQ_MCR1_W_20 0x02
#define DEQ_MCR1_W_24 0x03
#define DEQ_MCR2_DL 0x80
#define DEQ_MCR2_AP 0x02
#define DEQ_ACR_ADM 0x80
#define DEQ_ACR_LRB 0x40
#define DEQ_ACR_DM 0x0c
#define DEQ_ACR_DM_OFF 0x00
#define DEQ_ACR_DM_48 0x04
#define DEQ_ACR_DM_44 0x08
#define DEQ_ACR_INP 0x02
#define DEQ_ACR_INP_A 0x00
#define DEQ_ACR_INP_B 0x02
#define DEQ_ACR_APD 0x01
struct tas3004_reg {
u_char MCR1[1];
u_char DRC[6];
u_char VOLUME[6];
u_char TREBLE[1];
u_char BASS[1];
u_char MIXER_L[9];
u_char MIXER_R[9];
u_char LB0[15];
u_char LB1[15];
u_char LB2[15];
u_char LB3[15];
u_char LB4[15];
u_char LB5[15];
u_char LB6[15];
u_char RB0[15];
u_char RB1[15];
u_char RB2[15];
u_char RB3[15];
u_char RB4[15];
u_char RB5[15];
u_char RB6[15];
u_char LLB[15];
u_char RLB[15];
u_char LLB_GAIN[3];
u_char RLB_GAIN[3];
u_char ACR[1];
u_char MCR2[1];
};
static int
snapper_match(device_t parent, struct cfdata *match, void *aux)
{
struct confargs *ca;
int soundbus, soundchip, soundcodec;
char compat[32];
ca = aux;
if (strcmp(ca->ca_name, "i2s") != 0)
return 0;
if ((soundbus = OF_child(ca->ca_node)) == 0 ||
(soundchip = OF_child(soundbus)) == 0)
return 0;
memset(compat, 0, sizeof compat);
OF_getprop(soundchip, "compatible", compat, sizeof compat);
if (strcmp(compat, "snapper") == 0)
return 1;
if (strcmp(compat, "tumbler") == 0)
return 1;
if (strcmp(compat, "AOAKeylargo") == 0)
return 1;
if (strcmp(compat, "AOAK2") == 0)
return 1;
if (strcmp(compat, "AOAShasta") == 0)
return 1;
if (strcmp(compat, "AOAbase") == 0)
return 1;
if (OF_getprop(soundchip, "platform-tas-codec-ref",
&soundcodec, sizeof soundcodec) == sizeof soundcodec)
return 1;
return 0;
}
static void
snapper_attach(device_t parent, device_t self, void *aux)
{
struct snapper_softc *sc;
struct confargs *ca;
int cirq, oirq, iirq, oirq_type, iirq_type, soundbus;
uint32_t intr[6], reg[6];
char compat[32], intr_xname[INTRDEVNAMEBUF];
sc = device_private(self);
sc->sc_dev = self;
ca = aux;
soundbus = OF_child(ca->ca_node);
memset(compat, 0, sizeof compat);
OF_getprop(OF_child(soundbus), "compatible", compat, sizeof compat);
sc->sc_mode = SNAPPER_IS_TAS3004;
if (strcmp(compat, "tumbler") == 0)
sc->sc_mode = SNAPPER_IS_TAS3001;
sc->sc_swvol_l = 255;
sc->sc_swvol_r = 255;
sc->sc_vol_l = 128;
sc->sc_vol_r = 128;
sc->sc_rval = 0;
sc->sc_odmacmd = dbdma_alloc((SNAPPER_MAXPAGES + 4) *
sizeof(struct dbdma_command), NULL);
sc->sc_idmacmd = dbdma_alloc((SNAPPER_MAXPAGES + 4) *
sizeof(struct dbdma_command), NULL);
sc->sc_baseaddr = ca->ca_baseaddr;
OF_getprop(soundbus, "reg", reg, sizeof reg);
if (reg[0] == 0) {
reg[0] += ca->ca_reg[0];
reg[2] += ca->ca_reg[2];
reg[4] += ca->ca_reg[2];
}
reg[0] += ca->ca_baseaddr;
reg[2] += ca->ca_baseaddr;
reg[4] += ca->ca_baseaddr;
sc->sc_node = ca->ca_node;
sc->sc_tag = ca->ca_tag;
#ifdef SNAPPER_DEBUG
{
int i;
printf("\n");
for (i = 0; i < 6; i++) {
printf(" %08x", reg[i]);
}
printf("\n");
}
#endif
bus_space_map(sc->sc_tag, reg[0], reg[1], 0, &sc->sc_bsh);
obio_space_map(reg[2], reg[3], &sc->sc_odmah);
obio_space_map(reg[4], reg[5], &sc->sc_idmah);
sc->sc_odma = bus_space_vaddr(sc->sc_tag, sc->sc_odmah);
sc->sc_idma = bus_space_vaddr(sc->sc_tag, sc->sc_idmah);
DPRINTF("reg %08x odma %08x\n", (uint32_t)sc->sc_bsh, (uint32_t)sc->sc_odmah);
OF_getprop(soundbus, "interrupts", intr, sizeof intr);
cirq = intr[0];
oirq = intr[2];
iirq = intr[4];
oirq_type = (intr[3] & 1) ? IST_LEVEL : IST_EDGE;
iirq_type = (intr[5] & 1) ? IST_LEVEL : IST_EDGE;
snprintf(intr_xname, sizeof(intr_xname), "%s out", device_xname(self));
intr_establish_xname(oirq, oirq_type, IPL_AUDIO, snapper_intr, sc,
intr_xname);
snprintf(intr_xname, sizeof(intr_xname), "%s in", device_xname(self));
intr_establish_xname(iirq, iirq_type, IPL_AUDIO, snapper_intr, sc,
intr_xname);
aprint_normal(": irq %d,%d,%d\n", cirq, oirq, iirq);
mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_AUDIO);
pmf_device_register(sc->sc_dev, NULL, NULL);
config_defer(self, snapper_defer);
}
static void
snapper_defer(device_t dev)
{
struct snapper_softc *sc;
device_t dv;
deviter_t di;
struct deq_softc *deq;
char prop[64], next[64], codec[64], *cref;
int codec_node, soundbus, sound, ok, deqnode = 0;
sc = device_private(dev);
soundbus = OF_child(sc->sc_node);
sound = OF_child(soundbus);
ok = OF_nextprop(sound, NULL, next);
codec_node = 0;
while (ok && (codec_node == 0)) {
DPRINTF("prop %d %s\n", ok, next);
strncpy(prop, next, 64);
if ((cref = strstr(next, "-codec-ref")) != NULL) {
OF_getprop(sound, next, &codec_node, 4);
if (codec_node != 0) {
OF_getprop(codec_node, "compatible", codec, 64);
DPRINTF("%08x %s\n", codec_node, codec);
}
}
ok = OF_nextprop(sound, prop, next);
}
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dv != NULL;
dv = deviter_next(&di)) {
if (device_is_a(dv, "deq")) {
deq = device_private(dv);
if (codec_node != 0) {
if (codec_node != deq->sc_node)
continue;
}
sc->sc_i2c = deq->sc_i2c;
sc->sc_deqaddr = deq->sc_address;
deqnode = deq->sc_node;
}
}
deviter_release(&di);
DPRINTF("deqnode: %08x\n", deqnode);
if (sc->sc_i2c == NULL) {
sc->sc_mode = SNAPPER_SWVOL;
} else if (deqnode != 0) {
int ret;
codec[0] = 0;
ret = OF_getprop(deqnode, "compatible", codec, 64);
DPRINTF("codec <%s> %d\n", codec, ret);
if (codec[0] == 0) {
if (sc->sc_deqaddr == 0x34) {
sc->sc_mode = SNAPPER_IS_TAS3001;
} else {
int root = OF_finddevice("/");
char model[32];
sc->sc_mode = SNAPPER_IS_TAS3004;
if (OF_getprop(root, "model", model, 32) > 0) {
printf("model %s\n", model);
if (strcmp(model, "PowerMac8,1") == 0) {
sc->sc_mode = SNAPPER_IS_PCM3052;
}
}
}
} else if (strcmp(codec, "tas3004") == 0) {
sc->sc_mode = SNAPPER_IS_TAS3004;
} else if (strcmp(codec, "pcm3052") == 0) {
sc->sc_mode = SNAPPER_IS_PCM3052;
} else if (strcmp(codec, "cs8416") == 0) {
sc->sc_mode = SNAPPER_IS_CS8416;
}
}
DPRINTF("mode %d\n", sc->sc_mode);
switch (sc->sc_mode) {
case SNAPPER_SWVOL:
aprint_verbose("%s: software codec\n", device_xname(dev));
break;
case SNAPPER_IS_TAS3001:
aprint_verbose("%s: codec: TAS3001\n", device_xname(dev));
break;
case SNAPPER_IS_TAS3004:
aprint_verbose("%s: codec: TAS3004\n", device_xname(dev));
break;
case SNAPPER_IS_PCM3052:
aprint_verbose("%s: codec: PCM3052 / ONYX\n", device_xname(dev));
break;
default:
aprint_error_dev(sc->sc_dev, "unsupported codec\n");
sc->sc_mode = SNAPPER_SWVOL;
}
snapper_init(sc, sc->sc_node);
audio_attach_mi(&snapper_hw_if, sc, sc->sc_dev);
}
static int
snapper_intr(void *v)
{
struct snapper_softc *sc;
struct dbdma_command *cmd;
int count;
int status;
sc = v;
mutex_spin_enter(&sc->sc_intr_lock);
cmd = sc->sc_odmacmd;
count = sc->sc_opages;
while (count-- > 0) {
if ((in16rb(&cmd->d_command) & 0x30) == 0x30) {
status = in16rb(&cmd->d_status);
cmd->d_status = 0;
if (status)
if (sc->sc_ointr)
(*sc->sc_ointr)(sc->sc_oarg);
}
cmd++;
}
cmd = sc->sc_idmacmd;
count = sc->sc_ipages;
while (count-- > 0) {
if ((in16rb(&cmd->d_command) & 0x30) == 0x30) {
status = in16rb(&cmd->d_status);
cmd->d_status = 0;
if (status)
if (sc->sc_iintr)
(*sc->sc_iintr)(sc->sc_iarg);
}
cmd++;
}
mutex_spin_exit(&sc->sc_intr_lock);
return 1;
}
static int
snapper_query_format(void *h, audio_format_query_t *afp)
{
struct snapper_softc *sc = h;
switch (sc->sc_mode) {
case SNAPPER_IS_TAS3001:
return audio_query_format(tumbler_formats,
TUMBLER_NFORMATS, afp);
case SNAPPER_SWVOL:
case SNAPPER_IS_TAS3004:
return audio_query_format(snapper_formats,
SNAPPER_NFORMATS, afp);
case SNAPPER_IS_PCM3052:
return audio_query_format(onyx_formats,
ONYX_NFORMATS, afp);
}
return -1;
}
static int
snapper_set_format(void *h, int setmode,
const audio_params_t *play, const audio_params_t *rec,
audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
{
struct snapper_softc *sc;
sc = h;
if (sc->sc_mode == SNAPPER_SWVOL) {
pfil->codec = snapper_volume;
pfil->context = sc;
rfil->codec = snapper_volume;
rfil->context = sc;
} else if (sc->sc_mode == 0 && play->channels == 2) {
pfil->codec = snapper_fixphase;
pfil->context = sc;
rfil->codec = snapper_fixphase;
rfil->context = sc;
}
sc->sc_rate = play->sample_rate;
sc->sc_bitspersample = play->precision;
return 0;
}
static int
snapper_commit_settings(void *h)
{
struct snapper_softc *sc;
DPRINTF("commit_settings\n");
sc = h;
return snapper_set_rate(sc);
}
static int
snapper_round_blocksize(void *h, int size, int mode,
const audio_params_t *param)
{
if (size < (3 * NBPG))
size = (3 * NBPG);
return size & ~PGOFSET;
}
static int
snapper_halt_output(void *h)
{
struct snapper_softc *sc;
sc = h;
dbdma_stop(sc->sc_odma);
dbdma_reset(sc->sc_odma);
sc->sc_ointr = NULL;
sc->sc_rval = 0;
return 0;
}
static int
snapper_halt_input(void *h)
{
struct snapper_softc *sc;
sc = h;
dbdma_stop(sc->sc_idma);
dbdma_reset(sc->sc_idma);
sc->sc_iintr = NULL;
sc->sc_rval = 0;
return 0;
}
static int
snapper_getdev(void *h, struct audio_device *retp)
{
*retp = snapper_device;
return 0;
}
enum {
SNAPPER_MONITOR_CLASS,
SNAPPER_OUTPUT_CLASS,
SNAPPER_RECORD_CLASS,
SNAPPER_OUTPUT_SELECT,
SNAPPER_VOL_OUTPUT,
SNAPPER_DIGI1,
SNAPPER_DIGI2,
SNAPPER_VOL_INPUT,
SNAPPER_TREBLE,
SNAPPER_BASS,
SNAPPER_ANALOG,
SNAPPER_INPUT_SELECT,
SNAPPER_ENUM_LAST
};
static int
snapper_set_port(void *h, mixer_ctrl_t *mc)
{
struct snapper_softc *sc;
int l, r;
u_char data;
DPRINTF("snapper_set_port dev = %d, type = %d\n", mc->dev, mc->type);
sc = h;
l = mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
r = mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
switch (mc->dev) {
case SNAPPER_OUTPUT_SELECT:
if (mc->un.mask == sc->sc_output_mask)
return 0;
snapper_mute_speaker(sc, 1);
snapper_mute_headphone(sc, 1);
snapper_mute_lineout(sc, 1);
if (mc->un.mask & 1 << 0)
snapper_mute_speaker(sc, 0);
if (mc->un.mask & 1 << 1)
snapper_mute_headphone(sc, 0);
if (mc->un.mask & 1 << 2)
snapper_mute_lineout(sc, 0);
sc->sc_output_mask = mc->un.mask;
return 0;
case SNAPPER_VOL_OUTPUT:
snapper_set_volume(sc, l, r);
return 0;
case SNAPPER_INPUT_SELECT:
if (sc->sc_mode != 0)
return ENXIO;
if (mc->un.mask == sc->sc_record_source)
return 0;
switch (mc->un.mask) {
case 1 << 0:
data = DEQ_ACR_ADM | DEQ_ACR_LRB | DEQ_ACR_INP_B;
tas3004_write(sc, DEQ_ACR, &data);
break;
case 1 << 1:
data = 0;
tas3004_write(sc, DEQ_ACR, &data);
break;
default:
return EINVAL;
}
sc->sc_record_source = mc->un.mask;
return 0;
case SNAPPER_VOL_INPUT:
return 0;
case SNAPPER_BASS:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
snapper_set_bass(sc, l);
return 0;
case SNAPPER_TREBLE:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
snapper_set_treble(sc, l);
return 0;
case SNAPPER_DIGI1:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
sc->mixer[0] = l;
sc->mixer[3] = r;
snapper_write_mixers(sc);
return 0;
case SNAPPER_DIGI2:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
if (sc->sc_mode == SNAPPER_IS_TAS3001)
sc->mixer[3] = l;
else {
sc->mixer[1] = l;
sc->mixer[4] = r;
}
snapper_write_mixers(sc);
return 0;
case SNAPPER_ANALOG:
if (sc->sc_mode != 0)
return ENXIO;
sc->mixer[2] = l;
sc->mixer[5] = r;
snapper_write_mixers(sc);
return 0;
}
return ENXIO;
}
static int
snapper_get_port(void *h, mixer_ctrl_t *mc)
{
struct snapper_softc *sc;
DPRINTF("snapper_get_port dev = %d, type = %d\n", mc->dev, mc->type);
sc = h;
switch (mc->dev) {
case SNAPPER_OUTPUT_SELECT:
mc->un.mask = sc->sc_output_mask;
return 0;
case SNAPPER_VOL_OUTPUT:
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->sc_vol_l;
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->sc_vol_r;
return 0;
case SNAPPER_INPUT_SELECT:
if (sc->sc_mode != 0)
return ENXIO;
mc->un.mask = sc->sc_record_source;
return 0;
case SNAPPER_VOL_INPUT:
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = 0;
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 0;
return 0;
case SNAPPER_TREBLE:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_treble;
return 0;
case SNAPPER_BASS:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_bass;
return 0;
case SNAPPER_DIGI1:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->mixer[0];
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->mixer[3];
return 0;
case SNAPPER_DIGI2:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->mixer[1];
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->mixer[4];
return 0;
case SNAPPER_ANALOG:
if (sc->sc_mode != 0)
return ENXIO;
mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = sc->mixer[2];
mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->mixer[5];
return 0;
default:
return ENXIO;
}
return 0;
}
static int
snapper_query_devinfo(void *h, mixer_devinfo_t *dip)
{
struct snapper_softc *sc = h;
switch (dip->index) {
case SNAPPER_OUTPUT_SELECT:
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNoutput);
dip->type = AUDIO_MIXER_SET;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.s.num_mem = 3;
strcpy(dip->un.s.member[0].label.name, AudioNspeaker);
dip->un.s.member[0].mask = 1 << 0;
strcpy(dip->un.s.member[1].label.name, AudioNheadphone);
dip->un.s.member[1].mask = 1 << 1;
strcpy(dip->un.s.member[2].label.name, AudioNline);
dip->un.s.member[2].mask = 1 << 2;
return 0;
case SNAPPER_VOL_OUTPUT:
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNmaster);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels = 2;
dip->un.v.delta = 16;
strcpy(dip->un.v.units.name, AudioNvolume);
return 0;
case SNAPPER_INPUT_SELECT:
if (sc->sc_mode != 0)
return ENXIO;
dip->mixer_class = SNAPPER_RECORD_CLASS;
strcpy(dip->label.name, AudioNsource);
dip->type = AUDIO_MIXER_SET;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.s.num_mem = 2;
strcpy(dip->un.s.member[0].label.name, AudioNmicrophone);
dip->un.s.member[0].mask = 1 << 0;
strcpy(dip->un.s.member[1].label.name, AudioNline);
dip->un.s.member[1].mask = 1 << 1;
return 0;
case SNAPPER_VOL_INPUT:
dip->mixer_class = SNAPPER_RECORD_CLASS;
strcpy(dip->label.name, AudioNrecord);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
return 0;
case SNAPPER_MONITOR_CLASS:
dip->mixer_class = SNAPPER_MONITOR_CLASS;
strcpy(dip->label.name, AudioCmonitor);
dip->type = AUDIO_MIXER_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
return 0;
case SNAPPER_OUTPUT_CLASS:
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioCoutputs);
dip->type = AUDIO_MIXER_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
return 0;
case SNAPPER_RECORD_CLASS:
dip->mixer_class = SNAPPER_RECORD_CLASS;
strcpy(dip->label.name, AudioCrecord);
dip->type = AUDIO_MIXER_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
return 0;
case SNAPPER_TREBLE:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNtreble);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels = 1;
return 0;
case SNAPPER_BASS:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNbass);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels = 1;
return 0;
case SNAPPER_DIGI1:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNdac);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels =
sc->sc_mode == SNAPPER_IS_TAS3001? 1 : 2;
return 0;
case SNAPPER_DIGI2:
if (sc->sc_mode == SNAPPER_SWVOL)
return ENXIO;
dip->mixer_class = SNAPPER_OUTPUT_CLASS;
strcpy(dip->label.name, AudioNline);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels =
sc->sc_mode == SNAPPER_IS_TAS3001? 1 : 2;
return 0;
case SNAPPER_ANALOG:
if (sc->sc_mode != 0)
return ENXIO;
dip->mixer_class = SNAPPER_MONITOR_CLASS;
strcpy(dip->label.name, AudioNmicrophone);
dip->type = AUDIO_MIXER_VALUE;
dip->prev = dip->next = AUDIO_MIXER_LAST;
dip->un.v.num_channels = 2;
return 0;
}
return ENXIO;
}
static size_t
snapper_round_buffersize(void *h, int dir, size_t size)
{
if (size > 65536)
size = 65536;
return size;
}
static int
snapper_get_props(void *h)
{
return AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE |
AUDIO_PROP_FULLDUPLEX;
}
static int
snapper_trigger_output(void *h, void *start, void *end, int bsize,
void (*intr)(void *), void *arg,
const audio_params_t *param)
{
struct snapper_softc *sc;
struct dbdma_command *cmd;
vaddr_t va;
int i, len, intmode;
DPRINTF("trigger_output %p %p 0x%x\n", start, end, bsize);
sc = h;
cmd = sc->sc_odmacmd;
sc->sc_ointr = intr;
sc->sc_oarg = arg;
sc->sc_opages = ((char *)end - (char *)start) / NBPG;
#ifdef DIAGNOSTIC
if (sc->sc_opages > SNAPPER_MAXPAGES)
panic("snapper_trigger_output");
#endif
va = (vaddr_t)start;
len = 0;
for (i = sc->sc_opages; i > 0; i--) {
len += NBPG;
if (len < bsize)
intmode = 0;
else {
len = 0;
intmode = DBDMA_INT_ALWAYS;
}
DBDMA_BUILD(cmd, DBDMA_CMD_OUT_MORE, 0, NBPG, vtophys(va),
intmode, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
cmd++;
va += NBPG;
}
DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0,
0, 0, DBDMA_WAIT_NEVER,
DBDMA_BRANCH_ALWAYS);
out32rb(&cmd->d_cmddep, vtophys((vaddr_t)sc->sc_odmacmd));
dbdma_start(sc->sc_odma, sc->sc_odmacmd);
return 0;
}
static int
snapper_trigger_input(void *h, void *start, void *end, int bsize,
void (*intr)(void *), void *arg,
const audio_params_t *param)
{
struct snapper_softc *sc;
struct dbdma_command *cmd;
vaddr_t va;
int i, len, intmode;
DPRINTF("trigger_input %p %p 0x%x\n", start, end, bsize);
sc = h;
cmd = sc->sc_idmacmd;
sc->sc_iintr = intr;
sc->sc_iarg = arg;
sc->sc_ipages = ((char *)end - (char *)start) / NBPG;
#ifdef DIAGNOSTIC
if (sc->sc_ipages > SNAPPER_MAXPAGES)
panic("snapper_trigger_input");
#endif
va = (vaddr_t)start;
len = 0;
for (i = sc->sc_ipages; i > 0; i--) {
len += NBPG;
if (len < bsize)
intmode = 0;
else {
len = 0;
intmode = DBDMA_INT_ALWAYS;
}
DBDMA_BUILD(cmd, DBDMA_CMD_IN_MORE, 0, NBPG, vtophys(va),
intmode, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
cmd++;
va += NBPG;
}
DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0,
0, 0, DBDMA_WAIT_NEVER,
DBDMA_BRANCH_ALWAYS);
out32rb(&cmd->d_cmddep, vtophys((vaddr_t)sc->sc_idmacmd));
dbdma_start(sc->sc_idma, sc->sc_idmacmd);
return 0;
}
static void
snapper_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
{
struct snapper_softc *sc = opaque;
*intr = &sc->sc_intr_lock;
*thread = &sc->sc_lock;
}
static void
snapper_set_volume(struct snapper_softc *sc, u_int left, u_int right)
{
u_char regs[6];
int l, r;
left = uimin(255, left);
right = uimin(255, right);
if (sc->sc_mode == SNAPPER_SWVOL) {
sc->sc_swvol_l = left;
sc->sc_swvol_r = right;
} else {
l = 177 - (left * 178 / 256);
regs[0] = (snapper_mixer_gain[l][0] >> 4);
regs[1] = ((snapper_mixer_gain[l][0] & 0x0f) << 4) |
(snapper_mixer_gain[l][1] >> 4);
regs[2] = ((snapper_mixer_gain[l][1] & 0x0f) << 4) |
(snapper_mixer_gain[l][2] >> 4);
r = 177 - (right * 178 / 256);
regs[3] = (snapper_mixer_gain[r][0] >> 4);
regs[4] = ((snapper_mixer_gain[r][0] & 0x0f) << 4) |
(snapper_mixer_gain[r][1] >> 4);
regs[5] = ((snapper_mixer_gain[r][1] & 0x0f) << 4) |
(snapper_mixer_gain[r][2] >> 4);
tas3004_write(sc, DEQ_VOLUME, regs);
DPRINTF("%d %02x %02x %02x : %d %02x %02x %02x\n", l, regs[0],
regs[1], regs[2], r, regs[3], regs[4], regs[5]);
}
sc->sc_vol_l = left;
sc->sc_vol_r = right;
}
static void
snapper_set_basstreble(struct snapper_softc *sc, u_int val, u_int mode)
{
int i = val & 0xFF;
uint8_t reg;
i = (i - (128 - (SNAPPER_BASSTAB_0DB << 2))) >> 2;
if (i < 0)
i = 0;
else if (i >= sizeof(snapper_basstab))
i = sizeof(snapper_basstab) - 1;
reg = snapper_basstab[i];
if (sc->sc_mode == SNAPPER_IS_TAS3001 &&
mode == DEQ_BASS) {
reg = (reg >> 1) + 5;
}
tas3004_write(sc, mode, ®);
}
static void
snapper_set_treble(struct snapper_softc *sc, u_int val)
{
if (sc->sc_treble != (u_char)val) {
sc->sc_treble = val;
snapper_set_basstreble(sc, val, DEQ_TREBLE);
}
}
static void
snapper_set_bass(struct snapper_softc *sc, u_int val)
{
if (sc->sc_bass != (u_char)val) {
sc->sc_bass = val;
snapper_set_basstreble(sc, val, DEQ_BASS);
}
}
#define SNAPPER_MIXER_GAIN_SIZE (sizeof(snapper_mixer_gain) / \
sizeof(snapper_mixer_gain[0]))
#define NORMALIZE(i) ((~(i) & 0xff) - ((~128 & 0xff) - SNAPPER_MIXER_GAIN_0DB))
#define ADJUST(v, i) do { \
(v) = NORMALIZE(i);\
if ((v) < 0) \
(v) = 0; \
else if ((v) >= SNAPPER_MIXER_GAIN_SIZE) \
(v) = SNAPPER_MIXER_GAIN_SIZE - 1; \
\
} while (0)
static void
snapper_write_mixers(struct snapper_softc *sc)
{
uint8_t regs[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int i;
if (sc->sc_mode > 1) return;
ADJUST(i, sc->mixer[0]);
regs[0] = snapper_mixer_gain[i][0];
regs[1] = snapper_mixer_gain[i][1];
regs[2] = snapper_mixer_gain[i][2];
ADJUST(i, sc->mixer[1]);
regs[3] = snapper_mixer_gain[i][0];
regs[4] = snapper_mixer_gain[i][1];
regs[5] = snapper_mixer_gain[i][2];
ADJUST(i, sc->mixer[2]);
regs[6] = snapper_mixer_gain[i][0];
regs[7] = snapper_mixer_gain[i][1];
regs[8] = snapper_mixer_gain[i][2];
tas3004_write(sc, DEQ_MIXER_L, regs);
ADJUST(i, sc->mixer[3]);
regs[0] = snapper_mixer_gain[i][0];
regs[1] = snapper_mixer_gain[i][1];
regs[2] = snapper_mixer_gain[i][2];
ADJUST(i, sc->mixer[4]);
regs[3] = snapper_mixer_gain[i][0];
regs[4] = snapper_mixer_gain[i][1];
regs[5] = snapper_mixer_gain[i][2];
ADJUST(i, sc->mixer[5]);
regs[6] = snapper_mixer_gain[i][0];
regs[7] = snapper_mixer_gain[i][1];
regs[8] = snapper_mixer_gain[i][2];
tas3004_write(sc, DEQ_MIXER_R, regs);
}
int
snapper_set_rate(struct snapper_softc *sc)
{
u_int reg = 0, x;
u_int rate = sc->sc_rate;
uint32_t wordsize, ows;
int MCLK;
int clksrc, mdiv, sdiv;
int mclk_fs;
int timo;
uint8_t mcr1;
switch (rate) {
case 44100:
clksrc = 45158400;
reg = CLKSRC_45MHz;
mclk_fs = 256;
break;
case 32000:
case 48000:
case 96000:
clksrc = 49152000;
reg = CLKSRC_49MHz;
mclk_fs = 256;
break;
default:
DPRINTF("snapper_set_rate: invalid rate %u\n", rate);
return EINVAL;
}
MCLK = rate * mclk_fs;
mdiv = clksrc / MCLK;
sdiv = mclk_fs / 64;
switch (mdiv) {
case 1:
reg |= MCLK_DIV1;
break;
case 3:
reg |= MCLK_DIV3;
break;
case 5:
reg |= MCLK_DIV5;
break;
default:
reg |= ((mdiv / 2 - 1) << 24) & 0x1f000000;
break;
}
switch (sdiv) {
case 1:
reg |= SCLK_DIV1;
break;
case 3:
reg |= SCLK_DIV3;
break;
default:
reg |= ((sdiv / 2 - 1) << 20) & 0x00f00000;
break;
}
reg |= SCLK_MASTER;
reg |= SERIAL_64x;
DPRINTF("precision: %d\n", sc->sc_bitspersample);
switch(sc->sc_bitspersample) {
case 16:
wordsize = INPUT_STEREO | INPUT_16BIT |
OUTPUT_STEREO | OUTPUT_16BIT;
mcr1 = DEQ_MCR1_SC_64 | DEQ_MCR1_SM_I2S | DEQ_MCR1_W_16;
break;
case 24:
wordsize = INPUT_STEREO | INPUT_24BIT |
OUTPUT_STEREO | OUTPUT_24BIT;
mcr1 = DEQ_MCR1_SC_64 | DEQ_MCR1_SM_I2S | DEQ_MCR1_W_24;
break;
default:
printf("%s: unsupported sample size %d\n",
device_xname(sc->sc_dev), sc->sc_bitspersample);
return EINVAL;
}
if (sc->sc_mode == SNAPPER_IS_TAS3001)
mcr1 |= DEQ_MCR1_ISM_I2S;
ows = bus_space_read_4(sc->sc_tag, sc->sc_bsh, I2S_WORDSIZE);
DPRINTF("I2SSetDataWordSizeReg 0x%08x -> 0x%08x\n",
ows, wordsize);
if (ows != wordsize) {
bus_space_write_4(sc->sc_tag, sc->sc_bsh, I2S_WORDSIZE,
wordsize);
if (sc->sc_mode != SNAPPER_SWVOL)
tas3004_write(sc, DEQ_MCR1, &mcr1);
}
x = bus_space_read_4(sc->sc_tag, sc->sc_bsh, I2S_FORMAT);
if (x == reg)
return 0;
DPRINTF("I2SSetSerialFormatReg 0x%x -> 0x%x\n",
bus_space_read_4(sc->sc_tag, sc->sc_bsh, + I2S_FORMAT), reg);
bus_space_write_4(sc->sc_tag, sc->sc_bsh, I2S_INT, I2S_INT_CLKSTOPPEND);
x = obio_read_4(KEYLARGO_FCR1);
x &= ~I2S0CLKEN;
obio_write_4(KEYLARGO_FCR1, x);
for (timo = 1000; timo > 0; timo--) {
if (bus_space_read_4(sc->sc_tag, sc->sc_bsh, I2S_INT) &
I2S_INT_CLKSTOPPEND)
goto done;
delay(1);
}
DPRINTF("snapper_set_rate: timeout\n");
done:
bus_space_write_4(sc->sc_tag, sc->sc_bsh, I2S_FORMAT, reg);
x = obio_read_4(KEYLARGO_FCR1);
x |= I2S0CLKEN;
obio_write_4(KEYLARGO_FCR1, x);
return 0;
}
const struct tas3004_reg tas3004_initdata = {
{ DEQ_MCR1_SC_64 | DEQ_MCR1_SM_I2S | DEQ_MCR1_W_16 },
{ 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 },
{ 0 },
{ 2 }
};
const char tas3004_regsize[] = {
0,
sizeof tas3004_initdata.MCR1,
sizeof tas3004_initdata.DRC,
0,
sizeof tas3004_initdata.VOLUME,
sizeof tas3004_initdata.TREBLE,
sizeof tas3004_initdata.BASS,
sizeof tas3004_initdata.MIXER_L,
sizeof tas3004_initdata.MIXER_R,
0,
sizeof tas3004_initdata.LB0,
sizeof tas3004_initdata.LB1,
sizeof tas3004_initdata.LB2,
sizeof tas3004_initdata.LB3,
sizeof tas3004_initdata.LB4,
sizeof tas3004_initdata.LB5,
sizeof tas3004_initdata.LB6,
0,
0,
sizeof tas3004_initdata.RB0,
sizeof tas3004_initdata.RB1,
sizeof tas3004_initdata.RB2,
sizeof tas3004_initdata.RB3,
sizeof tas3004_initdata.RB4,
sizeof tas3004_initdata.RB5,
sizeof tas3004_initdata.RB6,
0,0,0,0, 0,0,
0,
sizeof tas3004_initdata.LLB,
sizeof tas3004_initdata.RLB,
sizeof tas3004_initdata.LLB_GAIN,
sizeof tas3004_initdata.RLB_GAIN,
0,0,0,0, 0,0,0,0, 0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
sizeof tas3004_initdata.ACR,
0,
0,
sizeof tas3004_initdata.MCR2
};
static int
tas3004_write(struct snapper_softc *sc, u_int reg, const void *data)
{
int size;
static char regblock[sizeof(struct tas3004_reg)+1];
if (sc->sc_i2c == NULL)
return 0;
KASSERT(reg < sizeof tas3004_regsize);
size = tas3004_regsize[reg];
KASSERT(size > 0);
DPRINTF("reg: %x, %d %d\n", reg, size, ((const char*)data)[0]);
regblock[0] = reg;
memcpy(®block[1], data, size);
if (sc->sc_mode == SNAPPER_IS_TAS3001) {
if (reg == DEQ_MIXER_L || reg == DEQ_MIXER_R)
size = 3;
else if (reg == DEQ_DRC || reg == DEQ_ACR ||
reg == DEQ_MCR2) {
return 0;
}
}
iic_acquire_bus(sc->sc_i2c, 0);
iic_exec(sc->sc_i2c, I2C_OP_WRITE, sc->sc_deqaddr, regblock, size + 1,
NULL, 0, 0);
iic_release_bus(sc->sc_i2c, 0);
return 0;
}
static int
gpio_read(bus_size_t addr)
{
if (obio_read_1(addr) & GPIO_DATA)
return 1;
return 0;
}
static void
gpio_write(bus_size_t addr, int val)
{
uint8_t data;
data = GPIO_DDR_OUTPUT;
if (val)
data |= GPIO_DATA;
obio_write_1(addr, data);
}
int headphone_active = 0;
int lineout_active = 0;
int amp_active = 0;
static void
snapper_mute_speaker(struct snapper_softc *sc, int mute)
{
int x;
if (amp_mute) {
DPRINTF("ampmute %d --> ", gpio_read(amp_mute));
if (mute)
x = amp_active;
else
x = amp_active ^ 1;
gpio_write(amp_mute, x);
DPRINTF("%d\n", gpio_read(amp_mute));
}
}
static void
snapper_mute_headphone(struct snapper_softc *sc, int mute)
{
u_int x;
if (headphone_mute != 0) {
DPRINTF("headphonemute %d --> ", gpio_read(headphone_mute));
if (mute)
x = headphone_active;
else
x = headphone_active ^ 1;
gpio_write(headphone_mute, x);
DPRINTF("%d\n", gpio_read(headphone_mute));
}
}
static void
snapper_mute_lineout(struct snapper_softc *sc, int mute)
{
u_int x;
if (lineout_mute != 0) {
DPRINTF("lineoutmute %d --> ", gpio_read(lineout_mute));
if (mute)
x = lineout_active;
else
x = lineout_active ^ 1;
gpio_write(lineout_mute, x);
DPRINTF("%d\n", gpio_read(lineout_mute));
}
}
static int
snapper_cint(void *v)
{
struct snapper_softc *sc = v;
u_int sense;
int mask = 1 << 0;
if (headphone_detect != 0) {
sense = obio_read_1(headphone_detect);
DPRINTF("headphone detect = 0x%x\n", sense);
if (((sense & 0x02) >> 1) == headphone_detect_active) {
DPRINTF("headphone is inserted\n");
mask |= 1 << 1;
mask &= ~(1 << 0);
} else {
DPRINTF("headphone is NOT inserted\n");
}
}
if (lineout_detect != 0) {
sense = obio_read_1(lineout_detect);
DPRINTF("lineout detect = 0x%x\n", sense);
if (((sense & 0x02) >> 1) == lineout_detect_active) {
DPRINTF("lineout is inserted\n");
mask |= 1 << 2;
mask &= ~(1 << 0);
} else {
DPRINTF("lineout is NOT inserted\n");
}
}
if (mask != sc->sc_output_mask) {
sc->sc_output_mask = mask;
if (mask & (1 << 0)) {
snapper_mute_speaker(sc, 0);
} else snapper_mute_speaker(sc, 1);
if (mask & (1 << 1)) {
snapper_mute_headphone(sc, 0);
} else snapper_mute_headphone(sc, 1);
if (mask & (1 << 2)) {
snapper_mute_lineout(sc, 0);
} else snapper_mute_lineout(sc, 1);
}
return 1;
}
#define reset_active 0
#define DEQ_WRITE(sc, reg, addr) \
if (tas3004_write(sc, reg, addr)) goto err
static int
tas3004_init(struct snapper_softc *sc)
{
if (audio_hw_reset == 0)
goto noreset;
gpio_write(audio_hw_reset, !reset_active);
delay(100000);
gpio_write(audio_hw_reset, reset_active);
delay(1);
gpio_write(audio_hw_reset, !reset_active);
delay(10000);
noreset:
if ((sc->sc_mode == SNAPPER_IS_TAS3004) ||
(sc->sc_mode == SNAPPER_IS_TAS3001)) {
DEQ_WRITE(sc, DEQ_LB0, tas3004_initdata.LB0);
DEQ_WRITE(sc, DEQ_LB1, tas3004_initdata.LB1);
DEQ_WRITE(sc, DEQ_LB2, tas3004_initdata.LB2);
DEQ_WRITE(sc, DEQ_LB3, tas3004_initdata.LB3);
DEQ_WRITE(sc, DEQ_LB4, tas3004_initdata.LB4);
DEQ_WRITE(sc, DEQ_LB5, tas3004_initdata.LB5);
DEQ_WRITE(sc, DEQ_LB6, tas3004_initdata.LB6);
DEQ_WRITE(sc, DEQ_RB0, tas3004_initdata.RB0);
DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
DEQ_WRITE(sc, DEQ_RB2, tas3004_initdata.RB2);
DEQ_WRITE(sc, DEQ_RB3, tas3004_initdata.RB3);
DEQ_WRITE(sc, DEQ_RB4, tas3004_initdata.RB4);
DEQ_WRITE(sc, DEQ_RB5, tas3004_initdata.RB5);
DEQ_WRITE(sc, DEQ_MCR1, tas3004_initdata.MCR1);
DEQ_WRITE(sc, DEQ_MCR2, tas3004_initdata.MCR2);
DEQ_WRITE(sc, DEQ_DRC, tas3004_initdata.DRC);
DEQ_WRITE(sc, DEQ_VOLUME, tas3004_initdata.VOLUME);
DEQ_WRITE(sc, DEQ_TREBLE, tas3004_initdata.TREBLE);
DEQ_WRITE(sc, DEQ_BASS, tas3004_initdata.BASS);
DEQ_WRITE(sc, DEQ_MIXER_L, tas3004_initdata.MIXER_L);
DEQ_WRITE(sc, DEQ_MIXER_R, tas3004_initdata.MIXER_R);
DEQ_WRITE(sc, DEQ_LLB, tas3004_initdata.LLB);
DEQ_WRITE(sc, DEQ_RLB, tas3004_initdata.RLB);
DEQ_WRITE(sc, DEQ_LLB_GAIN, tas3004_initdata.LLB_GAIN);
DEQ_WRITE(sc, DEQ_RLB_GAIN, tas3004_initdata.RLB_GAIN);
DEQ_WRITE(sc, DEQ_ACR, tas3004_initdata.ACR);
}
return 0;
err:
printf("tas3004_init: error\n");
return -1;
}
static void
snapper_init(struct snapper_softc *sc, int node)
{
int gpio;
int headphone_detect_intr, lineout_detect_intr;
uint32_t gpio_base, reg[1], fcreg, buf[8];
char intr_xname[INTRDEVNAMEBUF];
#ifdef SNAPPER_DEBUG
char fcr[32];
snprintb(fcr, sizeof(fcr), FCR3C_BITMASK, obio_read_4(KEYLARGO_FCR1));
printf("FCR(0x3c) %s\n", fcr);
#endif
fcreg = obio_read_4(KEYLARGO_FCR1);
fcreg |= I2S0CLKEN | I2S0EN;
obio_write_4(KEYLARGO_FCR1, fcreg);
headphone_detect_intr = -1;
lineout_detect_intr = -1;
gpio = of_getnode_byname(OF_parent(node), "gpio");
if (OF_getprop(gpio, "reg", reg, sizeof(reg)) == sizeof(reg))
gpio_base = reg[0];
else
gpio_base = 0;
DPRINTF(" /gpio 0x%x@0x%x\n", (unsigned)gpio, gpio_base);
gpio = OF_child(gpio);
while (gpio) {
char name[64], audio_gpio[64], sid[64];
int intr[2];
bus_size_t addr;
memset(name, 0, sizeof name);
memset(audio_gpio, 0, sizeof audio_gpio);
addr = 0;
OF_getprop(gpio, "name", name, sizeof name);
OF_getprop(gpio, "audio-gpio", audio_gpio, sizeof audio_gpio);
OF_getprop(gpio, "one-wire-bus", sid, sizeof sid);
if (OF_getprop(gpio, "AAPL,address", &addr, sizeof addr) == -1)
if (OF_getprop(gpio, "reg", reg, sizeof reg)
== sizeof reg)
addr = gpio_base + reg[0];
addr &= 0x7fff;
DPRINTF(" 0x%x %s %s %08x\n", gpio, name, audio_gpio, addr);
if (strcmp(audio_gpio, "headphone-mute") == 0 ||
strcmp(name, "headphone-mute") == 0) {
headphone_mute = addr;
if (OF_getprop(gpio,
"platform-do-headphone-mute", buf, 20) == 20) {
headphone_active = buf[3] & 1;
DPRINTF("platform-do-headphone-mute %d\n",
headphone_active);
}
}
if (strcmp(audio_gpio, "amp-mute") == 0 ||
strcmp(name, "amp-mute") == 0) {
amp_mute = addr;
if (OF_getprop(gpio,
"platform-do-amp-mute", buf, 20) == 20) {
amp_active = buf[3] & 1;
DPRINTF("platform-do-amp-mute %d\n",
amp_active);
}
}
if (strcmp(audio_gpio, "headphone-detect") == 0 ||
strcmp(name, "headphone-detect") == 0) {
uint32_t act = 0;
headphone_detect = addr;
OF_getprop(gpio, "audio-gpio-active-state", &act, 4);
headphone_detect_active = act;
if (OF_getprop(gpio, "interrupts", intr, 8) == 8) {
headphone_detect_intr = intr[0];
}
}
if (strcmp(audio_gpio, "lineout-mute") == 0 ||
strcmp(name, "lineout-mute") == 0 ||
strcmp(name, "line-output-mute") == 0) {
lineout_mute = addr;
if (OF_getprop(gpio,
"platform-do-lineout-mute", buf, 20) == 20) {
lineout_active = buf[3] & 1;
DPRINTF("platform-do-lineout-mute %d\n",
lineout_active);
}
}
if (strcmp(audio_gpio, "lineout-detect") == 0 ||
strcmp(name, "lineout-detect") == 0 ||
strcmp(name, "line-output-detect") == 0) {
uint32_t act = 0;
lineout_detect = addr;
OF_getprop(gpio, "audio-gpio-active-state", &act, 4);
lineout_detect_active = act;
if (OF_getprop(gpio, "interrupts", intr, 8) == 8) {
lineout_detect_intr = intr[0];
}
}
if (strcmp(sid, "speaker-id") == 0) {
owaddr = addr;
}
if (strcmp(audio_gpio, "audio-hw-reset") == 0 ||
strcmp(name, "hw-reset") == 0)
audio_hw_reset = addr;
gpio = OF_peer(gpio);
}
if (owaddr != -1) snapper_setup_ow(sc);
DPRINTF(" headphone-mute %x\n", headphone_mute);
DPRINTF(" lineout-mute %x\n", lineout_mute);
DPRINTF(" amp-mute %x\n", amp_mute);
DPRINTF(" headphone-detect %x\n", headphone_detect);
DPRINTF(" headphone-detect active %x\n", headphone_detect_active);
DPRINTF(" headphone-detect intr %x\n", headphone_detect_intr);
DPRINTF(" lineout-detect %x\n", lineout_detect);
DPRINTF(" lineout-detect active %x\n", lineout_detect_active);
DPRINTF(" lineout-detect intr %x\n", lineout_detect_intr);
DPRINTF(" audio-hw-reset %x\n", audio_hw_reset);
if (headphone_detect_intr != -1) {
snprintf(intr_xname, sizeof(intr_xname), "%s headphone",
device_xname(sc->sc_dev));
intr_establish_xname(headphone_detect_intr, IST_EDGE,
IPL_AUDIO, snapper_cint, sc, intr_xname);
}
if (lineout_detect_intr != -1) {
snprintf(intr_xname, sizeof(intr_xname), "%s line out",
device_xname(sc->sc_dev));
intr_establish_xname(lineout_detect_intr, IST_EDGE, IPL_AUDIO,
snapper_cint, sc, intr_xname);
}
sc->sc_rate = 44100;
sc->sc_bitspersample = 16;
if (headphone_detect != 0) {
obio_write_1(headphone_detect,
obio_read_1(headphone_detect) | 0x80);
}
if (lineout_detect != 0) {
obio_write_1(lineout_detect,
obio_read_1(lineout_detect) | 0x80);
}
if (tas3004_init(sc))
return;
snapper_cint(sc);
snapper_set_volume(sc, 128, 128);
snapper_set_bass(sc, 128);
snapper_set_treble(sc, 128);
sc->sc_record_source = 1 << 1;
sc->mixer[0] = 128;
sc->mixer[1] = 128;
sc->mixer[2] = 0;
if (sc->sc_mode == SNAPPER_IS_TAS3001) {
sc->mixer[3] = 0;
} else
sc->mixer[3] = 128;
sc->mixer[4] = 128;
sc->mixer[5] = 0;
snapper_write_mixers(sc);
}
static void
snapper_setup_ow(struct snapper_softc *sc)
{
struct onewirebus_attach_args oba;
sc->sc_ow_bus.bus_cookie = sc;
sc->sc_ow_bus.bus_reset = snapper_ow_reset;
sc->sc_ow_bus.bus_read_bit = snapper_ow_read_bit;
sc->sc_ow_bus.bus_write_bit = snapper_ow_write_bit;
memset(&oba, 0, sizeof(oba));
oba.oba_bus = &sc->sc_ow_bus;
sc->sc_ow_dev = config_found(sc->sc_dev, &oba, onewirebus_print,
CFARGS(.iattr = "onewirebus"));
}
static int
snapper_ow_reset(void *cookie)
{
return (onewire_bb_reset(&snapper_bbops, cookie));
}
static int
snapper_ow_read_bit(void *cookie)
{
return (onewire_bb_read_bit(&snapper_bbops, cookie));
}
static void
snapper_ow_write_bit(void *cookie, int bit)
{
onewire_bb_write_bit(&snapper_bbops, cookie, bit);
}
static void
snapper_bb_rx(void *cookie)
{
struct snapper_softc *sc = cookie;
sc->sc_ow_data &= ~GPIO_DDR_OUTPUT;
obio_write_1(owaddr, sc->sc_ow_data);
}
static void
snapper_bb_tx(void *cookie)
{
struct snapper_softc *sc = cookie;
sc->sc_ow_data |= GPIO_DDR_OUTPUT;
obio_write_1(owaddr, sc->sc_ow_data);
}
static int snapper_bb_get(void *cookie)
{
int data = (obio_read_1(owaddr) & GPIO_LEVEL) ? 1 : 0;
return data;
}
static void snapper_bb_set(void *cookie, int bit)
{
struct snapper_softc *sc = cookie;
if (bit) {
sc->sc_ow_data |= GPIO_DATA;
} else
sc->sc_ow_data &= ~GPIO_DATA;
obio_write_1(owaddr, sc->sc_ow_data);
}