diff --git a/f32x/Makefile b/f32x/Makefile index dc27598..44f06bc 100644 --- a/f32x/Makefile +++ b/f32x/Makefile @@ -18,12 +18,16 @@ TARGET = om endif CC_om = arm-angstrom-linux-gnueabi-gcc +CC_ben = mipsel-openwrt-linux-gcc CFLAGS_om = -O -DDRIVER=c2_om +CFLAGS_ben = -DDRIVER=c2_ben LDFLAGS_om = +LDFLAGS_ben = OBJS_om = c2-om.o gpio-s3c24xx.o rt.o +OBJS_ben = c2-ben.o gpio-xburst.o NAME = f32x CC = $(CC_$(TARGET)) @@ -56,9 +60,10 @@ include .depend endif c2-om.o: c2-bitbang.c +c2-ben.o: c2-bitbang.c clean: - rm -f $(OBJS) $(OBJS_om) .depend + rm -f $(OBJS) $(OBJS_om) $(OBJS_ben) .depend spotless: clean rm -f $(NAME) diff --git a/f32x/c2-ben.c b/f32x/c2-ben.c new file mode 100644 index 0000000..8e7b1eb --- /dev/null +++ b/f32x/c2-ben.c @@ -0,0 +1,43 @@ +/* + * f32x/c2-ben.c - Basic C2 messages, driver for Openmoko GTA01/GTA02+DebugV3 + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * 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 + + +#include "gpio-xburst.h" +#include "c2-drv.h" + + +#define POWER_OFF 3, 2 /* PD02, drive low to enable power */ +#define C2CK 3, 8 /* PD08 */ +#define C2D 3, 12 /* PD12 */ + + +#include "c2-bitbang.c" + + +static void ben_init(void) +{ + gpio_init(); + gpio_low(POWER_OFF); + c2_init(); + +} + + +struct c2_ops c2_ben = { + .init = ben_init, + .reset = c2_reset, + .addr_write = c2_addr_write, + .addr_read = c2_addr_read, + .data_write = c2_data_write, + .data_read = c2_data_read, +}; diff --git a/f32x/gpio-xburst.c b/f32x/gpio-xburst.c new file mode 100644 index 0000000..0b0e12e --- /dev/null +++ b/f32x/gpio-xburst.c @@ -0,0 +1,42 @@ +/* + * f32x/gpio-xburst.c - Really primitive XBurst GPIO access + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * 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 +#include +#include +#include + +#include "gpio-xburst.h" + + +#define BASE 0x10010000 + + +volatile void *mem; + + +void gpio_init(void) +{ + int fd; + + fd = open("/dev/mem", O_RDWR); + if (fd < 0) { + perror("/dev/mem"); + exit(1); + } + mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, BASE); + if (mem == MAP_FAILED) { + perror("mmap"); + exit(1); + } +} diff --git a/f32x/gpio-xburst.h b/f32x/gpio-xburst.h new file mode 100644 index 0000000..ae70320 --- /dev/null +++ b/f32x/gpio-xburst.h @@ -0,0 +1,80 @@ +/* + * f32x/gpio-xburst.h - Really primitive XBurst GPIO access + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * 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. + */ + +/* + * Ports are numbered 0 = A, 1 = B, ... + */ + + +#ifndef GPIO_XBURST_H +#define GPIO_XBURST_H + + +#include + + +volatile void *mem; + + +#define REG(off) (*(volatile uint32_t *) (mem+(off))) + +#define port_pin(port) REG(port*0x100) +#define port_dats(port) REG(port*0x100+0x14) +#define port_datc(port) REG(port*0x100+0x18) +#define port_func(port) REG(port*0x100+0x48) +#define port_dirs(port) REG(port*0x100+0x64) +#define port_dirc(port) REG(port*0x100+0x68) + + +static inline void gpio_high(unsigned port, unsigned bit) +{ + port_dats(port) = 1 << bit; +} + + +static inline void gpio_low(unsigned port, unsigned bit) +{ + port_datc(port) = 1 << bit; +} + + +static inline void gpio_set(unsigned port, unsigned bit, int value) +{ + if (value) + gpio_high(port, bit); + else + gpio_low(port, bit); +} + + +static inline int gpio_get(unsigned port, unsigned bit) +{ + return (port_pin(port) >> bit) & 1; +} + + +static inline void gpio_output(unsigned port, unsigned bit) +{ + port_dirs(port) = 1 << bit; +} + + +static inline void gpio_input(unsigned port, unsigned bit) +{ + port_dirc(port) = 1 << bit; +} + + +void gpio_init(void); + + +#endif /* !GPIO_XBURST_H */