trf7970a.c (a34631c2723797dd31e6f83538899eeb4c03b753) trf7970a.c (d34e48d6a62a06eb7f72c7dc534c4c318a163dad)
1/*
2 * TI TRF7970a RFID/NFC Transceiver Driver
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Erick Macias <emacias@ti.com>
7 * Author: Felipe Balbi <balbi@ti.com>
8 * Author: Mark A. Greer <mgreer@animalcreek.com>

--- 6 unchanged lines hidden (view full) ---

15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/netdevice.h>
18#include <linux/interrupt.h>
19#include <linux/pm_runtime.h>
20#include <linux/nfc.h>
21#include <linux/skbuff.h>
22#include <linux/delay.h>
1/*
2 * TI TRF7970a RFID/NFC Transceiver Driver
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
5 *
6 * Author: Erick Macias <emacias@ti.com>
7 * Author: Felipe Balbi <balbi@ti.com>
8 * Author: Mark A. Greer <mgreer@animalcreek.com>

--- 6 unchanged lines hidden (view full) ---

15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/netdevice.h>
18#include <linux/interrupt.h>
19#include <linux/pm_runtime.h>
20#include <linux/nfc.h>
21#include <linux/skbuff.h>
22#include <linux/delay.h>
23#include <linux/gpio.h>
23#include <linux/gpio/consumer.h>
24#include <linux/of.h>
24#include <linux/of.h>
25#include <linux/of_gpio.h>
26#include <linux/spi/spi.h>
27#include <linux/regulator/consumer.h>
28
29#include <net/nfc/nfc.h>
30#include <net/nfc/digital.h>
31
32/* There are 3 ways the host can communicate with the trf7970a:
33 * parallel mode, SPI with Slave Select (SS) mode, and SPI without

--- 413 unchanged lines hidden (view full) ---

447 u8 io_ctrl;
448 unsigned int guard_time;
449 int technology;
450 int framing;
451 u8 md_rf_tech;
452 u8 tx_cmd;
453 bool issue_eof;
454 bool adjust_resp_len;
25#include <linux/spi/spi.h>
26#include <linux/regulator/consumer.h>
27
28#include <net/nfc/nfc.h>
29#include <net/nfc/digital.h>
30
31/* There are 3 ways the host can communicate with the trf7970a:
32 * parallel mode, SPI with Slave Select (SS) mode, and SPI without

--- 413 unchanged lines hidden (view full) ---

446 u8 io_ctrl;
447 unsigned int guard_time;
448 int technology;
449 int framing;
450 u8 md_rf_tech;
451 u8 tx_cmd;
452 bool issue_eof;
453 bool adjust_resp_len;
455 int en2_gpio;
456 int en_gpio;
454 struct gpio_desc *en_gpiod;
455 struct gpio_desc *en2_gpiod;
457 struct mutex lock;
458 unsigned int timeout;
459 bool ignore_timeout;
460 struct delayed_work timeout_work;
461};
462
463
464static int trf7970a_cmd(struct trf7970a *trf, u8 opcode)

--- 1438 unchanged lines hidden (view full) ---

1903 ret = regulator_enable(trf->regulator);
1904 if (ret) {
1905 dev_err(trf->dev, "%s - Can't enable VIN: %d\n", __func__, ret);
1906 return ret;
1907 }
1908
1909 usleep_range(5000, 6000);
1910
456 struct mutex lock;
457 unsigned int timeout;
458 bool ignore_timeout;
459 struct delayed_work timeout_work;
460};
461
462
463static int trf7970a_cmd(struct trf7970a *trf, u8 opcode)

--- 1438 unchanged lines hidden (view full) ---

1902 ret = regulator_enable(trf->regulator);
1903 if (ret) {
1904 dev_err(trf->dev, "%s - Can't enable VIN: %d\n", __func__, ret);
1905 return ret;
1906 }
1907
1908 usleep_range(5000, 6000);
1909
1911 if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) {
1912 if (gpio_is_valid(trf->en2_gpio)) {
1913 gpio_set_value(trf->en2_gpio, 1);
1914 usleep_range(1000, 2000);
1915 }
1910 if (trf->en2_gpiod &&
1911 !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW)) {
1912 gpiod_set_value_cansleep(trf->en2_gpiod, 1);
1913 usleep_range(1000, 2000);
1916 }
1917
1914 }
1915
1918 gpio_set_value(trf->en_gpio, 1);
1916 gpiod_set_value_cansleep(trf->en_gpiod, 1);
1919
1920 usleep_range(20000, 21000);
1921
1922 trf->state = TRF7970A_ST_RF_OFF;
1923
1924 return 0;
1925}
1926

--- 7 unchanged lines hidden (view full) ---

1934 return 0;
1935
1936 if (trf->state != TRF7970A_ST_RF_OFF) {
1937 dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n",
1938 trf->state);
1939 return -EBUSY;
1940 }
1941
1917
1918 usleep_range(20000, 21000);
1919
1920 trf->state = TRF7970A_ST_RF_OFF;
1921
1922 return 0;
1923}
1924

--- 7 unchanged lines hidden (view full) ---

1932 return 0;
1933
1934 if (trf->state != TRF7970A_ST_RF_OFF) {
1935 dev_dbg(trf->dev, "Can't power down - not RF_OFF state (%d)\n",
1936 trf->state);
1937 return -EBUSY;
1938 }
1939
1942 gpio_set_value(trf->en_gpio, 0);
1940 gpiod_set_value_cansleep(trf->en_gpiod, 0);
1943
1941
1944 if (!(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW))
1945 if (gpio_is_valid(trf->en2_gpio))
1946 gpio_set_value(trf->en2_gpio, 0);
1942 if (trf->en2_gpiod &&
1943 !(trf->quirks & TRF7970A_QUIRK_EN2_MUST_STAY_LOW))
1944 gpiod_set_value_cansleep(trf->en2_gpiod, 0);
1947
1948 ret = regulator_disable(trf->regulator);
1949 if (ret)
1950 dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__,
1951 ret);
1952
1953 trf->state = TRF7970A_ST_PWR_OFF;
1954

--- 81 unchanged lines hidden (view full) ---

2036
2037 if (of_property_read_bool(np, "t5t-rmb-extra-byte-quirk"))
2038 trf->quirks |= TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE;
2039
2040 if (of_property_read_bool(np, "irq-status-read-quirk"))
2041 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ;
2042
2043 /* There are two enable pins - only EN must be present in the DT */
1945
1946 ret = regulator_disable(trf->regulator);
1947 if (ret)
1948 dev_err(trf->dev, "%s - Can't disable VIN: %d\n", __func__,
1949 ret);
1950
1951 trf->state = TRF7970A_ST_PWR_OFF;
1952

