Add AMD Fam10 B3 default settings to match AMD example code.
[coreboot.git] / util / flashrom / sst49lfxxxc.c
index 52f865a225afabfe3700f2e76a4c94be32174c19..b6693efb11d5e22076b0484cdc0b18633bf13c64 100644 (file)
@@ -1,28 +1,22 @@
 /*
- * 49lfxxxc.c: driver for SST49LFXXXC flash models.
+ * This file is part of the flashrom project.
  *
+ * Copyright (C) 2000 Silicon Integrated System Corporation
+ * Copyright (C) 2005-2007 coresystems GmbH
  *
- * Copyright 2000 Silicon Integrated System Corporation
- * Copyright 2005 coresystems GmbH <stepan@openbios.org>
+ * 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *
- * Reference:
- *     SST49LFxxxC data sheets
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
-
 #include "flash.h"
-#include "jedec.h"
-#include "debug.h"
 
 #define SECTOR_ERASE           0x30
 #define BLOCK_ERASE            0x20
@@ -74,7 +65,7 @@ static __inline__ int write_lockbits_49lfxxxc(volatile uint8_t *bios, int size,
        //printf("lockbits at address=0x%08lx is 0x%01x\n", (unsigned long)0xFFc00000 - size + address + 2, *(bios + address + 2) );
        *(bios + address + 2) = bits;
 
-       return (0);
+       return 0;
 }
 
 static __inline__ int erase_sector_49lfxxxc(volatile uint8_t *bios,
@@ -94,7 +85,7 @@ static __inline__ int erase_sector_49lfxxxc(volatile uint8_t *bios,
                }
        } while (!(status & STATUS_WSMS));
 
-       return (0);
+       return 0;
 }
 
 static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
@@ -127,14 +118,14 @@ static __inline__ int write_sector_49lfxxxc(volatile uint8_t *bios,
                } while (!(status & STATUS_WSMS));
        }
 
-       return (0);
+       return 0;
 }
 
 int probe_49lfxxxc(struct flashchip *flash)
 {
-       volatile uint8_t *bios = flash->virt_addr;
+       volatile uint8_t *bios = flash->virtual_memory;
+
        uint8_t id1, id2;
-       size_t size = flash->total_size * 1024;
 
        *bios = RESET;
 
@@ -145,34 +136,30 @@ int probe_49lfxxxc(struct flashchip *flash)
        *bios = RESET;
 
        printf_debug("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2);
+
        if (!(id1 == flash->manufacture_id && id2 == flash->model_id))
                return 0;
 
-       bios = mmap(0, size, PROT_WRITE | PROT_READ, MAP_SHARED,
-                   fd_mem, (off_t) (0xFFFFFFFF - 0x400000 - size + 1));
-       if (bios == MAP_FAILED) {
-               // it's this part but we can't map it ...
-               perror("Error MMAP /dev/mem");
-               exit(1);
-       }
-       flash->virt_addr_2 = bios;
+       map_flash_registers(flash);
+
        return 1;
 }
 
 int erase_49lfxxxc(struct flashchip *flash)
 {
-       volatile uint8_t *bios = flash->virt_addr;
-       volatile uint8_t *bios2 = flash->virt_addr_2;
+       volatile uint8_t *bios = flash->virtual_memory;
+       volatile uint8_t *registers = flash->virtual_registers;
        int i;
        unsigned int total_size = flash->total_size * 1024;
 
-       write_lockbits_49lfxxxc(bios2, total_size, 0);
+       write_lockbits_49lfxxxc(registers, total_size, 0);
        for (i = 0; i < total_size; i += flash->page_size)
                if (erase_sector_49lfxxxc(bios, i) != 0)
                        return (-1);
 
        *bios = RESET;
-       return (0);
+
+       return 0;
 }
 
 int write_49lfxxxc(struct flashchip *flash, uint8_t *buf)
@@ -180,10 +167,10 @@ int write_49lfxxxc(struct flashchip *flash, uint8_t *buf)
        int i;
        int total_size = flash->total_size * 1024;
        int page_size = flash->page_size;
-       volatile uint8_t *bios = flash->virt_addr;
+       volatile uint8_t *bios = flash->virtual_memory;
 
-       write_lockbits_49lfxxxc(flash->virt_addr_2, total_size, 0);
-       printf("Programming Page: ");
+       write_lockbits_49lfxxxc(flash->virtual_registers, total_size, 0);
+       printf("Programming page: ");
        for (i = 0; i < total_size / page_size; i++) {
                /* erase the page before programming */
                erase_sector_49lfxxxc(bios, i * page_size);
@@ -197,5 +184,6 @@ int write_49lfxxxc(struct flashchip *flash, uint8_t *buf)
        printf("\n");
 
        *bios = RESET;
-       return (0);
+
+       return 0;
 }