Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6876609rwr; Wed, 10 May 2023 00:08:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4TjZMKHK4tGrf88X1ibhK8BMPHm+epJOiHTtBAjE/tl6BCTMoACZ+HwHxSiiLRgrsb4Xct X-Received: by 2002:a05:6a20:158e:b0:101:c4df:ee8e with SMTP id h14-20020a056a20158e00b00101c4dfee8emr2947625pzj.21.1683702483257; Wed, 10 May 2023 00:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683702483; cv=none; d=google.com; s=arc-20160816; b=V90/713hEqtx2OU4FG4ofgSBRIS/7XXgKYjnLJP7xMI92rhZ96b1LV/pW3t/WE/3Cl T5/e4+Pa30hoVrxdkkTx4Fb38AszCxSkV1o5fDhTBmrJ9V/7CQ1BJUaF/a9oBvAsdAsF xq/I7OOVJCFCShgV0gIONnsneLIqlg1OFfSdyYwOYi0lPId5sNtpc/JHS+MTmEnQuBgS 5FVXUqL7li4bRGtOwoHk8rqu21h6dCiCCTfIMW8172mbeS9I77UFSnenrItyCzB39jVG avHpwhmFHtzhUtJd7LwBrSPZ1aiTu9fesPaE9gJM1VznNTb32aePlpZS7hK8uxE897LZ wBYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=D+HCy3L2OnT5uHyCBmjF1m1zbqDCsY+LQg7JElf9toM=; b=HY6v5sfurxb+DSVgNCL6Ghu0jS8LQTfKw9KXAiJcojUoqOJrqvSfYZRLS9guHQubGA GOwrRZpDbBLDiiBarH3PgiInzcH8KIuIXjHgHHvVXqHa98Myndad9rnCz2iLd6Yfcl44 giGkLEc54l0f+01huBM0dZfpSTwHQDlL5te666Dgj2neqPm0BpiC/x9NkaUESN03Wr6P Y424C3O5wSsgOXW3lwd2wHiUpxZTZcOnQBuDb6Nw5zRTigYlWkrV1LEhiUWagrmt1orx NNStJuf3Y4Q7X2PVBIp9G9X9cJFbJZj1KRn6wxd9R6GbAuaDoX4ls8pJ8LEKiR65QC9W CdMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kVYndPf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i30-20020a63585e000000b0052856cec94asi3392528pgm.884.2023.05.10.00.07.50; Wed, 10 May 2023 00:08:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=kVYndPf5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236275AbjEJHEB (ORCPT + 99 others); Wed, 10 May 2023 03:04:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbjEJHEA (ORCPT ); Wed, 10 May 2023 03:04:00 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DAFE8F; Wed, 10 May 2023 00:03:58 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-7577ef2fa31so985015585a.0; Wed, 10 May 2023 00:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683702237; x=1686294237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=D+HCy3L2OnT5uHyCBmjF1m1zbqDCsY+LQg7JElf9toM=; b=kVYndPf5sb08mccQU66KR3JCC+q0Wdd4ROZcbwPKP6FR3dGSWvS+wZM27gbuKva/4i 8ansQJVEPiS8/7temIWSXq9mdwMiaJeuJ0ZRHu2y5R6SL7FeDvozo03VTxGVNbGNMh7A LwSt8f6Bq96H8PNNp1qo735wQiBvIXK7WgOx6r3XDRA6/361NHbaoy5f82kvB0tOi91z iZRO654VRFHoCd3QeExHTeaL6mjESrpLoVgOSM4Ya7TvtZJH/mdLz+V15eqfeq5PXSR+ DBuL1e1zzDie6JHFUv2zbHdx/e5aG8vDPkfBJIJHbBpx/rM7t+/1TYaz+swH+PyMd28J 1d1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683702237; x=1686294237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D+HCy3L2OnT5uHyCBmjF1m1zbqDCsY+LQg7JElf9toM=; b=TnJjQ1KVFFZ0XDvvYcDl7MrYekGwY/nAothYwLlwVPKqcytxsLfDt/grCh5pOBWOoU kwOu1CEGWe87yh6ya6qQK3hK3SsDA8y4XiKefDglW2E9PeNLX5TkvTccFKqSOc19BKLL M7PS84yhjEiUkLByllntPQ0qS1fC1XC9BxnaFUHU4F8RfOliM/U2VFcuDw10g63dOiOY rhCYTNwOBU+0QmixG2eJi1rSb0U+9iuW9nIdKAltElyYrqDe+dRzpitOPQAulHEQcWj7 brxwf3P5aSOHvMBYpXhA6qRQNpVLbRdonFHQhP7nW7SbprQogs4PjUE6HVbP5+IMftr8 gyIA== X-Gm-Message-State: AC+VfDx2opuOdnXzIcOrSosxsi2m6BMSvmXM8OQ87Q4nnC7ihTiO4jns VvExURTJqfCOjKu3CRSKbW7OJTLARCjx6bO7tog= X-Received: by 2002:a05:6214:491:b0:616:7977:2460 with SMTP id pt17-20020a056214049100b0061679772460mr26683509qvb.24.1683702237418; Wed, 10 May 2023 00:03:57 -0700 (PDT) MIME-Version: 1.0 References: <20230426071045.20753-1-zhuyinbo@loongson.cn> <20230426071045.20753-3-zhuyinbo@loongson.cn> In-Reply-To: From: Andy Shevchenko Date: Wed, 10 May 2023 10:03:21 +0300 Message-ID: Subject: Re: [PATCH v9 2/2] spi: loongson: add bus driver for the loongson spi controller To: Mark Brown Cc: Yinbo Zhu , Rob Herring , Krzysztof Kozlowski , linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jianmin Lv , wanghongliang@loongson.cn, Liu Peibao , loongson-kernel@lists.loongnix.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 9, 2023 at 7:39=E2=80=AFAM Mark Brown wrot= e: > On Mon, May 08, 2023 at 06:04:06PM +0300, andy.shevchenko@gmail.com wrote= : > > Wed, Apr 26, 2023 at 03:10:45PM +0800, Yinbo Zhu kirjoitti: ... > > > + loongson_spi_write_reg(loongson_spi, > > > + LOONGSON_SPI_SFCS_REG, > > > + (val ? (0x11 << spi->chip_select) = : > > > + (0x1 << spi->chip_select)) | cs); > > > Too many parentheses. > > The code is absolutely fine, there is nothing wrong with adding explicit > parentheses even where not strictly needed if it helps to make things > clear (which is obviously always a problem wiht ternery operator use). > Please, stop this sort of nitpicking. It is at times actively unhelpful. Okay, sorry for the noise. ... > > > + bit =3D fls(div) - 1; > > > + if ((1< > > + bit--; > > > + div_tmp =3D rdiv[bit]; > > > I believe this can be optimized. > > This isn't constructive feedback, if there is a concrete optimisation > you want to suggest please just suggest it. It goes together with the other questions in this function. But if you think about some code proposal, here we are: _original_ const char rdiv[12] =3D {0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11}; div =3D DIV_ROUND_UP_ULL(loongson_spi->clk_rate, hz); if (div < 2) div =3D 2; if (div > 4096) div =3D 4096; bit =3D fls(div) - 1; if ((1<spcr =3D div_tmp & 3; loongson_spi->sper =3D (div_tmp >> 2) & 3; _proposed_ const char rdiv[12] =3D {0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10, 11}; // as far as I understood the above table 00 00 [0] <=3D 2 00 01 [1] <=3D 4 01 00 [2] <=3D 8 00 10 [3] <=3D 16 00 11 [4] <=3D 32 01 01 [5] <=3D 64 01 10 [6] <=3D 128 01 11 [7] <=3D 256 10 00 [8] <=3D 512 10 01 [9] <=3D 1024 10 10 [10] <=3D 2048 10 11 [11] <=3D 4096 div =3D clamp_val(DIV_ROUND_UP_ULL(loongson_spi->clk_rate, hz), 2, 4096); div_tmp =3D rdiv[fls(div - 1)]; loongson_spi->spcr =3D (div_tmp & GENMASK(1, 0)) >> 0; loongson_spi->sper =3D (div_tmp & GENMASK(3, 2)) >> 2; But TBH I would expect the author to think about it more. Also the check can be modified to have less indented code: if (hz && loongson_spi->hz =3D=3D hz) return 0; if (!((spi->mode ^ loongson_spi->mode) & SPI_MODE_X_MASK)) return 0; ... > > > +EXPORT_SYMBOL_GPL(loongson_spi_init_master); > > > Please, use _NS variant. > > It really does not matter, the chances of any collisions is pretty much > zero. The point is in preventing us from using those symbols outside of the scope= . -- With Best Regards, Andy Shevchenko