]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/mtd/nand/nand_micron.c
scsi: qedf: Fix a potential NULL pointer dereference
[mirror_ubuntu-artful-kernel.git] / drivers / mtd / nand / nand_micron.c
1 /*
2 * Copyright (C) 2017 Free Electrons
3 * Copyright (C) 2017 NextThing Co
4 *
5 * Author: Boris Brezillon <boris.brezillon@free-electrons.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18 #include <linux/mtd/nand.h>
19
20 struct nand_onfi_vendor_micron {
21 u8 two_plane_read;
22 u8 read_cache;
23 u8 read_unique_id;
24 u8 dq_imped;
25 u8 dq_imped_num_settings;
26 u8 dq_imped_feat_addr;
27 u8 rb_pulldown_strength;
28 u8 rb_pulldown_strength_feat_addr;
29 u8 rb_pulldown_strength_num_settings;
30 u8 otp_mode;
31 u8 otp_page_start;
32 u8 otp_data_prot_addr;
33 u8 otp_num_pages;
34 u8 otp_feat_addr;
35 u8 read_retry_options;
36 u8 reserved[72];
37 u8 param_revision;
38 } __packed;
39
40 static int micron_nand_setup_read_retry(struct mtd_info *mtd, int retry_mode)
41 {
42 struct nand_chip *chip = mtd_to_nand(mtd);
43 u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {retry_mode};
44
45 return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY,
46 feature);
47 }
48
49 /*
50 * Configure chip properties from Micron vendor-specific ONFI table
51 */
52 static int micron_nand_onfi_init(struct nand_chip *chip)
53 {
54 struct nand_onfi_params *p = &chip->onfi_params;
55 struct nand_onfi_vendor_micron *micron = (void *)p->vendor;
56
57 if (!chip->onfi_version)
58 return 0;
59
60 if (le16_to_cpu(p->vendor_revision) < 1)
61 return 0;
62
63 chip->read_retries = micron->read_retry_options;
64 chip->setup_read_retry = micron_nand_setup_read_retry;
65
66 return 0;
67 }
68
69 static int micron_nand_init(struct nand_chip *chip)
70 {
71 struct mtd_info *mtd = nand_to_mtd(chip);
72 int ret;
73
74 ret = micron_nand_onfi_init(chip);
75 if (ret)
76 return ret;
77
78 if (mtd->writesize == 2048)
79 chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
80
81 return 0;
82 }
83
84 const struct nand_manufacturer_ops micron_nand_manuf_ops = {
85 .init = micron_nand_init,
86 };