From patchwork Wed Sep 19 21:02:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 10606583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20496112B for ; Wed, 19 Sep 2018 21:04:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 105EA2BA58 for ; Wed, 19 Sep 2018 21:04:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 038A92BB71; Wed, 19 Sep 2018 21:04:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35B752BA58 for ; Wed, 19 Sep 2018 21:04:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t/uCd35X0Jf9IC9jmaxbwPaD65p3BIzxsOHBlAPrpbc=; b=djFRVK+LzZPpBc DVzOjlzHY6VL09SuMQfNdrhkGf0TtZjB9v2LoDoRileRu3rrkyo2G5O/YpABhqIMLKXJayXSvWJ1e dJh6khmTImVSPv8b+fmBa89EivHssB08YxdorAuYxv1T00xNhXjadD1FNwCpY58Leq+GfAsQvNK3t haqUE+IQl144Cxwnyi+Wuw0HfcgTRpI+E/Ol4p6RZoULmSOVbtKN9ntuqjkeUR15C5dKuLZH3+bYp jvhBQANALcvxSdEctOxsSOwOe1FKqB9MMngMn4I9FjOYcvksh64gGlSTfSesypIxe7g87lyi1NOHe AVnb+siy7/vvvR4/G9Kw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2jdd-0007pP-UZ; Wed, 19 Sep 2018 21:03:58 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2jcx-0007YB-Bf for linux-arm-kernel@lists.infradead.org; Wed, 19 Sep 2018 21:03:19 +0000 Received: by mail-lf1-x143.google.com with SMTP id x24-v6so6373861lfe.10 for ; Wed, 19 Sep 2018 14:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0M0nr6ChDfGwKYHG45b4AilQjj63vyytvhfSldZmRUo=; b=kPcGldbCTYIfnUVWbqyEz1fxaM9rVQ4bzodmuZaS0ME6lO2DuK8Gysem8PwAp4oI3a cM0jYg/cQDXcSsnCFg/RTm30cjW6wTSeS4w7DImSk6Uay72s4eF+P6hNdF8Wvyr+HIzH cU9dkbxw89sb9uWabmVqgOQtnMfmY6w3Ax6Msy+VzPv2ZE1X6RQNjJ4NPC3LF0EJNHpW FDjGNlW4u2mLRuIk42mnjAs3zK6KPLR3DlahcVdI0UQ5MDSnE7Q20KdoST0JV0O3TbFX zLsylQjbV1zxdd7kd4jn8ol1n6Y8UR/p4nPkzONTDaa6kBtjc6Bi1bmxOxe/thbayr/Z i3MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0M0nr6ChDfGwKYHG45b4AilQjj63vyytvhfSldZmRUo=; b=deDoh6OxDfKzU1R48jQulU/QxXwf9qndNQBISTPyz9+0wdqZ99VqCVooAHkScjxAK5 9yMo5pWqSd399mYxEpgFOC74O6UoaA7iFfkKMpRtei4kq/qOl3ltHZbqahkNbPP3z5qC 2RP77taiOM4jfAPLNPG7iplttgoB2vJOy675KulqNMJkbBM5HuhH3IyCUTjLUcCO5Mdk MUe5MgVLWQAqlbPNGh9dqqs0nxgpt7IqraURXdMc/ZzFHPR/k3anqzUvlIBXAzAv7u7V qQz/Gs+le5anEVnzcLqOsq44K4xkXhe5HYIsz1w/4AIo2YDRm656WKwcZ8KPcs16Puuh Ostg== X-Gm-Message-State: APzg51DIfI9kv9kB7wfPWn+mBkMVzCmHQoKbQSYmlw3eLL8AGek4hqa1 ZJLJkTEgSWq2RHfhxs6hoDk= X-Google-Smtp-Source: ANB0VdZIM1t84uJCACQMKB65lXyVkQcD1zJJ6HYQFc1nW2wRlHieJ2PS6DBIqNgZ/hkp9Qbwco7jzw== X-Received: by 2002:a19:5e5d:: with SMTP id z29-v6mr641293lfi.110.1537390983123; Wed, 19 Sep 2018 14:03:03 -0700 (PDT) Received: from linux-veee.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id a27-v6sm1263743lfi.59.2018.09.19.14.03.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Sep 2018 14:03:02 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Linus Walleij , linux-gpio@vger.kernel.org, Rob Herring , devicetree@vger.kernel.org Subject: [PATCH 2/2] pinctrl: bcm: add Northstar driver Date: Wed, 19 Sep 2018 23:02:19 +0200 Message-Id: <20180919210219.21921-2-zajec5@gmail.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180919210219.21921-1-zajec5@gmail.com> References: <20180919210219.21921-1-zajec5@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180919_140315_416585_9C1CCA1D X-CRM114-Status: GOOD ( 22.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Scott Branden , Jon Mason , Ray Jui , bcm-kernel-feedback-list@broadcom.com, =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafał Miłecki This driver provides support for Northstar mux controller. It differs from Northstar Plus one so a new binding and driver were needed. Right now it includes support for SPI pins only which is caused by a lack of access to Broadcom's datasheet. SPI pins info was extracted from the Broadcom's SDK. Once more pins are discovered they can be added to the driver without breaking any existing setups. Signed-off-by: Rafał Miłecki --- drivers/pinctrl/bcm/Kconfig | 13 +++ drivers/pinctrl/bcm/Makefile | 1 + drivers/pinctrl/bcm/pinctrl-ns.c | 246 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 drivers/pinctrl/bcm/pinctrl-ns.c diff --git a/drivers/pinctrl/bcm/Kconfig b/drivers/pinctrl/bcm/Kconfig index 0f38d51f47c6..c8575399d6f7 100644 --- a/drivers/pinctrl/bcm/Kconfig +++ b/drivers/pinctrl/bcm/Kconfig @@ -73,6 +73,19 @@ config PINCTRL_CYGNUS_MUX configuration, with the exception that certain individual pins can be overridden to GPIO function +config PINCTRL_NS + bool "Broadcom Northstar pins driver" + depends on OF && (ARCH_BCM_5301X || COMPILE_TEST) + select PINMUX + select GENERIC_PINCONF + default ARCH_BCM_5301X + help + Say yes here to enable the Broadcom NS SoC pins driver. + + The Broadcom Northstar pins driver supports muxing multi-purpose pins + that can be used for various functions (e.g. SPI, I2C, UART) as well + as GPIOs. + config PINCTRL_NSP_GPIO bool "Broadcom NSP GPIO (with PINCONF) driver" depends on OF_GPIO && (ARCH_BCM_NSP || COMPILE_TEST) diff --git a/drivers/pinctrl/bcm/Makefile b/drivers/pinctrl/bcm/Makefile index 80ceb9dae944..79d5e49fdd9a 100644 --- a/drivers/pinctrl/bcm/Makefile +++ b/drivers/pinctrl/bcm/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_PINCTRL_BCM281XX) += pinctrl-bcm281xx.o obj-$(CONFIG_PINCTRL_BCM2835) += pinctrl-bcm2835.o obj-$(CONFIG_PINCTRL_IPROC_GPIO) += pinctrl-iproc-gpio.o obj-$(CONFIG_PINCTRL_CYGNUS_MUX) += pinctrl-cygnus-mux.o +obj-$(CONFIG_PINCTRL_NS) += pinctrl-ns.o obj-$(CONFIG_PINCTRL_NSP_GPIO) += pinctrl-nsp-gpio.o obj-$(CONFIG_PINCTRL_NS2_MUX) += pinctrl-ns2-mux.o obj-$(CONFIG_PINCTRL_NSP_MUX) += pinctrl-nsp-mux.o diff --git a/drivers/pinctrl/bcm/pinctrl-ns.c b/drivers/pinctrl/bcm/pinctrl-ns.c new file mode 100644 index 000000000000..bf7703c4a2e3 --- /dev/null +++ b/drivers/pinctrl/bcm/pinctrl-ns.c @@ -0,0 +1,246 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018 Rafał Miłecki + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct ns_pinctrl { + struct pinctrl_dev *pctldev; + struct device *dev; + void __iomem *base; +}; + +/* + * Pins + */ + +struct ns_pin_data { + unsigned int reg; + unsigned int bit; +}; + +static const struct ns_pin_data ns_pins_data[] = { + [0] = { 0, 0 }, + [1] = { 0, 1 }, + [2] = { 0, 2 }, + [3] = { 0, 3 }, +}; + +static const struct pinctrl_pin_desc ns_pinctrl_pins[] = { + { 0, "spi_clk" }, + { 1, "spi_ss" }, + { 2, "spi_mosi" }, + { 3, "spi_miso" }, +}; + +/* + * Groups + */ + +struct ns_pinctrl_group { + const char *name; + const unsigned int *pins; + const unsigned int num_pins; +}; + +static const unsigned int spi_pins[] = { 0, 1, 2, 3 }; + +#define NS_GROUP(_name, _pins) \ +{ \ + .name = _name, \ + .pins = _pins, \ + .num_pins = ARRAY_SIZE(_pins), \ +} + +static const struct ns_pinctrl_group ns_pinctrl_groups[] = { + NS_GROUP("spi_grp", spi_pins), +}; + +/* + * Functions + */ + +struct ns_pinctrl_function { + const char *name; + const char * const *groups; + const unsigned int num_groups; +}; + +static const char * const spi_groups[] = { "spi_grp" }; + +#define NS_FUNCTION(_name, _groups) \ +{ \ + .name = _name, \ + .groups = _groups, \ + .num_groups = ARRAY_SIZE(_groups), \ +} + +static const struct ns_pinctrl_function ns_pinctrl_functions[] = { + NS_FUNCTION("spi", spi_groups), +}; + +/* + * Groups code + */ + +static int ns_pinctrl_get_groups_count(struct pinctrl_dev *pctrl_dev) +{ + return ARRAY_SIZE(ns_pinctrl_groups); +} + +static const char *ns_pinctrl_get_group_name(struct pinctrl_dev *pctrl_dev, + unsigned int selector) +{ + return ns_pinctrl_groups[selector].name; +} + +static int ns_pinctrl_get_group_pins(struct pinctrl_dev *pctrl_dev, + unsigned int selector, + const unsigned int **pins, + unsigned int *num_pins) +{ + *pins = ns_pinctrl_groups[selector].pins; + *num_pins = ns_pinctrl_groups[selector].num_pins; + + return 0; +} + +static const struct pinctrl_ops ns_pinctrl_ops = { + .get_groups_count = ns_pinctrl_get_groups_count, + .get_group_name = ns_pinctrl_get_group_name, + .get_group_pins = ns_pinctrl_get_group_pins, + .dt_node_to_map = pinconf_generic_dt_node_to_map_group, + .dt_free_map = pinconf_generic_dt_free_map, +}; + +/* + * Functions code + */ + +static int ns_pinctrl_get_functions_count(struct pinctrl_dev *pctrl_dev) +{ + return ARRAY_SIZE(ns_pinctrl_functions); +} + +static const char *ns_pinctrl_get_function_name(struct pinctrl_dev *pctrl_dev, + unsigned int selector) +{ + return ns_pinctrl_functions[selector].name; +} + +static int ns_pinctrl_get_function_groups(struct pinctrl_dev *pctrl_dev, + unsigned int selector, + const char * const **groups, + unsigned * const num_groups) +{ + *groups = ns_pinctrl_functions[selector].groups; + *num_groups = ns_pinctrl_functions[selector].num_groups; + + return 0; +} + +static int ns_pinctrl_set_mux(struct pinctrl_dev *pctrl_dev, + unsigned int func_select, + unsigned int grp_select) +{ + struct ns_pinctrl *ns_pinctrl = pinctrl_dev_get_drvdata(pctrl_dev); + u32 unset[9] = { }; + int i; + + for (i = 0; i < ns_pinctrl_groups[grp_select].num_pins; i++) { + int pin_number = ns_pinctrl_groups[grp_select].pins[i]; + const struct ns_pin_data *data = &ns_pins_data[pin_number]; + + unset[data->reg] |= BIT(data->bit); + } + + for (i = 0; i < ARRAY_SIZE(unset); i++) { + u32 tmp; + + if (!unset[i]) + continue; + + tmp = readl(ns_pinctrl->base + i); + tmp &= ~unset[i]; + writel(tmp, ns_pinctrl->base + i); + } + + return 0; +} + +static const struct pinmux_ops ns_pinctrl_pmxops = { + .get_functions_count = ns_pinctrl_get_functions_count, + .get_function_name = ns_pinctrl_get_function_name, + .get_function_groups = ns_pinctrl_get_function_groups, + .set_mux = ns_pinctrl_set_mux, +}; + +/* + * Controller code + */ + +static struct pinctrl_desc ns_pinctrl_desc = { + .name = "pinctrl-ns", + .pins = ns_pinctrl_pins, + .npins = ARRAY_SIZE(ns_pinctrl_pins), + .pctlops = &ns_pinctrl_ops, + .pmxops = &ns_pinctrl_pmxops, +}; + +static int ns_pinctrl_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct ns_pinctrl *ns_pinctrl; + struct resource *res; + + ns_pinctrl = devm_kzalloc(dev, sizeof(*ns_pinctrl), GFP_KERNEL); + if (!ns_pinctrl) + return -ENOMEM; + ns_pinctrl->dev = dev; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "cru_pins_control"); + ns_pinctrl->base = devm_ioremap_resource(dev, res); + if (IS_ERR(ns_pinctrl->base)) { + dev_err(dev, "Failed to map pinctrl regs\n"); + return PTR_ERR(ns_pinctrl->base); + } + + platform_set_drvdata(pdev, ns_pinctrl); + + ns_pinctrl->pctldev = devm_pinctrl_register(dev, &ns_pinctrl_desc, + ns_pinctrl); + if (IS_ERR(ns_pinctrl->pctldev)) { + dev_err(dev, "Failed to register pinctrl\n"); + return PTR_ERR(ns_pinctrl->pctldev); + } + + return 0; +} + +static const struct of_device_id ns_pinctrl_of_match_table[] = { + { .compatible = "brcm,ns-pinmux" }, + { } +}; + +static struct platform_driver ns_pinctrl_driver = { + .probe = ns_pinctrl_probe, + .driver = { + .name = "ns-pinmux", + .of_match_table = ns_pinctrl_of_match_table, + }, +}; + +module_platform_driver(ns_pinctrl_driver); + +MODULE_AUTHOR("Rafał Miłecki"); +MODULE_LICENSE("GPL v2");