From patchwork Tue Sep 6 19:21:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan McGee X-Patchwork-Id: 113661 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E07D8B6F70 for ; Wed, 7 Sep 2011 05:22:06 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754546Ab1IFTWF (ORCPT ); Tue, 6 Sep 2011 15:22:05 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:52070 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754378Ab1IFTWE (ORCPT ); Tue, 6 Sep 2011 15:22:04 -0400 Received: by gwaa12 with SMTP id a12so3755703gwa.19 for ; Tue, 06 Sep 2011 12:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=0xb9EH2Xsst32c8m48Z02gSVSQTn00t6VzPBZdO73vk=; b=H0w8e+n0VRaVR+l2GpSkq/KAJr9mx02/RcunDs8tWle04pEvLQpaMulX0pydUKR9Vp RxMqFGefRrUSyuwUpxZOqVihxiMvT+y8grHNvg58gOBfpUqFk+B8GirbKwUfGk2ovlbX 5xlHdbuUGG4rikpnhq+PjMzuwuA7fykl4eOFc= Received: by 10.150.238.11 with SMTP id l11mr3221265ybh.442.1315336922642; Tue, 06 Sep 2011 12:22:02 -0700 (PDT) Received: from localhost (c-71-239-242-45.hsd1.il.comcast.net [71.239.242.45]) by mx.google.com with ESMTPS id k12sm12879ybf.27.2011.09.06.12.22.00 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 06 Sep 2011 12:22:01 -0700 (PDT) From: Dan McGee To: linux-ide@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Jeff Garzik Subject: [PATCH 1/2] pata_sis: extract a sis_port_base() method Date: Tue, 6 Sep 2011 14:21:58 -0500 Message-Id: <1315336919-2737-1-git-send-email-dpmcgee@gmail.com> X-Mailer: git-send-email 1.7.6.1 Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org This is similar to the existing sis_old_port_base() method. We do this same calculation and logic in multiple places (with one more to come in a future patch), so extracting it into a method makes sense. Reviewed-by: Bartlomiej Zolnierkiewicz Signed-off-by: Dan McGee --- drivers/ata/pata_sis.c | 46 ++++++++++++++++++++++++++++------------------ 1 files changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c index 533f2ae..9374400 100644 --- a/drivers/ata/pata_sis.c +++ b/drivers/ata/pata_sis.c @@ -89,6 +89,29 @@ static int sis_old_port_base(struct ata_device *adev) } /** + * sis_port_base - return PCI configuration base for dev + * @adev: device + * + * Returns the base of the PCI configuration registers for this port + * number. + */ + +static int sis_port_base(struct ata_device *adev) +{ + struct ata_port *ap = adev->link->ap; + struct pci_dev *pdev = to_pci_dev(ap->host->dev); + int port = 0x40; + u32 reg54; + + /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ + pci_read_config_dword(pdev, 0x54, ®54); + if (reg54 & 0x40000000) + port = 0x70; + + return port + (8 * ap->port_no) + (4 * adev->devno); +} + +/** * sis_133_cable_detect - check for 40/80 pin * @ap: Port * @deadline: deadline jiffies for the operation @@ -266,9 +289,8 @@ static void sis_100_set_piomode (struct ata_port *ap, struct ata_device *adev) static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); - int port = 0x40; + int port; u32 t1; - u32 reg54; int speed = adev->pio_mode - XFER_PIO_0; const u32 timing133[] = { @@ -288,12 +310,7 @@ static void sis_133_set_piomode (struct ata_port *ap, struct ata_device *adev) sis_set_fifo(ap, adev); - /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ - pci_read_config_dword(pdev, 0x54, ®54); - if (reg54 & 0x40000000) - port = 0x70; - port += 8 * ap->port_no + 4 * adev->devno; - + port = sis_port_base(adev); pci_read_config_dword(pdev, port, &t1); t1 &= 0xC0C00FFF; /* Mask out timing */ @@ -465,21 +482,14 @@ static void sis_133_early_set_dmamode (struct ata_port *ap, struct ata_device *a static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev) { struct pci_dev *pdev = to_pci_dev(ap->host->dev); - int speed = adev->dma_mode - XFER_MW_DMA_0; - int port = 0x40; + int port; u32 t1; - u32 reg54; /* bits 4- cycle time 8 - cvs time */ static const u32 timing_u100[] = { 0x6B0, 0x470, 0x350, 0x140, 0x120, 0x110, 0x000 }; static const u32 timing_u133[] = { 0x9F0, 0x6A0, 0x470, 0x250, 0x230, 0x220, 0x210 }; - /* If bit 14 is set then the registers are mapped at 0x70 not 0x40 */ - pci_read_config_dword(pdev, 0x54, ®54); - if (reg54 & 0x40000000) - port = 0x70; - port += (8 * ap->port_no) + (4 * adev->devno); - + port = sis_port_base(adev); pci_read_config_dword(pdev, port, &t1); if (adev->dma_mode < XFER_UDMA_0) { @@ -487,7 +497,7 @@ static void sis_133_set_dmamode (struct ata_port *ap, struct ata_device *adev) /* FIXME: need data sheet to add MWDMA here. Also lacking on ide/pci driver */ } else { - speed = adev->dma_mode - XFER_UDMA_0; + int speed = adev->dma_mode - XFER_UDMA_0; /* if & 8 no UDMA133 - need info for ... */ t1 &= ~0x00000FF0; t1 |= 0x00000004;