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