From 67dec1928d08b6ca7dc9bebc4d3fe2d54da4b108 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:49 -0700 Subject: NFC: trf7970a: Don't de-assert EN2 unless it was asserted When the trf7970a part has the bug related to 'en2-rf-quirk', the GPIO connected to the EN2 pin will not be asserted by the driver when powering up so it shouldn't be de-asserted when powering down. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 2d1c8ca6e679..1a87525a88cd 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -1940,8 +1940,10 @@ static int trf7970a_power_down(struct trf7970a *trf) } gpio_set_value(trf->en_gpio, 0); - if (gpio_is_valid(trf->en2_gpio)) - gpio_set_value(trf->en2_gpio, 0); + + if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) + if (gpio_is_valid(trf->en2_gpio)) + gpio_set_value(trf->en2_gpio, 0); ret = regulator_disable(trf->regulator); if (ret) -- cgit v1.2.3 From 69f984f037a869477cac654a834e8b5435bb35b6 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:50 -0700 Subject: NFC: trf7970a: Fix inaccurate comment in trf7970a_probe() As of commit ce69b95ca4e4 ("NFC: Make EN2 pin optional in the TRF7970A driver"), only the GPIO for the 'EN' enable pin needs to be specified in the device tree so update the comments that says both 'EN' and 'EN2' must be specified. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 1a87525a88cd..5d5a8b0e57d4 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2046,7 +2046,7 @@ static int trf7970a_probe(struct spi_device *spi) if (of_property_read_bool(np, "irq-status-read-quirk")) trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; - /* There are two enable pins - both must be present */ + /* There are two enable pins - only EN must be present in the DT */ trf->en_gpio = of_get_named_gpio(np, "ti,enable-gpios", 0); if (!gpio_is_valid(trf->en_gpio)) { dev_err(trf->dev, "No EN GPIO property\n"); -- cgit v1.2.3 From afcb9fbdba71cd39daefaff1e288472565df6af2 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:51 -0700 Subject: NFC: trf7970a: Only check 'en2-rf-quirk' if EN2 is specified The quirk indicated by the 'en2-rf-quirk' device tree property is only relevant when there is a GPIO connected to the EN2 pin of the trf7970a. This means we should only check for 'en2-rf-quirk' when EN2 is specified in the 'ti,enable-gpios' property of the device tree. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 5d5a8b0e57d4..4655680b0e7b 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2070,6 +2070,9 @@ static int trf7970a_probe(struct spi_device *spi) dev_err(trf->dev, "Can't request EN2 GPIO: %d\n", ret); return ret; } + + if (of_property_read_bool(np, "en2-rf-quirk")) + trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; } of_property_read_u32(np, "clock-frequency", &clk_freq); @@ -2081,9 +2084,6 @@ static int trf7970a_probe(struct spi_device *spi) return -EINVAL; } - if (of_property_read_bool(np, "en2-rf-quirk")) - trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; - ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, trf7970a_irq, IRQF_TRIGGER_RISING | IRQF_ONESHOT, "trf7970a", trf); -- cgit v1.2.3 From fcc652f6885cd37a0c3f3b1ed572d3544c3240c4 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:52 -0700 Subject: NFC: trf7970a: Remove useless comment The last entry in the trf7970a_of_match[] table must be an empty entry to demarcate the end of the table. Currently, there is a comment indicating this but it is obvious so remove the comment. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 4655680b0e7b..b9a90843ea35 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2273,7 +2273,7 @@ static const struct dev_pm_ops trf7970a_pm_ops = { static const struct of_device_id trf7970a_of_match[] = { { .compatible = "ti,trf7970a", }, - { /* sentinel */ }, + {}, }; MODULE_DEVICE_TABLE(of, trf7970a_of_match); -- cgit v1.2.3 From a34631c2723797dd31e6f83538899eeb4c03b753 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:53 -0700 Subject: NFC: trf7970a: Remove support for 'vin-voltage-override' DT property The 'vin-voltage-override' DT property is used by the trf7970a driver to override the voltage presented to the driver by the regulator subsystem. This is unnecessary as properly specifying the regulator chain via DT properties will accomplish the same thing. Therefore, remove support for 'vin-voltage-override'. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- Documentation/devicetree/bindings/net/nfc/trf7970a.txt | 2 -- drivers/nfc/trf7970a.c | 11 +---------- 2 files changed, 1 insertion(+), 12 deletions(-) (limited to 'drivers/nfc') diff --git a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt index c627bbb3009e..57cb52c94783 100644 --- a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt +++ b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt @@ -13,7 +13,6 @@ Optional SoC Specific Properties: - pinctrl-names: Contains only one value - "default". - pintctrl-0: Specifies the pin control groups used for this controller. - autosuspend-delay: Specify autosuspend delay in milliseconds. -- vin-voltage-override: Specify voltage of VIN pin in microvolts. - irq-status-read-quirk: Specify that the trf7970a being used has the "IRQ Status Read" erratum. - en2-rf-quirk: Specify that the trf7970a being used has the "EN2 RF" @@ -40,7 +39,6 @@ Example (for ARM-based BeagleBone with TRF7970A on SPI1): ti,enable-gpios = <&gpio2 2 GPIO_ACTIVE_LOW>, <&gpio2 5 GPIO_ACTIVE_LOW>; vin-supply = <&ldo3_reg>; - vin-voltage-override = <5000000>; vdd-io-supply = <&ldo2_reg>; autosuspend-delay = <30000>; irq-status-read-quirk; diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index b9a90843ea35..5827ad111942 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2005,12 +2005,6 @@ static int trf7970a_get_autosuspend_delay(struct device_node *np) return autosuspend_delay; } -static int trf7970a_get_vin_voltage_override(struct device_node *np, - u32 *vin_uvolts) -{ - return of_property_read_u32(np, "vin-voltage-override", vin_uvolts); -} - static int trf7970a_probe(struct spi_device *spi) { struct device_node *np = spi->dev.of_node; @@ -2108,10 +2102,7 @@ static int trf7970a_probe(struct spi_device *spi) goto err_destroy_lock; } - ret = trf7970a_get_vin_voltage_override(np, &uvolts); - if (ret) - uvolts = regulator_get_voltage(trf->regulator); - + uvolts = regulator_get_voltage(trf->regulator); if (uvolts > 4000000) trf->chip_status_ctrl = TRF7970A_CHIP_STATUS_VRS5_3; -- cgit v1.2.3 From d34e48d6a62a06eb7f72c7dc534c4c318a163dad Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:55 -0700 Subject: NFC: trf7970a: Convert to descriptor based GPIO interface The trf7970a driver uses the deprecated integer-based GPIO consumer interface so convert it to use the new descriptor-based GPIO consumer interface. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/Kconfig | 2 +- drivers/nfc/trf7970a.c | 61 +++++++++++++++++++++----------------------------- 2 files changed, 26 insertions(+), 37 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/Kconfig b/drivers/nfc/Kconfig index c4208487fadc..b065eb605215 100644 --- a/drivers/nfc/Kconfig +++ b/drivers/nfc/Kconfig @@ -7,7 +7,7 @@ menu "Near Field Communication (NFC) devices" config NFC_TRF7970A tristate "Texas Instruments TRF7970a NFC driver" - depends on SPI && NFC_DIGITAL + depends on SPI && NFC_DIGITAL && GPIOLIB help This option enables the NFC driver for Texas Instruments' TRF7970a device. Such device supports 5 different protocols: ISO14443A, diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 5827ad111942..bb777f50b4fb 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -20,9 +20,8 @@ #include #include #include -#include +#include #include -#include #include #include @@ -452,8 +451,8 @@ struct trf7970a { u8 tx_cmd; bool issue_eof; bool adjust_resp_len; - int en2_gpio; - int en_gpio; + struct gpio_desc *en_gpiod; + struct gpio_desc *en2_gpiod; struct mutex lock; unsigned int timeout; bool ignore_timeout; @@ -1908,14 +1907,13 @@ static int trf7970a_power_up(struct trf7970a *trf) usleep_range(5000, 6000); - if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) { - if (gpio_is_valid(trf->en2_gpio)) { - gpio_set_value(trf->en2_gpio, 1); - usleep_range(1000, 2000); - } + if (trf->en2_gpiod && + !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) { + gpiod_set_value_cansleep(trf->en2_gpiod, 1); + usleep_range(1000, 2000); } - gpio_set_value(trf->en_gpio, 1); + gpiod_set_value_cansleep(trf->en_gpiod, 1); usleep_range(20000, 21000); @@ -1939,11 +1937,11 @@ static int trf7970a_power_down(struct trf7970a *trf) return -EBUSY; } - gpio_set_value(trf->en_gpio, 0); + gpiod_set_value_cansleep(trf->en_gpiod, 0); - if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) - if (gpio_is_valid(trf->en2_gpio)) - gpio_set_value(trf->en2_gpio, 0); + if (trf->en2_gpiod && + !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) + gpiod_set_value_cansleep(trf->en2_gpiod, 0); ret = regulator_disable(trf->regulator); if (ret) @@ -2041,32 +2039,23 @@ static int trf7970a_probe(struct spi_device *spi) trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; /* There are two enable pins - only EN must be present in the DT */ - trf->en_gpio = of_get_named_gpio(np, "ti,enable-gpios", 0); - if (!gpio_is_valid(trf->en_gpio)) { + trf->en_gpiod = devm_gpiod_get_index(trf->dev, "ti,enable", 0, + GPIOD_OUT_LOW); + if (IS_ERR(trf->en_gpiod)) { dev_err(trf->dev, "No EN GPIO property\n"); - return trf->en_gpio; - } - - ret = devm_gpio_request_one(trf->dev, trf->en_gpio, - GPIOF_DIR_OUT | GPIOF_INIT_LOW, "trf7970a EN"); - if (ret) { - dev_err(trf->dev, "Can't request EN GPIO: %d\n", ret); - return ret; + return PTR_ERR(trf->en_gpiod); } - trf->en2_gpio = of_get_named_gpio(np, "ti,enable-gpios", 1); - if (!gpio_is_valid(trf->en2_gpio)) { + trf->en2_gpiod = devm_gpiod_get_index_optional(trf->dev, "ti,enable", 1, + GPIOD_OUT_LOW); + if (!trf->en2_gpiod) { dev_info(trf->dev, "No EN2 GPIO property\n"); - } else { - ret = devm_gpio_request_one(trf->dev, trf->en2_gpio, - GPIOF_DIR_OUT | GPIOF_INIT_LOW, "trf7970a EN2"); - if (ret) { - dev_err(trf->dev, "Can't request EN2 GPIO: %d\n", ret); - return ret; - } - - if (of_property_read_bool(np, "en2-rf-quirk")) - trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; + } else if (IS_ERR(trf->en2_gpiod)) { + dev_err(trf->dev, "Error getting EN2 GPIO property: %ld\n", + PTR_ERR(trf->en2_gpiod)); + return PTR_ERR(trf->en2_gpiod); + } else if (of_property_read_bool(np, "en2-rf-quirk")) { + trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW; } of_property_read_u32(np, "clock-frequency", &clk_freq); -- cgit v1.2.3 From e2f0f67108a8f8ec23e2e530a1a52c97595a6f96 Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Tue, 25 Apr 2017 15:43:56 -0700 Subject: NFC: trf7970a: Clean up coding style issues Clean up coding style issues according to scripts/Lindent. Some scripts/Lindent changes were reverted when it appeared to make the code less readable or when it made the line run over 80 characters. Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 291 +++++++++++++++++++++++++------------------------ 1 file changed, 147 insertions(+), 144 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index bb777f50b4fb..28b942ea15fb 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -122,11 +122,10 @@ NFC_PROTO_ISO14443_B_MASK | NFC_PROTO_FELICA_MASK | \ NFC_PROTO_ISO15693_MASK | NFC_PROTO_NFC_DEP_MASK) -#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */ +#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */ #define TRF7970A_13MHZ_CLOCK_FREQUENCY 13560000 #define TRF7970A_27MHZ_CLOCK_FREQUENCY 27120000 - #define TRF7970A_RX_SKB_ALLOC_SIZE 256 #define TRF7970A_FIFO_SIZE 127 @@ -294,7 +293,7 @@ #define TRF7970A_REG_IO_CTRL_AUTO_REG BIT(7) /* IRQ Status Register Bits */ -#define TRF7970A_IRQ_STATUS_NORESP BIT(0) /* ISO15693 only */ +#define TRF7970A_IRQ_STATUS_NORESP BIT(0) /* ISO15693 only */ #define TRF7970A_IRQ_STATUS_NFC_COL_ERROR BIT(0) #define TRF7970A_IRQ_STATUS_COL BIT(1) #define TRF7970A_IRQ_STATUS_FRAMING_EOF_ERROR BIT(2) @@ -459,7 +458,6 @@ struct trf7970a { struct delayed_work timeout_work; }; - static int trf7970a_cmd(struct trf7970a *trf, u8 opcode) { u8 cmd = TRF7970A_CMD_BIT_CTRL | TRF7970A_CMD_BIT_OPCODE(opcode); @@ -470,7 +468,7 @@ static int trf7970a_cmd(struct trf7970a *trf, u8 opcode) ret = spi_write(trf->spi, &cmd, 1); if (ret) dev_err(trf->dev, "%s - cmd: 0x%x, ret: %d\n", __func__, cmd, - ret); + ret); return ret; } @@ -482,14 +480,15 @@ static int trf7970a_read(struct trf7970a *trf, u8 reg, u8 *val) ret = spi_write_then_read(trf->spi, &addr, 1, val, 1); if (ret) dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, - ret); + ret); dev_dbg(trf->dev, "read(0x%x): 0x%x\n", addr, *val); return ret; } -static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, size_t len) +static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, + size_t len) { u8 addr = reg | TRF7970A_CMD_BIT_RW | TRF7970A_CMD_BIT_CONTINUOUS; struct spi_transfer t[2]; @@ -513,7 +512,7 @@ static int trf7970a_read_cont(struct trf7970a *trf, u8 reg, u8 *buf, size_t len) ret = spi_sync(trf->spi, &m); if (ret) dev_err(trf->dev, "%s - addr: 0x%x, ret: %d\n", __func__, addr, - ret); + ret); return ret; } @@ -527,7 +526,7 @@ static int trf7970a_write(struct trf7970a *trf, u8 reg, u8 val) ret = spi_write(trf->spi, buf, 2); if (ret) dev_err(trf->dev, "%s - write: 0x%x 0x%x, ret: %d\n", __func__, - buf[0], buf[1], ret); + buf[0], buf[1], ret); return ret; } @@ -549,7 +548,7 @@ static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status) if (ret) dev_err(trf->dev, "%s - irqstatus: Status read failed: %d\n", - __func__, ret); + __func__, ret); else *status = buf[0]; @@ -563,12 +562,12 @@ static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto) u8 addr; addr = TRF79070A_NFC_TARGET_PROTOCOL | TRF7970A_CMD_BIT_RW | - TRF7970A_CMD_BIT_CONTINUOUS; + TRF7970A_CMD_BIT_CONTINUOUS; ret = spi_write_then_read(trf->spi, &addr, 1, buf, 2); if (ret) dev_err(trf->dev, "%s - target_proto: Read failed: %d\n", - __func__, ret); + __func__, ret); else *target_proto = buf[0]; @@ -599,7 +598,7 @@ static int trf7970a_mode_detect(struct trf7970a *trf, u8 *rf_tech) break; default: dev_dbg(trf->dev, "%s - mode_detect: target_proto: 0x%x\n", - __func__, target_proto); + __func__, target_proto); return -EIO; } @@ -615,8 +614,8 @@ static void trf7970a_send_upstream(struct trf7970a *trf) if (trf->rx_skb && !IS_ERR(trf->rx_skb) && !trf->aborting) print_hex_dump_debug("trf7970a rx data: ", DUMP_PREFIX_NONE, - 16, 1, trf->rx_skb->data, trf->rx_skb->len, - false); + 16, 1, trf->rx_skb->data, trf->rx_skb->len, + false); trf->state = TRF7970A_ST_IDLE; @@ -656,7 +655,8 @@ static void trf7970a_send_err_upstream(struct trf7970a *trf, int errno) } static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, - unsigned int len, u8 *prefix, unsigned int prefix_len) + unsigned int len, u8 *prefix, + unsigned int prefix_len) { struct spi_transfer t[2]; struct spi_message m; @@ -664,7 +664,7 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, int ret; print_hex_dump_debug("trf7970a tx data: ", DUMP_PREFIX_NONE, - 16, 1, skb->data, len, false); + 16, 1, skb->data, len, false); spi_message_init(&m); @@ -681,7 +681,7 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, ret = spi_sync(trf->spi, &m); if (ret) { dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__, - ret); + ret); return ret; } @@ -705,7 +705,7 @@ static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, } dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", timeout, - trf->state); + trf->state); schedule_delayed_work(&trf->timeout_work, msecs_to_jiffies(timeout)); @@ -773,9 +773,9 @@ static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) if (fifo_bytes > skb_tailroom(skb)) { skb = skb_copy_expand(skb, skb_headroom(skb), - max_t(int, fifo_bytes, - TRF7970A_RX_SKB_ALLOC_SIZE), - GFP_KERNEL); + max_t(int, fifo_bytes, + TRF7970A_RX_SKB_ALLOC_SIZE), + GFP_KERNEL); if (!skb) { trf7970a_send_err_upstream(trf, -ENOMEM); return; @@ -786,7 +786,7 @@ static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) } ret = trf7970a_read_cont(trf, TRF7970A_FIFO_IO_REGISTER, - skb_put(skb, fifo_bytes), fifo_bytes); + skb_put(skb, fifo_bytes), fifo_bytes); if (ret) { trf7970a_send_err_upstream(trf, ret); return; @@ -794,8 +794,7 @@ static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) /* If received Type 2 ACK/NACK, shift right 4 bits and pass up */ if ((trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T) && (skb->len == 1) && - (trf->special_fcn_reg1 == - TRF7970A_SPECIAL_FCN_REG1_4_BIT_RX)) { + (trf->special_fcn_reg1 == TRF7970A_SPECIAL_FCN_REG1_4_BIT_RX)) { skb->data[0] >>= 4; status = TRF7970A_IRQ_STATUS_SRX; } else { @@ -818,16 +817,16 @@ static void trf7970a_drain_fifo(struct trf7970a *trf, u8 status) } no_rx_data: - if (status == TRF7970A_IRQ_STATUS_SRX) { /* Receive complete */ + if (status == TRF7970A_IRQ_STATUS_SRX) { /* Receive complete */ trf7970a_send_upstream(trf); return; } dev_dbg(trf->dev, "Setting timeout for %d ms\n", - TRF7970A_WAIT_FOR_RX_DATA_TIMEOUT); + TRF7970A_WAIT_FOR_RX_DATA_TIMEOUT); schedule_delayed_work(&trf->timeout_work, - msecs_to_jiffies(TRF7970A_WAIT_FOR_RX_DATA_TIMEOUT)); + msecs_to_jiffies(TRF7970A_WAIT_FOR_RX_DATA_TIMEOUT)); } static irqreturn_t trf7970a_irq(int irq, void *dev_id) @@ -850,7 +849,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) } dev_dbg(trf->dev, "IRQ - state: %d, status: 0x%x\n", trf->state, - status); + status); if (!status) { mutex_unlock(&trf->lock); @@ -875,7 +874,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) case TRF7970A_ST_WAIT_FOR_TX_FIFO: if (status & TRF7970A_IRQ_STATUS_TX) { trf->ignore_timeout = - !cancel_delayed_work(&trf->timeout_work); + !cancel_delayed_work(&trf->timeout_work); trf7970a_fill_fifo(trf); } else { trf7970a_send_err_upstream(trf, -EIO); @@ -885,11 +884,11 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) case TRF7970A_ST_WAIT_FOR_RX_DATA_CONT: if (status & TRF7970A_IRQ_STATUS_SRX) { trf->ignore_timeout = - !cancel_delayed_work(&trf->timeout_work); + !cancel_delayed_work(&trf->timeout_work); trf7970a_drain_fifo(trf, status); } else if (status & TRF7970A_IRQ_STATUS_FIFO) { ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, - &fifo_bytes); + &fifo_bytes); fifo_bytes &= ~TRF7970A_FIFO_STATUS_OVERFLOW; @@ -898,14 +897,14 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) else if (!fifo_bytes) trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); } else if ((status == TRF7970A_IRQ_STATUS_TX) || - (!trf->is_initiator && - (status == (TRF7970A_IRQ_STATUS_TX | - TRF7970A_IRQ_STATUS_NFC_RF)))) { + (!trf->is_initiator && + (status == (TRF7970A_IRQ_STATUS_TX | + TRF7970A_IRQ_STATUS_NFC_RF)))) { trf7970a_cmd(trf, TRF7970A_CMD_FIFO_RESET); if (!trf->timeout) { - trf->ignore_timeout = !cancel_delayed_work( - &trf->timeout_work); + trf->ignore_timeout = + !cancel_delayed_work(&trf->timeout_work); trf->rx_skb = ERR_PTR(0); trf7970a_send_upstream(trf); break; @@ -929,13 +928,13 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) break; case NFC_DIGITAL_FRAMING_NFCA_ANTICOL_COMPLETE: ret = trf7970a_write(trf, - TRF7970A_SPECIAL_FCN_REG1, - TRF7970A_SPECIAL_FCN_REG1_14_ANTICOLL); + TRF7970A_SPECIAL_FCN_REG1, + TRF7970A_SPECIAL_FCN_REG1_14_ANTICOLL); if (ret) goto err_unlock_exit; trf->special_fcn_reg1 = - TRF7970A_SPECIAL_FCN_REG1_14_ANTICOLL; + TRF7970A_SPECIAL_FCN_REG1_14_ANTICOLL; break; default: break; @@ -943,7 +942,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) if (iso_ctrl != trf->iso_ctrl) { ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, - iso_ctrl); + iso_ctrl); if (ret) goto err_unlock_exit; @@ -960,7 +959,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) case TRF7970A_ST_LISTENING: if (status & TRF7970A_IRQ_STATUS_SRX) { trf->ignore_timeout = - !cancel_delayed_work(&trf->timeout_work); + !cancel_delayed_work(&trf->timeout_work); trf7970a_drain_fifo(trf, status); } else if (!(status & TRF7970A_IRQ_STATUS_NFC_RF)) { trf7970a_send_err_upstream(trf, -EIO); @@ -969,7 +968,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) case TRF7970A_ST_LISTENING_MD: if (status & TRF7970A_IRQ_STATUS_SRX) { trf->ignore_timeout = - !cancel_delayed_work(&trf->timeout_work); + !cancel_delayed_work(&trf->timeout_work); ret = trf7970a_mode_detect(trf, &trf->md_rf_tech); if (ret) { @@ -984,7 +983,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id) break; default: dev_err(trf->dev, "%s - Driver in invalid state: %d\n", - __func__, trf->state); + __func__, trf->state); } err_unlock_exit: @@ -1009,19 +1008,19 @@ static void trf7970a_issue_eof(struct trf7970a *trf) trf->state = TRF7970A_ST_WAIT_FOR_RX_DATA; dev_dbg(trf->dev, "Setting timeout for %d ms, state: %d\n", - trf->timeout, trf->state); + trf->timeout, trf->state); schedule_delayed_work(&trf->timeout_work, - msecs_to_jiffies(trf->timeout)); + msecs_to_jiffies(trf->timeout)); } static void trf7970a_timeout_work_handler(struct work_struct *work) { struct trf7970a *trf = container_of(work, struct trf7970a, - timeout_work.work); + timeout_work.work); dev_dbg(trf->dev, "Timeout - state: %d, ignore_timeout: %d\n", - trf->state, trf->ignore_timeout); + trf->state, trf->ignore_timeout); mutex_lock(&trf->lock); @@ -1052,7 +1051,7 @@ static int trf7970a_init(struct trf7970a *trf) goto err_out; ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, - trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); + trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); if (ret) goto err_out; @@ -1065,13 +1064,13 @@ static int trf7970a_init(struct trf7970a *trf) trf->chip_status_ctrl &= ~TRF7970A_CHIP_STATUS_RF_ON; ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, - trf->modulator_sys_clk_ctrl); + trf->modulator_sys_clk_ctrl); if (ret) goto err_out; ret = trf7970a_write(trf, TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS, - TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS_WLH_96 | - TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS_WLL_32); + TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS_WLH_96 | + TRF7970A_ADJUTABLE_FIFO_IRQ_LEVELS_WLL_32); if (ret) goto err_out; @@ -1092,7 +1091,7 @@ err_out: static void trf7970a_switch_rf_off(struct trf7970a *trf) { if ((trf->state == TRF7970A_ST_PWR_OFF) || - (trf->state == TRF7970A_ST_RF_OFF)) + (trf->state == TRF7970A_ST_RF_OFF)) return; dev_dbg(trf->dev, "Switching rf off\n"); @@ -1116,9 +1115,9 @@ static int trf7970a_switch_rf_on(struct trf7970a *trf) pm_runtime_get_sync(trf->dev); - if (trf->state != TRF7970A_ST_RF_OFF) { /* Power on, RF off */ + if (trf->state != TRF7970A_ST_RF_OFF) { /* Power on, RF off */ dev_err(trf->dev, "%s - Incorrect state: %d\n", __func__, - trf->state); + trf->state); return -EINVAL; } @@ -1153,7 +1152,7 @@ static int trf7970a_switch_rf(struct nfc_digital_dev *ddev, bool on) break; default: dev_err(trf->dev, "%s - Invalid request: %d %d\n", - __func__, trf->state, on); + __func__, trf->state, on); trf7970a_switch_rf_off(trf); ret = -EINVAL; } @@ -1164,7 +1163,7 @@ static int trf7970a_switch_rf(struct nfc_digital_dev *ddev, bool on) break; default: dev_err(trf->dev, "%s - Invalid request: %d %d\n", - __func__, trf->state, on); + __func__, trf->state, on); ret = -EINVAL; /* FALLTHROUGH */ case TRF7970A_ST_IDLE: @@ -1189,36 +1188,36 @@ static int trf7970a_in_config_rf_tech(struct trf7970a *trf, int tech) case NFC_DIGITAL_RF_TECH_106A: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443A_106; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_OOK; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_OOK; trf->guard_time = TRF7970A_GUARD_TIME_NFCA; break; case NFC_DIGITAL_RF_TECH_106B: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_14443B_106; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_ASK10; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_ASK10; trf->guard_time = TRF7970A_GUARD_TIME_NFCB; break; case NFC_DIGITAL_RF_TECH_212F: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_212; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_ASK10; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_ASK10; trf->guard_time = TRF7970A_GUARD_TIME_NFCF; break; case NFC_DIGITAL_RF_TECH_424F: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_FELICA_424; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_ASK10; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_ASK10; trf->guard_time = TRF7970A_GUARD_TIME_NFCF; break; case NFC_DIGITAL_RF_TECH_ISO15693: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_OOK; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_OOK; trf->guard_time = TRF7970A_GUARD_TIME_15693; break; default: @@ -1245,7 +1244,8 @@ static int trf7970a_is_rf_field(struct trf7970a *trf, bool *is_rf_field) u8 rssi; ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, - trf->chip_status_ctrl | TRF7970A_CHIP_STATUS_REC_ON); + trf->chip_status_ctrl | + TRF7970A_CHIP_STATUS_REC_ON); if (ret) return ret; @@ -1260,7 +1260,7 @@ static int trf7970a_is_rf_field(struct trf7970a *trf, bool *is_rf_field) return ret; ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, - trf->chip_status_ctrl); + trf->chip_status_ctrl); if (ret) return ret; @@ -1327,15 +1327,15 @@ static int trf7970a_in_config_framing(struct trf7970a *trf, int framing) trf->iso_ctrl = iso_ctrl; ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, - trf->modulator_sys_clk_ctrl); + trf->modulator_sys_clk_ctrl); if (ret) return ret; } if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, - trf->chip_status_ctrl | - TRF7970A_CHIP_STATUS_RF_ON); + trf->chip_status_ctrl | + TRF7970A_CHIP_STATUS_RF_ON); if (ret) return ret; @@ -1348,7 +1348,7 @@ static int trf7970a_in_config_framing(struct trf7970a *trf, int framing) } static int trf7970a_in_configure_hw(struct nfc_digital_dev *ddev, int type, - int param) + int param) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); int ret; @@ -1360,7 +1360,7 @@ static int trf7970a_in_configure_hw(struct nfc_digital_dev *ddev, int type, trf->is_initiator = true; if ((trf->state == TRF7970A_ST_PWR_OFF) || - (trf->state == TRF7970A_ST_RF_OFF)) { + (trf->state == TRF7970A_ST_RF_OFF)) { ret = trf7970a_switch_rf_on(trf); if (ret) goto err_unlock; @@ -1418,7 +1418,7 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) * has to send an EOF in order to get a response. */ if ((trf->technology == NFC_DIGITAL_RF_TECH_106A) && - (trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T)) { + (trf->framing == NFC_DIGITAL_FRAMING_NFCA_T2T)) { if (req[0] == NFC_T2T_CMD_READ) special_fcn_reg1 = 0; else @@ -1426,7 +1426,7 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) if (special_fcn_reg1 != trf->special_fcn_reg1) { ret = trf7970a_write(trf, TRF7970A_SPECIAL_FCN_REG1, - special_fcn_reg1); + special_fcn_reg1); if (ret) return ret; @@ -1446,7 +1446,7 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) iso_ctrl |= TRF7970A_ISO_CTRL_15693_SGL_1OF4_2648; break; case (ISO15693_REQ_FLAG_SUB_CARRIER | - ISO15693_REQ_FLAG_DATA_RATE): + ISO15693_REQ_FLAG_DATA_RATE): iso_ctrl |= TRF7970A_ISO_CTRL_15693_DBL_1OF4_2669; break; } @@ -1461,10 +1461,10 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) if (trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) { if (trf7970a_is_iso15693_write_or_lock(req[1]) && - (req[0] & ISO15693_REQ_FLAG_OPTION)) + (req[0] & ISO15693_REQ_FLAG_OPTION)) trf->issue_eof = true; else if ((trf->quirks & - TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE) && + TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE) && (req[1] == ISO15693_CMD_READ_MULTIPLE_BLOCK)) trf->adjust_resp_len = true; } @@ -1474,8 +1474,8 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) } static int trf7970a_send_cmd(struct nfc_digital_dev *ddev, - struct sk_buff *skb, u16 timeout, - nfc_digital_cmd_complete_t cb, void *arg) + struct sk_buff *skb, u16 timeout, + nfc_digital_cmd_complete_t cb, void *arg) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); u8 prefix[5]; @@ -1484,7 +1484,7 @@ static int trf7970a_send_cmd(struct nfc_digital_dev *ddev, u8 status; dev_dbg(trf->dev, "New request - state: %d, timeout: %d ms, len: %d\n", - trf->state, timeout, skb->len); + trf->state, timeout, skb->len); if (skb->len > TRF7970A_TX_MAX) return -EINVAL; @@ -1492,9 +1492,9 @@ static int trf7970a_send_cmd(struct nfc_digital_dev *ddev, mutex_lock(&trf->lock); if ((trf->state != TRF7970A_ST_IDLE) && - (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { + (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, - trf->state); + trf->state); ret = -EIO; goto out_err; } @@ -1508,7 +1508,7 @@ static int trf7970a_send_cmd(struct nfc_digital_dev *ddev, if (timeout) { trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, - GFP_KERNEL); + GFP_KERNEL); if (!trf->rx_skb) { dev_dbg(trf->dev, "Can't alloc rx_skb\n"); ret = -ENOMEM; @@ -1545,14 +1545,14 @@ static int trf7970a_send_cmd(struct nfc_digital_dev *ddev, * That totals 5 bytes. */ prefix[0] = TRF7970A_CMD_BIT_CTRL | - TRF7970A_CMD_BIT_OPCODE(TRF7970A_CMD_FIFO_RESET); + TRF7970A_CMD_BIT_OPCODE(TRF7970A_CMD_FIFO_RESET); prefix[1] = TRF7970A_CMD_BIT_CTRL | - TRF7970A_CMD_BIT_OPCODE(trf->tx_cmd); + TRF7970A_CMD_BIT_OPCODE(trf->tx_cmd); prefix[2] = TRF7970A_CMD_BIT_CONTINUOUS | TRF7970A_TX_LENGTH_BYTE1; if (trf->framing == NFC_DIGITAL_FRAMING_NFCA_SHORT) { prefix[3] = 0x00; - prefix[4] = 0x0f; /* 7 bits */ + prefix[4] = 0x0f; /* 7 bits */ } else { prefix[3] = (len & 0xf00) >> 4; prefix[3] |= ((len & 0xf0) >> 4); @@ -1586,25 +1586,24 @@ static int trf7970a_tg_config_rf_tech(struct trf7970a *trf, int tech) switch (tech) { case NFC_DIGITAL_RF_TECH_106A: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | - TRF7970A_ISO_CTRL_NFC_CE | - TRF7970A_ISO_CTRL_NFC_CE_14443A; + TRF7970A_ISO_CTRL_NFC_CE | TRF7970A_ISO_CTRL_NFC_CE_14443A; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_OOK; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_OOK; break; case NFC_DIGITAL_RF_TECH_212F: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | - TRF7970A_ISO_CTRL_NFC_NFCF_212; + TRF7970A_ISO_CTRL_NFC_NFCF_212; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_ASK10; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_ASK10; break; case NFC_DIGITAL_RF_TECH_424F: trf->iso_ctrl_tech = TRF7970A_ISO_CTRL_NFC_NFC_CE_MODE | - TRF7970A_ISO_CTRL_NFC_NFCF_424; + TRF7970A_ISO_CTRL_NFC_NFCF_424; trf->modulator_sys_clk_ctrl = - (trf->modulator_sys_clk_ctrl & 0xf8) | - TRF7970A_MODULATOR_DEPTH_ASK10; + (trf->modulator_sys_clk_ctrl & 0xf8) | + TRF7970A_MODULATOR_DEPTH_ASK10; break; default: dev_dbg(trf->dev, "Unsupported rf technology: %d\n", tech); @@ -1621,9 +1620,9 @@ static int trf7970a_tg_config_rf_tech(struct trf7970a *trf, int tech) * here. */ if ((trf->framing == NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED) && - (trf->iso_ctrl_tech != trf->iso_ctrl)) { + (trf->iso_ctrl_tech != trf->iso_ctrl)) { ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, - trf->iso_ctrl_tech); + trf->iso_ctrl_tech); trf->iso_ctrl = trf->iso_ctrl_tech; } @@ -1678,15 +1677,15 @@ static int trf7970a_tg_config_framing(struct trf7970a *trf, int framing) trf->iso_ctrl = iso_ctrl; ret = trf7970a_write(trf, TRF7970A_MODULATOR_SYS_CLK_CTRL, - trf->modulator_sys_clk_ctrl); + trf->modulator_sys_clk_ctrl); if (ret) return ret; } if (!(trf->chip_status_ctrl & TRF7970A_CHIP_STATUS_RF_ON)) { ret = trf7970a_write(trf, TRF7970A_CHIP_STATUS_CTRL, - trf->chip_status_ctrl | - TRF7970A_CHIP_STATUS_RF_ON); + trf->chip_status_ctrl | + TRF7970A_CHIP_STATUS_RF_ON); if (ret) return ret; @@ -1697,7 +1696,7 @@ static int trf7970a_tg_config_framing(struct trf7970a *trf, int framing) } static int trf7970a_tg_configure_hw(struct nfc_digital_dev *ddev, int type, - int param) + int param) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); int ret; @@ -1709,7 +1708,7 @@ static int trf7970a_tg_configure_hw(struct nfc_digital_dev *ddev, int type, trf->is_initiator = false; if ((trf->state == TRF7970A_ST_PWR_OFF) || - (trf->state == TRF7970A_ST_RF_OFF)) { + (trf->state == TRF7970A_ST_RF_OFF)) { ret = trf7970a_switch_rf_on(trf); if (ret) goto err_unlock; @@ -1733,7 +1732,8 @@ err_unlock: } static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, - nfc_digital_cmd_complete_t cb, void *arg, bool mode_detect) + nfc_digital_cmd_complete_t cb, void *arg, + bool mode_detect) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); int ret; @@ -1741,9 +1741,9 @@ static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, mutex_lock(&trf->lock); if ((trf->state != TRF7970A_ST_IDLE) && - (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { + (trf->state != TRF7970A_ST_IDLE_RX_BLOCKED)) { dev_err(trf->dev, "%s - Bogus state: %d\n", __func__, - trf->state); + trf->state); ret = -EIO; goto out_err; } @@ -1756,7 +1756,7 @@ static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, } trf->rx_skb = nfc_alloc_recv_skb(TRF7970A_RX_SKB_ALLOC_SIZE, - GFP_KERNEL); + GFP_KERNEL); if (!trf->rx_skb) { dev_dbg(trf->dev, "Can't alloc rx_skb\n"); ret = -ENOMEM; @@ -1764,25 +1764,25 @@ static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, } ret = trf7970a_write(trf, TRF7970A_RX_SPECIAL_SETTINGS, - TRF7970A_RX_SPECIAL_SETTINGS_HBT | - TRF7970A_RX_SPECIAL_SETTINGS_M848 | - TRF7970A_RX_SPECIAL_SETTINGS_C424 | - TRF7970A_RX_SPECIAL_SETTINGS_C212); + TRF7970A_RX_SPECIAL_SETTINGS_HBT | + TRF7970A_RX_SPECIAL_SETTINGS_M848 | + TRF7970A_RX_SPECIAL_SETTINGS_C424 | + TRF7970A_RX_SPECIAL_SETTINGS_C212); if (ret) goto out_err; ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL, - trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); + trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1)); if (ret) goto out_err; ret = trf7970a_write(trf, TRF7970A_NFC_LOW_FIELD_LEVEL, - TRF7970A_NFC_LOW_FIELD_LEVEL_RFDET(0x3)); + TRF7970A_NFC_LOW_FIELD_LEVEL_RFDET(0x3)); if (ret) goto out_err; ret = trf7970a_write(trf, TRF7970A_NFC_TARGET_LEVEL, - TRF7970A_NFC_TARGET_LEVEL_RFDET(0x7)); + TRF7970A_NFC_TARGET_LEVEL_RFDET(0x7)); if (ret) goto out_err; @@ -1807,32 +1807,33 @@ out_err: } static int trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, - nfc_digital_cmd_complete_t cb, void *arg) + nfc_digital_cmd_complete_t cb, void *arg) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); dev_dbg(trf->dev, "Listen - state: %d, timeout: %d ms\n", - trf->state, timeout); + trf->state, timeout); return _trf7970a_tg_listen(ddev, timeout, cb, arg, false); } static int trf7970a_tg_listen_md(struct nfc_digital_dev *ddev, - u16 timeout, nfc_digital_cmd_complete_t cb, void *arg) + u16 timeout, nfc_digital_cmd_complete_t cb, + void *arg) { struct trf7970a *trf = nfc_digital_get_drvdata(ddev); int ret; dev_dbg(trf->dev, "Listen MD - state: %d, timeout: %d ms\n", - trf->state, timeout); + trf->state, timeout); ret = trf7970a_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_RF_TECH, - NFC_DIGITAL_RF_TECH_106A); + NFC_DIGITAL_RF_TECH_106A); if (ret) return ret; ret = trf7970a_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, - NFC_DIGITAL_FRAMING_NFCA_NFC_DEP); + NFC_DIGITAL_FRAMING_NFCA_NFC_DEP); if (ret) return ret; @@ -1844,7 +1845,7 @@ static int trf7970a_tg_get_rf_tech(struct nfc_digital_dev *ddev, u8 *rf_tech) struct trf7970a *trf = nfc_digital_get_drvdata(ddev); dev_dbg(trf->dev, "Get RF Tech - state: %d, rf_tech: %d\n", - trf->state, trf->md_rf_tech); + trf->state, trf->md_rf_tech); *rf_tech = trf->md_rf_tech; @@ -1933,20 +1934,19 @@ static int trf7970a_power_down(struct trf7970a *trf) if (trf->state != TRF7970A_ST_RF_OFF) { dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n", - trf->state); + trf->state); return -EBUSY; } gpiod_set_value_cansleep(trf->en_gpiod, 0); - if (trf->en2_gpiod && - !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) + if (trf->en2_gpiod && !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) gpiod_set_value_cansleep(trf->en2_gpiod, 0); ret = regulator_disable(trf->regulator); if (ret) dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__, - ret); + ret); trf->state = TRF7970A_ST_PWR_OFF; @@ -2060,16 +2060,16 @@ static int trf7970a_probe(struct spi_device *spi) of_property_read_u32(np, "clock-frequency", &clk_freq); if ((clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) || - (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUENCY)) { + (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUENCY)) { dev_err(trf->dev, - "clock-frequency (%u Hz) unsupported\n", - clk_freq); + "clock-frequency (%u Hz) unsupported\n", clk_freq); return -EINVAL; } ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, - trf7970a_irq, IRQF_TRIGGER_RISING | IRQF_ONESHOT, - "trf7970a", trf); + trf7970a_irq, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + "trf7970a", trf); if (ret) { dev_err(trf->dev, "Can't request IRQ#%d: %d\n", spi->irq, ret); return ret; @@ -2114,9 +2114,10 @@ static int trf7970a_probe(struct spi_device *spi) } trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops, - TRF7970A_SUPPORTED_PROTOCOLS, - NFC_DIGITAL_DRV_CAPS_IN_CRC | - NFC_DIGITAL_DRV_CAPS_TG_CRC, 0, 0); + TRF7970A_SUPPORTED_PROTOCOLS, + NFC_DIGITAL_DRV_CAPS_IN_CRC | + NFC_DIGITAL_DRV_CAPS_TG_CRC, 0, + 0); if (!trf->ddev) { dev_err(trf->dev, "Can't allocate NFC digital device\n"); ret = -ENOMEM; @@ -2139,7 +2140,7 @@ static int trf7970a_probe(struct spi_device *spi) ret = nfc_digital_register_device(trf->ddev); if (ret) { dev_err(trf->dev, "Can't register NFC digital device: %d\n", - ret); + ret); goto err_shutdown; } @@ -2248,29 +2249,31 @@ static int trf7970a_pm_runtime_resume(struct device *dev) static const struct dev_pm_ops trf7970a_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(trf7970a_suspend, trf7970a_resume) SET_RUNTIME_PM_OPS(trf7970a_pm_runtime_suspend, - trf7970a_pm_runtime_resume, NULL) + trf7970a_pm_runtime_resume, NULL) }; static const struct of_device_id trf7970a_of_match[] = { - { .compatible = "ti,trf7970a", }, + {.compatible = "ti,trf7970a",}, {}, }; + MODULE_DEVICE_TABLE(of, trf7970a_of_match); static const struct spi_device_id trf7970a_id_table[] = { - { "trf7970a", 0 }, - { } + {"trf7970a", 0}, + {} }; + MODULE_DEVICE_TABLE(spi, trf7970a_id_table); static struct spi_driver trf7970a_spi_driver = { .probe = trf7970a_probe, .remove = trf7970a_remove, .id_table = trf7970a_id_table, - .driver = { - .name = "trf7970a", - .of_match_table = of_match_ptr(trf7970a_of_match), - .pm = &trf7970a_pm_ops, + .driver = { + .name = "trf7970a", + .of_match_table = of_match_ptr(trf7970a_of_match), + .pm = &trf7970a_pm_ops, }, }; -- cgit v1.2.3 From 15e0c59f1535926a939d1df66d6edcf997d7c1b9 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:36 +0200 Subject: NFC: nfcmrvl_uart: add missing tty-device sanity check Make sure to check the tty-device pointer before trying to access the parent device to avoid dereferencing a NULL-pointer when the tty is one end of a Unix98 pty. Fixes: e097dc624f78 ("NFC: nfcmrvl: add UART driver") Cc: stable # 4.2 Cc: Vincent Cuissard Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/uart.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c index 83a99e38e7bd..6c0c301611c4 100644 --- a/drivers/nfc/nfcmrvl/uart.c +++ b/drivers/nfc/nfcmrvl/uart.c @@ -109,6 +109,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) struct nfcmrvl_private *priv; struct nfcmrvl_platform_data *pdata = NULL; struct nfcmrvl_platform_data config; + struct device *dev = nu->tty->dev; /* * Platform data cannot be used here since usually it is already used @@ -116,9 +117,8 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) * and check if DT entries were added. */ - if (nu->tty->dev->parent && nu->tty->dev->parent->of_node) - if (nfcmrvl_uart_parse_dt(nu->tty->dev->parent->of_node, - &config) == 0) + if (dev && dev->parent && dev->parent->of_node) + if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0) pdata = &config; if (!pdata) { @@ -131,7 +131,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) } priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_UART, nu, &uart_ops, - nu->tty->dev, pdata); + dev, pdata); if (IS_ERR(priv)) return PTR_ERR(priv); -- cgit v1.2.3 From 0cbe40112f42cf5e008f9127f6cd5952ba3946c7 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:37 +0200 Subject: NFC: nfcmrvl: do not use device-managed resources This specifically fixes resource leaks in the registration error paths. Device-managed resources is a bad fit for this driver as devices can be registered from the n_nci line discipline. Firstly, a tty may not even have a corresponding device (should it be part of a Unix98 pty) something which would lead to a NULL-pointer dereference when registering resources. Secondly, if the tty has a class device, its lifetime exceeds that of the line discipline, which means that resources would leak every time the line discipline is closed (or if registration fails). Currently, the devres interface was only being used to request a reset gpio despite the fact that it was already explicitly freed in nfcmrvl_nci_unregister_dev() (along with the private data), something which also prevented the resource leak at close. Note that the driver treats gpio number 0 as invalid despite it being perfectly valid. This will be addressed in a follow-up patch. Fixes: b2fe288eac72 ("NFC: nfcmrvl: free reset gpio") Fixes: 4a2b947f56b3 ("NFC: nfcmrvl: add chip reset management") Cc: stable # 4.2: b2fe288eac72 Cc: Vincent Cuissard Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index c5038e6447bd..968da1901e85 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -124,12 +124,13 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, memcpy(&priv->config, pdata, sizeof(*pdata)); if (priv->config.reset_n_io) { - rc = devm_gpio_request_one(dev, - priv->config.reset_n_io, - GPIOF_OUT_INIT_LOW, - "nfcmrvl_reset_n"); - if (rc < 0) + rc = gpio_request_one(priv->config.reset_n_io, + GPIOF_OUT_INIT_LOW, + "nfcmrvl_reset_n"); + if (rc < 0) { + priv->config.reset_n_io = 0; nfc_err(dev, "failed to request reset_n io\n"); + } } if (phy == NFCMRVL_PHY_SPI) { @@ -154,7 +155,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, if (!priv->ndev) { nfc_err(dev, "nci_allocate_device failed\n"); rc = -ENOMEM; - goto error; + goto error_free_gpio; } nci_set_drvdata(priv->ndev, priv); @@ -179,7 +180,9 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, error_free_dev: nci_free_device(priv->ndev); -error: +error_free_gpio: + if (priv->config.reset_n_io) + gpio_free(priv->config.reset_n_io); kfree(priv); return ERR_PTR(rc); } @@ -195,7 +198,7 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) nfcmrvl_fw_dnld_deinit(priv); if (priv->config.reset_n_io) - devm_gpio_free(priv->dev, priv->config.reset_n_io); + gpio_free(priv->config.reset_n_io); nci_unregister_device(ndev); nci_free_device(ndev); -- cgit v1.2.3 From e5834ac22948169bbd7c45996d8d4905edd20f5e Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:38 +0200 Subject: NFC: nfcmrvl: use nfc-device for firmware download Use the nfc- rather than phy-device in firmware-management code that needs a valid struct device. This specifically fixes a NULL-pointer dereference in nfcmrvl_fw_dnld_init() during registration when the underlying tty is one end of a Unix98 pty. Note that the driver still uses the phy device for any debugging, which is fine for now. Fixes: 3194c6870158 ("NFC: nfcmrvl: add firmware download support") Cc: stable # 4.4 Cc: Vincent Cuissard Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/fw_dnld.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/fw_dnld.c b/drivers/nfc/nfcmrvl/fw_dnld.c index f9f000c546d1..7f8960a46aab 100644 --- a/drivers/nfc/nfcmrvl/fw_dnld.c +++ b/drivers/nfc/nfcmrvl/fw_dnld.c @@ -457,7 +457,7 @@ int nfcmrvl_fw_dnld_init(struct nfcmrvl_private *priv) INIT_WORK(&priv->fw_dnld.rx_work, fw_dnld_rx_work); snprintf(name, sizeof(name), "%s_nfcmrvl_fw_dnld_rx_wq", - dev_name(priv->dev)); + dev_name(&priv->ndev->nfc_dev->dev)); priv->fw_dnld.rx_wq = create_singlethread_workqueue(name); if (!priv->fw_dnld.rx_wq) return -ENOMEM; @@ -494,6 +494,7 @@ int nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name) { struct nfcmrvl_private *priv = nci_get_drvdata(ndev); struct nfcmrvl_fw_dnld *fw_dnld = &priv->fw_dnld; + int res; if (!priv->support_fw_dnld) return -ENOTSUPP; @@ -509,7 +510,9 @@ int nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name) */ /* Retrieve FW binary */ - if (request_firmware(&fw_dnld->fw, firmware_name, priv->dev) < 0) { + res = request_firmware(&fw_dnld->fw, firmware_name, + &ndev->nfc_dev->dev); + if (res < 0) { nfc_err(priv->dev, "failed to retrieve FW %s", firmware_name); return -ENOENT; } -- cgit v1.2.3 From 45dd39b974f6632222dd5cdcbea7358a077ab0b0 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:39 +0200 Subject: NFC: nfcmrvl: fix firmware-management initialisation The nci-device was never deregistered in the event that fw-initialisation failed. Fix this by moving the firmware initialisation before device registration since the firmware work queue should be available before registering. Note that this depends on a recent fix that moved device-name initialisation back to to nci_allocate_device() as the firmware-workqueue name is now derived from the nfc-device name. Fixes: 3194c6870158 ("NFC: nfcmrvl: add firmware download support") Cc: stable # 4.4 Cc: Vincent Cuissard Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/main.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index 968da1901e85..a5faa604a3b4 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -158,26 +158,28 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, goto error_free_gpio; } + rc = nfcmrvl_fw_dnld_init(priv); + if (rc) { + nfc_err(dev, "failed to initialize FW download %d\n", rc); + goto error_free_dev; + } + nci_set_drvdata(priv->ndev, priv); rc = nci_register_device(priv->ndev); if (rc) { nfc_err(dev, "nci_register_device failed %d\n", rc); - goto error_free_dev; + goto error_fw_dnld_deinit; } /* Ensure that controller is powered off */ nfcmrvl_chip_halt(priv); - rc = nfcmrvl_fw_dnld_init(priv); - if (rc) { - nfc_err(dev, "failed to initialize FW download %d\n", rc); - goto error_free_dev; - } - nfc_info(dev, "registered with nci successfully\n"); return priv; +error_fw_dnld_deinit: + nfcmrvl_fw_dnld_deinit(priv); error_free_dev: nci_free_device(priv->ndev); error_free_gpio: -- cgit v1.2.3 From d0607aa4aee88cb097b694caa619e68f1e0a39c6 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:40 +0200 Subject: NFC: nfcmrvl_uart: fix device-node leak during probe Make sure to release the device-node reference when done parsing the node. Fixes: e097dc624f78 ("NFC: nfcmrvl: add UART driver") Cc: Vincent Cuissard Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/uart.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c index 6c0c301611c4..91162f8e0366 100644 --- a/drivers/nfc/nfcmrvl/uart.c +++ b/drivers/nfc/nfcmrvl/uart.c @@ -84,6 +84,7 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node, ret = nfcmrvl_parse_dt(matched_node, pdata); if (ret < 0) { pr_err("Failed to get generic entries\n"); + of_node_put(matched_node); return ret; } @@ -97,6 +98,8 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node, else pdata->break_control = 0; + of_node_put(matched_node); + return 0; } -- cgit v1.2.3 From 0d1ca88bbfdfdad4f6fc0421da5e4ea9a13a0d42 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:41 +0200 Subject: NFC: nfcmrvl_usb: use interface as phy device Use the USB-interface rather than parent USB-device device, which is what this driver binds to, when registering the nci device. Note that using the right device is important when dealing with device- managed resources as the interface can be unbound independently of the parent device. Also note that private device pointer had already been set by nfcmrvl_nci_register_dev() so the redundant assignment can therefore be removed. Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/usb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c index 699aa9d16575..bd35eab652be 100644 --- a/drivers/nfc/nfcmrvl/usb.c +++ b/drivers/nfc/nfcmrvl/usb.c @@ -341,15 +341,13 @@ static int nfcmrvl_probe(struct usb_interface *intf, init_usb_anchor(&drv_data->deferred); priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_USB, drv_data, &usb_ops, - &drv_data->udev->dev, &config); + &intf->dev, &config); if (IS_ERR(priv)) return PTR_ERR(priv); drv_data->priv = priv; drv_data->priv->support_fw_dnld = false; - priv->dev = &drv_data->udev->dev; - usb_set_intfdata(intf, drv_data); return 0; -- cgit v1.2.3 From e33a3f84f88f13eab6a45c5230c9b9ee9ac78e60 Mon Sep 17 00:00:00 2001 From: Johan Hovold Date: Thu, 30 Mar 2017 12:15:42 +0200 Subject: NFC: nfcmrvl: allow gpio 0 for reset signalling Allow gpio 0 to be used for reset signalling, and instead use negative errnos to disable the reset functionality. Signed-off-by: Johan Hovold Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcmrvl/main.c | 9 ++++----- include/linux/platform_data/nfcmrvl.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c index a5faa604a3b4..e65d027b91fa 100644 --- a/drivers/nfc/nfcmrvl/main.c +++ b/drivers/nfc/nfcmrvl/main.c @@ -123,12 +123,12 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy, memcpy(&priv->config, pdata, sizeof(*pdata)); - if (priv->config.reset_n_io) { + if (gpio_is_valid(priv->config.reset_n_io)) { rc = gpio_request_one(priv->config.reset_n_io, GPIOF_OUT_INIT_LOW, "nfcmrvl_reset_n"); if (rc < 0) { - priv->config.reset_n_io = 0; + priv->config.reset_n_io = -EINVAL; nfc_err(dev, "failed to request reset_n io\n"); } } @@ -183,7 +183,7 @@ error_fw_dnld_deinit: error_free_dev: nci_free_device(priv->ndev); error_free_gpio: - if (priv->config.reset_n_io) + if (gpio_is_valid(priv->config.reset_n_io)) gpio_free(priv->config.reset_n_io); kfree(priv); return ERR_PTR(rc); @@ -199,7 +199,7 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) nfcmrvl_fw_dnld_deinit(priv); - if (priv->config.reset_n_io) + if (gpio_is_valid(priv->config.reset_n_io)) gpio_free(priv->config.reset_n_io); nci_unregister_device(ndev); @@ -267,7 +267,6 @@ int nfcmrvl_parse_dt(struct device_node *node, reset_n_io = of_get_named_gpio(node, "reset-n-io", 0); if (reset_n_io < 0) { pr_info("no reset-n-io config\n"); - reset_n_io = 0; } else if (!gpio_is_valid(reset_n_io)) { pr_err("invalid reset-n-io GPIO\n"); return reset_n_io; diff --git a/include/linux/platform_data/nfcmrvl.h b/include/linux/platform_data/nfcmrvl.h index a6f9d633f5be..9e75ac8d19be 100644 --- a/include/linux/platform_data/nfcmrvl.h +++ b/include/linux/platform_data/nfcmrvl.h @@ -23,7 +23,7 @@ struct nfcmrvl_platform_data { */ /* GPIO that is wired to RESET_N signal */ - unsigned int reset_n_io; + int reset_n_io; /* Tell if transport is muxed in HCI one */ unsigned int hci_muxed; -- cgit v1.2.3 From 99f2064e15afcf81b5af22bc7c996cd5c182baf5 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:46 +0300 Subject: NFC: pn544: Switch to devm_acpi_dev_add_driver_gpios() Switch to use managed variant of acpi_dev_add_driver_gpios() to simplify error path and fix potentially wrong assignment if ->probe() fails. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/pn544/i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/pn544/i2c.c b/drivers/nfc/pn544/i2c.c index fedde9d46ab6..4b14740edb67 100644 --- a/drivers/nfc/pn544/i2c.c +++ b/drivers/nfc/pn544/i2c.c @@ -904,7 +904,7 @@ static int pn544_hci_i2c_probe(struct i2c_client *client, phy->i2c_dev = client; i2c_set_clientdata(client, phy); - r = acpi_dev_add_driver_gpios(ACPI_COMPANION(dev), acpi_pn544_gpios); + r = devm_acpi_dev_add_driver_gpios(dev, acpi_pn544_gpios); if (r) dev_dbg(dev, "Unable to add GPIO mapping table\n"); @@ -958,7 +958,6 @@ static int pn544_hci_i2c_remove(struct i2c_client *client) if (phy->powered) pn544_hci_i2c_disable(phy); - acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev)); return 0; } -- cgit v1.2.3 From 394671e79ee6e9e23ddd673ba5bbae5887f97182 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:47 +0300 Subject: NFC: st21nfca: Add GPIO ACPI mapping table In order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware. Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st21nfca/i2c.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c index 4bff76baa341..3621290807f6 100644 --- a/drivers/nfc/st21nfca/i2c.c +++ b/drivers/nfc/st21nfca/i2c.c @@ -501,14 +501,25 @@ static struct nfc_phy_ops i2c_phy_ops = { .disable = st21nfca_hci_i2c_disable, }; +static const struct acpi_gpio_params enable_gpios = { 1, 0, false }; + +static const struct acpi_gpio_mapping acpi_st21nfca_gpios[] = { + { "enable-gpios", &enable_gpios, 1 }, + {}, +}; + static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client) { struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); struct device *dev = &client->dev; + int ret; + + ret = devm_acpi_dev_add_driver_gpios(dev, acpi_st21nfca_gpios); + if (ret) + return ret; /* Get EN GPIO from ACPI */ - phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 1, - GPIOD_OUT_LOW); + phy->gpiod_ena = devm_gpiod_get(dev, ST21NFCA_GPIO_NAME_EN, GPIOD_OUT_LOW); if (IS_ERR(phy->gpiod_ena)) { nfc_err(dev, "Unable to get ENABLE GPIO\n"); return PTR_ERR(phy->gpiod_ena); @@ -523,8 +534,7 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) struct device *dev = &client->dev; /* Get GPIO from device tree */ - phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 0, - GPIOD_OUT_HIGH); + phy->gpiod_ena = devm_gpiod_get(dev, ST21NFCA_GPIO_NAME_EN, GPIOD_OUT_HIGH); if (IS_ERR(phy->gpiod_ena)) { nfc_err(dev, "Failed to request enable pin\n"); return PTR_ERR(phy->gpiod_ena); -- cgit v1.2.3 From d31748be2ba37b29bc051f1b5ce2f30294db2cc1 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:48 +0300 Subject: NFC: st21nfca: Get rid of code duplication in ->probe() Since OF and ACPI case almost the same get rid of code duplication by moving gpiod_get() calls directly to ->probe(). Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st21nfca/i2c.c | 62 ++++++++-------------------------------------- 1 file changed, 10 insertions(+), 52 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c index 3621290807f6..cd1f7bfa75eb 100644 --- a/drivers/nfc/st21nfca/i2c.c +++ b/drivers/nfc/st21nfca/i2c.c @@ -61,8 +61,6 @@ #define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci" #define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c" -#define ST21NFCA_GPIO_NAME_EN "enable" - struct st21nfca_i2c_phy { struct i2c_client *i2c_dev; struct nfc_hci_dev *hdev; @@ -508,44 +506,10 @@ static const struct acpi_gpio_mapping acpi_st21nfca_gpios[] = { {}, }; -static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client) -{ - struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); - struct device *dev = &client->dev; - int ret; - - ret = devm_acpi_dev_add_driver_gpios(dev, acpi_st21nfca_gpios); - if (ret) - return ret; - - /* Get EN GPIO from ACPI */ - phy->gpiod_ena = devm_gpiod_get(dev, ST21NFCA_GPIO_NAME_EN, GPIOD_OUT_LOW); - if (IS_ERR(phy->gpiod_ena)) { - nfc_err(dev, "Unable to get ENABLE GPIO\n"); - return PTR_ERR(phy->gpiod_ena); - } - - return 0; -} - -static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) -{ - struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); - struct device *dev = &client->dev; - - /* Get GPIO from device tree */ - phy->gpiod_ena = devm_gpiod_get(dev, ST21NFCA_GPIO_NAME_EN, GPIOD_OUT_HIGH); - if (IS_ERR(phy->gpiod_ena)) { - nfc_err(dev, "Failed to request enable pin\n"); - return PTR_ERR(phy->gpiod_ena); - } - - return 0; -} - static int st21nfca_hci_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct st21nfca_i2c_phy *phy; int r; @@ -572,21 +536,15 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client, mutex_init(&phy->phy_lock); i2c_set_clientdata(client, phy); - if (client->dev.of_node) { - r = st21nfca_hci_i2c_of_request_resources(client); - if (r) { - nfc_err(&client->dev, "No platform data\n"); - return r; - } - } else if (ACPI_HANDLE(&client->dev)) { - r = st21nfca_hci_i2c_acpi_request_resources(client); - if (r) { - nfc_err(&client->dev, "Cannot get ACPI data\n"); - return r; - } - } else { - nfc_err(&client->dev, "st21nfca platform resources not available\n"); - return -ENODEV; + r = devm_acpi_dev_add_driver_gpios(dev, acpi_st21nfca_gpios); + if (r) + dev_dbg(dev, "Unable to add GPIO mapping table\n"); + + /* Get EN GPIO from resource provider */ + phy->gpiod_ena = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); + if (IS_ERR(phy->gpiod_ena)) { + nfc_err(dev, "Unable to get ENABLE GPIO\n"); + return PTR_ERR(phy->gpiod_ena); } phy->se_status.is_ese_present = -- cgit v1.2.3 From 8597c0920d6f4af66d2100b93599b0c0850dffdd Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:49 +0300 Subject: NFC: fdp: Convert I2C driver to ->probe_new() There is no platform code that uses i2c module table. Remove it altogether and adjust ->probe() to be ->probe_new(). Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/fdp/i2c.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index e0baec848ff2..8a66b1845f27 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -281,8 +281,7 @@ vsc_read_err: *clock_type, *clock_freq, *fw_vsc_cfg != NULL ? "yes" : "no"); } -static int fdp_nci_i2c_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int fdp_nci_i2c_probe(struct i2c_client *client) { struct fdp_i2c_phy *phy; struct device *dev = &client->dev; @@ -360,12 +359,6 @@ static int fdp_nci_i2c_remove(struct i2c_client *client) return 0; } -static struct i2c_device_id fdp_nci_i2c_id_table[] = { - {"int339a", 0}, - {} -}; -MODULE_DEVICE_TABLE(i2c, fdp_nci_i2c_id_table); - static const struct acpi_device_id fdp_nci_i2c_acpi_match[] = { {"INT339A", 0}, {} @@ -377,8 +370,7 @@ static struct i2c_driver fdp_nci_i2c_driver = { .name = FDP_I2C_DRIVER_NAME, .acpi_match_table = ACPI_PTR(fdp_nci_i2c_acpi_match), }, - .id_table = fdp_nci_i2c_id_table, - .probe = fdp_nci_i2c_probe, + .probe_new = fdp_nci_i2c_probe, .remove = fdp_nci_i2c_remove, }; module_i2c_driver(fdp_nci_i2c_driver); -- cgit v1.2.3 From 7b9fcda91e18f13905e07f0145cc7efbe0e503dc Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:50 +0300 Subject: NFC: fdp: Convert to use devres API It looks like there are two leftovers, at least one of which can leak the resource (IRQ). Convert both places to use managed variants of the functions. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/fdp/fdp.c | 15 ++++----------- drivers/nfc/fdp/i2c.c | 10 +++++----- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/fdp/fdp.c b/drivers/nfc/fdp/fdp.c index badd8167ac73..ec50027b0d8b 100644 --- a/drivers/nfc/fdp/fdp.c +++ b/drivers/nfc/fdp/fdp.c @@ -749,11 +749,9 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, u32 protocols; int r; - info = kzalloc(sizeof(struct fdp_nci_info), GFP_KERNEL); - if (!info) { - r = -ENOMEM; - goto err_info_alloc; - } + info = devm_kzalloc(dev, sizeof(struct fdp_nci_info), GFP_KERNEL); + if (!info) + return -ENOMEM; info->phy = phy; info->phy_ops = phy_ops; @@ -775,8 +773,7 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, tx_tailroom); if (!ndev) { nfc_err(dev, "Cannot allocate nfc ndev\n"); - r = -ENOMEM; - goto err_alloc_ndev; + return -ENOMEM; } r = nci_register_device(ndev); @@ -792,9 +789,6 @@ int fdp_nci_probe(struct fdp_i2c_phy *phy, struct nfc_phy_ops *phy_ops, err_regdev: nci_free_device(ndev); -err_alloc_ndev: - kfree(info); -err_info_alloc: return r; } EXPORT_SYMBOL(fdp_nci_probe); @@ -808,7 +802,6 @@ void fdp_nci_remove(struct nci_dev *ndev) nci_unregister_device(ndev); nci_free_device(ndev); - kfree(info); } EXPORT_SYMBOL(fdp_nci_remove); diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index 8a66b1845f27..c955f1f5139d 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -303,8 +303,7 @@ static int fdp_nci_i2c_probe(struct i2c_client *client) return -ENODEV; } - phy = devm_kzalloc(dev, sizeof(struct fdp_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc(dev, sizeof(struct fdp_i2c_phy), GFP_KERNEL); if (!phy) return -ENOMEM; @@ -312,9 +311,10 @@ static int fdp_nci_i2c_probe(struct i2c_client *client) phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD; i2c_set_clientdata(client, phy); - r = request_threaded_irq(client->irq, NULL, fdp_nci_i2c_irq_thread_fn, - IRQF_TRIGGER_RISING | IRQF_ONESHOT, - FDP_I2C_DRIVER_NAME, phy); + r = devm_request_threaded_irq(dev, client->irq, + NULL, fdp_nci_i2c_irq_thread_fn, + IRQF_TRIGGER_RISING | IRQF_ONESHOT, + FDP_I2C_DRIVER_NAME, phy); if (r < 0) { nfc_err(&client->dev, "Unable to register IRQ handler\n"); -- cgit v1.2.3 From a5d410949ab0a8934e9352dad08ad588beae3395 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:51 +0300 Subject: NFC: fdp: Add GPIO ACPI mapping table In order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware. Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/fdp/i2c.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/fdp/i2c.c b/drivers/nfc/fdp/i2c.c index c955f1f5139d..c4da50e07bbc 100644 --- a/drivers/nfc/fdp/i2c.c +++ b/drivers/nfc/fdp/i2c.c @@ -27,7 +27,6 @@ #define FDP_I2C_DRIVER_NAME "fdp_nci_i2c" -#define FDP_DP_POWER_GPIO_NAME "power" #define FDP_DP_CLOCK_TYPE_NAME "clock-type" #define FDP_DP_CLOCK_FREQ_NAME "clock-freq" #define FDP_DP_FW_VSC_CFG_NAME "fw-vsc-cfg" @@ -281,6 +280,13 @@ vsc_read_err: *clock_type, *clock_freq, *fw_vsc_cfg != NULL ? "yes" : "no"); } +static const struct acpi_gpio_params power_gpios = { 0, 0, false }; + +static const struct acpi_gpio_mapping acpi_fdp_gpios[] = { + { "power-gpios", &power_gpios, 1 }, + {}, +}; + static int fdp_nci_i2c_probe(struct i2c_client *client) { struct fdp_i2c_phy *phy; @@ -321,10 +327,12 @@ static int fdp_nci_i2c_probe(struct i2c_client *client) return r; } - /* Requesting the power gpio */ - phy->power_gpio = devm_gpiod_get(dev, FDP_DP_POWER_GPIO_NAME, - GPIOD_OUT_LOW); + r = devm_acpi_dev_add_driver_gpios(dev, acpi_fdp_gpios); + if (r) + dev_dbg(dev, "Unable to add GPIO mapping table\n"); + /* Requesting the power gpio */ + phy->power_gpio = devm_gpiod_get(dev, "power", GPIOD_OUT_LOW); if (IS_ERR(phy->power_gpio)) { nfc_err(dev, "Power GPIO request failed\n"); return PTR_ERR(phy->power_gpio); -- cgit v1.2.3 From 61a04101c8a486dec586b2657bffede1b3b979f3 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:52 +0300 Subject: NFC: st-nci: Get rid of platform data Legacy platform data must go away. We are on the safe side here since there are no users of it in the kernel. If anyone by any odd reason needs it the GPIO lookup tables and built-in device properties at your service. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- MAINTAINERS | 1 - drivers/nfc/st-nci/i2c.c | 43 ++---------------------------------- drivers/nfc/st-nci/spi.c | 43 ++---------------------------------- include/linux/platform_data/st-nci.h | 31 -------------------------- 4 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 include/linux/platform_data/st-nci.h (limited to 'drivers/nfc') diff --git a/MAINTAINERS b/MAINTAINERS index 1616d8f10767..f83b9b4d452e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9071,7 +9071,6 @@ F: include/linux/platform_data/nfcmrvl.h F: include/linux/platform_data/nxp-nci.h F: include/linux/platform_data/pn544.h F: include/linux/platform_data/st21nfca.h -F: include/linux/platform_data/st-nci.h F: Documentation/devicetree/bindings/net/nfc/ NFS, SUNRPC, AND LOCKD CLIENTS diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index 9dfae0efa922..6d3d8e43fa50 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "st-nci.h" @@ -40,6 +39,7 @@ #define ST_NCI_I2C_MIN_SIZE 4 /* PCB(1) + NCI Packet header(3) */ #define ST_NCI_I2C_MAX_SIZE 250 /* req 4.2.1 */ +#define ST_NCI_DRIVER_NAME "st_nci" #define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c" #define ST_NCI_GPIO_NAME_RESET "reset" @@ -281,41 +281,10 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) return 0; } -static int st_nci_i2c_request_resources(struct i2c_client *client) -{ - struct st_nci_nfc_platform_data *pdata; - struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); - int r; - - pdata = client->dev.platform_data; - if (pdata == NULL) { - nfc_err(&client->dev, "No platform data\n"); - return -EINVAL; - } - - /* store for later use */ - phy->gpio_reset = pdata->gpio_reset; - phy->irq_polarity = pdata->irq_polarity; - - r = devm_gpio_request_one(&client->dev, - phy->gpio_reset, GPIOF_OUT_INIT_HIGH, - ST_NCI_GPIO_NAME_RESET); - if (r) { - pr_err("%s : reset gpio_request failed\n", __FILE__); - return r; - } - - phy->se_status.is_ese_present = pdata->is_ese_present; - phy->se_status.is_uicc_present = pdata->is_uicc_present; - - return 0; -} - static int st_nci_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct st_nci_i2c_phy *phy; - struct st_nci_nfc_platform_data *pdata; int r; dev_dbg(&client->dev, "%s\n", __func__); @@ -335,20 +304,12 @@ static int st_nci_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, phy); - pdata = client->dev.platform_data; - if (!pdata && client->dev.of_node) { + if (client->dev.of_node) { r = st_nci_i2c_of_request_resources(client); if (r) { nfc_err(&client->dev, "No platform data\n"); return r; } - } else if (pdata) { - r = st_nci_i2c_request_resources(client); - if (r) { - nfc_err(&client->dev, - "Cannot get platform resources\n"); - return r; - } } else if (ACPI_HANDLE(&client->dev)) { r = st_nci_i2c_acpi_request_resources(client); if (r) { diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 89e341eba3eb..ee8ea708d5b7 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -28,7 +28,6 @@ #include #include #include -#include #include "st-nci.h" @@ -41,6 +40,7 @@ #define ST_NCI_SPI_MIN_SIZE 4 /* PCB(1) + NCI Packet header(3) */ #define ST_NCI_SPI_MAX_SIZE 250 /* req 4.2.1 */ +#define ST_NCI_DRIVER_NAME "st_nci" #define ST_NCI_SPI_DRIVER_NAME "st_nci_spi" #define ST_NCI_GPIO_NAME_RESET "reset" @@ -296,40 +296,9 @@ static int st_nci_spi_of_request_resources(struct spi_device *dev) return 0; } -static int st_nci_spi_request_resources(struct spi_device *dev) -{ - struct st_nci_nfc_platform_data *pdata; - struct st_nci_spi_phy *phy = spi_get_drvdata(dev); - int r; - - pdata = dev->dev.platform_data; - if (pdata == NULL) { - nfc_err(&dev->dev, "No platform data\n"); - return -EINVAL; - } - - /* store for later use */ - phy->gpio_reset = pdata->gpio_reset; - phy->irq_polarity = pdata->irq_polarity; - - r = devm_gpio_request_one(&dev->dev, - phy->gpio_reset, GPIOF_OUT_INIT_HIGH, - ST_NCI_GPIO_NAME_RESET); - if (r) { - pr_err("%s : reset gpio_request failed\n", __FILE__); - return r; - } - - phy->se_status.is_ese_present = pdata->is_ese_present; - phy->se_status.is_uicc_present = pdata->is_uicc_present; - - return 0; -} - static int st_nci_spi_probe(struct spi_device *dev) { struct st_nci_spi_phy *phy; - struct st_nci_nfc_platform_data *pdata; int r; dev_dbg(&dev->dev, "%s\n", __func__); @@ -351,20 +320,12 @@ static int st_nci_spi_probe(struct spi_device *dev) spi_set_drvdata(dev, phy); - pdata = dev->dev.platform_data; - if (!pdata && dev->dev.of_node) { + if (dev->dev.of_node) { r = st_nci_spi_of_request_resources(dev); if (r) { nfc_err(&dev->dev, "No platform data\n"); return r; } - } else if (pdata) { - r = st_nci_spi_request_resources(dev); - if (r) { - nfc_err(&dev->dev, - "Cannot get platform resources\n"); - return r; - } } else if (ACPI_HANDLE(&dev->dev)) { r = st_nci_spi_acpi_request_resources(dev); if (r) { diff --git a/include/linux/platform_data/st-nci.h b/include/linux/platform_data/st-nci.h deleted file mode 100644 index f6494b347c06..000000000000 --- a/include/linux/platform_data/st-nci.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Driver include for ST NCI NFC chip family. - * - * Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, see . - */ - -#ifndef _ST_NCI_H_ -#define _ST_NCI_H_ - -#define ST_NCI_DRIVER_NAME "st_nci" - -struct st_nci_nfc_platform_data { - unsigned int gpio_reset; - unsigned int irq_polarity; - bool is_ese_present; - bool is_uicc_present; -}; - -#endif /* _ST_NCI_H_ */ -- cgit v1.2.3 From 1af9fea6be9de6e86f628e66c0eae996c49dbe80 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:53 +0300 Subject: NFC: st-nci: Get rid of "interesting" use of interrupt polarity I2C and SPI frameworks followed by IRQ framework do set interrupt polarity correctly if it's properly specified in firmware (ACPI or DT). Get rid of the redundant trick when requesting interrupt. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st-nci/i2c.c | 8 +------- drivers/nfc/st-nci/spi.c | 8 +------- 2 files changed, 2 insertions(+), 14 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index 6d3d8e43fa50..bdfbd543e671 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -51,7 +50,6 @@ struct st_nci_i2c_phy { bool irq_active; unsigned int gpio_reset; - unsigned int irq_polarity; struct st_nci_se_status se_status; }; @@ -225,8 +223,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) phy->gpio_reset = desc_to_gpio(gpiod_reset); - phy->irq_polarity = irq_get_trigger_type(client->irq); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false; @@ -271,8 +267,6 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) } phy->gpio_reset = gpio; - phy->irq_polarity = irq_get_trigger_type(client->irq); - phy->se_status.is_ese_present = of_property_read_bool(pp, "ese-present"); phy->se_status.is_uicc_present = @@ -333,7 +327,7 @@ static int st_nci_i2c_probe(struct i2c_client *client, phy->irq_active = true; r = devm_request_threaded_irq(&client->dev, client->irq, NULL, st_nci_irq_thread_fn, - phy->irq_polarity | IRQF_ONESHOT, + IRQF_ONESHOT, ST_NCI_DRIVER_NAME, phy); if (r < 0) nfc_err(&client->dev, "Unable to register IRQ handler\n"); diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index ee8ea708d5b7..4585e205778b 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -52,7 +51,6 @@ struct st_nci_spi_phy { bool irq_active; unsigned int gpio_reset; - unsigned int irq_polarity; struct st_nci_se_status se_status; }; @@ -240,8 +238,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) phy->gpio_reset = desc_to_gpio(gpiod_reset); - phy->irq_polarity = irq_get_trigger_type(spi_dev->irq); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false; @@ -286,8 +282,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *dev) } phy->gpio_reset = gpio; - phy->irq_polarity = irq_get_trigger_type(dev->irq); - phy->se_status.is_ese_present = of_property_read_bool(pp, "ese-present"); phy->se_status.is_uicc_present = @@ -349,7 +343,7 @@ static int st_nci_spi_probe(struct spi_device *dev) phy->irq_active = true; r = devm_request_threaded_irq(&dev->dev, dev->irq, NULL, st_nci_irq_thread_fn, - phy->irq_polarity | IRQF_ONESHOT, + IRQF_ONESHOT, ST_NCI_SPI_DRIVER_NAME, phy); if (r < 0) nfc_err(&dev->dev, "Unable to register IRQ handler\n"); -- cgit v1.2.3 From a89e68f118e96b165555f7c64fee8aaff7bb7fb3 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:54 +0300 Subject: NFC: st-nci: Covert to use GPIO descriptor Since we got rid of platform data, the driver may use GPIO descriptor directly. Looking deeply to the use of the GPIO pin it looks like it should be a GPIO based reset control rather than custom GPIO handling. But this is out of scope of the change. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st-nci/i2c.c | 39 ++++++++++++--------------------------- drivers/nfc/st-nci/spi.c | 47 ++++++++++++++++------------------------------- 2 files changed, 28 insertions(+), 58 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index bdfbd543e671..93a621e27d4e 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -19,13 +19,12 @@ #include #include -#include #include -#include #include #include #include #include +#include #include "st-nci.h" @@ -49,7 +48,7 @@ struct st_nci_i2c_phy { bool irq_active; - unsigned int gpio_reset; + struct gpio_desc *gpiod_reset; struct st_nci_se_status se_status; }; @@ -58,9 +57,9 @@ static int st_nci_i2c_enable(void *phy_id) { struct st_nci_i2c_phy *phy = phy_id; - gpio_set_value(phy->gpio_reset, 0); + gpiod_set_value(phy->gpiod_reset, 0); usleep_range(10000, 15000); - gpio_set_value(phy->gpio_reset, 1); + gpiod_set_value(phy->gpiod_reset, 1); usleep_range(80000, 85000); if (phy->ndlc->powered == 0 && phy->irq_active == 0) { @@ -209,20 +208,17 @@ static struct nfc_phy_ops i2c_phy_ops = { static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); - struct gpio_desc *gpiod_reset; struct device *dev = &client->dev; u8 tmp; /* Get RESET GPIO from ACPI */ - gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1, - GPIOD_OUT_HIGH); - if (IS_ERR(gpiod_reset)) { + phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, + 1, GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { nfc_err(dev, "Unable to get RESET GPIO\n"); return -ENODEV; } - phy->gpio_reset = desc_to_gpio(gpiod_reset); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false; @@ -242,30 +238,19 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) static int st_nci_i2c_of_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); + struct device *dev = &client->dev; struct device_node *pp; - int gpio; - int r; pp = client->dev.of_node; if (!pp) return -ENODEV; /* Get GPIO from device tree */ - gpio = of_get_named_gpio(pp, "reset-gpios", 0); - if (gpio < 0) { - nfc_err(&client->dev, - "Failed to retrieve reset-gpios from device tree\n"); - return gpio; - } - - /* GPIO request and configuration */ - r = devm_gpio_request_one(&client->dev, gpio, - GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET); - if (r) { - nfc_err(&client->dev, "Failed to request reset pin\n"); - return r; + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { + nfc_err(dev, "Unable to get RESET GPIO\n"); + return PTR_ERR(phy->gpiod_reset); } - phy->gpio_reset = gpio; phy->se_status.is_ese_present = of_property_read_bool(pp, "ese-present"); diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 4585e205778b..2834f6984608 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -19,13 +19,12 @@ #include #include -#include #include -#include #include #include #include #include +#include #include #include "st-nci.h" @@ -50,7 +49,7 @@ struct st_nci_spi_phy { bool irq_active; - unsigned int gpio_reset; + struct gpio_desc *gpiod_reset; struct st_nci_se_status se_status; }; @@ -59,9 +58,9 @@ static int st_nci_spi_enable(void *phy_id) { struct st_nci_spi_phy *phy = phy_id; - gpio_set_value(phy->gpio_reset, 0); + gpiod_set_value(phy->gpiod_reset, 0); usleep_range(10000, 15000); - gpio_set_value(phy->gpio_reset, 1); + gpiod_set_value(phy->gpiod_reset, 1); usleep_range(80000, 85000); if (phy->ndlc->powered == 0 && phy->irq_active == 0) { @@ -224,20 +223,17 @@ static struct nfc_phy_ops spi_phy_ops = { static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) { struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); - struct gpio_desc *gpiod_reset; struct device *dev = &spi_dev->dev; u8 tmp; /* Get RESET GPIO from ACPI */ - gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1, - GPIOD_OUT_HIGH); - if (IS_ERR(gpiod_reset)) { + phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, + 1, GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { nfc_err(dev, "Unable to get RESET GPIO\n"); - return -ENODEV; + return PTR_ERR(phy->gpiod_reset); } - phy->gpio_reset = desc_to_gpio(gpiod_reset); - phy->se_status.is_ese_present = false; phy->se_status.is_uicc_present = false; @@ -254,33 +250,22 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) return 0; } -static int st_nci_spi_of_request_resources(struct spi_device *dev) +static int st_nci_spi_of_request_resources(struct spi_device *spi) { - struct st_nci_spi_phy *phy = spi_get_drvdata(dev); + struct st_nci_spi_phy *phy = spi_get_drvdata(spi); + struct device *dev = &spi->dev; struct device_node *pp; - int gpio; - int r; - pp = dev->dev.of_node; + pp = spi->dev.of_node; if (!pp) return -ENODEV; /* Get GPIO from device tree */ - gpio = of_get_named_gpio(pp, "reset-gpios", 0); - if (gpio < 0) { - nfc_err(&dev->dev, - "Failed to retrieve reset-gpios from device tree\n"); - return gpio; - } - - /* GPIO request and configuration */ - r = devm_gpio_request_one(&dev->dev, gpio, - GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET); - if (r) { - nfc_err(&dev->dev, "Failed to request reset pin\n"); - return r; + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { + nfc_err(dev, "Unable to get RESET GPIO\n"); + return PTR_ERR(phy->gpiod_reset); } - phy->gpio_reset = gpio; phy->se_status.is_ese_present = of_property_read_bool(pp, "ese-present"); -- cgit v1.2.3 From 75719b2b7a03729f403aed55bec938c6d2784690 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:55 +0300 Subject: NFC: st-nci: Use unified device properties API meaningfully Use unified device properties API in meaningful way. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st-nci/i2c.c | 30 ++++++------------------------ drivers/nfc/st-nci/spi.c | 29 +++++------------------------ 2 files changed, 11 insertions(+), 48 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index 93a621e27d4e..2ee381586f14 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -209,7 +209,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); struct device *dev = &client->dev; - u8 tmp; /* Get RESET GPIO from ACPI */ phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, @@ -219,19 +218,6 @@ static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) return -ENODEV; } - phy->se_status.is_ese_present = false; - phy->se_status.is_uicc_present = false; - - if (device_property_present(dev, "ese-present")) { - device_property_read_u8(dev, "ese-present", &tmp); - phy->se_status.is_ese_present = tmp; - } - - if (device_property_present(dev, "uicc-present")) { - device_property_read_u8(dev, "uicc-present", &tmp); - phy->se_status.is_uicc_present = tmp; - } - return 0; } @@ -239,11 +225,6 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); struct device *dev = &client->dev; - struct device_node *pp; - - pp = client->dev.of_node; - if (!pp) - return -ENODEV; /* Get GPIO from device tree */ phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); @@ -252,17 +233,13 @@ static int st_nci_i2c_of_request_resources(struct i2c_client *client) return PTR_ERR(phy->gpiod_reset); } - phy->se_status.is_ese_present = - of_property_read_bool(pp, "ese-present"); - phy->se_status.is_uicc_present = - of_property_read_bool(pp, "uicc-present"); - return 0; } static int st_nci_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct st_nci_i2c_phy *phy; int r; @@ -301,6 +278,11 @@ static int st_nci_i2c_probe(struct i2c_client *client, return -ENODEV; } + phy->se_status.is_ese_present = + device_property_read_bool(dev, "ese-present"); + phy->se_status.is_uicc_present = + device_property_read_bool(dev, "uicc-present"); + r = ndlc_probe(phy, &i2c_phy_ops, &client->dev, ST_NCI_FRAME_HEADROOM, ST_NCI_FRAME_TAILROOM, &phy->ndlc, &phy->se_status); diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 2834f6984608..383bf69163ef 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -224,7 +224,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) { struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); struct device *dev = &spi_dev->dev; - u8 tmp; /* Get RESET GPIO from ACPI */ phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, @@ -234,19 +233,6 @@ static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) return PTR_ERR(phy->gpiod_reset); } - phy->se_status.is_ese_present = false; - phy->se_status.is_uicc_present = false; - - if (device_property_present(dev, "ese-present")) { - device_property_read_u8(dev, "ese-present", &tmp); - tmp = phy->se_status.is_ese_present; - } - - if (device_property_present(dev, "uicc-present")) { - device_property_read_u8(dev, "uicc-present", &tmp); - tmp = phy->se_status.is_uicc_present; - } - return 0; } @@ -254,11 +240,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *spi) { struct st_nci_spi_phy *phy = spi_get_drvdata(spi); struct device *dev = &spi->dev; - struct device_node *pp; - - pp = spi->dev.of_node; - if (!pp) - return -ENODEV; /* Get GPIO from device tree */ phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); @@ -267,11 +248,6 @@ static int st_nci_spi_of_request_resources(struct spi_device *spi) return PTR_ERR(phy->gpiod_reset); } - phy->se_status.is_ese_present = - of_property_read_bool(pp, "ese-present"); - phy->se_status.is_uicc_present = - of_property_read_bool(pp, "uicc-present"); - return 0; } @@ -317,6 +293,11 @@ static int st_nci_spi_probe(struct spi_device *dev) return -ENODEV; } + phy->se_status.is_ese_present = + device_property_read_bool(&dev->dev, "ese-present"); + phy->se_status.is_uicc_present = + device_property_read_bool(&dev->dev, "uicc-present"); + r = ndlc_probe(phy, &spi_phy_ops, &dev->dev, ST_NCI_FRAME_HEADROOM, ST_NCI_FRAME_TAILROOM, &phy->ndlc, &phy->se_status); -- cgit v1.2.3 From 85d23e772931e347c145fa78db3c48f29e169838 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:56 +0300 Subject: NFC: st-nci: Add GPIO ACPI mapping table In order to make GPIO ACPI library stricter prepare users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware. Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver. Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st-nci/i2c.c | 17 +++++++++++++---- drivers/nfc/st-nci/spi.c | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index 2ee381586f14..edda253b07fe 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -40,8 +40,6 @@ #define ST_NCI_DRIVER_NAME "st_nci" #define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c" -#define ST_NCI_GPIO_NAME_RESET "reset" - struct st_nci_i2c_phy { struct i2c_client *i2c_dev; struct llt_ndlc *ndlc; @@ -205,14 +203,25 @@ static struct nfc_phy_ops i2c_phy_ops = { .disable = st_nci_i2c_disable, }; +static const struct acpi_gpio_params reset_gpios = { 1, 0, false }; + +static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { + { "reset-gpios", &reset_gpios, 1 }, + {}, +}; + static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) { struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); struct device *dev = &client->dev; + int r; + + r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); + if (r) + return r; /* Get RESET GPIO from ACPI */ - phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, - 1, GPIOD_OUT_HIGH); + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(phy->gpiod_reset)) { nfc_err(dev, "Unable to get RESET GPIO\n"); return -ENODEV; diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 383bf69163ef..99ecf92edc8c 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -41,8 +41,6 @@ #define ST_NCI_DRIVER_NAME "st_nci" #define ST_NCI_SPI_DRIVER_NAME "st_nci_spi" -#define ST_NCI_GPIO_NAME_RESET "reset" - struct st_nci_spi_phy { struct spi_device *spi_dev; struct llt_ndlc *ndlc; @@ -220,14 +218,25 @@ static struct nfc_phy_ops spi_phy_ops = { .disable = st_nci_spi_disable, }; +static const struct acpi_gpio_params reset_gpios = { 1, 0, false }; + +static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { + { "reset-gpios", &reset_gpios, 1 }, + {}, +}; + static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) { struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); struct device *dev = &spi_dev->dev; + int r; + + r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); + if (r) + return r; /* Get RESET GPIO from ACPI */ - phy->gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, - 1, GPIOD_OUT_HIGH); + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(phy->gpiod_reset)) { nfc_err(dev, "Unable to get RESET GPIO\n"); return PTR_ERR(phy->gpiod_reset); -- cgit v1.2.3 From c745120e343abfbcf5c9239e09cae4a3cf651fa0 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 19 Jun 2017 13:08:57 +0300 Subject: NFC: st-nci: Get rid of code duplication in ->probe() Since OF and ACPI case almost the same get rid of code duplication by moving gpiod_get() calls directly to ->probe(). Signed-off-by: Andy Shevchenko Signed-off-by: Samuel Ortiz --- drivers/nfc/st-nci/i2c.c | 61 +++++++----------------------------------------- drivers/nfc/st-nci/spi.c | 60 +++++++---------------------------------------- 2 files changed, 18 insertions(+), 103 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/st-nci/i2c.c b/drivers/nfc/st-nci/i2c.c index edda253b07fe..515f08d037fb 100644 --- a/drivers/nfc/st-nci/i2c.c +++ b/drivers/nfc/st-nci/i2c.c @@ -210,41 +210,6 @@ static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { {}, }; -static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) -{ - struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); - struct device *dev = &client->dev; - int r; - - r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); - if (r) - return r; - - /* Get RESET GPIO from ACPI */ - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(phy->gpiod_reset)) { - nfc_err(dev, "Unable to get RESET GPIO\n"); - return -ENODEV; - } - - return 0; -} - -static int st_nci_i2c_of_request_resources(struct i2c_client *client) -{ - struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); - struct device *dev = &client->dev; - - /* Get GPIO from device tree */ - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(phy->gpiod_reset)) { - nfc_err(dev, "Unable to get RESET GPIO\n"); - return PTR_ERR(phy->gpiod_reset); - } - - return 0; -} - static int st_nci_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id) { @@ -260,8 +225,7 @@ static int st_nci_i2c_probe(struct i2c_client *client, return -ENODEV; } - phy = devm_kzalloc(&client->dev, sizeof(struct st_nci_i2c_phy), - GFP_KERNEL); + phy = devm_kzalloc(dev, sizeof(struct st_nci_i2c_phy), GFP_KERNEL); if (!phy) return -ENOMEM; @@ -269,21 +233,14 @@ static int st_nci_i2c_probe(struct i2c_client *client, i2c_set_clientdata(client, phy); - if (client->dev.of_node) { - r = st_nci_i2c_of_request_resources(client); - if (r) { - nfc_err(&client->dev, "No platform data\n"); - return r; - } - } else if (ACPI_HANDLE(&client->dev)) { - r = st_nci_i2c_acpi_request_resources(client); - if (r) { - nfc_err(&client->dev, "Cannot get ACPI data\n"); - return r; - } - } else { - nfc_err(&client->dev, - "st_nci platform resources not available\n"); + r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); + if (r) + dev_dbg(dev, "Unable to add GPIO mapping table\n"); + + /* Get RESET GPIO */ + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { + nfc_err(dev, "Unable to get RESET GPIO\n"); return -ENODEV; } diff --git a/drivers/nfc/st-nci/spi.c b/drivers/nfc/st-nci/spi.c index 99ecf92edc8c..14705591b0fb 100644 --- a/drivers/nfc/st-nci/spi.c +++ b/drivers/nfc/st-nci/spi.c @@ -225,41 +225,6 @@ static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = { {}, }; -static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) -{ - struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); - struct device *dev = &spi_dev->dev; - int r; - - r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); - if (r) - return r; - - /* Get RESET GPIO from ACPI */ - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(phy->gpiod_reset)) { - nfc_err(dev, "Unable to get RESET GPIO\n"); - return PTR_ERR(phy->gpiod_reset); - } - - return 0; -} - -static int st_nci_spi_of_request_resources(struct spi_device *spi) -{ - struct st_nci_spi_phy *phy = spi_get_drvdata(spi); - struct device *dev = &spi->dev; - - /* Get GPIO from device tree */ - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(phy->gpiod_reset)) { - nfc_err(dev, "Unable to get RESET GPIO\n"); - return PTR_ERR(phy->gpiod_reset); - } - - return 0; -} - static int st_nci_spi_probe(struct spi_device *dev) { struct st_nci_spi_phy *phy; @@ -284,22 +249,15 @@ static int st_nci_spi_probe(struct spi_device *dev) spi_set_drvdata(dev, phy); - if (dev->dev.of_node) { - r = st_nci_spi_of_request_resources(dev); - if (r) { - nfc_err(&dev->dev, "No platform data\n"); - return r; - } - } else if (ACPI_HANDLE(&dev->dev)) { - r = st_nci_spi_acpi_request_resources(dev); - if (r) { - nfc_err(&dev->dev, "Cannot get ACPI data\n"); - return r; - } - } else { - nfc_err(&dev->dev, - "st_nci platform resources not available\n"); - return -ENODEV; + r = devm_acpi_dev_add_driver_gpios(&dev->dev, acpi_st_nci_gpios); + if (r) + dev_dbg(&dev->dev, "Unable to add GPIO mapping table\n"); + + /* Get RESET GPIO */ + phy->gpiod_reset = devm_gpiod_get(&dev->dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(phy->gpiod_reset)) { + nfc_err(&dev->dev, "Unable to get RESET GPIO\n"); + return PTR_ERR(phy->gpiod_reset); } phy->se_status.is_ese_present = -- cgit v1.2.3 From e1038535106e73e48204ec3bfe5a428fe6cb35cb Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Mon, 24 Apr 2017 14:36:02 +0100 Subject: NFC: trf7970a: fix check of clock frequencies, use && instead of || The "or" condition (clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) || (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUE) will always be true because clk_freq cannot be equal to two different values at the same time. Use the && operator instead of || to fix this. Detected by CoverityScan, CID#1430468 ("Constant expression result") Fixes: 837eb4d21ecde7 ("NFC: trf7970a: add device tree option for 27MHz clock") Signed-off-by: Colin Ian King Acked-by: Geoff Lansberry Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 28b942ea15fb..914463a0e7b3 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2059,7 +2059,7 @@ static int trf7970a_probe(struct spi_device *spi) } of_property_read_u32(np, "clock-frequency", &clk_freq); - if ((clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) || + if ((clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) && (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUENCY)) { dev_err(trf->dev, "clock-frequency (%u Hz) unsupported\n", clk_freq); -- cgit v1.2.3 From a81d1ab3cad77e20c2df8baef0a35a4980fc511c Mon Sep 17 00:00:00 2001 From: Mark Greer Date: Thu, 15 Jun 2017 10:46:17 -0700 Subject: Revert "NFC: trf7970a: Handle extra byte in response to Type 5 RMB commands" This reverts commit ab714817d7e891608d31f6996b1e4c43cf2bf342. The original commit was designed to handle a bug in the trf7970a NFC controller where an extra byte was returned in Read Multiple Blocks (RMB) command responses. However, it has become less clear whether it is a bug in the trf7970a or in the tag. In addition, it was assumed that the extra byte was always returned but it turns out that is not always the case. The result is that a byte of good data is trimmed off when the extra byte is not present ultimately causing the neard deamon to fail the read. Since the trf7970a driver does not have the context to know when to trim the byte or not, remove the code from the trf7970a driver all together (and move it up to the neard daemon). This has the added benefit of simplifying the kernel driver and putting the extra complexity into userspace. CC: Rob Herring CC: devicetree@vger.kernel.org Signed-off-by: Mark Greer Signed-off-by: Samuel Ortiz --- .../devicetree/bindings/net/nfc/trf7970a.txt | 4 ---- drivers/nfc/trf7970a.c | 25 ++++------------------ 2 files changed, 4 insertions(+), 25 deletions(-) (limited to 'drivers/nfc') diff --git a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt index a24a93a4b010..60c833d62181 100644 --- a/Documentation/devicetree/bindings/net/nfc/trf7970a.txt +++ b/Documentation/devicetree/bindings/net/nfc/trf7970a.txt @@ -17,9 +17,6 @@ Optional SoC Specific Properties: "IRQ Status Read" erratum. - en2-rf-quirk: Specify that the trf7970a being used has the "EN2 RF" erratum. -- t5t-rmb-extra-byte-quirk: Specify that the trf7970a has the erratum - where an extra byte is returned by Read Multiple Block commands issued - to Type 5 tags. - vdd-io-supply: Regulator specifying voltage for vdd-io - clock-frequency: Set to specify that the input frequency to the trf7970a is 13560000Hz or 27120000Hz @@ -43,7 +40,6 @@ Example (for ARM-based BeagleBone with TRF7970A on SPI1): autosuspend-delay = <30000>; irq-status-read-quirk; en2-rf-quirk; - t5t-rmb-extra-byte-quirk; clock-frequency = <27120000>; status = "okay"; }; diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 914463a0e7b3..6ee7b038823d 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -150,7 +150,6 @@ */ #define TRF7970A_QUIRK_IRQ_STATUS_READ BIT(0) #define TRF7970A_QUIRK_EN2_MUST_STAY_LOW BIT(1) -#define TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE BIT(2) /* Direct commands */ #define TRF7970A_CMD_IDLE 0x00 @@ -449,7 +448,6 @@ struct trf7970a { u8 md_rf_tech; u8 tx_cmd; bool issue_eof; - bool adjust_resp_len; struct gpio_desc *en_gpiod; struct gpio_desc *en2_gpiod; struct mutex lock; @@ -630,13 +628,6 @@ static void trf7970a_send_upstream(struct trf7970a *trf) trf->aborting = false; } - if (trf->adjust_resp_len) { - if (trf->rx_skb) - skb_trim(trf->rx_skb, trf->rx_skb->len - 1); - - trf->adjust_resp_len = false; - } - trf->cb(trf->ddev, trf->cb_arg, trf->rx_skb); trf->rx_skb = NULL; @@ -1459,15 +1450,10 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf, struct sk_buff *skb) trf->iso_ctrl = iso_ctrl; } - if (trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) { - if (trf7970a_is_iso15693_write_or_lock(req[1]) && - (req[0] & ISO15693_REQ_FLAG_OPTION)) - trf->issue_eof = true; - else if ((trf->quirks & - TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE) && - (req[1] == ISO15693_CMD_READ_MULTIPLE_BLOCK)) - trf->adjust_resp_len = true; - } + if ((trf->framing == NFC_DIGITAL_FRAMING_ISO15693_T5T) && + trf7970a_is_iso15693_write_or_lock(req[1]) && + (req[0] & ISO15693_REQ_FLAG_OPTION)) + trf->issue_eof = true; } return 0; @@ -2032,9 +2018,6 @@ static int trf7970a_probe(struct spi_device *spi) return ret; } - if (of_property_read_bool(np, "t5t-rmb-extra-byte-quirk")) - trf->quirks |= TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE; - if (of_property_read_bool(np, "irq-status-read-quirk")) trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ; -- cgit v1.2.3 From 6f874bafacf053b87887f4149fc117e2b1096138 Mon Sep 17 00:00:00 2001 From: "Gustavo A. R. Silva" Date: Tue, 30 May 2017 15:43:07 -0500 Subject: NFC: add NULL checks to avoid potential NULL pointer dereference NULL checks at line 457: if (!link0 || !link1) {, implies that both pointers link0 and link1 might be NULL. Function nfcsim_link_free() dereference pointers link0 and link1. Add NULL checks before calling nfcsim_link_free() to avoid a potential NULL pointer dereference. Addresses-Coverity-ID: 1364857 Signed-off-by: Gustavo A. R. Silva Signed-off-by: Samuel Ortiz --- drivers/nfc/nfcsim.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/nfc') diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c index a466e7978466..33449820e754 100644 --- a/drivers/nfc/nfcsim.c +++ b/drivers/nfc/nfcsim.c @@ -482,8 +482,10 @@ static int __init nfcsim_init(void) exit_err: pr_err("Failed to initialize nfcsim driver (%d)\n", rc); - nfcsim_link_free(link0); - nfcsim_link_free(link1); + if (link0) + nfcsim_link_free(link0); + if (link1) + nfcsim_link_free(link1); return rc; } -- cgit v1.2.3 From bd751808f9ff5e1822c627f6c4283009e66b2e53 Mon Sep 17 00:00:00 2001 From: Geoff Lansberry Date: Thu, 27 Apr 2017 17:28:46 -0400 Subject: NFC: trf7970a: Correct register settings for 27MHz clock In prior commits the selected clock frequency does not propagate correctly to what is written to the TRF7970A_MODULATOR_SYS_CLK_CTRL register. Signed-off-by: Geoff Lansberry Acked-by: Mark Greer Signed-off-by: Samuel Ortiz --- drivers/nfc/trf7970a.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/nfc') diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c index 6ee7b038823d..eee5cc1a9220 100644 --- a/drivers/nfc/trf7970a.c +++ b/drivers/nfc/trf7970a.c @@ -2049,6 +2049,13 @@ static int trf7970a_probe(struct spi_device *spi) return -EINVAL; } + if (clk_freq == TRF7970A_27MHZ_CLOCK_FREQUENCY) { + trf->modulator_sys_clk_ctrl = TRF7970A_MODULATOR_27MHZ; + dev_dbg(trf->dev, "trf7970a configured for 27MHz crystal\n"); + } else { + trf->modulator_sys_clk_ctrl = 0; + } + ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL, trf7970a_irq, IRQF_TRIGGER_RISING | IRQF_ONESHOT, -- cgit v1.2.3