CVS commit: src/sys/dev/nand

2020-07-06 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jul  6 10:22:07 UTC 2020

Modified Files:
src/sys/dev/nand: nand.h

Log Message:
Include opt_nand.h for NAND_DEBUG.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.19 src/sys/dev/nand/nand.h:1.20
--- src/sys/dev/nand/nand.h:1.19	Thu Apr 19 21:50:09 2018
+++ src/sys/dev/nand/nand.h	Mon Jul  6 10:22:07 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.19 2018/04/19 21:50:09 christos Exp $	*/
+/*	$NetBSD: nand.h,v 1.20 2020/07/06 10:22:07 rin Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -37,6 +37,10 @@
 #include 
 #include 
 
+#ifdef _KERNEL_OPT
+#include "opt_nand.h"
+#endif
+
 #include 
 #include 
 #include 



CVS commit: src/sys/dev/nand

2019-02-05 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Tue Feb  5 08:02:19 UTC 2019

Modified Files:
src/sys/dev/nand: nandemulator.c

Log Message:
add fallthru comments, and a comment this code needs attention


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nandemulator.c
diff -u src/sys/dev/nand/nandemulator.c:1.7 src/sys/dev/nand/nandemulator.c:1.8
--- src/sys/dev/nand/nandemulator.c:1.7	Thu Aug 20 14:40:18 2015
+++ src/sys/dev/nand/nandemulator.c	Tue Feb  5 08:02:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: nandemulator.c,v 1.7 2015/08/20 14:40:18 christos Exp $	*/
+/*	$NetBSD: nandemulator.c,v 1.8 2019/02/05 08:02:19 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -32,7 +32,9 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.7 2015/08/20 14:40:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.8 2019/02/05 08:02:19 mrg Exp $");
+
+/* XXX this code likely needs work */
 
 #include 
 #include 
