From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964846AbbLGW1S (ORCPT ); Mon, 7 Dec 2015 17:27:18 -0500 Received: from down.free-electrons.com ([37.187.137.238]:49602 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S964809AbbLGW1P (ORCPT ); Mon, 7 Dec 2015 17:27:15 -0500 From: Boris Brezillon To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Cc: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Kukjin Kim , Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ralf Baechle , linux-mips@linux-mips.org, Josh Wu , Ezequiel Garcia , Maxime Ripard , Chen-Yu Tsai , linux-sunxi@googlegroups.com, Stefan Agner , Kyungmin Park , Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, punnaiah choudary kalluri , Boris Brezillon Subject: [PATCH 11/23] mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions Date: Mon, 7 Dec 2015 23:26:06 +0100 Message-Id: <1449527178-5930-12-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1449527178-5930-1-git-send-email-boris.brezillon@free-electrons.com> References: <1449527178-5930-1-git-send-email-boris.brezillon@free-electrons.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to make the ecclayout definition completely dynamic we need to rework the way these different ECC layouts are defined and iterated. Create the mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helpers to hide ecclayout definition internals to their users. Signed-off-by: Boris Brezillon --- include/linux/mtd/mtd.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9cf13c4..25e3d0f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -253,6 +253,38 @@ struct mtd_info { int usecount; }; +static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte) +{ + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (eccbyte >= mtd->ecclayout->eccbytes) + return -ERANGE; + + return mtd->ecclayout->eccpos[eccbyte]; +} + +static inline int mtd_oobfree(struct mtd_info *mtd, int section, + struct nand_oobfree *oobfree) +{ + memset(oobfree, 0, sizeof(*oobfree)); + + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE) + return -ERANGE; + + *oobfree = mtd->ecclayout->oobfree[section]; + + return 0; +} + +static inline int mtd_eccbytes(struct mtd_info *mtd) +{ + return mtd->ecclayout ? mtd->ecclayout->eccbytes : 0; +} + static inline void mtd_set_of_node(struct mtd_info *mtd, struct device_node *np) { -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Brezillon Subject: [PATCH 11/23] mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions Date: Mon, 7 Dec 2015 23:26:06 +0100 Message-ID: <1449527178-5930-12-git-send-email-boris.brezillon@free-electrons.com> References: <1449527178-5930-1-git-send-email-boris.brezillon@free-electrons.com> Reply-To: boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: In-Reply-To: <1449527178-5930-1-git-send-email-boris.brezillon-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org> List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , To: David Woodhouse , Brian Norris , linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org Cc: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Kukjin Kim , Krzysztof Kozlowski , linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, Ralf Baechle , linux-mips-6z/3iImG2C8G8FEW9MqTrA@public.gmane.org, Josh Wu , Ezequiel Garcia , Maxime Ripard , Chen-Yu Tsai , linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org, Stefan Agner , Kyungmin Park , Greg Kroah-Hartman , devel-gWbeCf7V1WCQmaza687I9mD2FQJk+8+b@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, punnaiah choudary kalluri , Boris Brezillon List-Id: linux-samsung-soc@vger.kernel.org In order to make the ecclayout definition completely dynamic we need to rework the way these different ECC layouts are defined and iterated. Create the mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helpers to hide ecclayout definition internals to their users. Signed-off-by: Boris Brezillon --- include/linux/mtd/mtd.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9cf13c4..25e3d0f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -253,6 +253,38 @@ struct mtd_info { int usecount; }; +static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte) +{ + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (eccbyte >= mtd->ecclayout->eccbytes) + return -ERANGE; + + return mtd->ecclayout->eccpos[eccbyte]; +} + +static inline int mtd_oobfree(struct mtd_info *mtd, int section, + struct nand_oobfree *oobfree) +{ + memset(oobfree, 0, sizeof(*oobfree)); + + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE) + return -ERANGE; + + *oobfree = mtd->ecclayout->oobfree[section]; + + return 0; +} + +static inline int mtd_eccbytes(struct mtd_info *mtd) +{ + return mtd->ecclayout ? mtd->ecclayout->eccbytes : 0; +} + static inline void mtd_set_of_node(struct mtd_info *mtd, struct device_node *np) { -- 2.1.4 From mboxrd@z Thu Jan 1 00:00:00 1970 From: boris.brezillon@free-electrons.com (Boris Brezillon) Date: Mon, 7 Dec 2015 23:26:06 +0100 Subject: [PATCH 11/23] mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions In-Reply-To: <1449527178-5930-1-git-send-email-boris.brezillon@free-electrons.com> References: <1449527178-5930-1-git-send-email-boris.brezillon@free-electrons.com> Message-ID: <1449527178-5930-12-git-send-email-boris.brezillon@free-electrons.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org In order to make the ecclayout definition completely dynamic we need to rework the way these different ECC layouts are defined and iterated. Create the mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helpers to hide ecclayout definition internals to their users. Signed-off-by: Boris Brezillon --- include/linux/mtd/mtd.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9cf13c4..25e3d0f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -253,6 +253,38 @@ struct mtd_info { int usecount; }; +static inline int mtd_eccpos(struct mtd_info *mtd, int eccbyte) +{ + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (eccbyte >= mtd->ecclayout->eccbytes) + return -ERANGE; + + return mtd->ecclayout->eccpos[eccbyte]; +} + +static inline int mtd_oobfree(struct mtd_info *mtd, int section, + struct nand_oobfree *oobfree) +{ + memset(oobfree, 0, sizeof(*oobfree)); + + if (!mtd->ecclayout) + return -ENOTSUPP; + + if (section >= MTD_MAX_OOBFREE_ENTRIES_LARGE) + return -ERANGE; + + *oobfree = mtd->ecclayout->oobfree[section]; + + return 0; +} + +static inline int mtd_eccbytes(struct mtd_info *mtd) +{ + return mtd->ecclayout ? mtd->ecclayout->eccbytes : 0; +} + static inline void mtd_set_of_node(struct mtd_info *mtd, struct device_node *np) { -- 2.1.4