linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergei Shtylyov <sshtylyov@ru.mvista.com>
To: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Cc: linux-mips@linux-mips.org, linux-ide@vger.kernel.org,
	Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>,
	ralf@linux-mips.org
Subject: Re: [PATCH 1/2] ide: Add tx4939ide driver
Date: Fri, 12 Sep 2008 02:33:12 +0400	[thread overview]
Message-ID: <48C99CA8.5030602@ru.mvista.com> (raw)
In-Reply-To: <20080910.010824.07456636.anemo@mba.ocn.ne.jp>

Hello.

Atsushi Nemoto wrote:

> This is the driver for the Toshiba TX4939 SoC ATA controller.
>
> This controller has standard ATA taskfile registers and DMA
> command/status registers, but the register layout is swapped on big
> endian.  There are some other endian issue and some special registers
> which requires many custom dma_ops/port_ops routines.
>
> Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
>   
[...]
> diff --git a/drivers/ide/mips/tx4939ide.c b/drivers/ide/mips/tx4939ide.c
> new file mode 100644
> index 0000000..ba9776d
> --- /dev/null
> +++ b/drivers/ide/mips/tx4939ide.c
> @@ -0,0 +1,762 @@
>   
[...]
> +static void tx4939ide_dma_host_set(ide_drive_t *drive, int on)
> +{
> +	ide_hwif_t *hwif	= HWIF(drive);
> +	u8 unit			= drive->dn & 1;
> +	unsigned long base = TX4939IDE_BASE(hwif);
> +	u8 dma_stat = TX4939IDE_readb(base, DMA_stat);
> +
> +	if (on)
> +		dma_stat |= (1 << (5 + unit));
> +	else
> +		dma_stat &= ~(1 << (5 + unit));
> +
> +	TX4939IDE_writeb(dma_stat, base, DMA_stat);
> +}
>   

   BTW, you could save on using ide_dma_host_set() in LE mode if you'd 
set hwif->dma_base properly...

> +static int __tx4939ide_dma_setup(ide_drive_t *drive)
> +{
> +	ide_hwif_t *hwif = drive->hwif;
> +	struct request *rq = HWGROUP(drive)->rq;
> +	unsigned int reading;
> +	u8 dma_stat;
> +	unsigned long base = TX4939IDE_BASE(hwif);
> +
[...]
> +
> +	/* read DMA status for INTR & ERROR flags */
> +	dma_stat = TX4939IDE_readb(base, DMA_stat);
> +
> +	/* clear INTR & ERROR flags */
> +	TX4939IDE_writeb(dma_stat | 6, base, DMA_stat);
> +	/* recover intmask cleared by writing to bit2 of DMA_stat */
> +	TX4939IDE_writew(TX4939IDE_IGNORE_INTS << 8, base, int_ctl);
>   

   I think it might be worth factoring the BMDMA status clearing code 
into a separate function...

> +
> +	drive->waiting_for_dma = 1;
> +	return 0;
> +}
> +
> +static int tx4939ide_dma_setup(ide_drive_t *drive)
> +{
> +	ide_hwif_t *hwif = HWIF(drive);
> +	unsigned long base = TX4939IDE_BASE(hwif);
> +	int is_slave = drive->dn & 1;
> +	unsigned int nframes;
> +	int rc, i;
> +	unsigned int sect_size = queue_hardsect_size(drive->queue);
> +	u16 select_data;
> +
> +	select_data = (hwif->select_data >> (is_slave ? 16 : 0)) & 0xffff;
> +	TX4939IDE_writew(select_data, base, Sys_Ctl);
> +	if (is_slave)
> +		TX4939IDE_writew(sect_size / 2, base, Xfer_Cnt_2);
> +	else
> +		TX4939IDE_writew(sect_size / 2, base, Xfer_Cnt_1);
> +
> +	rc = __tx4939ide_dma_setup(drive);
>   

   Hm, I think you need to call this earlier and do an early exit if it 
returns 1.

> +	if (rc == 0) {
>   

   Better check for !=0, return early and avoid unnecessary 
indentatiuon, isn't it?

> +		/* Number of sectors to transfer. */
> +		nframes = 0;
> +		for (i = 0; i < hwif->sg_nents; i++)
> +			nframes += sg_dma_len(&hwif->sg_table[i]);
> +		BUG_ON(nframes % sect_size != 0);
> +		nframes /= sect_size;
> +		BUG_ON(nframes == 0);
> +		TX4939IDE_writew(nframes, base, Sec_Cnt);
> +	}
> +	return rc;
> +}
> +
> +static void tx4939ide_dma_start(ide_drive_t *drive)
> +{
> +	ide_hwif_t *hwif = drive->hwif;
> +	unsigned long base = TX4939IDE_BASE(hwif);
> +	u8 dma_cmd;
> +
> +	/* Note that this is done *after* the cmd has
> +	 * been issued to the drive, as per the BM-IDE spec.
> +	 */
> +	dma_cmd = TX4939IDE_readb(base, DMA_Cmd);
> +	/* start DMA */
> +	TX4939IDE_writeb(dma_cmd | 1, base, DMA_Cmd);
> +
> +	wmb();
> +}
>   

   You could save by using ide_dma_start() in LE mode too...

