Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3027503pxb; Sat, 23 Oct 2021 14:05:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNdt4oWY79aF58fHSMA2TLot0zkJHkeXTOBZuidwuxxGrbcyluCHj591Y807lgw18/SczG X-Received: by 2002:a17:90b:84:: with SMTP id bb4mr11077392pjb.2.1635023135832; Sat, 23 Oct 2021 14:05:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635023135; cv=none; d=google.com; s=arc-20160816; b=X3q2pJncWHWFhWzsMY9r2wjiYFEMZOVYBjvU2L44udlQvLTK84hXTC6uFPZ0JXxNES oGVg0pBe2HGWQXAc5edoGBJ1O08+MzuBN3l2pXTNMQ5TcB7/MJWnoTosl7ab6GkyqKve xfwix3gcYeA4Hgt0UaeCCxm3neZlk5muNkMATAWDZsth273t1VNnASJQT+OH5bb9wGUq tccOCptlXVeahCQyrd+hxOoKi0bm7NknI/TpA94jdk/qux7MOr3PuU4RvJeqUXp0b8Sw mzUctftZfAadV0bqEfKt5jIC9WbJEelWwO6TVkHy+BYR+Djb7OhqkCqKcYKtdSWfhAXY pSpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=BZh2M7QGexTIuPxtm9Pv4Za0Wma1jz1TKQDX4gzJw84=; b=xCFEzTm598T36bS1ScZdeYRzQJZyq6hPRX1X1SWoiTBmOQTIHJyb1NZvLKLmTdqvkG Iohs/cUQ3glGjVTjQDDh8r2rAegNOL7d7r3A8FODic8w1kFAh+5lPj8gkRV5ZHZv6VMl Pqj23D7WwQIIY60L6zyN5jZgQg29e7UdsFmnz+A0SnE6PILpNYlynAPjx2qHv5d9DUWw 6j4Oo5MUlZNUyw6ib5AIhMw3Y0YzeGGrBIQgo/RUpS7SMmFfQ+YPCyxRrR4pdsTCgoy1 i1mb0oUPSaL5Xtbd4WQEfA3RZuFAmttXLOQqOfIvTRCqReMepRavG/QwaBlT/Z/sCbwT S4wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oo13si25562149pjb.120.2021.10.23.14.05.20; Sat, 23 Oct 2021 14:05:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbhJWVFW (ORCPT + 99 others); Sat, 23 Oct 2021 17:05:22 -0400 Received: from mail-pj1-f48.google.com ([209.85.216.48]:45749 "EHLO mail-pj1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230280AbhJWVFV (ORCPT ); Sat, 23 Oct 2021 17:05:21 -0400 Received: by mail-pj1-f48.google.com with SMTP id ls14-20020a17090b350e00b001a00e2251c8so5474685pjb.4; Sat, 23 Oct 2021 14:03:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=BZh2M7QGexTIuPxtm9Pv4Za0Wma1jz1TKQDX4gzJw84=; b=4tz4u0QI57K+6rytVoKgHrTaiTk/x4xHzExqt6AwffuPmpQJLVajs7qt/yHI4RfFq6 mqEE+AOAIxn0A3ARAJ/1ojXuef7SDiGmz2NC0fs+BfNDhIPEKUMHyv+xgGmaoDCxp77A aWpd42zQ1fMYGPn6HmFNA4no0rOuPFbJfVOqkF73BjI/SCAldHccdG/GYxigrlGKxFZ8 ngnJ4JH9lbsNbfBeboxnw42GpFJeEWkAPjnPSK7vdT6uoY6jf7A4FbLjZt9vSsygVEK8 ykXFrs3IQEAp1nyX8l6JzFcndVJ6jbTZq9AUWIl7xFZDVbd3OkFCbTiu0gl9xlAu1oOz mYBQ== X-Gm-Message-State: AOAM532tD70tifyuSjRqi6KVSN5QOmQviKM4X4yOOkXbnJzfK2KJlC+m vMsUg3cWKcQsNzWIPF/Vchp8EapOUwryzCapptU= X-Received: by 2002:a17:903:11c5:b0:13f:ef40:e319 with SMTP id q5-20020a17090311c500b0013fef40e319mr7351904plh.33.1635022982010; Sat, 23 Oct 2021 14:03:02 -0700 (PDT) MIME-Version: 1.0 References: <20211021174223.43310-1-kernel@esmil.dk> <20211021174223.43310-13-kernel@esmil.dk> In-Reply-To: From: Emil Renner Berthing Date: Sat, 23 Oct 2021 23:02:50 +0200 Message-ID: Subject: Re: [PATCH v2 12/16] pinctrl: starfive: Add pinctrl driver for StarFive SoCs To: Andy Shevchenko Cc: linux-riscv , devicetree , linux-clk , "open list:GPIO SUBSYSTEM" , "open list:SERIAL DRIVERS" , Palmer Dabbelt , Paul Walmsley , Rob Herring , Michael Turquette , Stephen Boyd , Thomas Gleixner , Marc Zyngier , Philipp Zabel , Linus Walleij , Greg Kroah-Hartman , Daniel Lezcano , Andy Shevchenko , Jiri Slaby , Maximilian Luz , Sagar Kadam , Drew Fustini , Geert Uytterhoeven , Michael Zhu , Fu Wei , Anup Patel , Atish Patra , Matteo Croce , Linux Kernel Mailing List , Huan Feng Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 23 Oct 2021 at 22:29, Andy Shevchenko wrote: > On Sat, Oct 23, 2021 at 9:46 PM Emil Renner Berthing wrote: > > On Fri, 22 Oct 2021 at 15:32, Andy Shevchenko wrote: > > > On Thu, Oct 21, 2021 at 8:44 PM Emil Renner Berthing wrote: > > > > + } else if ((npins = of_property_count_u32_elems(child, "pins")) > 0) { > > > > + pins = devm_kcalloc(dev, npins, sizeof(*pins), GFP_KERNEL); > > > > + if (!pins) > > > > + goto free_grpname; > > > > + > > > > + pinmux = NULL; > > > > + > > > > + for (i = 0; i < npins; i++) { > > > > + u32 v; > > > > + > > > > + ret = of_property_read_u32_index(child, "pins", i, &v); > > > > + if (ret) > > > > + goto free_pins; > > > > + pins[i] = v; > > > > + } > > > > > > NIH _array() APIs. > > > > .. here the pins array is an int array and not u32 array. I can cast > > it and and hope Linux will never run on a machine where sizeof(int) != > > 4 if you think that's better? > > Can you make it u32? No, the pinctrl API takes an int array. > > > > +free_pinmux: > > > > + devm_kfree(dev, pinmux); > > > > +free_pins: > > > > + devm_kfree(dev, pins); > > > > +free_grpname: > > > > + devm_kfree(dev, grpname); > > > > > > > +free_pgnames: > > > > + devm_kfree(dev, pgnames); > > > > > > Just no, please get rid of them either way as I explained in previous reviews. > > > > So I asked you if you thought it was better to leave these unused > > allocations when parsing the device tree node fails but you never > > answered that. I didn't want put words in your mouth so I could only > > assume you didn't. I'd really like a straight answer to that so I have > > something to refer to when people ask why this driver doesn't do the > > same as fx. the pinctrl-single. So just to be clear: do you think it's > > better to leave this unused garbage allocated if parsing the device > > tree node fails? > > If it's only one time use, I don't think it's good to have it hanging > around, BUT at the same time devm_*() is not suitable for such > allocations. So is that a yes or a no to my question? It's not clear to me. > > > > + if (reg_din) > > > > + writel_relaxed(gpio + 2, reg_din); > > > > > > Why 0 can't be written? > > > > Because signal 0 is a special "always 0" signal and signal 1 is a > > special "always 1" signal, and after that signal n is the input value > > of GPIO n - 2. We don't want to overwrite the PoR defaults. > > Okay, this, perhaps, needs a comment (if I have not missed the existing one). > > And what about checking for reg_din? Do you have some blocks output-only? I don't know know what you mean by the first question, but yes fx. the uart tx pins would be an example of pins that have their output signal set to the uart peripheral, the output enable set to the special "always enabled" signal, and no input signal is set to any of the tx pins. > > > > + case PIN_CONFIG_BIAS_DISABLE: > > > > + mask |= PAD_BIAS_MASK; > > > > + value = (value & ~PAD_BIAS_MASK) | PAD_BIAS_DISABLE; > > > > > > Okay, I have got why you are masking on each iteration, but here is > > > the question, shouldn't you apply the cnages belonged to each of the > > > group of options as it's requested by the user? Here you basically > > > ignore all previous changes to bias. > > > > > > I would expect that you have something like > > > > > > for () { > > > switch (type) { > > > case BIAS*: > > > return apply_bias(); > > > ...other types... > > > default: > > > return err; > > > } > > > } > > > > I such cases where you get conflicting PIN_CONFIG_BIAS_* settings I > > don't see why it's better to do the rmw on the padctl register for the > > first bias setting only to then change the bits again a few > > microseconds later when the loop encounters the second bias setting. > > After the loop is done the end result would still be just the last > > bias setting. > > It could be bias X followed by something else followed by bias Y. You > will write something else with bias Y. I admit I don't know this > hardware and you and maintainers are supposed to decide what's better, > but my guts are telling me that current algo is buggy. So there is only one padctl register pr. pin. I don't see why first setting the bias bits to X, then setting some other bits, and then setting the bias bits to Y would be different from just setting all the bits in one go. Except for during that little microsecond window during the loop that I actually think it's better to avoid. > > > > + break; > > ... > > > > > +static int starfive_gpio_request(struct gpio_chip *gc, unsigned int gpio) > > > > +{ > > > > + return pinctrl_gpio_request(gc->base + gpio); > > > > +} > > > > + > > > > +static void starfive_gpio_free(struct gpio_chip *gc, unsigned int gpio) > > > > +{ > > > > + pinctrl_gpio_free(gc->base + gpio); > > > > +} > > > > > > Point of having these function is...? > > > > These calls tells the pinctrl system that a certain pin is now used > > for GPIO. Conversely it'll also prevent fx. userspace from doing GPIO > > on a pin that's already used by I2C, a UART or some other peripheral. > > Isn't pin control doing it by default? I actually tested that before posting and the answer seems to be no. > ... > > > > > + /* enable input and schmitt trigger */ > > > > > > Use capitalization consistently. > > > > I am? > > In the comment is one style, in other comments it's another. There are documentation comments in the beginning of the file and then there are code comments in the code. I think it's a lot easier to read like that, but if you insist I can lowercase the documentation. > > > > + case IRQ_TYPE_EDGE_RISING: > > > > > + handler = handle_edge_irq; > > > > + break; > > > > + case IRQ_TYPE_EDGE_FALLING: > > > > > + handler = handle_edge_irq > > > > + break; > > > > + case IRQ_TYPE_EDGE_BOTH: > > > > > + handler = handle_edge_irq; > > > > > > Dup. You may do it once without any temporary variable. > > > I haven't got why you haven't addressed this. > > > > So you want two switches on the trigger variable, one for irq_type, > > edge_both and polarity, and one for the handler? If this is not what > > you have in mind please be a lot more explicit. Trying to guess what > > you mean gets really old. > > switch (type) { > case bla bla bla: > ...everything except handler... > } > > if (type & EDGE) > irq_lock(edge_handler) > else if (type & LEVEL) > irq_lock(level_handler) If you look at include/dt-bindings/interrupt-controller/irq.h I don't think such a mask exists. I guess we could do if (trigger & IRQ_TYPE_EDGE_BOTH) edge_handler else if (trigger == IRQ_TYPE_LEVEL_HIGH || trigger == IRQ_TYPE_LEVEL_LOW) level_handler else return -EINVAL ..but at that point I think it's probably easer to read a 2nd switch case or just leave the code as it is. What do you think? > > > > > > + break; > > > > + case IRQ_TYPE_LEVEL_HIGH: > > > > > + handler = handle_level_irq; > > > > + break; > > > > + case IRQ_TYPE_LEVEL_LOW: > > > > > + handler = handle_level_irq; > > > > > > Ditto. > > > > > > > + break; > > ... > > > > > + clk = devm_clk_get(dev, NULL); > > > > + if (IS_ERR(clk)) { > > > > > > > + ret = PTR_ERR(clk); > > > > > > Inline into below. > > > > > > > + return dev_err_probe(dev, ret, "could not get clock: %d\n", ret); > > > > + } > > > > > > Ditto for all other similar cases. > > > > So you would rather want this? > > return dev_err_probe(dev, PTR_ERR(clk), "could not get clock: %d\n", > > PTR_ERR(clk)); > > or just not tell why getting the clock failed? > > Of course not, no dup of the printing error code is needed. I guess I > mentioned it in another patch. > > return dev_err_probe(dev, PTR_ERR($error), "$msg\n"); > > ... > > > > > + if (!device_property_read_u32(dev, "starfive,signal-group", &value)) { > > > > > > Since you are using of_property_* elsewhere, makes sense to use same > > > here, or otherwise, use device_*() APIs there. > > > > Wait, so now you want of_property_read_u32(dev->of_node, ...) here > > again, is that right? > > Before I missed that there are other of_property_read*() calls, now > since you used them elsewhere it makes sense to be consistent over the > code. Gotcha. > -- > With Best Regards, > Andy Shevchenko