Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1696617lqa; Mon, 29 Apr 2024 17:03:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW5mfB+Niu50nifxmuYsiNk6Oo20FM++9aayftVepN9wqVQ6IhfyRvD+46zHMgjvbFL0g3/JTLLa72gQDT7l434+o1woT5gAGjm1mi2BQ== X-Google-Smtp-Source: AGHT+IHUvUrYg7CHZLVndfBJRnkAxeDs5+KYZv0fZ33jOSdgco/dz+YjStGI/zJBxjRb5B8i0cH+ X-Received: by 2002:a50:9b50:0:b0:570:5b70:3407 with SMTP id a16-20020a509b50000000b005705b703407mr9789266edj.10.1714435397791; Mon, 29 Apr 2024 17:03:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714435397; cv=pass; d=google.com; s=arc-20160816; b=L8KdC5e93wCv7iVKoYMtYw+ofFZPo6gtYxQynGS+uZBJh8C3TSIbItwTMvK3/CdRPD /YMkGhXRQwt8Ipp+h7D0ro05a8sjRwYdbLr0HKZlbflC9JI6tzgDoAEkkClGWq0zvjEy i0LVAX70SRQz0fhAgbnra/ut8a1AfeaSYBhuv6XtdLxhfXdgbZmG/YPMmhCA6yaHZMi5 shuyq3FHgVPjqEAGmCkQO5FHpYd0hpJlbDciAvEvkEu9Zb2Sr/jPhCe0PrKyBHQJuE/a LStJfqboSAMhspQ+KEyhD0RepP+ZpI9QmoPSmavqxysLtdoKP+84P5cagJOp3yhosJU4 znjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:to:from:date; bh=Zo8D3lsFdEeXxAxf62RcXBt5LC5gx4r/O8NQQwJG9EY=; fh=dOESFQxeiz23UAu+UBL6ROWaTMe6wNNEkQa1nvxBjn4=; b=jIhImTU7oZ4itGNDvQ7hddV4UDfQPhJqp0Mb3HyM0BYyKCwht4CM4SL6lNjne3lZN8 vUeZkizsm0cnZHmiRIAOLWmRj5qyohSiTKyw2Kz1p1njgH7fQPmFZwmjlfMo4brEP3CC 5VUvid1veynfbuE0ssdt9qzT2XDi3MwWzK+VpMgvKIJHyURMQqeohRkyc/i38wxUisGJ +kzBdUFKN7N09BwK+OwCHUfaBF6YbKg25AdquDPqDV7iQVeumejifHH/cQFSQwHFe7eH ZbrF353xtA70yU+oK7uPxAl1DGwAqU7Hc6cCrLeZTWwc5KHJbnt0B0r41dyuGm3/X06/ GcaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-163170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163170-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l27-20020a50d6db000000b005727c647b94si2458286edj.247.2024.04.29.17.03.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 17:03:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-163170-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163170-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 853BB1F230B1 for ; Tue, 30 Apr 2024 00:03:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59A421C33; Tue, 30 Apr 2024 00:03:07 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22B91623; Tue, 30 Apr 2024 00:03:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714435386; cv=none; b=VGdAZRpTEcOdi2YV9wolqn4+iaHvJM5II0wmUZ1H5UJmLdE6qY88of7W3HpB1/c90J03owmi3wuLfgCMWpn/oi2EDbsurUXD5BYj6p4UCc14sD2PM7zbRKXNrmDlCIA6FZyl+WTbKdqicj61DEdccYMqSdxGItw3W2kFguYg3L4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714435386; c=relaxed/simple; bh=OAALAvGgj2+eNeT14GTmZ9nctNzxrwyvFnOi6pdmdv0=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=UPhSpWWmObfMAt2dC+FF7c1mEpk37QCoVuVAOhui4+OwK0a8yXB8fH57UWTRsTsietFQZ9j1S/llGepm+Wszd6XVZE8k9Qb73thg0iNDOYNXUtyft2aexKKz02I1Rek5fWASMj7xAom+yHGPZ5WRdF4MBPiWE5XHwvAUFEs2yls= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.97.1) (envelope-from ) id 1s1ah2-000000003Ss-0jtq; Mon, 29 Apr 2024 23:45:56 +0000 Date: Tue, 30 Apr 2024 00:45:46 +0100 From: Daniel Golle To: =?utf-8?B?QXLEsW7DpyDDnE5BTA==?= , Felix Fietkau , Rob Herring , Krzysztof Kozlowski , Conor Dooley , DENG Qingfang , Sean Wang , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthias Brugger , AngeloGioacchino Del Regno , Landen Chao , devicetree@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH net] net: dsa: mt7530: fix impossible MDIO address and issue warning Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The MDIO address of the MT7530 and MT7531 switch ICs can be configured using bootstrap pins. However, there are only 4 possible options for the switch itself: 7, 15, 23 and 31 (ie. only 3 and 4 can be configured, bit 0~2 are always 111). Practically all boards known as of today use the default setting which is to have the switch respond to address 31, while the built-in switch PHYs respond to address 0~4 in this case. However, even in MediaTek's SDK the address of the switch is wrongly stated in the device trees as 0 (while in reality it is 31), so warn the user about such broken device tree and make a good guess what was actually intended. This is imporant to not break compatibility with older Device Trees as with commit 868ff5f4944a ("net: dsa: mt7530-mdio: read PHY address of switch from device tree") the address in device tree will be taken into account. Doing so instead of assuming the switch is always at address 31 which was previously hard-coded will obviously break things for many existing downstream device trees as they contain the wrong address (0) which previously didn't matter. Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch") Signed-off-by: Daniel Golle --- drivers/net/dsa/mt7530-mdio.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c index fa3ee85a99c1..119630fd9060 100644 --- a/drivers/net/dsa/mt7530-mdio.c +++ b/drivers/net/dsa/mt7530-mdio.c @@ -193,6 +193,19 @@ mt7530_probe(struct mdio_device *mdiodev) return PTR_ERR(priv->io_pwr); } + /* Only MDIO bus address 7, 15, 23 and 31 are valid options */ + if (~(priv->mdiodev->addr & 0x7) & 0x7) { + /* If the address in DT must be wrong, make a good guess about + * the most likely intention, and issue a warning. + */ + int correct_addr = ((((priv->mdiodev->addr - 7) & ~0x7) % 0x20) + 7) & 0x1f; + + dev_warn(&mdiodev->dev, + "impossible switch MDIO address in device tree: %d, assuming %d\n", + priv->mdiodev->addr, correct_addr); + priv->mdiodev->addr = correct_addr; + } + regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config), GFP_KERNEL); if (!regmap_config) -- 2.44.0