> +#ifdef __BIG_ENDIAN
> +/* custom iops (independent from SWAP_IO_SPACE) */
> +static u8 mm_inb(unsigned long port)
> +{
> +	return (u8)readb((void __iomem *)port);
> +}
> +static void mm_outb(u8 value, unsigned long port)
> +{
> +	writeb(value, (void __iomem *)port);
> +}
>   

   I'm not sure readb()/writeb() are good substitute for 
__raw_readb()/__raw_writeb() as __swizzle_addr_b() might be actually 
changing the address...

MBR, Sergei



  parent reply	other threads:[~2008-09-11 22:33 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-09 16:08 [PATCH 1/2] ide: Add tx4939ide driver Atsushi Nemoto
2008-09-09 16:44 ` Alan Cox
2008-09-09 17:08   ` Sergei Shtylyov
2008-09-10 15:12     ` Atsushi Nemoto
2008-09-10 15:06   ` Atsushi Nemoto
2008-09-13 13:37     ` Atsushi Nemoto
2008-09-09 17:50 ` Sergei Shtylyov
2008-09-10 15:32   ` Atsushi Nemoto
2008-09-10 15:55     ` Sergei Shtylyov
2008-09-10 16:25       ` Sergei Shtylyov
2008-09-11 15:03       ` Atsushi Nemoto
2008-09-11 15:18         ` Sergei Shtylyov
2008-09-10 23:02 ` Sergei Shtylyov
2008-09-11 15:52   ` Atsushi Nemoto
2008-09-12 15:34     ` Sergei Shtylyov
2008-09-12 15:59       ` Atsushi Nemoto
2008-09-12 16:44         ` Sergei Shtylyov
2008-09-12 17:19         ` Sergei Shtylyov
2008-09-13 12:32           ` Atsushi Nemoto
2008-09-16 21:15             ` Sergei Shtylyov
2008-09-16 21:39               ` Sergei Shtylyov
2008-09-27 16:19         ` Bartlomiej Zolnierkiewicz
2008-09-27 22:09           ` Tejun Heo
2008-09-30 13:07             ` Atsushi Nemoto
2008-09-30 15:09             ` James Bottomley
2008-10-04  2:56               ` Tejun Heo
2008-10-07 12:09                 ` Jens Axboe
2008-09-28  8:41           ` Ralf Baechle
2008-09-11 22:33 ` Sergei Shtylyov [this message]
2008-09-12 14:37   ` Atsushi Nemoto
2008-09-12 15:01     ` Sergei Shtylyov
2008-09-13 21:48 ` Sergei Shtylyov
2008-09-14 13:05   ` Atsushi Nemoto
2008-09-16 10:29     ` Sergei Shtylyov
2008-09-16 15:20       ` Atsushi Nemoto
2008-09-16 15:32         ` Sergei Shtylyov
2008-09-16 16:24         ` Sergei Shtylyov
2008-09-16 21:02           ` Sergei Shtylyov
2008-09-14 20:55   ` Sergei Shtylyov
2008-09-15 14:01     ` Atsushi Nemoto
2008-09-16 21:59 ` Sergei Shtylyov
2008-09-17 15:12   ` Atsushi Nemoto

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=48C99CA8.5030602@ru.mvista.com \
    --to=sshtylyov@ru.mvista.com \
    --cc=anemo@mba.ocn.ne.jp \
    --cc=bzolnier@gmail.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.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;
as well as URLs for NNTP newsgroup(s).