Skip to content

Commit 104e442

Browse files
author
Boris Brezillon
committed
mtd: nand: Pass the CS line to ->setup_data_interface()
Some NAND controllers can assign different NAND timings to different CS lines. Pass the CS line information to ->setup_data_interface() so that the NAND controller driver knows which CS line is concerned by the setup_data_interface() request. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
1 parent ebb528d commit 104e442

7 files changed

Lines changed: 37 additions & 35 deletions

File tree

‎drivers/mtd/nand/fsmc_nand.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,8 @@ static int fsmc_calc_timings(struct fsmc_nand_data *host,
388388
return 0;
389389
}
390390

391-
static int fsmc_setup_data_interface(struct mtd_info *mtd,
392-
const struct nand_data_interface *conf,
393-
bool check_only)
391+
static int fsmc_setup_data_interface(struct mtd_info *mtd, int csline,
392+
const struct nand_data_interface *conf)
394393
{
395394
struct nand_chip *nand = mtd_to_nand(mtd);
396395
struct fsmc_nand_data *host = nand_get_controller_data(nand);
@@ -406,7 +405,7 @@ static int fsmc_setup_data_interface(struct mtd_info *mtd,
406405
if (ret)
407406
return ret;
408407

409-
if (check_only)
408+
if (csline == NAND_DATA_IFACE_CHECK_ONLY)
410409
return 0;
411410

412411
fsmc_nand_setup(host, &tims);

‎drivers/mtd/nand/mxc_nand.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ struct mxc_nand_devtype_data {
152152
void (*select_chip)(struct mtd_info *mtd, int chip);
153153
int (*correct_data)(struct mtd_info *mtd, u_char *dat,
154154
u_char *read_ecc, u_char *calc_ecc);
155-
int (*setup_data_interface)(struct mtd_info *mtd,
156-
const struct nand_data_interface *conf,
157-
bool check_only);
155+
int (*setup_data_interface)(struct mtd_info *mtd, int csline,
156+
const struct nand_data_interface *conf);
158157

159158
/*
160159
* On i.MX21 the CONFIG2:INT bit cannot be read if interrupts are masked
@@ -1015,9 +1014,8 @@ static void preset_v1(struct mtd_info *mtd)
10151014
writew(0x4, NFC_V1_V2_WRPROT);
10161015
}
10171016

1018-
static int mxc_nand_v2_setup_data_interface(struct mtd_info *mtd,
1019-
const struct nand_data_interface *conf,
1020-
bool check_only)
1017+
static int mxc_nand_v2_setup_data_interface(struct mtd_info *mtd, int csline,
1018+
const struct nand_data_interface *conf)
10211019
{
10221020
struct nand_chip *nand_chip = mtd_to_nand(mtd);
10231021
struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
@@ -1075,7 +1073,7 @@ static int mxc_nand_v2_setup_data_interface(struct mtd_info *mtd,
10751073
return -EINVAL;
10761074
}
10771075

1078-
if (check_only)
1076+
if (csline == NAND_DATA_IFACE_CHECK_ONLY)
10791077
return 0;
10801078

10811079
ret = clk_set_rate(host->clk, rate);

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,12 +1042,13 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
10421042
/**
10431043
* nand_reset_data_interface - Reset data interface and timings
10441044
* @chip: The NAND chip
1045+
* @chipnr: Internal die id
10451046
*
10461047
* Reset the Data interface and timings to ONFI mode 0.
10471048
*
10481049
* Returns 0 for success or negative error code otherwise.
10491050
*/
1050-
static int nand_reset_data_interface(struct nand_chip *chip)
1051+
static int nand_reset_data_interface(struct nand_chip *chip, int chipnr)
10511052
{
10521053
struct mtd_info *mtd = nand_to_mtd(chip);
10531054
const struct nand_data_interface *conf;
@@ -1071,7 +1072,7 @@ static int nand_reset_data_interface(struct nand_chip *chip)
10711072
*/
10721073

10731074
conf = nand_get_default_data_interface();
1074-
ret = chip->setup_data_interface(mtd, conf, false);
1075+
ret = chip->setup_data_interface(mtd, chipnr, conf);
10751076
if (ret)
10761077
pr_err("Failed to configure data interface to SDR timing mode 0\n");
10771078

@@ -1081,6 +1082,7 @@ static int nand_reset_data_interface(struct nand_chip *chip)
10811082
/**
10821083
* nand_setup_data_interface - Setup the best data interface and timings
10831084
* @chip: The NAND chip
1085+
* @chipnr: Internal die id
10841086
*
10851087
* Find and configure the best data interface and NAND timings supported by
10861088
* the chip and the driver.
@@ -1090,7 +1092,7 @@ static int nand_reset_data_interface(struct nand_chip *chip)
10901092
*
10911093
* Returns 0 for success or negative error code otherwise.
10921094
*/
1093-
static int nand_setup_data_interface(struct nand_chip *chip)
1095+
static int nand_setup_data_interface(struct nand_chip *chip, int chipnr)
10941096
{
10951097
struct mtd_info *mtd = nand_to_mtd(chip);
10961098
int ret;
@@ -1114,7 +1116,7 @@ static int nand_setup_data_interface(struct nand_chip *chip)
11141116
goto err;
11151117
}
11161118

1117-
ret = chip->setup_data_interface(mtd, chip->data_interface, false);
1119+
ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface);
11181120
err:
11191121
return ret;
11201122
}
@@ -1165,8 +1167,10 @@ static int nand_init_data_interface(struct nand_chip *chip)
11651167
if (ret)
11661168
continue;
11671169

1168-
ret = chip->setup_data_interface(mtd, chip->data_interface,
1169-
true);
1170+
/* Pass -1 to only */
1171+
ret = chip->setup_data_interface(mtd,
1172+
NAND_DATA_IFACE_CHECK_ONLY,
1173+
chip->data_interface);
11701174
if (!ret) {
11711175
chip->onfi_timing_mode_default = mode;
11721176
break;
@@ -1193,7 +1197,7 @@ int nand_reset(struct nand_chip *chip, int chipnr)
11931197
struct mtd_info *mtd = nand_to_mtd(chip);
11941198
int ret;
11951199

1196-
ret = nand_reset_data_interface(chip);
1200+
ret = nand_reset_data_interface(chip, chipnr);
11971201
if (ret)
11981202
return ret;
11991203

@@ -1206,7 +1210,7 @@ int nand_reset(struct nand_chip *chip, int chipnr)
12061210
chip->select_chip(mtd, -1);
12071211

12081212
chip->select_chip(mtd, chipnr);
1209-
ret = nand_setup_data_interface(chip);
1213+
ret = nand_setup_data_interface(chip, chipnr);
12101214
chip->select_chip(mtd, -1);
12111215
if (ret)
12121216
return ret;
@@ -4396,7 +4400,7 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,
43964400
* For the other dies, nand_reset() will automatically switch to the
43974401
* best mode for us.
43984402
*/
4399-
ret = nand_setup_data_interface(chip);
4403+
ret = nand_setup_data_interface(chip, 0);
44004404
if (ret)
44014405
return ret;
44024406

‎drivers/mtd/nand/s3c2410.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,8 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
812812
return -ENODEV;
813813
}
814814

815-
static int s3c2410_nand_setup_data_interface(struct mtd_info *mtd,
816-
const struct nand_data_interface *conf,
817-
bool check_only)
815+
static int s3c2410_nand_setup_data_interface(struct mtd_info *mtd, int csline,
816+
const struct nand_data_interface *conf)
818817
{
819818
struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd);
820819
struct s3c2410_platform_nand *pdata = info->platform;

‎drivers/mtd/nand/sunxi_nand.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,8 @@ static int _sunxi_nand_lookup_timing(const s32 *lut, int lut_size, u32 duration,
15921592
#define sunxi_nand_lookup_timing(l, p, c) \
15931593
_sunxi_nand_lookup_timing(l, ARRAY_SIZE(l), p, c)
15941594

1595-
static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd,
1596-
const struct nand_data_interface *conf,
1597-
bool check_only)
1595+
static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd, int csline,
1596+
const struct nand_data_interface *conf)
15981597
{
15991598
struct nand_chip *nand = mtd_to_nand(mtd);
16001599
struct sunxi_nand_chip *chip = to_sunxi_nand(nand);
@@ -1707,7 +1706,7 @@ static int sunxi_nfc_setup_data_interface(struct mtd_info *mtd,
17071706
return tRHW;
17081707
}
17091708

1710-
if (check_only)
1709+
if (csline == NAND_DATA_IFACE_CHECK_ONLY)
17111710
return 0;
17121711

17131712
/*

‎drivers/mtd/nand/tango_nand.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ static u32 to_ticks(int kHz, int ps)
476476
return DIV_ROUND_UP_ULL((u64)kHz * ps, NSEC_PER_SEC);
477477
}
478478

479-
static int tango_set_timings(struct mtd_info *mtd,
480-
const struct nand_data_interface *conf,
481-
bool check_only)
479+
static int tango_set_timings(struct mtd_info *mtd, int csline,
480+
const struct nand_data_interface *conf)
482481
{
483482
const struct nand_sdr_timings *sdr = nand_get_sdr_timings(conf);
484483
struct nand_chip *chip = mtd_to_nand(mtd);
@@ -490,7 +489,7 @@ static int tango_set_timings(struct mtd_info *mtd,
490489
if (IS_ERR(sdr))
491490
return PTR_ERR(sdr);
492491

493-
if (check_only)
492+
if (csline == NAND_DATA_IFACE_CHECK_ONLY)
494493
return 0;
495494

496495
Trdy = to_ticks(kHz, sdr->tCEA_max - sdr->tREA_max);

‎include/linux/mtd/nand.h‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len);
107107
#define NAND_STATUS_READY 0x40
108108
#define NAND_STATUS_WP 0x80
109109

110+
#define NAND_DATA_IFACE_CHECK_ONLY -1
111+
110112
/*
111113
* Constants for ECC_MODES
112114
*/
@@ -818,7 +820,10 @@ struct nand_manufacturer_ops {
818820
* @read_retries: [INTERN] the number of read retry modes supported
819821
* @onfi_set_features: [REPLACEABLE] set the features for ONFI nand
820822
* @onfi_get_features: [REPLACEABLE] get the features for ONFI nand
821-
* @setup_data_interface: [OPTIONAL] setup the data interface and timing
823+
* @setup_data_interface: [OPTIONAL] setup the data interface and timing. If
824+
* chipnr is set to %NAND_DATA_IFACE_CHECK_ONLY this
825+
* means the configuration should not be applied but
826+
* only checked.
822827
* @bbt: [INTERN] bad block table pointer
823828
* @bbt_td: [REPLACEABLE] bad block table descriptor for flash
824829
* lookup.
@@ -862,9 +867,8 @@ struct nand_chip {
862867
int (*onfi_get_features)(struct mtd_info *mtd, struct nand_chip *chip,
863868
int feature_addr, uint8_t *subfeature_para);
864869
int (*setup_read_retry)(struct mtd_info *mtd, int retry_mode);
865-
int (*setup_data_interface)(struct mtd_info *mtd,
866-
const struct nand_data_interface *conf,
867-
bool check_only);
870+
int (*setup_data_interface)(struct mtd_info *mtd, int chipnr,
871+
const struct nand_data_interface *conf);
868872

869873

870874
int chip_delay;

0 commit comments

Comments
 (0)