From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751134AbdEaIDZ (ORCPT ); Wed, 31 May 2017 04:03:25 -0400 Received: from sci-ig2.spreadtrum.com ([222.66.158.135]:20615 "EHLO SHSQR01.spreadtrum.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750974AbdEaIDU (ORCPT ); Wed, 31 May 2017 04:03:20 -0400 Date: Wed, 31 May 2017 16:00:12 +0800 From: Baolin Wang To: Linus Walleij CC: Mark Rutland , Rob Herring , "linux-gpio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Mark Brown , Baolin Wang Subject: Re: [PATCH 2/2] pinctrl: sprd: Add Spreadtrum pin control driver Message-ID: <20170531080012.GB31518@spreadtrum.com> Mail-Followup-To: Linus Walleij , Mark Rutland , Rob Herring , "linux-gpio@vger.kernel.org" , "devicetree@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Mark Brown , Baolin Wang References: <58b4b6fb2765ab9d5d3ac77f3854d0a88a0973bd.1495863824.git.baolin.wang@spreadtrum.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-MAIL: SHSQR01.spreadtrum.com v4V82AiY020052 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, On 一, 5月 29, 2017 at 06:28:49下午 +0200, Linus Walleij wrote: > On Sat, May 27, 2017 at 7:56 AM, Baolin Wang wrote: > > > This patch adds the pin control driver for Spreadtrum SC9860 platform. > > > > Signed-off-by: Baolin Wang > > Overall I see that you want to store functions and groups in the device tree > using the current helpers from Tony. That is OK if you want to take that > approach, though I prefer the pins/groups/function encoding in plaintext. > > But when it comes to pin config: > > > +static int sprd_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin_id, > > + unsigned long *config) > > +{ > > + struct sprd_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); > > + struct sprd_pin *pin = sprd_pinctrl_get_pin_by_id(pctl, pin_id); > > + > > + if (!pin) > > + return -EINVAL; > > + > > + if (pin->type == GLOBAL_CTRL_PIN) { > > + *config = (readl((void __iomem *)pin->reg) >> > > + pin->bit_offset) & PINCTRL_BIT_MASK(pin->bit_width); > > + } else { > > + *config = readl((void __iomem *)pin->reg); > > + } > > + > > + return 0; > > +} > > + > > +static int sprd_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin_id, > > + unsigned long *configs, unsigned int num_configs) > > +{ > > + struct sprd_pinctrl *pctl = pinctrl_dev_get_drvdata(pctldev); > > + struct sprd_pin *pin = sprd_pinctrl_get_pin_by_id(pctl, pin_id); > > + unsigned long reg; > > + int i; > > + > > + if (!pin) > > + return -EINVAL; > > + > > + for (i = 0; i < num_configs; i++) { > > + if (pin->type == GLOBAL_CTRL_PIN) { > > + reg = readl((void __iomem *)pin->reg); > > + reg &= ~(PINCTRL_BIT_MASK(pin->bit_width) > > + << pin->bit_offset); > > + reg |= (configs[i] & PINCTRL_BIT_MASK(pin->bit_width)) > > + << pin->bit_offset; > > + writel(reg, (void __iomem *)pin->reg); > > + } else { > > + writel(configs[i], (void __iomem *)pin->reg); > > + } > > + pin->config = configs[i]; > > + } > > + > > + return 0; > > +} > > This is just hammering the register values, you have effectively defined your > register layout as your device tree ABI. > > Please don't do this, please use genric pin config and use the approach > other drivers take with explicit strings encoding the pin configuration. Make sense. I will try to use genric pin config instead of the magic number. Thanks for your comments. > > Even pinctrl-single that maintain quite a bit of muxing data in the device > tree still use the generic pin config API, see: > drivers/pinctrl/pinctrl-single.c > pcs_pinconf_get(), pcs_pinconf_set() > > Same for group config. > > Yours, > Linus Walleij