diff mbox

[v2] mtdchar: handle chips that have user otp but no factory otp

Message ID 1362414924-27506-1-git-send-email-u.kleine-koenig@pengutronix.de
State Accepted
Commit 5dc63fa2c2e149dd3e8128e54c9ca251d0558ea0
Headers show

Commit Message

Uwe Kleine-König March 4, 2013, 4:35 p.m. UTC
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>
Forwarded: id:1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de
---

Notes:
    Changes since (implicit) v1, sent with
    Message-Id:1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de:
    
     - drop usage of a function pointer and accept minimal code duplication
       instead;
     - don't modify mfi->mode when returning -EINVAL;

 drivers/mtd/mtdchar.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

Comments

Artem Bityutskiy March 6, 2013, 8:47 a.m. UTC | #1
On Mon, 2013-03-04 at 17:35 +0100, Uwe Kleine-König wrote:
> 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>
> Forwarded: id:1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de

Pushed to l2-mtd.git, thanks.

I've removed the "Forwarded:" tag since I've never seen these to be used
before and not sure if this is an agreed practice.
Uwe Kleine-König March 6, 2013, 8:51 a.m. UTC | #2
On Wed, Mar 06, 2013 at 10:47:05AM +0200, Artem Bityutskiy wrote:
> On Mon, 2013-03-04 at 17:35 +0100, Uwe Kleine-König wrote:
> > 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>
> > Forwarded: id:1361182768-31919-1-git-send-email-u.kleine-koenig@pengutronix.de
> 
> Pushed to l2-mtd.git, thanks.
> 
> I've removed the "Forwarded:" tag since I've never seen these to be used
> before and not sure if this is an agreed practice.
We use this internally at Pengutronix to keep track of what is already
sent. Usually I remove the tag before resubmission.

Having said that I think it doesn't hurt and tip documents the message
id, too. But there are more urgent problems to solve and I'm fine with
dropping the tag.

Thanks
Uwe
diff mbox

Patch

diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 82c0616..68959a3 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -370,28 +370,30 @@  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;
 
 	switch (mode) {
 	case MTD_OTP_FACTORY:
+		if (mtd_read_fact_prot_reg(mtd, -1, 0, &retlen, NULL) ==
+				-EOPNOTSUPP)
+			return -EOPNOTSUPP;
+
 		mfi->mode = MTD_FILE_MODE_OTP_FACTORY;
 		break;
 	case MTD_OTP_USER:
+		if (mtd_read_user_prot_reg(mtd, -1, 0, &retlen, NULL) ==
+				-EOPNOTSUPP)
+			return -EOPNOTSUPP;
+
 		mfi->mode = MTD_FILE_MODE_OTP_USER;
 		break;
-	default:
-		ret = -EINVAL;
 	case MTD_OTP_OFF:
+		mfi->mode = MTD_FILE_MODE_NORMAL;
 		break;
+	default:
+		return -EINVAL;
 	}
-	return ret;
+
+	return 0;
 }
 #else
 # define otp_select_filemode(f,m)	-EOPNOTSUPP