diff --git avrdude/usbasp.c avrdude/usbasp.c
index bf34847..9b640b1 100644
--- avrdude/usbasp.c
+++ avrdude/usbasp.c
@@ -161,7 +161,6 @@ static int usbasp_spi_set_sck_period(PROGRAMMER *pgm, double sckperiod);
 static void usbasp_tpi_send_byte(PROGRAMMER * pgm, uint8_t b);
 static int usbasp_tpi_cmd(PROGRAMMER * pgm, unsigned char cmd[4], unsigned char res[4]);
 static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p);
-static int usbasp_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p);
 static int usbasp_tpi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
                                  unsigned int page_size,
                                  unsigned int addr, unsigned int n_bytes);
@@ -171,6 +170,7 @@ static int usbasp_tpi_paged_write(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
 static int usbasp_tpi_set_sck_period(PROGRAMMER *pgm, double sckperiod);
 static int usbasp_tpi_read_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char * value);
 static int usbasp_tpi_write_byte(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m, unsigned long addr, unsigned char data);
+static int usbasp_cmd_tpi(PROGRAMMER * pgm, unsigned char cmd[], int cmd_len, unsigned char res[], int res_len);
 
 
 /* Interface - management */
@@ -522,6 +522,8 @@ static int usbasp_initialize(PROGRAMMER * pgm, AVRPART * p)
 
   pdata->use_tpi = ((pdata->capabilities & USBASP_CAP_TPI) != 0 && (p->flags & AVRPART_HAS_TPI) != 0) ? 1 : 0;
 
+  pgm->cmd_tpi = usbasp_cmd_tpi;
+
   if(pdata->use_tpi)
   {
     /* calc tpiclk delay */
@@ -538,7 +540,7 @@ static int usbasp_initialize(PROGRAMMER * pgm, AVRPART * p)
     
     /* change interface */
     pgm->program_enable = usbasp_tpi_program_enable;
-    pgm->chip_erase     = usbasp_tpi_chip_erase;
+    pgm->chip_erase     = avr_tpi_chip_erase;
     pgm->cmd            = usbasp_tpi_cmd;
     pgm->read_byte      = usbasp_tpi_read_byte;
     pgm->write_byte     = usbasp_tpi_write_byte;
@@ -890,71 +892,29 @@ static int usbasp_tpi_nvm_waitbusy(PROGRAMMER * pgm)
   return -1;
 }
 
-static int usbasp_tpi_cmd(PROGRAMMER * pgm, unsigned char cmd[4], unsigned char res[4])
+static int usbasp_cmd_tpi(PROGRAMMER * pgm, unsigned char cmd[], int cmd_len, unsigned char res[], int res_len)
 {
-  fprintf(stderr, "%s: error: spi_cmd used in TPI mode: not allowed\n", progname);
-  return -1;
-}
+  int i;
 
-static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
-{
-  int retry;
+  for(i = 0; i < cmd_len; i++)
+    usbasp_tpi_send_byte(pgm, cmd[i]);
 
-  
-  /* change guard time */
-  usbasp_tpi_send_byte(pgm, TPI_OP_SSTCS(TPIPCR));
-  usbasp_tpi_send_byte(pgm, TPIPCR_GT_2b);
-
-  /* send SKEY */
-  usbasp_tpi_send_byte(pgm, 0xE0);
-  usbasp_tpi_send_byte(pgm, 0xFF);
-  usbasp_tpi_send_byte(pgm, 0x88);
-  usbasp_tpi_send_byte(pgm, 0xD8);
-  usbasp_tpi_send_byte(pgm, 0xCD);
-  usbasp_tpi_send_byte(pgm, 0x45);
-  usbasp_tpi_send_byte(pgm, 0xAB);
-  usbasp_tpi_send_byte(pgm, 0x89);
-  usbasp_tpi_send_byte(pgm, 0x12);
-
-  /* check if device is ready */
-  for(retry=0; retry<10; retry++)
-  {
-    usbasp_tpi_send_byte(pgm, TPI_OP_SLDCS(TPIIR));
-    if(usbasp_tpi_recv_byte(pgm) != 0x80)
-      continue;
-    usbasp_tpi_send_byte(pgm, TPI_OP_SLDCS(TPISR));
-    if((usbasp_tpi_recv_byte(pgm) & TPISR_NVMEN) == 0)
-      continue;
-    break;
-  }
-  if(retry >= 10)
-  {
-    fprintf(stderr, "%s: error: programm enable: target doesn't answer.\n", progname);
-    return -1;
-  }
+  for(i = 0; i < res_len; i++)
+    res[i] = usbasp_tpi_recv_byte(pgm);
 
   return 0;
+
 }
 
-static int usbasp_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p)
+static int usbasp_tpi_cmd(PROGRAMMER * pgm, unsigned char cmd[4], unsigned char res[4])
 {
-  /* Set PR to flash */
-  usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(0));
-  usbasp_tpi_send_byte(pgm, 0x01);
-  usbasp_tpi_send_byte(pgm, TPI_OP_SSTPR(1));
-  usbasp_tpi_send_byte(pgm, 0x40);
-  /* select ERASE */
-  usbasp_tpi_send_byte(pgm, TPI_OP_SOUT(NVMCMD));
-  usbasp_tpi_send_byte(pgm, NVMCMD_CHIP_ERASE);
-  /* dummy write */
-  usbasp_tpi_send_byte(pgm, TPI_OP_SST_INC);
-  usbasp_tpi_send_byte(pgm, 0x00);
-  usbasp_tpi_nvm_waitbusy(pgm);
-  
-  usleep(p->chip_erase_delay);
-  pgm->initialize(pgm, p);
+  fprintf(stderr, "%s: error: spi_cmd used in TPI mode: not allowed\n", progname);
+  return -1;
+}
 
-  return 0;
+static int usbasp_tpi_program_enable(PROGRAMMER * pgm, AVRPART * p)
+{
+	return avr_tpi_program_enable(pgm, p, TPIPCR_GT_2b);
 }
 
 static int usbasp_tpi_paged_load(PROGRAMMER * pgm, AVRPART * p, AVRMEM * m,
