Received: by 10.223.164.202 with SMTP id h10csp926476wrb; Fri, 17 Nov 2017 10:55:20 -0800 (PST) X-Google-Smtp-Source: AGs4zMarXu9dg3Eq7etPgTI1u+j99aUzKNzl4xJXz7ETugYzd+cJPe+g//snJyvDyt6vLd0kuYN4 X-Received: by 10.98.18.79 with SMTP id a76mr3068914pfj.204.1510944920846; Fri, 17 Nov 2017 10:55:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510944920; cv=none; d=google.com; s=arc-20160816; b=RF1RP10w4nTtGXumbA/0SEFicnp7Jz2LYm4njSAO+Ko14/jdJgVFGN4uSu+Ue9hqBN wQVu7c2u48hgrYOblxQ9hJhx6s/3ThkfuO+pBqNC1ayq/r3uDQ7faV9ZMhhfb2hoyFSE TDuJjdLZVopMHWWlarB/rystT8G3AVrU5hjkPEHieVn6bQyRU/sQRH2b+zRPkFA+Yn/O Zh0KojzFCs0TPqM7ud5jwlOSfUxIsuXdq76mFjGDXO1gFKrIabast6mC59/Pbd3V02rv cDa2oHTyR6nzihdVBn5v498XYRhCo5CMv9FuwXH69vo4OibyTjpn1FhWmkteQX7OI042 BdzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :dkim-signature:arc-authentication-results; bh=l1pN8o1p6KwVcJeTMIT6I1nBqBtCHGvCSnqt8AdKLHM=; b=mqRcvinP+FMynxGrd/c5uPQIYI7P267XDVjolYXxTrAfUW82e+0jJoEOuW6jxFFj5D qpcHAzgRkibJVVYxadaUUYqQxusAzntPUOzxK91wlO1ejPtmlVUu/HZRPM3FvuzehKd/ T5D5tdcFIWhJHofEDYYLxuCPu86z4ijwaA0Xa7YWzA/t6FTLwnsBrEzPeDmyjqLNtS8l SHGBcchSW1AENFPZdJ99KwTyfRCqmnayYf8BbPY6J3sk4gwwhSiX4a/9VBq3j2p7urkZ GdjYLAPSrx/nIVlYEr2b6CTEkyzjhveU7nLsPJvMRkA0KsySrPvvtBD3jBp9TIlp3f9t uszA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=KCpowSR1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c78si3515691pfd.293.2017.11.17.10.55.07; Fri, 17 Nov 2017 10:55:20 -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; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=KCpowSR1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756590AbdKQNSH (ORCPT + 92 others); Fri, 17 Nov 2017 08:18:07 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:35414 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756405AbdKQNSB (ORCPT ); Fri, 17 Nov 2017 08:18:01 -0500 Received: by mail-wm0-f66.google.com with SMTP id y80so6397126wmd.0 for ; Fri, 17 Nov 2017 05:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:organization:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=l1pN8o1p6KwVcJeTMIT6I1nBqBtCHGvCSnqt8AdKLHM=; b=KCpowSR1W452h+VI98Wq3uIOzFqVhh6Vq02Fy7W+QZSbU2rsoTy1ZB4MdDdKcNEjCs KdPD5bBpWDRwTUKqyQJYc6OUjlhnif4oCJxaAgvwi1sBwQRrF0nOzO7oj7h/HWJCeO2+ V0YMWNde28q1z4Ay/ZNnPOPraTcA2megp5mPaBaHd2q4YfGsEQxTmFtwVSZoVdB+oMCu iBKdbm5Jq7Zk554G10krCuhDNo+CQfgaHv+/Ttr0Mzqe+R3mUNkZeSzHA7Zy8egaJTKh dH8UoJp5045v6UBS/+edD+m1acQKdk3XmwvnK3MvQu/XepkUnZmEe2uqLvQo+55q04lR q24A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=l1pN8o1p6KwVcJeTMIT6I1nBqBtCHGvCSnqt8AdKLHM=; b=OV5LOo0VNLv/bgFbvkwk9E+FdrluvW9FMmS/UlS5VJ0I9gixit31C6DHkyJPTkERi/ oG6+iOznWslY83hbi5+5/vFEayHyrRR95fRR7TPV6EK71t1glemjpuHqCjVa7t7ysGU7 tpYlO8JuRO0HEwap2Tc9YcqRIUBVOeEfncV6tB5fdykQ8F5ajkvAVdErkMLXuWY3Rjue 1LEmQTggPg/Q2Mm799oDQdSZQwU2FbcfKGbiQxYAbliONsdhXV5qynMeNWU5W+QGf2Nt 7Sm0t25Qw/wfaynAGch2UAF0OAqd0AlARH0J0G6HQtRzQSpkYopszzkb/YuIqeb5z886 MUfg== X-Gm-Message-State: AJaThX4Sipo/dpbBFdVNCOwxesy8qPx+OjUUxlW6D8adeM0iQuPFwYaR x761cn3uY4BH/qyZYQuzvp4f8FBo+8s= X-Received: by 10.80.176.194 with SMTP id j60mr7551728edd.254.1510924680068; Fri, 17 Nov 2017 05:18:00 -0800 (PST) Received: from [192.168.1.29] ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id s8sm1480304edh.51.2017.11.17.05.17.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Nov 2017 05:17:59 -0800 (PST) Subject: Re: [PATCH 2/4] pinctrl: meson-axg: Introduce a pinctrl pinmux ops for Meson-AXG SoC To: Yixun Lan , Jerome Brunet , Linus Walleij Cc: Carlo Caione , Kevin Hilman , Xingyu Chen , linux-amlogic@lists.infradead.org, linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20171108064717.32577-1-yixun.lan@amlogic.com> From: Neil Armstrong Organization: Baylibre Message-ID: <902cc0db-13d1-fcb9-23fa-6883df37e814@baylibre.com> Date: Fri, 17 Nov 2017 14:17:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171108064717.32577-1-yixun.lan@amlogic.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/11/2017 07:47, Yixun Lan wrote: > From: Xingyu Chen > > The pin controller has been updated in the Amlogic Meson AXG series, > which use continuous 4-bit register to select function for each pin. > In order to support this, a new pinmux operations "meson_axg_pmx_ops" > has been added. > > Signed-off-by: Xingyu Chen > Signed-off-by: Yixun Lan > --- > drivers/pinctrl/meson/Kconfig | 3 + > drivers/pinctrl/meson/Makefile | 1 + > drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c | 118 ++++++++++++++++++++++++++ > drivers/pinctrl/meson/pinctrl-meson-axg-pmx.h | 62 ++++++++++++++ > drivers/pinctrl/meson/pinctrl-meson.h | 1 + > 5 files changed, 185 insertions(+) > create mode 100644 drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c > create mode 100644 drivers/pinctrl/meson/pinctrl-meson-axg-pmx.h > > diff --git a/drivers/pinctrl/meson/Kconfig b/drivers/pinctrl/meson/Kconfig > index 1a51778759ea..fe5e6ca88412 100644 > --- a/drivers/pinctrl/meson/Kconfig > +++ b/drivers/pinctrl/meson/Kconfig > @@ -38,4 +38,7 @@ config PINCTRL_MESON_GXL > config PINCTRL_MESON8_PMX > bool > > +config PINCTRL_MESON_AXG_PMX > + bool > + > endif > diff --git a/drivers/pinctrl/meson/Makefile b/drivers/pinctrl/meson/Makefile > index cbd47bb74549..8de839512677 100644 > --- a/drivers/pinctrl/meson/Makefile > +++ b/drivers/pinctrl/meson/Makefile > @@ -4,3 +4,4 @@ obj-$(CONFIG_PINCTRL_MESON8) += pinctrl-meson8.o > obj-$(CONFIG_PINCTRL_MESON8B) += pinctrl-meson8b.o > obj-$(CONFIG_PINCTRL_MESON_GXBB) += pinctrl-meson-gxbb.o > obj-$(CONFIG_PINCTRL_MESON_GXL) += pinctrl-meson-gxl.o > +obj-$(CONFIG_PINCTRL_MESON_AXG_PMX) += pinctrl-meson-axg-pmx.o > diff --git a/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c > new file mode 100644 > index 000000000000..e8931d9cf863 > --- /dev/null > +++ b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.c > @@ -0,0 +1,118 @@ > +/* > + * Second generation of pinmux driver for Amlogic Meson-AXG SoC. > + * > + * Copyright (c) 2017 Baylibre SAS. > + * Author: Jerome Brunet > + * > + * Copyright (c) 2017 Amlogic, Inc. All rights reserved. > + * Author: Xingyu Chen > + * > + * SPDX-License-Identifier: (GPL-2.0+ or MIT) > + */ > + > +/* > + * This new generation of pinctrl IP is mainly adopted by the > + * Meson-AXG SoC and later series, which use 4-width continuous > + * register bit to select the function for each pin. > + * > + * The value 0 is always selecting the GPIO mode, while other > + * values (start from 1) for selecting the function mode. > + */ > +#include > +#include > +#include > +#include > + > +#include "pinctrl-meson.h" > +#include "pinctrl-meson-axg-pmx.h" > + > +static int meson_axg_pmx_get_bank(struct meson_pinctrl *pc, > + unsigned int pin, > + struct meson_pmx_bank **bank) > +{ > + int i; > + struct meson_axg_pmx_data *pmx = pc->data->pmx_data; > + > + for (i = 0; i < pmx->num_pmx_banks; i++) > + if (pin >= pmx->pmx_banks[i].first && > + pin <= pmx->pmx_banks[i].last) { > + *bank = &pmx->pmx_banks[i]; > + return 0; > + } > + > + return -EINVAL; > +} > + > +static int meson_pmx_calc_reg_and_offset(struct meson_pmx_bank *bank, > + unsigned int pin, unsigned int *reg, > + unsigned int *offset) > +{ > + int shift; > + > + shift = pin - bank->first; > + > + *reg = bank->reg + (bank->offset + (shift << 2)) / 32; > + *offset = (bank->offset + (shift << 2)) % 32; > + > + return 0; > +} > + > +static int meson_axg_pmx_update_function(struct meson_pinctrl *pc, > + unsigned int pin, unsigned int func) > +{ > + int ret; > + int reg; > + int offset; > + struct meson_pmx_bank *bank; > + > + ret = meson_axg_pmx_get_bank(pc, pin, &bank); > + if (ret) > + return ret; > + > + meson_pmx_calc_reg_and_offset(bank, pin, ®, &offset); > + > + ret = regmap_update_bits(pc->reg_mux, reg << 2, > + 0xf << offset, (func & 0xf) << offset); > + > + return ret; > +} > + > +static int meson_axg_pmx_set_mux(struct pinctrl_dev *pcdev, > + unsigned int func_num, unsigned int group_num) > +{ > + int i; > + int ret; > + struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); > + struct meson_pmx_func *func = &pc->data->funcs[func_num]; > + struct meson_pmx_group *group = &pc->data->groups[group_num]; > + struct meson_pmx_axg_data *pmx_data = > + (struct meson_pmx_axg_data *)group->data; > + > + dev_dbg(pc->dev, "enable function %s, group %s\n", func->name, > + group->name); > + > + for (i = 0; i < group->num_pins; i++) { > + ret = meson_axg_pmx_update_function(pc, group->pins[i], > + pmx_data->func); > + if (ret) > + return ret; > + } > + > + return 0; > +} > + > +static int meson_axg_pmx_request_gpio(struct pinctrl_dev *pcdev, > + struct pinctrl_gpio_range *range, unsigned int offset) > +{ > + struct meson_pinctrl *pc = pinctrl_dev_get_drvdata(pcdev); > + > + return meson_axg_pmx_update_function(pc, offset, 0); > +} > + > +const struct pinmux_ops meson_axg_pmx_ops = { > + .set_mux = meson_axg_pmx_set_mux, > + .get_functions_count = meson_pmx_get_funcs_count, > + .get_function_name = meson_pmx_get_func_name, > + .get_function_groups = meson_pmx_get_groups, > + .gpio_request_enable = meson_axg_pmx_request_gpio, > +}; > diff --git a/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.h b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.h > new file mode 100644 > index 000000000000..8ff88bf2e849 > --- /dev/null > +++ b/drivers/pinctrl/meson/pinctrl-meson-axg-pmx.h > @@ -0,0 +1,62 @@ > +/* > + * Copyright (c) 2017 Baylibre SAS. > + * Author: Jerome Brunet > + * > + * Copyright (c) 2017 Amlogic, Inc. All rights reserved. > + * Author: Xingyu Chen > + * > + * SPDX-License-Identifier: (GPL-2.0+ or MIT) > + */ > + > +struct meson_pmx_bank { > + const char *name; > + unsigned int first; > + unsigned int last; > + unsigned int reg; > + unsigned int offset; > +}; > + > +struct meson_axg_pmx_data { > + struct meson_pmx_bank *pmx_banks; > + unsigned int num_pmx_banks; > +}; > + > +#define BANK_PMX(n, f, l, r, o) \ > + { \ > + .name = n, \ > + .first = f, \ > + .last = l, \ > + .reg = r, \ > + .offset = o, \ > + } > + > +struct meson_pmx_axg_data { > + unsigned int func; > +}; > + > +#define PMX_DATA(f) \ > + { \ > + .func = f, \ > + } > + > +#define GROUP(grp, f) \ > + { \ > + .name = #grp, \ > + .pins = grp ## _pins, \ > + .num_pins = ARRAY_SIZE(grp ## _pins), \ > + .data = (const struct meson_pmx_axg_data[]){ \ > + PMX_DATA(f), \ > + }, \ > + } > + > +#define GPIO_GROUP(gpio) \ > + { \ > + .name = #gpio, \ > + .pins = (const unsigned int[]){ gpio }, \ > + .num_pins = 1, \ > + .data = (const struct meson_pmx_axg_data[]){ \ > + PMX_DATA(0), \ > + }, \ > + } > + > +extern const struct pinmux_ops meson_axg_pmx_ops; > diff --git a/drivers/pinctrl/meson/pinctrl-meson.h b/drivers/pinctrl/meson/pinctrl-meson.h > index 183b6e471635..12a391109329 100644 > --- a/drivers/pinctrl/meson/pinctrl-meson.h > +++ b/drivers/pinctrl/meson/pinctrl-meson.h > @@ -108,6 +108,7 @@ struct meson_pinctrl_data { > struct meson_bank *banks; > unsigned int num_banks; > const struct pinmux_ops *pmx_ops; > + void *pmx_data; > }; > > struct meson_pinctrl { > Reviewed-by: Neil Armstrong From 1583483587975584422@xxx Wed Nov 08 07:53:48 +0000 2017 X-GM-THRID: 1583483587975584422 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread