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