Home | History | Annotate | Line # | Download | only in nand
nand_micron.c revision 1.4.4.2
      1  1.4.4.2  jruoho /*	$NetBSD: nand_micron.c,v 1.4.4.2 2011/06/06 09:08:08 jruoho Exp $	*/
      2  1.4.4.2  jruoho 
      3  1.4.4.2  jruoho /*-
      4  1.4.4.2  jruoho  * Copyright (c) 2011 Department of Software Engineering,
      5  1.4.4.2  jruoho  *		      University of Szeged, Hungary
      6  1.4.4.2  jruoho  * Copyright (c) 2011 Adam Hoka <ahoka (at) NetBSD.org>
      7  1.4.4.2  jruoho  * All rights reserved.
      8  1.4.4.2  jruoho  *
      9  1.4.4.2  jruoho  * This code is derived from software contributed to The NetBSD Foundation
     10  1.4.4.2  jruoho  * by the Department of Software Engineering, University of Szeged, Hungary
     11  1.4.4.2  jruoho  *
     12  1.4.4.2  jruoho  * Redistribution and use in source and binary forms, with or without
     13  1.4.4.2  jruoho  * modification, are permitted provided that the following conditions
     14  1.4.4.2  jruoho  * are met:
     15  1.4.4.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     16  1.4.4.2  jruoho  *    notice, this list of conditions and the following disclaimer.
     17  1.4.4.2  jruoho  * 2. Redistributions in binary form must reproduce the above copyright
     18  1.4.4.2  jruoho  *    notice, this list of conditions and the following disclaimer in the
     19  1.4.4.2  jruoho  *    documentation and/or other materials provided with the distribution.
     20  1.4.4.2  jruoho  *
     21  1.4.4.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.4.4.2  jruoho  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.4.4.2  jruoho  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.4.4.2  jruoho  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.4.4.2  jruoho  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     26  1.4.4.2  jruoho  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27  1.4.4.2  jruoho  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     28  1.4.4.2  jruoho  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     29  1.4.4.2  jruoho  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.4.4.2  jruoho  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.4.4.2  jruoho  * SUCH DAMAGE.
     32  1.4.4.2  jruoho  */
     33  1.4.4.2  jruoho 
     34  1.4.4.2  jruoho /*
     35  1.4.4.2  jruoho  * Device specific functions for legacy Micron NAND chips
     36  1.4.4.2  jruoho  *
     37  1.4.4.2  jruoho  * Currently supported:
     38  1.4.4.2  jruoho  * MT29F2G08AACWP, MT29F4G08BACWP, MT29F8G08FACWP
     39  1.4.4.2  jruoho  */
     40  1.4.4.2  jruoho 
     41  1.4.4.2  jruoho #include <sys/cdefs.h>
     42  1.4.4.2  jruoho __KERNEL_RCSID(0, "$NetBSD: nand_micron.c,v 1.4.4.2 2011/06/06 09:08:08 jruoho Exp $");
     43  1.4.4.2  jruoho 
     44  1.4.4.2  jruoho #include "nand.h"
     45  1.4.4.2  jruoho #include "onfi.h"
     46  1.4.4.2  jruoho 
     47  1.4.4.2  jruoho #define MT29F2G08AAC	0xda
     48  1.4.4.2  jruoho #define MT29F2G08ABC	0xaa
     49  1.4.4.2  jruoho #define MT29F2G16AAC	0xca
     50  1.4.4.2  jruoho #define MT29F2G16ABC	0xba
     51  1.4.4.2  jruoho #define MT29F4G08BAC	0xdc
     52  1.4.4.2  jruoho #define MT29F8G08FAC	0xdc		/* each 4GB section */
     53  1.4.4.2  jruoho 
     54  1.4.4.2  jruoho #define MT29FxG_PARAM_WIDTH(p)		(((p) >> 1) & __BIT(0))
     55  1.4.4.2  jruoho #define MT29FxG_PAGESIZE		(2 * 1024)
     56  1.4.4.2  jruoho #define MT29FxG_BLOCK_PAGES		64		/* pages per block */
     57  1.4.4.2  jruoho #define MT29FxG_BLOCKSIZE		(128 * 1024)	/* not including spares */
     58  1.4.4.2  jruoho #define MT29FxG_SPARESIZE		64
     59  1.4.4.2  jruoho 
     60  1.4.4.2  jruoho struct nand_micron_devices {
     61  1.4.4.2  jruoho 	const char *name;
     62  1.4.4.2  jruoho 	uint8_t	id;
     63  1.4.4.2  jruoho 	uint8_t width;			/* bus width */
     64  1.4.4.2  jruoho 	u_int lun_blocks;		/* number of blocks per LUN */
     65  1.4.4.2  jruoho 	u_int num_luns;			/* number LUNs */
     66  1.4.4.2  jruoho };
     67  1.4.4.2  jruoho 
     68  1.4.4.2  jruoho static const struct nand_micron_devices nand_micron_devices[] = {
     69  1.4.4.2  jruoho 	{ "MT29F2G08AAC", MT29F2G08AAC,  8,  2048, 1 },
     70  1.4.4.2  jruoho 	{ "MT29F2G08ABC", MT29F2G08ABC,  8,  2048, 1 },
     71  1.4.4.2  jruoho 	{ "MT29F2G16AAC", MT29F2G16AAC, 16,  2048, 1 },
     72  1.4.4.2  jruoho 	{ "MT29F2G16ABC", MT29F2G16ABC, 16,  2048, 1 },
     73  1.4.4.2  jruoho 	{ "MT29F4G08BAC", MT29F4G08BAC,  8,  4096, 1 },
     74  1.4.4.2  jruoho #ifdef NOTYET
     75  1.4.4.2  jruoho 	/* how do we recognize/match this? */
     76  1.4.4.2  jruoho 	{ "MT29F8G08FAC", MT29F8G08FAC,  8,  4096, 2 },
     77  1.4.4.2  jruoho #endif
     78  1.4.4.2  jruoho };
     79  1.4.4.2  jruoho 
     80  1.4.4.2  jruoho static int mt29fxgx_parameters(device_t, struct nand_chip *, u_int8_t, uint8_t);
     81  1.4.4.2  jruoho 
     82  1.4.4.2  jruoho static const struct nand_micron_devices *
     83  1.4.4.2  jruoho nand_micron_device_lookup(u_int8_t id)
     84  1.4.4.2  jruoho {
     85  1.4.4.2  jruoho 	for (int i=0; i < __arraycount(nand_micron_devices); i++)
     86  1.4.4.2  jruoho 		if (nand_micron_devices[i].id == id)
     87  1.4.4.2  jruoho 			return &nand_micron_devices[i];
     88  1.4.4.2  jruoho 	return NULL;
     89  1.4.4.2  jruoho }
     90  1.4.4.2  jruoho 
     91  1.4.4.2  jruoho int
     92  1.4.4.2  jruoho nand_read_parameters_micron(device_t self, struct nand_chip *chip)
     93  1.4.4.2  jruoho {
     94  1.4.4.2  jruoho 	uint8_t mfgrid;
     95  1.4.4.2  jruoho 	uint8_t devid;
     96  1.4.4.2  jruoho 	uint8_t dontcare;
     97  1.4.4.2  jruoho 	uint8_t params;
     98  1.4.4.2  jruoho 
     99  1.4.4.2  jruoho 	KASSERT(chip->nc_manf_id == NAND_MFR_MICRON);
    100  1.4.4.2  jruoho 	switch (chip->nc_manf_id) {
    101  1.4.4.2  jruoho 	case NAND_MFR_MICRON:
    102  1.4.4.2  jruoho 		break;
    103  1.4.4.2  jruoho 	default:
    104  1.4.4.2  jruoho 		return 1;
    105  1.4.4.2  jruoho 	}
    106  1.4.4.2  jruoho 
    107  1.4.4.2  jruoho 	nand_select(self, true);
    108  1.4.4.2  jruoho 	nand_command(self, ONFI_READ_ID);
    109  1.4.4.2  jruoho 	nand_address(self, 0x00);
    110  1.4.4.2  jruoho 	nand_read_byte(self, &mfgrid);
    111  1.4.4.2  jruoho 	nand_read_byte(self, &devid);
    112  1.4.4.2  jruoho 	nand_read_byte(self, &dontcare);
    113  1.4.4.2  jruoho 	nand_read_byte(self, &params);
    114  1.4.4.2  jruoho 	nand_select(self, false);
    115  1.4.4.2  jruoho 
    116  1.4.4.2  jruoho 	KASSERT(chip->nc_manf_id == mfgrid);
    117  1.4.4.2  jruoho 
    118  1.4.4.2  jruoho 	switch(devid) {
    119  1.4.4.2  jruoho 	case MT29F2G08AAC:
    120  1.4.4.2  jruoho 	case MT29F2G08ABC:
    121  1.4.4.2  jruoho 	case MT29F2G16AAC:
    122  1.4.4.2  jruoho 	case MT29F2G16ABC:
    123  1.4.4.2  jruoho 	case MT29F4G08BAC:
    124  1.4.4.2  jruoho 		return mt29fxgx_parameters(self, chip, devid, params);
    125  1.4.4.2  jruoho 	default:
    126  1.4.4.2  jruoho 		aprint_error_dev(self, "unsupported device id %#x\n", devid);
    127  1.4.4.2  jruoho 		return 1;
    128  1.4.4.2  jruoho 	}
    129  1.4.4.2  jruoho }
    130  1.4.4.2  jruoho 
    131  1.4.4.2  jruoho static int
    132  1.4.4.2  jruoho mt29fxgx_parameters(device_t self, struct nand_chip *chip,
    133  1.4.4.2  jruoho 	u_int8_t devid, uint8_t params)
    134  1.4.4.2  jruoho {
    135  1.4.4.2  jruoho 	const struct nand_micron_devices *dp;
    136  1.4.4.2  jruoho 	const char *vendor = "Micron";
    137  1.4.4.2  jruoho 
    138  1.4.4.2  jruoho 	dp = nand_micron_device_lookup(devid);
    139  1.4.4.2  jruoho 	if (dp == NULL) {
    140  1.4.4.2  jruoho 		aprint_error_dev(self, "unknown device id %#x\n", devid);
    141  1.4.4.2  jruoho 		return 1;
    142  1.4.4.2  jruoho 	}
    143  1.4.4.2  jruoho 
    144  1.4.4.2  jruoho 	/*
    145  1.4.4.2  jruoho 	 * MT29FxGx params across models are the same
    146  1.4.4.2  jruoho 	 * except for luns, blocks per lun, and bus width
    147  1.4.4.2  jruoho 	 * (and voltage)
    148  1.4.4.2  jruoho 	 */
    149  1.4.4.2  jruoho 	chip->nc_addr_cycles_column = 2;	/* XXX */
    150  1.4.4.2  jruoho 	chip->nc_addr_cycles_row = 3;		/* XXX */
    151  1.4.4.2  jruoho 	if (dp->width == 16)
    152  1.4.4.2  jruoho 		chip->nc_flags |= NC_BUSWIDTH_16;
    153  1.4.4.2  jruoho 	chip->nc_page_size = MT29FxG_PAGESIZE;
    154  1.4.4.2  jruoho 	chip->nc_block_pages = MT29FxG_BLOCK_PAGES;
    155  1.4.4.2  jruoho 	chip->nc_block_size = MT29FxG_BLOCK_PAGES * MT29FxG_PAGESIZE;
    156  1.4.4.2  jruoho 	chip->nc_spare_size = MT29FxG_SPARESIZE;
    157  1.4.4.2  jruoho 	chip->nc_lun_blocks = dp->lun_blocks;
    158  1.4.4.2  jruoho 	chip->nc_num_luns = dp->num_luns;
    159  1.4.4.2  jruoho 	chip->nc_size = MT29FxG_PAGESIZE * MT29FxG_BLOCK_PAGES *
    160  1.4.4.2  jruoho 		dp->lun_blocks * dp->num_luns;
    161  1.4.4.2  jruoho 
    162  1.4.4.2  jruoho 	aprint_normal_dev(self, "%s %s, size %zuMB\n",
    163  1.4.4.2  jruoho 		vendor, dp->name, chip->nc_size >> 20);
    164  1.4.4.2  jruoho 
    165  1.4.4.2  jruoho 	return 0;
    166  1.4.4.2  jruoho }
    167