From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 06/11] mtd: cfi-flash: make flash_detect_width more readable
Date: Mon, 22 Jun 2015 10:41:01 +0200 [thread overview]
Message-ID: <1434962466-23590-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1434962466-23590-1-git-send-email-s.hauer@pengutronix.de>
Use variables instead of long defines to get the loops into a single
line. Also use goto to move the deeply indented code more to the left.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/mtd/nor/cfi_flash.c | 63 +++++++++++++++++++++++++--------------------
1 file changed, 35 insertions(+), 28 deletions(-)
diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c
index 762a6c6..a369b46 100644
--- a/drivers/mtd/nor/cfi_flash.c
+++ b/drivers/mtd/nor/cfi_flash.c
@@ -224,42 +224,49 @@ static void flash_read_cfi (struct flash_info *info, void *buf,
p[i] = flash_read_uchar(info, start + i);
}
-static int flash_detect_width (struct flash_info *info, struct cfi_qry *qry)
+static int flash_detect_width(struct flash_info *info, struct cfi_qry *qry)
{
int cfi_offset;
+ int pw, cw;
+ for (pw = CFG_FLASH_CFI_WIDTH; pw <= FLASH_CFI_64BIT; pw <<= 1) {
+ for (cw = FLASH_CFI_BY8; cw <= pw; cw <<= 1) {
+ info->chipwidth = cw;
+ info->portwidth = pw;
- for (info->portwidth = CFG_FLASH_CFI_WIDTH;
- info->portwidth <= FLASH_CFI_64BIT; info->portwidth <<= 1) {
- for (info->chipwidth = FLASH_CFI_BY8;
- info->chipwidth <= info->portwidth;
- info->chipwidth <<= 1) {
- flash_write_cmd (info, 0, 0, AMD_CMD_RESET);
- flash_write_cmd (info, 0, 0, FLASH_CMD_RESET);
- for (cfi_offset=0; cfi_offset < sizeof(flash_offset_cfi)/sizeof(uint); cfi_offset++) {
- flash_write_cmd (info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI);
- if (flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP, 'Q')
- && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R')
- && flash_isequal (info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y')) {
- flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP,
- sizeof(struct cfi_qry));
- info->interface = le16_to_cpu(qry->interface_desc);
-
- info->cfi_offset=flash_offset_cfi[cfi_offset];
- dev_dbg(info->dev, "device interface is %d\n",
- info->interface);
- dev_dbg(info->dev, "found port %d chip %d chip_lsb %d ",
- info->portwidth, info->chipwidth, info->chip_lsb);
- dev_dbg(info->dev, "port %d bits chip %d bits\n",
- info->portwidth << CFI_FLASH_SHIFT_WIDTH,
- info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
- return 1;
- }
+ flash_write_cmd(info, 0, 0, AMD_CMD_RESET);
+ flash_write_cmd(info, 0, 0, FLASH_CMD_RESET);
+
+ for (cfi_offset = 0; cfi_offset < sizeof(flash_offset_cfi) / sizeof(uint);
+ cfi_offset++) {
+
+ flash_write_cmd(info, 0, flash_offset_cfi[cfi_offset], FLASH_CMD_CFI);
+
+ if (flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP, 'Q') &&
+ flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 1, 'R') &&
+ flash_isequal(info, 0, FLASH_OFFSET_CFI_RESP + 2, 'Y'))
+ goto found;
}
}
}
- dev_dbg(info->dev, "not found\n");
+
+ dev_dbg(info->dev, "no flash found\n");
+
return 0;
+
+found:
+ flash_read_cfi(info, qry, FLASH_OFFSET_CFI_RESP,
+ sizeof(struct cfi_qry));
+ info->interface = le16_to_cpu(qry->interface_desc);
+ info->cfi_offset=flash_offset_cfi[cfi_offset];
+ dev_dbg(info->dev, "device interface is %d\n", info->interface);
+ dev_dbg(info->dev, "found port %d chip %d chip_lsb %d ",
+ info->portwidth, info->chipwidth, info->chip_lsb);
+ dev_dbg(info->dev, "port %d bits chip %d bits\n",
+ info->portwidth << CFI_FLASH_SHIFT_WIDTH,
+ info->chipwidth << CFI_FLASH_SHIFT_WIDTH);
+
+ return 1;
}
static int flash_detect_cfi (struct flash_info *info, struct cfi_qry *qry)
--
2.1.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-06-22 8:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-22 8:40 cfi-flash cleanups Sascha Hauer
2015-06-22 8:40 ` [PATCH 01/11] mtd: cfi-flash: We can print longlongs Sascha Hauer
2015-06-22 8:40 ` [PATCH 02/11] mtd: cfi-flash: save indention level Sascha Hauer
2015-06-22 8:40 ` [PATCH 03/11] mtd: cfi-flash: statically initialize instead of memset Sascha Hauer
2015-06-22 8:40 ` [PATCH 04/11] mtd: cfi-flash: replace ifdef with IS_ENABLED Sascha Hauer
2015-06-22 8:41 ` [PATCH 05/11] mtd: cfi-flash: remove unnecessary ifdefs Sascha Hauer
2015-06-22 8:41 ` Sascha Hauer [this message]
2015-06-22 8:41 ` [PATCH 07/11] mtd: cfi-flash: return 0 for success Sascha Hauer
2015-06-22 8:41 ` [PATCH 08/11] mtd: cfi-flash: turn some messages into vdbg Sascha Hauer
2015-06-22 8:41 ` [PATCH 09/11] mtd: cfi-flash: use unaligned accessor functions Sascha Hauer
2015-06-22 8:41 ` [PATCH 10/11] mtd: cfi-flash: Coding style cleanup Sascha Hauer
2015-06-22 8:41 ` [PATCH 11/11] mtd: cfi-flash: remove dead code Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434962466-23590-7-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox