From patchwork Thu Jun 22 13:21:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QsO2c3rDtnJtw6lueWkgWm9sdMOhbg==?= X-Patchwork-Id: 779518 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 3wtj1c6RKDz9s87 for ; Thu, 22 Jun 2017 23:22:44 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=pr.hu header.i=@pr.hu header.b="hyUfger9"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753350AbdFVNW3 (ORCPT ); Thu, 22 Jun 2017 09:22:29 -0400 Received: from mail7.pr.hu ([87.242.0.7]:48728 "EHLO mail7.pr.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752332AbdFVNW1 (ORCPT ); Thu, 22 Jun 2017 09:22:27 -0400 Received: from [2a02:808:3:101::5] (helo=mail.pr.hu) by frontdoor.pr.hu with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1dO23m-0005It-84; Thu, 22 Jun 2017 15:22:10 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=pr.hu; s=pr20170203; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=QOp+JJlI1O4mymvrLnKKy2v0IzF/DZXosyO10wrKppg=; b=hyUfger9rVj9DxeSRweygJX0QV3BMHc2+YawXipsc5hu542eu9b2oHnAl+dJV95p3oXJ+SrZttpR6oCPZpWFPEUQxEmhzm+Bxw4PxXWRdtXuJdXk0ea2PhyC9tZIA3fbHa3D41N/2DPK7PKJraLO5e6rXU/4f6w9n4ocQqbWdcht0RaI8JXcUP0pcfNVQgV3qKra8U/BUxPRQ84So+IYMq/X2Gj+Xsm2fDc07m5jS/Ff5rkQC2CKrryzeugZQC7ympjCq8FQl+lgscSS6hvyO8HZokAx3/jb1X2DBPO53VMTVBc1TlaB38VVX5v4zpiuGoKhjBE1TWHI0NaXQS1uIg==; Received: from host-87-242-51-16.prtelecom.hu ([87.242.51.16] helo=s002.sicom.com) by mail.pr.hu with esmtpa (Exim 4.80) (envelope-from ) id 1dO23i-0000Fg-Aa; Thu, 22 Jun 2017 15:22:08 +0200 From: =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?= To: linux-kernel@vger.kernel.org Cc: linux-usb@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-i2c@vger.kernel.org, Paul Menzel , Christian Fetzer , Jean Delvare , Nehal Shah , Tim Small , Guenter Roeck , kernel@ekass.net, wim@iguana.be, jlayton@poochiereds.net, marc.2377@gmail.com, cshorler@googlemail.com, wsa@the-dreams.de, regressions@leemhuis.info, =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?= Subject: [PATCH 5/5 v4] watchdog: sp5100_tco: Use request_declared_muxed_region() Date: Thu, 22 Jun 2017 15:21:34 +0200 Message-Id: <20170622132134.7200-6-zboszor@pr.hu> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170622132134.7200-1-zboszor@pr.hu> References: <20170621035349.4125-1-zboszor@pr.hu> <20170622132134.7200-1-zboszor@pr.hu> MIME-Version: 1.0 X-Spam-Score: 0.3 (/) X-Scan-Signature: 4bde8b99861392d72ba365f4b27fc0a1 X-Spam-Tracer: backend.mail.pr.hu 0.3 20170622132208Z Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Use the new request_declared_muxed_region() macro to synchronize accesses to the SB800 I/O port pair (0xcd6 / 0xcd7) with the PCI quirk for isochronous USB transfers and with the i2c-piix4 driver. At the same time, remove the long lifetime request_region() call to reserve these I/O ports, similarly to i2c-piix4 so the code is now uniform across the three drivers. v1: Started with a common mutex in a C source file. v2: Referenced the common mutex from drivers/usb/host/pci-quirks.c v3: Switched to using the new request_declared_muxed_region macro. v4: Fixed checkpatch.pl warnings and use the new release_declared_region() macro. Signed-off-by: Zoltán Böszörményi --- drivers/watchdog/sp5100_tco.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/watchdog/sp5100_tco.c b/drivers/watchdog/sp5100_tco.c index 028618c..cb42b72 100644 --- a/drivers/watchdog/sp5100_tco.c +++ b/drivers/watchdog/sp5100_tco.c @@ -48,7 +48,6 @@ static u32 tcobase_phys; static u32 tco_wdt_fired; static void __iomem *tcobase; -static unsigned int pm_iobase; static DEFINE_SPINLOCK(tco_lock); /* Guards the hardware */ static unsigned long timer_alive; static char tco_expect_close; @@ -70,6 +69,11 @@ module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started." " (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +/* synchronized access to the I/O port pair */ +static struct resource sp5100_res = DEFINE_RES_IO_NAMED(SB800_IO_PM_INDEX_REG, + SP5100_PM_IOPORTS_SIZE, + TCO_MODULE_NAME); + /* * Some TCO specific functions */ @@ -139,6 +143,7 @@ static void tco_timer_enable(void) if (!tco_has_sp5100_reg_layout(sp5100_tco_pci)) { /* For SB800 or later */ /* Set the Watchdog timer resolution to 1 sec */ + request_declared_muxed_region(&sp5100_res); outb(SB800_PM_WATCHDOG_CONFIG, SB800_IO_PM_INDEX_REG); val = inb(SB800_IO_PM_DATA_REG); val |= SB800_PM_WATCHDOG_SECOND_RES; @@ -150,6 +155,7 @@ static void tco_timer_enable(void) val |= SB800_PCI_WATCHDOG_DECODE_EN; val &= ~SB800_PM_WATCHDOG_DISABLE; outb(val, SB800_IO_PM_DATA_REG); + release_declared_region(&sp5100_res); } else { /* For SP5100 or SB7x0 */ /* Enable watchdog decode bit */ @@ -164,11 +170,13 @@ static void tco_timer_enable(void) val); /* Enable Watchdog timer and set the resolution to 1 sec */ + request_declared_muxed_region(&sp5100_res); outb(SP5100_PM_WATCHDOG_CONTROL, SP5100_IO_PM_INDEX_REG); val = inb(SP5100_IO_PM_DATA_REG); val |= SP5100_PM_WATCHDOG_SECOND_RES; val &= ~SP5100_PM_WATCHDOG_DISABLE; outb(val, SP5100_IO_PM_DATA_REG); + release_declared_region(&sp5100_res); } } @@ -361,16 +369,10 @@ static unsigned char sp5100_tco_setupdevice(void) base_addr = SB800_PM_WATCHDOG_BASE; } - /* Request the IO ports used by this driver */ - pm_iobase = SP5100_IO_PM_INDEX_REG; - if (!request_region(pm_iobase, SP5100_PM_IOPORTS_SIZE, dev_name)) { - pr_err("I/O address 0x%04x already in use\n", pm_iobase); - goto exit; - } - /* * First, Find the watchdog timer MMIO address from indirect I/O. */ + request_declared_muxed_region(&sp5100_res); outb(base_addr+3, index_reg); val = inb(data_reg); outb(base_addr+2, index_reg); @@ -380,6 +382,7 @@ static unsigned char sp5100_tco_setupdevice(void) outb(base_addr+0, index_reg); /* Low three bits of BASE are reserved */ val = val << 8 | (inb(data_reg) & 0xf8); + release_declared_region(&sp5100_res); pr_debug("Got 0x%04x from indirect I/O\n", val); @@ -400,6 +403,7 @@ static unsigned char sp5100_tco_setupdevice(void) SP5100_SB_RESOURCE_MMIO_BASE, &val); } else { /* Read SBResource_MMIO from AcpiMmioEn(PM_Reg: 24h) */ + request_declared_muxed_region(&sp5100_res); outb(SB800_PM_ACPI_MMIO_EN+3, SB800_IO_PM_INDEX_REG); val = inb(SB800_IO_PM_DATA_REG); outb(SB800_PM_ACPI_MMIO_EN+2, SB800_IO_PM_INDEX_REG); @@ -408,6 +412,7 @@ static unsigned char sp5100_tco_setupdevice(void) val = val << 8 | inb(SB800_IO_PM_DATA_REG); outb(SB800_PM_ACPI_MMIO_EN+0, SB800_IO_PM_INDEX_REG); val = val << 8 | inb(SB800_IO_PM_DATA_REG); + release_declared_region(&sp5100_res); } /* The SBResource_MMIO is enabled and mapped memory space? */ @@ -429,7 +434,7 @@ static unsigned char sp5100_tco_setupdevice(void) pr_debug("SBResource_MMIO is disabled(0x%04x)\n", val); pr_notice("failed to find MMIO address, giving up.\n"); - goto unreg_region; + goto exit; setup_wdt: tcobase_phys = val; @@ -469,8 +474,6 @@ static unsigned char sp5100_tco_setupdevice(void) unreg_mem_region: release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); -unreg_region: - release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); exit: return 0; } @@ -517,7 +520,7 @@ static int sp5100_tco_init(struct platform_device *dev) exit: iounmap(tcobase); release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); - release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); + release_region(SB800_IO_PM_INDEX_REG, SP5100_PM_IOPORTS_SIZE); return ret; } @@ -531,7 +534,6 @@ static void sp5100_tco_cleanup(void) misc_deregister(&sp5100_tco_miscdev); iounmap(tcobase); release_mem_region(tcobase_phys, SP5100_WDT_MEM_MAP_SIZE); - release_region(pm_iobase, SP5100_PM_IOPORTS_SIZE); } static int sp5100_tco_remove(struct platform_device *dev)