@@ -388,9 +390,11 @@ nandemulator_command(device_t self, uint
 		break;
 	case ONFI_PAGE_PROGRAM:
 		sc->sc_register_writable = true;
+		/* FALLTHROUGH */
 	case ONFI_READ:
 	case ONFI_BLOCK_ERASE:
 		sc->sc_address_counter = 0;
+		/* FALLTHROUGH */
 	case ONFI_READ_ID:
 	case ONFI_READ_PARAMETER_PAGE:
 		sc->sc_io_len = 0;



CVS commit: src/sys/dev/nand

2018-02-07 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Thu Feb  8 07:48:19 UTC 2018

Modified Files:
src/sys/dev/nand: nand_bbt.c

Log Message:
update for GCC 6:
- nand_bbt_block_mark() has a left-shift of negative value issue.
  this change avoids it, but reviewers indicate this function has
  other problems.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nand/nand_bbt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.7 src/sys/dev/nand/nand_bbt.c:1.8
--- src/sys/dev/nand/nand_bbt.c:1.7	Tue Oct 22 01:01:27 2013
+++ src/sys/dev/nand/nand_bbt.c	Thu Feb  8 07:48:19 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.7 2013/10/22 01:01:27 htodd Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.8 2018/02/08 07:48:19 mrg Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand_bbt.c,v 1.7 2013/10/22 01:01:27 htodd Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand_bbt.c,v 1.8 2018/02/08 07:48:19 mrg Exp $");
 
 #include 
 #include 
@@ -208,7 +208,7 @@ nand_bbt_block_mark(device_t self, flash
 	__USE(chip);
 	KASSERT(block < chip->nc_size / chip->nc_block_size);
 
-	clean = (~0x03 << ((block % 4) * 2));
+	clean = (0xfc << ((block % 4) * 2));
 	marker = (marker << ((block % 4) * 2));
 
 	/* set byte containing the 2 bit marker for this block */



CVS commit: src/sys/dev/nand

2017-11-13 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Nov 13 17:36:39 UTC 2017

Modified Files:
src/sys/dev/nand: nand.c nand.h

Log Message:
Add support for dynamic flash partitions


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.26 src/sys/dev/nand/nand.c:1.27
--- src/sys/dev/nand/nand.c:1.26	Thu Nov  9 21:50:15 2017
+++ src/sys/dev/nand/nand.c	Mon Nov 13 17:36:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.26 2017/11/09 21:50:15 jmcneill Exp $	*/
+/*	$NetBSD: nand.c,v 1.27 2017/11/13 17:36:39 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.26 2017/11/09 21:50:15 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.27 2017/11/13 17:36:39 jmcneill Exp $");
 
 #include "locators.h"
 
@@ -188,8 +188,12 @@ nand_search(device_t parent, cfdata_t cf
 	struct nand_chip *chip = >sc_chip;
 	struct flash_attach_args faa;
 
+	if (cf->cf_loc[FLASHBUSCF_DYNAMIC] != 0)
+		return 0;
+
 	faa.flash_if = _flash_if;
 
+	faa.partinfo.part_name = NULL;
 	faa.partinfo.part_offset = cf->cf_loc[FLASHBUSCF_OFFSET];
 
 	if (cf->cf_loc[FLASHBUSCF_SIZE] == 0) {
@@ -215,6 +219,16 @@ nand_search(device_t parent, cfdata_t cf
 	return 1;
 }
 
+void
+nand_attach_mtdparts(device_t parent, const char *mtd_id, const char *cmdline)
+{
+	struct nand_softc *sc = device_private(parent);
+	struct nand_chip *chip = >sc_chip;
+
+	flash_attach_mtdparts(_flash_if, parent, chip->nc_size,
+	mtd_id, cmdline);
+}
+
 int
 nand_detach(device_t self, int flags)
 {

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.17 src/sys/dev/nand/nand.h:1.18
--- src/sys/dev/nand/nand.h:1.17	Thu Nov  9 21:50:15 2017
+++ src/sys/dev/nand/nand.h	Mon Nov 13 17:36:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.17 2017/11/09 21:50:15 jmcneill Exp $	*/
+/*	$NetBSD: nand.h,v 1.18 2017/11/13 17:36:39 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -468,6 +468,7 @@ int nand_read_oob(device_t, size_t, uint
 
 device_t nand_attach_mi(struct nand_interface *, device_t);
 void nand_init_interface(struct nand_interface *);
+void nand_attach_mtdparts(device_t, const char *, const char *);
 
 /* controller drivers may use these functions to get info about the chip */
 void nand_read_id(device_t, uint8_t *, uint8_t *);



CVS commit: src/sys/dev/nand

2017-11-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Nov  9 21:50:15 UTC 2017

Modified Files:
src/sys/dev/nand: files.nand nand.c nand.h
Added Files:
src/sys/dev/nand: nand_toshiba.c

Log Message:
Add support for decoding legacy Toshiba TC58NVG2S0H NAND chip params.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/files.nand
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/nand/nand.h
cvs rdiff -u -r0 -r1.1 src/sys/dev/nand/nand_toshiba.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/files.nand
diff -u src/sys/dev/nand/files.nand:1.5 src/sys/dev/nand/files.nand:1.6
--- src/sys/dev/nand/files.nand:1.5	Wed Oct 31 18:58:08 2012
+++ src/sys/dev/nand/files.nand	Thu Nov  9 21:50:15 2017
@@ -1,4 +1,4 @@
-# $NetBSD: files.nand,v 1.5 2012/10/31 18:58:08 riz Exp $
+# $NetBSD: files.nand,v 1.6 2017/11/09 21:50:15 jmcneill Exp $
 
 define	nandbus	{ }
 
@@ -10,6 +10,7 @@ file	dev/nand/nand_bbt.c	nand
 file	dev/nand/nand_crc.c	nand
 file	dev/nand/nand_micron.c	nand
 file	dev/nand/nand_samsung.c	nand
+file	dev/nand/nand_toshiba.c	nand
 
 defpseudodev	nandemulator: nandbus
 file	dev/nand/nandemulator.c	nandemulator

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.25 src/sys/dev/nand/nand.c:1.26
--- src/sys/dev/nand/nand.c:1.25	Tue Oct  4 14:47:18 2016
+++ src/sys/dev/nand/nand.c	Thu Nov  9 21:50:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.25 2016/10/04 14:47:18 kiyohara Exp $	*/
+/*	$NetBSD: nand.c,v 1.26 2017/11/09 21:50:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.25 2016/10/04 14:47:18 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.26 2017/11/09 21:50:15 jmcneill Exp $");
 
 #include "locators.h"
 
@@ -88,7 +88,6 @@ struct flash_interface nand_flash_if = {
 	.submit = nand_flash_submit
 };
 
-#ifdef NAND_VERBOSE
 const struct nand_manufacturer nand_mfrs[] = {
 	{ NAND_MFR_AMD,		"AMD" },
 	{ NAND_MFR_FUJITSU,	"Fujitsu" },
@@ -116,7 +115,6 @@ nand_midtoname(int id)
 
 	return nand_mfrs[i].name;
 }
-#endif
 
 /* ARGSUSED */
 int
@@ -335,6 +333,8 @@ nand_fill_chip_structure_legacy(device_t
 		return nand_read_parameters_micron(self, chip);
 	case NAND_MFR_SAMSUNG:
 		return nand_read_parameters_samsung(self, chip);
+	case NAND_MFR_TOSHIBA:
+		return nand_read_parameters_toshiba(self, chip);
 	default:
 		return 1;
 	}
@@ -368,6 +368,12 @@ nand_scan_media(device_t self, struct na
 	nand_read_1(self, _signature[3]);
 	nand_select(self, false);
 
+#ifdef NAND_DEBUG
+	device_printf(self, "signature: %02x %02x %02x %02x\n",
+	onfi_signature[0], onfi_signature[1],
+	onfi_signature[2], onfi_signature[3]);
+#endif
+
 	if (onfi_signature[0] != 'O' || onfi_signature[1] != 'N' ||
 	onfi_signature[2] != 'F' || onfi_signature[3] != 'I') {
 		chip->nc_isonfi = false;
@@ -395,13 +401,11 @@ nand_scan_media(device_t self, struct na
 		}
 	}
 
-#ifdef NAND_VERBOSE
 	aprint_normal_dev(self,
 	"manufacturer id: 0x%.2x (%s), device id: 0x%.2x\n",
 	chip->nc_manf_id,
 	nand_midtoname(chip->nc_manf_id),
 	chip->nc_dev_id);
-#endif
 
 	aprint_normal_dev(self,
 	"page size: %" PRIu32 " bytes, spare size: %" PRIu32 " bytes, "

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.16 src/sys/dev/nand/nand.h:1.17
--- src/sys/dev/nand/nand.h:1.16	Sat Nov  3 12:12:48 2012
+++ src/sys/dev/nand/nand.h	Thu Nov  9 21:50:15 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.16 2012/11/03 12:12:48 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.17 2017/11/09 21:50:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -428,6 +428,7 @@ extern const struct nand_manufacturer na
  */
 int nand_read_parameters_micron(device_t, struct nand_chip *);
 int nand_read_parameters_samsung(device_t, struct nand_chip *);
+int nand_read_parameters_toshiba(device_t, struct nand_chip *);
 
 /* debug inlines */
 

Added files:

Index: src/sys/dev/nand/nand_toshiba.c
diff -u /dev/null src/sys/dev/nand/nand_toshiba.c:1.1
--- /dev/null	Thu Nov  9 21:50:15 2017
+++ src/sys/dev/nand/nand_toshiba.c	Thu Nov  9 21:50:15 2017
@@ -0,0 +1,155 @@
+/*	$NetBSD: nand_toshiba.c,v 1.1 2017/11/09 21:50:15 jmcneill Exp $	*/
+
+/*-
+ * Copyright (c) 2012-2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Adam Hoka.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. 

CVS commit: src/sys/dev/nand

2017-11-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Nov  9 21:45:24 UTC 2017

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
ul is not 64-bit on all platforms, use ull when calculating planesize


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.9 src/sys/dev/nand/nand_samsung.c:1.10
--- src/sys/dev/nand/nand_samsung.c:1.9	Sat Nov  3 12:12:48 2012
+++ src/sys/dev/nand/nand_samsung.c	Thu Nov  9 21:45:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.9 2012/11/03 12:12:48 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.10 2017/11/09 21:45:24 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand_samsung.c,v 1.9 2012/11/03 12:12:48 ahoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand_samsung.c,v 1.10 2017/11/09 21:45:24 jmcneill Exp $");
 
 #include "nand.h"
 #include "onfi.h"
@@ -181,13 +181,13 @@ nand_read_parameters_samsung(device_t se
 			planesize = 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x5:
-			planesize = 2ul * 1024 * 1024 * 1024 / 8;
+			planesize = 2ull * 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x6:
-			planesize = 4ul * 1024 * 1024 * 1024 / 8;
+			planesize = 4ull * 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x7:
-			planesize = 8ul * 1024 * 1024 * 1024 / 8;
+			planesize = 8ull * 1024 * 1024 * 1024 / 8;
 			break;
 		default:
 			KASSERTMSG(false, "ID Data parsing bug detected!");



CVS commit: src/sys/dev/nand

2016-10-04 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Tue Oct  4 14:47:18 UTC 2016

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Use ONFI_STATUS_WP instead of 0x80.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.24 src/sys/dev/nand/nand.c:1.25
--- src/sys/dev/nand/nand.c:1.24	Tue Oct  4 14:43:55 2016
+++ src/sys/dev/nand/nand.c	Tue Oct  4 14:47:18 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.24 2016/10/04 14:43:55 kiyohara Exp $	*/
+/*	$NetBSD: nand.c,v 1.25 2016/10/04 14:47:18 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.24 2016/10/04 14:43:55 kiyohara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.25 2016/10/04 14:47:18 kiyohara Exp $");
 
 #include "locators.h"
 
@@ -640,7 +640,7 @@ nand_get_status(device_t self)
 static bool
 nand_check_wp(device_t self)
 {
-	if (nand_get_status(self) & 0x80)
+	if (nand_get_status(self) & ONFI_STATUS_WP)
 		return false;
 	else
 		return true;



CVS commit: src/sys/dev/nand

2016-10-04 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Tue Oct  4 14:43:55 UTC 2016

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Wait STATUS_RDY after ONFI_RESET.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.23 src/sys/dev/nand/nand.c:1.24
--- src/sys/dev/nand/nand.c:1.23	Sun Oct 20 17:13:18 2013
+++ src/sys/dev/nand/nand.c	Tue Oct  4 14:43:55 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $	*/
+/*	$NetBSD: nand.c,v 1.24 2016/10/04 14:43:55 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nand.c,v 1.24 2016/10/04 14:43:55 kiyohara Exp $");
 
 #include "locators.h"
 
@@ -63,6 +63,7 @@ int nand_print(void *, const char *);
 
 static int nand_search(device_t, cfdata_t, const int *, void *);
 static void nand_address_row(device_t, size_t);
+static inline uint8_t nand_get_status(device_t);
 static void nand_address_column(device_t, size_t, size_t);
 static int nand_fill_chip_structure(device_t, struct nand_chip *);
 static int nand_scan_media(device_t, struct nand_chip *);
@@ -354,6 +355,7 @@ nand_scan_media(device_t self, struct na
 
 	nand_select(self, true);
 	nand_command(self, ONFI_RESET);
+	KASSERT(nand_get_status(self) & ONFI_STATUS_RDY);
 	nand_select(self, false);
 
 	/* check if the device implements the ONFI standard */



CVS commit: src/sys/dev/nand

2013-10-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Oct 21 15:13:09 UTC 2013

Modified Files:
src/sys/dev/nand: nand_bbt.c

Log Message:
remove DIAGNOSTIC ifdef in preparation of a KASSERT that consumes its
arguments


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nand_bbt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.4 src/sys/dev/nand/nand_bbt.c:1.5
--- src/sys/dev/nand/nand_bbt.c:1.4	Sun May  1 09:20:28 2011
+++ src/sys/dev/nand/nand_bbt.c	Mon Oct 21 11:13:09 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.4 2011/05/01 13:20:28 rmind Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.5 2013/10/21 15:13:09 christos Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.4 2011/05/01 13:20:28 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.5 2013/10/21 15:13:09 christos Exp $);
 
 #include sys/param.h
 #include sys/kmem.h
@@ -201,9 +201,7 @@ void
 nand_bbt_block_mark(device_t self, flash_off_t block, uint8_t marker)
 {
 	struct nand_softc *sc = device_private(self);
-#ifdef DIAGNOSTIC
 	struct nand_chip *chip = sc-sc_chip;
-#endif
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t clean;
 
@@ -221,9 +219,7 @@ bool
 nand_bbt_block_isbad(device_t self, flash_off_t block)
 {
 	struct nand_softc *sc = device_private(self);
-#ifdef DIAGNOSTIC
 	struct nand_chip *chip = sc-sc_chip;
-#endif
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t byte, marker;
 	bool result;



CVS commit: src/sys/dev/nand

2013-10-21 Thread Marc Balmer
Module Name:src
Committed By:   mbalmer
Date:   Mon Oct 21 17:47:28 UTC 2013

Modified Files:
src/sys/dev/nand: nand_bbt.c

Log Message:
chip unused variable; let the system build again


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/nand_bbt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.5 src/sys/dev/nand/nand_bbt.c:1.6
--- src/sys/dev/nand/nand_bbt.c:1.5	Mon Oct 21 15:13:09 2013
+++ src/sys/dev/nand/nand_bbt.c	Mon Oct 21 17:47:28 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.5 2013/10/21 15:13:09 christos Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.6 2013/10/21 17:47:28 mbalmer Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.5 2013/10/21 15:13:09 christos Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.6 2013/10/21 17:47:28 mbalmer Exp $);
 
 #include sys/param.h
 #include sys/kmem.h
@@ -201,7 +201,6 @@ void
 nand_bbt_block_mark(device_t self, flash_off_t block, uint8_t marker)
 {
 	struct nand_softc *sc = device_private(self);
-	struct nand_chip *chip = sc-sc_chip;
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t clean;
 
@@ -219,7 +218,6 @@ bool
 nand_bbt_block_isbad(device_t self, flash_off_t block)
 {
 	struct nand_softc *sc = device_private(self);
-	struct nand_chip *chip = sc-sc_chip;
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t byte, marker;
 	bool result;



CVS commit: src/sys/dev/nand

2013-10-21 Thread Hisashi T Fujinaka
Module Name:src
Committed By:   htodd
Date:   Tue Oct 22 01:01:27 UTC 2013

Modified Files:
src/sys/dev/nand: nand_bbt.c

Log Message:
Fix build for missing chip.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/nand/nand_bbt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.6 src/sys/dev/nand/nand_bbt.c:1.7
--- src/sys/dev/nand/nand_bbt.c:1.6	Mon Oct 21 17:47:28 2013
+++ src/sys/dev/nand/nand_bbt.c	Tue Oct 22 01:01:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.6 2013/10/21 17:47:28 mbalmer Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.7 2013/10/22 01:01:27 htodd Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.6 2013/10/21 17:47:28 mbalmer Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.7 2013/10/22 01:01:27 htodd Exp $);
 
 #include sys/param.h
 #include sys/kmem.h
@@ -201,9 +201,11 @@ void
 nand_bbt_block_mark(device_t self, flash_off_t block, uint8_t marker)
 {
 	struct nand_softc *sc = device_private(self);
+	struct nand_chip *chip = sc-sc_chip;
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t clean;
 
+	__USE(chip);
 	KASSERT(block  chip-nc_size / chip-nc_block_size);
 
 	clean = (~0x03  ((block % 4) * 2));
@@ -218,10 +220,12 @@ bool
 nand_bbt_block_isbad(device_t self, flash_off_t block)
 {
 	struct nand_softc *sc = device_private(self);
+	struct nand_chip *chip = sc-sc_chip;
 	struct nand_bbt *bbt = sc-sc_bbt;
 	uint8_t byte, marker;
 	bool result;
 
+	__USE(chip);
 	KASSERT(block  chip-nc_size / chip-nc_block_size);
 
 	/* get byte containing the 2 bit marker for this block */



CVS commit: src/sys/dev/nand

2013-10-20 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 20 17:13:18 UTC 2013

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
remove unused


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.22 src/sys/dev/nand/nand.c:1.23
--- src/sys/dev/nand/nand.c:1.22	Sat Nov  3 08:45:28 2012
+++ src/sys/dev/nand/nand.c	Sun Oct 20 13:13:18 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.23 2013/10/20 17:13:18 christos Exp $);
 
 #include locators.h
 
@@ -863,7 +863,7 @@ nand_markbad(device_t self, size_t offse
 {
 	struct nand_softc *sc = device_private(self);
 	struct nand_chip *chip = sc-sc_chip;
-	flash_off_t blockoffset, marker;
+	flash_off_t blockoffset;
 #ifdef NAND_BBT
 	flash_off_t block;
 
@@ -872,7 +872,6 @@ nand_markbad(device_t self, size_t offse
 	nand_bbt_block_markbad(self, block);
 #endif
 	blockoffset = offset  chip-nc_block_mask;
-	marker = chip-nc_badmarker_offs  ~0x01;
 
 	/* check if it is already marked bad */
 	if (nand_isbad(self, blockoffset))



CVS commit: src/sys/dev/nand

2012-11-03 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Sat Nov  3 12:12:48 UTC 2012

Modified Files:
src/sys/dev/nand: nand.c nand.h nand_micron.c nand_samsung.c

Log Message:
Make nc_block_pages go aways, its redundant and unused.
Print more info on attach including the width.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nand/nand_micron.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.20 src/sys/dev/nand/nand.c:1.21
--- src/sys/dev/nand/nand.c:1.20	Fri Nov  2 19:50:22 2012
+++ src/sys/dev/nand/nand.c	Sat Nov  3 12:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.20 2012/11/02 19:50:22 pgoyette Exp $	*/
+/*	$NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.20 2012/11/02 19:50:22 pgoyette Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $);
 
 #include locators.h
 
@@ -412,11 +412,10 @@ nand_scan_media(device_t self, struct na
 	chip-nc_lun_blocks, chip-nc_num_luns,
 	chip-nc_size / 1024 / 1024);
 
-#ifdef NAND_VERBOSE
 	aprint_normal_dev(self, column cycles: % PRIu8 , row cycles: %
-	PRIu8 \n,
-	chip-nc_addr_cycles_column, chip-nc_addr_cycles_row);
-#endif
+	PRIu8 , width: %s\n,
+	chip-nc_addr_cycles_column, chip-nc_addr_cycles_row,
+	(chip-nc_flags  NC_BUSWIDTH_16) ? x16 : x8);
 
 	ecc = chip-nc_ecc = sc-nand_if-ecc;
 
@@ -563,7 +562,6 @@ nand_fill_chip_structure(device_t self, 
 	params.param_lunsize * params.param_numluns;
 
 	chip-nc_page_size = params.param_pagesize;
-	chip-nc_block_pages = params.param_blocksize;
 	chip-nc_block_size = params.param_blocksize * params.param_pagesize;
 	chip-nc_spare_size = params.param_sparesize;
 	chip-nc_lun_blocks = params.param_lunsize;

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.15 src/sys/dev/nand/nand.h:1.16
--- src/sys/dev/nand/nand.h:1.15	Fri Nov  2 17:14:41 2012
+++ src/sys/dev/nand/nand.h	Sat Nov  3 12:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.15 2012/11/02 17:14:41 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.16 2012/11/03 12:12:48 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -113,9 +113,7 @@ struct nand_chip {
 	uint8_t *nc_ecc_cache;		/* buffer for ecc */
 	uint64_t nc_size;		/* storage size in bytes */
 	uint32_t nc_page_size;		/* page size in bytes */
-	uint32_t nc_block_pages;	/* block size in pages */
 	uint32_t nc_block_size;		/* block size in bytes */
-	uint32_t nc_spare_size;		/* spare (oob) size in bytes */
 	uint32_t nc_lun_blocks;		/* LUN size in blocks */
 	uint32_t nc_flags;		/* bitfield flags */
 	uint32_t nc_quirks;		/* bitfield quirks */
@@ -123,6 +121,7 @@ struct nand_chip {
 	uint32_t nc_page_mask;		/* page mask for page alignment */
 	uint32_t nc_block_shift;	/* write shift */
 	uint32_t nc_block_mask;		/* write mask */
+	uint16_t nc_spare_size;		/* spare (oob) size in bytes */
 	uint8_t nc_num_luns;		/* number of LUNs */
 	uint8_t nc_manf_id;		/* manufacturer id */
 	uint8_t nc_dev_id;		/* device id  */

Index: src/sys/dev/nand/nand_micron.c
diff -u src/sys/dev/nand/nand_micron.c:1.7 src/sys/dev/nand/nand_micron.c:1.8
--- src/sys/dev/nand/nand_micron.c:1.7	Fri Nov  2 17:14:41 2012
+++ src/sys/dev/nand/nand_micron.c	Sat Nov  3 12:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_micron.c,v 1.7 2012/11/02 17:14:41 ahoka Exp $	*/
+/*	$NetBSD: nand_micron.c,v 1.8 2012/11/03 12:12:48 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -39,7 +39,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_micron.c,v 1.7 2012/11/02 17:14:41 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_micron.c,v 1.8 2012/11/03 12:12:48 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
@@ -151,7 +151,6 @@ mt29fxgx_parameters(device_t self, struc
 	if (dp-width == 16)
 		chip-nc_flags |= NC_BUSWIDTH_16;
 	chip-nc_page_size = MT29FxG_PAGESIZE;
-	chip-nc_block_pages = MT29FxG_BLOCK_PAGES;
 	chip-nc_block_size = MT29FxG_BLOCK_PAGES * MT29FxG_PAGESIZE;
 	chip-nc_spare_size = MT29FxG_SPARESIZE;
 	chip-nc_lun_blocks = dp-lun_blocks;

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.8 src/sys/dev/nand/nand_samsung.c:1.9
--- src/sys/dev/nand/nand_samsung.c:1.8	Fri Nov  2 21:38:29 2012
+++ src/sys/dev/nand/nand_samsung.c	Sat Nov  3 12:12:48 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.8 2012/11/02 21:38:29 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.9 2012/11/03 12:12:48 ahoka Exp $	*/
 
 /*-
  * 

CVS commit: src/sys/dev/nand

2012-11-03 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Sat Nov  3 12:45:28 UTC 2012

Modified Files:
src/sys/dev/nand: nand.c nandemulator.c

Log Message:
Endiannes fixes from Brett Slager in ONFI Param page parsing.
Similar changes in nandemulator by me.
Remove panic about more than one LUNs.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.21 src/sys/dev/nand/nand.c:1.22
--- src/sys/dev/nand/nand.c:1.21	Sat Nov  3 12:12:48 2012
+++ src/sys/dev/nand/nand.c	Sat Nov  3 12:45:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.21 2012/11/03 12:12:48 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.22 2012/11/03 12:45:28 ahoka Exp $);
 
 #include locators.h
 
@@ -550,33 +550,29 @@ nand_fill_chip_structure(device_t self, 
 
 	aprint_normal_dev(self, vendor: %s, model: %s\n, vendor, model);
 
-	/* XXX TODO multiple LUNs */
-	if (params.param_numluns != 1) {
-		aprint_error_dev(self,
-		more than one LUNs are not supported yet!\n);
-
-		return 1;
-	}
-
-	chip-nc_size = params.param_pagesize * params.param_blocksize *
-	params.param_lunsize * params.param_numluns;
-
-	chip-nc_page_size = params.param_pagesize;
-	chip-nc_block_size = params.param_blocksize * params.param_pagesize;
-	chip-nc_spare_size = params.param_sparesize;
-	chip-nc_lun_blocks = params.param_lunsize;
+	chip-nc_page_size = le32toh(params.param_pagesize);
+	chip-nc_block_size =
+	le32toh(params.param_blocksize) * chip-nc_page_size;
+	chip-nc_spare_size = le16toh(params.param_sparesize);
+	chip-nc_lun_blocks = le32toh(params.param_lunsize);
 	chip-nc_num_luns = params.param_numluns;
 
+	chip-nc_size =
+	chip-nc_block_size * chip-nc_lun_blocks * chip-nc_num_luns;
+
 	/* the lower 4 bits contain the row address cycles */
 	chip-nc_addr_cycles_row = params.param_addr_cycles  0x07;
 	/* the upper 4 bits contain the column address cycles */
 	chip-nc_addr_cycles_column = (params.param_addr_cycles  ~0x07)  4;
 
-	if (params.param_features  ONFI_FEATURE_16BIT)
+	uint16_t features = le16toh(params.param_features);
+	if (features  ONFI_FEATURE_16BIT) {
 		chip-nc_flags |= NC_BUSWIDTH_16;
+	}
 
-	if (params.param_features  ONFI_FEATURE_EXTENDED_PARAM)
+	if (features  ONFI_FEATURE_EXTENDED_PARAM) {
 		chip-nc_flags |= NC_EXTENDED_PARAM;
+	}
 
 	return 0;
 }

Index: src/sys/dev/nand/nandemulator.c
diff -u src/sys/dev/nand/nandemulator.c:1.5 src/sys/dev/nand/nandemulator.c:1.6
--- src/sys/dev/nand/nandemulator.c:1.5	Tue Jun 28 10:32:45 2011
+++ src/sys/dev/nand/nandemulator.c	Sat Nov  3 12:45:28 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $	*/
+/*	$NetBSD: nandemulator.c,v 1.6 2012/11/03 12:45:28 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.6 2012/11/03 12:45:28 ahoka Exp $);
 
 #include sys/param.h
 #include sys/device.h
@@ -235,11 +235,11 @@ nandemulator_attach(device_t parent, dev
 	for (i = 0; i  4; i++) {
 		opp = sc-sc_parameter_page[i];
 
-		opp-param_signature = *(uint32_t *)sig;
-		opp-param_pagesize = sc-sc_page_size;
-		opp-param_blocksize = sc-sc_block_size;
-		opp-param_sparesize = sc-sc_spare_size;
-		opp-param_lunsize = sc-sc_lun_size;
+		opp-param_signature = htole32(*(uint32_t *)sig);
+		opp-param_pagesize = htole32(sc-sc_page_size);
+		opp-param_blocksize = htole32(sc-sc_block_size);
+		opp-param_sparesize = htole16(sc-sc_spare_size);
+		opp-param_lunsize = htole32(sc-sc_lun_size);
 		opp-param_numluns = 1;
 
 		opp-param_manufacturer_id = 0x00;
@@ -248,7 +248,8 @@ nandemulator_attach(device_t parent, dev
 		memcpy(opp-param_model,
 		NANDEMULATOR, strlen(NANDEMULATOR));
 
-		opp-param_features = ONFI_FEATURE_16BIT;
+		uint16_t features = ONFI_FEATURE_16BIT;
+		opp-param_features = htole16(features);
 
 		/* the lower 4 bits contain the row address cycles
 		 * the upper 4 bits contain the column address cycles



CVS commit: src/sys/dev/nand

2012-11-02 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov  2 17:14:41 UTC 2012

Modified Files:
src/sys/dev/nand: nand.c nand.h nand_micron.c

Log Message:
No longer use size_t in the chip structure.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/nand/nand_micron.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.18 src/sys/dev/nand/nand.c:1.19
--- src/sys/dev/nand/nand.c:1.18	Wed Oct 31 18:58:08 2012
+++ src/sys/dev/nand/nand.c	Fri Nov  2 17:14:41 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.18 2012/10/31 18:58:08 riz Exp $	*/
+/*	$NetBSD: nand.c,v 1.19 2012/11/02 17:14:41 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.18 2012/10/31 18:58:08 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.19 2012/11/02 17:14:41 ahoka Exp $);
 
 #include locators.h
 
@@ -402,13 +402,13 @@ nand_scan_media(device_t self, struct na
 #endif
 
 	aprint_normal_dev(self,
-	page size: %zu bytes, spare size: %zu bytes, 
-	block size: %zu bytes\n,
+	page size: % PRIu32  bytes, spare size: % PRIu32  bytes, 
+	block size: % PRIu32  bytes\n,
 	chip-nc_page_size, chip-nc_spare_size, chip-nc_block_size);
 
 	aprint_normal_dev(self,
 	LUN size: % PRIu32  blocks, LUNs: % PRIu8
-	, total storage size: %zu MB\n,
+	, total storage size: % PRIu64  MB\n,
 	chip-nc_lun_blocks, chip-nc_num_luns,
 	chip-nc_size / 1024 / 1024);
 
@@ -441,7 +441,7 @@ nand_scan_media(device_t self, struct na
 		ecc-necc_offset = 80;
 		break;
 	default:
-		panic(OOB size %zu is unexpected, chip-nc_spare_size);
+		panic(OOB size % PRIu32  is unexpected, chip-nc_spare_size);
 	}
 
 	ecc-necc_steps = chip-nc_page_size / ecc-necc_block_size;
@@ -597,7 +597,7 @@ nand_address_column(device_t self, size_
 	struct nand_chip *chip = sc-sc_chip;
 	uint8_t i;
 
-	DPRINTF((addressing row: 0x%jx column: %zu\n,
+	DPRINTF((addressing row: 0x%jx column: % PRIu32 \n,
 		(uintmax_t )row, column));
 
 	/* XXX TODO */
@@ -727,18 +727,18 @@ nand_default_read_page(device_t self, si
 		case NAND_ECC_CORRECTED:
 			aprint_error_dev(self,
 			data corrected with ECC at page offset 0x%jx 
-			block %zu\n, (uintmax_t)offset, b);
+			block % PRIu32 \n, (uintmax_t)offset, b);
 			break;
 		case NAND_ECC_TWOBIT:
 			aprint_error_dev(self,
 			uncorrectable ECC error at page offset 0x%jx 
-			block %zu\n, (uintmax_t)offset, b);
+			block % PRIu32 \n, (uintmax_t)offset, b);
 			return EIO;
 			break;
 		case NAND_ECC_INVALID:
 			aprint_error_dev(self,
 			invalid ECC in oob at page offset 0x%jx 
-			block %zu\n, (uintmax_t)offset, b);
+			block % PRIu32 \n, (uintmax_t)offset, b);
 			return EIO;
 			break;
 		default:
@@ -1153,8 +1153,8 @@ nand_flash_write_unaligned(device_t self
 		} else {
 			/* XXX debug */
 			if (left  chip-nc_page_size) {
-printf(left: %zu, i: %d, count: %zu\n,
-(size_t )left, i, count);
+printf(left: % PRIu32 , i: %d, count: % PRIu32 \n,
+left, i, count);
 			}
 			KASSERT(left  chip-nc_page_size);
 
@@ -1232,7 +1232,7 @@ nand_flash_write(device_t self, flash_of
 	}
 out:
 	mutex_exit(sc-sc_device_lock);
-	DPRINTF((page programming: retlen: %zu, len: %zu\n, *retlen, len));
+	DPRINTF((page programming: retlen: % PRIu32 , len: % PRIu32 \n, *retlen, len));
 
 	return error;
 }
@@ -1324,11 +1324,11 @@ nand_flash_read(device_t self, flash_off
 
 	*retlen = 0;
 
-	DPRINTF((nand_flash_read: off: 0x%jx, len: %zu\n,
+	DPRINTF((nand_flash_read: off: 0x%jx, len: % PRIu32 \n,
 		(uintmax_t)offset, len));
 
 	if (__predict_false((offset + len)  chip-nc_size)) {
-		DPRINTF((nand_flash_read: read (off: 0x%jx, len: %zu),
+		DPRINTF((nand_flash_read: read (off: 0x%jx, len: % PRIu32 ),
 			 is over device size (%ju)\n, (uintmax_t)offset,
 			len, (uintmax_t)chip-nc_size));
 		return EINVAL;

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.14 src/sys/dev/nand/nand.h:1.15
--- src/sys/dev/nand/nand.h:1.14	Wed Oct 31 18:58:08 2012
+++ src/sys/dev/nand/nand.h	Fri Nov  2 17:14:41 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.14 2012/10/31 18:58:08 riz Exp $	*/
+/*	$NetBSD: nand.h,v 1.15 2012/11/02 17:14:41 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -110,19 +110,19 @@ struct nand_chip {
 	struct nand_ecc *nc_ecc; 	/* ecc information */
 	uint8_t	*nc_oob_cache;		/* buffer for oob cache */
 	uint8_t *nc_page_cache;		/* buffer for page cache */
-	uint8_t *nc_ecc_cache;
-	size_t nc_size;			/* storage size in bytes */
-	size_t nc_page_size;		/* page size in bytes */
-	

CVS commit: src/sys/dev/nand

2012-11-02 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov  2 20:55:01 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Fix a typo and add a debug print.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.4 src/sys/dev/nand/nand_samsung.c:1.5
--- src/sys/dev/nand/nand_samsung.c:1.4	Wed Oct 31 21:30:27 2012
+++ src/sys/dev/nand/nand_samsung.c	Fri Nov  2 20:55:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.4 2012/10/31 21:30:27 riz Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.5 2012/11/02 20:55:01 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,15 +37,15 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.4 2012/10/31 21:30:27 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.5 2012/11/02 20:55:01 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
 
 enum {
 	NAND_SAMSUNG_PAGEMASK = 0x3,
-	NAND_SAMSUNG_BLOCKMASK = 0x3  4,
 	NAND_SAMSUNG_SPAREMASK = 0x1  2,
+	NAND_SAMSUNG_BLOCKMASK = 0x3  4,
 	NAND_SAMSUNG_BITSMASK = 0x1  6
 };
 
@@ -54,6 +54,9 @@ enum {
 	NAND_SAMSUNG_PLANESIZEMASK = 0x7  4
 };
 
+CTASSERT(NAND_SAMSUNG_PAGEMASK | NAND_SAMSUNG_SPAREMASK
+| NAND_SAMSUNG_BLOCKMASK | NAND_SAMSUNG_BITSMASK == 0xff);
+
 int
 nand_read_parameters_samsung(device_t self, struct nand_chip * const chip)
 {
@@ -78,6 +81,10 @@ nand_read_parameters_samsung(device_t se
 	nand_read_1(self, params3);
 	nand_select(self, false);
 
+	aprint_debug_dev(self,
+	ID Definition table: 0x%2.x 0x%2.x 0x%2.x 0x%2.x 0x%2.x\n,
+	mfgrid, devid, params1, params2, params3);
+
 	/* K9XXG08UXA */
 	if (devid == 0xdc) {
 		/* From the documentation */
@@ -99,7 +106,7 @@ nand_read_parameters_samsung(device_t se
 			break;
 		}
 
-		switch ((params2  NAND_SAMSUNG_PAGEMASK)  4) {
+		switch ((params2  NAND_SAMSUNG_BLOCKMASK)  4) {
 		case 0x0:
 			chip-nc_block_size = 64 * 1024;
 			break;
@@ -132,7 +139,7 @@ nand_read_parameters_samsung(device_t se
 			chip-nc_flags |= NC_BUSWIDTH_16;
 			break;
 		}
-		
+
 		switch ((params3  NAND_SAMSUNG_PLANENUMMASK)  2) {
 		case 0x0:
 			chip-nc_num_luns = 1;
@@ -183,6 +190,6 @@ nand_read_parameters_samsung(device_t se
 	} else {
 		return 1;
 	}
-   
+
 	return 0;
 }



CVS commit: src/sys/dev/nand

2012-11-02 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov  2 21:17:26 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Add assertions and remove bogus ctassert.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.5 src/sys/dev/nand/nand_samsung.c:1.6
--- src/sys/dev/nand/nand_samsung.c:1.5	Fri Nov  2 20:55:01 2012
+++ src/sys/dev/nand/nand_samsung.c	Fri Nov  2 21:17:26 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.5 2012/11/02 20:55:01 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.6 2012/11/02 21:17:26 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.5 2012/11/02 20:55:01 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.6 2012/11/02 21:17:26 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
@@ -54,9 +54,6 @@ enum {
 	NAND_SAMSUNG_PLANESIZEMASK = 0x7  4
 };
 
-CTASSERT(NAND_SAMSUNG_PAGEMASK | NAND_SAMSUNG_SPAREMASK
-| NAND_SAMSUNG_BLOCKMASK | NAND_SAMSUNG_BITSMASK == 0xff);
-
 int
 nand_read_parameters_samsung(device_t self, struct nand_chip * const chip)
 {
@@ -104,6 +101,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x3:
 			chip-nc_page_size = 8192;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		switch ((params2  NAND_SAMSUNG_BLOCKMASK)  4) {
@@ -119,6 +118,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x3:
 			chip-nc_block_size = 512 * 1024;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		/* 8/16 bytes per 512 bytes! XXX do i get this right? */
@@ -129,6 +130,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x1:
 			chip-nc_spare_size = 16 * chip-nc_page_size / 512;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		switch ((params2  NAND_SAMSUNG_BITSMASK)  6) {
@@ -138,6 +141,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x1:
 			chip-nc_flags |= NC_BUSWIDTH_16;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		switch ((params3  NAND_SAMSUNG_PLANENUMMASK)  2) {
@@ -153,6 +158,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x3:
 			chip-nc_num_luns = 8;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		uint64_t planesize = 0;
@@ -181,6 +188,8 @@ nand_read_parameters_samsung(device_t se
 		case 0x7:
 			planesize = 8ul * 1024 * 1024 * 1024;
 			break;
+		default:
+			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
 		chip-nc_lun_blocks = planesize / chip-nc_block_size;



CVS commit: src/sys/dev/nand

2012-11-02 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov  2 21:27:46 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Set nc_block_pages


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.6 src/sys/dev/nand/nand_samsung.c:1.7
--- src/sys/dev/nand/nand_samsung.c:1.6	Fri Nov  2 21:17:26 2012
+++ src/sys/dev/nand/nand_samsung.c	Fri Nov  2 21:27:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.6 2012/11/02 21:17:26 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.7 2012/11/02 21:27:46 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.6 2012/11/02 21:17:26 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.7 2012/11/02 21:27:46 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
@@ -122,6 +122,8 @@ nand_read_parameters_samsung(device_t se
 			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
+		chip-nc_block_pages = chip-nc_block_size / chip-nc_page_size;
+
 		/* 8/16 bytes per 512 bytes! XXX do i get this right? */
 		switch ((params2  NAND_SAMSUNG_SPAREMASK)  2) {
 		case 0x0:



CVS commit: src/sys/dev/nand

2012-11-02 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Nov  2 21:38:29 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Hah! Size is actually in megaBIT!


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.7 src/sys/dev/nand/nand_samsung.c:1.8
--- src/sys/dev/nand/nand_samsung.c:1.7	Fri Nov  2 21:27:46 2012
+++ src/sys/dev/nand/nand_samsung.c	Fri Nov  2 21:38:29 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.7 2012/11/02 21:27:46 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.8 2012/11/02 21:38:29 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.7 2012/11/02 21:27:46 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.8 2012/11/02 21:38:29 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
@@ -164,31 +164,32 @@ nand_read_parameters_samsung(device_t se
 			KASSERTMSG(false, ID Data parsing bug detected!);
 		}
 
+		/* This one reads in megabit for some reason */
 		uint64_t planesize = 0;
 		switch ((params3  NAND_SAMSUNG_PLANESIZEMASK)  4) {
 		case 0x0:
-			planesize = 64 * 1024 * 1024;
+			planesize = 64 * 1024 * 1024 / 8;
 			break;
 		case 0x1:
-			planesize = 128 * 1024 * 1024;
+			planesize = 128 * 1024 * 1024 / 8;
 			break;
 		case 0x2:
-			planesize = 256 * 1024 * 1024;
+			planesize = 256 * 1024 * 1024 / 8;
 			break;
 		case 0x3:
-			planesize = 512 * 1024 * 1024;
+			planesize = 512 * 1024 * 1024 / 8;
 			break;
 		case 0x4:
-			planesize = 1024 * 1024 * 1024;
+			planesize = 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x5:
-			planesize = 2ul * 1024 * 1024 * 1024;
+			planesize = 2ul * 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x6:
-			planesize = 4ul * 1024 * 1024 * 1024;
+			planesize = 4ul * 1024 * 1024 * 1024 / 8;
 			break;
 		case 0x7:
-			planesize = 8ul * 1024 * 1024 * 1024;
+			planesize = 8ul * 1024 * 1024 * 1024 / 8;
 			break;
 		default:
 			KASSERTMSG(false, ID Data parsing bug detected!);



CVS commit: src/sys/dev/nand

2012-10-31 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Oct 31 18:58:09 UTC 2012

Modified Files:
src/sys/dev/nand: files.nand nand.c nand.h

Log Message:
Hook nand_samsung.c into the build, and use it if a legacy chip
from Samsung is found.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/files.nand
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/files.nand
diff -u src/sys/dev/nand/files.nand:1.4 src/sys/dev/nand/files.nand:1.5
--- src/sys/dev/nand/files.nand:1.4	Tue Jun 28 18:14:11 2011
+++ src/sys/dev/nand/files.nand	Wed Oct 31 18:58:08 2012
@@ -1,4 +1,4 @@
-# $NetBSD: files.nand,v 1.4 2011/06/28 18:14:11 ahoka Exp $
+# $NetBSD: files.nand,v 1.5 2012/10/31 18:58:08 riz Exp $
 
 define	nandbus	{ }
 
@@ -9,6 +9,7 @@ file	dev/nand/hamming.c	nand
 file	dev/nand/nand_bbt.c	nand
 file	dev/nand/nand_crc.c	nand
 file	dev/nand/nand_micron.c	nand
+file	dev/nand/nand_samsung.c	nand
 
 defpseudodev	nandemulator: nandbus
 file	dev/nand/nandemulator.c	nandemulator

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.17 src/sys/dev/nand/nand.c:1.18
--- src/sys/dev/nand/nand.c:1.17	Thu Jul 12 03:05:01 2012
+++ src/sys/dev/nand/nand.c	Wed Oct 31 18:58:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.17 2012/07/12 03:05:01 matt Exp $	*/
+/*	$NetBSD: nand.c,v 1.18 2012/10/31 18:58:08 riz Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.17 2012/07/12 03:05:01 matt Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.18 2012/10/31 18:58:08 riz Exp $);
 
 #include locators.h
 
@@ -332,6 +332,8 @@ nand_fill_chip_structure_legacy(device_t
 	switch (chip-nc_manf_id) {
 	case NAND_MFR_MICRON:
 		return nand_read_parameters_micron(self, chip);
+	case NAND_MFR_SAMSUNG:
+		return nand_read_parameters_samsung(self, chip);
 	default:
 		return 1;
 	}

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.13 src/sys/dev/nand/nand.h:1.14
--- src/sys/dev/nand/nand.h:1.13	Fri Jul 15 19:19:57 2011
+++ src/sys/dev/nand/nand.h	Wed Oct 31 18:58:08 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.13 2011/07/15 19:19:57 cliff Exp $	*/
+/*	$NetBSD: nand.h,v 1.14 2012/10/31 18:58:08 riz Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -428,6 +428,7 @@ extern const struct nand_manufacturer na
  * Manufacturer specific parameter functions
  */
 int nand_read_parameters_micron(device_t, struct nand_chip *);
+int nand_read_parameters_samsung(device_t, struct nand_chip *);
 
 /* debug inlines */
 



CVS commit: src/sys/dev/nand

2012-10-31 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Wed Oct 31 20:51:25 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Fill more info in nand chip structure.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.2 src/sys/dev/nand/nand_samsung.c:1.3
--- src/sys/dev/nand/nand_samsung.c:1.2	Tue Oct 30 22:43:36 2012
+++ src/sys/dev/nand/nand_samsung.c	Wed Oct 31 20:51:25 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.2 2012/10/30 22:43:36 riz Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.3 2012/10/31 20:51:25 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,11 +37,23 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.2 2012/10/30 22:43:36 riz Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.3 2012/10/31 20:51:25 ahoka Exp $);
 
 #include nand.h
 #include onfi.h
 
+enum {
+	NAND_SAMSUNG_PAGEMASK = 0x3,
+	NAND_SAMSUNG_BLOCKMASK = 0x3  4,
+	NAND_SAMSUNG_SPAREMASK = 0x1  2,
+	NAND_SAMSUNG_BITSMASK = 0x1  6
+};
+
+enum {
+	NAND_SAMSUNG_PLANENUMMASK = 0x3  2,
+	NAND_SAMSUNG_PLANESIZEMASK = 0x7  4
+};
+
 int
 nand_read_parameters_samsung(device_t self, struct nand_chip * const chip)
 {
@@ -66,15 +78,12 @@ nand_read_parameters_samsung(device_t se
 	nand_read_1(self, params3);
 	nand_select(self, false);
 
-	enum {
-		NAND_SAMSUNG_PAGEMASK = 0x3,
-		NAND_SAMSUNG_BLOCKMASK = 0x3  4,
-		NAND_SAMSUNG_SPAREMASK = 0x1  2,
-		NAND_SAMSUNG_BITSMASK = 0x1  6
-	};
-
 	/* K9XXG08UXA */
 	if (devid == 0xdc) {
+		/* From the documentation */
+		chip-nc_addr_cycles_column = 2;
+		chip-nc_addr_cycles_row = 3;
+
 		switch (params2  NAND_SAMSUNG_PAGEMASK) {
 		case 0x0:
 			chip-nc_page_size = 1024;
@@ -124,12 +133,56 @@ nand_read_parameters_samsung(device_t se
 			break;
 		}
 		
-		// TODO make this nice like the above
-		chip-nc_size = (((params3  4)  0x7) + 1) * 64 * 1024 * 1024;
+		switch ((params3  NAND_SAMSUNG_PLANENUMMASK)  2) {
+		case 0x0:
+			chip-nc_num_luns = 1;
+			break;
+		case 0x1:
+			chip-nc_num_luns = 2;
+			break;
+		case 0x2:
+			chip-nc_num_luns = 4;
+			break;
+		case 0x3:
+			chip-nc_num_luns = 8;
+			break;
+		}
+
+		uint64_t planesize;
+		switch ((params3  NAND_SAMSUNG_PLANESIZEMASK)  4) {
+		case 0x0:
+			planesize = 64 * 1024 * 1024;
+			break;
+		case 0x1:
+			planesize = 128 * 1024 * 1024;
+			break;
+		case 0x2:
+			planesize = 256 * 1024 * 1024;
+			break;
+		case 0x3:
+			planesize = 512 * 1024 * 1024;
+			break;
+		case 0x4:
+			planesize = 1024 * 1024 * 1024;
+			break;
+		case 0x5:
+			planesize = 2ul * 1024 * 1024 * 1024;
+			break;
+		case 0x6:
+			planesize = 4ul * 1024 * 1024 * 1024;
+			break;
+		case 0x7:
+			planesize = 8ul * 1024 * 1024 * 1024;
+			break;
+		}
+
+		chip-nc_lun_blocks = planesize / chip-nc_block_size;
+		chip-nc_size = planesize * chip-nc_num_luns;
+
+		aprint_normal_dev(self, vendor: Samsung, model: K9XXG08UXA\n);
 	} else {
 		return 1;
 	}

 	return 0;
 }
-



CVS commit: src/sys/dev/nand

2012-10-31 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Wed Oct 31 21:30:27 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Avoid a 'may be used uninitialized' warning.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.3 src/sys/dev/nand/nand_samsung.c:1.4
--- src/sys/dev/nand/nand_samsung.c:1.3	Wed Oct 31 20:51:25 2012
+++ src/sys/dev/nand/nand_samsung.c	Wed Oct 31 21:30:27 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.3 2012/10/31 20:51:25 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.4 2012/10/31 21:30:27 riz Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.3 2012/10/31 20:51:25 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.4 2012/10/31 21:30:27 riz Exp $);
 
 #include nand.h
 #include onfi.h
@@ -148,7 +148,7 @@ nand_read_parameters_samsung(device_t se
 			break;
 		}
 
-		uint64_t planesize;
+		uint64_t planesize = 0;
 		switch ((params3  NAND_SAMSUNG_PLANESIZEMASK)  4) {
 		case 0x0:
 			planesize = 64 * 1024 * 1024;



CVS commit: src/sys/dev/nand

2012-10-30 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Oct 30 22:03:00 UTC 2012

Added Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Add support for samsung devices, currently a draft to aid Kirkwood NAND
driver development.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u /dev/null src/sys/dev/nand/nand_samsung.c:1.1
--- /dev/null	Tue Oct 30 22:03:00 2012
+++ src/sys/dev/nand/nand_samsung.c	Tue Oct 30 22:03:00 2012
@@ -0,0 +1,135 @@
+/*	$NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $	*/
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Adam Hoka.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Device specific functions for legacy Samsung NAND chips
+ *
+ * Currently supported:
+ * K9XXG08UXA
+ */
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $);
+
+#include nand.h
+#include onfi.h
+
+int
+nand_read_parameters_samsung(device_t self, struct nand_chip * const chip)
+{
+	uint8_t mfgrid;
+	uint8_t devid;
+	uint8_t dontcare1;
+	uint8_t dontcare2;
+	uint8_t params2;
+
+	/* Only for Samsung devices, obviously */
+	if (chip-nc_manf_id != NAND_MFR_SAMSUNG) {
+		return 1;
+	}
+
+	nand_select(self, true);
+	nand_command(self, ONFI_READ_ID);
+	nand_address(self, 0x00);
+	nand_read_1(self, mfgrid);
+	nand_read_1(self, devid);
+	nand_read_1(self, params1);
+	nand_read_1(self, params2);
+	nand_read_1(self, params3);
+	nand_select(self, false);
+
+	enum {
+		NAND_SAMSUNG_PAGEMASK = 0x3,
+		NAND_SAMSUNG_BLOCKMASK = 0x3  4,
+		NAND_SAMSUNG_SPAREMASK = 0x1  2,
+		NAND_SAMSUNG_BITSMASK = 0x1  6
+	};
+
+	/* K9XXG08UXA */
+	if (devid == 0xdc) {
+		switch (params2  NAND_SAMSUNG_PAGEMASK) {
+		case 0x0:
+			chip-nc_page_size = 1024;
+			break;
+		case 0x1:
+			chip-nc_page_size = 2048;
+			break;
+		case 0x2:
+			chip-nc_page_size = 4096;
+			break;
+		case 0x3:
+			chip-nc_page_size = 8192;
+			break;
+		}
+
+		switch ((params2  NAND_SAMSUNG_PAGEMASK)  4) {
+		case 0x0:
+			chip-nc_block_size = 64 * 1024;
+			break;
+		case 0x0:
+			chip-nc_block_size = 128 * 1024;
+			break;
+		case 0x0:
+			chip-nc_block_size = 256 * 1024;
+			break;
+		case 0x0:
+			chip-nc_block_size = 512 * 1024;
+			break;
+		}
+
+		/* 8/16 bytes per 512 bytes! XXX do i get this right? */
+		switch ((params2  NAND_SAMSUNG_SPAREMASK)  2) {
+		case 0x0:
+			chip-nc_spare_size = 8 * chip-nc_page_size / 512;
+			break;
+		case 0x1:
+			chip-nc_spare_size = 16 * chip-nc_page_size / 512;
+			break;
+		}
+
+		switch ((params2  NAND_SAMSUNG_BITSMASK)  6) {
+		case 0x0:
+			/* its an 8bit chip */
+			break;
+		case 0x1:
+			chip-nc_flags |= NC_BUSWIDTH_16;
+			break;
+		}
+		
+		// TODO make this nice like the above
+		chip-nc_size = (((params3  4)  0x7) + 1) * 64 * 1024 * 1024;
+	} else {
+		return 1;
+	}
+   
+	return 0;
+}
+



CVS commit: src/sys/dev/nand

2012-10-30 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Oct 30 22:43:36 UTC 2012

Modified Files:
src/sys/dev/nand: nand_samsung.c

Log Message:
Make this compile.  (Still untested)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/nand_samsung.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_samsung.c
diff -u src/sys/dev/nand/nand_samsung.c:1.1 src/sys/dev/nand/nand_samsung.c:1.2
--- src/sys/dev/nand/nand_samsung.c:1.1	Tue Oct 30 22:03:00 2012
+++ src/sys/dev/nand/nand_samsung.c	Tue Oct 30 22:43:36 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $	*/
+/*	$NetBSD: nand_samsung.c,v 1.2 2012/10/30 22:43:36 riz Exp $	*/
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_samsung.c,v 1.2 2012/10/30 22:43:36 riz Exp $);
 
 #include nand.h
 #include onfi.h
@@ -47,9 +47,9 @@ nand_read_parameters_samsung(device_t se
 {
 	uint8_t mfgrid;
 	uint8_t devid;
-	uint8_t dontcare1;
-	uint8_t dontcare2;
+	uint8_t params1;
 	uint8_t params2;
+	uint8_t params3;
 
 	/* Only for Samsung devices, obviously */
 	if (chip-nc_manf_id != NAND_MFR_SAMSUNG) {
@@ -94,13 +94,13 @@ nand_read_parameters_samsung(device_t se
 		case 0x0:
 			chip-nc_block_size = 64 * 1024;
 			break;
-		case 0x0:
+		case 0x1:
 			chip-nc_block_size = 128 * 1024;
 			break;
-		case 0x0:
+		case 0x2:
 			chip-nc_block_size = 256 * 1024;
 			break;
-		case 0x0:
+		case 0x3:
 			chip-nc_block_size = 512 * 1024;
 			break;
 		}



CVS commit: src/sys/dev/nand

2012-07-11 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Thu Jul 12 03:05:01 UTC 2012

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Deal with a spare size of 32.  XXX necc_offset is only a guess.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.16 src/sys/dev/nand/nand.c:1.17
--- src/sys/dev/nand/nand.c:1.16	Sun Aug 28 20:49:30 2011
+++ src/sys/dev/nand/nand.c	Thu Jul 12 03:05:01 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.16 2011/08/28 20:49:30 martin Exp $	*/
+/*	$NetBSD: nand.c,v 1.17 2012/07/12 03:05:01 matt Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.16 2011/08/28 20:49:30 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.17 2012/07/12 03:05:01 matt Exp $);
 
 #include locators.h
 
@@ -429,6 +429,9 @@ nand_scan_media(device_t self, struct na
 	case 16:
 		ecc-necc_offset = 0;
 		break;
+	case 32:
+		ecc-necc_offset = 0;
+		break;
 	case 64:
 		ecc-necc_offset = 40;
 		break;
@@ -436,7 +439,7 @@ nand_scan_media(device_t self, struct na
 		ecc-necc_offset = 80;
 		break;
 	default:
-		panic(OOB size is unexpected);
+		panic(OOB size %zu is unexpected, chip-nc_spare_size);
 	}
 
 	ecc-necc_steps = chip-nc_page_size / ecc-necc_block_size;



CVS commit: src/sys/dev/nand

2011-08-28 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Aug 28 20:49:31 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Rename isbad argument to is_bad - stupid namespace pollution and ancient
bad sector routines interfere on some archs and cause global shadowing
warnings.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.15 src/sys/dev/nand/nand.c:1.16
--- src/sys/dev/nand/nand.c:1.15	Fri Jul 15 19:19:57 2011
+++ src/sys/dev/nand/nand.c	Sun Aug 28 20:49:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.15 2011/07/15 19:19:57 cliff Exp $	*/
+/*	$NetBSD: nand.c,v 1.16 2011/08/28 20:49:30 martin Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.15 2011/07/15 19:19:57 cliff Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.16 2011/08/28 20:49:30 martin Exp $);
 
 #include locators.h
 
@@ -1372,7 +1372,7 @@
 }
 
 int
-nand_flash_isbad(device_t self, flash_off_t ofs, bool *isbad)
+nand_flash_isbad(device_t self, flash_off_t ofs, bool *is_bad)
 {
 	struct nand_softc *sc = device_private(self);
 	struct nand_chip *chip = sc-sc_chip;
@@ -1396,7 +1396,7 @@
 	result = nand_isbad(self, ofs);
 	mutex_exit(sc-sc_device_lock);
 
-	*isbad = result;
+	*is_bad = result;
 
 	return 0;
 }



CVS commit: src/sys/dev/nand

2011-07-01 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Jul  1 16:46:13 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c nand.h

Log Message:
Make this actually compile by adding a wrapper function which calls
flash_io_submit.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.13 src/sys/dev/nand/nand.c:1.14
--- src/sys/dev/nand/nand.c:1.13	Tue Jun 28 18:14:11 2011
+++ src/sys/dev/nand/nand.c	Fri Jul  1 16:46:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.13 2011/06/28 18:14:11 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.14 2011/07/01 16:46:13 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.13 2011/06/28 18:14:11 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.14 2011/07/01 16:46:13 ahoka Exp $);
 
 #include locators.h
 
@@ -84,7 +84,7 @@
 	.block_isbad = nand_flash_isbad,
 	.block_markbad = nand_flash_markbad,
 
-	.submit = nand_io_submit
+	.submit = nand_flash_submit
 };
 
 #ifdef NAND_VERBOSE
@@ -228,7 +228,7 @@
 		return error;
 	}
 
-	nand_sync_thread_stop(self);
+	flash_sync_thread_destroy(sc-sc_flash_io);
 #ifdef NAND_BBT
 	nand_bbt_detach(self);
 #endif
@@ -1036,6 +1036,14 @@
 
 /* implementation of the block device API */
 
+int
+nand_flash_submit(device_t self, struct buf *bp)
+{
+	struct nand_softc *sc = device_private(self);
+
+	return flash_io_submit(sc-sc_flash_io, bp);
+}
+
 /*
  * handle (page) unaligned write to nand
  */

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.11 src/sys/dev/nand/nand.h:1.12
--- src/sys/dev/nand/nand.h:1.11	Tue Jun 28 18:14:11 2011
+++ src/sys/dev/nand/nand.h	Fri Jul  1 16:46:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.11 2011/06/28 18:14:11 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.12 2011/07/01 16:46:13 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -452,15 +452,11 @@
 int nand_flash_write(device_t, flash_off_t, size_t, size_t *, const u_char *);
 int nand_flash_read(device_t, flash_off_t, size_t, size_t *, uint8_t *);
 int nand_flash_erase(device_t, struct flash_erase_instruction *);
+int nand_flash_submit(device_t, struct buf *);
 
 /* nand specific functions */
 int nand_erase_block(device_t, size_t);
 
-int nand_io_submit(device_t, struct buf *);
-void nand_sync_thread(void *);
-int nand_sync_thread_start(device_t);
-void nand_sync_thread_stop(device_t);
-
 bool nand_isfactorybad(device_t, flash_off_t);
 bool nand_iswornoutbad(device_t, flash_off_t);
 bool nand_isbad(device_t, flash_off_t);



CVS commit: src/sys/dev/nand

2011-06-28 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Jun 28 07:16:11 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c nand.h nand_micron.c

Log Message:
follow bus_space conventions in naming


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nand_micron.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.11 src/sys/dev/nand/nand.c:1.12
--- src/sys/dev/nand/nand.c:1.11	Sun May  1 13:20:28 2011
+++ src/sys/dev/nand/nand.c	Tue Jun 28 07:16:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.11 2011/05/01 13:20:28 rmind Exp $	*/
+/*	$NetBSD: nand.c,v 1.12 2011/06/28 07:16:11 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.11 2011/05/01 13:20:28 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.12 2011/06/28 07:16:11 ahoka Exp $);
 
 #include locators.h
 
@@ -133,7 +133,7 @@
 		aprint_error(NAND chip is write protected!\n);
 		return;
 	}
-	
+
 	if (nand_scan_media(self, chip)) {
 		return;
 	}
@@ -289,14 +289,14 @@
 	interface-select = nand_default_select;
 	interface-command = NULL;
 	interface-address = NULL;
-	interface-read_buf_byte = NULL;
-	interface-read_buf_word = NULL;
-	interface-read_byte = NULL;
-	interface-read_word = NULL;
-	interface-write_buf_byte = NULL;
-	interface-write_buf_word = NULL;
-	interface-write_byte = NULL;
-	interface-write_word = NULL;
+	interface-read_buf_1 = NULL;
+	interface-read_buf_2 = NULL;
+	interface-read_1 = NULL;
+	interface-read_2 = NULL;
+	interface-write_buf_1 = NULL;
+	interface-write_buf_2 = NULL;
+	interface-write_1 = NULL;
+	interface-write_2 = NULL;
 	interface-busy = NULL;
 
 	/*-
@@ -366,10 +366,10 @@
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x20);
-	nand_read_byte(self, onfi_signature[0]);
-	nand_read_byte(self, onfi_signature[1]);
-	nand_read_byte(self, onfi_signature[2]);
-	nand_read_byte(self, onfi_signature[3]);
+	nand_read_1(self, onfi_signature[0]);
+	nand_read_1(self, onfi_signature[1]);
+	nand_read_1(self, onfi_signature[2]);
+	nand_read_1(self, onfi_signature[3]);
 	nand_select(self, false);
 
 	if (onfi_signature[0] != 'O' || onfi_signature[1] != 'N' ||
@@ -423,7 +423,7 @@
 	PRIu8 \n,
 	chip-nc_addr_cycles_column, chip-nc_addr_cycles_row);
 #endif
-		
+
 	ecc = chip-nc_ecc = sc-nand_if-ecc;
 
 	/*
@@ -488,8 +488,8 @@
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x00);
 
-	nand_read_byte(self, manf);
-	nand_read_byte(self, dev);
+	nand_read_1(self, manf);
+	nand_read_1(self, dev);
 
 	nand_select(self, false);
 }
@@ -505,7 +505,7 @@
 
 //read_params:
 //	tries++;
-	
+
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_PARAMETER_PAGE);
 	nand_address(self, 0x00);
@@ -517,10 +517,10 @@
 	bufp = (uint8_t *)params;
 	/* XXX why i am not using read_buf? */
 	for (i = 0; i  256; i++) {
-		nand_read_byte(self, bufp[i]);
+		nand_read_1(self, bufp[i]);
 	}
 	nand_select(self, false);
-	
+
 	/* validate the parameter page with the crc */
 	crc = nand_crc16(bufp, 254);
 
@@ -639,7 +639,7 @@
 
 	nand_command(self, ONFI_READ_STATUS);
 	nand_busy(self);
-	nand_read_byte(self, status);
+	nand_read_1(self, status);
 
 	return status;
 }
@@ -682,14 +682,14 @@
 	if (chip-nc_flags  NC_BUSWIDTH_16) {
 		for (b = 0, e = 0; b  chip-nc_page_size; b += bs, e += cs) {
 			nand_ecc_prepare(self, NAND_ECC_READ);
-			nand_read_buf_word(self, data + b, bs);
+			nand_read_buf_2(self, data + b, bs);
 			nand_ecc_compute(self, data + b,
 			chip-nc_ecc_cache + e);
 		}
 	} else {
 		for (b = 0, e = 0; b  chip-nc_page_size; b += bs, e += cs) {
 			nand_ecc_prepare(self, NAND_ECC_READ);
-			nand_read_buf_byte(self, data + b, bs);
+			nand_read_buf_1(self, data + b, bs);
 			nand_ecc_compute(self, data + b,
 			chip-nc_ecc_cache + e);
 		}
@@ -775,20 +775,20 @@
 	if (chip-nc_flags  NC_BUSWIDTH_16) {
 		for (b = 0, e = 0; b  chip-nc_page_size; b += bs, e += cs) {
 			nand_ecc_prepare(self, NAND_ECC_WRITE);
-			nand_write_buf_word(self, data + b, bs);
+			nand_write_buf_2(self, data + b, bs);
 			nand_ecc_compute(self, data + b, ecc + e);
 		}
 		/* write oob with ecc correction code */
-		nand_write_buf_word(self, chip-nc_oob_cache,
+		nand_write_buf_2(self, chip-nc_oob_cache,
 		chip-nc_spare_size);
 	} else {
 		for (b = 0, e = 0; b  chip-nc_page_size; b += bs, e += cs) {
 			nand_ecc_prepare(self, NAND_ECC_WRITE);
-			nand_write_buf_byte(self, data + b, bs);
+			nand_write_buf_1(self, data + b, bs);
 			nand_ecc_compute(self, data + b, ecc + e);
 		}
 		/* write oob with ecc correction code */
-		nand_write_buf_byte(self, 

CVS commit: src/sys/dev/nand

2011-06-28 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Jun 28 10:32:45 UTC 2011

Modified Files:
src/sys/dev/nand: nandemulator.c

Log Message:
adjust to nand changes


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nandemulator.c
diff -u src/sys/dev/nand/nandemulator.c:1.4 src/sys/dev/nand/nandemulator.c:1.5
--- src/sys/dev/nand/nandemulator.c:1.4	Tue Apr 26 13:38:13 2011
+++ src/sys/dev/nand/nandemulator.c	Tue Jun 28 10:32:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nandemulator.c,v 1.4 2011/04/26 13:38:13 ahoka Exp $	*/
+/*	$NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.4 2011/04/26 13:38:13 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.5 2011/06/28 10:32:45 ahoka Exp $);
 
 #include sys/param.h
 #include sys/device.h
@@ -57,14 +57,14 @@
 static void nandemulator_command(device_t, uint8_t);
 static void nandemulator_address(device_t, uint8_t);
 static void nandemulator_busy(device_t);
-static void nandemulator_read_byte(device_t, uint8_t *);
-static void nandemulator_write_byte(device_t, uint8_t);
-static void nandemulator_read_word(device_t, uint16_t *);
-static void nandemulator_write_word(device_t, uint16_t);
-static void nandemulator_read_buf_byte(device_t, void *, size_t);
-static void nandemulator_read_buf_word(device_t, void *, size_t);
-static void nandemulator_write_buf_byte(device_t, const void *, size_t);
-static void nandemulator_write_buf_word(device_t, const void *, size_t);
+static void nandemulator_read_1(device_t, uint8_t *);
+static void nandemulator_write_1(device_t, uint8_t);
+static void nandemulator_read_2(device_t, uint16_t *);
+static void nandemulator_write_2(device_t, uint16_t);
+static void nandemulator_read_buf_1(device_t, void *, size_t);
+static void nandemulator_read_buf_2(device_t, void *, size_t);
+static void nandemulator_write_buf_1(device_t, const void *, size_t);
+static void nandemulator_write_buf_2(device_t, const void *, size_t);
 
 static size_t nandemulator_address_to_page(device_t);
 static size_t nandemulator_page_to_backend_offset(device_t, size_t);
@@ -186,14 +186,14 @@
 
 	sc-sc_nand_if.command = nandemulator_command;
 	sc-sc_nand_if.address = nandemulator_address;
-	sc-sc_nand_if.read_buf_byte = nandemulator_read_buf_byte;
-	sc-sc_nand_if.read_buf_word = nandemulator_read_buf_word;
-	sc-sc_nand_if.read_byte = nandemulator_read_byte;
-	sc-sc_nand_if.read_word = nandemulator_read_word;
-	sc-sc_nand_if.write_buf_byte = nandemulator_write_buf_byte;
-	sc-sc_nand_if.write_buf_word = nandemulator_write_buf_word;
-	sc-sc_nand_if.write_byte = nandemulator_write_byte;
-	sc-sc_nand_if.write_word = nandemulator_write_word;
+	sc-sc_nand_if.read_buf_1 = nandemulator_read_buf_1;
+	sc-sc_nand_if.read_buf_2 = nandemulator_read_buf_2;
+	sc-sc_nand_if.read_1 = nandemulator_read_1;
+	sc-sc_nand_if.read_2 = nandemulator_read_2;
+	sc-sc_nand_if.write_buf_1 = nandemulator_write_buf_1;
+	sc-sc_nand_if.write_buf_2 = nandemulator_write_buf_2;
+	sc-sc_nand_if.write_1 = nandemulator_write_1;
+	sc-sc_nand_if.write_2 = nandemulator_write_2;
 	sc-sc_nand_if.busy = nandemulator_busy;
 
 	sc-sc_nand_if.ecc.necc_code_size = 3;
@@ -326,7 +326,7 @@
 
 	KASSERT(sc-sc_address_counter ==
 	sc-sc_column_cycles + sc-sc_row_cycles);
-	
+
 	if (sc-sc_address_counter !=
 	sc-sc_column_cycles + sc-sc_row_cycles) {
 		aprint_error_dev(self, incorrect number of address cycles\n);
@@ -472,7 +472,7 @@
 		sc-sc_address = 8;
 		sc-sc_address |= address;
 		sc-sc_address_counter++;
-		
+
 		if (sc-sc_address_counter ==
 		sc-sc_column_cycles + sc-sc_row_cycles) {
 			nandemulator_address_chip(self);
@@ -505,7 +505,7 @@
 }
 
 static void
-nandemulator_read_byte(device_t self, uint8_t *data)
+nandemulator_read_1(device_t self, uint8_t *data)
 {
 	struct nandemulator_softc *sc = device_private(self);
 
@@ -523,7 +523,7 @@
 }
 
 static void
-nandemulator_write_byte(device_t self, uint8_t data)
+nandemulator_write_1(device_t self, uint8_t data)
 {
 	struct nandemulator_softc *sc = device_private(self);
 
@@ -548,7 +548,7 @@
 }
 
 static void
-nandemulator_read_word(device_t self, uint16_t *data)
+nandemulator_read_2(device_t self, uint16_t *data)
 {
 	struct nandemulator_softc *sc = device_private(self);
 
@@ -574,7 +574,7 @@
 }
 
 static void
-nandemulator_write_word(device_t self, uint16_t data)
+nandemulator_write_2(device_t self, uint16_t data)
 {
 	struct nandemulator_softc *sc = device_private(self);
 
@@ -607,7 +607,7 @@
 }
 
 static void
-nandemulator_read_buf_byte(device_t self, void *buf, size_t len)
+nandemulator_read_buf_1(device_t self, void *buf, size_t len)
 {
 	uint8_t *addr;
 
@@ -616,13 

CVS commit: src/sys/dev/nand

2011-05-01 Thread Mindaugas Rasiukevicius
Module Name:src
Committed By:   rmind
Date:   Sun May  1 13:20:29 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c nand_bbt.c nand_io.c nand_micron.c

Log Message:
Remove trailing tabs, add RCS IDs.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nand_bbt.c \
src/sys/dev/nand/nand_micron.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nand_io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.10 src/sys/dev/nand/nand.c:1.11
--- src/sys/dev/nand/nand.c:1.10	Tue Apr 26 17:31:57 2011
+++ src/sys/dev/nand/nand.c	Sun May  1 13:20:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.10 2011/04/26 17:31:57 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.11 2011/05/01 13:20:28 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.10 2011/04/26 17:31:57 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.11 2011/05/01 13:20:28 rmind Exp $);
 
 #include locators.h
 
@@ -343,7 +343,7 @@
 	default:
 		return 1;
 	}
-	
+
 	return 0;
 }
 
@@ -375,9 +375,9 @@
 	if (onfi_signature[0] != 'O' || onfi_signature[1] != 'N' ||
 	onfi_signature[2] != 'F' || onfi_signature[3] != 'I') {
 		chip-nc_isonfi = false;
-		
+
 		aprint_normal(: Legacy NAND Flash\n);
-		
+
 		nand_read_id(self, chip-nc_manf_id, chip-nc_dev_id);
 
 		if (nand_fill_chip_structure_legacy(self, chip)) {
@@ -391,11 +391,10 @@
 		aprint_normal(: ONFI NAND Flash\n);
 
 		nand_read_id(self, chip-nc_manf_id, chip-nc_dev_id);
-		
+
 		if (nand_fill_chip_structure(self, chip)) {
 			aprint_error_dev(self,
 			can't read device parameters\n);
-			
 			return 1;
 		}
 	}
@@ -488,10 +487,10 @@
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x00);
-	
+
 	nand_read_byte(self, manf);
 	nand_read_byte(self, dev);
-	
+
 	nand_select(self, false);
 }
 
@@ -1300,9 +1299,7 @@
 
 		addr += chip-nc_page_size;
 	}
-
 	KASSERT(*retlen == len);
-
 out:
 	mutex_exit(sc-sc_device_lock);
 
@@ -1341,7 +1338,6 @@
 	if (len  chip-nc_page_size)
 		panic(TODO page size is larger than read size);
 #endif
-	
 
 	if (len % chip-nc_page_size != 0 ||
 	offset % chip-nc_page_size != 0) {
@@ -1369,7 +1365,6 @@
 		addr += chip-nc_page_size;
 		*retlen += chip-nc_page_size;
 	}
-
 out:
 	mutex_exit(sc-sc_device_lock);
 
@@ -1402,7 +1397,7 @@
 	mutex_exit(sc-sc_device_lock);
 
 	*isbad = result;
-	
+
 	return 0;
 }
 
@@ -1473,7 +1468,6 @@
 		if (nand_isbad(self, addr)) {
 			aprint_error_dev(self, bad block encountered\n);
 			ei-ei_state = FLASH_ERASE_FAILED;
-			
 			error = EIO;
 			goto out;
 		}
@@ -1481,7 +1475,6 @@
 		error = nand_erase_block(self, addr);
 		if (error) {
 			ei-ei_state = FLASH_ERASE_FAILED;
-			
 			goto out;
 		}
 

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.3 src/sys/dev/nand/nand_bbt.c:1.4
--- src/sys/dev/nand/nand_bbt.c:1.3	Tue Apr 26 13:38:13 2011
+++ src/sys/dev/nand/nand_bbt.c	Sun May  1 13:20:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.3 2011/04/26 13:38:13 ahoka Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.4 2011/05/01 13:20:28 rmind Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -31,7 +31,12 @@
  * SUCH DAMAGE.
  */
 
-/* Support for Bad Block Tables (BBTs) */
+/*
+ * Implementation of Bad Block Tables (BBTs).
+ */
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: nand_bbt.c,v 1.4 2011/05/01 13:20:28 rmind Exp $);
 
 #include sys/param.h
 #include sys/kmem.h
@@ -95,9 +100,9 @@
 	struct nand_softc *sc = device_private(self);
 	struct nand_chip *chip = sc-sc_chip;
 	uint8_t *oob = chip-nc_oob_cache;
-	
+
 	nand_read_oob(self, addr, oob);
-	
+
 	if (oob[NAND_BBT_OFFSET] == 'B' 
 	oob[NAND_BBT_OFFSET + 1] == 'b' 
 	oob[NAND_BBT_OFFSET + 2] == 't') {
@@ -123,26 +128,26 @@
 	if (nand_isbad(self, addr)) {
 		return false;
 	}
-		
+
 	if (nand_bbt_page_has_bbt(self, addr)) {
 		bbtp = bbt-nbbt_bitmap;
 		left = bbt-nbbt_size;
-		
+
 		for (i = 0; i  bbt_pages; i++) {
 			nand_read_page(self, addr, buf);
-
+
 			if (i == bbt_pages - 1) {
 KASSERT(left = chip-nc_page_size);
 memcpy(bbtp, buf, left);
 			} else {
 memcpy(bbtp, buf, chip-nc_page_size);
 			}
-
+
 			bbtp += chip-nc_page_size;
 			left -= chip-nc_page_size;
 			addr += chip-nc_page_size;
 		}
-		
+
 		return true;
 	} else {
 		return false;
Index: src/sys/dev/nand/nand_micron.c
diff -u src/sys/dev/nand/nand_micron.c:1.3 src/sys/dev/nand/nand_micron.c:1.4
--- src/sys/dev/nand/nand_micron.c:1.3	Fri Mar 18 16:46:04 2011
+++ src/sys/dev/nand/nand_micron.c	Sun May  1 13:20:28 2011
@@ -1,4 +1,5 @@
-/*	$NetBSD: nand_micron.c,v 1.3 2011/03/18 16:46:04 ahoka Exp $	*/

CVS commit: src/sys/dev/nand

2011-05-01 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Sun May  1 14:48:11 UTC 2011

Modified Files:
src/sys/dev/nand: nand.h nand_io.c

Log Message:
fix some bugs and simplify locking
from rmind


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/nand_io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.8 src/sys/dev/nand/nand.h:1.9
--- src/sys/dev/nand/nand.h:1.8	Tue Apr 26 17:31:57 2011
+++ src/sys/dev/nand/nand.h	Sun May  1 14:48:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.8 2011/04/26 17:31:57 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.9 2011/05/01 14:48:11 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -141,6 +141,9 @@
 	daddr_t nwc_block;
 	kmutex_t nwc_lock;
 	bool nwc_write_pending;
+	struct lwp *nwc_thread;
+	kcondvar_t nwc_cv;
+	bool nwc_exiting;
 };
 
 /* driver softc for nand */
@@ -154,13 +157,7 @@
 	size_t sc_part_offset;
 	size_t sc_part_size;
 	kmutex_t sc_device_lock; /* serialize access to chip */
-
-	/* for the i/o thread */
-	struct lwp *sc_sync_thread;
 	struct nand_write_cache sc_cache;
-	kmutex_t sc_io_lock;
-	kcondvar_t sc_io_cv;
-	bool sc_io_running;
 };
 
 /* structure holding the nand api */

Index: src/sys/dev/nand/nand_io.c
diff -u src/sys/dev/nand/nand_io.c:1.5 src/sys/dev/nand/nand_io.c:1.6
--- src/sys/dev/nand/nand_io.c:1.5	Sun May  1 13:20:28 2011
+++ src/sys/dev/nand/nand_io.c	Sun May  1 14:48:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_io.c,v 1.5 2011/05/01 13:20:28 rmind Exp $	*/
+/*	$NetBSD: nand_io.c,v 1.6 2011/05/01 14:48:11 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -37,7 +37,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand_io.c,v 1.5 2011/05/01 13:20:28 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand_io.c,v 1.6 2011/05/01 14:48:11 ahoka Exp $);
 
 #include sys/param.h
 #include sys/buf.h
@@ -109,31 +109,27 @@
 
 	sc-sc_cache.nwc_data = kmem_alloc(chip-nc_block_size, KM_SLEEP);
 
-	mutex_init(sc-sc_io_lock, MUTEX_DEFAULT, IPL_NONE);
 	mutex_init(wc-nwc_lock, MUTEX_DEFAULT, IPL_NONE);
-	cv_init(sc-sc_io_cv, nandcv);
+	cv_init(wc-nwc_cv, nandcv);
 
 	error = bufq_alloc(wc-nwc_bufq, fcfs, BUFQ_SORT_RAWBLOCK);
 	if (error)
 		goto err_bufq;
 
-	sc-sc_io_running = true;
+	wc-nwc_exiting = false;
 	wc-nwc_write_pending = false;
 
 	/* arrange to allocate the kthread */
 	error = kthread_create(PRI_NONE, KTHREAD_JOINABLE | KTHREAD_MPSAFE,
-	NULL, nand_sync_thread, self, sc-sc_sync_thread, nandio);
+	NULL, nand_sync_thread, self, wc-nwc_thread, nandio);
 
 	if (!error)
 		return 0;
 
 	bufq_free(wc-nwc_bufq);
 err_bufq:
-	cv_destroy(sc-sc_io_cv);
-
-	mutex_destroy(sc-sc_io_lock);
+	cv_destroy(wc-nwc_cv);
 	mutex_destroy(wc-nwc_lock);
-	
 	kmem_free(sc-sc_cache.nwc_data, chip-nc_block_size);
 
 	return error;
@@ -148,27 +144,17 @@
 
 	DPRINTF((stopping nand io thread\n));
 
-	kmem_free(wc-nwc_data, chip-nc_block_size);
-
-	sc-sc_io_running = false;
-
-	mutex_enter(sc-sc_io_lock);
-	cv_broadcast(sc-sc_io_cv);
-	mutex_exit(sc-sc_io_lock);
+	mutex_enter(wc-nwc_lock);
+	wc-nwc_exiting = true;
+	cv_broadcast(wc-nwc_cv);
+	mutex_exit(wc-nwc_lock);
 
-	kthread_join(sc-sc_sync_thread);
+	kthread_join(wc-nwc_thread);
 
+	kmem_free(wc-nwc_data, chip-nc_block_size);
 	bufq_free(wc-nwc_bufq);
 	mutex_destroy(wc-nwc_lock);
-
-#ifdef DIAGNOSTIC
-	mutex_enter(sc-sc_io_lock);
-	KASSERT(!cv_has_waiters(sc-sc_io_cv));
-	mutex_exit(sc-sc_io_lock);
-#endif
-
-	cv_destroy(sc-sc_io_cv);
-	mutex_destroy(sc-sc_io_lock);
+	cv_destroy(wc-nwc_cv);
 }
 
 int
@@ -179,7 +165,7 @@
 
 	DPRINTF((submitting job to nand io thread: %p\n, bp));
 
-	if (__predict_false(!sc-sc_io_running)) {
+	if (__predict_false(wc-nwc_exiting)) {
 		nand_io_done(self, bp, ENODEV);
 		return ENODEV;
 	}
@@ -211,6 +197,7 @@
 	daddr_t base, offset;
 	int error;
 
+	KASSERT(mutex_owned(wc-nwc_lock));
 	KASSERT(chip-nc_block_size != 0);
 
 	base = block * chip-nc_block_size;
@@ -247,7 +234,6 @@
 	return 0;
 }
 
-/* must be called with nwc_lock hold */
 void
 nand_io_cache_sync(device_t self)
 {
@@ -260,6 +246,8 @@
 	daddr_t base;
 	int error;
 
+	KASSERT(mutex_owned(wc-nwc_lock));
+
 	if (!wc-nwc_write_pending) {
 		DPRINTF((trying to sync with an invalid buffer\n));
 		return;
@@ -305,18 +293,12 @@
 	struct nand_write_cache *wc = sc-sc_cache;
 	struct bintime now;
 
-	/* sync thread waking in every seconds */
-	while (sc-sc_io_running) {
-		mutex_enter(sc-sc_io_lock);
-		cv_timedwait_sig(sc-sc_io_cv, sc-sc_io_lock, hz / 4);
-		mutex_exit(sc-sc_io_lock);
-
-		mutex_enter(wc-nwc_lock);
+	mutex_enter(wc-nwc_lock);
+	while (!wc-nwc_exiting) {
+		cv_timedwait_sig(wc-nwc_cv, wc-nwc_lock, hz / 4);
 		if (!wc-nwc_write_pending) {
-			mutex_exit(wc-nwc_lock);
 			continue;
 		}
-
 		/* see if the cache is older 

CVS commit: src/sys/dev/nand

2011-04-26 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Apr 26 13:38:13 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c nand.h nand_bbt.c nand_io.c nandemulator.c

Log Message:
fix some bugs in detachment


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nand_bbt.c \
src/sys/dev/nand/nand_io.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.8 src/sys/dev/nand/nand.c:1.9
--- src/sys/dev/nand/nand.c:1.8	Sun Apr 10 12:48:09 2011
+++ src/sys/dev/nand/nand.c	Tue Apr 26 13:38:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.8 2011/04/10 12:48:09 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.9 2011/04/26 13:38:13 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.8 2011/04/10 12:48:09 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.9 2011/04/26 13:38:13 ahoka Exp $);
 
 #include locators.h
 
@@ -43,6 +43,7 @@
 #include sys/device.h
 #include sys/kmem.h
 #include sys/sysctl.h
+#include sys/atomic.h
 
 #include dev/flash/flash.h
 #include dev/nand/nand.h
@@ -57,6 +58,7 @@
 void nand_attach(device_t, device_t, void *);
 int nand_detach(device_t, int);
 bool nand_shutdown(device_t, int);
+void nand_childdet(device_t, device_t);
 
 int nand_print(void *, const char *);
 
@@ -67,8 +69,12 @@
 static int nand_scan_media(device_t, struct nand_chip *);
 static bool nand_check_wp(device_t);
 
-CFATTACH_DECL_NEW(nand, sizeof(struct nand_softc),
-nand_match, nand_attach, nand_detach, NULL);
+CFATTACH_DECL2_NEW(nand, sizeof(struct nand_softc),
+nand_match, nand_attach, nand_detach,
+NULL, NULL, nand_childdet);
+
+//CFATTACH_DECL_NEW(nand, sizeof(struct nand_softc),
+//nand_match, nand_attach, nand_detach, NULL);
 
 #ifdef NAND_DEBUG
 int	nanddebug = NAND_DEBUG;
@@ -126,6 +132,8 @@
 	sc-controller_dev = parent;
 	sc-nand_if = naa-naa_nand_if;
 
+	sc-sc_children = 0;
+
 	aprint_naive(\n);
 
 	if (nand_check_wp(self)) {
@@ -211,8 +219,12 @@
 	faa.flash_if = flash_if;
 
 	if (config_match(parent, cf, faa)) {
-		config_attach(parent, cf, faa, nand_print);
-		return 0;
+		if (config_attach(parent, cf, faa, nand_print) != NULL) {
+			atomic_inc_uint(sc-sc_children);
+			return 0;
+		} else {
+			return 1;
+		}
 	} else {
 		kmem_free(flash_if, sizeof(*flash_if));
 	}
@@ -227,11 +239,14 @@
 	struct nand_chip *chip = sc-sc_chip;
 	int ret = 0;
 
+	if (sc-sc_children != 0) {
+		return EBUSY;
+	}
+
+	nand_sync_thread_stop(self);
 #ifdef NAND_BBT
 	nand_bbt_detach(self);
 #endif
-	nand_sync_thread_stop(self);
-
 	/* free oob cache */
 	kmem_free(chip-nc_oob_cache, chip-nc_spare_size);
 	kmem_free(chip-nc_page_cache, chip-nc_page_size);
@@ -244,6 +259,15 @@
 	return ret;
 }
 
+void
+nand_childdet(device_t self, device_t child)
+{
+	struct nand_softc *sc = device_private(self);
+
+	atomic_dec_uint(sc-sc_children);
+	KASSERT(sc-sc_children = 0);
+}
+
 int
 nand_print(void *aux, const char *pnp)
 {

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.6 src/sys/dev/nand/nand.h:1.7
--- src/sys/dev/nand/nand.h:1.6	Sun Apr 10 12:48:09 2011
+++ src/sys/dev/nand/nand.h	Tue Apr 26 13:38:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.6 2011/04/10 12:48:09 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.7 2011/04/26 13:38:13 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -45,11 +45,9 @@
 #include dev/flash/flash.h
 
 #ifdef NAND_DEBUG
-#define DPRINTF(x)	if (nanddebug) printf x
-#define DPRINTFN(n,x)	if (nanddebug(n)) printf x
+#define DPRINTF(x)	printf x
 #else
 #define DPRINTF(x)
-#define DPRINTFN(n,x)
 #endif
 
 //#define NAND_VERBOSE
@@ -161,9 +159,15 @@
 	struct lwp *sc_sync_thread;
 	struct nand_write_cache sc_cache;
 	kmutex_t sc_io_lock;
-	kmutex_t sc_waitq_lock;
 	kcondvar_t sc_io_cv;
 	bool sc_io_running;
+
+	/* currently we cant automatically detach children
+	 * so keep count of attached children so we will
+	 * know, that when is safe to detach...
+	 * XXX is it a problem only as a module? (ioconf bug?)
+	 */
+	unsigned int sc_children;
 };
 
 /* structure holding the nand api */

Index: src/sys/dev/nand/nand_bbt.c
diff -u src/sys/dev/nand/nand_bbt.c:1.2 src/sys/dev/nand/nand_bbt.c:1.3
--- src/sys/dev/nand/nand_bbt.c:1.2	Mon Apr  4 14:25:10 2011
+++ src/sys/dev/nand/nand_bbt.c	Tue Apr 26 13:38:13 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_bbt.c,v 1.2 2011/04/04 14:25:10 ahoka Exp $	*/
+/*	$NetBSD: nand_bbt.c,v 1.3 2011/04/26 13:38:13 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -58,9 +58,7 @@
 	struct nand_softc *sc = 

CVS commit: src/sys/dev/nand

2011-04-26 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Apr 26 17:27:53 UTC 2011

Modified Files:
src/sys/dev/nand: nand_io.c

Log Message:
whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nand_io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_io.c
diff -u src/sys/dev/nand/nand_io.c:1.3 src/sys/dev/nand/nand_io.c:1.4
--- src/sys/dev/nand/nand_io.c:1.3	Tue Apr 26 13:38:13 2011
+++ src/sys/dev/nand/nand_io.c	Tue Apr 26 17:27:52 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand_io.c,v 1.3 2011/04/26 13:38:13 ahoka Exp $	*/
+/*	$NetBSD: nand_io.c,v 1.4 2011/04/26 17:27:52 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -141,17 +141,17 @@
 	struct nand_softc *sc = device_private(self);
 	struct nand_chip *chip = sc-sc_chip;
 	struct nand_write_cache *wc = sc-sc_cache;
-	
+
 	DPRINTF((stopping nand io thread\n));
-	
+
 	kmem_free(wc-nwc_data, chip-nc_block_size);
-	
+
 	sc-sc_io_running = false;
-	
+
 	mutex_enter(sc-sc_io_lock);
 	cv_broadcast(sc-sc_io_cv);
 	mutex_exit(sc-sc_io_lock);
-	
+
 	kthread_join(sc-sc_sync_thread);
 
 	bufq_free(wc-nwc_bufq);
@@ -162,7 +162,7 @@
 	KASSERT(!cv_has_waiters(sc-sc_io_cv));
 	mutex_exit(sc-sc_io_lock);
 #endif
-	
+
 	cv_destroy(sc-sc_io_cv);
 	mutex_destroy(sc-sc_io_lock);
 }



CVS commit: src/sys/dev/nand

2011-04-26 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Tue Apr 26 17:31:58 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c nand.h

Log Message:
it seems we have a config_detach_children (though undocumented)
lets use that to detach flash devices before detaching nand


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.9 src/sys/dev/nand/nand.c:1.10
--- src/sys/dev/nand/nand.c:1.9	Tue Apr 26 13:38:13 2011
+++ src/sys/dev/nand/nand.c	Tue Apr 26 17:31:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.9 2011/04/26 13:38:13 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.10 2011/04/26 17:31:57 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.9 2011/04/26 13:38:13 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.10 2011/04/26 17:31:57 ahoka Exp $);
 
 #include locators.h
 
@@ -58,7 +58,6 @@
 void nand_attach(device_t, device_t, void *);
 int nand_detach(device_t, int);
 bool nand_shutdown(device_t, int);
-void nand_childdet(device_t, device_t);
 
 int nand_print(void *, const char *);
 
@@ -69,12 +68,8 @@
 static int nand_scan_media(device_t, struct nand_chip *);
 static bool nand_check_wp(device_t);
 
-CFATTACH_DECL2_NEW(nand, sizeof(struct nand_softc),
-nand_match, nand_attach, nand_detach,
-NULL, NULL, nand_childdet);
-
-//CFATTACH_DECL_NEW(nand, sizeof(struct nand_softc),
-//nand_match, nand_attach, nand_detach, NULL);
+CFATTACH_DECL_NEW(nand, sizeof(struct nand_softc),
+nand_match, nand_attach, nand_detach, NULL);
 
 #ifdef NAND_DEBUG
 int	nanddebug = NAND_DEBUG;
@@ -132,8 +127,6 @@
 	sc-controller_dev = parent;
 	sc-nand_if = naa-naa_nand_if;
 
-	sc-sc_children = 0;
-
 	aprint_naive(\n);
 
 	if (nand_check_wp(self)) {
@@ -220,7 +213,6 @@
 
 	if (config_match(parent, cf, faa)) {
 		if (config_attach(parent, cf, faa, nand_print) != NULL) {
-			atomic_inc_uint(sc-sc_children);
 			return 0;
 		} else {
 			return 1;
@@ -237,10 +229,11 @@
 {
 	struct nand_softc *sc = device_private(self);
 	struct nand_chip *chip = sc-sc_chip;
-	int ret = 0;
+	int error = 0;
 
-	if (sc-sc_children != 0) {
-		return EBUSY;
+	error = config_detach_children(self, flags);
+	if (error) {
+		return error;
 	}
 
 	nand_sync_thread_stop(self);
@@ -256,16 +249,7 @@
 
 	pmf_device_deregister(sc-sc_dev);
 
-	return ret;
-}
-
-void
-nand_childdet(device_t self, device_t child)
-{
-	struct nand_softc *sc = device_private(self);
-
-	atomic_dec_uint(sc-sc_children);
-	KASSERT(sc-sc_children = 0);
+	return error;
 }
 
 int

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.7 src/sys/dev/nand/nand.h:1.8
--- src/sys/dev/nand/nand.h:1.7	Tue Apr 26 13:38:13 2011
+++ src/sys/dev/nand/nand.h	Tue Apr 26 17:31:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.7 2011/04/26 13:38:13 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.8 2011/04/26 17:31:57 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -161,13 +161,6 @@
 	kmutex_t sc_io_lock;
 	kcondvar_t sc_io_cv;
 	bool sc_io_running;
-
-	/* currently we cant automatically detach children
-	 * so keep count of attached children so we will
-	 * know, that when is safe to detach...
-	 * XXX is it a problem only as a module? (ioconf bug?)
-	 */
-	unsigned int sc_children;
 };
 
 /* structure holding the nand api */



CVS commit: src/sys/dev/nand

2011-04-10 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Sun Apr 10 10:56:37 UTC 2011

Modified Files:
src/sys/dev/nand: nandemulator.c

Log Message:
Add some KASSERTs and a few more debug printf


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nandemulator.c
diff -u src/sys/dev/nand/nandemulator.c:1.2 src/sys/dev/nand/nandemulator.c:1.3
--- src/sys/dev/nand/nandemulator.c:1.2	Sun Mar 27 13:33:04 2011
+++ src/sys/dev/nand/nandemulator.c	Sun Apr 10 10:56:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nandemulator.c,v 1.2 2011/03/27 13:33:04 ahoka Exp $	*/
+/*	$NetBSD: nandemulator.c,v 1.3 2011/04/10 10:56:37 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.2 2011/03/27 13:33:04 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nandemulator.c,v 1.3 2011/04/10 10:56:37 ahoka Exp $);
 
 #include sys/param.h
 #include sys/device.h
@@ -306,6 +306,8 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	DPRINTF((device reset\n));
+
 	sc-sc_command = 0;
 	sc-sc_register_writable = false;
 	sc-sc_io_len = 0;
@@ -321,6 +323,9 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 	size_t page, offset;
+
+	KASSERT(sc-sc_address_counter ==
+	sc-sc_column_cycles + sc-sc_row_cycles);
 	
 	if (sc-sc_address_counter !=
 	sc-sc_column_cycles + sc-sc_row_cycles) {
@@ -337,6 +342,8 @@
 		(uintmax_t )page,
 		(uintmax_t )offset));
 
+	KASSERT(offset  sc-sc_device_size);
+
 	if (offset = sc-sc_device_size) {
 		aprint_error_dev(self, address  device size!\n);
 		sc-sc_io_len = 0;
@@ -400,6 +407,8 @@
 		KASSERT(offset %
 		(sc-sc_block_size * sc-sc_page_size) == 0);
 
+		KASSERT(offset  sc-sc_device_size);
+
 		if (offset = sc-sc_device_size) {
 			aprint_error_dev(self, address  device size!\n);
 		} else {
@@ -423,6 +432,7 @@
 	default:
 		aprint_error_dev(self,
 		invalid nand command (0x%hhx)\n, command);
+		KASSERT(false);
 		sc-sc_io_len = 0;
 	}
 };
@@ -432,6 +442,8 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	DPRINTF((nandemulator_address: %hhx\n, address));
+
 	/**
 	 * we have to handle read id/parameter page here,
 	 * as we can read right after giving the address.
@@ -497,6 +509,8 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	KASSERT(sc-sc_io_len  0);
+
 	if (sc-sc_io_len  0) {
 		*data = *sc-sc_io_pointer;
 
@@ -513,12 +527,16 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	KASSERT(sc-sc_register_writable);
+
 	if (!sc-sc_register_writable) {
 		aprint_error_dev(self,
 		trying to write read only location without effect\n);
 		return;
 	}
 
+	KASSERT(sc-sc_io_len  0);
+
 	if (sc-sc_io_len  0) {
 		*sc-sc_io_pointer = data;
 
@@ -534,12 +552,16 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	KASSERT(sc-sc_buswidth == NANDEMULATOR_16BIT);
+
 	if (sc-sc_buswidth != NANDEMULATOR_16BIT) {
 		aprint_error_dev(self,
 		trying to read a word on an 8bit chip\n);
 		return;
 	}
 
+	KASSERT(sc-sc_io_len  1);
+
 	if (sc-sc_io_len  1) {
 		*data = *(uint16_t *)sc-sc_io_pointer;
 
@@ -556,18 +578,24 @@
 {
 	struct nandemulator_softc *sc = device_private(self);
 
+	KASSERT(sc-sc_register_writable);
+
 	if (!sc-sc_register_writable) {
 		aprint_error_dev(self,
 		trying to write read only location without effect\n);
 		return;
 	}
 
+	KASSERT(sc-sc_buswidth == NANDEMULATOR_16BIT);
+
 	if (sc-sc_buswidth != NANDEMULATOR_16BIT) {
 		aprint_error_dev(self,
 		trying to write a word to an 8bit chip);
 		return;
 	}
 
+	KASSERT(sc-sc_io_len  1);
+
 	if (sc-sc_io_len  1) {
 		*(uint16_t *)sc-sc_io_pointer = data;
 



CVS commit: src/sys/dev/nand

2011-03-27 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Sun Mar 27 13:33:04 UTC 2011

Modified Files:
src/sys/dev/nand: files.nand nand.c nand.h nandemulator.c

Log Message:
Add support for redifining page read and program functions by drivers.
Some controllers implement read/write in one step, so this is required
to support those.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/files.nand
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/nand/nand.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nand.h
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/nandemulator.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/files.nand
diff -u src/sys/dev/nand/files.nand:1.2 src/sys/dev/nand/files.nand:1.3
--- src/sys/dev/nand/files.nand:1.2	Wed Mar  9 10:05:08 2011
+++ src/sys/dev/nand/files.nand	Sun Mar 27 13:33:04 2011
@@ -1,4 +1,4 @@
-# $NetBSD: files.nand,v 1.2 2011/03/09 10:05:08 ahoka Exp $
+# $NetBSD: files.nand,v 1.3 2011/03/27 13:33:04 ahoka Exp $
 
 define	nandbus	{ }
 
@@ -15,3 +15,5 @@
 file	dev/nand/nandemulator.c	nandemulator
 
 defflag opt_nand.h		NAND_BBT
+defflag opt_nand.h		NAND_DEBUG
+defflag opt_nand.h		NAND_VERBOSE

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.5 src/sys/dev/nand/nand.c:1.6
--- src/sys/dev/nand/nand.c:1.5	Wed Mar  9 12:33:59 2011
+++ src/sys/dev/nand/nand.c	Sun Mar 27 13:33:04 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.5 2011/03/09 12:33:59 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.6 2011/03/27 13:33:04 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.5 2011/03/09 12:33:59 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.6 2011/03/27 13:33:04 ahoka Exp $);
 
 #include locators.h
 
@@ -63,9 +63,7 @@
 static int nand_search(device_t, cfdata_t, const int *, void *);
 static void nand_address_row(device_t, size_t);
 static void nand_address_column(device_t, size_t, size_t);
-static void nand_readid(device_t, struct nand_chip *);
-static void nand_read_parameter_page(device_t, struct nand_chip *);
-static const char *nand_midtoname(int);
+static int nand_fill_chip_structure(device_t, struct nand_chip *);
 static int nand_scan_media(device_t, struct nand_chip *);
 static bool nand_check_wp(device_t);
 
@@ -79,6 +77,7 @@
 int nand_cachesync_timeout = 1;
 int nand_cachesync_nodenum;
 
+#ifdef NAND_VERBOSE
 const struct nand_manufacturer nand_mfrs[] = {
 	{ NAND_MFR_AMD,		AMD },
 	{ NAND_MFR_FUJITSU,	Fujitsu },
@@ -92,6 +91,22 @@
 	{ NAND_MFR_UNKNOWN,	Unknown }
 };
 
+static const char *
+nand_midtoname(int id)
+{
+	int i;
+
+	for (i = 0; nand_mfrs[i].id != 0; i++) {
+		if (nand_mfrs[i].id == id)
+			return nand_mfrs[i].name;
+	}
+
+	KASSERT(nand_mfrs[i].id == 0);
+
+	return nand_mfrs[i].name;
+}
+#endif
+
 /* ARGSUSED */
 int
 nand_match(device_t parent, cfdata_t match, void *aux)
@@ -108,7 +123,7 @@
 	struct nand_chip *chip = sc-sc_chip;
 
 	sc-sc_dev = self;
-	sc-nand_dev = parent;
+	sc-controller_dev = parent;
 	sc-nand_if = naa-naa_nand_if;
 
 	aprint_naive(\n);
@@ -238,6 +253,7 @@
 	return UNCONF;
 }
 
+/* ask for a nand driver to attach to the controller */
 device_t
 nand_attach_mi(struct nand_interface *nand_if, device_t parent)
 {
@@ -245,23 +261,50 @@
 
 	KASSERT(nand_if != NULL);
 
+	/* fill the defaults if we have null pointers */
+	if (nand_if-program_page == NULL) {
+		nand_if-program_page = nand_default_program_page;
+	}
+
+	if (nand_if-read_page == NULL) {
+		nand_if-read_page = nand_default_read_page;
+	}
+
 	arg.naa_nand_if = nand_if;
 	return config_found_ia(parent, nandbus, arg, nand_print);
 }
 
-static const char *
-nand_midtoname(int id)
+/* default everything to reasonable values, to ease future api changes */
+void
+nand_init_interface(struct nand_interface *interface)
 {
-	int i;
-
-	for (i = 0; nand_mfrs[i].id != 0; i++) {
-		if (nand_mfrs[i].id == id)
-			return nand_mfrs[i].name;
-	}
-
-	KASSERT(nand_mfrs[i].id == 0);
+	interface-select = nand_default_select;
+	interface-command = NULL;
+	interface-address = NULL;
+	interface-read_buf_byte = NULL;
+	interface-read_buf_word = NULL;
+	interface-read_byte = NULL;
+	interface-read_word = NULL;
+	interface-write_buf_byte = NULL;
+	interface-write_buf_word = NULL;
+	interface-write_byte = NULL;
+	interface-write_word = NULL;
+	interface-busy = NULL;
+
+	/*-
+	 * most drivers dont want to change this, but some implement
+	 * read/program in one step
+	 */
+	interface-program_page = nand_default_program_page;
+	interface-read_page = nand_default_read_page;
 
-	return nand_mfrs[i].name;
+	/* default to soft ecc, that should work everywhere */
+	interface-ecc_compute = nand_default_ecc_compute;
+	interface-ecc_correct = nand_default_ecc_correct;
+	interface-ecc_prepare = NULL;
+	

CVS commit: src/sys/dev/nand

2011-03-18 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Fri Mar 18 16:46:04 UTC 2011

Modified Files:
src/sys/dev/nand: nand_micron.c

Log Message:
use %zu for size_t, also add rcsid


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nand_micron.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_micron.c
diff -u src/sys/dev/nand/nand_micron.c:1.2 src/sys/dev/nand/nand_micron.c:1.3
--- src/sys/dev/nand/nand_micron.c:1.2	Fri Mar 18 00:57:51 2011
+++ src/sys/dev/nand/nand_micron.c	Fri Mar 18 16:46:04 2011
@@ -1,3 +1,4 @@
+/*	$NetBSD: nand_micron.c,v 1.3 2011/03/18 16:46:04 ahoka Exp $	*/
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
  *		  University of Szeged, Hungary
@@ -154,7 +155,7 @@
 	chip-nc_size = MT29FxG_PAGESIZE * MT29FxG_BLOCK_PAGES *
 		dp-lun_blocks * dp-num_luns;
 
-	aprint_normal_dev(self, %s %s, size %ldMB\n,
+	aprint_normal_dev(self, %s %s, size %zuMB\n,
 		vendor, dp-name, chip-nc_size  20);
 
 	return 0;



CVS commit: src/sys/dev/nand

2011-03-17 Thread Cliff Neighbors
Module Name:src
Committed By:   cliff
Date:   Fri Mar 18 00:57:51 UTC 2011

Modified Files:
src/sys/dev/nand: nand_micron.c

Log Message:
- add suport for MT29FxGx family devices


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/nand_micron.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand_micron.c
diff -u src/sys/dev/nand/nand_micron.c:1.1 src/sys/dev/nand/nand_micron.c:1.2
--- src/sys/dev/nand/nand_micron.c:1.1	Wed Mar  9 10:05:08 2011
+++ src/sys/dev/nand/nand_micron.c	Fri Mar 18 00:57:51 2011
@@ -39,39 +39,123 @@
 #include nand.h
 #include onfi.h
 
+#define MT29F2G08AAC	0xda
+#define MT29F2G08ABC	0xaa
+#define MT29F2G16AAC	0xca
+#define MT29F2G16ABC	0xba
+#define MT29F4G08BAC	0xdc
+#define MT29F8G08FAC	0xdc		/* each 4GB section */
+
+#define MT29FxG_PARAM_WIDTH(p)		(((p)  1)  __BIT(0))
+#define MT29FxG_PAGESIZE		(2 * 1024)
+#define MT29FxG_BLOCK_PAGES		64		/* pages per block */
+#define MT29FxG_BLOCKSIZE		(128 * 1024)	/* not including spares */
+#define MT29FxG_SPARESIZE		64
+
+struct nand_micron_devices {
+	const char *name;
+	uint8_t	id;
+	uint8_t width;			/* bus width */
+	u_int lun_blocks;		/* number of blocks per LUN */
+	u_int num_luns;			/* number LUNs */
+};
+
+static const struct nand_micron_devices nand_micron_devices[] = {
+	{ MT29F2G08AAC, MT29F2G08AAC,  8,  2048, 1 },
+	{ MT29F2G08ABC, MT29F2G08ABC,  8,  2048, 1 },
+	{ MT29F2G16AAC, MT29F2G16AAC, 16,  2048, 1 },
+	{ MT29F2G16ABC, MT29F2G16ABC, 16,  2048, 1 },
+	{ MT29F4G08BAC, MT29F4G08BAC,  8,  4096, 1 },
+#ifdef NOTYET
+	/* how do we recognize/match this? */
+	{ MT29F8G08FAC, MT29F8G08FAC,  8,  4096, 2 },
+#endif
+};
+
+static int mt29fxgx_parameters(device_t, struct nand_chip *, u_int8_t, uint8_t);
+
+static const struct nand_micron_devices *
+nand_micron_device_lookup(u_int8_t id)
+{
+	for (int i=0; i  __arraycount(nand_micron_devices); i++)
+		if (nand_micron_devices[i].id == id)
+			return nand_micron_devices[i];
+	return NULL;
+}
+
 int
 nand_read_parameters_micron(device_t self, struct nand_chip *chip)
 {
-	uint8_t byte;
+	uint8_t mfgrid;
+	uint8_t devid;
+	uint8_t dontcare;
+	uint8_t params;
 
 	KASSERT(chip-nc_manf_id == NAND_MFR_MICRON);
+	switch (chip-nc_manf_id) {
+	case NAND_MFR_MICRON:
+		break;
+	default:
+		return 1;
+	}
 
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x00);
+	nand_read_byte(self, mfgrid);
+	nand_read_byte(self, devid);
+	nand_read_byte(self, dontcare);
+	nand_read_byte(self, params);
+	nand_select(self, false);
 
-	switch (chip-nc_manf_id) {
-		/* three dummy reads */
-		nand_read_byte(self, byte); /* vendor */
-		nand_read_byte(self, byte); /* device */
-		nand_read_byte(self, byte); /* unused */
-
-		/* this is the interesting one */
-		nand_read_byte(self, byte);
-		/* TODO actually get info */
-		nand_select(self, false);
-		return 1;
-		
-		break;
+	KASSERT(chip-nc_manf_id == mfgrid);
+
+	switch(devid) {
+	case MT29F2G08AAC:
+	case MT29F2G08ABC:
+	case MT29F2G16AAC:
+	case MT29F2G16ABC:
+	case MT29F4G08BAC:
+		return mt29fxgx_parameters(self, chip, devid, params);
 	default:
-		nand_select(self, false);
+		aprint_error_dev(self, unsupported device id %#x\n, devid);
 		return 1;
 	}
-	
-	chip-nc_num_luns = 1;
-	chip-nc_lun_blocks = chip-nc_size / chip-nc_block_size;
+}
 
-	nand_select(self, false);
+static int
+mt29fxgx_parameters(device_t self, struct nand_chip *chip,
+	u_int8_t devid, uint8_t params)
+{
+	const struct nand_micron_devices *dp;
+	const char *vendor = Micron;
+
+	dp = nand_micron_device_lookup(devid);
+	if (dp == NULL) {
+		aprint_error_dev(self, unknown device id %#x\n, devid); 
+		return 1;
+	}
+
+	/*
+	 * MT29FxGx params across models are the same
+	 * except for luns, blocks per lun, and bus width
+	 * (and voltage)
+	 */
+	chip-nc_addr_cycles_column = 2;	/* XXX */
+	chip-nc_addr_cycles_row = 3;		/* XXX */
+	if (dp-width == 16)
+		chip-nc_flags |= NC_BUSWIDTH_16;
+	chip-nc_page_size = MT29FxG_PAGESIZE;
+	chip-nc_block_pages = MT29FxG_BLOCK_PAGES;
+	chip-nc_block_size = MT29FxG_BLOCK_PAGES * MT29FxG_PAGESIZE;
+	chip-nc_spare_size = MT29FxG_SPARESIZE;
+	chip-nc_lun_blocks = dp-lun_blocks;
+	chip-nc_num_luns = dp-num_luns;
+	chip-nc_size = MT29FxG_PAGESIZE * MT29FxG_BLOCK_PAGES *
+		dp-lun_blocks * dp-num_luns;
+
+	aprint_normal_dev(self, %s %s, size %ldMB\n,
+		vendor, dp-name, chip-nc_size  20);
 
 	return 0;
 }



CVS commit: src/sys/dev/nand

2011-03-09 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Wed Mar  9 10:05:08 UTC 2011

Modified Files:
src/sys/dev/nand: files.nand nand.c nand.h
Added Files:
src/sys/dev/nand: nand_micron.c

Log Message:
Add support for legacy devices not supporting the ONFI READ_PARAMETER_PAGE
command with example usage for Micron chips


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/files.nand
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nand.c src/sys/dev/nand/nand.h
cvs rdiff -u -r0 -r1.1 src/sys/dev/nand/nand_micron.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/files.nand
diff -u src/sys/dev/nand/files.nand:1.1 src/sys/dev/nand/files.nand:1.2
--- src/sys/dev/nand/files.nand:1.1	Sat Feb 26 18:07:31 2011
+++ src/sys/dev/nand/files.nand	Wed Mar  9 10:05:08 2011
@@ -1,4 +1,4 @@
-# $NetBSD: files.nand,v 1.1 2011/02/26 18:07:31 ahoka Exp $
+# $NetBSD: files.nand,v 1.2 2011/03/09 10:05:08 ahoka Exp $
 
 define	nandbus	{ }
 
@@ -9,6 +9,7 @@
 file	dev/nand/hamming.c	nand
 file	dev/nand/nand_bbt.c	nand
 file	dev/nand/nand_crc.c	nand
+file	dev/nand/nand_micron.c	nand
 
 defpseudodev	nandemulator: nandbus
 file	dev/nand/nandemulator.c	nandemulator

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.2 src/sys/dev/nand/nand.c:1.3
--- src/sys/dev/nand/nand.c:1.2	Wed Mar  9 07:49:15 2011
+++ src/sys/dev/nand/nand.c	Wed Mar  9 10:05:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.2 2011/03/09 07:49:15 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.3 2011/03/09 10:05:08 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.2 2011/03/09 07:49:15 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.3 2011/03/09 10:05:08 ahoka Exp $);
 
 #include locators.h
 
@@ -117,8 +117,10 @@
 		aprint_error(NAND chip is write protected!\n);
 		return;
 	}
-	if (nand_scan_media(self, chip))
+	
+	if (nand_scan_media(self, chip)) {
 		return;
+	}
 
 	/* allocate cache */
 	chip-nc_oob_cache = kmem_alloc(chip-nc_spare_size, KM_SLEEP);
@@ -281,6 +283,19 @@
 }
 #endif
 
+static int
+nand_read_legacy_parameters(device_t self, struct nand_chip *chip)
+{
+	switch (chip-nc_manf_id) {
+	case NAND_MFR_MICRON:
+		return nand_read_parameters_micron(self, chip);
+	default:
+		return 1;
+	}
+	
+	return 0;
+}
+
 /**
  * scan media to determine the chip's properties
  * this function resets the device
@@ -296,6 +311,7 @@
 	nand_command(self, ONFI_RESET);
 	nand_select(self, false);
 
+	/* check if the device implements the ONFI standard */
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x20);
@@ -307,24 +323,48 @@
 
 	if (onfi_signature[0] != 'O' || onfi_signature[1] != 'N' ||
 	onfi_signature[2] != 'F' || onfi_signature[3] != 'I') {
-		aprint_error_dev(self,
-		device does not support the ONFI specification\n);
+		chip-nc_isonfi = false;
+		
+		aprint_normal(: Legacy NAND Flash\n);
+		
+		nand_readid(self, chip);
 
-		return 1;
-	}
+		if (nand_read_legacy_parameters(self, chip)) {
+			aprint_error_dev(self,
+			can't read device parameters for legacy chip\n);
+			return 1;
+		}
+	} else {
+		chip-nc_isonfi = true;
 
-	nand_readid(self, chip);
+		aprint_normal(: ONFI NAND Flash\n);
 
-	aprint_normal(: NAND Flash\n);
+		nand_readid(self, chip);
+		nand_read_parameter_page(self, chip);
+	}
 
-	aprint_debug_dev(self,
+#ifdef NAND_VERBOSE
+	aprint_normal_dev(self,
 	manufacturer id: 0x%.2x (%s), device id: 0x%.2x\n,
 	chip-nc_manf_id,
 	nand_midtoname(chip-nc_manf_id),
 	chip-nc_dev_id);
+#endif
 
-	nand_read_parameter_page(self, chip);
+	aprint_normal_dev(self,
+	   page size: %u bytes, spare size: %u bytes, block size: %u bytes\n,
+	chip-nc_page_size, chip-nc_spare_size, chip-nc_block_size);
+
+	aprint_normal_dev(self,
+	LUN size: %u blocks, LUNs: %u, total storage size: %u MB\n,
+	chip-nc_lun_blocks, chip-nc_num_luns,
+	chip-nc_size / 1024 / 1024);
 
+#ifdef NAND_VERBOSE
+	aprint_normal_dev(self, column cycles: %d, row cycles: %d\n,
+	chip-nc_addr_cycles_column, chip-nc_addr_cycles_row);
+#endif
+		
 	ecc = chip-nc_ecc = sc-nand_if-ecc;
 
 	/*
@@ -388,12 +428,13 @@
 	nand_select(self, true);
 	nand_command(self, ONFI_READ_ID);
 	nand_address(self, 0x00);
+	
 	nand_read_byte(self, chip-nc_manf_id);
 	nand_read_byte(self, chip-nc_dev_id);
+	
 	nand_select(self, false);
 }
 
-/* read the parameter page. TODO: check CRC! */
 static void
 nand_read_parameter_page(device_t self, struct nand_chip *chip)
 {
@@ -435,20 +476,10 @@
 
 	aprint_normal_dev(self, vendor: %s, model: %s\n, vendor, model);
 
-	aprint_normal_dev(self,
-	   page size: %u bytes, spare size: %u bytes, block size: %u bytes\n,
-	params.param_pagesize, params.param_sparesize,
-	

CVS commit: src/sys/dev/nand

2011-03-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Mar  9 12:13:42 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Use %zu for size_t


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.3 src/sys/dev/nand/nand.c:1.4
--- src/sys/dev/nand/nand.c:1.3	Wed Mar  9 10:05:08 2011
+++ src/sys/dev/nand/nand.c	Wed Mar  9 12:13:42 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.3 2011/03/09 10:05:08 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.4 2011/03/09 12:13:42 martin Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.3 2011/03/09 10:05:08 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.4 2011/03/09 12:13:42 martin Exp $);
 
 #include locators.h
 
@@ -352,11 +352,11 @@
 #endif
 
 	aprint_normal_dev(self,
-	   page size: %u bytes, spare size: %u bytes, block size: %u bytes\n,
+	   page size: %zu bytes, spare size: %zu bytes, block size: %zu bytes\n,
 	chip-nc_page_size, chip-nc_spare_size, chip-nc_block_size);
 
 	aprint_normal_dev(self,
-	LUN size: %u blocks, LUNs: %u, total storage size: %u MB\n,
+	LUN size: %u blocks, LUNs: %u, total storage size: %zu MB\n,
 	chip-nc_lun_blocks, chip-nc_num_luns,
 	chip-nc_size / 1024 / 1024);
 



CVS commit: src/sys/dev/nand

2011-03-09 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Wed Mar  9 12:33:59 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
Add some PRIxxx macros to correctly print stdint types


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.4 src/sys/dev/nand/nand.c:1.5
--- src/sys/dev/nand/nand.c:1.4	Wed Mar  9 12:13:42 2011
+++ src/sys/dev/nand/nand.c	Wed Mar  9 12:33:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.4 2011/03/09 12:13:42 martin Exp $	*/
+/*	$NetBSD: nand.c,v 1.5 2011/03/09 12:33:59 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.4 2011/03/09 12:13:42 martin Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.5 2011/03/09 12:33:59 ahoka Exp $);
 
 #include locators.h
 
@@ -352,16 +352,19 @@
 #endif
 
 	aprint_normal_dev(self,
-	   page size: %zu bytes, spare size: %zu bytes, block size: %zu bytes\n,
+	page size: %zu bytes, spare size: %zu bytes, 
+	block size: %zu bytes\n,
 	chip-nc_page_size, chip-nc_spare_size, chip-nc_block_size);
 
 	aprint_normal_dev(self,
-	LUN size: %u blocks, LUNs: %u, total storage size: %zu MB\n,
+	LUN size: % PRIu32  blocks, LUNs: % PRIu8
+	, total storage size: %zu MB\n,
 	chip-nc_lun_blocks, chip-nc_num_luns,
 	chip-nc_size / 1024 / 1024);
 
 #ifdef NAND_VERBOSE
-	aprint_normal_dev(self, column cycles: %d, row cycles: %d\n,
+	aprint_normal_dev(self, column cycles: % PRIu8 , row cycles: %
+	PRIu8 \n,
 	chip-nc_addr_cycles_column, chip-nc_addr_cycles_row);
 #endif
 		



CVS commit: src/sys/dev/nand

2011-03-08 Thread Adam Hoka
Module Name:src
Committed By:   ahoka
Date:   Wed Mar  9 07:49:15 UTC 2011

Modified Files:
src/sys/dev/nand: nand.c

Log Message:
cleanup comments, prototypes
remove unused leftover debug code


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/nand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.c
diff -u src/sys/dev/nand/nand.c:1.1 src/sys/dev/nand/nand.c:1.2
--- src/sys/dev/nand/nand.c:1.1	Sat Feb 26 18:07:31 2011
+++ src/sys/dev/nand/nand.c	Wed Mar  9 07:49:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.c,v 1.1 2011/02/26 18:07:31 ahoka Exp $	*/
+/*	$NetBSD: nand.c,v 1.2 2011/03/09 07:49:15 ahoka Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -34,7 +34,7 @@
 /* Common driver for NAND chips implementing the ONFI 2.2 specification */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.1 2011/02/26 18:07:31 ahoka Exp $);
+__KERNEL_RCSID(0, $NetBSD: nand.c,v 1.2 2011/03/09 07:49:15 ahoka Exp $);
 
 #include locators.h
 
@@ -53,22 +53,21 @@
 
 #include opt_nand.h
 
-int nand_match(device_t parent, cfdata_t match, void *aux);
-void nand_attach(device_t parent, device_t self, void *aux);
-int nand_detach(device_t device, int flags);
-bool nand_shutdown(device_t self, int howto);
-
-int nand_print(void *aux, const char *pnp);
-
-static int nand_search(device_t parent, cfdata_t cf, const int *ldesc,
-void *aux);
-static void nand_address_row(device_t self, size_t row);
-static void nand_address_column(device_t self, size_t row, size_t column);
-static void nand_readid(device_t self, struct nand_chip *chip);
-static void nand_read_parameter_page(device_t self, struct nand_chip *chip);
-static const char *nand_midtoname(int id);
-static int nand_scan_media(device_t self, struct nand_chip *chip);
-static bool nand_check_wp(device_t self);
+int nand_match(device_t, cfdata_t, void *);
+void nand_attach(device_t, device_t, void *);
+int nand_detach(device_t, int);
+bool nand_shutdown(device_t, int);
+
+int nand_print(void *, const char *);
+
+static int nand_search(device_t, cfdata_t, const int *, void *);
+static void nand_address_row(device_t, size_t);
+static void nand_address_column(device_t, size_t, size_t);
+static void nand_readid(device_t, struct nand_chip *);
+static void nand_read_parameter_page(device_t, struct nand_chip *);
+static const char *nand_midtoname(int);
+static int nand_scan_media(device_t, struct nand_chip *);
+static bool nand_check_wp(device_t);
 
 CFATTACH_DECL_NEW(nand, sizeof(struct nand_softc),
 nand_match, nand_attach, nand_detach, NULL);
@@ -107,17 +106,12 @@
 	struct nand_softc *sc = device_private(self);
 	struct nand_attach_args *naa = aux;
 	struct nand_chip *chip = sc-sc_chip;
-//	struct flash_interface *flash_if;
-//	int i;
 
 	sc-sc_dev = self;
 	sc-nand_dev = parent;
 	sc-nand_if = naa-naa_nand_if;
 
-//	sc-nand_softc = device_private(parent);
-
 	aprint_naive(\n);
-//	aprint_normal(: NAND flash memory\n);
 
 	if (nand_check_wp(self)) {
 		aprint_error(NAND chip is write protected!\n);
@@ -500,7 +494,6 @@
 
 	/* XXX TODO */
 	row = chip-nc_page_shift;
-//	DPRINTF((row address is: 0x%jx\n, (uintmax_t )row));
 
 	/* Write the column (subpage) address */
 	if (chip-nc_flags  NC_BUSWIDTH_16)
@@ -520,8 +513,6 @@
 	struct nand_chip *chip = sc-sc_chip;
 	off_t i;
 
-//	DPRINTF((addressing row: %zu\n, row));
-
 	/* XXX TODO */
 	row = chip-nc_page_shift;
 
@@ -571,8 +562,6 @@
 	uint8_t *ecc;
 	int result;
 
-	DPRINTF((nand read page\n));
-
 	nand_prepare_read(self, offset, 0);
 
 	bs = chip-nc_ecc-necc_block_size;
@@ -595,7 +584,10 @@
 		}
 	}
 
-//	nand_dump_data(page, data, chip-nc_page_size);
+	/* for debugging new drivers */
+#if 0
+	nand_dump_data(page, data, chip-nc_page_size);
+#endif
 
 	nand_read_oob(self, offset, chip-nc_oob_cache);
 	ecc = chip-nc_oob_cache + chip-nc_ecc-necc_offset;
@@ -693,6 +685,7 @@
 
 	nand_busy(self);
 
+	/* for debugging ecc */
 #if 0
 	printf(dumping ecc %d\n--\n, chip-nc_ecc-necc_steps);
 	for (e = 0; e  chip-nc_ecc-necc_steps; e++) {
@@ -728,7 +721,10 @@
 	else
 		nand_read_buf_byte(self, oob, chip-nc_spare_size);
 
-//	nand_dump_data(oob, oob, chip-nc_spare_size);
+	/* for debugging drivers */
+#if 0
+	nand_dump_data(oob, oob, chip-nc_spare_size);
+#endif
 
 	return 0;
 }
@@ -888,8 +884,6 @@
 int
 nand_erase_block(device_t self, size_t offset)
 {
-//	struct nand_softc *sc = device_private(self);
-//	struct nand_chip *chip = sc-sc_chip;
 	uint8_t status;
 
 	/* xxx calculate first page of block for address? */
@@ -953,9 +947,6 @@
 	size_t left, count;
 	int error, i;
 
-	/* to debug chfs */
-//	printf(unaligned write to nand\n);
-
 	first = offset  chip-nc_page_mask;
 	firstoff = offset  ~chip-nc_page_mask;
 	/* XXX check if this should be len - 1 */
@@ -1131,13 +1122,9 @@
 	size_t left;
 	int error = 0, i;
 
-	/* to debug chfs */

CVS commit: src/sys/dev/nand

2011-03-04 Thread Jukka Ruohonen
Module Name:src
Committed By:   jruoho
Date:   Sat Mar  5 06:28:29 UTC 2011

Modified Files:
src/sys/dev/nand: nand.h

Log Message:
KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/nand/nand.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/nand/nand.h
diff -u src/sys/dev/nand/nand.h:1.1 src/sys/dev/nand/nand.h:1.2
--- src/sys/dev/nand/nand.h:1.1	Sat Feb 26 18:07:31 2011
+++ src/sys/dev/nand/nand.h	Sat Mar  5 06:28:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: nand.h,v 1.1 2011/02/26 18:07:31 ahoka Exp $	*/
+/*	$NetBSD: nand.h,v 1.2 2011/03/05 06:28:29 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2010 Department of Software Engineering,
@@ -453,9 +453,11 @@
 static inline void
 nand_dump_data(const char *name, void *data, size_t len)
 {
-	printf(dumping %s\n--\n, name);
 	uint8_t *dump = data;
-	for (int i = 0; i  len; i++) {
+	int i;
+
+	printf(dumping %s\n--\n, name);
+	for (i = 0; i  len; i++) {
 		printf(0x%.2hhx , *dump);
 		dump++;
 	}