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