diff mbox

[4/8] mtd: rawnand: mtk: Remove max_sector_size from struct mtk_nfc_caps

Message ID 1523418118-57686-5-git-send-email-xiaolei.li@mediatek.com (mailing list archive)
State New, archived
Headers show

Commit Message

xiaolei li April 11, 2018, 3:41 a.m. UTC
Remove max_sector_size from struct mtk_nfc_caps, and use sector size
array and number of sector size to show sector sizes that controller
supports.

Signed-off-by: Xiaolei Li <xiaolei.li@mediatek.com>
---
 drivers/mtd/nand/raw/mtk_nand.c | 32 +++++++++++++++++++++++++++-----
 1 file changed, 27 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c
index b05f619..2c244c2 100644
--- a/drivers/mtd/nand/raw/mtk_nand.c
+++ b/drivers/mtd/nand/raw/mtk_nand.c
@@ -105,10 +105,11 @@ 
 struct mtk_nfc_caps {
 	const u8 *spare_size;
 	u8 num_spare_size;
+	const int *sector_size;
+	int num_sector_size;
 	u8 pageformat_spare_shift;
 	u8 nfi_clk_div;
 	u8 max_sector;
-	u32 max_sector_size;
 };
 
 struct mtk_nfc_bad_mark_ctl {
@@ -177,6 +178,14 @@  struct mtk_nfc {
 	16, 26, 27, 28
 };
 
+static const int sector_size_max_1k[] = {
+	1024, 512
+};
+
+static const int sector_size_max_512[] = {
+	512
+};
+
 static inline struct mtk_nfc_nand_chip *to_mtk_nand(struct nand_chip *nand)
 {
 	return container_of(nand, struct mtk_nfc_nand_chip, nand);
@@ -257,6 +266,16 @@  static inline u8 nfi_readb(struct mtk_nfc *nfc, u32 reg)
 	return readb_relaxed(nfc->regs + reg);
 }
 
+static int mtk_nfc_max_sector_size(struct mtk_nfc *nfc)
+{
+	int i, sector_size = 0;
+
+	for (i = 0; i < nfc->caps->num_sector_size; i++)
+		sector_size = max(sector_size, nfc->caps->sector_size[i]);
+
+	return sector_size;
+}
+
 static void mtk_nfc_hw_reset(struct mtk_nfc *nfc)
 {
 	struct device *dev = nfc->dev;
@@ -1211,7 +1230,7 @@  static int mtk_nfc_ecc_init(struct device *dev, struct mtd_info *mtd)
 		 */
 		if (nand->ecc.size < 1024) {
 			if (mtd->writesize > 512 &&
-			    nfc->caps->max_sector_size > 512) {
+			    mtk_nfc_max_sector_size(nfc) > 512) {
 				nand->ecc.size = 1024;
 				nand->ecc.strength <<= 1;
 			} else {
@@ -1400,28 +1419,31 @@  static int mtk_nfc_nand_chips_init(struct device *dev, struct mtk_nfc *nfc)
 static const struct mtk_nfc_caps mtk_nfc_caps_mt2701 = {
 	.spare_size = spare_size_mt2701,
 	.num_spare_size = 16,
+	.sector_size = sector_size_max_1k,
+	.num_sector_size = 2,
 	.pageformat_spare_shift = 4,
 	.nfi_clk_div = 1,
 	.max_sector = 16,
-	.max_sector_size = 1024,
 };
 
 static const struct mtk_nfc_caps mtk_nfc_caps_mt2712 = {
 	.spare_size = spare_size_mt2712,
 	.num_spare_size = 19,
+	.sector_size = sector_size_max_1k,
+	.num_sector_size = 2,
 	.pageformat_spare_shift = 16,
 	.nfi_clk_div = 2,
 	.max_sector = 16,
-	.max_sector_size = 1024,
 };
 
 static const struct mtk_nfc_caps mtk_nfc_caps_mt7622 = {
 	.spare_size = spare_size_mt7622,
 	.num_spare_size = 4,
+	.sector_size = sector_size_max_512,
+	.num_sector_size = 1,
 	.pageformat_spare_shift = 4,
 	.nfi_clk_div = 1,
 	.max_sector = 8,
-	.max_sector_size = 512,
 };
 
 static const struct of_device_id mtk_nfc_id_table[] = {