r4884 - in developers/werner: . wolfhammer
werner at docs.openmoko.org
werner at docs.openmoko.org
Tue Jan 13 18:03:15 CET 2009
Author: werner
Date: 2009-01-13 18:03:14 +0100 (Tue, 13 Jan 2009)
New Revision: 4884
Added:
developers/werner/wolfhammer/
developers/werner/wolfhammer/Makefile
developers/werner/wolfhammer/wolfhammer.c
Log:
Hammer the Wolfson, for MICBIAS testing.
Added: developers/werner/wolfhammer/Makefile
===================================================================
--- developers/werner/wolfhammer/Makefile (rev 0)
+++ developers/werner/wolfhammer/Makefile 2009-01-13 17:03:14 UTC (rev 4884)
@@ -0,0 +1,35 @@
+CC=arm-angstrom-linux-gnueabi-gcc
+
+CFLAGS=-Wall -Wshadow -g -O
+LDFLAGS=-lm
+
+PREFIX=/usr
+
+NAME=wolfhammer
+OBJS=wolfhammer.o
+
+.PHONY: all install uninstall clean depend spotless
+
+all: $(NAME)
+
+$(NAME): $(OBJS)
+
+install: $(NAME)
+ install -D $(NAME) $(PREFIX)/bin/$(NAME)
+
+uninstall:
+ rm -f $(PREFIX)/bin/$(NAME)
+
+depend:
+ $(CPP) $(CFLAGS) -MM -MG *.c >.depend || \
+ { rm -f .depend; exit 1; }
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
+
+clean:
+ rm -f $(OBJS) .depend
+
+spotless: clean
+ rm -f $(NAME)
Added: developers/werner/wolfhammer/wolfhammer.c
===================================================================
--- developers/werner/wolfhammer/wolfhammer.c (rev 0)
+++ developers/werner/wolfhammer/wolfhammer.c 2009-01-13 17:03:14 UTC (rev 4884)
@@ -0,0 +1,113 @@
+/*
+ * wolfhammer.c - Hammer the Wolfson codec over I2C (toggle MICBIAS)
+ *
+ * Copyright (C) 2009 by OpenMoko, Inc.
+ * Written by Werner Almesberger <werner at openmoko.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+#include <linux/i2c.h>
+#include <linux/i2c-dev.h>
+
+
+#define I2C_DEVICE "/dev/i2c-0"
+#define I2C_ADDRESS 0x1a
+
+
+/*
+ * Register 0x14, Power Management (1)
+ *
+ * Bit#
+ * 7-8 VMIDSEL 3 = max
+ * 6 VREF 1 = on
+ * 5 MICB 0 = off, 1 = on
+ * 4 VDAC 0 = off
+ * 3 DACL 0 = off
+ * 2 DACR 0 = off
+ * 1 0
+ * 0 DIGENB 0 = MCLK enabled
+ *
+ * Register 0x33, Mic Bias comp control
+ *
+ * Bit#
+ * 8 MBVSEL 0 = 0.9*AVDD, 1 = 0.75*AVDD
+ * 5-6 MICSEL
+ * 4-5 MBSCTHRESH
+ * 1-3 MBTHRESH
+ * 0 MBCEN
+ */
+
+#define MICBIAS_ON 0x14 << 1 | 1, 0xe0
+#define MICBIAS_OFF 0x14 << 1 | 1, 0xc0
+
+
+static void codec_write(int fd, uint8_t reg, uint8_t value)
+{
+ struct i2c_smbus_ioctl_data msg = {
+ .read_write = I2C_SMBUS_WRITE,
+ .command = reg,
+ .size = I2C_SMBUS_BYTE_DATA,
+ .data = (void *) &value,
+ };
+
+ if (ioctl(fd, I2C_SMBUS, (void *) &msg) < 0) {
+ perror("ioctl(I2C_SMBUS)");
+ exit(1);
+ }
+}
+
+
+static int codec_open(void)
+{
+ int fd;
+
+ fd = open(I2C_DEVICE, O_RDWR);
+ if (fd < 0) {
+ perror(I2C_DEVICE);
+ exit(1);
+ }
+ if (ioctl(fd, I2C_SLAVE_FORCE, I2C_ADDRESS) < 0) {
+ perror("ioctl(I2C_SLAVE_FORCE)");
+ exit(1);
+ }
+ return fd;
+}
+
+
+static void usage(const char *name)
+{
+ fprintf(stderr, "usage: %s loops\n", name);
+ exit(1);
+}
+
+
+int main(int argc, char **argv)
+{
+ unsigned long n, i;
+ char *end;
+ int fd;
+
+ if (argc != 2)
+ usage(*argv);
+ n = strtoul(argv[1], &end, 0);
+ if (*end)
+ usage(*argv);
+
+ fd = codec_open();
+ for (i = 0; i != n; i++) {
+ codec_write(fd, MICBIAS_ON);
+ codec_write(fd, MICBIAS_OFF);
+ }
+ return 0;
+}
More information about the commitlog
mailing list