public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mtdchar: handle chips that have user otp but no factory otp
@ 2013-02-18 10:19 Uwe Kleine-König
  2013-03-02 15:41 ` Artem Bityutskiy
  2013-03-04 16:35 ` [PATCH v2] " Uwe Kleine-König
  0 siblings, 2 replies; 32+ messages in thread
From: Uwe Kleine-König @ 2013-02-18 10:19 UTC (permalink / raw)
  To: linux-mtd; +Cc: kernel

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 <u.kleine-koenig@pengutronix.de>
---
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
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2014-01-14  8:30 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-18 10:19 [PATCH] mtdchar: handle chips that have user otp but no factory otp Uwe Kleine-König
2013-03-02 15:41 ` Artem Bityutskiy
2013-03-02 21:08   ` Uwe Kleine-König
2013-03-04 16:35 ` [PATCH v2] " Uwe Kleine-König
2013-03-04 16:47   ` [PATCH v2] mtd/nand: don't use {read,write}_buf for 8-bit transfers Uwe Kleine-König
2013-03-04 16:50     ` Uwe Kleine-König
2013-03-05  2:00       ` [PATCH v2] mtd/nand: don't use {read, write}_buf " Huang Shijie
2013-03-13  9:33     ` [PATCH v2] mtd/nand: don't use {read,write}_buf " Artem Bityutskiy
2013-11-26 21:03       ` Uwe Kleine-König
2013-11-27  6:59         ` Brian Norris
2013-03-13 10:26     ` Artem Bityutskiy
2013-04-05 12:13     ` David Woodhouse
2013-11-26 21:15       ` [PATCH v3] " Uwe Kleine-König
2013-11-27  7:35         ` Brian Norris
2013-11-29 12:20           ` Ezequiel Garcia
2013-11-30  6:04             ` Brian Norris
2013-11-30 11:19               ` Ezequiel Garcia
2013-11-30 16:35               ` Ezequiel Garcia
2013-11-30 16:51                 ` Ezequiel Garcia
2013-11-30 19:01                   ` Brian Norris
2013-11-30 21:06                     ` Ezequiel Garcia
2013-12-02 19:40                       ` Gupta, Pekon
2013-11-30 18:53                 ` Brian Norris
2013-11-30 20:57                   ` Ezequiel Garcia
2013-12-05 21:22           ` [PATCH v4] " Uwe Kleine-König
2013-12-17  5:48             ` Brian Norris
2013-12-17 21:46               ` Ezequiel Garcia
2013-12-19  7:39                 ` Brian Norris
2014-01-14  8:12             ` Brian Norris
2014-01-14  8:29               ` Uwe Kleine-König
2013-03-06  8:47   ` [PATCH v2] mtdchar: handle chips that have user otp but no factory otp Artem Bityutskiy
2013-03-06  8:51     ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox