nand_samsung.c revision 1.1 1 1.1 ahoka /* $NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $ */
2 1.1 ahoka
3 1.1 ahoka /*-
4 1.1 ahoka * Copyright (c) 2012 The NetBSD Foundation, Inc.
5 1.1 ahoka * All rights reserved.
6 1.1 ahoka *
7 1.1 ahoka * This code is derived from software contributed to The NetBSD Foundation
8 1.1 ahoka * by Adam Hoka.
9 1.1 ahoka *
10 1.1 ahoka * Redistribution and use in source and binary forms, with or without
11 1.1 ahoka * modification, are permitted provided that the following conditions
12 1.1 ahoka * are met:
13 1.1 ahoka * 1. Redistributions of source code must retain the above copyright
14 1.1 ahoka * notice, this list of conditions and the following disclaimer.
15 1.1 ahoka * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 ahoka * notice, this list of conditions and the following disclaimer in the
17 1.1 ahoka * documentation and/or other materials provided with the distribution.
18 1.1 ahoka *
19 1.1 ahoka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 ahoka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 ahoka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 ahoka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 ahoka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 ahoka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 ahoka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 ahoka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 ahoka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 ahoka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 ahoka * POSSIBILITY OF SUCH DAMAGE.
30 1.1 ahoka */
31 1.1 ahoka
32 1.1 ahoka /*
33 1.1 ahoka * Device specific functions for legacy Samsung NAND chips
34 1.1 ahoka *
35 1.1 ahoka * Currently supported:
36 1.1 ahoka * K9XXG08UXA
37 1.1 ahoka */
38 1.1 ahoka
39 1.1 ahoka #include <sys/cdefs.h>
40 1.1 ahoka __KERNEL_RCSID(0, "$NetBSD: nand_samsung.c,v 1.1 2012/10/30 22:03:00 ahoka Exp $");
41 1.1 ahoka
42 1.1 ahoka #include "nand.h"
43 1.1 ahoka #include "onfi.h"
44 1.1 ahoka
45 1.1 ahoka int
46 1.1 ahoka nand_read_parameters_samsung(device_t self, struct nand_chip * const chip)
47 1.1 ahoka {
48 1.1 ahoka uint8_t mfgrid;
49 1.1 ahoka uint8_t devid;
50 1.1 ahoka uint8_t dontcare1;
51 1.1 ahoka uint8_t dontcare2;
52 1.1 ahoka uint8_t params2;
53 1.1 ahoka
54 1.1 ahoka /* Only for Samsung devices, obviously */
55 1.1 ahoka if (chip->nc_manf_id != NAND_MFR_SAMSUNG) {
56 1.1 ahoka return 1;
57 1.1 ahoka }
58 1.1 ahoka
59 1.1 ahoka nand_select(self, true);
60 1.1 ahoka nand_command(self, ONFI_READ_ID);
61 1.1 ahoka nand_address(self, 0x00);
62 1.1 ahoka nand_read_1(self, &mfgrid);
63 1.1 ahoka nand_read_1(self, &devid);
64 1.1 ahoka nand_read_1(self, ¶ms1);
65 1.1 ahoka nand_read_1(self, ¶ms2);
66 1.1 ahoka nand_read_1(self, ¶ms3);
67 1.1 ahoka nand_select(self, false);
68 1.1 ahoka
69 1.1 ahoka enum {
70 1.1 ahoka NAND_SAMSUNG_PAGEMASK = 0x3,
71 1.1 ahoka NAND_SAMSUNG_BLOCKMASK = 0x3 << 4,
72 1.1 ahoka NAND_SAMSUNG_SPAREMASK = 0x1 << 2,
73 1.1 ahoka NAND_SAMSUNG_BITSMASK = 0x1 << 6
74 1.1 ahoka };
75 1.1 ahoka
76 1.1 ahoka /* K9XXG08UXA */
77 1.1 ahoka if (devid == 0xdc) {
78 1.1 ahoka switch (params2 & NAND_SAMSUNG_PAGEMASK) {
79 1.1 ahoka case 0x0:
80 1.1 ahoka chip->nc_page_size = 1024;
81 1.1 ahoka break;
82 1.1 ahoka case 0x1:
83 1.1 ahoka chip->nc_page_size = 2048;
84 1.1 ahoka break;
85 1.1 ahoka case 0x2:
86 1.1 ahoka chip->nc_page_size = 4096;
87 1.1 ahoka break;
88 1.1 ahoka case 0x3:
89 1.1 ahoka chip->nc_page_size = 8192;
90 1.1 ahoka break;
91 1.1 ahoka }
92 1.1 ahoka
93 1.1 ahoka switch ((params2 & NAND_SAMSUNG_PAGEMASK) >> 4) {
94 1.1 ahoka case 0x0:
95 1.1 ahoka chip->nc_block_size = 64 * 1024;
96 1.1 ahoka break;
97 1.1 ahoka case 0x0:
98 1.1 ahoka chip->nc_block_size = 128 * 1024;
99 1.1 ahoka break;
100 1.1 ahoka case 0x0:
101 1.1 ahoka chip->nc_block_size = 256 * 1024;
102 1.1 ahoka break;
103 1.1 ahoka case 0x0:
104 1.1 ahoka chip->nc_block_size = 512 * 1024;
105 1.1 ahoka break;
106 1.1 ahoka }
107 1.1 ahoka
108 1.1 ahoka /* 8/16 bytes per 512 bytes! XXX do i get this right? */
109 1.1 ahoka switch ((params2 & NAND_SAMSUNG_SPAREMASK) >> 2) {
110 1.1 ahoka case 0x0:
111 1.1 ahoka chip->nc_spare_size = 8 * chip->nc_page_size / 512;
112 1.1 ahoka break;
113 1.1 ahoka case 0x1:
114 1.1 ahoka chip->nc_spare_size = 16 * chip->nc_page_size / 512;
115 1.1 ahoka break;
116 1.1 ahoka }
117 1.1 ahoka
118 1.1 ahoka switch ((params2 & NAND_SAMSUNG_BITSMASK) >> 6) {
119 1.1 ahoka case 0x0:
120 1.1 ahoka /* its an 8bit chip */
121 1.1 ahoka break;
122 1.1 ahoka case 0x1:
123 1.1 ahoka chip->nc_flags |= NC_BUSWIDTH_16;
124 1.1 ahoka break;
125 1.1 ahoka }
126 1.1 ahoka
127 1.1 ahoka // TODO make this nice like the above
128 1.1 ahoka chip->nc_size = (((params3 >> 4) & 0x7) + 1) * 64 * 1024 * 1024;
129 1.1 ahoka } else {
130 1.1 ahoka return 1;
131 1.1 ahoka }
132 1.1 ahoka
133 1.1 ahoka return 0;
134 1.1 ahoka }
135 1.1 ahoka
136