Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp622118rdb; Thu, 15 Feb 2024 10:02:32 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVz6cUDD3TSWI5fx/xcCWyLm/3olVrLahlMQNl7hbUEjDel5iymj1Qry1sLirv+LzVMggfy2XjGuFg4WxSZirl/U2ppR/Kybwyx1cdtuQ== X-Google-Smtp-Source: AGHT+IHugSZSb7tNPxdSFj6CCJCb+mb8EzO4v9amrZdCuN2GnYJwTuBJ0tKeyaFeqXrEJfgOQJ2A X-Received: by 2002:a54:4019:0:b0:3bf:feab:f91c with SMTP id x25-20020a544019000000b003bffeabf91cmr2458779oie.21.1708020152329; Thu, 15 Feb 2024 10:02:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708020152; cv=pass; d=google.com; s=arc-20160816; b=PkxQti90UUOF9gm4Ervnk4pBKhQqQhyltIPRYIFwheLZQkEVFtEbBkBUujwzmfoY79 iT969ARLGRFEj0G+w/3xq7giy3CLDPtoXBnsZcv8ifojI5gHOr+EKAuYsHfQwm6lZeA7 qtJl7neZvsRM0L9AYQ8FCVzHmC9YtYvonSWDSDH+YFA6sY2TMUrAPENMLCOzb5gjoq7n r3lzdSrazDR1coH/y/FtZA8F0Hud580E77P/sMBxgK/kei21D48dAkYIITk5RiZwnGWQ kff9qUov5+y+j8CgN0Pjx/asADG+7hThTFVJiu6CzBZYZzWcRpXzaT4zFXVe2aExsmW6 PfIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ef0c0lkPbUi43MY5AODLBrbnTIwKOtyjY4A1tP/i59I=; fh=8QR3YP2+G9bDWSYPIN6zlh0fuiauNXNLi06nWPfg0dQ=; b=pUQuKekrzmRPC4k7v1JBZjMVGblfikDs2VIznyFjhLuFguoeBYLuu6vMu/cNk0ym0P MkrnGbK6+bqg/D3iFWoAm8SAaJMK7iw4HjlgtymA6uhdf4kwMENj1htgJx//++Xrj7mk y+RGdt5Y1vQ9nRbwtVcd3wDwJz2NN6JD7FujxjzWszvsKEVofCLVKXhwAsyRPb4EZLXK lW1DyuHp3/p4CWmWnOrtRo7wenVxY/xB9dOr2fAmmxitu0pcsnNm5hxxy43ghu1yspzm PjyehVqKsQtQhIETtAwR1Hdj9kwrdJK6qaMUCKkL9ozCZxYJGTTbDxB1+L/gBnDuRAT8 SMKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hLijPB+4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id r28-20020ab04a5c000000b007d91d35e3fcsi400746uae.99.2024.02.15.10.02.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:02:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=hLijPB+4; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-67462-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67462-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 058AF1C23D2C for ; Thu, 15 Feb 2024 18:02:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60C1D13957B; Thu, 15 Feb 2024 18:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hLijPB+4" Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDAA91386C1; Thu, 15 Feb 2024 18:01:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708020090; cv=none; b=sYL1TVLGfbLL03+R0js7H5Iz1AYe912QW0e1nNz68rErs75rNabX0rpbe7oJZatMGB/cHsT3p27SNyQfbLTRLRhv1rA7d+g8NmIs3eWP1C+xxzcN4Ydeuu5qT6I9UGbWd+MH3F/TuD9XdGv4atVk0DFhyTUytFhA0NEArK/Dl4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708020090; c=relaxed/simple; bh=KBAkQBgpYdLDaJ5qYLlC9p8SlXhmDfw3UvehvJhSkG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I5TFkfZCITTvjpoNLnXNAQTIqFSW7fJn06K4pdB7c4Dmws0mM2caOj4+3Q5OxNUWyWg+41cKKaMVg0U4LaHPxwpYOHP2Bsk4T4ehLHjeqCrPiRyN2VjPVtecG8oPuLgfZOEEQDTF9iUDQ68yzbL8F8ZECEa7ZqlKNm5e31Pyyok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hLijPB+4; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-511831801f3so1203100e87.2; Thu, 15 Feb 2024 10:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708020086; x=1708624886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ef0c0lkPbUi43MY5AODLBrbnTIwKOtyjY4A1tP/i59I=; b=hLijPB+4/4rFFtoTdtnw2fOkvvknMJy5zQa2JWAzVoaUruqBbQDdRrNQQyQ/qsbguP CxKzJj3BQrDN3ChRd0ODgflCTHamKWQDoHweML6EO4t2m6Ft/5/zumNljIG03DRxHN7c 5zDvvKSLPueDayZwEcj5VAE97HSfkwtKdMiffOTIHGhPK7pGcx+7LnB+8Vse32QBVV5u ilGqQZGzrK0ljTSV61NzYUCa5jnV7nyBGzDTlFFTEkkzz6SIEqjcPBgIfGuUbst2NFQD AZshjoOZhoJcB+YzN5hjOdXymhjyE0pucaW4TcA5CDR6EVmp9qe6hel6T4CxgTu5iVB7 9/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708020086; x=1708624886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ef0c0lkPbUi43MY5AODLBrbnTIwKOtyjY4A1tP/i59I=; b=opVCDZ2Hkw3u/o/0JvvQQKJd+5F/baiH9hjDQGrDfULCsi6UCh6GEz9ee4/BoTaVG6 mLBtkQq9kN3iY5H+OsN4H3h439szjIiN2urwtrhWyPphiftKSqIJ1c0BiO9jXLBouX5b hsax+BH5Ero33snd7Zo/PoJJB/lDzNXi4pKozGaoldYjD7YMJOcC3CfsCo7U6qWP2N7M pijjrK59ase9JWW0h173o+SNW9dPHX2rXWrsQhBU+UyUz9tF/n6SxIu3fOK0NHJIDgv1 fa9BLsxyGn+RptiU7OWxHRbkp+00IVQjMoPUcc8cDWoffE4htjqRcuZhb8rdo5kqRw94 ShyQ== X-Forwarded-Encrypted: i=1; AJvYcCX8OPJvcE8sGa7r8bIoraQPiEGcpFflrNixHbqMP1S08yyzbxAWRL2vToGuSQl2sHffWdKR1QjS+wkDrwTZtiwNFCvpEosz18IeCZPWASE/6tLBIguE7MWNPu+egyXiCXQLDKut+DyV X-Gm-Message-State: AOJu0YwC5PoqamiZ1qb8lrS5EsH292TFz3pRg//e5wiRF2BjMXoN4GBG cCAbD0KX9oCoFn/7ybGBpzLgJ6MQPtVdn0OLuAiOWEemuFWfDtcs X-Received: by 2002:ac2:59d0:0:b0:512:851d:41c5 with SMTP id x16-20020ac259d0000000b00512851d41c5mr1898427lfn.20.1708020084995; Thu, 15 Feb 2024 10:01:24 -0800 (PST) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id k11-20020ac2456b000000b00511ae3225d1sm321197lfm.226.2024.02.15.10.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:01:24 -0800 (PST) From: Serge Semin To: Serge Semin , Mark Brown , Andy Shevchenko Cc: Alexey Malahov , Andy Shevchenko , Andy Shevchenko , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] spi: dw: Add a number of native CS auto-detection Date: Thu, 15 Feb 2024 21:00:47 +0300 Message-ID: <20240215180102.13887-3-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240215180102.13887-1-fancer.lancer@gmail.com> References: <20240215180102.13887-1-fancer.lancer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Aside with the FIFO depth and DFS field size it's possible to auto-detect a number of native chip-select synthesized in the DW APB/AHB SSI IP-core. It can be done just by writing ones to the SER register. The number of writable flags in the register is limited by the SSI_NUM_SLAVES IP-core synthesize parameter. All the upper flags are read-only and wired to zero. Based on that let's add the number of native CS auto-detection procedure so the low-level platform drivers wouldn't need to manually set it up unless it's required to set a constraint due to platform-specific reasons (for instance, due to a hardware bug). Signed-off-by: Serge Semin --- drivers/spi/spi-dw-core.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/spi/spi-dw-core.c b/drivers/spi/spi-dw-core.c index 722b5eb1f709..ddfdb903047a 100644 --- a/drivers/spi/spi-dw-core.c +++ b/drivers/spi/spi-dw-core.c @@ -834,6 +834,20 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws) DW_SPI_GET_BYTE(dws->ver, 1)); } + /* + * Try to detect the number of native chip-selects if the platform + * driver didn't set it up. There can be up to 16 lines configured. + */ + if (!dws->num_cs) { + u32 ser; + + dw_writel(dws, DW_SPI_SER, 0xffff); + ser = dw_readl(dws, DW_SPI_SER); + dw_writel(dws, DW_SPI_SER, 0); + + dws->num_cs = hweight16(ser); + } + /* * Try to detect the FIFO depth if not set by interface driver, * the depth could be from 2 to 256 from HW spec -- 2.43.0