Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'nfc-next-4.5-1' of git://git.kernel.org/pub/scm/linux/kernel/git/sameo/nfc-next

Samuel Ortiz says:

====================
NFC 4.5 pull request

This is the first NFC pull request for 4.5 and it brings:

- A new driver for the STMicroelectronics ST95HF NFC chipset.
The ST95HF is an NFC digital transceiver with an embedded analog
front-end and as such relies on the Linux NFC digital
implementation. This is the 3rd user of the NFC digital stack.

- ACPI support for the ST st-nci and st21nfca drivers.

- A small improvement for the nfcsim driver, as we can now tune
the Rx delay through sysfs.

- A bunch of minor cleanups and small fixes from Christophe Ricard,
for a few drivers and the NFC core code.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+1862 -181
+50
Documentation/devicetree/bindings/net/nfc/st95hf.txt
··· 1 + * STMicroelectronics : NFC Transceiver ST95HF 2 + 3 + ST NFC Transceiver is required to attach with SPI bus. 4 + ST95HF node should be defined in DT as SPI slave device of SPI 5 + master with which ST95HF transceiver is physically connected. 6 + The properties defined below are required to be the part of DT 7 + to include ST95HF transceiver into the platform. 8 + 9 + Required properties: 10 + =================== 11 + - reg: Address of SPI slave "ST95HF transceiver" on SPI master bus. 12 + 13 + - compatible: should be "st,st95hf" for ST95HF NFC transceiver 14 + 15 + - spi-max-frequency: Max. operating SPI frequency for ST95HF 16 + transceiver. 17 + 18 + - enable-gpio: GPIO line to enable ST95HF transceiver. 19 + 20 + - interrupt-parent : Standard way to specify the controller to which 21 + ST95HF transceiver's interrupt is routed. 22 + 23 + - interrupts : Standard way to define ST95HF transceiver's out 24 + interrupt. 25 + 26 + Optional property: 27 + ================= 28 + - st95hfvin-supply : This is an optional property. It contains a 29 + phandle to ST95HF transceiver's regulator supply node in DT. 30 + 31 + Example: 32 + ======= 33 + spi@9840000 { 34 + reg = <0x9840000 0x110>; 35 + #address-cells = <1>; 36 + #size-cells = <0>; 37 + cs-gpios = <&pio0 4>; 38 + status = "okay"; 39 + 40 + st95hf@0{ 41 + reg = <0>; 42 + compatible = "st,st95hf"; 43 + status = "okay"; 44 + spi-max-frequency = <1000000>; 45 + enable-gpio = <&pio4 0>; 46 + interrupt-parent = <&pio0>; 47 + interrupts = <7 IRQ_TYPE_EDGE_FALLING>; 48 + }; 49 + 50 + };
+5
MAINTAINERS
··· 7523 7523 F: include/net/nfc/ 7524 7524 F: include/uapi/linux/nfc.h 7525 7525 F: drivers/nfc/ 7526 + F: include/linux/platform_data/microread.h 7527 + F: include/linux/platform_data/nfcmrvl.h 7528 + F: include/linux/platform_data/nxp-nci.h 7526 7529 F: include/linux/platform_data/pn544.h 7530 + F: include/linux/platform_data/st21nfca.h 7531 + F: include/linux/platform_data/st-nci.h 7527 7532 F: Documentation/devicetree/bindings/net/nfc/ 7528 7533 7529 7534 NFS, SUNRPC, AND LOCKD CLIENTS
+1
drivers/nfc/Kconfig
··· 76 76 source "drivers/nfc/st-nci/Kconfig" 77 77 source "drivers/nfc/nxp-nci/Kconfig" 78 78 source "drivers/nfc/s3fwrn5/Kconfig" 79 + source "drivers/nfc/st95hf/Kconfig" 79 80 endmenu
+1
drivers/nfc/Makefile
··· 16 16 obj-$(CONFIG_NFC_ST_NCI) += st-nci/ 17 17 obj-$(CONFIG_NFC_NXP_NCI) += nxp-nci/ 18 18 obj-$(CONFIG_NFC_S3FWRN5) += s3fwrn5/ 19 + obj-$(CONFIG_NFC_ST95HF) += st95hf/
+6 -6
drivers/nfc/fdp/i2c.c
··· 298 298 return -ENODEV; 299 299 } 300 300 301 + /* Checking if we have an irq */ 302 + if (client->irq <= 0) { 303 + nfc_err(dev, "IRQ not present\n"); 304 + return -ENODEV; 305 + } 306 + 301 307 phy = devm_kzalloc(dev, sizeof(struct fdp_i2c_phy), 302 308 GFP_KERNEL); 303 309 if (!phy) ··· 312 306 phy->i2c_dev = client; 313 307 phy->next_read_size = FDP_NCI_I2C_MIN_PAYLOAD; 314 308 i2c_set_clientdata(client, phy); 315 - 316 - /* Checking if we have an irq */ 317 - if (client->irq <= 0) { 318 - dev_err(dev, "IRQ not present\n"); 319 - return -ENODEV; 320 - } 321 309 322 310 r = request_threaded_irq(client->irq, NULL, fdp_nci_i2c_irq_thread_fn, 323 311 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-2
drivers/nfc/microread/i2c.c
··· 50 50 struct i2c_client *i2c_dev; 51 51 struct nfc_hci_dev *hdev; 52 52 53 - int irq; 54 - 55 53 int hard_fault; /* 56 54 * < 0 if hardware error occured (e.g. i2c err) 57 55 * and prevents normal operation.
+7 -3
drivers/nfc/nfcsim.c
··· 32 32 #define NFCSIM_POLL_TARGET 2 33 33 #define NFCSIM_POLL_DUAL (NFCSIM_POLL_INITIATOR | NFCSIM_POLL_TARGET) 34 34 35 + #define RX_DEFAULT_DELAY 5 36 + 35 37 struct nfcsim { 36 38 struct nfc_dev *nfc_dev; 37 39 ··· 52 50 u8 up; 53 51 54 52 u8 initiator; 53 + 54 + u32 rx_delay; 55 55 56 56 data_exchange_cb_t cb; 57 57 void *cb_context; ··· 324 320 * If packet transmission occurs immediately between them, we have a 325 321 * non-stop flow of several tens of thousands SYMM packets per second 326 322 * and a burning cpu. 327 - * 328 - * TODO: Add support for a sysfs entry to control this delay. 329 323 */ 330 - queue_delayed_work(wq, &peer->recv_work, msecs_to_jiffies(5)); 324 + queue_delayed_work(wq, &peer->recv_work, 325 + msecs_to_jiffies(dev->rx_delay)); 331 326 332 327 mutex_unlock(&peer->lock); 333 328 ··· 464 461 if (rc) 465 462 goto free_nfc_dev; 466 463 464 + dev->rx_delay = RX_DEFAULT_DELAY; 467 465 return dev; 468 466 469 467 free_nfc_dev:
+3 -31
drivers/nfc/nxp-nci/i2c.c
··· 52 52 53 53 unsigned int gpio_en; 54 54 unsigned int gpio_fw; 55 - unsigned int gpio_irq; 56 55 57 56 int hard_fault; /* 58 57 * < 0 if hardware error occurred (e.g. i2c err) ··· 84 85 return phy->hard_fault; 85 86 86 87 r = i2c_master_send(client, skb->data, skb->len); 87 - if (r == -EREMOTEIO) { 88 + if (r < 0) { 88 89 /* Retry, chip was in standby */ 89 90 usleep_range(110000, 120000); 90 91 r = i2c_master_send(client, skb->data, skb->len); ··· 263 264 return IRQ_NONE; 264 265 } 265 266 266 - #ifdef CONFIG_OF 267 - 268 267 static int nxp_nci_i2c_parse_devtree(struct i2c_client *client) 269 268 { 270 269 struct nxp_nci_i2c_phy *phy = i2c_get_clientdata(client); ··· 291 294 } 292 295 phy->gpio_fw = r; 293 296 294 - r = irq_of_parse_and_map(pp, 0); 295 - if (r < 0) { 296 - nfc_err(&client->dev, "Unable to get irq, error: %d\n", r); 297 - return r; 298 - } 299 - client->irq = r; 300 - 301 297 return 0; 302 298 } 303 - 304 - #else 305 - 306 - static int nxp_nci_i2c_parse_devtree(struct i2c_client *client) 307 - { 308 - return -ENODEV; 309 - } 310 - 311 - #endif 312 299 313 300 static int nxp_nci_i2c_acpi_config(struct nxp_nci_i2c_phy *phy) 314 301 { 315 302 struct i2c_client *client = phy->i2c_dev; 316 - struct gpio_desc *gpiod_en, *gpiod_fw, *gpiod_irq; 303 + struct gpio_desc *gpiod_en, *gpiod_fw; 317 304 318 305 gpiod_en = devm_gpiod_get_index(&client->dev, NULL, 2, GPIOD_OUT_LOW); 319 306 gpiod_fw = devm_gpiod_get_index(&client->dev, NULL, 1, GPIOD_OUT_LOW); 320 - gpiod_irq = devm_gpiod_get_index(&client->dev, NULL, 0, GPIOD_IN); 321 307 322 - if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw) || IS_ERR(gpiod_irq)) { 308 + if (IS_ERR(gpiod_en) || IS_ERR(gpiod_fw)) { 323 309 nfc_err(&client->dev, "No GPIOs\n"); 324 - return -EINVAL; 325 - } 326 - 327 - client->irq = gpiod_to_irq(gpiod_irq); 328 - if (client->irq < 0) { 329 - nfc_err(&client->dev, "No IRQ\n"); 330 310 return -EINVAL; 331 311 } 332 312 333 313 phy->gpio_en = desc_to_gpio(gpiod_en); 334 314 phy->gpio_fw = desc_to_gpio(gpiod_fw); 335 - phy->gpio_irq = desc_to_gpio(gpiod_irq); 336 315 337 316 return 0; 338 317 } ··· 347 374 } else if (pdata) { 348 375 phy->gpio_en = pdata->gpio_en; 349 376 phy->gpio_fw = pdata->gpio_fw; 350 - client->irq = pdata->irq; 351 377 } else if (ACPI_HANDLE(&client->dev)) { 352 378 r = nxp_nci_i2c_acpi_config(phy); 353 379 if (r < 0)
+1 -45
drivers/nfc/pn544/i2c.c
··· 166 166 struct nfc_hci_dev *hdev; 167 167 168 168 unsigned int gpio_en; 169 - unsigned int gpio_irq; 170 169 unsigned int gpio_fw; 171 170 unsigned int en_polarity; 172 171 ··· 878 879 { 879 880 struct pn544_i2c_phy *phy = i2c_get_clientdata(client); 880 881 const struct acpi_device_id *id; 881 - struct gpio_desc *gpiod_en, *gpiod_irq, *gpiod_fw; 882 + struct gpio_desc *gpiod_en, *gpiod_fw; 882 883 struct device *dev; 883 - int ret; 884 884 885 885 if (!client) 886 886 return -EINVAL; ··· 912 914 913 915 phy->gpio_fw = desc_to_gpio(gpiod_fw); 914 916 915 - /* Get IRQ GPIO */ 916 - gpiod_irq = devm_gpiod_get_index(dev, PN544_GPIO_NAME_IRQ, 0, 917 - GPIOD_IN); 918 - if (IS_ERR(gpiod_irq)) { 919 - nfc_err(dev, "Unable to get IRQ GPIO\n"); 920 - return -ENODEV; 921 - } 922 - 923 - phy->gpio_irq = desc_to_gpio(gpiod_irq); 924 - 925 - /* Map the pin to an IRQ */ 926 - ret = gpiod_to_irq(gpiod_irq); 927 - if (ret < 0) { 928 - nfc_err(dev, "Fail pin IRQ mapping\n"); 929 - return ret; 930 - } 931 - 932 - nfc_info(dev, "GPIO resource, no:%d irq:%d\n", 933 - desc_to_gpio(gpiod_irq), ret); 934 - client->irq = ret; 935 - 936 917 return 0; 937 918 } 938 - 939 - #ifdef CONFIG_OF 940 919 941 920 static int pn544_hci_i2c_of_request_resources(struct i2c_client *client) 942 921 { ··· 971 996 goto err_gpio_fw; 972 997 } 973 998 974 - /* IRQ */ 975 - ret = irq_of_parse_and_map(pp, 0); 976 - if (ret < 0) { 977 - nfc_err(&client->dev, 978 - "Unable to get irq, error: %d\n", ret); 979 - goto err_gpio_fw; 980 - } 981 - client->irq = ret; 982 - 983 999 return 0; 984 1000 985 1001 err_gpio_fw: ··· 980 1014 err_dt: 981 1015 return ret; 982 1016 } 983 - 984 - #else 985 - 986 - static int pn544_hci_i2c_of_request_resources(struct i2c_client *client) 987 - { 988 - return -ENODEV; 989 - } 990 - 991 - #endif 992 1017 993 1018 static int pn544_hci_i2c_probe(struct i2c_client *client, 994 1019 const struct i2c_device_id *id) ··· 1033 1076 1034 1077 phy->gpio_en = pdata->get_gpio(NFC_GPIO_ENABLE); 1035 1078 phy->gpio_fw = pdata->get_gpio(NFC_GPIO_FW_RESET); 1036 - phy->gpio_irq = pdata->get_gpio(NFC_GPIO_IRQ); 1037 1079 /* Using ACPI */ 1038 1080 } else if (ACPI_HANDLE(&client->dev)) { 1039 1081 r = pn544_hci_i2c_acpi_request_resources(client);
+1 -1
drivers/nfc/s3fwrn5/core.c
··· 147 147 }; 148 148 149 149 int s3fwrn5_probe(struct nci_dev **ndev, void *phy_id, struct device *pdev, 150 - struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload) 150 + const struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload) 151 151 { 152 152 struct s3fwrn5_info *info; 153 153 int ret;
+1 -1
drivers/nfc/s3fwrn5/i2c.c
··· 125 125 return 0; 126 126 } 127 127 128 - static struct s3fwrn5_phy_ops i2c_phy_ops = { 128 + static const struct s3fwrn5_phy_ops i2c_phy_ops = { 129 129 .set_wake = s3fwrn5_i2c_set_wake, 130 130 .set_mode = s3fwrn5_i2c_set_mode, 131 131 .get_mode = s3fwrn5_i2c_get_mode,
+2 -2
drivers/nfc/s3fwrn5/s3fwrn5.h
··· 44 44 void *phy_id; 45 45 struct device *pdev; 46 46 47 - struct s3fwrn5_phy_ops *phy_ops; 47 + const struct s3fwrn5_phy_ops *phy_ops; 48 48 unsigned int max_payload; 49 49 50 50 struct s3fwrn5_fw_info fw_info; ··· 90 90 } 91 91 92 92 int s3fwrn5_probe(struct nci_dev **ndev, void *phy_id, struct device *pdev, 93 - struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload); 93 + const struct s3fwrn5_phy_ops *phy_ops, unsigned int max_payload); 94 94 void s3fwrn5_remove(struct nci_dev *ndev); 95 95 96 96 int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
+7 -11
drivers/nfc/st-nci/Kconfig
··· 1 1 config NFC_ST_NCI 2 - tristate "STMicroelectronics ST NCI NFC driver" 3 - depends on NFC_NCI 4 - default n 2 + tristate 5 3 ---help--- 6 4 STMicroelectronics NFC NCI chips core driver. It implements the chipset 7 5 NCI logic and hooks into the NFC kernel APIs. Physical layers will 8 6 register against it. 9 7 10 - To compile this driver as a module, choose m here. The module will 11 - be called st-nci. 12 - Say N if unsure. 13 - 14 8 config NFC_ST_NCI_I2C 15 - tristate "NFC ST NCI i2c support" 16 - depends on NFC_ST_NCI && I2C 9 + tristate "STMicroelectronics ST NCI NFC driver (I2C)" 10 + depends on NFC_NCI && I2C 11 + select NFC_ST_NCI 17 12 ---help--- 18 13 This module adds support for an I2C interface to the 19 14 STMicroelectronics NFC NCI chips familly. ··· 18 23 Say N if unsure. 19 24 20 25 config NFC_ST_NCI_SPI 21 - tristate "NFC ST NCI spi support" 22 - depends on NFC_ST_NCI && SPI 26 + tristate "STMicroelectronics ST NCI NFC driver (SPI)" 27 + depends on NFC_NCI && SPI 28 + select NFC_ST_NCI 23 29 ---help--- 24 30 This module adds support for an SPI interface to the 25 31 STMicroelectronics NFC NCI chips familly.
+63 -17
drivers/nfc/st-nci/i2c.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/i2c.h> 22 22 #include <linux/gpio.h> 23 + #include <linux/gpio/consumer.h> 23 24 #include <linux/of_irq.h> 24 25 #include <linux/of_gpio.h> 26 + #include <linux/acpi.h> 25 27 #include <linux/interrupt.h> 26 28 #include <linux/delay.h> 27 29 #include <linux/nfc.h> ··· 42 40 43 41 #define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c" 44 42 45 - static struct i2c_device_id st_nci_i2c_id_table[] = { 46 - {ST_NCI_DRIVER_NAME, 0}, 47 - {} 48 - }; 49 - MODULE_DEVICE_TABLE(i2c, st_nci_i2c_id_table); 43 + #define ST_NCI_GPIO_NAME_RESET "clf_reset" 50 44 51 45 struct st_nci_i2c_phy { 52 46 struct i2c_client *i2c_dev; ··· 208 210 .disable = st_nci_i2c_disable, 209 211 }; 210 212 211 - #ifdef CONFIG_OF 213 + static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) 214 + { 215 + struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); 216 + const struct acpi_device_id *id; 217 + struct gpio_desc *gpiod_reset; 218 + struct device *dev; 219 + 220 + if (!client) 221 + return -EINVAL; 222 + 223 + dev = &client->dev; 224 + 225 + /* Match the struct device against a given list of ACPI IDs */ 226 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 227 + if (!id) 228 + return -ENODEV; 229 + 230 + /* Get RESET GPIO from ACPI */ 231 + gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1, 232 + GPIOD_OUT_HIGH); 233 + if (IS_ERR(gpiod_reset)) { 234 + nfc_err(dev, "Unable to get RESET GPIO\n"); 235 + return -ENODEV; 236 + } 237 + 238 + phy->gpio_reset = desc_to_gpio(gpiod_reset); 239 + 240 + phy->irq_polarity = irq_get_trigger_type(client->irq); 241 + 242 + phy->se_status.is_ese_present = 243 + device_property_present(dev, "ese-present"); 244 + phy->se_status.is_uicc_present = 245 + device_property_present(dev, "uicc-present"); 246 + 247 + return 0; 248 + } 249 + 212 250 static int st_nci_i2c_of_request_resources(struct i2c_client *client) 213 251 { 214 252 struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); ··· 266 232 267 233 /* GPIO request and configuration */ 268 234 r = devm_gpio_request_one(&client->dev, gpio, 269 - GPIOF_OUT_INIT_HIGH, "clf_reset"); 235 + GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET); 270 236 if (r) { 271 237 nfc_err(&client->dev, "Failed to request reset pin\n"); 272 238 return r; ··· 282 248 283 249 return 0; 284 250 } 285 - #else 286 - static int st_nci_i2c_of_request_resources(struct i2c_client *client) 287 - { 288 - return -ENODEV; 289 - } 290 - #endif 291 251 292 252 static int st_nci_i2c_request_resources(struct i2c_client *client) 293 253 { ··· 300 272 phy->irq_polarity = pdata->irq_polarity; 301 273 302 274 r = devm_gpio_request_one(&client->dev, 303 - phy->gpio_reset, GPIOF_OUT_INIT_HIGH, "clf_reset"); 275 + phy->gpio_reset, GPIOF_OUT_INIT_HIGH, 276 + ST_NCI_GPIO_NAME_RESET); 304 277 if (r) { 305 278 pr_err("%s : reset gpio_request failed\n", __FILE__); 306 279 return r; ··· 351 322 "Cannot get platform resources\n"); 352 323 return r; 353 324 } 325 + } else if (ACPI_HANDLE(&client->dev)) { 326 + r = st_nci_i2c_acpi_request_resources(client); 327 + if (r) { 328 + nfc_err(&client->dev, "Cannot get ACPI data\n"); 329 + return r; 330 + } 354 331 } else { 355 332 nfc_err(&client->dev, 356 333 "st_nci platform resources not available\n"); ··· 393 358 return 0; 394 359 } 395 360 396 - #ifdef CONFIG_OF 361 + static struct i2c_device_id st_nci_i2c_id_table[] = { 362 + {ST_NCI_DRIVER_NAME, 0}, 363 + {} 364 + }; 365 + MODULE_DEVICE_TABLE(i2c, st_nci_i2c_id_table); 366 + 367 + static const struct acpi_device_id st_nci_i2c_acpi_match[] = { 368 + {"SMO2101"}, 369 + {"SMO2102"}, 370 + {} 371 + }; 372 + MODULE_DEVICE_TABLE(acpi, st_nci_i2c_acpi_match); 373 + 397 374 static const struct of_device_id of_st_nci_i2c_match[] = { 398 375 { .compatible = "st,st21nfcb-i2c", }, 399 376 { .compatible = "st,st21nfcb_i2c", }, ··· 413 366 {} 414 367 }; 415 368 MODULE_DEVICE_TABLE(of, of_st_nci_i2c_match); 416 - #endif 417 369 418 370 static struct i2c_driver st_nci_i2c_driver = { 419 371 .driver = { 420 372 .owner = THIS_MODULE, 421 373 .name = ST_NCI_I2C_DRIVER_NAME, 422 374 .of_match_table = of_match_ptr(of_st_nci_i2c_match), 375 + .acpi_match_table = ACPI_PTR(st_nci_i2c_acpi_match), 423 376 }, 424 377 .probe = st_nci_i2c_probe, 425 378 .id_table = st_nci_i2c_id_table, 426 379 .remove = st_nci_i2c_remove, 427 380 }; 428 - 429 381 module_i2c_driver(st_nci_i2c_driver); 430 382 431 383 MODULE_LICENSE("GPL");
-1
drivers/nfc/st-nci/ndlc.c
··· 20 20 #include <net/nfc/nci_core.h> 21 21 22 22 #include "st-nci.h" 23 - #include "ndlc.h" 24 23 25 24 #define NDLC_TIMER_T1 100 26 25 #define NDLC_TIMER_T1_WAIT 400
+1 -2
drivers/nfc/st-nci/se.c
··· 331 331 332 332 switch (event) { 333 333 case ST_NCI_EVT_CONNECTIVITY: 334 - 334 + r = nfc_se_connectivity(ndev->nfc_dev, host); 335 335 break; 336 336 case ST_NCI_EVT_TRANSACTION: 337 337 /* According to specification etsi 102 622 ··· 391 391 } 392 392 } 393 393 EXPORT_SYMBOL_GPL(st_nci_hci_event_received); 394 - 395 394 396 395 void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd, 397 396 struct sk_buff *skb)
+63 -18
drivers/nfc/st-nci/spi.c
··· 20 20 #include <linux/module.h> 21 21 #include <linux/spi/spi.h> 22 22 #include <linux/gpio.h> 23 + #include <linux/gpio/consumer.h> 23 24 #include <linux/of_irq.h> 24 25 #include <linux/of_gpio.h> 26 + #include <linux/acpi.h> 25 27 #include <linux/interrupt.h> 26 28 #include <linux/delay.h> 27 29 #include <linux/nfc.h> ··· 36 34 37 35 /* ndlc header */ 38 36 #define ST_NCI_FRAME_HEADROOM 1 39 - #define ST_NCI_FRAME_TAILROOM 0 37 + #define ST_NCI_FRAME_TAILROOM 0 40 38 41 39 #define ST_NCI_SPI_MIN_SIZE 4 /* PCB(1) + NCI Packet header(3) */ 42 40 #define ST_NCI_SPI_MAX_SIZE 250 /* req 4.2.1 */ 43 41 44 42 #define ST_NCI_SPI_DRIVER_NAME "st_nci_spi" 45 43 46 - static struct spi_device_id st_nci_spi_id_table[] = { 47 - {ST_NCI_SPI_DRIVER_NAME, 0}, 48 - {} 49 - }; 50 - MODULE_DEVICE_TABLE(spi, st_nci_spi_id_table); 44 + #define ST_NCI_GPIO_NAME_RESET "clf_reset" 51 45 52 46 struct st_nci_spi_phy { 53 47 struct spi_device *spi_dev; ··· 223 225 .disable = st_nci_spi_disable, 224 226 }; 225 227 226 - #ifdef CONFIG_OF 228 + static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) 229 + { 230 + struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); 231 + const struct acpi_device_id *id; 232 + struct gpio_desc *gpiod_reset; 233 + struct device *dev; 234 + 235 + if (!spi_dev) 236 + return -EINVAL; 237 + 238 + dev = &spi_dev->dev; 239 + 240 + /* Match the struct device against a given list of ACPI IDs */ 241 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 242 + if (!id) 243 + return -ENODEV; 244 + 245 + /* Get RESET GPIO from ACPI */ 246 + gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1, 247 + GPIOD_OUT_HIGH); 248 + if (IS_ERR(gpiod_reset)) { 249 + nfc_err(dev, "Unable to get RESET GPIO\n"); 250 + return -ENODEV; 251 + } 252 + 253 + phy->gpio_reset = desc_to_gpio(gpiod_reset); 254 + 255 + phy->irq_polarity = irq_get_trigger_type(spi_dev->irq); 256 + 257 + phy->se_status.is_ese_present = 258 + device_property_present(dev, "ese-present"); 259 + phy->se_status.is_uicc_present = 260 + device_property_present(dev, "uicc-present"); 261 + 262 + return 0; 263 + } 264 + 227 265 static int st_nci_spi_of_request_resources(struct spi_device *dev) 228 266 { 229 267 struct st_nci_spi_phy *phy = spi_get_drvdata(dev); ··· 281 247 282 248 /* GPIO request and configuration */ 283 249 r = devm_gpio_request_one(&dev->dev, gpio, 284 - GPIOF_OUT_INIT_HIGH, "clf_reset"); 250 + GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET); 285 251 if (r) { 286 252 nfc_err(&dev->dev, "Failed to request reset pin\n"); 287 253 return r; ··· 297 263 298 264 return 0; 299 265 } 300 - #else 301 - static int st_nci_spi_of_request_resources(struct spi_device *dev) 302 - { 303 - return -ENODEV; 304 - } 305 - #endif 306 266 307 267 static int st_nci_spi_request_resources(struct spi_device *dev) 308 268 { ··· 315 287 phy->irq_polarity = pdata->irq_polarity; 316 288 317 289 r = devm_gpio_request_one(&dev->dev, 318 - phy->gpio_reset, GPIOF_OUT_INIT_HIGH, "clf_reset"); 290 + phy->gpio_reset, GPIOF_OUT_INIT_HIGH, 291 + ST_NCI_GPIO_NAME_RESET); 319 292 if (r) { 320 293 pr_err("%s : reset gpio_request failed\n", __FILE__); 321 294 return r; ··· 367 338 "Cannot get platform resources\n"); 368 339 return r; 369 340 } 341 + } else if (ACPI_HANDLE(&dev->dev)) { 342 + r = st_nci_spi_acpi_request_resources(dev); 343 + if (r) { 344 + nfc_err(&dev->dev, "Cannot get ACPI data\n"); 345 + return r; 346 + } 370 347 } else { 371 348 nfc_err(&dev->dev, 372 349 "st_nci platform resources not available\n"); ··· 409 374 return 0; 410 375 } 411 376 412 - #ifdef CONFIG_OF 377 + static struct spi_device_id st_nci_spi_id_table[] = { 378 + {ST_NCI_SPI_DRIVER_NAME, 0}, 379 + {} 380 + }; 381 + MODULE_DEVICE_TABLE(spi, st_nci_spi_id_table); 382 + 383 + static const struct acpi_device_id st_nci_spi_acpi_match[] = { 384 + {"SMO2101", 0}, 385 + {} 386 + }; 387 + MODULE_DEVICE_TABLE(acpi, st_nci_spi_acpi_match); 388 + 413 389 static const struct of_device_id of_st_nci_spi_match[] = { 414 390 { .compatible = "st,st21nfcb-spi", }, 415 391 {} 416 392 }; 417 393 MODULE_DEVICE_TABLE(of, of_st_nci_spi_match); 418 - #endif 419 394 420 395 static struct spi_driver st_nci_spi_driver = { 421 396 .driver = { 422 397 .name = ST_NCI_SPI_DRIVER_NAME, 423 398 .of_match_table = of_match_ptr(of_st_nci_spi_match), 399 + .acpi_match_table = ACPI_PTR(st_nci_spi_acpi_match), 424 400 }, 425 401 .probe = st_nci_spi_probe, 426 402 .id_table = st_nci_spi_id_table, 427 403 .remove = st_nci_spi_remove, 428 404 }; 429 - 430 405 module_spi_driver(st_nci_spi_driver); 431 406 432 407 MODULE_LICENSE("GPL");
+4 -9
drivers/nfc/st21nfca/Kconfig
··· 1 1 config NFC_ST21NFCA 2 - tristate "STMicroelectronics ST21NFCA NFC driver" 3 - depends on NFC_HCI 2 + tristate 4 3 select CRC_CCITT 5 - default n 6 4 ---help--- 7 5 STMicroelectronics ST21NFCA core driver. It implements the chipset 8 6 HCI logic and hooks into the NFC kernel APIs. Physical layers will 9 7 register against it. 10 8 11 - To compile this driver as a module, choose m here. The module will 12 - be called st21nfca. 13 - Say N if unsure. 14 - 15 9 config NFC_ST21NFCA_I2C 16 - tristate "NFC ST21NFCA i2c support" 17 - depends on NFC_ST21NFCA && I2C && NFC_SHDLC 10 + tristate "STMicroelectronics ST21NFCA NFC driver (I2C)" 11 + depends on NFC_HCI && I2C && NFC_SHDLC 12 + select NFC_ST21NFCA 18 13 ---help--- 19 14 This module adds support for the STMicroelectronics st21nfca i2c interface. 20 15 Select this if your platform is using the i2c bus.
+60 -20
drivers/nfc/st21nfca/i2c.c
··· 21 21 #include <linux/module.h> 22 22 #include <linux/i2c.h> 23 23 #include <linux/gpio.h> 24 + #include <linux/gpio/consumer.h> 24 25 #include <linux/of_irq.h> 25 26 #include <linux/of_gpio.h> 27 + #include <linux/acpi.h> 26 28 #include <linux/miscdevice.h> 27 29 #include <linux/interrupt.h> 28 30 #include <linux/delay.h> ··· 62 60 63 61 #define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c" 64 62 65 - static struct i2c_device_id st21nfca_hci_i2c_id_table[] = { 66 - {ST21NFCA_HCI_DRIVER_NAME, 0}, 67 - {} 68 - }; 69 - 70 - MODULE_DEVICE_TABLE(i2c, st21nfca_hci_i2c_id_table); 63 + #define ST21NFCA_GPIO_NAME_EN "clf_enable" 71 64 72 65 struct st21nfca_i2c_phy { 73 66 struct i2c_client *i2c_dev; ··· 164 167 { 165 168 struct st21nfca_i2c_phy *phy = phy_id; 166 169 167 - pr_info("\n"); 168 170 gpio_set_value(phy->gpio_ena, 0); 169 171 170 172 phy->powered = 0; ··· 205 209 u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE * 2]; 206 210 207 211 I2C_DUMP_SKB("st21nfca_hci_i2c_write", skb); 208 - 209 212 210 213 if (phy->hard_fault != 0) 211 214 return phy->hard_fault; ··· 504 509 .disable = st21nfca_hci_i2c_disable, 505 510 }; 506 511 507 - #ifdef CONFIG_OF 512 + static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client) 513 + { 514 + struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); 515 + const struct acpi_device_id *id; 516 + struct gpio_desc *gpiod_ena; 517 + struct device *dev; 518 + 519 + if (!client) 520 + return -EINVAL; 521 + 522 + dev = &client->dev; 523 + 524 + /* Match the struct device against a given list of ACPI IDs */ 525 + id = acpi_match_device(dev->driver->acpi_match_table, dev); 526 + if (!id) 527 + return -ENODEV; 528 + 529 + /* Get EN GPIO from ACPI */ 530 + gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 1, 531 + GPIOD_OUT_LOW); 532 + if (!IS_ERR(gpiod_ena)) 533 + phy->gpio_ena = desc_to_gpio(gpiod_ena); 534 + 535 + phy->gpio_ena = desc_to_gpio(gpiod_ena); 536 + 537 + phy->irq_polarity = irq_get_trigger_type(client->irq); 538 + 539 + phy->se_status.is_ese_present = 540 + device_property_present(dev, "ese-present"); 541 + phy->se_status.is_uicc_present = 542 + device_property_present(dev, "uicc-present"); 543 + 544 + return 0; 545 + } 546 + 508 547 static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) 509 548 { 510 549 struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); ··· 559 530 560 531 /* GPIO request and configuration */ 561 532 r = devm_gpio_request_one(&client->dev, gpio, GPIOF_OUT_INIT_HIGH, 562 - "clf_enable"); 533 + ST21NFCA_GPIO_NAME_EN); 563 534 if (r) { 564 535 nfc_err(&client->dev, "Failed to request enable pin\n"); 565 536 return r; ··· 576 547 577 548 return 0; 578 549 } 579 - #else 580 - static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) 581 - { 582 - return -ENODEV; 583 - } 584 - #endif 585 550 586 551 static int st21nfca_hci_i2c_request_resources(struct i2c_client *client) 587 552 { ··· 595 572 596 573 if (phy->gpio_ena > 0) { 597 574 r = devm_gpio_request_one(&client->dev, phy->gpio_ena, 598 - GPIOF_OUT_INIT_HIGH, "clf_enable"); 575 + GPIOF_OUT_INIT_HIGH, 576 + ST21NFCA_GPIO_NAME_EN); 599 577 if (r) { 600 578 pr_err("%s : ena gpio_request failed\n", __FILE__); 601 579 return r; ··· 652 628 nfc_err(&client->dev, "Cannot get platform resources\n"); 653 629 return r; 654 630 } 631 + } else if (ACPI_HANDLE(&client->dev)) { 632 + r = st21nfca_hci_i2c_acpi_request_resources(client); 633 + if (r) { 634 + nfc_err(&client->dev, "Cannot get ACPI data\n"); 635 + return r; 636 + } 655 637 } else { 656 638 nfc_err(&client->dev, "st21nfca platform resources not available\n"); 657 639 return -ENODEV; ··· 700 670 return 0; 701 671 } 702 672 703 - #ifdef CONFIG_OF 673 + static struct i2c_device_id st21nfca_hci_i2c_id_table[] = { 674 + {ST21NFCA_HCI_DRIVER_NAME, 0}, 675 + {} 676 + }; 677 + MODULE_DEVICE_TABLE(i2c, st21nfca_hci_i2c_id_table); 678 + 679 + static const struct acpi_device_id st21nfca_hci_i2c_acpi_match[] = { 680 + {"SMO2100", 0}, 681 + {} 682 + }; 683 + MODULE_DEVICE_TABLE(acpi, st21nfca_hci_i2c_acpi_match); 684 + 704 685 static const struct of_device_id of_st21nfca_i2c_match[] = { 705 686 { .compatible = "st,st21nfca-i2c", }, 706 687 { .compatible = "st,st21nfca_i2c", }, 707 688 {} 708 689 }; 709 690 MODULE_DEVICE_TABLE(of, of_st21nfca_i2c_match); 710 - #endif 711 691 712 692 static struct i2c_driver st21nfca_hci_i2c_driver = { 713 693 .driver = { 714 694 .owner = THIS_MODULE, 715 695 .name = ST21NFCA_HCI_I2C_DRIVER_NAME, 716 696 .of_match_table = of_match_ptr(of_st21nfca_i2c_match), 697 + .acpi_match_table = ACPI_PTR(st21nfca_hci_i2c_acpi_match), 717 698 }, 718 699 .probe = st21nfca_hci_i2c_probe, 719 700 .id_table = st21nfca_hci_i2c_id_table, 720 701 .remove = st21nfca_hci_i2c_remove, 721 702 }; 722 - 723 703 module_i2c_driver(st21nfca_hci_i2c_driver); 724 704 725 705 MODULE_LICENSE("GPL");
+3 -2
drivers/nfc/st21nfca/se.c
··· 312 312 313 313 switch (event) { 314 314 case ST21NFCA_EVT_CONNECTIVITY: 315 - break; 315 + r = nfc_se_connectivity(hdev->ndev, host); 316 + break; 316 317 case ST21NFCA_EVT_TRANSACTION: 317 318 /* 318 319 * According to specification etsi 102 622 ··· 343 342 transaction->aid_len + 4, transaction->params_len); 344 343 345 344 r = nfc_se_transaction(hdev->ndev, host, transaction); 346 - break; 345 + break; 347 346 default: 348 347 nfc_err(&hdev->ndev->dev, "Unexpected event on connectivity gate\n"); 349 348 return 1;
+10
drivers/nfc/st95hf/Kconfig
··· 1 + config NFC_ST95HF 2 + tristate "ST95HF NFC Transceiver driver" 3 + depends on SPI && NFC_DIGITAL 4 + help 5 + This enables the ST NFC driver for ST95HF NFC transceiver. 6 + This makes use of SPI framework to communicate with transceiver 7 + and registered with NFC digital core to support Linux NFC framework. 8 + 9 + Say Y here to compile support for ST NFC transceiver ST95HF 10 + linux driver into the kernel or say M to compile it as module.
+6
drivers/nfc/st95hf/Makefile
··· 1 + # 2 + # Makefile for STMicroelectronics NFC transceiver ST95HF 3 + # 4 + 5 + obj-$(CONFIG_NFC_ST95HF) += st95hf.o 6 + st95hf-objs := spi.o core.o
+1273
drivers/nfc/st95hf/core.c
··· 1 + /* 2 + * -------------------------------------------------------------------- 3 + * Driver for ST NFC Transceiver ST95HF 4 + * -------------------------------------------------------------------- 5 + * Copyright (C) 2015 STMicroelectronics Pvt. Ltd. All rights reserved. 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms and conditions of the GNU General Public License, 9 + * version 2, as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include <linux/err.h> 21 + #include <linux/gpio.h> 22 + #include <linux/init.h> 23 + #include <linux/interrupt.h> 24 + #include <linux/irq.h> 25 + #include <linux/module.h> 26 + #include <linux/netdevice.h> 27 + #include <linux/nfc.h> 28 + #include <linux/of_gpio.h> 29 + #include <linux/of.h> 30 + #include <linux/of_irq.h> 31 + #include <linux/property.h> 32 + #include <linux/regulator/consumer.h> 33 + #include <linux/wait.h> 34 + #include <net/nfc/digital.h> 35 + #include <net/nfc/nfc.h> 36 + 37 + #include "spi.h" 38 + 39 + /* supported protocols */ 40 + #define ST95HF_SUPPORTED_PROT (NFC_PROTO_ISO14443_MASK | \ 41 + NFC_PROTO_ISO14443_B_MASK | \ 42 + NFC_PROTO_ISO15693_MASK) 43 + /* driver capabilities */ 44 + #define ST95HF_CAPABILITIES NFC_DIGITAL_DRV_CAPS_IN_CRC 45 + 46 + /* Command Send Interface */ 47 + /* ST95HF_COMMAND_SEND CMD Ids */ 48 + #define ECHO_CMD 0x55 49 + #define WRITE_REGISTER_CMD 0x9 50 + #define PROTOCOL_SELECT_CMD 0x2 51 + #define SEND_RECEIVE_CMD 0x4 52 + 53 + /* Select protocol codes */ 54 + #define ISO15693_PROTOCOL_CODE 0x1 55 + #define ISO14443A_PROTOCOL_CODE 0x2 56 + #define ISO14443B_PROTOCOL_CODE 0x3 57 + 58 + /* 59 + * head room len is 3 60 + * 1 byte for control byte 61 + * 1 byte for cmd 62 + * 1 byte for size 63 + */ 64 + #define ST95HF_HEADROOM_LEN 3 65 + 66 + /* 67 + * tailroom is 1 for ISO14443A 68 + * and 0 for ISO14443B/ISO15693, 69 + * hence the max value 1 should be 70 + * taken. 71 + */ 72 + #define ST95HF_TAILROOM_LEN 1 73 + 74 + /* Command Response interface */ 75 + #define MAX_RESPONSE_BUFFER_SIZE 280 76 + #define ECHORESPONSE 0x55 77 + #define ST95HF_ERR_MASK 0xF 78 + #define ST95HF_TIMEOUT_ERROR 0x87 79 + #define ST95HF_NFCA_CRC_ERR_MASK 0x20 80 + #define ST95HF_NFCB_CRC_ERR_MASK 0x01 81 + 82 + /* ST95HF transmission flag values */ 83 + #define TRFLAG_NFCA_SHORT_FRAME 0x07 84 + #define TRFLAG_NFCA_STD_FRAME 0x08 85 + #define TRFLAG_NFCA_STD_FRAME_CRC 0x28 86 + 87 + /* Misc defs */ 88 + #define HIGH 1 89 + #define LOW 0 90 + #define ISO14443A_RATS_REQ 0xE0 91 + #define RATS_TB1_PRESENT_MASK 0x20 92 + #define RATS_TA1_PRESENT_MASK 0x10 93 + #define TB1_FWI_MASK 0xF0 94 + #define WTX_REQ_FROM_TAG 0xF2 95 + 96 + #define MAX_CMD_LEN 0x7 97 + 98 + #define MAX_CMD_PARAMS 4 99 + struct cmd { 100 + int cmd_len; 101 + unsigned char cmd_id; 102 + unsigned char no_cmd_params; 103 + unsigned char cmd_params[MAX_CMD_PARAMS]; 104 + enum req_type req; 105 + }; 106 + 107 + struct param_list { 108 + int param_offset; 109 + int new_param_val; 110 + }; 111 + 112 + /* 113 + * List of top-level cmds to be used internally by the driver. 114 + * All these commands are build on top of ST95HF basic commands 115 + * such as SEND_RECEIVE_CMD, PROTOCOL_SELECT_CMD, etc. 116 + * These top level cmds are used internally while implementing various ops of 117 + * digital layer/driver probe or extending the digital framework layer for 118 + * features that are not yet implemented there, for example, WTX cmd handling. 119 + */ 120 + enum st95hf_cmd_list { 121 + CMD_ECHO, 122 + CMD_ISO14443A_CONFIG, 123 + CMD_ISO14443A_DEMOGAIN, 124 + CMD_ISO14443B_DEMOGAIN, 125 + CMD_ISO14443A_PROTOCOL_SELECT, 126 + CMD_ISO14443B_PROTOCOL_SELECT, 127 + CMD_WTX_RESPONSE, 128 + CMD_FIELD_OFF, 129 + CMD_ISO15693_PROTOCOL_SELECT, 130 + }; 131 + 132 + static const struct cmd cmd_array[] = { 133 + [CMD_ECHO] = { 134 + .cmd_len = 0x2, 135 + .cmd_id = ECHO_CMD, 136 + .no_cmd_params = 0, 137 + .req = SYNC, 138 + }, 139 + [CMD_ISO14443A_CONFIG] = { 140 + .cmd_len = 0x7, 141 + .cmd_id = WRITE_REGISTER_CMD, 142 + .no_cmd_params = 0x4, 143 + .cmd_params = {0x3A, 0x00, 0x5A, 0x04}, 144 + .req = SYNC, 145 + }, 146 + [CMD_ISO14443A_DEMOGAIN] = { 147 + .cmd_len = 0x7, 148 + .cmd_id = WRITE_REGISTER_CMD, 149 + .no_cmd_params = 0x4, 150 + .cmd_params = {0x68, 0x01, 0x01, 0xDF}, 151 + .req = SYNC, 152 + }, 153 + [CMD_ISO14443B_DEMOGAIN] = { 154 + .cmd_len = 0x7, 155 + .cmd_id = WRITE_REGISTER_CMD, 156 + .no_cmd_params = 0x4, 157 + .cmd_params = {0x68, 0x01, 0x01, 0x51}, 158 + .req = SYNC, 159 + }, 160 + [CMD_ISO14443A_PROTOCOL_SELECT] = { 161 + .cmd_len = 0x7, 162 + .cmd_id = PROTOCOL_SELECT_CMD, 163 + .no_cmd_params = 0x4, 164 + .cmd_params = {ISO14443A_PROTOCOL_CODE, 0x00, 0x01, 0xA0}, 165 + .req = SYNC, 166 + }, 167 + [CMD_ISO14443B_PROTOCOL_SELECT] = { 168 + .cmd_len = 0x7, 169 + .cmd_id = PROTOCOL_SELECT_CMD, 170 + .no_cmd_params = 0x4, 171 + .cmd_params = {ISO14443B_PROTOCOL_CODE, 0x01, 0x03, 0xFF}, 172 + .req = SYNC, 173 + }, 174 + [CMD_WTX_RESPONSE] = { 175 + .cmd_len = 0x6, 176 + .cmd_id = SEND_RECEIVE_CMD, 177 + .no_cmd_params = 0x3, 178 + .cmd_params = {0xF2, 0x00, TRFLAG_NFCA_STD_FRAME_CRC}, 179 + .req = ASYNC, 180 + }, 181 + [CMD_FIELD_OFF] = { 182 + .cmd_len = 0x5, 183 + .cmd_id = PROTOCOL_SELECT_CMD, 184 + .no_cmd_params = 0x2, 185 + .cmd_params = {0x0, 0x0}, 186 + .req = SYNC, 187 + }, 188 + [CMD_ISO15693_PROTOCOL_SELECT] = { 189 + .cmd_len = 0x5, 190 + .cmd_id = PROTOCOL_SELECT_CMD, 191 + .no_cmd_params = 0x2, 192 + .cmd_params = {ISO15693_PROTOCOL_CODE, 0x0D}, 193 + .req = SYNC, 194 + }, 195 + }; 196 + 197 + /* st95_digital_cmd_complete_arg stores client context */ 198 + struct st95_digital_cmd_complete_arg { 199 + struct sk_buff *skb_resp; 200 + nfc_digital_cmd_complete_t complete_cb; 201 + void *cb_usrarg; 202 + bool rats; 203 + }; 204 + 205 + /* 206 + * structure containing ST95HF driver specific data. 207 + * @spicontext: structure containing information required 208 + * for spi communication between st95hf and host. 209 + * @ddev: nfc digital device object. 210 + * @nfcdev: nfc device object. 211 + * @enable_gpio: gpio used to enable st95hf transceiver. 212 + * @complete_cb_arg: structure to store various context information 213 + * that is passed from nfc requesting thread to the threaded ISR. 214 + * @st95hf_supply: regulator "consumer" for NFC device. 215 + * @sendrcv_trflag: last byte of frame send by sendrecv command 216 + * of st95hf. This byte contains transmission flag info. 217 + * @exchange_lock: semaphore used for signaling the st95hf_remove 218 + * function that the last outstanding async nfc request is finished. 219 + * @rm_lock: mutex for ensuring safe access of nfc digital object 220 + * from threaded ISR. Usage of this mutex avoids any race between 221 + * deletion of the object from st95hf_remove() and its access from 222 + * the threaded ISR. 223 + * @nfcdev_free: flag to have the state of nfc device object. 224 + * [alive | died] 225 + * @current_protocol: current nfc protocol. 226 + * @current_rf_tech: current rf technology. 227 + * @fwi: frame waiting index, received in reply of RATS according to 228 + * digital protocol. 229 + */ 230 + struct st95hf_context { 231 + struct st95hf_spi_context spicontext; 232 + struct nfc_digital_dev *ddev; 233 + struct nfc_dev *nfcdev; 234 + unsigned int enable_gpio; 235 + struct st95_digital_cmd_complete_arg complete_cb_arg; 236 + struct regulator *st95hf_supply; 237 + unsigned char sendrcv_trflag; 238 + struct semaphore exchange_lock; 239 + struct mutex rm_lock; 240 + bool nfcdev_free; 241 + u8 current_protocol; 242 + u8 current_rf_tech; 243 + int fwi; 244 + }; 245 + 246 + /* 247 + * st95hf_send_recv_cmd() is for sending commands to ST95HF 248 + * that are described in the cmd_array[]. It can optionally 249 + * receive the response if the cmd request is of type 250 + * SYNC. For that to happen caller must pass true to recv_res. 251 + * For ASYNC request, recv_res is ignored and the 252 + * function will never try to receive the response on behalf 253 + * of the caller. 254 + */ 255 + static int st95hf_send_recv_cmd(struct st95hf_context *st95context, 256 + enum st95hf_cmd_list cmd, 257 + int no_modif, 258 + struct param_list *list_array, 259 + bool recv_res) 260 + { 261 + unsigned char spi_cmd_buffer[MAX_CMD_LEN]; 262 + int i, ret; 263 + struct device *dev = &st95context->spicontext.spidev->dev; 264 + 265 + if (cmd_array[cmd].cmd_len > MAX_CMD_LEN) 266 + return -EINVAL; 267 + if (cmd_array[cmd].no_cmd_params < no_modif) 268 + return -EINVAL; 269 + if (no_modif && !list_array) 270 + return -EINVAL; 271 + 272 + spi_cmd_buffer[0] = ST95HF_COMMAND_SEND; 273 + spi_cmd_buffer[1] = cmd_array[cmd].cmd_id; 274 + spi_cmd_buffer[2] = cmd_array[cmd].no_cmd_params; 275 + 276 + memcpy(&spi_cmd_buffer[3], cmd_array[cmd].cmd_params, 277 + spi_cmd_buffer[2]); 278 + 279 + for (i = 0; i < no_modif; i++) { 280 + if (list_array[i].param_offset >= cmd_array[cmd].no_cmd_params) 281 + return -EINVAL; 282 + spi_cmd_buffer[3 + list_array[i].param_offset] = 283 + list_array[i].new_param_val; 284 + } 285 + 286 + ret = st95hf_spi_send(&st95context->spicontext, 287 + spi_cmd_buffer, 288 + cmd_array[cmd].cmd_len, 289 + cmd_array[cmd].req); 290 + if (ret) { 291 + dev_err(dev, "st95hf_spi_send failed with error %d\n", ret); 292 + return ret; 293 + } 294 + 295 + if (cmd_array[cmd].req == SYNC && recv_res) { 296 + unsigned char st95hf_response_arr[2]; 297 + 298 + ret = st95hf_spi_recv_response(&st95context->spicontext, 299 + st95hf_response_arr); 300 + if (ret < 0) { 301 + dev_err(dev, "spi error from st95hf_spi_recv_response(), err = 0x%x\n", 302 + ret); 303 + return ret; 304 + } 305 + 306 + if (st95hf_response_arr[0]) { 307 + dev_err(dev, "st95hf error from st95hf_spi_recv_response(), err = 0x%x\n", 308 + st95hf_response_arr[0]); 309 + return -EIO; 310 + } 311 + } 312 + 313 + return 0; 314 + } 315 + 316 + static int st95hf_echo_command(struct st95hf_context *st95context) 317 + { 318 + int result = 0; 319 + unsigned char echo_response; 320 + 321 + result = st95hf_send_recv_cmd(st95context, CMD_ECHO, 0, NULL, false); 322 + if (result) 323 + return result; 324 + 325 + /* If control reached here, response can be taken */ 326 + result = st95hf_spi_recv_echo_res(&st95context->spicontext, 327 + &echo_response); 328 + if (result) { 329 + dev_err(&st95context->spicontext.spidev->dev, 330 + "err: echo response receieve error = 0x%x\n", result); 331 + return result; 332 + } 333 + 334 + if (echo_response == ECHORESPONSE) 335 + return 0; 336 + 337 + dev_err(&st95context->spicontext.spidev->dev, "err: echo res is 0x%x\n", 338 + echo_response); 339 + 340 + return -EIO; 341 + } 342 + 343 + static int secondary_configuration_type4a(struct st95hf_context *stcontext) 344 + { 345 + int result = 0; 346 + struct device *dev = &stcontext->nfcdev->dev; 347 + 348 + /* 14443A config setting after select protocol */ 349 + result = st95hf_send_recv_cmd(stcontext, 350 + CMD_ISO14443A_CONFIG, 351 + 0, 352 + NULL, 353 + true); 354 + if (result) { 355 + dev_err(dev, "type a config cmd, err = 0x%x\n", result); 356 + return result; 357 + } 358 + 359 + /* 14443A demo gain setting */ 360 + result = st95hf_send_recv_cmd(stcontext, 361 + CMD_ISO14443A_DEMOGAIN, 362 + 0, 363 + NULL, 364 + true); 365 + if (result) 366 + dev_err(dev, "type a demogain cmd, err = 0x%x\n", result); 367 + 368 + return result; 369 + } 370 + 371 + static int secondary_configuration_type4b(struct st95hf_context *stcontext) 372 + { 373 + int result = 0; 374 + struct device *dev = &stcontext->nfcdev->dev; 375 + 376 + result = st95hf_send_recv_cmd(stcontext, 377 + CMD_ISO14443B_DEMOGAIN, 378 + 0, 379 + NULL, 380 + true); 381 + if (result) 382 + dev_err(dev, "type b demogain cmd, err = 0x%x\n", result); 383 + 384 + return result; 385 + } 386 + 387 + static int st95hf_select_protocol(struct st95hf_context *stcontext, int type) 388 + { 389 + int result = 0; 390 + struct device *dev; 391 + 392 + dev = &stcontext->nfcdev->dev; 393 + 394 + switch (type) { 395 + case NFC_DIGITAL_RF_TECH_106A: 396 + stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_106A; 397 + result = st95hf_send_recv_cmd(stcontext, 398 + CMD_ISO14443A_PROTOCOL_SELECT, 399 + 0, 400 + NULL, 401 + true); 402 + if (result) { 403 + dev_err(dev, "protocol sel, err = 0x%x\n", 404 + result); 405 + return result; 406 + } 407 + 408 + /* secondary config. for 14443Type 4A after protocol select */ 409 + result = secondary_configuration_type4a(stcontext); 410 + if (result) { 411 + dev_err(dev, "type a secondary config, err = 0x%x\n", 412 + result); 413 + return result; 414 + } 415 + break; 416 + case NFC_DIGITAL_RF_TECH_106B: 417 + stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_106B; 418 + result = st95hf_send_recv_cmd(stcontext, 419 + CMD_ISO14443B_PROTOCOL_SELECT, 420 + 0, 421 + NULL, 422 + true); 423 + if (result) { 424 + dev_err(dev, "protocol sel send, err = 0x%x\n", 425 + result); 426 + return result; 427 + } 428 + 429 + /* 430 + * delay of 5-6 ms is required after select protocol 431 + * command in case of ISO14443 Type B 432 + */ 433 + usleep_range(50000, 60000); 434 + 435 + /* secondary config. for 14443Type 4B after protocol select */ 436 + result = secondary_configuration_type4b(stcontext); 437 + if (result) { 438 + dev_err(dev, "type b secondary config, err = 0x%x\n", 439 + result); 440 + return result; 441 + } 442 + break; 443 + case NFC_DIGITAL_RF_TECH_ISO15693: 444 + stcontext->current_rf_tech = NFC_DIGITAL_RF_TECH_ISO15693; 445 + result = st95hf_send_recv_cmd(stcontext, 446 + CMD_ISO15693_PROTOCOL_SELECT, 447 + 0, 448 + NULL, 449 + true); 450 + if (result) { 451 + dev_err(dev, "protocol sel send, err = 0x%x\n", 452 + result); 453 + return result; 454 + } 455 + break; 456 + default: 457 + return -EINVAL; 458 + } 459 + 460 + return 0; 461 + } 462 + 463 + static void st95hf_send_st95enable_negativepulse(struct st95hf_context *st95con) 464 + { 465 + /* First make irq_in pin high */ 466 + gpio_set_value(st95con->enable_gpio, HIGH); 467 + 468 + /* wait for 1 milisecond */ 469 + usleep_range(1000, 2000); 470 + 471 + /* Make irq_in pin low */ 472 + gpio_set_value(st95con->enable_gpio, LOW); 473 + 474 + /* wait for minimum interrupt pulse to make st95 active */ 475 + usleep_range(1000, 2000); 476 + 477 + /* At end make it high */ 478 + gpio_set_value(st95con->enable_gpio, HIGH); 479 + } 480 + 481 + /* 482 + * Send a reset sequence over SPI bus (Reset command + wait 3ms + 483 + * negative pulse on st95hf enable gpio 484 + */ 485 + static int st95hf_send_spi_reset_sequence(struct st95hf_context *st95context) 486 + { 487 + int result = 0; 488 + unsigned char reset_cmd = ST95HF_COMMAND_RESET; 489 + 490 + result = st95hf_spi_send(&st95context->spicontext, 491 + &reset_cmd, 492 + ST95HF_RESET_CMD_LEN, 493 + ASYNC); 494 + if (result) { 495 + dev_err(&st95context->spicontext.spidev->dev, 496 + "spi reset sequence cmd error = %d", result); 497 + return result; 498 + } 499 + 500 + /* wait for 3 milisecond to complete the controller reset process */ 501 + usleep_range(3000, 4000); 502 + 503 + /* send negative pulse to make st95hf active */ 504 + st95hf_send_st95enable_negativepulse(st95context); 505 + 506 + /* wait for 10 milisecond : HFO setup time */ 507 + usleep_range(10000, 20000); 508 + 509 + return result; 510 + } 511 + 512 + static int st95hf_por_sequence(struct st95hf_context *st95context) 513 + { 514 + int nth_attempt = 1; 515 + int result; 516 + 517 + st95hf_send_st95enable_negativepulse(st95context); 518 + 519 + usleep_range(5000, 6000); 520 + do { 521 + /* send an ECHO command and checks ST95HF response */ 522 + result = st95hf_echo_command(st95context); 523 + 524 + dev_dbg(&st95context->spicontext.spidev->dev, 525 + "response from echo function = 0x%x, attempt = %d\n", 526 + result, nth_attempt); 527 + 528 + if (!result) 529 + return 0; 530 + 531 + /* send an pulse on IRQ in case of the chip is on sleep state */ 532 + if (nth_attempt == 2) 533 + st95hf_send_st95enable_negativepulse(st95context); 534 + else 535 + st95hf_send_spi_reset_sequence(st95context); 536 + 537 + /* delay of 50 milisecond */ 538 + usleep_range(50000, 51000); 539 + } while (nth_attempt++ < 3); 540 + 541 + return -ETIMEDOUT; 542 + } 543 + 544 + static int iso14443_config_fdt(struct st95hf_context *st95context, int wtxm) 545 + { 546 + int result = 0; 547 + struct device *dev = &st95context->spicontext.spidev->dev; 548 + struct nfc_digital_dev *nfcddev = st95context->ddev; 549 + unsigned char pp_typeb; 550 + struct param_list new_params[2]; 551 + 552 + pp_typeb = cmd_array[CMD_ISO14443B_PROTOCOL_SELECT].cmd_params[2]; 553 + 554 + if (nfcddev->curr_protocol == NFC_PROTO_ISO14443 && 555 + st95context->fwi < 4) 556 + st95context->fwi = 4; 557 + 558 + new_params[0].param_offset = 2; 559 + if (nfcddev->curr_protocol == NFC_PROTO_ISO14443) 560 + new_params[0].new_param_val = st95context->fwi; 561 + else if (nfcddev->curr_protocol == NFC_PROTO_ISO14443_B) 562 + new_params[0].new_param_val = pp_typeb; 563 + 564 + new_params[1].param_offset = 3; 565 + new_params[1].new_param_val = wtxm; 566 + 567 + switch (nfcddev->curr_protocol) { 568 + case NFC_PROTO_ISO14443: 569 + result = st95hf_send_recv_cmd(st95context, 570 + CMD_ISO14443A_PROTOCOL_SELECT, 571 + 2, 572 + new_params, 573 + true); 574 + if (result) { 575 + dev_err(dev, "WTX type a sel proto, err = 0x%x\n", 576 + result); 577 + return result; 578 + } 579 + 580 + /* secondary config. for 14443Type 4A after protocol select */ 581 + result = secondary_configuration_type4a(st95context); 582 + if (result) { 583 + dev_err(dev, "WTX type a second. config, err = 0x%x\n", 584 + result); 585 + return result; 586 + } 587 + break; 588 + case NFC_PROTO_ISO14443_B: 589 + result = st95hf_send_recv_cmd(st95context, 590 + CMD_ISO14443B_PROTOCOL_SELECT, 591 + 2, 592 + new_params, 593 + true); 594 + if (result) { 595 + dev_err(dev, "WTX type b sel proto, err = 0x%x\n", 596 + result); 597 + return result; 598 + } 599 + 600 + /* secondary config. for 14443Type 4B after protocol select */ 601 + result = secondary_configuration_type4b(st95context); 602 + if (result) { 603 + dev_err(dev, "WTX type b second. config, err = 0x%x\n", 604 + result); 605 + return result; 606 + } 607 + break; 608 + default: 609 + return -EINVAL; 610 + } 611 + 612 + return 0; 613 + } 614 + 615 + static int st95hf_handle_wtx(struct st95hf_context *stcontext, 616 + bool new_wtx, 617 + int wtx_val) 618 + { 619 + int result = 0; 620 + unsigned char val_mm = 0; 621 + struct param_list new_params[1]; 622 + struct nfc_digital_dev *nfcddev = stcontext->ddev; 623 + struct device *dev = &stcontext->nfcdev->dev; 624 + 625 + if (new_wtx) { 626 + result = iso14443_config_fdt(stcontext, wtx_val & 0x3f); 627 + if (result) { 628 + dev_err(dev, "Config. setting error on WTX req, err = 0x%x\n", 629 + result); 630 + return result; 631 + } 632 + 633 + /* Send response of wtx with ASYNC as no response expected */ 634 + new_params[0].param_offset = 1; 635 + new_params[0].new_param_val = wtx_val; 636 + 637 + result = st95hf_send_recv_cmd(stcontext, 638 + CMD_WTX_RESPONSE, 639 + 1, 640 + new_params, 641 + false); 642 + if (result) 643 + dev_err(dev, "WTX response send, err = 0x%x\n", result); 644 + return result; 645 + } 646 + 647 + /* if no new wtx, cofigure with default values */ 648 + if (nfcddev->curr_protocol == NFC_PROTO_ISO14443) 649 + val_mm = cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[3]; 650 + else if (nfcddev->curr_protocol == NFC_PROTO_ISO14443_B) 651 + val_mm = cmd_array[CMD_ISO14443B_PROTOCOL_SELECT].cmd_params[3]; 652 + 653 + result = iso14443_config_fdt(stcontext, val_mm); 654 + if (result) 655 + dev_err(dev, "Default config. setting error after WTX processing, err = 0x%x\n", 656 + result); 657 + 658 + return result; 659 + } 660 + 661 + static int st95hf_error_handling(struct st95hf_context *stcontext, 662 + struct sk_buff *skb_resp, 663 + int res_len) 664 + { 665 + int result = 0; 666 + unsigned char error_byte; 667 + struct device *dev = &stcontext->nfcdev->dev; 668 + 669 + /* First check ST95HF specific error */ 670 + if (skb_resp->data[0] & ST95HF_ERR_MASK) { 671 + if (skb_resp->data[0] == ST95HF_TIMEOUT_ERROR) 672 + result = -ETIMEDOUT; 673 + else 674 + result = -EIO; 675 + return result; 676 + } 677 + 678 + /* Check for CRC err only if CRC is present in the tag response */ 679 + switch (stcontext->current_rf_tech) { 680 + case NFC_DIGITAL_RF_TECH_106A: 681 + if (stcontext->sendrcv_trflag == TRFLAG_NFCA_STD_FRAME_CRC) { 682 + error_byte = skb_resp->data[res_len - 3]; 683 + if (error_byte & ST95HF_NFCA_CRC_ERR_MASK) { 684 + /* CRC error occurred */ 685 + dev_err(dev, "CRC error, byte received = 0x%x\n", 686 + error_byte); 687 + result = -EIO; 688 + } 689 + } 690 + break; 691 + case NFC_DIGITAL_RF_TECH_106B: 692 + case NFC_DIGITAL_RF_TECH_ISO15693: 693 + error_byte = skb_resp->data[res_len - 1]; 694 + if (error_byte & ST95HF_NFCB_CRC_ERR_MASK) { 695 + /* CRC error occurred */ 696 + dev_err(dev, "CRC error, byte received = 0x%x\n", 697 + error_byte); 698 + result = -EIO; 699 + } 700 + break; 701 + } 702 + 703 + return result; 704 + } 705 + 706 + static int st95hf_response_handler(struct st95hf_context *stcontext, 707 + struct sk_buff *skb_resp, 708 + int res_len) 709 + { 710 + int result = 0; 711 + int skb_len; 712 + unsigned char val_mm; 713 + struct nfc_digital_dev *nfcddev = stcontext->ddev; 714 + struct device *dev = &stcontext->nfcdev->dev; 715 + struct st95_digital_cmd_complete_arg *cb_arg; 716 + 717 + cb_arg = &stcontext->complete_cb_arg; 718 + 719 + /* Process the response */ 720 + skb_put(skb_resp, res_len); 721 + 722 + /* Remove st95 header */ 723 + skb_pull(skb_resp, 2); 724 + 725 + skb_len = skb_resp->len; 726 + 727 + /* check if it is case of RATS request reply & FWI is present */ 728 + if (nfcddev->curr_protocol == NFC_PROTO_ISO14443 && cb_arg->rats && 729 + (skb_resp->data[1] & RATS_TB1_PRESENT_MASK)) { 730 + if (skb_resp->data[1] & RATS_TA1_PRESENT_MASK) 731 + stcontext->fwi = 732 + (skb_resp->data[3] & TB1_FWI_MASK) >> 4; 733 + else 734 + stcontext->fwi = 735 + (skb_resp->data[2] & TB1_FWI_MASK) >> 4; 736 + 737 + val_mm = cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[3]; 738 + 739 + result = iso14443_config_fdt(stcontext, val_mm); 740 + if (result) { 741 + dev_err(dev, "error in config_fdt to handle fwi of ATS, error=%d\n", 742 + result); 743 + return result; 744 + } 745 + } 746 + cb_arg->rats = false; 747 + 748 + /* Remove CRC bytes only if received frames data has an eod (CRC) */ 749 + switch (stcontext->current_rf_tech) { 750 + case NFC_DIGITAL_RF_TECH_106A: 751 + if (stcontext->sendrcv_trflag == TRFLAG_NFCA_STD_FRAME_CRC) 752 + skb_trim(skb_resp, (skb_len - 5)); 753 + else 754 + skb_trim(skb_resp, (skb_len - 3)); 755 + break; 756 + case NFC_DIGITAL_RF_TECH_106B: 757 + case NFC_DIGITAL_RF_TECH_ISO15693: 758 + skb_trim(skb_resp, (skb_len - 3)); 759 + break; 760 + } 761 + 762 + return result; 763 + } 764 + 765 + static irqreturn_t st95hf_irq_handler(int irq, void *st95hfcontext) 766 + { 767 + struct st95hf_context *stcontext = 768 + (struct st95hf_context *)st95hfcontext; 769 + 770 + if (stcontext->spicontext.req_issync) { 771 + complete(&stcontext->spicontext.done); 772 + stcontext->spicontext.req_issync = false; 773 + return IRQ_HANDLED; 774 + } 775 + 776 + return IRQ_WAKE_THREAD; 777 + } 778 + 779 + static irqreturn_t st95hf_irq_thread_handler(int irq, void *st95hfcontext) 780 + { 781 + int result = 0; 782 + int res_len; 783 + static bool wtx; 784 + struct device *dev; 785 + struct device *spidevice; 786 + struct nfc_digital_dev *nfcddev; 787 + struct sk_buff *skb_resp; 788 + struct st95hf_context *stcontext = 789 + (struct st95hf_context *)st95hfcontext; 790 + struct st95_digital_cmd_complete_arg *cb_arg; 791 + 792 + spidevice = &stcontext->spicontext.spidev->dev; 793 + 794 + /* 795 + * check semaphore, if not down() already, then we don't 796 + * know in which context the ISR is called and surely it 797 + * will be a bug. Note that down() of the semaphore is done 798 + * in the corresponding st95hf_in_send_cmd() and then 799 + * only this ISR should be called. ISR will up() the 800 + * semaphore before leaving. Hence when the ISR is called 801 + * the correct behaviour is down_trylock() should always 802 + * return 1 (indicating semaphore cant be taken and hence no 803 + * change in semaphore count). 804 + * If not, then we up() the semaphore and crash on 805 + * a BUG() ! 806 + */ 807 + if (!down_trylock(&stcontext->exchange_lock)) { 808 + up(&stcontext->exchange_lock); 809 + WARN(1, "unknown context in ST95HF ISR"); 810 + return IRQ_NONE; 811 + } 812 + 813 + cb_arg = &stcontext->complete_cb_arg; 814 + skb_resp = cb_arg->skb_resp; 815 + 816 + mutex_lock(&stcontext->rm_lock); 817 + res_len = st95hf_spi_recv_response(&stcontext->spicontext, 818 + skb_resp->data); 819 + if (res_len < 0) { 820 + dev_err(spidevice, "TISR spi response err = 0x%x\n", res_len); 821 + result = res_len; 822 + goto end; 823 + } 824 + 825 + /* if stcontext->nfcdev_free is true, it means remove already ran */ 826 + if (stcontext->nfcdev_free) { 827 + result = -ENODEV; 828 + goto end; 829 + } 830 + 831 + dev = &stcontext->nfcdev->dev; 832 + nfcddev = stcontext->ddev; 833 + if (skb_resp->data[2] == WTX_REQ_FROM_TAG) { 834 + /* Request for new FWT from tag */ 835 + result = st95hf_handle_wtx(stcontext, true, skb_resp->data[3]); 836 + if (result) 837 + goto end; 838 + 839 + wtx = true; 840 + mutex_unlock(&stcontext->rm_lock); 841 + return IRQ_HANDLED; 842 + } 843 + 844 + result = st95hf_error_handling(stcontext, skb_resp, res_len); 845 + if (result) 846 + goto end; 847 + 848 + result = st95hf_response_handler(stcontext, skb_resp, res_len); 849 + if (result) 850 + goto end; 851 + 852 + /* 853 + * If select protocol is done on wtx req. do select protocol 854 + * again with default values 855 + */ 856 + if (wtx) { 857 + wtx = false; 858 + result = st95hf_handle_wtx(stcontext, false, 0); 859 + if (result) 860 + goto end; 861 + } 862 + 863 + /* call digital layer callback */ 864 + cb_arg->complete_cb(stcontext->ddev, cb_arg->cb_usrarg, skb_resp); 865 + 866 + /* up the semaphore before returning */ 867 + up(&stcontext->exchange_lock); 868 + mutex_unlock(&stcontext->rm_lock); 869 + 870 + return IRQ_HANDLED; 871 + 872 + end: 873 + kfree_skb(skb_resp); 874 + wtx = false; 875 + cb_arg->rats = false; 876 + skb_resp = ERR_PTR(result); 877 + /* call of callback with error */ 878 + cb_arg->complete_cb(stcontext->ddev, cb_arg->cb_usrarg, skb_resp); 879 + /* up the semaphore before returning */ 880 + up(&stcontext->exchange_lock); 881 + mutex_unlock(&stcontext->rm_lock); 882 + return IRQ_HANDLED; 883 + } 884 + 885 + /* NFC ops functions definition */ 886 + static int st95hf_in_configure_hw(struct nfc_digital_dev *ddev, 887 + int type, 888 + int param) 889 + { 890 + struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev); 891 + 892 + if (type == NFC_DIGITAL_CONFIG_RF_TECH) 893 + return st95hf_select_protocol(stcontext, param); 894 + 895 + if (type == NFC_DIGITAL_CONFIG_FRAMING) { 896 + switch (param) { 897 + case NFC_DIGITAL_FRAMING_NFCA_SHORT: 898 + stcontext->sendrcv_trflag = TRFLAG_NFCA_SHORT_FRAME; 899 + break; 900 + case NFC_DIGITAL_FRAMING_NFCA_STANDARD: 901 + stcontext->sendrcv_trflag = TRFLAG_NFCA_STD_FRAME; 902 + break; 903 + case NFC_DIGITAL_FRAMING_NFCA_T4T: 904 + case NFC_DIGITAL_FRAMING_NFCA_NFC_DEP: 905 + case NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A: 906 + stcontext->sendrcv_trflag = TRFLAG_NFCA_STD_FRAME_CRC; 907 + break; 908 + case NFC_DIGITAL_FRAMING_NFCB: 909 + case NFC_DIGITAL_FRAMING_ISO15693_INVENTORY: 910 + case NFC_DIGITAL_FRAMING_ISO15693_T5T: 911 + break; 912 + } 913 + } 914 + 915 + return 0; 916 + } 917 + 918 + static int rf_off(struct st95hf_context *stcontext) 919 + { 920 + int rc; 921 + struct device *dev; 922 + 923 + dev = &stcontext->nfcdev->dev; 924 + 925 + rc = st95hf_send_recv_cmd(stcontext, CMD_FIELD_OFF, 0, NULL, true); 926 + if (rc) 927 + dev_err(dev, "protocol sel send field off, err = 0x%x\n", rc); 928 + 929 + return rc; 930 + } 931 + 932 + static int st95hf_in_send_cmd(struct nfc_digital_dev *ddev, 933 + struct sk_buff *skb, 934 + u16 timeout, 935 + nfc_digital_cmd_complete_t cb, 936 + void *arg) 937 + { 938 + struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev); 939 + int rc; 940 + struct sk_buff *skb_resp; 941 + int len_data_to_tag = 0; 942 + 943 + skb_resp = nfc_alloc_recv_skb(MAX_RESPONSE_BUFFER_SIZE, GFP_KERNEL); 944 + if (!skb_resp) { 945 + rc = -ENOMEM; 946 + goto error; 947 + } 948 + 949 + switch (stcontext->current_rf_tech) { 950 + case NFC_DIGITAL_RF_TECH_106A: 951 + len_data_to_tag = skb->len + 1; 952 + *skb_put(skb, 1) = stcontext->sendrcv_trflag; 953 + break; 954 + case NFC_DIGITAL_RF_TECH_106B: 955 + case NFC_DIGITAL_RF_TECH_ISO15693: 956 + len_data_to_tag = skb->len; 957 + break; 958 + default: 959 + rc = -EINVAL; 960 + goto free_skb_resp; 961 + } 962 + 963 + skb_push(skb, 3); 964 + skb->data[0] = ST95HF_COMMAND_SEND; 965 + skb->data[1] = SEND_RECEIVE_CMD; 966 + skb->data[2] = len_data_to_tag; 967 + 968 + stcontext->complete_cb_arg.skb_resp = skb_resp; 969 + stcontext->complete_cb_arg.cb_usrarg = arg; 970 + stcontext->complete_cb_arg.complete_cb = cb; 971 + 972 + if ((skb->data[3] == ISO14443A_RATS_REQ) && 973 + ddev->curr_protocol == NFC_PROTO_ISO14443) 974 + stcontext->complete_cb_arg.rats = true; 975 + 976 + /* 977 + * down the semaphore to indicate to remove func that an 978 + * ISR is pending, note that it will not block here in any case. 979 + * If found blocked, it is a BUG! 980 + */ 981 + rc = down_killable(&stcontext->exchange_lock); 982 + if (rc) { 983 + WARN(1, "Semaphore is not found up in st95hf_in_send_cmd\n"); 984 + return rc; 985 + } 986 + 987 + rc = st95hf_spi_send(&stcontext->spicontext, skb->data, 988 + skb->len, 989 + ASYNC); 990 + if (rc) { 991 + dev_err(&stcontext->nfcdev->dev, 992 + "Error %d trying to perform data_exchange", rc); 993 + /* up the semaphore since ISR will never come in this case */ 994 + up(&stcontext->exchange_lock); 995 + goto free_skb_resp; 996 + } 997 + 998 + kfree_skb(skb); 999 + 1000 + return rc; 1001 + 1002 + free_skb_resp: 1003 + kfree_skb(skb_resp); 1004 + error: 1005 + return rc; 1006 + } 1007 + 1008 + /* p2p will be supported in a later release ! */ 1009 + static int st95hf_tg_configure_hw(struct nfc_digital_dev *ddev, 1010 + int type, 1011 + int param) 1012 + { 1013 + return 0; 1014 + } 1015 + 1016 + static int st95hf_tg_send_cmd(struct nfc_digital_dev *ddev, 1017 + struct sk_buff *skb, 1018 + u16 timeout, 1019 + nfc_digital_cmd_complete_t cb, 1020 + void *arg) 1021 + { 1022 + return 0; 1023 + } 1024 + 1025 + static int st95hf_tg_listen(struct nfc_digital_dev *ddev, 1026 + u16 timeout, 1027 + nfc_digital_cmd_complete_t cb, 1028 + void *arg) 1029 + { 1030 + return 0; 1031 + } 1032 + 1033 + static int st95hf_tg_get_rf_tech(struct nfc_digital_dev *ddev, u8 *rf_tech) 1034 + { 1035 + return 0; 1036 + } 1037 + 1038 + static int st95hf_switch_rf(struct nfc_digital_dev *ddev, bool on) 1039 + { 1040 + u8 rf_tech; 1041 + struct st95hf_context *stcontext = nfc_digital_get_drvdata(ddev); 1042 + 1043 + rf_tech = ddev->curr_rf_tech; 1044 + 1045 + if (on) 1046 + /* switch on RF field */ 1047 + return st95hf_select_protocol(stcontext, rf_tech); 1048 + 1049 + /* switch OFF RF field */ 1050 + return rf_off(stcontext); 1051 + } 1052 + 1053 + /* TODO st95hf_abort_cmd */ 1054 + static void st95hf_abort_cmd(struct nfc_digital_dev *ddev) 1055 + { 1056 + } 1057 + 1058 + static struct nfc_digital_ops st95hf_nfc_digital_ops = { 1059 + .in_configure_hw = st95hf_in_configure_hw, 1060 + .in_send_cmd = st95hf_in_send_cmd, 1061 + 1062 + .tg_listen = st95hf_tg_listen, 1063 + .tg_configure_hw = st95hf_tg_configure_hw, 1064 + .tg_send_cmd = st95hf_tg_send_cmd, 1065 + .tg_get_rf_tech = st95hf_tg_get_rf_tech, 1066 + 1067 + .switch_rf = st95hf_switch_rf, 1068 + .abort_cmd = st95hf_abort_cmd, 1069 + }; 1070 + 1071 + static const struct spi_device_id st95hf_id[] = { 1072 + { "st95hf", 0 }, 1073 + {} 1074 + }; 1075 + MODULE_DEVICE_TABLE(spi, st95hf_id); 1076 + 1077 + static int st95hf_probe(struct spi_device *nfc_spi_dev) 1078 + { 1079 + int ret; 1080 + 1081 + struct st95hf_context *st95context; 1082 + struct st95hf_spi_context *spicontext; 1083 + 1084 + nfc_info(&nfc_spi_dev->dev, "ST95HF driver probe called.\n"); 1085 + 1086 + st95context = devm_kzalloc(&nfc_spi_dev->dev, 1087 + sizeof(struct st95hf_context), 1088 + GFP_KERNEL); 1089 + if (!st95context) 1090 + return -ENOMEM; 1091 + 1092 + spicontext = &st95context->spicontext; 1093 + 1094 + spicontext->spidev = nfc_spi_dev; 1095 + 1096 + st95context->fwi = 1097 + cmd_array[CMD_ISO14443A_PROTOCOL_SELECT].cmd_params[2]; 1098 + 1099 + if (device_property_present(&nfc_spi_dev->dev, "st95hfvin")) { 1100 + st95context->st95hf_supply = 1101 + devm_regulator_get(&nfc_spi_dev->dev, 1102 + "st95hfvin"); 1103 + if (IS_ERR(st95context->st95hf_supply)) { 1104 + dev_err(&nfc_spi_dev->dev, "failed to acquire regulator\n"); 1105 + return PTR_ERR(st95context->st95hf_supply); 1106 + } 1107 + 1108 + ret = regulator_enable(st95context->st95hf_supply); 1109 + if (ret) { 1110 + dev_err(&nfc_spi_dev->dev, "failed to enable regulator\n"); 1111 + return ret; 1112 + } 1113 + } 1114 + 1115 + init_completion(&spicontext->done); 1116 + mutex_init(&spicontext->spi_lock); 1117 + 1118 + /* 1119 + * Store spicontext in spi device object for using it in 1120 + * remove function 1121 + */ 1122 + dev_set_drvdata(&nfc_spi_dev->dev, spicontext); 1123 + 1124 + st95context->enable_gpio = 1125 + of_get_named_gpio(nfc_spi_dev->dev.of_node, 1126 + "enable-gpio", 1127 + 0); 1128 + if (!gpio_is_valid(st95context->enable_gpio)) { 1129 + dev_err(&nfc_spi_dev->dev, "No valid enable gpio\n"); 1130 + ret = st95context->enable_gpio; 1131 + goto err_disable_regulator; 1132 + } 1133 + 1134 + ret = devm_gpio_request_one(&nfc_spi_dev->dev, st95context->enable_gpio, 1135 + GPIOF_DIR_OUT | GPIOF_INIT_HIGH, 1136 + "enable_gpio"); 1137 + if (ret) 1138 + goto err_disable_regulator; 1139 + 1140 + if (nfc_spi_dev->irq > 0) { 1141 + if (devm_request_threaded_irq(&nfc_spi_dev->dev, 1142 + nfc_spi_dev->irq, 1143 + st95hf_irq_handler, 1144 + st95hf_irq_thread_handler, 1145 + IRQF_TRIGGER_FALLING, 1146 + "st95hf", 1147 + (void *)st95context) < 0) { 1148 + dev_err(&nfc_spi_dev->dev, "err: irq request for st95hf is failed\n"); 1149 + ret = -EINVAL; 1150 + goto err_disable_regulator; 1151 + } 1152 + } else { 1153 + dev_err(&nfc_spi_dev->dev, "not a valid IRQ associated with ST95HF\n"); 1154 + ret = -EINVAL; 1155 + goto err_disable_regulator; 1156 + } 1157 + 1158 + /* 1159 + * First reset SPI to handle warm reset of the system. 1160 + * It will put the ST95HF device in Power ON state 1161 + * which make the state of device identical to state 1162 + * at the time of cold reset of the system. 1163 + */ 1164 + ret = st95hf_send_spi_reset_sequence(st95context); 1165 + if (ret) { 1166 + dev_err(&nfc_spi_dev->dev, "err: spi_reset_sequence failed\n"); 1167 + goto err_disable_regulator; 1168 + } 1169 + 1170 + /* call PowerOnReset sequence of ST95hf to activate it */ 1171 + ret = st95hf_por_sequence(st95context); 1172 + if (ret) { 1173 + dev_err(&nfc_spi_dev->dev, "err: por seq failed for st95hf\n"); 1174 + goto err_disable_regulator; 1175 + } 1176 + 1177 + /* create NFC dev object and register with NFC Subsystem */ 1178 + st95context->ddev = nfc_digital_allocate_device(&st95hf_nfc_digital_ops, 1179 + ST95HF_SUPPORTED_PROT, 1180 + ST95HF_CAPABILITIES, 1181 + ST95HF_HEADROOM_LEN, 1182 + ST95HF_TAILROOM_LEN); 1183 + if (!st95context->ddev) { 1184 + ret = -ENOMEM; 1185 + goto err_disable_regulator; 1186 + } 1187 + 1188 + st95context->nfcdev = st95context->ddev->nfc_dev; 1189 + nfc_digital_set_parent_dev(st95context->ddev, &nfc_spi_dev->dev); 1190 + 1191 + ret = nfc_digital_register_device(st95context->ddev); 1192 + if (ret) { 1193 + dev_err(&st95context->nfcdev->dev, "st95hf registration failed\n"); 1194 + goto err_free_digital_device; 1195 + } 1196 + 1197 + /* store st95context in nfc device object */ 1198 + nfc_digital_set_drvdata(st95context->ddev, st95context); 1199 + 1200 + sema_init(&st95context->exchange_lock, 1); 1201 + mutex_init(&st95context->rm_lock); 1202 + 1203 + return ret; 1204 + 1205 + err_free_digital_device: 1206 + nfc_digital_free_device(st95context->ddev); 1207 + err_disable_regulator: 1208 + if (st95context->st95hf_supply) 1209 + regulator_disable(st95context->st95hf_supply); 1210 + 1211 + return ret; 1212 + } 1213 + 1214 + static int st95hf_remove(struct spi_device *nfc_spi_dev) 1215 + { 1216 + int result = 0; 1217 + unsigned char reset_cmd = ST95HF_COMMAND_RESET; 1218 + struct st95hf_spi_context *spictx = dev_get_drvdata(&nfc_spi_dev->dev); 1219 + 1220 + struct st95hf_context *stcontext = container_of(spictx, 1221 + struct st95hf_context, 1222 + spicontext); 1223 + 1224 + mutex_lock(&stcontext->rm_lock); 1225 + 1226 + nfc_digital_unregister_device(stcontext->ddev); 1227 + nfc_digital_free_device(stcontext->ddev); 1228 + stcontext->nfcdev_free = true; 1229 + 1230 + mutex_unlock(&stcontext->rm_lock); 1231 + 1232 + /* if last in_send_cmd's ISR is pending, wait for it to finish */ 1233 + result = down_killable(&stcontext->exchange_lock); 1234 + if (result == -EINTR) 1235 + dev_err(&spictx->spidev->dev, "sleep for semaphore interrupted by signal\n"); 1236 + 1237 + /* next reset the ST95HF controller */ 1238 + result = st95hf_spi_send(&stcontext->spicontext, 1239 + &reset_cmd, 1240 + ST95HF_RESET_CMD_LEN, 1241 + ASYNC); 1242 + if (result) { 1243 + dev_err(&spictx->spidev->dev, 1244 + "ST95HF reset failed in remove() err = %d\n", result); 1245 + return result; 1246 + } 1247 + 1248 + /* wait for 3 ms to complete the controller reset process */ 1249 + usleep_range(3000, 4000); 1250 + 1251 + /* disable regulator */ 1252 + if (stcontext->st95hf_supply) 1253 + regulator_disable(stcontext->st95hf_supply); 1254 + 1255 + return result; 1256 + } 1257 + 1258 + /* Register as SPI protocol driver */ 1259 + static struct spi_driver st95hf_driver = { 1260 + .driver = { 1261 + .name = "st95hf", 1262 + .owner = THIS_MODULE, 1263 + }, 1264 + .id_table = st95hf_id, 1265 + .probe = st95hf_probe, 1266 + .remove = st95hf_remove, 1267 + }; 1268 + 1269 + module_spi_driver(st95hf_driver); 1270 + 1271 + MODULE_AUTHOR("Shikha Singh <shikha.singh@st.com>"); 1272 + MODULE_DESCRIPTION("ST NFC Transceiver ST95HF driver"); 1273 + MODULE_LICENSE("GPL v2");
+167
drivers/nfc/st95hf/spi.c
··· 1 + /* 2 + * ---------------------------------------------------------------------------- 3 + * drivers/nfc/st95hf/spi.c function definitions for SPI communication 4 + * ---------------------------------------------------------------------------- 5 + * Copyright (C) 2015 STMicroelectronics Pvt. Ltd. All rights reserved. 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms and conditions of the GNU General Public License, 9 + * version 2, as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "spi.h" 21 + 22 + /* Function to send user provided buffer to ST95HF through SPI */ 23 + int st95hf_spi_send(struct st95hf_spi_context *spicontext, 24 + unsigned char *buffertx, 25 + int datalen, 26 + enum req_type reqtype) 27 + { 28 + struct spi_message m; 29 + int result = 0; 30 + struct spi_device *spidev = spicontext->spidev; 31 + struct spi_transfer tx_transfer = { 32 + .tx_buf = buffertx, 33 + .len = datalen, 34 + }; 35 + 36 + mutex_lock(&spicontext->spi_lock); 37 + 38 + if (reqtype == SYNC) { 39 + spicontext->req_issync = true; 40 + reinit_completion(&spicontext->done); 41 + } else { 42 + spicontext->req_issync = false; 43 + } 44 + 45 + spi_message_init(&m); 46 + spi_message_add_tail(&tx_transfer, &m); 47 + 48 + result = spi_sync(spidev, &m); 49 + if (result) { 50 + dev_err(&spidev->dev, "error: sending cmd to st95hf using SPI = %d\n", 51 + result); 52 + mutex_unlock(&spicontext->spi_lock); 53 + return result; 54 + } 55 + 56 + /* return for asynchronous or no-wait case */ 57 + if (reqtype == ASYNC) { 58 + mutex_unlock(&spicontext->spi_lock); 59 + return 0; 60 + } 61 + 62 + result = wait_for_completion_timeout(&spicontext->done, 63 + msecs_to_jiffies(1000)); 64 + /* check for timeout or success */ 65 + if (!result) { 66 + dev_err(&spidev->dev, "error: response not ready timeout\n"); 67 + result = -ETIMEDOUT; 68 + } else { 69 + result = 0; 70 + } 71 + 72 + mutex_unlock(&spicontext->spi_lock); 73 + 74 + return result; 75 + } 76 + EXPORT_SYMBOL_GPL(st95hf_spi_send); 77 + 78 + /* Function to Receive command Response */ 79 + int st95hf_spi_recv_response(struct st95hf_spi_context *spicontext, 80 + unsigned char *receivebuff) 81 + { 82 + int len = 0; 83 + struct spi_transfer tx_takedata; 84 + struct spi_message m; 85 + struct spi_device *spidev = spicontext->spidev; 86 + unsigned char readdata_cmd = ST95HF_COMMAND_RECEIVE; 87 + struct spi_transfer t[2] = { 88 + {.tx_buf = &readdata_cmd, .len = 1,}, 89 + {.rx_buf = receivebuff, .len = 2, .cs_change = 1,}, 90 + }; 91 + 92 + int ret = 0; 93 + 94 + memset(&tx_takedata, 0x0, sizeof(struct spi_transfer)); 95 + 96 + mutex_lock(&spicontext->spi_lock); 97 + 98 + /* First spi transfer to know the length of valid data */ 99 + spi_message_init(&m); 100 + spi_message_add_tail(&t[0], &m); 101 + spi_message_add_tail(&t[1], &m); 102 + 103 + ret = spi_sync(spidev, &m); 104 + if (ret) { 105 + dev_err(&spidev->dev, "spi_recv_resp, data length error = %d\n", 106 + ret); 107 + mutex_unlock(&spicontext->spi_lock); 108 + return ret; 109 + } 110 + 111 + /* As 2 bytes are already read */ 112 + len = 2; 113 + 114 + /* Support of long frame */ 115 + if (receivebuff[0] & 0x60) 116 + len += (((receivebuff[0] & 0x60) >> 5) << 8) | receivebuff[1]; 117 + else 118 + len += receivebuff[1]; 119 + 120 + /* Now make a transfer to read only relevant bytes */ 121 + tx_takedata.rx_buf = &receivebuff[2]; 122 + tx_takedata.len = len - 2; 123 + 124 + spi_message_init(&m); 125 + spi_message_add_tail(&tx_takedata, &m); 126 + 127 + ret = spi_sync(spidev, &m); 128 + 129 + mutex_unlock(&spicontext->spi_lock); 130 + if (ret) { 131 + dev_err(&spidev->dev, "spi_recv_resp, data read error = %d\n", 132 + ret); 133 + return ret; 134 + } 135 + 136 + return len; 137 + } 138 + EXPORT_SYMBOL_GPL(st95hf_spi_recv_response); 139 + 140 + int st95hf_spi_recv_echo_res(struct st95hf_spi_context *spicontext, 141 + unsigned char *receivebuff) 142 + { 143 + unsigned char readdata_cmd = ST95HF_COMMAND_RECEIVE; 144 + struct spi_transfer t[2] = { 145 + {.tx_buf = &readdata_cmd, .len = 1,}, 146 + {.rx_buf = receivebuff, .len = 1,}, 147 + }; 148 + struct spi_message m; 149 + struct spi_device *spidev = spicontext->spidev; 150 + int ret = 0; 151 + 152 + mutex_lock(&spicontext->spi_lock); 153 + 154 + spi_message_init(&m); 155 + spi_message_add_tail(&t[0], &m); 156 + spi_message_add_tail(&t[1], &m); 157 + ret = spi_sync(spidev, &m); 158 + 159 + mutex_unlock(&spicontext->spi_lock); 160 + 161 + if (ret) 162 + dev_err(&spidev->dev, "recv_echo_res, data read error = %d\n", 163 + ret); 164 + 165 + return ret; 166 + } 167 + EXPORT_SYMBOL_GPL(st95hf_spi_recv_echo_res);
+64
drivers/nfc/st95hf/spi.h
··· 1 + /* 2 + * --------------------------------------------------------------------------- 3 + * drivers/nfc/st95hf/spi.h functions declarations for SPI communication 4 + * --------------------------------------------------------------------------- 5 + * Copyright (C) 2015 STMicroelectronics – All Rights Reserved 6 + * 7 + * This program is free software; you can redistribute it and/or modify it 8 + * under the terms and conditions of the GNU General Public License, 9 + * version 2, as published by the Free Software Foundation. 10 + * 11 + * This program is distributed in the hope that it will be useful, 12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + * GNU General Public License for more details. 15 + * 16 + * You should have received a copy of the GNU General Public License 17 + * along with this program; if not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef __LINUX_ST95HF_SPI_H 21 + #define __LINUX_ST95HF_SPI_H 22 + 23 + #include <linux/spi/spi.h> 24 + 25 + /* Basic ST95HF SPI CMDs */ 26 + #define ST95HF_COMMAND_SEND 0x0 27 + #define ST95HF_COMMAND_RESET 0x1 28 + #define ST95HF_COMMAND_RECEIVE 0x2 29 + 30 + #define ST95HF_RESET_CMD_LEN 0x1 31 + 32 + /* 33 + * structure to contain st95hf spi communication specific information. 34 + * @req_issync: true for synchronous calls. 35 + * @spidev: st95hf spi device object. 36 + * @done: completion structure to wait for st95hf response 37 + * for synchronous calls. 38 + * @spi_lock: mutex to allow only one spi transfer at a time. 39 + */ 40 + struct st95hf_spi_context { 41 + bool req_issync; 42 + struct spi_device *spidev; 43 + struct completion done; 44 + struct mutex spi_lock; 45 + }; 46 + 47 + /* flag to differentiate synchronous & asynchronous spi request */ 48 + enum req_type { 49 + SYNC, 50 + ASYNC, 51 + }; 52 + 53 + int st95hf_spi_send(struct st95hf_spi_context *spicontext, 54 + unsigned char *buffertx, 55 + int datalen, 56 + enum req_type reqtype); 57 + 58 + int st95hf_spi_recv_response(struct st95hf_spi_context *spicontext, 59 + unsigned char *receivebuff); 60 + 61 + int st95hf_spi_recv_echo_res(struct st95hf_spi_context *spicontext, 62 + unsigned char *receivebuff); 63 + 64 + #endif
+4 -4
drivers/nfc/trf7970a.c
··· 2139 2139 #ifdef CONFIG_PM_SLEEP 2140 2140 static int trf7970a_suspend(struct device *dev) 2141 2141 { 2142 - struct spi_device *spi = container_of(dev, struct spi_device, dev); 2142 + struct spi_device *spi = to_spi_device(dev); 2143 2143 struct trf7970a *trf = spi_get_drvdata(spi); 2144 2144 2145 2145 dev_dbg(dev, "Suspend\n"); ··· 2155 2155 2156 2156 static int trf7970a_resume(struct device *dev) 2157 2157 { 2158 - struct spi_device *spi = container_of(dev, struct spi_device, dev); 2158 + struct spi_device *spi = to_spi_device(dev); 2159 2159 struct trf7970a *trf = spi_get_drvdata(spi); 2160 2160 int ret; 2161 2161 ··· 2174 2174 #ifdef CONFIG_PM 2175 2175 static int trf7970a_pm_runtime_suspend(struct device *dev) 2176 2176 { 2177 - struct spi_device *spi = container_of(dev, struct spi_device, dev); 2177 + struct spi_device *spi = to_spi_device(dev); 2178 2178 struct trf7970a *trf = spi_get_drvdata(spi); 2179 2179 int ret; 2180 2180 ··· 2191 2191 2192 2192 static int trf7970a_pm_runtime_resume(struct device *dev) 2193 2193 { 2194 - struct spi_device *spi = container_of(dev, struct spi_device, dev); 2194 + struct spi_device *spi = to_spi_device(dev); 2195 2195 struct trf7970a *trf = spi_get_drvdata(spi); 2196 2196 int ret; 2197 2197
+1 -1
include/linux/platform_data/microread.h
··· 1 1 /* 2 - * Driver include for the PN544 NFC chip. 2 + * Driver include for the Inside Secure microread NFC Chip. 3 3 * 4 4 * Copyright (C) 2011 Tieto Poland 5 5 * Copyright (C) 2012 Intel Corporation. All rights reserved.
+1
include/net/nfc/nfc.h
··· 299 299 300 300 int nfc_se_transaction(struct nfc_dev *dev, u8 se_idx, 301 301 struct nfc_evt_transaction *evt_transaction); 302 + int nfc_se_connectivity(struct nfc_dev *dev, u8 se_idx); 302 303 int nfc_add_se(struct nfc_dev *dev, u32 se_idx, u16 type); 303 304 int nfc_remove_se(struct nfc_dev *dev, u32 se_idx); 304 305 struct nfc_se *nfc_find_se(struct nfc_dev *dev, u32 se_idx);
+13
net/nfc/core.c
··· 953 953 } 954 954 EXPORT_SYMBOL(nfc_se_transaction); 955 955 956 + int nfc_se_connectivity(struct nfc_dev *dev, u8 se_idx) 957 + { 958 + int rc; 959 + 960 + pr_debug("connectivity: %x\n", se_idx); 961 + 962 + device_lock(&dev->dev); 963 + rc = nfc_genl_se_connectivity(dev, se_idx); 964 + device_unlock(&dev->dev); 965 + return rc; 966 + } 967 + EXPORT_SYMBOL(nfc_se_connectivity); 968 + 956 969 static void nfc_release(struct device *d) 957 970 { 958 971 struct nfc_dev *dev = to_nfc_dev(d);
+2 -1
net/nfc/digital_core.c
··· 20 20 #include "digital.h" 21 21 22 22 #define DIGITAL_PROTO_NFCA_RF_TECH \ 23 - (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | NFC_PROTO_NFC_DEP_MASK) 23 + (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | \ 24 + NFC_PROTO_NFC_DEP_MASK | NFC_PROTO_ISO14443_MASK) 24 25 25 26 #define DIGITAL_PROTO_NFCB_RF_TECH NFC_PROTO_ISO14443_B_MASK 26 27
+3 -3
net/nfc/nci/core.c
··· 610 610 struct nci_core_conn_create_cmd *cmd; 611 611 struct core_conn_create_data data; 612 612 613 + if (!number_destination_params) 614 + return -EINVAL; 615 + 613 616 data.length = params_len + sizeof(struct nci_core_conn_create_cmd); 614 617 cmd = kzalloc(data.length, GFP_KERNEL); 615 618 if (!cmd) 616 619 return -ENOMEM; 617 - 618 - if (!number_destination_params) 619 - return -EINVAL; 620 620 621 621 cmd->destination_type = destination_type; 622 622 cmd->number_destination_params = number_destination_params;
+1 -1
net/nfc/nci/hci.c
··· 676 676 break; 677 677 default: 678 678 pipe = nci_hci_create_pipe(ndev, dest_host, dest_gate, &r); 679 - if (pipe < 0) 679 + if (pipe == NCI_HCI_INVALID_PIPE) 680 680 return r; 681 681 pipe_created = true; 682 682 break;
+37
net/nfc/netlink.c
··· 552 552 return -EMSGSIZE; 553 553 } 554 554 555 + int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx) 556 + { 557 + struct nfc_se *se; 558 + struct sk_buff *msg; 559 + void *hdr; 560 + 561 + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); 562 + if (!msg) 563 + return -ENOMEM; 564 + 565 + hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0, 566 + NFC_EVENT_SE_CONNECTIVITY); 567 + if (!hdr) 568 + goto free_msg; 569 + 570 + se = nfc_find_se(dev, se_idx); 571 + if (!se) 572 + goto free_msg; 573 + 574 + if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || 575 + nla_put_u32(msg, NFC_ATTR_SE_INDEX, se_idx) || 576 + nla_put_u8(msg, NFC_ATTR_SE_TYPE, se->type)) 577 + goto nla_put_failure; 578 + 579 + genlmsg_end(msg, hdr); 580 + 581 + genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL); 582 + 583 + return 0; 584 + 585 + nla_put_failure: 586 + genlmsg_cancel(msg, hdr); 587 + free_msg: 588 + nlmsg_free(msg); 589 + return -EMSGSIZE; 590 + } 591 + 555 592 static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev, 556 593 u32 portid, u32 seq, 557 594 struct netlink_callback *cb,
+1
net/nfc/nfc.h
··· 105 105 int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx); 106 106 int nfc_genl_se_transaction(struct nfc_dev *dev, u8 se_idx, 107 107 struct nfc_evt_transaction *evt_transaction); 108 + int nfc_genl_se_connectivity(struct nfc_dev *dev, u8 se_idx); 108 109 109 110 struct nfc_dev *nfc_get_device(unsigned int idx); 110 111