| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $ */ | | 1 | /* $NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2010 Department of Software Engineering, | | 4 | * Copyright (c) 2010 Department of Software Engineering, |
5 | * University of Szeged, Hungary | | 5 | * University of Szeged, Hungary |
6 | * Copyright (c) 2010 Adam Hoka <ahoka@NetBSD.org> | | 6 | * Copyright (c) 2010 Adam Hoka <ahoka@NetBSD.org> |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * This code is derived from software contributed to The NetBSD Foundation | | 9 | * This code is derived from software contributed to The NetBSD Foundation |
10 | * by the Department of Software Engineering, University of Szeged, Hungary | | 10 | * by the Department of Software Engineering, University of Szeged, Hungary |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
| @@ -24,27 +24,27 @@ | | | @@ -24,27 +24,27 @@ |
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. | | 31 | * SUCH DAMAGE. |
32 | */ | | 32 | */ |
33 | | | 33 | |
34 | /* Common driver for NAND chips implementing the ONFI 2.2 specification */ | | 34 | /* Common driver for NAND chips implementing the ONFI 2.2 specification */ |
35 | | | 35 | |
36 | #include <sys/cdefs.h> | | 36 | #include <sys/cdefs.h> |
37 | __KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $"); | | 37 | __KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $"); |
38 | | | 38 | |
39 | #include "locators.h" | | 39 | #include "locators.h" |
40 | | | 40 | |
41 | #include <sys/param.h> | | 41 | #include <sys/param.h> |
42 | #include <sys/types.h> | | 42 | #include <sys/types.h> |
43 | #include <sys/device.h> | | 43 | #include <sys/device.h> |
44 | #include <sys/kmem.h> | | 44 | #include <sys/kmem.h> |
45 | #include <sys/atomic.h> | | 45 | #include <sys/atomic.h> |
46 | | | 46 | |
47 | #include <dev/flash/flash.h> | | 47 | #include <dev/flash/flash.h> |
48 | #include <dev/flash/flash_io.h> | | 48 | #include <dev/flash/flash_io.h> |
49 | #include <dev/nand/nand.h> | | 49 | #include <dev/nand/nand.h> |
50 | #include <dev/nand/onfi.h> | | 50 | #include <dev/nand/onfi.h> |
| @@ -853,36 +853,35 @@ nand_write_oob(device_t self, size_t off | | | @@ -853,36 +853,35 @@ nand_write_oob(device_t self, size_t off |
853 | status = nand_get_status(self); | | 853 | status = nand_get_status(self); |
854 | KASSERT(status & ONFI_STATUS_RDY); | | 854 | KASSERT(status & ONFI_STATUS_RDY); |
855 | if (status & ONFI_STATUS_FAIL) | | 855 | if (status & ONFI_STATUS_FAIL) |
856 | return EIO; | | 856 | return EIO; |
857 | else | | 857 | else |
858 | return 0; | | 858 | return 0; |
859 | } | | 859 | } |
860 | | | 860 | |
861 | void | | 861 | void |
862 | nand_markbad(device_t self, size_t offset) | | 862 | nand_markbad(device_t self, size_t offset) |
863 | { | | 863 | { |
864 | struct nand_softc *sc = device_private(self); | | 864 | struct nand_softc *sc = device_private(self); |
865 | struct nand_chip *chip = &sc->sc_chip; | | 865 | struct nand_chip *chip = &sc->sc_chip; |
866 | flash_off_t blockoffset, marker; | | 866 | flash_off_t blockoffset; |
867 | #ifdef NAND_BBT | | 867 | #ifdef NAND_BBT |
868 | flash_off_t block; | | 868 | flash_off_t block; |
869 | | | 869 | |
870 | block = offset / chip->nc_block_size; | | 870 | block = offset / chip->nc_block_size; |
871 | | | 871 | |
872 | nand_bbt_block_markbad(self, block); | | 872 | nand_bbt_block_markbad(self, block); |
873 | #endif | | 873 | #endif |
874 | blockoffset = offset & chip->nc_block_mask; | | 874 | blockoffset = offset & chip->nc_block_mask; |
875 | marker = chip->nc_badmarker_offs & ~0x01; | | | |
876 | | | 875 | |
877 | /* check if it is already marked bad */ | | 876 | /* check if it is already marked bad */ |
878 | if (nand_isbad(self, blockoffset)) | | 877 | if (nand_isbad(self, blockoffset)) |
879 | return; | | 878 | return; |
880 | | | 879 | |
881 | nand_read_oob(self, blockoffset, chip->nc_oob_cache); | | 880 | nand_read_oob(self, blockoffset, chip->nc_oob_cache); |
882 | | | 881 | |
883 | chip->nc_oob_cache[chip->nc_badmarker_offs] = 0x00; | | 882 | chip->nc_oob_cache[chip->nc_badmarker_offs] = 0x00; |
884 | chip->nc_oob_cache[chip->nc_badmarker_offs + 1] = 0x00; | | 883 | chip->nc_oob_cache[chip->nc_badmarker_offs + 1] = 0x00; |
885 | | | 884 | |
886 | nand_write_oob(self, blockoffset, chip->nc_oob_cache); | | 885 | nand_write_oob(self, blockoffset, chip->nc_oob_cache); |
887 | } | | 886 | } |
888 | | | 887 | |