Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp694314ybx; Thu, 7 Nov 2019 01:08:27 -0800 (PST) X-Google-Smtp-Source: APXvYqz5LB6p/87Y5hTIlw4f2LBmoL//5pg3vEpgw7G9QHEnGBQCOQyPmd8e9dHZfoYF7HkSODLJ X-Received: by 2002:aa7:cad0:: with SMTP id l16mr2379035edt.82.1573117707797; Thu, 07 Nov 2019 01:08:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573117707; cv=none; d=google.com; s=arc-20160816; b=a8aUoPhi10HjFeFUNCTOMZMb/zustC3leSUvaHM1xvpV6pOQwmO7a35apsCEBPDxcr +3ZqsmGZ3DbwzGCtR6Hmjeb0cxWWYZ49+rOV6L9XgMTyAS8rGdGn9y7Hn0ybXzAxiFfg TsjAIoPoTZ5cVZ6cCOAShSL6125IYiAfpJsUVpC6uNvYK6CzKPSeBaC/w5IsGXIVMDnu yscPzEYkrMUoUhLZWSpZW9+BP9b0gXU5Rtmd8jtDTXesd8DJk0ospMub8F5vlV1vqnt4 6h+3y/rPUbQNqoN10ikyfUYnno2T7hhfM+WXN8Z4PmE68pfjU9LgnZbRJ2q3wYXpMzSc IVLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=OF+eycupM5DZferYZfrM7aHFkBXmCocCZJOZDrcZfVc=; b=WDJhVRHgbuhNOam91UtQE+A+Zyq71dqdHHKm9vywWYk91/aPAch4JHzQbWXIhIIHHH fsZxaGB4nemsCh6ffugLyi43UXERUqVleQIC9S/tPUBreIj1e9KYx6+XRLlZPD6kHb2k haYxnI8eh+iGmaXe5aupBU6ZKv0EabDujhTUuKVvehg78V3aKmwGqigTeJnGJ5Qj58HN HTn1SPVbl6G0ekHiAwXFTFx8Dw/A9ya/03Qt9WBMqA9o2q1NMFuaAvxNoDXVReFw45of QYHMyzpYqwwhOaXSz6K3J+AIYSZ5NWtF0MSEOYY4LOHfxdv2CNOjNAg+nqQFvoSw9nDN mH7Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g1si990902ejj.26.2019.11.07.01.08.04; Thu, 07 Nov 2019 01:08:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387467AbfKGJHU (ORCPT + 99 others); Thu, 7 Nov 2019 04:07:20 -0500 Received: from mga12.intel.com ([192.55.52.136]:3962 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726800AbfKGJHU (ORCPT ); Thu, 7 Nov 2019 04:07:20 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2019 01:07:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,277,1569308400"; d="scan'208";a="205618822" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga003.jf.intel.com with ESMTP; 07 Nov 2019 01:07:13 -0800 Received: from andy by smile with local (Exim 4.93-RC1) (envelope-from ) id 1iSdl2-0001eW-PM; Thu, 07 Nov 2019 11:07:12 +0200 Date: Thu, 7 Nov 2019 11:07:12 +0200 From: Andy Shevchenko To: Rahul Tanwar Cc: linus.walleij@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, qi-ming.wu@intel.com, yixin.zhu@linux.intel.com, cheol.yong.kim@intel.com Subject: Re: [PATCH v4 1/2] pinctrl: Add pinmux & GPIO controller driver for a new SoC Message-ID: <20191107090712.GV32742@smile.fi.intel.com> References: <63273c2b9ad14dae2b74e27e679da4d60a67d284.1573111648.git.rahul.tanwar@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <63273c2b9ad14dae2b74e27e679da4d60a67d284.1573111648.git.rahul.tanwar@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 07, 2019 at 03:36:44PM +0800, Rahul Tanwar wrote: > Intel Lightning Mountain SoC has a pinmux controller & GPIO controller IP which > controls pin multiplexing & configuration including GPIO functions selection & > GPIO attributes configuration. > > This IP is not based on & does not have anything in common with Chassis > specification. The pinctrl drivers under pinctrl/intel/* are all based upon > Chassis spec compliant pinctrl IPs. So this driver doesn't fit & can not use > pinctrl framework under pinctrl/intel/* and it requires a separate new driver. > > Add a new GPIO & pin control framework based driver for this IP. > +static void eqbr_gpio_mask_ack_irq(struct irq_data *d) > +{ > + eqbr_gpio_disable_irq(d); > + eqbr_gpio_ack_irq(d); Potential race? > +} > +static int eqbr_pinmux_set_mux(struct pinctrl_dev *pctldev, > + unsigned int selector, unsigned int group) > +{ > + struct eqbr_pinctrl_drv_data *pctl = pinctrl_dev_get_drvdata(pctldev); > + struct function_desc *func; > + struct group_desc *grp; > + unsigned int *pinmux; > + int i; > + > + func = pinmux_generic_get_function(pctldev, selector); > + if (!func) > + return -EINVAL; > + > + grp = pinctrl_generic_get_group(pctldev, group); > + if (!grp) > + return -EINVAL; > + > + pinmux = grp->data; > + for (i = 0; i < grp->num_pins; i++) > + eqbr_set_pin_mux(pctl, pinmux[i], grp->pins[i]); What if in the middle of the loop mux of one of the pins be changed by parallel thread? > + return 0; > +} > +static int eqbr_pinmux_gpio_request(struct pinctrl_dev *pctldev, > + struct pinctrl_gpio_range *range, > + unsigned int pin) > +{ > + struct eqbr_pinctrl_drv_data *pctl = pinctrl_dev_get_drvdata(pctldev); > + > + /* 0 mux is reserved for GPIO */ Perhaps #define EQBR_GPIO_MODE 0 ? > + return eqbr_set_pin_mux(pctl, 0, pin); > +} > + for (i = 0; i < npins; i++) { > + ret = eqbr_pinconf_set(pctldev, pins[i], configs, num_configs); > + if (ret) > + return ret; What if in the middle of the loop settings of one of the pins be changed by parallel thread? > + } > +static int eqbr_build_groups(struct eqbr_pinctrl_drv_data *drvdata) > +{ > + struct device *dev = drvdata->dev; > + struct device_node *node = dev->of_node; > + unsigned int *pinmux, pin_id, pinmux_id; > + struct group_desc group; > + struct device_node *np; > + struct property *prop; > + int j, err; > + > + for_each_child_of_node(node, np) { > + prop = of_find_property(np, "groups", NULL); > + if (!prop) > + continue; > + > + group.num_pins = of_property_count_u32_elems(np, "pins"); > + if (group.num_pins < 0) { > + dev_err(dev, "No pins in the group: %s\n", > + prop->name); It is perfectly one line. The idea of if (!foo) pattern in the loop to make code occupy less LOCs along with increased readability. > + return -EINVAL; > + } > + group.name = prop->value; > + group.pins = devm_kcalloc(dev, group.num_pins, > + sizeof(*(group.pins)), GFP_KERNEL); > + pinmux = devm_kcalloc(dev, group.num_pins, > + sizeof(*pinmux), GFP_KERNEL); These can be rearranged. > + > + if (!group.pins || !pinmux) > + return -ENOMEM; > + for (j = 0; j < group.num_pins; j++) { > + if (of_property_read_u32_index(np, "pins", > + j, &pin_id)) { One line. And so on... > + dev_err(dev, "Group %s: Read intel pins id failed\n", > + group.name); > + return -EINVAL; > + } > + if (pin_id >= drvdata->pctl_desc.npins) { > + dev_err(dev, "Group %s: Invalid pin ID, idx: %d, pin %u\n", > + group.name, j, pin_id); > + return -EINVAL; > + } > + group.pins[j] = pin_id; > + if (of_property_read_u32_index(np, "pinmux", > + j, &pinmux_id)) { > + dev_err(dev, "Group %s: Read intel pinmux id failed\n", > + group.name); > + return -EINVAL; > + } > + pinmux[j] = pinmux_id; > + } > + > + err = pinctrl_generic_add_group(drvdata->pctl_dev, group.name, > + group.pins, group.num_pins, > + pinmux); > + if (err < 0) { > + dev_err(dev, "Failed to register group %s\n", > + group.name); > + return err; > + } > + memset(&group, 0, sizeof(group)); > + pinmux = NULL; > + } > + > + return 0; > +} -- With Best Regards, Andy Shevchenko