public inbox for linux-sh@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Simon Holm Thøgersen" <odie@cs.aau.dk>
Cc: Adrian McMenamin <adrian@newgolddream.dyndns.info>,
	Paul Mundt <lethal@linux-sh.org>,
	Jens Axboe <jens.axboe@oracle.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-sh <linux-sh@vger.kernel.org>
Subject: Re: [PATCH] SH/Dreamcast - add support for GD-Rom device
Date: Sat, 29 Dec 2007 01:57:49 +0000	[thread overview]
Message-ID: <1198893469.4861.9.camel@localhost> (raw)
In-Reply-To: <1198801142.5354.67.camel@odie>

On Fri, 2007-12-28 at 01:18 +0100, Simon Holm Thøgersen wrote:
> > -	while ((ctrl_inb(GDROM_ALTSTATUS_REG) & 0x80) && (time_before(jiffies, timeout)))
> > +	while (gdrom_is_busy() && (time_before(jiffies, timeout)))
> You don't need those parentheses.
> > +		while (((ctrl_inb(GDROM_ALTSTATUS_REG) & 0x88) != 8) &&
> > +		       (time_before(jiffies, timeout)))
> What about a nice telling function like gdrom_is_busy for this?

Perhaps (uncompiled/untested):

    Remove unnecessary parenthesis
    Remove GDROM: prefix from sense_texts
    Add function gdrom_data_request
    Check sense_key against sense_text array size

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/cdrom/gdrom.c |   53 ++++++++++++++++++++++++++----------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 59d26e0..ab95438 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -80,16 +80,15 @@ static const struct {
 	int sense_key;
 	const char * const text;
 } sense_texts[] = {
-	{NO_SENSE, "GDROM: OK"},
-	{RECOVERED_ERROR, "GDROM: Recovered from error"},
-	{NOT_READY, "GDROM: Device not ready"},
-	{MEDIUM_ERROR, "GDROM: Disk not ready"},
-	{HARDWARE_ERROR, "GDROM: Hardware error"},
-	{ILLEGAL_REQUEST, "GDROM: Command has failed"},
-	{UNIT_ATTENTION, "GDROM: Device needs attention - "
-			 "disk may have been changed"},
-	{DATA_PROTECT, "GDROM: Data protection error"},
-	{ABORTED_COMMAND, "GDROM: Command aborted"},
+	{NO_SENSE, "OK"},
+	{RECOVERED_ERROR, "Recovered from error"},
+	{NOT_READY, "Device not ready"},
+	{MEDIUM_ERROR, "Disk not ready"},
+	{HARDWARE_ERROR, "Hardware error"},
+	{ILLEGAL_REQUEST, "Command has failed"},
+	{UNIT_ATTENTION, "Device needs attention - disk may have been changed"},
+	{DATA_PROTECT, "Data protection error"},
+	{ABORTED_COMMAND, "Command aborted"},
 };
 
 static struct platform_device *pd;
@@ -140,11 +139,16 @@ static bool gdrom_is_busy(void)
 	return (ctrl_inb(GDROM_ALTSTATUS_REG) & 0x80) != 0;
 }
 
+static bool gdrom_data_request(void)
+{
+	return (ctrl_inb(GDROM_ALTSTATUS_REG) & 0x88) = 8;
+}
+
 static void gdrom_wait_clrbusy(void)
 {
 	/* long timeouts - typical for a CD Rom */
 	unsigned long timeout = jiffies + HZ * 60;
-	while (gdrom_is_busy() && (time_before(jiffies, timeout)))
+	while (gdrom_is_busy() && time_before(jiffies, timeout))
 		cpu_relax();
 }
 
@@ -153,7 +157,7 @@ static void gdrom_wait_busy_sleeps(void)
 	unsigned long timeout;
 	/* Wait to get busy first */
 	timeout = jiffies + HZ * 60;
-	while (!gdrom_is_busy() && (time_before(jiffies, timeout)))
+	while (!gdrom_is_busy() && time_before(jiffies, timeout))
 		cpu_relax();
 	/* Now wait for busy to clear */
 	gdrom_wait_clrbusy();
@@ -186,8 +190,8 @@ static void gdrom_spicommand(void *spi_string, int buflen)
 	/* Wait until we can go */
 	gdrom_wait_clrbusy();
 	ctrl_outb(GDROM_COM_PACKET, GDROM_STATUSCOMMAND_REG);
-	while ((ctrl_inb(GDROM_ALTSTATUS_REG) & 0x88) != 8)
-		cpu_relax(); /* wait for DRQ to be set to 1 */
+	while (!gdrom_data_request())
+		cpu_relax();
 	outsw(PHYSADDR(GDROM_DATA_REG), cmd, 6);
 }
 
@@ -354,7 +358,7 @@ static int gdrom_drivestatus(struct cdrom_device_info *cd_info, int ignore)
 static int gdrom_mediachanged(struct cdrom_device_info *cd_info, int ignore)
 {
 	/* check the sense key */
-	return ((ctrl_inb(GDROM_ERROR_REG) & 0xF0) = 0x60);
+	return (ctrl_inb(GDROM_ERROR_REG) & 0xF0) = 0x60;
 }
 
 /* reset the G1 bus */
