From 4cb7962bdcbf9d7d363cd97becea9d3eb1850c8a Mon Sep 17 00:00:00 2001 From: Marcel Telka Date: Wed, 13 Aug 2003 14:58:49 +0000 Subject: [PATCH] 2003-08-13 Marcel Telka * include/bus.h (new_sh7751r_bus): New function declaration (patch 773533, Matan Ziv-Av). * src/bus/Makefile.am (libbus_a_SOURCES): Added sh7751r.c (patch 773533, Matan Ziv-Av). * src/bus/sh7751r.c: New file (patch 773533, Matan Ziv-Av). git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@508 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- jtag/ChangeLog | 6 + jtag/NEWS | 1 + jtag/THANKS | 2 + jtag/include/bus.h | 1 + jtag/src/bus/Makefile.am | 3 +- jtag/src/bus/sh7751r.c | 328 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 jtag/src/bus/sh7751r.c diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 5b59fb5f..3fcd4b02 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,9 @@ +2003-08-13 Marcel Telka + + * include/bus.h (new_sh7751r_bus): New function declaration (patch 773533, Matan Ziv-Av). + * src/bus/Makefile.am (libbus_a_SOURCES): Added sh7751r.c (patch 773533, Matan Ziv-Av). + * src/bus/sh7751r.c: New file (patch 773533, Matan Ziv-Av). + 2003-08-13 Marcel Telka * include/part.h (struct part): Added new member 'id'. diff --git a/jtag/NEWS b/jtag/NEWS index da75fe00..35ac42c2 100644 --- a/jtag/NEWS +++ b/jtag/NEWS @@ -8,6 +8,7 @@ jtag-0.5: * Added new commands 'peek' and 'poke' (patch 747447, Matan Ziv-Av). * Fixed bugs in SH7727 bus driver (thanks to Rainer Dörken). * Added bus drivers for Hitachi SH7750R and Broadcom BCM1250 (patch 753300, Matan Ziv-Av). + * Added bus driver for Hitachi SH7751R (patch 773533, Matan Ziv-Av). * Added bus width detection using MD3 and MD4 signals in SH7727 bus driver (thanks to Rainer Dörken). * Changes in 'discovery' command: diff --git a/jtag/THANKS b/jtag/THANKS index 71b7f452..fd941084 100644 --- a/jtag/THANKS +++ b/jtag/THANKS @@ -1,5 +1,7 @@ $Id$ +See also libbrux/THANKS. + Ian Campbell Alex (d18c7db) Rainer Dörken diff --git a/jtag/include/bus.h b/jtag/include/bus.h index 15981847..e64af6d5 100644 --- a/jtag/include/bus.h +++ b/jtag/include/bus.h @@ -47,6 +47,7 @@ bus_t *new_pxa250_bus( chain_t *chain, int pn ); bus_t *new_ixp425_bus( chain_t *chain, int pn ); bus_t *new_sh7727_bus( chain_t *chain, int pn ); bus_t *new_sh7750r_bus( chain_t *chain, int pn ); +bus_t *new_sh7751r_bus( chain_t *chain, int pn ); bus_t *new_bcm1250_bus( chain_t *chain, int pn ); #endif /* BUS_H */ diff --git a/jtag/src/bus/Makefile.am b/jtag/src/bus/Makefile.am index 3feb4d99..5a60844c 100644 --- a/jtag/src/bus/Makefile.am +++ b/jtag/src/bus/Makefile.am @@ -32,4 +32,5 @@ libbus_a_SOURCES = \ pxa2x0.c \ sa1110.c \ sh7727.c \ - sh7750r.c + sh7750r.c \ + sh7751r.c diff --git a/jtag/src/bus/sh7751r.c b/jtag/src/bus/sh7751r.c new file mode 100644 index 00000000..03b2e80a --- /dev/null +++ b/jtag/src/bus/sh7751r.c @@ -0,0 +1,328 @@ +/* + * $Id$ + * + * Copyright (C) 2003 ETC s.r.o. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by Matan Ziv-Av , 2003. + * Modified by Marcel Telka , 2003. + * + */ + +#include + +#include +#include +#include + +#include "part.h" +#include "bus.h" +#include "chain.h" +#include "bssignal.h" + +typedef struct { + chain_t *chain; + part_t *part; + signal_t *a[26]; + signal_t *d[32]; + signal_t *cs[8]; + signal_t *we[4]; + signal_t *rdwr; + signal_t *rd; + signal_t *bs; +} bus_params_t; + +#define CHAIN ((bus_params_t *) bus->params)->chain +#define PART ((bus_params_t *) bus->params)->part +#define A ((bus_params_t *) bus->params)->a +#define D ((bus_params_t *) bus->params)->d +#define CS ((bus_params_t *) bus->params)->cs +#define WE ((bus_params_t *) bus->params)->we +#define RDWR ((bus_params_t *) bus->params)->rdwr +#define RD ((bus_params_t *) bus->params)->rd +#define BS ((bus_params_t *) bus->params)->bs + +static void +setup_address( bus_t *bus, uint32_t a ) +{ + int i; + part_t *p = PART; + + for (i = 0; i < 26; i++) + part_set_signal( p, A[i], 1, (a >> i) & 1 ); +} + +static void +set_data_in( bus_t *bus ) +{ + int i; + part_t *p = PART; + + for (i = 0; i < 32; i++) + part_set_signal( p, D[i], 0, 0 ); +} + +static void +setup_data( bus_t *bus, uint32_t d ) +{ + int i; + part_t *p = PART; + + for (i = 0; i < 32; i++) + part_set_signal( p, D[i], 1, (d >> i) & 1 ); +} + +static void +sh7751r_bus_prepare( bus_t *bus ) +{ + part_set_instruction( PART, "EXTEST" ); + chain_shift_instructions( CHAIN ); +} + +static void +sh7751r_bus_read_start( bus_t *bus, uint32_t adr ) +{ + part_t *p = PART; + int cs[8]; + int i; + + for (i = 0; i < 8; i++) + cs[i] = 1; + cs[(adr & 0x1C000000) >> 26] = 0; + + part_set_signal( p, CS[0], 1, cs[0] ); + part_set_signal( p, CS[1], 1, cs[1] ); + part_set_signal( p, CS[2], 1, cs[2] ); + part_set_signal( p, CS[3], 1, cs[3] ); + part_set_signal( p, CS[4], 1, cs[4] ); + part_set_signal( p, CS[5], 1, cs[5] ); + part_set_signal( p, CS[6], 1, cs[6] ); + part_set_signal( p, RDWR, 1, 1 ); + part_set_signal( p, WE[0], 1, 1 ); + part_set_signal( p, WE[1], 1, 1 ); + part_set_signal( p, WE[2], 1, 1 ); + part_set_signal( p, WE[3], 1, 1 ); + part_set_signal( p, RD, 1, 0 ); + + setup_address( bus, adr ); + set_data_in( bus ); + chain_shift_data_registers( CHAIN, 0 ); +} + +static uint32_t +sh7751r_bus_read_next( bus_t *bus, uint32_t adr ) +{ + part_t *p = PART; + int i; + uint32_t d = 0; + + setup_address( bus, adr ); + chain_shift_data_registers( CHAIN, 1 ); + + for (i = 0; i < 32; i++) + d |= (uint32_t) (part_get_signal( p, D[i] ) << i); + + return d; +} + +static uint32_t +sh7751r_bus_read_end( bus_t *bus ) +{ + part_t *p = PART; + int cs[8]; + int i; + uint32_t d = 0; + + for (i = 0; i < 8; i++) + cs[i] = 1; + + part_set_signal( p, CS[0], 1, cs[0] ); + part_set_signal( p, CS[1], 1, cs[1] ); + part_set_signal( p, CS[2], 1, cs[2] ); + part_set_signal( p, CS[3], 1, cs[3] ); + part_set_signal( p, CS[4], 1, cs[4] ); + part_set_signal( p, CS[5], 1, cs[5] ); + part_set_signal( p, CS[6], 1, cs[6] ); + + part_set_signal( p, RD, 1, 1 ); + chain_shift_data_registers( CHAIN, 1 ); + + for (i = 0; i < 32; i++) + d |= (uint32_t) (part_get_signal( p, D[i] ) << i); + + return d; +} + +static uint32_t +sh7751r_bus_read( bus_t *bus, uint32_t adr ) +{ + sh7751r_bus_read_start( bus, adr ); + return sh7751r_bus_read_end( bus ); +} + +static void +sh7751r_bus_write( bus_t *bus, uint32_t adr, uint32_t data ) +{ + chain_t *chain = CHAIN; + part_t *p = PART; + int cs[8]; + int i; + + for (i = 0; i < 8 ; i++) + cs[i] = 1; + cs[(adr & 0x1C000000) >> 26] = 0; + + part_set_signal( p, CS[0], 1, cs[0] ); + part_set_signal( p, CS[1], 1, cs[1] ); + part_set_signal( p, CS[2], 1, cs[2] ); + part_set_signal( p, CS[3], 1, cs[3] ); + part_set_signal( p, CS[4], 1, cs[4] ); + part_set_signal( p, CS[5], 1, cs[5] ); + part_set_signal( p, CS[6], 1, cs[6] ); + + part_set_signal( p, RDWR, 1, 0 ); + part_set_signal( p, WE[0], 1, 1 ); + part_set_signal( p, WE[1], 1, 1 ); + part_set_signal( p, WE[2], 1, 1 ); + part_set_signal( p, WE[3], 1, 1 ); + part_set_signal( p, RD, 1, 1 ); + + setup_address( bus, adr ); + setup_data( bus, data ); + chain_shift_data_registers( chain, 0 ); + + part_set_signal( p, WE[0], 1, 0 ); + part_set_signal( p, WE[1], 1, 0 ); + part_set_signal( p, WE[2], 1, 0 ); + part_set_signal( p, WE[3], 1, 0 ); + + chain_shift_data_registers( chain, 0 ); + + part_set_signal( p, WE[0], 1, 1 ); + part_set_signal( p, WE[1], 1, 1 ); + part_set_signal( p, WE[2], 1, 1 ); + part_set_signal( p, WE[3], 1, 1 ); + + chain_shift_data_registers( chain, 0 ); +} + +static unsigned int +sh7751r_bus_width( bus_t *bus, uint32_t adr ) +{ + return 16; +} + +static void +sh7751r_bus_free( bus_t *bus ) +{ + free( bus->params ); + free( bus ); +} + +static const bus_t sh7751r_bus = { + NULL, + sh7751r_bus_prepare, + sh7751r_bus_width, + sh7751r_bus_read_start, + sh7751r_bus_read_next, + sh7751r_bus_read_end, + sh7751r_bus_read, + sh7751r_bus_write, + sh7751r_bus_free +}; + +bus_t * +new_sh7751r_bus( chain_t *chain, int pn ) +{ + bus_t *bus; + char buff[10]; + int i; + int failed = 0; + + if (!chain || !chain->parts || chain->parts->len <= pn || pn < 0) + return NULL; + + bus = malloc( sizeof (bus_t) ); + if (!bus) + return NULL; + + memcpy( bus, &sh7751r_bus, sizeof (bus_t) ); + + bus->params = calloc( 1, sizeof (bus_params_t) ); + if (!bus->params) { + free( bus ); + return NULL; + } + + CHAIN = chain; + PART = chain->parts->parts[pn]; + + for (i = 0; i < 26; i++) { + sprintf( buff, "A%d", i ); + A[i] = part_find_signal( PART, buff ); + if (!A[i]) { + printf( _("signal '%s' not found\n"), buff ); + failed = 1; + break; + } + } + for (i = 0; i < 32; i++) { + sprintf( buff, "D%d", i ); + D[i] = part_find_signal( PART, buff ); + if (!D[i]) { + printf( _("signal '%s' not found\n"), buff ); + failed = 1; + break; + } + } + for (i = 0; i < 7; i++) { + sprintf( buff, "CS%d", i ); + CS[i] = part_find_signal( PART, buff ); + if (!CS[i]) { + printf( _("signal '%s' not found\n"), buff ); + failed = 1; + break; + } + } + for (i = 0; i < 4; i++) { + sprintf( buff, "WE%d", i ); + WE[i] = part_find_signal( PART, buff ); + if (!WE[i]) { + printf( _("signal '%s' not found\n"), buff ); + failed = 1; + break; + } + } + RDWR = part_find_signal( PART, "RD_WR" ); + if (!RDWR) { + printf( _("signal '%s' not found\n"), "RDWR" ); + failed = 1; + } + RD = part_find_signal( PART, "RD_CASS_FRAME" ); + if (!RD) { + printf( _("signal '%s' not found\n"), "RD" ); + failed = 1; + } + + if (failed) { + free( bus->params ); + free( bus ); + return NULL; + } + + return bus; +}