From patchwork Mon Feb 20 04:50:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atsushi Nemoto X-Patchwork-Id: 9581993 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 505A660578 for ; Mon, 20 Feb 2017 05:12:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4109728860 for ; Mon, 20 Feb 2017 05:12:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33C9628863; Mon, 20 Feb 2017 05:12:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4986C28860 for ; Mon, 20 Feb 2017 05:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750872AbdBTFMX (ORCPT ); Mon, 20 Feb 2017 00:12:23 -0500 Received: from ms2.toshiba-tops.co.jp ([61.200.21.4]:43702 "EHLO dmz-ms2.toshiba-tops.co.jp" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750737AbdBTFMW (ORCPT ); Mon, 20 Feb 2017 00:12:22 -0500 X-Greylist: delayed 602 seconds by postgrey-1.27 at vger.kernel.org; Mon, 20 Feb 2017 00:12:22 EST Received: from [192.168.254.254] ([192.168.254.254]) by dmz-ms2.toshiba-tops.co.jp ([192.168.254.3]) with ESMTP id 1487566224.599133.3045854112.dmz-ms2 for <>; Mon, 20 Feb 2017 13:50:24 +0900 (JST) Received: from localhost (172.17.28.65) by TPSSRV64.toshiba-tops.co.jp (172.16.4.164) with Microsoft SMTP Server id 14.2.318.1; Mon, 20 Feb 2017 13:50:15 +0900 Date: Mon, 20 Feb 2017 13:50:14 +0900 Message-ID: <20170220.135014.415950098927632727.nemoto@toshiba-tops.co.jp> To: CC: Jean Delvare , Guenter Roeck , Subject: [PATCH] hwmon: (w83627ehf) Use request_muxed_region X-TERRACE-DUMMYSUBJECT: Terrace Spam system * From: Atsushi Nemoto X-Fingerprint: 6ACA 1623 39BD 9A94 9B1A B746 CA77 FE94 2874 D52F X-Pgp-Public-Key: http://wwwkeys.pgp.net:11371/pks/lookup?op=get&search=0x2874D52F X-Mailer: Mew version 6.5 on Emacs 24.3 / Mule 6.0 (HANACHIRUSATO) MIME-Version: 1.0 X-TERRACE-SPAMMARK: NO (SR:34.22) (by Terrace) X-TERRACE-SID: 1487566224.599133.3045854112.dmz-ms2 X-TERRACE-CLASSID: Terrace Spam system Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Katsumi Sato Serialize access to the hardware by using "request_muxed_region". Call to this macro will hold off the requestor if the resource is currently busy. "superio_enter" will return an error if call to "request_muxed_region" fails. Signed-off-by: Katsumi Sato Signed-off-by: Atsushi Nemoto --- drivers/hwmon/w83627ehf.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 697007a..40cb8fa 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -135,11 +135,16 @@ enum kinds { outb(ld, ioreg + 1); } -static inline void +static inline int superio_enter(int ioreg) { + if (!request_muxed_region(ioreg, 2, DRVNAME)) + return -EBUSY; + outb(0x87, ioreg); outb(0x87, ioreg); + + return 0; } static inline void @@ -148,6 +153,7 @@ enum kinds { outb(0xaa, ioreg); outb(0x02, ioreg); outb(0x02, ioreg + 1); + release_region(ioreg, 2); } /* @@ -1970,7 +1976,10 @@ static void w82627ehf_swap_tempreg(struct w83627ehf_data *data, return; } - superio_enter(sio_data->sioreg); + if (superio_enter(sio_data->sioreg)) { + pr_err("%s: superio is busy!!\n", __func__); + return; + } /* fan4 and fan5 share some pins with the GPIO and serial flash */ if (sio_data->kind == nct6775) { @@ -2352,7 +2361,11 @@ static int w83627ehf_probe(struct platform_device *pdev) w83627ehf_init_device(data, sio_data->kind); data->vrm = vid_which_vrm(); - superio_enter(sio_data->sioreg); + + err = superio_enter(sio_data->sioreg); + if (err) + goto exit_release; + /* Read VID value */ if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b || sio_data->kind == nct6775 || sio_data->kind == nct6776) { @@ -2364,8 +2377,10 @@ static int w83627ehf_probe(struct platform_device *pdev) superio_select(sio_data->sioreg, W83667HG_LD_VID); data->vid = superio_inb(sio_data->sioreg, 0xe3); err = device_create_file(dev, &dev_attr_cpu0_vid); - if (err) + if (err) { + superio_exit(sio_data->sioreg); goto exit_release; + } } else if (sio_data->kind != w83627uhg) { superio_select(sio_data->sioreg, W83627EHF_LD_HWM); if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { @@ -2401,8 +2416,10 @@ static int w83627ehf_probe(struct platform_device *pdev) data->vid &= 0x3f; err = device_create_file(dev, &dev_attr_cpu0_vid); - if (err) + if (err) { + superio_exit(sio_data->sioreg); goto exit_release; + } } else { dev_info(dev, "VID pins in output mode, CPU VID not available\n"); @@ -2712,8 +2729,11 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr, u16 val; const char *sio_name; + int err; - superio_enter(sioaddr); + err = superio_enter(sioaddr); + if (err) + return err; if (force_id) val = force_id;