1 From 5c5e3963a1b58be1669da5da93f51dc339cd73d7 Mon Sep 17 00:00:00 2001
2 From: Boris BREZILLON <b.brezillon.dev@gmail.com>
3 Date: Mon, 24 Feb 2014 16:30:22 +0100
4 Subject: [PATCH] mtd: nand: Add hynix specific initializer
6 Add an hynix initiliazer to manage read retries on h27uxgt8t2a chip.
8 Signed-off-by: Boris BREZILLON <b.brezillon.dev@gmail.com>
9 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
11 drivers/mtd/nand/Makefile | 2 +-
12 drivers/mtd/nand/nand_hynix.c | 159 ++++++++++++++++++++++++++++++++++++++++++
13 drivers/mtd/nand/nand_ids.c | 3 +-
14 include/linux/mtd/nand.h | 2 +
15 4 files changed, 164 insertions(+), 2 deletions(-)
16 create mode 100644 drivers/mtd/nand/nand_hynix.c
18 --- a/drivers/mtd/nand/Makefile
19 +++ b/drivers/mtd/nand/Makefile
21 obj-$(CONFIG_MTD_NAND) += nand.o
22 obj-$(CONFIG_MTD_NAND_ECC) += nand_ecc.o
23 obj-$(CONFIG_MTD_NAND_BCH) += nand_bch.o
24 -obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o
25 +obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o nand_hynix.o
26 obj-$(CONFIG_MTD_SM_COMMON) += sm_common.o
28 obj-$(CONFIG_MTD_NAND_CAFE) += cafe_nand.o
30 +++ b/drivers/mtd/nand/nand_hynix.c
33 + * Copyright (C) 2014 Boris BREZILLON <b.brezillon.dev@gmail.com>
35 + * This program is free software; you can redistribute it and/or modify
36 + * it under the terms of the GNU General Public License as published by
37 + * the Free Software Foundation; either version 2 of the License, or
38 + * (at your option) any later version.
40 + * This program is distributed in the hope that it will be useful,
41 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 + * GNU General Public License for more details.
46 +#include <linux/module.h>
47 +#include <linux/mtd/nand.h>
48 +#include <linux/slab.h>
50 +static u8 h27ucg8t2a_read_retry_regs[] = {
51 + 0xcc, 0xbf, 0xaa, 0xab, 0xcd, 0xad, 0xae, 0xaf
54 +struct hynix_read_retry {
60 + struct hynix_read_retry read_retry;
63 +int nand_setup_read_retry_hynix(struct mtd_info *mtd, int retry_mode)
65 + struct nand_chip *chip = mtd->priv;
66 + struct hynix_nand *hynix = chip->manuf_priv;
67 + int offset = retry_mode * 8;
71 + chip->cmdfunc(mtd, 0x36, -1, -1);
72 + for (i = 0; i < 8; i++) {
73 + int column = hynix->read_retry.regs[i];
74 + column |= column << 8;
75 + chip->cmdfunc(mtd, NAND_CMD_NONE, column, -1);
76 + chip->write_byte(mtd, hynix->read_retry.values[offset + i]);
78 + chip->cmdfunc(mtd, 0x16, -1, -1);
80 + status = chip->waitfunc(mtd, chip);
81 + if (status & NAND_STATUS_FAIL)
87 +static void h27ucg8t2a_cleanup(struct mtd_info *mtd)
89 + struct nand_chip *chip = mtd->priv;
90 + kfree(chip->manuf_priv);
93 +static int h27ucg8t2a_init(struct mtd_info *mtd, const uint8_t *id)
95 + struct nand_chip *chip = mtd->priv;
96 + struct hynix_nand *hynix;
101 + buf = kzalloc(1024, GFP_KERNEL);
105 + chip->select_chip(mtd, 0);
106 + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
107 + chip->cmdfunc(mtd, 0x36, 0xff, -1);
108 + chip->write_byte(mtd, 0x40);
109 + chip->cmdfunc(mtd, NAND_CMD_NONE, 0xcc, -1);
110 + chip->write_byte(mtd, 0x4d);
111 + chip->cmdfunc(mtd, 0x16, -1, -1);
112 + chip->cmdfunc(mtd, 0x17, -1, -1);
113 + chip->cmdfunc(mtd, 0x04, -1, -1);
114 + chip->cmdfunc(mtd, 0x19, -1, -1);
115 + chip->cmdfunc(mtd, NAND_CMD_READ0, 0x0, 0x200);
117 + chip->read_buf(mtd, buf, 2);
118 + if (buf[0] != 0x8 || buf[1] != 0x8) {
122 + chip->read_buf(mtd, buf, 1024);
125 + for (j = 0; j < 8; j++) {
126 + for (i = 0; i < 64; i++) {
127 + u8 *tmp = buf + (128 * j);
128 + if ((tmp[i] | tmp[i + 64]) != 0xff) {
135 + chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
136 + chip->cmdfunc(mtd, 0x38, -1, -1);
137 + chip->select_chip(mtd, -1);
140 + hynix = kzalloc(sizeof(*hynix), GFP_KERNEL);
146 + hynix->read_retry.regs = h27ucg8t2a_read_retry_regs;
147 + memcpy(hynix->read_retry.values, buf, 64);
148 + chip->manuf_priv = hynix;
149 + chip->setup_read_retry = nand_setup_read_retry_hynix;
150 + chip->read_retries = 8;
151 + chip->manuf_cleanup = h27ucg8t2a_cleanup;
160 +struct hynix_nand_initializer {
162 + int (*init)(struct mtd_info *mtd, const uint8_t *id);
165 +struct hynix_nand_initializer initializers[] = {
167 + .id = {NAND_MFR_HYNIX, 0xde, 0x94, 0xda, 0x74, 0xc4},
168 + .init = h27ucg8t2a_init,
172 +int hynix_nand_init(struct mtd_info *mtd, const uint8_t *id)
176 + for (i = 0; i < ARRAY_SIZE(initializers); i++) {
177 + struct hynix_nand_initializer *initializer = &initializers[i];
178 + if (memcmp(id, initializer->id, sizeof(initializer->id)))
181 + return initializer->init(mtd, id);
186 +EXPORT_SYMBOL(hynix_nand_init);
188 +MODULE_LICENSE("GPL");
189 +MODULE_AUTHOR("Boris BREZILLON <b.brezillon.dev@gmail.com>");
190 +MODULE_DESCRIPTION("Hynix NAND specific code");
191 --- a/drivers/mtd/nand/nand_ids.c
192 +++ b/drivers/mtd/nand/nand_ids.c
193 @@ -163,6 +163,7 @@ struct nand_flash_dev nand_flash_ids[] =
198 /* Manufacturer IDs */
199 struct nand_manufacturers nand_manuf_ids[] = {
200 {NAND_MFR_TOSHIBA, "Toshiba"},
201 @@ -171,7 +172,7 @@ struct nand_manufacturers nand_manuf_ids
202 {NAND_MFR_NATIONAL, "National"},
203 {NAND_MFR_RENESAS, "Renesas"},
204 {NAND_MFR_STMICRO, "ST Micro"},
205 - {NAND_MFR_HYNIX, "Hynix"},
206 + {NAND_MFR_HYNIX, "Hynix", hynix_nand_init},
207 {NAND_MFR_MICRON, "Micron"},
208 {NAND_MFR_AMD, "AMD/Spansion"},
209 {NAND_MFR_MACRONIX, "Macronix"},
210 --- a/include/linux/mtd/nand.h
211 +++ b/include/linux/mtd/nand.h
212 @@ -959,6 +959,8 @@ struct nand_manufacturers {
213 extern struct nand_flash_dev nand_flash_ids[];
214 extern struct nand_manufacturers nand_manuf_ids[];
216 +int hynix_nand_init(struct mtd_info *mtd, const uint8_t *id);
218 extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
219 extern int nand_default_bbt(struct mtd_info *mtd);
220 extern int nand_markbad_bbt(struct mtd_info *mtd, loff_t offs);