From patchwork Thu Apr 27 20:45:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 2875 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D93623F334 for ; Thu, 27 Apr 2023 22:45:54 +0200 (CEST) Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5066c9c2ed6sf10262005a12.2 for ; Thu, 27 Apr 2023 13:45:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1682628354; cv=pass; d=google.com; s=arc-20160816; b=wmnYigq++9AthP5+fk0O9Yy/vboiCpdbjYcu87acoGotK3fA+dWVEv7gWfYVNR0l2+ 4TCaCinDGuWgvQybxcJ3BuRMUXjSUzekZ/p0aBriXXOftDgEmv9KW0ZP1tp0gT6WhxVP OB11h3g1BiIcAuUREUdnuWBkW5/pYQYYfFrCJ4I4aZzFTyxo9pve0j/NC35PzEw0cShl MtgIGPOhjp8xKjsJI7WQ9bN1VqO3yiDadmtSEwUPaR8SGPvddLXs9BAEZ5VEe/C173be v+VkE7aMyrCMzC9hjuSuH0MjIMogWm7oWokMiv9vEdVIBfQGNPp2Dv+CSAIGKHtoIwO4 KthA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=minPKAlFXsPwq5spRgDaE6CUQaQJcrtHFI4ELgRACR4=; b=gDnXjR66nMbsNFsCH6c/dpWZ/vQOSDTtifTsA6HMHPffjnUYujh/qAV4VDWd34LiY+ nTj5hQN9w36Lcj9Ot7U5SLekDwgr0SFycfzHXcBu4KbZyIIGlMFlBRoLsLVlZFgGBRD6 62ZNZiUhjfKsJJd89BmtY+6KJI5/cor7jWEB8UafpKHsbkS0FNnYkWyZZOrqS0hwIBJu ZwxlQ5B2PNkEni57H54P3N8dkQXSNp7FY4FrPzOfN2Mmb/fsEt4jOGz/kzNuAdJ9evZ9 zWni5yTwzC09kg++sn31cRBmXsOGOv0uF/MxyhwqzMvo8hymxxM3W4wxorECeleOLuhX 5XPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=DvLGcylp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1682628354; x=1685220354; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=minPKAlFXsPwq5spRgDaE6CUQaQJcrtHFI4ELgRACR4=; b=FOL2KXL71o6eGeINBb6sbEpaniu1HywQ9Z67q1X+eH8tTy+CdGJOE+qO8PLw7d3uZw bcU5f4FsH+zUNtWl2qPCnOsiR9f4swHxEFQfRGpaJ6RcWeaw0Os3GGse7FlOO9IX2Yu/ oOVzEaeTcwwC3SqtszWA7jD4BGw3OQnf8Kym4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682628354; x=1685220354; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=minPKAlFXsPwq5spRgDaE6CUQaQJcrtHFI4ELgRACR4=; b=INZsSHl5r5CpePkmoqN1BEATEQlRR4WVsCYQL1S8h4DNiOemgk6VoF+AV2usRN5clE 1bpS5mhJE4hpEh6tZNz6EmJty+DB5PkUaF12LyvwxgeCtS8L2VV0pPNjZRq0FU0KBI1O SDOqibnIEsACbBwx1nZgpE09yqvgnQ5IVPZzZ/8m5nS7Zq13geMACiATw7RLBLQkCI1W pwP2x8ZJLrwLhwi3AFcaX8/sRbFp5aAcA0inabTU0vCop2B+oUt5boMZqf1OxqTpmPhH 6mbJll0fqUESgw2h1lccTjE8Ipkq5iWk6EWC9o+nED+DsNFMxdgE+lYifFExKbxXAQcz uisQ== X-Gm-Message-State: AC+VfDxdhFPMXWDf+UjUZJ+DvBhhm90ZCHb5chc6ECaWJfBxaSPWYhh5 1MPrAwnSyeAloEoHKdiyVYmbcl3r X-Google-Smtp-Source: ACHHUZ4OwSsZ5AsRD+n2ZiCBggcVfqacdkErcdTbuksOMF0f+OtLCwfwpFDjh4tpuNQixxxxh8UACA== X-Received: by 2002:a50:bb23:0:b0:506:a665:d667 with SMTP id y32-20020a50bb23000000b00506a665d667mr1305480ede.0.1682628354412; Thu, 27 Apr 2023 13:45:54 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:907:d08:b0:957:4017:48f3 with SMTP id gn8-20020a1709070d0800b00957401748f3ls1414926ejc.3.-pod-prod-gmail; Thu, 27 Apr 2023 13:45:53 -0700 (PDT) X-Received: by 2002:a17:907:36c4:b0:94f:ab46:77f9 with SMTP id bj4-20020a17090736c400b0094fab4677f9mr3096029ejc.15.1682628352749; Thu, 27 Apr 2023 13:45:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682628352; cv=none; d=google.com; s=arc-20160816; b=rYDY7tj/2Nh9vi8bJGI1GIeqYX3NdKG7Dbi1Y/IyXKbOuO2ThwcndhCzfRK+GJ/D5s DuEviDCEqdjoPYn3HoZAUMULW95b1EeUm4CsRNAZwVbjPkHYvGISiEmm7ITcgBKHBCGY Jp0HkSE45pKv3DkFVmfHEpoCnKwwqDjOBPNIrm3PyW+aKLdrEG0aUoLdLlfO+8hDMXLi xanyeEoXdInymS5+ocPd+yzlgIZ6m3rHFwVBeNJyRs2UjlnODMRIaur8ZoXkqExTNaRM jNtJNXnR/KlyhB80Ja0vpmssL/Ss5Z98dtORRUWHFaCYzZ4k8G6DCjXvYo8REyz48YP2 05xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=v1g80Na1OEbBoslJdzzF/Prgy9dbHeWplBduFJrTGTE=; b=WHdTg0j6P8V83S1sIMn1poXUMCKiYBILMDZ12fxR9dDZR70RqcdGD8hGZD8DVjqIoF iFxDVG4FrP+r69fVpampZlHLkDQUWN6CUscgWirjq1e0UoGIwRp74KBegfucdXlKZa3b WyCKRFwXDaDM2t3yBazI7+38WcqecqWZMPtKafvrHRXa56MQDsyXECuMYDIsGFcwWopP 3+E1Qb3J8U3PcYdWPI15etBZMOkHyWEg5M9o/ymhyqwnW47ewBDWl7oHzdjKDiES2No7 HDcdA1Z+Tzuyd4++nqt7zjNLmRyvIJjdYca8wrMoR6JfqjK7ms/d9f23wcF2ijMA3dy4 nhbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=DvLGcylp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id q15-20020a1709060e4f00b0094f2da5a78asor10031657eji.86.2023.04.27.13.45.52 for (Google Transport Security); Thu, 27 Apr 2023 13:45:52 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Received: by 2002:a17:906:4fd6:b0:958:2cb5:9ada with SMTP id i22-20020a1709064fd600b009582cb59adamr3071816ejw.39.1682628352378; Thu, 27 Apr 2023 13:45:52 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-87-5-99-194.retail.telecomitalia.it. [87.5.99.194]) by smtp.gmail.com with ESMTPSA id s12-20020a170906bc4c00b00947ed087a2csm10171360ejv.154.2023.04.27.13.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 13:45:51 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, Amarula patchwork , Dario Binacchi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Marc Kleine-Budde , Paolo Abeni , Wolfgang Grandegger , linux-can@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v2 4/5] can: bxcan: add support for single peripheral configuration Date: Thu, 27 Apr 2023 22:45:39 +0200 Message-Id: <20230427204540.3126234-5-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230427204540.3126234-1-dario.binacchi@amarulasolutions.com> References: <20230427204540.3126234-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=DvLGcylp; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add support for bxCAN controller in single peripheral configuration: - primary bxCAN - dedicated Memory Access Controller unit - 512-byte SRAM memory - 14 filter banks Signed-off-by: Dario Binacchi --- Changes in v2: - s/fiter/filter/ in the commit message - Replace struct bxcan_mb::primary with struct bxcan_mb::cfg. drivers/net/can/bxcan.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/net/can/bxcan.c b/drivers/net/can/bxcan.c index e26ccd41e3cb..027a8a162fe4 100644 --- a/drivers/net/can/bxcan.c +++ b/drivers/net/can/bxcan.c @@ -118,7 +118,7 @@ #define BXCAN_FiR1_REG(b) (0x40 + (b) * 8) #define BXCAN_FiR2_REG(b) (0x44 + (b) * 8) -#define BXCAN_FILTER_ID(primary) (primary ? 0 : 14) +#define BXCAN_FILTER_ID(cfg) ((cfg) == BXCAN_CFG_DUAL_SECONDARY ? 14 : 0) /* Filter primary register (FMR) bits */ #define BXCAN_FMR_CANSB_MASK GENMASK(13, 8) @@ -135,6 +135,12 @@ enum bxcan_lec_code { BXCAN_LEC_UNUSED }; +enum bxcan_cfg { + BXCAN_CFG_SINGLE = 0, + BXCAN_CFG_DUAL_PRIMARY, + BXCAN_CFG_DUAL_SECONDARY +}; + /* Structure of the message buffer */ struct bxcan_mb { u32 id; /* can identifier */ @@ -167,7 +173,7 @@ struct bxcan_priv { struct regmap *gcan; int tx_irq; int sce_irq; - bool primary; + enum bxcan_cfg cfg; struct clk *clk; spinlock_t rmw_lock; /* lock for read-modify-write operations */ unsigned int tx_head; @@ -202,17 +208,17 @@ static inline void bxcan_rmw(struct bxcan_priv *priv, void __iomem *addr, spin_unlock_irqrestore(&priv->rmw_lock, flags); } -static void bxcan_disable_filters(struct bxcan_priv *priv, bool primary) +static void bxcan_disable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg) { - unsigned int fid = BXCAN_FILTER_ID(primary); + unsigned int fid = BXCAN_FILTER_ID(cfg); u32 fmask = BIT(fid); regmap_update_bits(priv->gcan, BXCAN_FA1R_REG, fmask, 0); } -static void bxcan_enable_filters(struct bxcan_priv *priv, bool primary) +static void bxcan_enable_filters(struct bxcan_priv *priv, enum bxcan_cfg cfg) { - unsigned int fid = BXCAN_FILTER_ID(primary); + unsigned int fid = BXCAN_FILTER_ID(cfg); u32 fmask = BIT(fid); /* Filter settings: @@ -680,7 +686,7 @@ static int bxcan_chip_start(struct net_device *ndev) BXCAN_BTR_BRP_MASK | BXCAN_BTR_TS1_MASK | BXCAN_BTR_TS2_MASK | BXCAN_BTR_SJW_MASK, set); - bxcan_enable_filters(priv, priv->primary); + bxcan_enable_filters(priv, priv->cfg); /* Clear all internal status */ priv->tx_head = 0; @@ -806,7 +812,7 @@ static void bxcan_chip_stop(struct net_device *ndev) BXCAN_IER_EPVIE | BXCAN_IER_EWGIE | BXCAN_IER_FOVIE1 | BXCAN_IER_FFIE1 | BXCAN_IER_FMPIE1 | BXCAN_IER_FOVIE0 | BXCAN_IER_FFIE0 | BXCAN_IER_FMPIE0 | BXCAN_IER_TMEIE, 0); - bxcan_disable_filters(priv, priv->primary); + bxcan_disable_filters(priv, priv->cfg); bxcan_enter_sleep_mode(priv); priv->can.state = CAN_STATE_STOPPED; } @@ -931,7 +937,7 @@ static int bxcan_probe(struct platform_device *pdev) struct clk *clk = NULL; void __iomem *regs; struct regmap *gcan; - bool primary; + enum bxcan_cfg cfg; int err, rx_irq, tx_irq, sce_irq; regs = devm_platform_ioremap_resource(pdev, 0); @@ -946,7 +952,13 @@ static int bxcan_probe(struct platform_device *pdev) return PTR_ERR(gcan); } - primary = of_property_read_bool(np, "st,can-primary"); + if (of_property_read_bool(np, "st,can-primary")) + cfg = BXCAN_CFG_DUAL_PRIMARY; + else if (of_property_read_bool(np, "st,can-secondary")) + cfg = BXCAN_CFG_DUAL_SECONDARY; + else + cfg = BXCAN_CFG_SINGLE; + clk = devm_clk_get(dev, NULL); if (IS_ERR(clk)) { dev_err(dev, "failed to get clock\n"); @@ -992,7 +1004,7 @@ static int bxcan_probe(struct platform_device *pdev) priv->clk = clk; priv->tx_irq = tx_irq; priv->sce_irq = sce_irq; - priv->primary = primary; + priv->cfg = cfg; priv->can.clock.freq = clk_get_rate(clk); spin_lock_init(&priv->rmw_lock); priv->tx_head = 0;