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