From patchwork Mon Feb 18 10:19:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 221191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4F84C2C0099 for ; Mon, 18 Feb 2013 21:21:20 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U7Now-0004u0-Mj; Mon, 18 Feb 2013 10:19:38 +0000 Received: from metis.ext.pengutronix.de ([2001:6f8:1178:4:290:27ff:fe1d:cc33]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U7Nou-0004tU-5V for linux-mtd@lists.infradead.org; Mon, 18 Feb 2013 10:19:36 +0000 Received: from dude.hi.pengutronix.de ([2001:6f8:1178:2:21e:67ff:fe11:9c5c]) by metis.ext.pengutronix.de with esmtp (Exim 4.72) (envelope-from ) id 1U7Nop-0000QC-R6; Mon, 18 Feb 2013 11:19:31 +0100 Received: from ukl by dude.hi.pengutronix.de with local (Exim 4.80) (envelope-from ) id 1U7Nop-0000Gd-Pk; Mon, 18 Feb 2013 11:19:31 +0100 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: linux-mtd@lists.infradead.org Subject: [PATCH] mtdchar: handle chips that have user otp but no factory otp Date: Mon, 18 Feb 2013 11:19:28 +0100 Message-Id: <1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:6f8:1178:2:21e:67ff:fe11:9c5c X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130218_051936_365758_F6F20F34 X-CRM114-Status: GOOD ( 15.82 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: kernel@pengutronix.de X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Before this patch mtd_read_fact_prot_reg was used to check availability for both MTD_OTP_FACTORY and MTD_OTP_USER access. This made accessing user otp for chips that don't have a factory otp area impossible. So use the right wrapper depending on the intended area to be accessed. Signed-off-by: Uwe Kleine-König --- Hello, I'm currently working on accessing the user otp area of MT29F2G nand flash that doesn't have a factory otp. Reading and writing are not ready yet, but this change is an obvious prerequisite. Best regards Uwe drivers/mtd/mtdchar.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index a6e7451..1f4034a 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -371,26 +371,34 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode) struct mtd_info *mtd = mfi->mtd; size_t retlen; int ret = 0; - - /* - * Make a fake call to mtd_read_fact_prot_reg() to check if OTP - * operations are supported. - */ - if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP) - return -EOPNOTSUPP; + int (*func)(struct mtd_info *, loff_t, size_t, size_t *, u_char *) = + NULL; + enum mtd_file_modes outmode = MTD_FILE_MODE_NORMAL; switch (mode) { case MTD_OTP_FACTORY: - mfi->mode = MTD_FILE_MODE_OTP_FACTORY; + outmode = MTD_FILE_MODE_OTP_FACTORY; + func = mtd_read_fact_prot_reg; break; case MTD_OTP_USER: - mfi->mode = MTD_FILE_MODE_OTP_USER; + outmode = MTD_FILE_MODE_OTP_USER; + func = mtd_read_user_prot_reg; break; - default: - ret = -EINVAL; case MTD_OTP_OFF: break; + default: + ret = -EINVAL; } + + /* + * Make a fake call to mtd_read_fact_prot_reg() or + * mtd_read_user_prot_reg() to check if OTP operations are supported. + */ + if (func && func(mtd, -1, 0, &retlen, NULL) == -EOPNOTSUPP) + return -EOPNOTSUPP; + + mfi->mode = outmode; + return ret; } #else