From patchwork Mon Apr 18 19:48:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Lansberry X-Patchwork-Id: 8874641 X-Patchwork-Delegate: sameo@linux.intel.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F0EE2BF29F for ; Mon, 18 Apr 2016 19:49:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9A2E201C8 for ; Mon, 18 Apr 2016 19:49:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B9B71201BC for ; Mon, 18 Apr 2016 19:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752100AbcDRTtK (ORCPT ); Mon, 18 Apr 2016 15:49:10 -0400 Received: from mail-qg0-f49.google.com ([209.85.192.49]:34423 "EHLO mail-qg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751886AbcDRTtI (ORCPT ); Mon, 18 Apr 2016 15:49:08 -0400 Received: by mail-qg0-f49.google.com with SMTP id c6so124731718qga.1 for ; Mon, 18 Apr 2016 12:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kuvee-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UNvfDIM+4Q306SmzRIcnPopxQgQX23/P69K12ED04is=; b=w4cPRMc/DZdvZaSuwXoXCvt0EX3W9LFsHMzv8lT7Nj4HSVmYQKNqGhacaBmjfnZscw Jot3VMwjMbINR9o0N0YP3kS2TaO2fnVMv0b4kmU56HPnq/JbOjA4jkcX2lg2UBcM/APX jVE7j5iYBB2/BXFo5ZHHnAIdnIOZ1ix+TXYVWewzT1Lm9tESKQ1fmQigZ5xGMCFBRL9E Y0Zo8PRWqw4f4b5DUKDOnubd/99Fq6FXatmncSuiibHeEAycKqQpSXlBDBqi/pglbe2E RNI0iX7BXo6zUZjdRLaCEZRXSFwXSRZOE2Rg4sNe4S4LA0jqIRxRNT+pVKfUUwq79SM3 G1gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UNvfDIM+4Q306SmzRIcnPopxQgQX23/P69K12ED04is=; b=lcM7CI1CkEJpL3+X/NDZVC/zR2HxzavWR0cNAbz0f9rSeEl2uBebSNXDjFo68gfFB1 s9t5k6Fm2C8b4WJu1c3ev1nnMtx6oI/omKNykaxmSBwRkx2nkKFgC/KO33BTOhmmCn1s F+sQ6IF6zxZykZNjmI3DoGQtyphuASQVoILw8jKXjE6Mn+AQG9eZl0rktq55zMtco53t jBe8jcuXv5/NxNm26ZiJQiENk1ay/XnLNYo0wjhN23+w7mfgXb4xsCsqvF39xLqUbU4U 7tqk0XxvoEPCqQ2TsNhoBoZ0wWyERx9UiZd7DnFx7dIW5jnS76FuEd8KMgDLLKtFUufx Eyfw== X-Gm-Message-State: AOPr4FVI02UwOUkEbLNOlr5XpWDc7xwMdkf0qIFwA3An7a12J665N9qujoZNjljI5aaMcA== X-Received: by 10.55.156.201 with SMTP id f192mr6952625qke.9.1461008947591; Mon, 18 Apr 2016 12:49:07 -0700 (PDT) Received: from localhost (c-76-28-119-232.hsd1.ma.comcast.net. [76.28.119.232]) by smtp.gmail.com with ESMTPSA id s85sm23056158qke.29.2016.04.18.12.49.06 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 18 Apr 2016 12:49:07 -0700 (PDT) From: Geoff Lansberry To: linux-wireless@vger.kernel.org Cc: lauro.venancio@openbossa.org, aloisio.almeida@openbossa.org, sameo@linux.intel.com, mgreer@animalcreek.com, justin@kuvee.com, Geoff Lansberry Subject: [PATCH 1/4] NFC: trf7970a: Add support for gpio as SS Date: Mon, 18 Apr 2016 15:48:38 -0400 Message-Id: <1461008921-15100-2-git-send-email-geoff@kuvee.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461008921-15100-1-git-send-email-geoff@kuvee.com> References: <1461008921-15100-1-git-send-email-geoff@kuvee.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Geoff Lansberry --- .../devicetree/bindings/net/nfc/trf7970a.txt | 2 ++ drivers/nfc/trf7970a.c | 33 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt index 32b35a0..09c5056 100644 --- a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt +++ b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt @@ -7,6 +7,7 @@ Required properties: - interrupts: A single interrupt specifier. - ti,enable-gpios: Two GPIO entries used for 'EN' and 'EN2' pins on the TRF7970A. +- ti,ss-gpio: GPIO entry used for active low SS (spi slave select) on the TRF7970A - vin-supply: Regulator for supply voltage to VIN pin Optional SoC Specific Properties: @@ -37,6 +38,7 @@ Example (for ARM-based BeagleBone with TRF7970A on SPI1): interrupts = <14 0>; ti,enable-gpios = <&gpio2 2 GPIO_ACTIVE_LOW>, <&gpio2 5 GPIO_ACTIVE_LOW>; + ti,ss-gpio = <&gpio2 4 GPIO_ACTIVE_HIGH>; vin-supply = <&ldo3_reg>; vin-voltage-override = <5000000>; autosuspend-delay = <30000>; diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 10842b7..2c3530a 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -450,6 +450,7 @@ struct trf7970a { bool adjust_resp_len; int en2_gpio; int en_gpio; + int ss_gpio; struct mutex lock; unsigned int timeout; bool ignore_timeout; @@ -462,9 +463,11 @@ static int trf7970a_cmd(struct trf7970a *trf, u8 opcode) u8 cmd = TRF7970A_CMD_BIT_CTRL | TRF7970A_CMD_BIT_OPCODE(opcode); int ret; + gpio_set_value(trf->ss_gpio, 0); dev_dbg(trf->dev, "cmd: 0x%x\n", cmd); ret = spi_write(trf->spi, &cmd, 1); + gpio_set_value(trf->ss_gpio, 1); if (ret) dev_err(trf->dev, "%s - cmd: 0x%x, ret: %d\n", __func__, cmd, ret); @@ -476,7 +479,9 @@ static int trf7970a_read(struct trf7970a *trf, u8 reg, u8 *val) u8 addr = TRF7970A_CMD_BIT_RW | reg; int ret; + gpio_set_value(trf->ss_gpio, 0); ret = spi_write_then_read(trf->spi, &addr, 1, val, 1); + gpio_set_value(trf->ss_gpio, 1); if (ret) dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, ret); @@ -493,6 +498,7 @@ static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, size_t len) struct spi_message m; int ret; + gpio_set_value(trf->ss_gpio, 0); dev_dbg(trf->dev, "read_cont(0x%x, %zd)\n", addr, len); spi_message_init(&m); @@ -508,6 +514,7 @@ static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, size_t len) spi_message_add_tail(&t[1], &m); ret = spi_sync(trf->spi, &m); + gpio_set_value(trf->ss_gpio, 1); if (ret) dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, ret); @@ -519,9 +526,11 @@ static int trf7970a_write(struct trf7970a *trf, u8 reg, u8 val) u8 buf[2] = { reg, val }; int ret; + gpio_set_value(trf->ss_gpio, 0); dev_dbg(trf->dev, "write(0x%x): 0x%x\n", reg, val); ret = spi_write(trf->spi, buf, 2); + gpio_set_value(trf->ss_gpio, 1); if (ret) dev_err(trf->dev, "%s - write: 0x%x 0x%x, ret: %d\n", __func__, buf[0], buf[1], ret); @@ -535,6 +544,7 @@ static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status) u8 buf[2]; u8 addr; + gpio_set_value(trf->ss_gpio, 0); addr = TRF7970A_IRQ_STATUS | TRF7970A_CMD_BIT_RW; if (trf->quirks & TRF7970A_QUIRK_IRQ_STATUS_READ) { @@ -544,6 +554,7 @@ static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status) ret = spi_write_then_read(trf->spi, &addr, 1, buf, 1); } + gpio_set_value(trf->ss_gpio, 1); if (ret) dev_err(trf->dev, "%s - irqstatus: Status read failed: %d\n", __func__, ret); @@ -559,6 +570,7 @@ static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto) u8 buf[2]; u8 addr; + gpio_set_value(trf->ss_gpio, 0); addr = TRF79070A_NFC_TARGET_PROTOCOL | TRF7970A_CMD_BIT_RW | TRF7970A_CMD_BIT_CONTINUOUS; @@ -569,6 +581,7 @@ static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto) else *target_proto = buf[0]; + gpio_set_value(trf->ss_gpio, 1); return ret; } @@ -663,6 +676,7 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, print_hex_dump_debug("trf7970a tx data: ", DUMP_PREFIX_NONE, 16, 1, skb->data, len, false); + gpio_set_value(trf->ss_gpio, 0); spi_message_init(&m); memset(&t, 0, sizeof(t)); @@ -679,7 +693,7 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, if (ret) { dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__, ret); - return ret; + goto out_err; } skb_pull(skb, len); @@ -706,7 +720,9 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); - return 0; +out_err: + gpio_set_value(trf->ss_gpio, 1); + return ret; } static void trf7970a_fill_fifo(struct trf7970a *trf) @@ -2039,6 +2055,19 @@ static int trf7970a_probe(struct spi_device *spi) return ret; } + trf->ss_gpio = of_get_named_gpio(np, "ti,ss-gpio", 0); + if (!gpio_is_valid(trf->ss_gpio)) { + dev_err(trf->dev, "No SS GPIO property\n"); + return trf->ss_gpio; + } + + ret = devm_gpio_request_one(trf->dev, trf->ss_gpio, + GPIOF_DIR_OUT | GPIOF_INIT_HIGH, "trf7970a SS"); + if (ret) { + dev_err(trf->dev, "Can't request SS GPIO: %d\n", ret); + return ret; + } + if (of_property_read_bool(np, "en2-rf-quirk")) trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW;