From 0c2b98274fff9bd39e94114617776c33bb542b63 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 7 Mar 2011 17:07:44 -0300 Subject: [PATCH] avrdude/patches/nanonote.patch: added clock output with -x clk=#MHz - nanonote.c (nanonote_open): increased register window to include clock and MMC controller registers - nanonote.c (gpio_function): set a pin to function or GPIO - nanonote.c (nanonote_initpgm, nanonote_parseextparams): accept the extended option clk=N where N is the clock frequency in (whole) MHz - nanonote.c (nanonote_enable): if the clock option is set, switch CLK to function and output the specified clock --- avrdude/patches/nanonote.patch | 118 +++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 19 deletions(-) diff --git a/avrdude/patches/nanonote.patch b/avrdude/patches/nanonote.patch index acc9f3a..c264174 100644 --- a/avrdude/patches/nanonote.patch +++ b/avrdude/patches/nanonote.patch @@ -1,7 +1,7 @@ Index: avrdude/avrdude-5.10/Makefile.am =================================================================== ---- avrdude.orig/avrdude-5.10/Makefile.am 2011-02-15 00:16:48.000000000 -0300 -+++ avrdude/avrdude-5.10/Makefile.am 2011-02-15 00:16:52.000000000 -0300 +--- avrdude.orig/avrdude-5.10/Makefile.am 2011-03-07 15:10:10.000000000 -0300 ++++ avrdude/avrdude-5.10/Makefile.am 2011-03-07 15:10:12.000000000 -0300 @@ -111,6 +111,8 @@ lists.c \ lists.h \ @@ -13,8 +13,8 @@ Index: avrdude/avrdude-5.10/Makefile.am pgm.c \ Index: avrdude/avrdude-5.10/config_gram.y =================================================================== ---- avrdude.orig/avrdude-5.10/config_gram.y 2011-02-15 00:16:48.000000000 -0300 -+++ avrdude/avrdude-5.10/config_gram.y 2011-02-15 00:16:52.000000000 -0300 +--- avrdude.orig/avrdude-5.10/config_gram.y 2011-03-07 15:10:10.000000000 -0300 ++++ avrdude/avrdude-5.10/config_gram.y 2011-03-07 15:10:12.000000000 -0300 @@ -48,6 +48,7 @@ #include "avr.h" #include "jtagmkI.h" @@ -46,8 +46,8 @@ Index: avrdude/avrdude-5.10/config_gram.y current_prog->desc[PGM_DESCLEN-1] = 0; Index: avrdude/avrdude-5.10/lexer.l =================================================================== ---- avrdude.orig/avrdude-5.10/lexer.l 2011-02-15 00:16:48.000000000 -0300 -+++ avrdude/avrdude-5.10/lexer.l 2011-02-15 00:16:52.000000000 -0300 +--- avrdude.orig/avrdude-5.10/lexer.l 2011-03-07 15:10:10.000000000 -0300 ++++ avrdude/avrdude-5.10/lexer.l 2011-03-07 15:10:12.000000000 -0300 @@ -164,6 +164,7 @@ min_write_delay { yylval=NULL; return K_MIN_WRITE_DELAY; } miso { yylval=NULL; return K_MISO; } @@ -59,8 +59,8 @@ Index: avrdude/avrdude-5.10/lexer.l Index: avrdude/avrdude-5.10/nanonote.c =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ avrdude/avrdude-5.10/nanonote.c 2011-02-15 00:20:23.000000000 -0300 -@@ -0,0 +1,290 @@ ++++ avrdude/avrdude-5.10/nanonote.c 2011-03-07 16:41:00.000000000 -0300 +@@ -0,0 +1,370 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2000, 2001, 2002, 2003 Brian S. Dean @@ -100,6 +100,12 @@ Index: avrdude/avrdude-5.10/nanonote.c +#include "bitbang.h" + + ++struct pdata { ++ unsigned clk; /* clock output on CLK; 0 if none */ ++}; ++ ++#define PDATA(pgm) ((struct pdata *) (pgm)->cookie) ++ + +static volatile void *mem; + @@ -129,16 +135,28 @@ Index: avrdude/avrdude-5.10/nanonote.c +}; + + -+#define BASE 0x10010000 ++#define BASE 0x10000000 ++#define REG_WINDOW 0x30000 + +#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) ++#define CGU(n) REG(0x00000+(n)) ++#define GPIO(n) REG(0x10000+(n)) ++#define MSC(n) REG(0x21000+(n)) ++ ++#define port_pin(port) GPIO(port*0x100) ++#define port_dats(port) GPIO(port*0x100+0x14) ++#define port_datc(port) GPIO(port*0x100+0x18) ++#define port_funs(port) GPIO(port*0x100+0x44) ++#define port_func(port) GPIO(port*0x100+0x48) ++#define port_dirs(port) GPIO(port*0x100+0x64) ++#define port_dirc(port) GPIO(port*0x100+0x68) ++ ++#define MSC_STRPCL MSC(0x00) /* Start/stop MMC/SD clock */ ++#define MSC_CLKRT MSC(0x08) /* MSC Clock Rate */ ++ ++#define CLKGR CGU(0x0020) /* Clock Gate */ ++#define MSCCDR CGU(0x0068) /* MSC device clock divider */ + + +static inline void gpio_high(unsigned port, unsigned bit) @@ -180,6 +198,15 @@ Index: avrdude/avrdude-5.10/nanonote.c +} + + ++static void gpio_function(unsigned port, unsigned bit, int on) ++{ ++ if (on) ++ port_funs(port) = 1 << bit; ++ else ++ port_func(port) = 1 << bit; ++} ++ ++ +static int nanonote_setpin(PROGRAMMER *pgm, int pin, int value) +{ + if (pin & PIN_INVERSE) { @@ -258,15 +285,43 @@ Index: avrdude/avrdude-5.10/nanonote.c + +static void nanonote_enable(PROGRAMMER *pgm) +{ ++ int div, log2 = 0; ++ + misc_high(pgm); -+ /* @@@ set CLK to function and output clock */ ++ if (!PDATA(pgm)->clk) ++ return; ++ ++ /* give the bus clock output to the MMC controller */ ++ gpio_function(CLK, 1); ++ ++ /* ++ * set the MSC clock divider, dividing the 316 MHz system clock ++ */ ++ div = 316/PDATA(pgm)->clk+1; ++ while (div > 32) { ++ log2++; ++ div = (div+1)/2; ++ } ++ MSCCDR = div-1; ++ ++ /* ++ * Enable the MSC clock. We need to do this before accessing any ++ * registers of the MSC block ! ++ */ ++ CLKGR &= ~(1 << 7); ++ ++ /* bus clock = MSC clock / 2^log2 */ ++ MSC_CLKRT = log2; ++ ++ /* start MMC clock output */ ++ MSC_STRPCL = 2; +} + + +static void nanonote_disable(PROGRAMMER *pgm) +{ + misc_high(pgm); -+ /* @@@ set CLK to GPIO */ ++ gpio_function(CLK, 0); /* set CLK to GPIO */ + gpio_high(CLK); +} + @@ -298,7 +353,7 @@ Index: avrdude/avrdude-5.10/nanonote.c + perror("/dev/mem"); + return -1; + } -+ mem = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, ++ mem = mmap(NULL, REG_WINDOW, PROT_READ | PROT_WRITE, MAP_SHARED, + pgm->fd.ifd, BASE); + if (mem == MAP_FAILED) { + perror("mmap"); @@ -326,6 +381,23 @@ Index: avrdude/avrdude-5.10/nanonote.c +} + + ++static int nanonote_parseextparams(PROGRAMMER *pgm, LISTID extparms) ++{ ++ LNODEID n; ++ const char *param; ++ ++ for (n = lfirst(extparms); n; n = lnext(n)) { ++ param = ldata(n); ++ if (sscanf(param, "clk=%u", &PDATA(pgm)->clk) == 1) ++ continue; ++ fprintf(stderr, "unrecognized parameter \"%s\"\n", param); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++ +void nanonote_initpgm(PROGRAMMER *pgm) +{ + strcpy(pgm->type, "NANONOTE"); @@ -350,11 +422,19 @@ Index: avrdude/avrdude-5.10/nanonote.c + pgm->highpulsepin = nanonote_highpulsepin; + pgm->read_byte = avr_read_byte_default; + pgm->write_byte = avr_write_byte_default; ++ pgm->parseextparams = nanonote_parseextparams; ++ ++ pgm->cookie = malloc(sizeof(struct pdata)); ++ if (!pgm->cookie) { ++ perror("malloc"); ++ exit(1); ++ } ++ PDATA(pgm)->clk = 0; +} Index: avrdude/avrdude-5.10/nanonote.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 -+++ avrdude/avrdude-5.10/nanonote.h 2011-02-15 00:16:52.000000000 -0300 ++++ avrdude/avrdude-5.10/nanonote.h 2011-03-07 15:10:12.000000000 -0300 @@ -0,0 +1,6 @@ +#ifndef nanonote_h +#define nanonote_h