r4542 - in developers/werner: . mmcds
werner at docs.openmoko.org
werner at docs.openmoko.org
Sun Jul 20 04:12:33 CEST 2008
Author: werner
Date: 2008-07-20 04:12:32 +0200 (Sun, 20 Jul 2008)
New Revision: 4542
Added:
developers/werner/mmcds/
developers/werner/mmcds/Makefile
developers/werner/mmcds/mmcds.c
Log:
MMC Drive Strength get/set utility. (GTA02)
Added: developers/werner/mmcds/Makefile
===================================================================
--- developers/werner/mmcds/Makefile (rev 0)
+++ developers/werner/mmcds/Makefile 2008-07-20 02:12:32 UTC (rev 4542)
@@ -0,0 +1,5 @@
+CC=arm-angstrom-linux-gnueabi-gcc
+
+CFLAGS=-Wall -g
+
+all: mmcds
Added: developers/werner/mmcds/mmcds.c
===================================================================
--- developers/werner/mmcds/mmcds.c (rev 0)
+++ developers/werner/mmcds/mmcds.c 2008-07-20 02:12:32 UTC (rev 4542)
@@ -0,0 +1,94 @@
+/*
+ * mmcds.c - Get/set the MMC drive strength (of the Smedia Glamo 3362)
+ *
+ * Copyright (C) 2008 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 <string.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+
+#define BASE 0x08000000
+
+#define MMC_BASIC (*(uint16_t *) (mem+0x1430))
+
+static volatile void *mem;
+
+
+/* ----- Register decoding ------------------------------------------------- */
+
+
+static const char *strength[] = { "min", "low", "high", "max" };
+
+static void show_mmc_basic(uint16_t reg)
+{
+ int drv = (reg >> 6) & 3;
+
+ printf("MMC_BASIC = 0x%04x\n", reg);
+ printf(" MCGIODrv = %d (%s)\n", drv, strength[drv]);
+}
+
+
+/* ----- Command-line parsing ---------------------------------------------- */
+
+
+static void __attribute__((noreturn)) usage(const char *name)
+{
+ fprintf(stderr, "usage: %s [min|low|high|max|0|1|2|3]\n", name);
+ exit(1);
+}
+
+
+static int decode(const char *name, const char *arg)
+{
+ int i;
+
+ for (i = 0; i != 4; i++)
+ if (!strcmp(strength[i], arg) ||
+ (arg[0] == '0'+i && !arg[1]))
+ return i;
+ usage(name);
+}
+
+
+int main(int argc, char **argv)
+{
+ int fd, new;
+
+ fd = open("/dev/mem", O_RDWR);
+ if (fd < 0) {
+ perror("/dev/mem");
+ exit(1);
+ }
+ mem = mmap(NULL, 0x2000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE);
+ if (mem == MAP_FAILED) {
+ perror("mmap");
+ exit(1);
+ }
+ switch (argc) {
+ case 1:
+ show_mmc_basic(MMC_BASIC);
+ break;
+ case 2:
+ new = decode(*argv, argv[1]);
+ /* should disable interrupts around here */
+ MMC_BASIC = (MMC_BASIC & ~(uint16_t) 0xc0) | (new << 6);
+ /* should disable interrupts around here */
+ break;
+ default:
+ usage(*argv);
+ }
+ return 0;
+}
More information about the commitlog
mailing list