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