--- 81 unchanged lines hidden (view full) ---

2034
2035 if (of_property_read_bool(np, "t5t-rmb-extra-byte-quirk"))
2036 trf->quirks |= TRF7970A_QUIRK_T5T_RMB_EXTRA_BYTE;
2037
2038 if (of_property_read_bool(np, "irq-status-read-quirk"))
2039 trf->quirks |= TRF7970A_QUIRK_IRQ_STATUS_READ;
2040
2041 /* There are two enable pins - only EN must be present in the DT */
2044 trf->en_gpio = of_get_named_gpio(np, "ti,enable-gpios", 0);
2045 if (!gpio_is_valid(trf->en_gpio)) {
2042 trf->en_gpiod = devm_gpiod_get_index(trf->dev, "ti,enable", 0,
2043 GPIOD_OUT_LOW);
2044 if (IS_ERR(trf->en_gpiod)) {
2046 dev_err(trf->dev, "No EN GPIO property\n");
2045 dev_err(trf->dev, "No EN GPIO property\n");
2047 return trf->en_gpio;
2046 return PTR_ERR(trf->en_gpiod);
2048 }
2049
2047 }
2048
2050 ret = devm_gpio_request_one(trf->dev, trf->en_gpio,
2051 GPIOF_DIR_OUT | GPIOF_INIT_LOW, "trf7970a EN");
2052 if (ret) {
2053 dev_err(trf->dev, "Can't request EN GPIO: %d\n", ret);
2054 return ret;
2055 }
2056
2057 trf->en2_gpio = of_get_named_gpio(np, "ti,enable-gpios", 1);
2058 if (!gpio_is_valid(trf->en2_gpio)) {
2049 trf->en2_gpiod = devm_gpiod_get_index_optional(trf->dev, "ti,enable", 1,
2050 GPIOD_OUT_LOW);
2051 if (!trf->en2_gpiod) {
2059 dev_info(trf->dev, "No EN2 GPIO property\n");
2052 dev_info(trf->dev, "No EN2 GPIO property\n");
2060 } else {
2061 ret = devm_gpio_request_one(trf->dev, trf->en2_gpio,
2062 GPIOF_DIR_OUT | GPIOF_INIT_LOW, "trf7970a EN2");
2063 if (ret) {
2064 dev_err(trf->dev, "Can't request EN2 GPIO: %d\n", ret);
2065 return ret;
2066 }
2067
2068 if (of_property_read_bool(np, "en2-rf-quirk"))
2069 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW;
2053 } else if (IS_ERR(trf->en2_gpiod)) {
2054 dev_err(trf->dev, "Error getting EN2 GPIO property: %ld\n",
2055 PTR_ERR(trf->en2_gpiod));
2056 return PTR_ERR(trf->en2_gpiod);
2057 } else if (of_property_read_bool(np, "en2-rf-quirk")) {
2058 trf->quirks |= TRF7970A_QUIRK_EN2_MUST_STAY_LOW;
2070 }
2071
2072 of_property_read_u32(np, "clock-frequency", &clk_freq);
2073 if ((clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) ||
2074 (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUENCY)) {
2075 dev_err(trf->dev,
2076 "clock-frequency (%u Hz) unsupported\n",
2077 clk_freq);

--- 215 unchanged lines hidden ---
2059 }
2060
2061 of_property_read_u32(np, "clock-frequency", &clk_freq);
2062 if ((clk_freq != TRF7970A_27MHZ_CLOCK_FREQUENCY) ||
2063 (clk_freq != TRF7970A_13MHZ_CLOCK_FREQUENCY)) {
2064 dev_err(trf->dev,
2065 "clock-frequency (%u Hz) unsupported\n",
2066 clk_freq);

--- 215 unchanged lines hidden ---