@@ -412,11 +416,13 @@ static int gdrom_getsense(short *bufstring)
 		return -EIO;
 	}
 	sense_key = sense[1] & 0x0F;
-	printk(KERN_INFO "%s\n", sense_texts[sense_key].text);
+	if (sense_key < ARRAY_SIZE(sense_texts))
+		printk(KERN_INFO "GDROM: %s\n", sense_texts[sense_key].text);
+	else
+		printk(KERN_ERR "GDROM: Unknown sense key: %d\n", sense_key);
 
-	if (bufstring)
+	if (bufstring)			/* return additional sense data */
 		memcpy(bufstring, &sense[4], 2);
-					/* return additional sense data */
 
 	if (sense_key < 2)
 		return 0;
@@ -550,19 +556,18 @@ static void gdrom_readdisk_dma(struct work_struct *work)
 		ctrl_outb(0, GDROM_INTSEC_REG);
 		/* In multiple DMA transfers need to wait */
 		timeout = jiffies + HZ / 2;
-		while (gdrom_is_busy() && (time_before(jiffies, timeout)))
+		while (gdrom_is_busy() && time_before(jiffies, timeout))
 			cpu_relax();
 		ctrl_outb(GDROM_COM_PACKET, GDROM_STATUSCOMMAND_REG);
 		timeout = jiffies + HZ / 2;
-		while (((ctrl_inb(GDROM_ALTSTATUS_REG) & 0x88) != 8) &&
-		       (time_before(jiffies, timeout)))
-			cpu_relax(); /* wait for DRQ to be set to 1 */
+		while (!gdrom_data_request() && time_before(jiffies, timeout))
+			cpu_relax();
 		gd.pending = 1;
 		gd.transfer = 1;
 		outsw(PHYSADDR(GDROM_DATA_REG), &read_command->cmd, 6);
 		timeout = jiffies + HZ / 2;
-		while ((ctrl_inb(GDROM_DMA_STATUS_REG)) &&
-		       (time_before(jiffies, timeout)))
+		while (ctrl_inb(GDROM_DMA_STATUS_REG) &&
+		       time_before(jiffies, timeout))
 			cpu_relax();
 		ctrl_outb(1, GDROM_DMA_STATUS_REG);
 		/* 5 second error margin here seems more reasonable */



  reply	other threads:[~2007-12-29  1:57 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-27  1:26 [PATCH] SH/Dreamcast - add support for GD-Rom device Adrian McMenamin
2007-12-27  8:18 ` Paul Mundt
2007-12-27 12:49   ` Adrian McMenamin
2007-12-27 19:52     ` Jens Axboe
2007-12-27 19:11   ` Mike Frysinger
2007-12-27 16:52 ` Adrian McMenamin
2007-12-27 20:56   ` Adrian McMenamin
2007-12-27 22:20   ` Paul Mundt
2007-12-27 22:58   ` Joe Perches
2007-12-28  0:18     ` Simon Holm Thøgersen
2007-12-29  1:57       ` Joe Perches [this message]
2007-12-29 12:03         ` Adrian McMenamin
2007-12-29 12:10           ` Adrian McMenamin
2007-12-29 18:07           ` Joe Perches
2007-12-28  0:49     ` Mike Frysinger
2007-12-28  3:41       ` Paul Mundt
2007-12-28 19:17     ` Gino Badouri
2007-12-28 22:09       ` Joe Perches
2007-12-30 13:38     ` Adrian McMenamin
2007-12-31  5:23       ` Paul Mundt
2008-01-10 23:25 ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Adrian McMenamin
2008-01-11 21:56   ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Adrian McMenamin
2008-01-12 11:57     ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Jens Axboe
2008-01-12 13:36     ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Andrew Morton
2008-01-12 14:14       ` Adrian McMenamin
2008-01-12 19:15         ` Andrew Morton
2008-01-13 18:24           ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Adrian McMenamin
2008-01-14 23:00       ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Adrian McMenamin
2008-01-14 23:17         ` Adrian McMenamin
2008-01-15  0:29           ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Paul Mundt
2008-01-15 20:41             ` Adrian McMenamin
2008-01-16 23:57           ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Adrian McMenamin
2008-01-17  1:27             ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Paul Mundt
2008-01-17 22:30               ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Adrian McMenamin
2008-01-18  0:56                 ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Paul Mundt
2008-01-28  5:33                   ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on Andrew Morton
2008-01-28  5:53                     ` [PATCH] SH/Dreamcast - add support for GD-Rom CDROM drive on SEGA Dreamcast Paul Mundt
2008-01-16  1:57       ` Paul Mundt

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=1198893469.4861.9.camel@localhost \
    --to=joe@perches.com \
    --cc=adrian@newgolddream.dyndns.info \
    --cc=jens.axboe@oracle.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=odie@cs.aau.dk \
    /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