Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753384AbaA3OaO (ORCPT ); Thu, 30 Jan 2014 09:30:14 -0500 Received: from smtp5.epfl.ch ([128.178.224.8]:54657 "EHLO smtp5.epfl.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753382AbaA3O3x (ORCPT ); Thu, 30 Jan 2014 09:29:53 -0500 From: Florian Vaussard To: Wolfgang Grandegger , Marc Kleine-Budde Cc: linux-can@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, florian.vaussard@epfl.ch, Grant Likely , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , devicetree@vger.kernel.org Subject: [PATCH 5/5] can: sja1000: of: add read/write routines for 8, 16 and 32-bit register access Date: Thu, 30 Jan 2014 15:29:28 +0100 Message-Id: <1391092168-21246-6-git-send-email-florian.vaussard@epfl.ch> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1391092168-21246-1-git-send-email-florian.vaussard@epfl.ch> References: <1391092168-21246-1-git-send-email-florian.vaussard@epfl.ch> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add routines for 8, 16 and 32-bit access like in sja1000_platform.c Cc: Grant Likely Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Cc: Kumar Gala Cc: devicetree@vger.kernel.org Signed-off-by: Florian Vaussard --- drivers/net/can/sja1000/sja1000_of_platform.c | 41 +++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/sja1000/sja1000_of_platform.c b/drivers/net/can/sja1000/sja1000_of_platform.c index 8ebb4af..a9a0696 100644 --- a/drivers/net/can/sja1000/sja1000_of_platform.c +++ b/drivers/net/can/sja1000/sja1000_of_platform.c @@ -55,17 +55,39 @@ MODULE_LICENSE("GPL v2"); #define SJA1000_OFP_CAN_CLOCK (16000000 / 2) -static u8 sja1000_ofp_read_reg(const struct sja1000_priv *priv, int reg) +static u8 sja1000_ofp_read_reg8(const struct sja1000_priv *priv, int reg) { return ioread8(priv->reg_base + reg); } -static void sja1000_ofp_write_reg(const struct sja1000_priv *priv, - int reg, u8 val) +static void sja1000_ofp_write_reg8(const struct sja1000_priv *priv, + int reg, u8 val) { iowrite8(val, priv->reg_base + reg); } +static u8 sja1000_ofp_read_reg16(const struct sja1000_priv *priv, int reg) +{ + return ioread8(priv->reg_base + reg * 2); +} + +static void sja1000_ofp_write_reg16(const struct sja1000_priv *priv, + int reg, u8 val) +{ + iowrite8(val, priv->reg_base + reg * 2); +} + +static u8 sja1000_ofp_read_reg32(const struct sja1000_priv *priv, int reg) +{ + return ioread8(priv->reg_base + reg * 4); +} + +static void sja1000_ofp_write_reg32(const struct sja1000_priv *priv, + int reg, u8 val) +{ + iowrite8(val, priv->reg_base + reg * 4); +} + static int sja1000_ofp_remove(struct platform_device *ofdev) { struct net_device *dev = platform_get_drvdata(ofdev); @@ -121,8 +143,17 @@ static int sja1000_ofp_probe(struct platform_device *ofdev) priv = netdev_priv(dev); - priv->read_reg = sja1000_ofp_read_reg; - priv->write_reg = sja1000_ofp_write_reg; + of_property_read_u32(np, "reg-io-width", &prop); + if (prop == 4) { + priv->read_reg = sja1000_ofp_read_reg32; + priv->write_reg = sja1000_ofp_write_reg32; + } else if (prop == 2) { + priv->read_reg = sja1000_ofp_read_reg16; + priv->write_reg = sja1000_ofp_write_reg16; + } else { + priv->read_reg = sja1000_ofp_read_reg8; + priv->write_reg = sja1000_ofp_write_reg8; + } err = of_property_read_u32(np, "nxp,external-clock-frequency", &prop); if (!err) -- 1.8.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/