socsvn commit: r289647 - soc2015/pratiksinghal/cubie-head/sys/arm/allwinner
pratiksinghal at FreeBSD.org
pratiksinghal at FreeBSD.org
Wed Aug 12 19:03:20 UTC 2015
Author: pratiksinghal
Date: Wed Aug 12 19:03:19 2015
New Revision: 289647
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=289647
Log:
Added the format and init methods, use of kobj class and other methods remaining
Modified:
soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c
Modified: soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c
==============================================================================
--- soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c Wed Aug 12 18:47:30 2015 (r289646)
+++ soc2015/pratiksinghal/cubie-head/sys/arm/allwinner/a10_ac97.c Wed Aug 12 19:03:19 2015 (r289647)
@@ -42,6 +42,17 @@
/* TODO :- Add DMA support after the pio mode works corectly. */
+struct a10_ac97_channel
+{
+ struct snd_dbuf* buf;
+ struct pcm_channel* channel;
+ struct a10_ac97_info* parent;
+ uint32_t flags;
+ uint32_t fmt;
+ int type;
+ int8_t in_use;
+};
+
struct a10_ac97_info
{
device_t ac_dev;
@@ -54,19 +65,27 @@
bus_space_tag_t ac97_bst;
struct mtx ac97_mtx;
struct ac97_info *codec;
+ struct a10_ac97_channel cht; /* Playing */
+ struct a10_ac97_channel chr; /* Recording */
uint32_t ienab;
uint32_t use_dma;
};
+static int ac97_probe(device_t);
+static int ac97_attach(device_t);
+static int ac97_detach(device_t);
+static void *a10_ac97_chan_init(kobj_t, void *, struct snd_dbuf *, struct pcm_channel *, int);
+static int a10_ac97_setfmt(kobj_t, void *, uint32_t);
+
#define AC97_READ(_sc, _reg) \
bus_space_read_4((_sc)->ac97_bst, (_sc)->ac97_bsh, _reg)
#define AC97_WRITE(_sc, _reg, _value) \
bus_space_write_4((_sc)->ac97_bst, (_sc)->ac97_bsh, _reg, _value)
#define AC97_LOCK(_sc) \
- mtx_lock((_sc)->ac97_mtx)
+ mtx_lock(&(_sc)->ac97_mtx)
#define AC97_UNLOCK(_sc) \
- mtx_unlock((_sc)->ac97_mtx)
+ mtx_unlock(&(_sc)->ac97_mtx)
static int
@@ -156,12 +175,74 @@
return (EBUSY);
}
-static device_method_t a10_ac97_methods[] = {
- DEVMETHOD(device_probe, ac97_probe),
- DEVMETHOD(device_attach, ac97_attach),
- DEVMETHOD(device_detach, ac97_detach),
+static void * a10_ac97_chan_init(kobj_t kobj, void *devinfo, struct snd_dbuf *b,
+ struct pcm_channel *c, int type)
+{
+ struct a10_ac97_info* sc = (struct a10_ac97_info*) devinfo;
+ struct a10_ac97_channel* ch;
+
+ if (type == PCMDIR_PLAY)
+ ch = &(sc->cht);
+ else
+ ch = &(sc->chr);
+
+ AC97_LOCK(sc);
+ ch->in_use = 1;
+ ch->buf = b;
+ ch->channel = c;
+ ch->parent = sc;
+ ch->type = type;
+ AC97_UNLOCK(sc);
+
+ return (ch);
+}
+
+static int a10_ac97_setfmt(kobj_t obj, void *chn, uint32_t fmt)
+{
+ struct a10_ac97_channel *channel = (struct a10_ac97_channel *)chn;
+ struct a10_ac97_info *sc = channel->parent;
+ uint32_t value;
+
+ AC97_LOCK(sc);
+ value = AC_TX_MODE_2;
+ if (fmt & AFMT_16BIT) {
+ if (channel->type == PCMDIR_PLAY)
+ value |= AC_TX_RES_16;
+ else
+ value |= AC_RX_RES_16;
+ channel->fmt = fmt;
+ AC97_WRITE(sc,AC_FAT,value);
+ AC97_UNLOCK(sc);
+
+ return (0);
+ }
+ else {
+ device_printf(channel->parent->ac_dev, "Resolution not supported\n");
+ AC97_UNLOCK(sc);
+
+ return -1;
+ }
+}
+
+static kobj_method_t a10_ac97_chan_methods[] = {
+ KOBJMETHOD(channel_init, a10_ac97_chan_init),
+ KOBJMETHOD(channel_setformat, a10_ac97_setfmt),
+ //KOBJMETHOD(channel_setspeed, a10_ac97_speed),
+ //KOBJMETHOD(channel_setblocksize, a10_ac97_setblksz),
+ //KOBJMETHOD(channel_setfragments, a10_ac97_setfragments),
+ //KOBJMETHOD(channel_trigger, a10_ac97_chan_trigger),
+ //KOBJMETHOD(channel_getptr, a10_ac97_getptr),
+ //KOBJMETHOD(channel_getcaps, a10_ac97_getcaps)
+ KOBJMETHOD_END
+};
- DEVMETHOD_END
+CHANNEL_DECLARE(a10_ac97_chan);
+
+static device_method_t a10_ac97_methods[] = {
+ DEVMETHOD(device_probe, ac97_probe),
+ DEVMETHOD(device_attach, ac97_attach),
+ DEVMETHOD(device_detach, ac97_detach),
+ DEVMETHOD_END
};
static devclass_t a10_ac97_devclass;
More information about the svn-soc-all
mailing list