diff options
| author | isaki <isaki@NetBSD.org> | 2021-02-04 15:08:44 +0000 |
|---|---|---|
| committer | isaki <isaki@NetBSD.org> | 2021-02-04 15:08:44 +0000 |
| commit | 71f314ab5df75b992ebd67cc2180fe6fde01fbb5 (patch) | |
| tree | 44e5ccd9f6b95bae3c694d4d974130ee690148eb /sys | |
| parent | b96dc5cc35e0aba0de047a958abe2255a14b424d (diff) | |
Simplify harmony_speed_bits().
It no longer needs to write back the speed value.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/arch/hppa/gsc/harmony.c | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/sys/arch/hppa/gsc/harmony.c b/sys/arch/hppa/gsc/harmony.c index f890d770dc6..6da337222bb 100644 --- a/sys/arch/hppa/gsc/harmony.c +++ b/sys/arch/hppa/gsc/harmony.c @@ -1,4 +1,4 @@ -/* $NetBSD: harmony.c,v 1.9 2021/02/04 15:06:11 isaki Exp $ */ +/* $NetBSD: harmony.c,v 1.10 2021/02/04 15:08:44 isaki Exp $ */ /* $OpenBSD: harmony.c,v 1.23 2004/02/13 21:28:19 mickey Exp $ */ @@ -165,7 +165,7 @@ CFATTACH_DECL_NEW(harmony, sizeof(struct harmony_softc), int harmony_intr(void *); void harmony_intr_enable(struct harmony_softc *); void harmony_intr_disable(struct harmony_softc *); -uint32_t harmony_speed_bits(struct harmony_softc *, u_int *); +uint32_t harmony_speed_bits(struct harmony_softc *, u_int); int harmony_set_gainctl(struct harmony_softc *); void harmony_reset_codec(struct harmony_softc *); void harmony_start_cp(struct harmony_softc *, int); @@ -441,7 +441,6 @@ harmony_set_format(void *vsc, int setmode, { struct harmony_softc *sc; uint32_t bits; - int rate; sc = vsc; @@ -464,10 +463,7 @@ harmony_set_format(void *vsc, int setmode, bits |= CNTL_OLB; bits |= CNTL_CHANS_STEREO; - - /* XXX modify harmony_speed_bits() not to rewrite rate */ - rate = play->sample_rate; - bits |= harmony_speed_bits(sc, &rate); + bits |= harmony_speed_bits(sc, play->sample_rate); sc->sc_cntlbits = bits; sc->sc_need_commit = 1; @@ -1161,39 +1157,17 @@ static const struct speed_struct { }; uint32_t -harmony_speed_bits(struct harmony_softc *sc, u_int *speedp) +harmony_speed_bits(struct harmony_softc *sc, u_int speed) { - int i, n, selected; - - selected = -1; - n = sizeof(harmony_speeds) / sizeof(harmony_speeds[0]); + int i; - if ((*speedp) <= harmony_speeds[0].speed) - selected = 0; - else if ((*speedp) >= harmony_speeds[n - 1].speed) - selected = n - 1; - else { - for (i = 1; selected == -1 && i < n; i++) { - if ((*speedp) == harmony_speeds[i].speed) - selected = i; - else if ((*speedp) < harmony_speeds[i].speed) { - int diff1, diff2; - - diff1 = (*speedp) - harmony_speeds[i - 1].speed; - diff2 = harmony_speeds[i].speed - (*speedp); - if (diff1 < diff2) - selected = i - 1; - else - selected = i; - } + for (i = 0; i < __arraycount(harmony_speeds); i++) { + if (speed == harmony_speeds[i].speed) { + return harmony_speeds[i].bits; } } - - if (selected == -1) - selected = 2; - - *speedp = harmony_speeds[selected].speed; - return harmony_speeds[selected].bits; + /* If this happens, harmony_formats[] is wrong */ + panic("speed %u not supported", speed); } int |
