From patchwork Sat Nov 28 16:08:02 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noble Pepper X-Patchwork-Id: 549654 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CB3DA1402A6 for ; Sun, 29 Nov 2015 03:08:35 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 2355A28A98D; Sat, 28 Nov 2015 17:08:13 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,HK_RANDOM_ENVFROM autolearn=no version=3.3.2 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id D24DD28A98D for ; Sat, 28 Nov 2015 17:08:05 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .noblepepper. - helo: .dallas123.arvixeshared. - helo-domain: .arvixeshared.) FROM/MX_MATCHES_NOT_HELO(DOMAIN)=1 RANDOM_SENDER=0.25; rate: -5.25 Received: from dallas123.arvixeshared.com (dallas123.arvixeshared.com [207.210.200.146]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Sat, 28 Nov 2015 17:08:03 +0100 (CET) Received: from adsl-98-87-26-127.bna.bellsouth.net ([98.87.26.127]:50846 helo=elbono-bigguy) by dallas123.arvixeshared.com with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.86) (envelope-from ) id 1a2i2d-0001ff-GK; Sat, 28 Nov 2015 11:08:03 -0500 Message-ID: <1448726882.12969.27.camel@noblepepper.com> From: Noble Pepper To: John Crispin Date: Sat, 28 Nov 2015 10:08:02 -0600 In-Reply-To: <565217C8.1090600@openwrt.org> References: <1446553602.2521.26.camel@noblepepper.com> <5650D4C2.9080306@openwrt.org> <1448220398.4993.72.camel@noblepepper.com> <565217C8.1090600@openwrt.org> X-Mailer: Evolution 3.12.9-1+b1 Mime-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - dallas123.arvixeshared.com X-AntiAbuse: Original Domain - lists.openwrt.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - noblepepper.com X-Get-Message-Sender-Via: dallas123.arvixeshared.com: authenticated_id: openwrtmail@noblepepper.com X-Authenticated-Sender: dallas123.arvixeshared.com: openwrtmail@noblepepper.com X-Source: X-Source-Args: X-Source-Dir: Cc: "openwrt-devel@lists.openwrt.org" Subject: Re: [OpenWrt-Devel] [PATCH v2] ramips:Allow funcs in multiple groups in pinctrl-rt2880.c for UARTF pin sharing X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" This does work as you describe if the proper entries are in the device tree. There must be a node for the gpio system to use which references the group and function desired instead of a node like I had for uartf. The changes in v2 from the first patch are: 1. A change similar to what you descibe but instead of changing which pins are marked gpio changing which ones are marked as not gpio. 2. Moving the usage example to a separate .dts file that generates a separate image instead of changing an existing one. 3. Does not touch rt305x.c, uses the existing muxes Please let me know your thoughts. Regards, Noble On Sun, 2015-11-22 at 20:30 +0100, John Crispin wrote: > > On 22/11/2015 20:26, Noble Pepper wrote: > > Hi, thanks for looking at this. > > > > I actually tried this approach before deciding groups that are not a > > fixed set of pins would require modifying pinctrl/pinmux.c and possibly > > pinctrl/core.c thus would affect a lot more than just the ralink > > drivers. > > > > The problem arises when pinmux_enable_setting() in pinmux.c calls > > rt2880_get_group_pins() without any information about which function is > > to be > used. pinmux_enable_setting() then allocates the pins thus > > obtained before calling rt2880_pmx_group_enable (specifying which > > function) and the damage is already done. > > ok, i had a look at the core.c but not in that detail. i'll have another > look tomorrow to see if i can think of another solution. > > > > > The section titled "PINMUX interfaces" in Documentation/pinctrl.txt > > seems to imply that a group is a fixed set of pins and pinmux.c and > > core.c look to have been written assuming this is true. > > > > Regards, Noble > > > > On Sat, 2015-11-21 at 21:32 +0100, John Crispin wrote: > >> Hi, > >> > >> i had a closer look at the code. what you want to do instead of adding 2 > >> dummy muxes is to modify > >> > >> static int rt2880_pmx_group_enable(struct pinctrl_dev *pctrldev, > >> > >> and change this part > >> > >> /* mark the pins as gpio */ > >> for (i = 0; i < p->groups[group].func[0].pin_count; i++) > >> p->gpio[p->groups[group].func[0].pins[i]] = 1; > >> > >> to not use [0] but the real mux which will enable the upper 4 gpio for > >> gpio usage. > >> > >> John > >> > >> On 03/11/2015 13:26, Noble Pepper wrote: > >>> > >>> Signed-off-by: Noble Pepper > >>> --- > >>> Existing pinctrl-rt2880.c code only kept track of one pin group that > >>> functions other than gpio may use. Functions in rt305x.c had differing > >>> numbers of pins which caused rt2880_get_group_pins() to sometimes return > >>> incorrect pins. Example: when trying to use "gpio uartf" function pins > >>> 7-14 instead of 7-10 may be claimed for uartf preventing using gpio on > >>> pins 11-14. Usage of groups and functions added to rt305x.c is shown in > >>> VOCORE.dtsi. > >>> > >>> Signed-off-by: Noble Pepper --- target/linux/ramips/dts/VOCORE-uartf-16M.dts | 72 +++++++++++++++++ target/linux/ramips/image/Makefile | 16 +--- ...ralink-allow-functions-on-multiple-groups.patch | 90 ++++++++++++++++++++++ 3 files changed, 165 insertions(+), 13 deletions(-) create mode 100644 target/linux/ramips/dts/VOCORE-uartf-16M.dts create mode 100644 target/linux/ramips/patches-3.18/0031-pinctrl-ralink-allow-functions-on-multiple-groups.patch diff --git a/target/linux/ramips/dts/VOCORE-uartf-16M.dts b/target/linux/ramips/dts/VOCORE-uartf-16M.dts new file mode 100644 index 0000000..4c8a86b --- /dev/null +++ b/target/linux/ramips/dts/VOCORE-uartf-16M.dts @@ -0,0 +1,72 @@ +/dts-v1/; + +/ { + palmbus@10000000 { + uartlite@c00 { + status = "okay"; + }; + }; +}; +/include/ "VOCORE.dtsi" + +/ { + palmbus@10000000 { + uart@500 { + status = "okay"; + }; + spi@b00 { + m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "w25q128"; + reg = <0>; + linux,modalias = "m25p80", "w25q128"; + spi-max-frequency = <10000000>; + + partition@0 { + label = "uboot"; + reg = <0x0 0x30000>; + read-only; + }; + + partition@30000 { + label = "uboot-env"; + reg = <0x30000 0x10000>; + read-only; + }; + + factory: partition@40000 { + label = "factory"; + reg = <0x40000 0x10000>; + read-only; + }; + + partition@50000 { + label = "firmware"; + reg = <0x50000 0xfb0000>; + }; + }; + }; + }; + pinctrl { + state_default: pinctrl0 { + gpio { + ralink,group = "jtag", "led"; + ralink,function = "gpio"; + }; + gpiouartf { + ralink,group = "uartf"; + ralink,function = "gpio uartf"; + }; + }; + }; + gpio-export { + /* missing gpio11 in standard VOCORE.dtsi*/ + gpio11 { + /* uartf_dtr_n */ + gpio-export,name = "gpio11"; + gpio-export,direction_may_change = <1>; + gpios = <&gpio0 11 0>; + }; + }; +}; diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile index e58d012..7213a4a 100644 --- a/target/linux/ramips/image/Makefile +++ b/target/linux/ramips/image/Makefile @@ -607,6 +607,7 @@ vocore_16mb_mtd_size=16449536 define BuildFirmware/VOCORE/squashfs $(call BuildFirmware/CustomFlash/$(1),$(1),$(2)-8M,$(3)-8M,$(vocore_8mb_mtd_size)) $(call BuildFirmware/CustomFlash/$(1),$(1),$(2)-16M,$(3)-16M,$(vocore_16mb_mtd_size)) + $(call BuildFirmware/CustomFlash/$(1),$(1),$(2)-uartf-16M,$(3)-uartf-16M,$(vocore_16mb_mtd_size)) endef define BuildFirmware/VOCORE/initramfs $(call BuildFirmware/OF/initramfs,$(1),$(2)-8M,$(3)-8M) --- /dev/null +++ b/target/linux/ramips/patches-3.18/0031-pinctrl-ralink-allow-functions-on-multiple-groups.patch @@ -0,0 +1,89 @@ +diff -Naur a/arch/mips/include/asm/mach-ralink/pinmux.h b/arch/mips/include/asm/mach-ralink/pinmux.h +--- a/arch/mips/include/asm/mach-ralink/pinmux.h 2015-11-26 13:04:18.385540854 -0600 ++++ b/arch/mips/include/asm/mach-ralink/pinmux.h 2015-11-26 13:10:43.538466391 -0600 +@@ -31,6 +31,7 @@ + int *pins; + + int *groups; ++ int **group_names; + int group_count; + + int enabled; +diff -Naur a/drivers/pinctrl/pinctrl-rt2880.c b/drivers/pinctrl/pinctrl-rt2880.c +--- a/drivers/pinctrl/pinctrl-rt2880.c 2015-11-26 20:03:51.323363701 -0600 ++++ b/drivers/pinctrl/pinctrl-rt2880.c 2015-11-26 20:12:07.403942521 -0600 +@@ -188,12 +188,8 @@ + unsigned * const num_groups) + { + struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); +- +- if (p->func[func]->group_count == 1) +- *groups = &p->group_names[p->func[func]->groups[0]]; +- else +- *groups = p->group_names; +- ++ if (p->func[func]->group_count != 0) ++ *groups = p->func[func]->group_names; + *num_groups = p->func[func]->group_count; + + return 0; +@@ -206,7 +202,7 @@ + struct rt2880_priv *p = pinctrl_dev_get_drvdata(pctrldev); + u32 mode = 0; + u32 reg = SYSC_REG_GPIO_MODE; +- int i; ++ int i, j; + int shift; + + /* dont allow double use */ +@@ -234,12 +230,16 @@ + if (func == 0) { + mode |= p->groups[group].gpio << shift; + } else { +- for (i = 0; i < p->func[func]->pin_count; i++) +- p->gpio[p->func[func]->pins[i]] = 0; ++ for (j = 0; j < p->groups[group].func_count; j++){ ++ if (strcmp(p->groups[group].func[j].name, p->func[func]->name) == 0){ ++ for (i = 0; i < p->groups[group].func[j].pin_count; i++){ ++ p->gpio[p->groups[group].func[j].pins[i]] = 0; ++ } ++ } ++ } + mode |= p->func[func]->value << shift; + } + rt_sysc_w32(mode, reg); +- + return 0; + } + +@@ -319,12 +319,30 @@ + for (i = 0; i < p->group_count; i++) { + for (j = 0; j < p->groups[i].func_count; j++) { + f[c] = &p->groups[i].func[j]; +- f[c]->groups = devm_kzalloc(p->dev, sizeof(int), GFP_KERNEL); ++ f[c]->groups = devm_kzalloc(p->dev, sizeof(int) * p->group_count, GFP_KERNEL); ++ if (!f[c]->groups) ++ return -1; ++ f[c]->group_names = devm_kzalloc(p->dev, sizeof(char *) * p->group_count, GFP_KERNEL); ++ if (!f[c]->group_names) ++ return -1; + f[c]->groups[0] = i; + f[c]->group_count = 1; + c++; + } + } ++ f[0]->group_names = p->group_names; ++ for (c = 1; c < p->func_count; c++) { ++ f[c]->group_count = 0; ++ for (i = 0; i < p->group_count; i++) { ++ for (j = 0; j < p->groups[i].func_count; j++) { ++ if (strcmp(f[c]->name, p->groups[i].func[j].name) == 0) { ++ f[c]->groups[f[c]->group_count] = i; ++ f[c]->group_names[f[c]->group_count] = p->groups[i].name; ++ f[c]->group_count++; ++ } ++ } ++ } ++ } + return 0; + }