Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2895368pxj; Sun, 23 May 2021 14:47:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9DQ4/Z8ZFOefzaWBfS/+CQNd8PWoMo15Oha7uUB2yhOynTfTn+qQpDELGrUZAfpYHWQM/ X-Received: by 2002:aa7:db90:: with SMTP id u16mr21933057edt.106.1621806431050; Sun, 23 May 2021 14:47:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621806431; cv=none; d=google.com; s=arc-20160816; b=NbNyh+IgFjjO6zHasLtA9WqVktQrXU2fWcoAK5MDeT1DDmUh8IVO+RDGmG9SZTprqJ BoDJ8gh3RyFv3R5cGfiWrP/mVKNuYHyBZXAnFsLvPXJsSONglROmPUm1dlWFRVS3r1om GuKMw9rwoet1DA6OtrgW4CCbhLlCkB75g4mJ53di9a0eW1XZUPsqS7h6sq1lstfCSyD7 5Ugl/Dk+cSw9HY9v3sicjhujwU4a6f2lPHkIypy2OJ8ezvFFuk7za9FK9nmhvLlKuFkZ WF91rrr+hr8kng7f/Ny0Gtbd9P5CmZRvrmABMPtsWYa0LWxr+TGagYTb75QO3bMF1Hri Ej8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=aDvbepKOHmQ4oKKtd37YsHrWXOB6koq5xikaO4ZN6I4=; b=TfMBfaYV8ptbNusU6YOrFKTleNVj6Q6Jq4dr/Eweuw2uOwnreUGFlUrf4VLyrgTb9v TKzv2IBy/+m5bvUuNfvreLurGJIFY9yAtcANwP6ceTa5yk5dvky92CuakbQ6fDs5MV9E 75lv8PR6hfnjAng64dqZr6LdplGa7OWHaaOlGJaCLeIoMGXwwWOb+4t9WBG28rGGmuag XPrq4FuPXGQSAnz4K84ByZk6vCZJwKljfAXBn6r1J/lhwTRk0ehGHAYmSuu4h0kISmHS BtT9L9z8yHciKJog4d8nObtcLqKAuJ11Ak9GPcrhZZXuO0MQimeHuMrxfQXGrr5CZsC+ rlMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=sNlPe1gP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id js19si8822110ejc.277.2021.05.23.14.46.37; Sun, 23 May 2021 14:47:11 -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; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b=sNlPe1gP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231972AbhEWVoG (ORCPT + 99 others); Sun, 23 May 2021 17:44:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231969AbhEWVoF (ORCPT ); Sun, 23 May 2021 17:44:05 -0400 Received: from polaris.svanheule.net (polaris.svanheule.net [IPv6:2a00:c98:2060:a004:1::200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2EE2C06138A for ; Sun, 23 May 2021 14:42:37 -0700 (PDT) Received: from [IPv6:2a02:a03f:eafb:ee01:bd37:7535:eb00:6fa] (unknown [IPv6:2a02:a03f:eafb:ee01:bd37:7535:eb00:6fa]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id BAEF9202A12; Sun, 23 May 2021 23:42:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1621806156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aDvbepKOHmQ4oKKtd37YsHrWXOB6koq5xikaO4ZN6I4=; b=sNlPe1gPCSXiH18mrpM4ZhE3daoJ3IEwkq+eGKBNHWvZnFYgKoGeSTlhAa33nWDEMRGqW7 T7GwjiPkQEKlXtJKz32lF9fjtr5o2I4e5FbxZqREC0SXi/VUGu8wsvLUHW4brn1M/aRsb1 99qpKWdDWL4c907AIEPw8ziF4cuLV8iJX/qE+cMGLTJUHllXwmED2ZnbJnNR0Bl6ScwxP/ 2F2U4aPp3b0bdjRp95emeR/NSq/IFSoSw3l3PlPgpNtyku6EI/YeAFW2LDNsHB7Pdlwi8P TtViKH74G8RPABeyzH1ei3TCY5uvJcBYN0D9z4AFxrOAjFuhB3kdy7j3lGh+bg== Message-ID: <19144bf02d8678af521986e0e768193fb9084e6d.camel@svanheule.net> Subject: Re: [PATCH v2 6/7] pinctrl: Add RTL8231 pin control and GPIO support From: Sander Vanheule To: Andy Shevchenko Cc: Pavel Machek , Rob Herring , Lee Jones , Mark Brown , Greg Kroah-Hartman , "Rafael J . Wysocki" , Michael Walle , Linus Walleij , Bartosz Golaszewski , Linux LED Subsystem , devicetree , "open list:GPIO SUBSYSTEM" , Andrew Lunn , Linux Kernel Mailing List Date: Sun, 23 May 2021 23:42:34 +0200 In-Reply-To: References: <041077d195f1cc81bf6363388cb4adfb06cff4ef.1621279162.git.sander@svanheule.net> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andy, On Tue, 2021-05-18 at 00:42 +0300, Andy Shevchenko wrote: > On Mon, May 17, 2021 at 10:28 PM Sander Vanheule wrote: > > > > This driver implements the GPIO and pin muxing features provided by the > > RTL8231. The device should be instantiated as an MFD child, where the > > parent device has already configured the regmap used for register > > access. > > > > Although described in the bindings, pin debouncing and drive strength > > selection are currently not implemented. Debouncing is only available > > for the six highest GPIOs, and must be emulated when other pins are used > > for (button) inputs anyway. > > ... > > > +struct rtl8231_pin_desc { > > +       unsigned int number; > > +       const char *name; > > +       enum rtl8231_pin_function functions; > > +       u8 reg; > > +       u8 offset; > > +       u8 gpio_function_value; > > +}; > > I would see rather > > sturct pinctrl_pin_desc desc; > > Where drv_data describes the rest of the data for pin > I've split up the definitions into two parts: * pinctrl_pin_desc with the standard info, which has drv_data pointing to... * a device-specific rtl8231_pin_desc, with the register field info and alternate function So the pin descriptions are now entirely static, and only the pin functions are assembled at runtime. > > > +static int rtl8231_get_group_pins(struct pinctrl_dev *pctldev, unsigned int > > selector, > > +       const unsigned int **pins, unsigned int *num_pins) > > +{ > > > +       if (selector < ARRAY_SIZE(rtl8231_pins)) { > > Can we use traditional pattern, i.e. > >   if (... >= ARRAY_SIZE(...)) >     return -EINVAL; > >   ... >   return 0; > > ? Sure. Will be implemented in v3. > > > +               *pins = &rtl8231_pins[selector].number; > > +               *num_pins = 1; > > +               return 0; > > +       } > > + > > +       return -EINVAL; > > +} > > ... > > > +static int rtl8231_set_mux(struct pinctrl_dev *pctldev, unsigned int > > func_selector, > > +       unsigned int group_selector) > > +{ > > > +       int err = 0; > > Redundant variable. > > > +       switch (func_flag) { > > +       case RTL8231_PIN_FUNCTION_LED: > > +       case RTL8231_PIN_FUNCTION_PWM: > > +               err = regmap_update_bits(ctrl->map, desc->reg, > > function_mask, ~gpio_function); > > +               break; > > +       case RTL8231_PIN_FUNCTION_GPIO: > > +               err = regmap_update_bits(ctrl->map, desc->reg, > > function_mask, gpio_function); > > +               break; > > +       default: > > +               return -EINVAL; > > +       } > > + > > +       return err; > > +} > I've reworked this whole section a bit. since a pin is either (only) GPIO, or some alternative function, this could be done with a simpler if/else. > > > +static const struct pinmux_ops rtl8231_pinmux_ops = { > > +       .set_mux = rtl8231_set_mux, > > +       .get_functions_count = rtl8231_get_functions_count, > > +       .get_function_name = rtl8231_get_function_name, > > +       .get_function_groups = rtl8231_get_function_groups, > > +       .gpio_request_enable = rtl8231_gpio_request_enable, > > > +       .strict = true > > Leave comma for non-terminator entries. > > > +}; > > + > > + > > One blank line is enough. > > ... > > > +static int rtl8231_pinctrl_init_functions(struct device *dev, struct > > rtl8231_pin_ctrl *ctrl) > > +{ > > +       struct rtl8231_function *function; > > +       const char **group_name; > > +       unsigned int f_idx; > > +       unsigned int pin; > > + > > +       ctrl->nfunctions = ARRAY_SIZE(rtl8231_pin_function_names); > > +       ctrl->functions = devm_kcalloc(dev, ctrl->nfunctions, sizeof(*ctrl- > > >functions), GFP_KERNEL); > > +       if (IS_ERR(ctrl->functions)) { > > Wrong. I was somehow thinking that this would either return an error value or a valid point. Don't know where I got that, but should be fixed here and for the other kallocs. Best, Sander