From patchwork Thu Oct 20 21:00:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyle Moffett X-Patchwork-Id: 120902 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B73781007D1 for ; Fri, 21 Oct 2011 08:15:47 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751749Ab1JTVNY (ORCPT ); Thu, 20 Oct 2011 17:13:24 -0400 Received: from 26.241.167.70.in-addr.border.exmeritus.com ([70.167.241.26]:35669 "EHLO border.exmeritus.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752511Ab1JTVNV (ORCPT ); Thu, 20 Oct 2011 17:13:21 -0400 Received: from ysera.exmeritus.com (firewall2.exmeritus.com [10.13.38.2]) by border.exmeritus.com (Postfix) with ESMTP id CFF31AC0AB; Thu, 20 Oct 2011 17:03:40 -0400 (EDT) From: Kyle Moffett To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Kyle Moffett , David Miller , Stephen Hemminger , Andrew Morton , Mike Frysinger Subject: [RFC PATCH 16/17] phy_device: Add phy_setmask helper function Date: Thu, 20 Oct 2011 17:00:23 -0400 Message-Id: <1319144425-15547-17-git-send-email-Kyle.D.Moffett@boeing.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1319144425-15547-1-git-send-email-Kyle.D.Moffett@boeing.com> References: <1319144425-15547-1-git-send-email-Kyle.D.Moffett@boeing.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In the PHY layer there are frequently occasions when code needs to modify only some subset of the bits in a particular 16-bit register. To clean up the flow control and improve readability a phy_setmask() helper function is added. Signed-off-by: Kyle Moffett --- include/linux/phy.h | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/include/linux/phy.h b/include/linux/phy.h index 0cb300d..3713c8d 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -474,6 +474,26 @@ static inline int phy_write(struct phy_device *phydev, u32 regnum, u16 val) return mdiobus_write(phydev->bus, phydev->addr, regnum, val); } +/** + * phy_setmask - Convenience function for changing PHY register bits + * @phydev: the phy_device struct + * @regnum: register number to write + * @val: value to write to the @mask bits of @regnum + * @mask: the mask of bits to change + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +static inline int phy_setmask(struct phy_device *phydev, u16 regnum, + u16 val, u16 mask) +{ + int ret = phy_read(phydev, regnum); + if (ret < 0) + return ret; + return phy_write(phydev, regnum, (ret & ~mask) | (val & mask)); +} + int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id); struct phy_device* get_phy_device(struct mii_bus *bus, int addr); int phy_device_register(struct phy_device *phy);