2019-05-31 15:09:57 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2014-03-25 12:51:47 +07:00
|
|
|
/*
|
|
|
|
* I2C Link Layer for ST21NFCA HCI based Driver
|
|
|
|
* Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/crc-ccitt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
nfc: st21nfca: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2100 is used for st21nfca
It has been tested with the following acpi node on Minnowboard Max:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2100") // _HID: Hardware ID
Name (_CID, "SMO2100") // _CID: Compatible ID
Name (_DDN, "SMO NFC") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Name (_DSD, Package (0x02)
{
/* Device Properties for _DSD */
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package (0x02)
{
Package (0x02) { "uicc-present", 1 },
Package (0x02) { "ese-present", 1 }
}
})
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x0001, ControllerInitiated, 400000,
AddressingMode7Bit, "\\_SB.I2C7",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.I2C7.NFC1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-12-24 05:45:11 +07:00
|
|
|
#include <linux/gpio/consumer.h>
|
2014-05-14 03:03:39 +07:00
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_gpio.h>
|
nfc: st21nfca: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2100 is used for st21nfca
It has been tested with the following acpi node on Minnowboard Max:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2100") // _HID: Hardware ID
Name (_CID, "SMO2100") // _CID: Compatible ID
Name (_DDN, "SMO NFC") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Name (_DSD, Package (0x02)
{
/* Device Properties for _DSD */
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package (0x02)
{
Package (0x02) { "uicc-present", 1 },
Package (0x02) { "ese-present", 1 }
}
})
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x0001, ControllerInitiated, 400000,
AddressingMode7Bit, "\\_SB.I2C7",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.I2C7.NFC1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-12-24 05:45:11 +07:00
|
|
|
#include <linux/acpi.h>
|
2014-03-25 12:51:47 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/nfc.h>
|
|
|
|
#include <linux/firmware.h>
|
2017-03-07 17:25:43 +07:00
|
|
|
|
2014-11-20 03:17:22 +07:00
|
|
|
#include <asm/unaligned.h>
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
#include <net/nfc/hci.h>
|
|
|
|
#include <net/nfc/llc.h>
|
|
|
|
#include <net/nfc/nfc.h>
|
|
|
|
|
|
|
|
#include "st21nfca.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Every frame starts with ST21NFCA_SOF_EOF and ends with ST21NFCA_SOF_EOF.
|
|
|
|
* Because ST21NFCA_SOF_EOF is a possible data value, there is a mecanism
|
|
|
|
* called byte stuffing has been introduced.
|
|
|
|
*
|
|
|
|
* if byte == ST21NFCA_SOF_EOF or ST21NFCA_ESCAPE_BYTE_STUFFING
|
|
|
|
* - insert ST21NFCA_ESCAPE_BYTE_STUFFING (escape byte)
|
|
|
|
* - xor byte with ST21NFCA_BYTE_STUFFING_MASK
|
|
|
|
*/
|
|
|
|
#define ST21NFCA_SOF_EOF 0x7e
|
|
|
|
#define ST21NFCA_BYTE_STUFFING_MASK 0x20
|
|
|
|
#define ST21NFCA_ESCAPE_BYTE_STUFFING 0x7d
|
|
|
|
|
2014-04-25 04:19:31 +07:00
|
|
|
/* SOF + 00 */
|
2014-03-25 12:51:47 +07:00
|
|
|
#define ST21NFCA_FRAME_HEADROOM 2
|
|
|
|
|
2014-04-25 04:19:31 +07:00
|
|
|
/* 2 bytes crc + EOF */
|
|
|
|
#define ST21NFCA_FRAME_TAILROOM 3
|
2014-04-25 04:19:33 +07:00
|
|
|
#define IS_START_OF_FRAME(buf) (buf[0] == ST21NFCA_SOF_EOF && \
|
|
|
|
buf[1] == 0)
|
2014-03-25 12:51:47 +07:00
|
|
|
|
2017-03-07 17:25:43 +07:00
|
|
|
#define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci"
|
2014-03-25 12:51:47 +07:00
|
|
|
#define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c"
|
|
|
|
|
|
|
|
struct st21nfca_i2c_phy {
|
|
|
|
struct i2c_client *i2c_dev;
|
|
|
|
struct nfc_hci_dev *hdev;
|
|
|
|
|
2017-03-07 17:25:45 +07:00
|
|
|
struct gpio_desc *gpiod_ena;
|
NFC: st21nfca: Adding support for secure element
st21nfca has 1 physical SWP line and can support up to 2 secure elements
(UICC & eSE) thanks to an external switch managed with a gpio.
The platform integrator needs to specify thanks to 2 initialization
properties, uicc-present and ese-present, if it is suppose to have uicc
and/or ese. Of course if the platform does not have an external switch,
only one kind of secure element can be supported. Those parameters are
under platform integrator responsibilities.
During initialization, the white_list will be set according to those
parameters.
The discovery_se function will assume a secure element is physically
present according to uicc-present and ese-present values and will add it
to the secure element list. On ese activation, the atr is retrieved to
calculate a command exchange timeout based on the first atr(TB) value.
The se_io will allow to transfer data over SWP. 2 kind of events may appear
after a data is sent over:
- ST21NFCA_EVT_TRANSMIT_DATA when receiving an apdu answer
- ST21NFCA_EVT_WTX_REQUEST when the secure element needs more time than
expected to compute a command. If this timeout expired, a first recovery
tentative consist to send a simple software reset proprietary command.
If this tentative still fail, a second recovery tentative consist to send
a hardware reset proprietary command.
This function is only relevant for eSE like secure element.
This patch also change the way a pipe is referenced. There can be
different pipe connected to the same gate with different host destination
(ex: CONNECTIVITY). In order to keep host information every pipe are
reference with a tuple (gate, host). In order to reduce changes, we are
keeping unchanged the way a gate is addressed on the Terminal Host.
However, this is working because we consider the apdu reader gate is only
present on the eSE slot also the connectivity gate cannot give a reliable
value; it will give the latest stored pipe value.
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-01-27 07:18:19 +07:00
|
|
|
struct st21nfca_se_status se_status;
|
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
struct sk_buff *pending_skb;
|
|
|
|
int current_read_len;
|
|
|
|
/*
|
|
|
|
* crc might have fail because i2c macro
|
|
|
|
* is disable due to other interface activity
|
|
|
|
*/
|
|
|
|
int crc_trials;
|
|
|
|
|
|
|
|
int powered;
|
|
|
|
int run_mode;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* < 0 if hardware error occured (e.g. i2c err)
|
|
|
|
* and prevents normal operation.
|
|
|
|
*/
|
|
|
|
int hard_fault;
|
2014-04-25 04:19:34 +07:00
|
|
|
struct mutex phy_lock;
|
2014-03-25 12:51:47 +07:00
|
|
|
};
|
2015-10-26 04:54:45 +07:00
|
|
|
|
2014-05-21 03:21:56 +07:00
|
|
|
static u8 len_seq[] = { 16, 24, 12, 29 };
|
2014-03-25 12:51:47 +07:00
|
|
|
static u16 wait_tab[] = { 2, 3, 5, 15, 20, 40};
|
|
|
|
|
|
|
|
#define I2C_DUMP_SKB(info, skb) \
|
|
|
|
do { \
|
|
|
|
pr_debug("%s:\n", info); \
|
|
|
|
print_hex_dump(KERN_DEBUG, "i2c: ", DUMP_PREFIX_OFFSET, \
|
|
|
|
16, 1, (skb)->data, (skb)->len, 0); \
|
|
|
|
} while (0)
|
|
|
|
|
2014-04-01 05:34:07 +07:00
|
|
|
/*
|
|
|
|
* In order to get the CLF in a known state we generate an internal reboot
|
|
|
|
* using a proprietary command.
|
|
|
|
* Once the reboot is completed, we expect to receive a ST21NFCA_SOF_EOF
|
|
|
|
* fill buffer.
|
|
|
|
*/
|
|
|
|
static int st21nfca_hci_platform_init(struct st21nfca_i2c_phy *phy)
|
2014-03-25 12:51:47 +07:00
|
|
|
{
|
2014-04-01 05:34:03 +07:00
|
|
|
u16 wait_reboot[] = { 50, 300, 1000 };
|
2014-03-25 12:51:47 +07:00
|
|
|
char reboot_cmd[] = { 0x7E, 0x66, 0x48, 0xF6, 0x7E };
|
|
|
|
u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE];
|
|
|
|
int i, r = -1;
|
|
|
|
|
2014-04-01 05:34:07 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(wait_reboot) && r < 0; i++) {
|
|
|
|
r = i2c_master_send(phy->i2c_dev, reboot_cmd,
|
|
|
|
sizeof(reboot_cmd));
|
|
|
|
if (r < 0)
|
|
|
|
msleep(wait_reboot[i]);
|
|
|
|
}
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* CLF is spending about 20ms to do an internal reboot */
|
|
|
|
msleep(20);
|
|
|
|
r = -1;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(wait_reboot) && r < 0; i++) {
|
2014-03-25 12:51:47 +07:00
|
|
|
r = i2c_master_recv(phy->i2c_dev, tmp,
|
|
|
|
ST21NFCA_HCI_LLC_MAX_SIZE);
|
2014-04-01 05:34:07 +07:00
|
|
|
if (r < 0)
|
|
|
|
msleep(wait_reboot[i]);
|
|
|
|
}
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
2014-04-01 05:34:07 +07:00
|
|
|
for (i = 0; i < ST21NFCA_HCI_LLC_MAX_SIZE &&
|
|
|
|
tmp[i] == ST21NFCA_SOF_EOF; i++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (r != ST21NFCA_HCI_LLC_MAX_SIZE)
|
|
|
|
return -ENODEV;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
2014-04-01 05:34:07 +07:00
|
|
|
usleep_range(1000, 1500);
|
|
|
|
return 0;
|
2014-03-25 12:51:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int st21nfca_hci_i2c_enable(void *phy_id)
|
|
|
|
{
|
|
|
|
struct st21nfca_i2c_phy *phy = phy_id;
|
|
|
|
|
2017-03-07 17:25:45 +07:00
|
|
|
gpiod_set_value(phy->gpiod_ena, 1);
|
2014-03-25 12:51:47 +07:00
|
|
|
phy->powered = 1;
|
|
|
|
phy->run_mode = ST21NFCA_HCI_MODE;
|
|
|
|
|
|
|
|
usleep_range(10000, 15000);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void st21nfca_hci_i2c_disable(void *phy_id)
|
|
|
|
{
|
|
|
|
struct st21nfca_i2c_phy *phy = phy_id;
|
|
|
|
|
2017-03-07 17:25:45 +07:00
|
|
|
gpiod_set_value(phy->gpiod_ena, 0);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
phy->powered = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-25 04:19:31 +07:00
|
|
|
static void st21nfca_hci_add_len_crc(struct sk_buff *skb)
|
2014-03-25 12:51:47 +07:00
|
|
|
{
|
|
|
|
u16 crc;
|
|
|
|
u8 tmp;
|
|
|
|
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:23 +07:00
|
|
|
*(u8 *)skb_push(skb, 1) = 0;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
crc = crc_ccitt(0xffff, skb->data, skb->len);
|
|
|
|
crc = ~crc;
|
|
|
|
|
|
|
|
tmp = crc & 0x00ff;
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:24 +07:00
|
|
|
skb_put_u8(skb, tmp);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
tmp = (crc >> 8) & 0x00ff;
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:24 +07:00
|
|
|
skb_put_u8(skb, tmp);
|
2014-03-25 12:51:47 +07:00
|
|
|
}
|
|
|
|
|
2014-04-25 04:19:31 +07:00
|
|
|
static void st21nfca_hci_remove_len_crc(struct sk_buff *skb)
|
2014-03-25 12:51:47 +07:00
|
|
|
{
|
|
|
|
skb_pull(skb, ST21NFCA_FRAME_HEADROOM);
|
2014-04-25 04:19:31 +07:00
|
|
|
skb_trim(skb, skb->len - ST21NFCA_FRAME_TAILROOM);
|
2014-03-25 12:51:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Writing a frame must not return the number of written bytes.
|
|
|
|
* It must return either zero for success, or <0 for error.
|
|
|
|
* In addition, it must not alter the skb
|
|
|
|
*/
|
|
|
|
static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
|
|
|
|
{
|
2014-04-25 04:19:31 +07:00
|
|
|
int r = -1, i, j;
|
2014-03-25 12:51:47 +07:00
|
|
|
struct st21nfca_i2c_phy *phy = phy_id;
|
|
|
|
struct i2c_client *client = phy->i2c_dev;
|
|
|
|
u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE * 2];
|
|
|
|
|
|
|
|
I2C_DUMP_SKB("st21nfca_hci_i2c_write", skb);
|
|
|
|
|
|
|
|
if (phy->hard_fault != 0)
|
|
|
|
return phy->hard_fault;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute CRC before byte stuffing computation on frame
|
|
|
|
* Note st21nfca_hci_add_len_crc is doing a byte stuffing
|
|
|
|
* on its own value
|
|
|
|
*/
|
2014-04-25 04:19:31 +07:00
|
|
|
st21nfca_hci_add_len_crc(skb);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
/* add ST21NFCA_SOF_EOF on tail */
|
networking: add and use skb_put_u8()
Joe and Bjørn suggested that it'd be nicer to not have the
cast in the fairly common case of doing
*(u8 *)skb_put(skb, 1) = c;
Add skb_put_u8() for this case, and use it across the code,
using the following spatch:
@@
expression SKB, C, S;
typedef u8;
identifier fn = {skb_put};
fresh identifier fn2 = fn ## "_u8";
@@
- *(u8 *)fn(SKB, S) = C;
+ fn2(SKB, C);
Note that due to the "S", the spatch isn't perfect, it should
have checked that S is 1, but there's also places that use a
sizeof expression like sizeof(var) or sizeof(u8) etc. Turns
out that nobody ever did something like
*(u8 *)skb_put(skb, 2) = c;
which would be wrong anyway since the second byte wouldn't be
initialized.
Suggested-by: Joe Perches <joe@perches.com>
Suggested-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:24 +07:00
|
|
|
skb_put_u8(skb, ST21NFCA_SOF_EOF);
|
2014-03-25 12:51:47 +07:00
|
|
|
/* add ST21NFCA_SOF_EOF on head */
|
networking: make skb_push & __skb_push return void pointers
It seems like a historic accident that these return unsigned char *,
and in many places that means casts are required, more often than not.
Make these functions return void * and remove all the casts across
the tree, adding a (u8 *) cast only where the unsigned char pointer
was used directly, all done with the following spatch:
@@
expression SKB, LEN;
typedef u8;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- *(fn(SKB, LEN))
+ *(u8 *)fn(SKB, LEN)
@@
expression E, SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
type T;
@@
- E = ((T *)(fn(SKB, LEN)))
+ E = fn(SKB, LEN)
@@
expression SKB, LEN;
identifier fn = { skb_push, __skb_push, skb_push_rcsum };
@@
- fn(SKB, LEN)[0]
+ *(u8 *)fn(SKB, LEN)
Note that the last part there converts from push(...)[0] to the
more idiomatic *(u8 *)push(...).
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:23 +07:00
|
|
|
*(u8 *)skb_push(skb, 1) = ST21NFCA_SOF_EOF;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute byte stuffing
|
|
|
|
* if byte == ST21NFCA_SOF_EOF or ST21NFCA_ESCAPE_BYTE_STUFFING
|
|
|
|
* insert ST21NFCA_ESCAPE_BYTE_STUFFING (escape byte)
|
|
|
|
* xor byte with ST21NFCA_BYTE_STUFFING_MASK
|
|
|
|
*/
|
|
|
|
tmp[0] = skb->data[0];
|
|
|
|
for (i = 1, j = 1; i < skb->len - 1; i++, j++) {
|
|
|
|
if (skb->data[i] == ST21NFCA_SOF_EOF
|
|
|
|
|| skb->data[i] == ST21NFCA_ESCAPE_BYTE_STUFFING) {
|
|
|
|
tmp[j] = ST21NFCA_ESCAPE_BYTE_STUFFING;
|
|
|
|
j++;
|
|
|
|
tmp[j] = skb->data[i] ^ ST21NFCA_BYTE_STUFFING_MASK;
|
|
|
|
} else {
|
|
|
|
tmp[j] = skb->data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmp[j] = skb->data[i];
|
|
|
|
j++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manage sleep mode
|
|
|
|
* Try 3 times to send data with delay between each
|
|
|
|
*/
|
2014-04-25 04:19:34 +07:00
|
|
|
mutex_lock(&phy->phy_lock);
|
2014-03-25 12:51:47 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(wait_tab) && r < 0; i++) {
|
|
|
|
r = i2c_master_send(client, tmp, j);
|
|
|
|
if (r < 0)
|
|
|
|
msleep(wait_tab[i]);
|
|
|
|
}
|
2014-04-25 04:19:34 +07:00
|
|
|
mutex_unlock(&phy->phy_lock);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
if (r >= 0) {
|
|
|
|
if (r != j)
|
|
|
|
r = -EREMOTEIO;
|
|
|
|
else
|
|
|
|
r = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-25 04:19:31 +07:00
|
|
|
st21nfca_hci_remove_len_crc(skb);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_frame_size(u8 *buf, int buflen)
|
|
|
|
{
|
|
|
|
int len = 0;
|
2014-07-28 23:11:31 +07:00
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
if (buf[len + 1] == ST21NFCA_SOF_EOF)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (len = 1; len < buflen && buf[len] != ST21NFCA_SOF_EOF; len++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int check_crc(u8 *buf, int buflen)
|
|
|
|
{
|
|
|
|
u16 crc;
|
|
|
|
|
|
|
|
crc = crc_ccitt(0xffff, buf, buflen - 2);
|
|
|
|
crc = ~crc;
|
|
|
|
|
|
|
|
if (buf[buflen - 2] != (crc & 0xff) || buf[buflen - 1] != (crc >> 8)) {
|
|
|
|
pr_err(ST21NFCA_HCI_DRIVER_NAME
|
|
|
|
": CRC error 0x%x != 0x%x 0x%x\n", crc, buf[buflen - 1],
|
|
|
|
buf[buflen - 2]);
|
|
|
|
|
|
|
|
pr_info(DRIVER_DESC ": %s : BAD CRC\n", __func__);
|
|
|
|
print_hex_dump(KERN_DEBUG, "crc: ", DUMP_PREFIX_NONE,
|
|
|
|
16, 2, buf, buflen, false);
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prepare received data for upper layer.
|
|
|
|
* Received data include byte stuffing, crc and sof/eof
|
|
|
|
* which is not usable by hci part.
|
|
|
|
* returns:
|
|
|
|
* frame size without sof/eof, header and byte stuffing
|
|
|
|
* -EBADMSG : frame was incorrect and discarded
|
|
|
|
*/
|
|
|
|
static int st21nfca_hci_i2c_repack(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int i, j, r, size;
|
2014-07-28 23:11:31 +07:00
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
if (skb->len < 1 || (skb->len > 1 && skb->data[1] != 0))
|
|
|
|
return -EBADMSG;
|
|
|
|
|
|
|
|
size = get_frame_size(skb->data, skb->len);
|
|
|
|
if (size > 0) {
|
|
|
|
skb_trim(skb, size);
|
|
|
|
/* remove ST21NFCA byte stuffing for upper layer */
|
|
|
|
for (i = 1, j = 0; i < skb->len; i++) {
|
2014-04-25 04:19:32 +07:00
|
|
|
if (skb->data[i + j] ==
|
2014-03-25 12:51:47 +07:00
|
|
|
(u8) ST21NFCA_ESCAPE_BYTE_STUFFING) {
|
2014-04-25 04:19:32 +07:00
|
|
|
skb->data[i] = skb->data[i + j + 1]
|
|
|
|
| ST21NFCA_BYTE_STUFFING_MASK;
|
2014-03-25 12:51:47 +07:00
|
|
|
i++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
skb->data[i] = skb->data[i + j];
|
|
|
|
}
|
|
|
|
/* remove byte stuffing useless byte */
|
|
|
|
skb_trim(skb, i - j);
|
|
|
|
/* remove ST21NFCA_SOF_EOF from head */
|
|
|
|
skb_pull(skb, 1);
|
|
|
|
|
|
|
|
r = check_crc(skb->data, skb->len);
|
|
|
|
if (r != 0) {
|
|
|
|
i = 0;
|
|
|
|
return -EBADMSG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove headbyte */
|
|
|
|
skb_pull(skb, 1);
|
|
|
|
/* remove crc. Byte Stuffing is already removed here */
|
|
|
|
skb_trim(skb, skb->len - 2);
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads an shdlc frame and returns it in a newly allocated sk_buff. Guarantees
|
|
|
|
* that i2c bus will be flushed and that next read will start on a new frame.
|
|
|
|
* returned skb contains only LLC header and payload.
|
|
|
|
* returns:
|
|
|
|
* frame size : if received frame is complete (find ST21NFCA_SOF_EOF at
|
|
|
|
* end of read)
|
|
|
|
* -EAGAIN : if received frame is incomplete (not find ST21NFCA_SOF_EOF
|
|
|
|
* at end of read)
|
|
|
|
* -EREMOTEIO : i2c read error (fatal)
|
|
|
|
* -EBADMSG : frame was incorrect and discarded
|
|
|
|
* (value returned from st21nfca_hci_i2c_repack)
|
|
|
|
* -EIO : if no ST21NFCA_SOF_EOF is found after reaching
|
|
|
|
* the read length end sequence
|
|
|
|
*/
|
|
|
|
static int st21nfca_hci_i2c_read(struct st21nfca_i2c_phy *phy,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int r, i;
|
|
|
|
u8 len;
|
2014-04-25 04:19:33 +07:00
|
|
|
u8 buf[ST21NFCA_HCI_LLC_MAX_PAYLOAD];
|
2014-03-25 12:51:47 +07:00
|
|
|
struct i2c_client *client = phy->i2c_dev;
|
|
|
|
|
|
|
|
if (phy->current_read_len < ARRAY_SIZE(len_seq)) {
|
|
|
|
len = len_seq[phy->current_read_len];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add retry mecanism
|
|
|
|
* Operation on I2C interface may fail in case of operation on
|
|
|
|
* RF or SWP interface
|
|
|
|
*/
|
|
|
|
r = 0;
|
2014-04-25 04:19:34 +07:00
|
|
|
mutex_lock(&phy->phy_lock);
|
2014-03-25 12:51:47 +07:00
|
|
|
for (i = 0; i < ARRAY_SIZE(wait_tab) && r <= 0; i++) {
|
2014-04-25 04:19:33 +07:00
|
|
|
r = i2c_master_recv(client, buf, len);
|
2014-03-25 12:51:47 +07:00
|
|
|
if (r < 0)
|
|
|
|
msleep(wait_tab[i]);
|
|
|
|
}
|
2014-04-25 04:19:34 +07:00
|
|
|
mutex_unlock(&phy->phy_lock);
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
if (r != len) {
|
|
|
|
phy->current_read_len = 0;
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
|
|
|
|
2014-04-25 04:19:33 +07:00
|
|
|
/*
|
|
|
|
* The first read sequence does not start with SOF.
|
|
|
|
* Data is corrupeted so we drop it.
|
|
|
|
*/
|
2014-05-21 03:21:55 +07:00
|
|
|
if (!phy->current_read_len && !IS_START_OF_FRAME(buf)) {
|
2014-04-25 04:19:33 +07:00
|
|
|
skb_trim(skb, 0);
|
|
|
|
phy->current_read_len = 0;
|
|
|
|
return -EIO;
|
2014-05-21 03:21:55 +07:00
|
|
|
} else if (phy->current_read_len && IS_START_OF_FRAME(buf)) {
|
2014-04-25 04:19:33 +07:00
|
|
|
/*
|
|
|
|
* Previous frame transmission was interrupted and
|
|
|
|
* the frame got repeated.
|
|
|
|
* Received frame start with ST21NFCA_SOF_EOF + 00.
|
|
|
|
*/
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
phy->current_read_len = 0;
|
|
|
|
}
|
|
|
|
|
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 19:29:20 +07:00
|
|
|
skb_put_data(skb, buf, len);
|
2014-04-25 04:19:33 +07:00
|
|
|
|
|
|
|
if (skb->data[skb->len - 1] == ST21NFCA_SOF_EOF) {
|
2014-03-25 12:51:47 +07:00
|
|
|
phy->current_read_len = 0;
|
|
|
|
return st21nfca_hci_i2c_repack(skb);
|
|
|
|
}
|
|
|
|
phy->current_read_len++;
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads an shdlc frame from the chip. This is not as straightforward as it
|
|
|
|
* seems. The frame format is data-crc, and corruption can occur anywhere
|
|
|
|
* while transiting on i2c bus, such that we could read an invalid data.
|
|
|
|
* The tricky case is when we read a corrupted data or crc. We must detect
|
|
|
|
* this here in order to determine that data can be transmitted to the hci
|
|
|
|
* core. This is the reason why we check the crc here.
|
|
|
|
* The CLF will repeat a frame until we send a RR on that frame.
|
|
|
|
*
|
|
|
|
* On ST21NFCA, IRQ goes in idle when read starts. As no size information are
|
|
|
|
* available in the incoming data, other IRQ might come. Every IRQ will trigger
|
|
|
|
* a read sequence with different length and will fill the current frame.
|
|
|
|
* The reception is complete once we reach a ST21NFCA_SOF_EOF.
|
|
|
|
*/
|
|
|
|
static irqreturn_t st21nfca_hci_irq_thread_fn(int irq, void *phy_id)
|
|
|
|
{
|
|
|
|
struct st21nfca_i2c_phy *phy = phy_id;
|
|
|
|
struct i2c_client *client;
|
|
|
|
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (!phy || irq != phy->i2c_dev->irq) {
|
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = phy->i2c_dev;
|
|
|
|
dev_dbg(&client->dev, "IRQ\n");
|
|
|
|
|
|
|
|
if (phy->hard_fault != 0)
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
r = st21nfca_hci_i2c_read(phy, phy->pending_skb);
|
|
|
|
if (r == -EREMOTEIO) {
|
|
|
|
phy->hard_fault = r;
|
|
|
|
|
|
|
|
nfc_hci_recv_frame(phy->hdev, NULL);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
} else if (r == -EAGAIN || r == -EIO) {
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
} else if (r == -EBADMSG && phy->crc_trials < ARRAY_SIZE(wait_tab)) {
|
|
|
|
/*
|
|
|
|
* With ST21NFCA, only one interface (I2C, RF or SWP)
|
|
|
|
* may be active at a time.
|
|
|
|
* Having incorrect crc is usually due to i2c macrocell
|
|
|
|
* deactivation in the middle of a transmission.
|
|
|
|
* It may generate corrupted data on i2c.
|
|
|
|
* We give sometime to get i2c back.
|
|
|
|
* The complete frame will be repeated.
|
|
|
|
*/
|
|
|
|
msleep(wait_tab[phy->crc_trials]);
|
|
|
|
phy->crc_trials++;
|
|
|
|
phy->current_read_len = 0;
|
2014-04-25 04:19:35 +07:00
|
|
|
kfree_skb(phy->pending_skb);
|
2014-03-25 12:51:47 +07:00
|
|
|
} else if (r > 0) {
|
|
|
|
/*
|
|
|
|
* We succeeded to read data from the CLF and
|
|
|
|
* data is valid.
|
|
|
|
* Reset counter.
|
|
|
|
*/
|
|
|
|
nfc_hci_recv_frame(phy->hdev, phy->pending_skb);
|
|
|
|
phy->crc_trials = 0;
|
2014-05-21 03:21:54 +07:00
|
|
|
} else {
|
|
|
|
kfree_skb(phy->pending_skb);
|
2014-03-25 12:51:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
phy->pending_skb = alloc_skb(ST21NFCA_HCI_LLC_MAX_SIZE * 2, GFP_KERNEL);
|
|
|
|
if (phy->pending_skb == NULL) {
|
|
|
|
phy->hard_fault = -ENOMEM;
|
|
|
|
nfc_hci_recv_frame(phy->hdev, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nfc_phy_ops i2c_phy_ops = {
|
|
|
|
.write = st21nfca_hci_i2c_write,
|
|
|
|
.enable = st21nfca_hci_i2c_enable,
|
|
|
|
.disable = st21nfca_hci_i2c_disable,
|
|
|
|
};
|
|
|
|
|
2017-06-19 17:08:47 +07:00
|
|
|
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 },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
static int st21nfca_hci_i2c_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2017-06-19 17:08:48 +07:00
|
|
|
struct device *dev = &client->dev;
|
2014-03-25 12:51:47 +07:00
|
|
|
struct st21nfca_i2c_phy *phy;
|
2014-04-01 05:34:06 +07:00
|
|
|
int r;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s\n", __func__);
|
|
|
|
dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
|
|
|
|
|
|
|
|
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
|
|
|
|
nfc_err(&client->dev, "Need I2C_FUNC_I2C\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy = devm_kzalloc(&client->dev, sizeof(struct st21nfca_i2c_phy),
|
|
|
|
GFP_KERNEL);
|
2015-01-26 05:33:27 +07:00
|
|
|
if (!phy)
|
2014-03-25 12:51:47 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
phy->i2c_dev = client;
|
2014-04-01 05:34:06 +07:00
|
|
|
phy->pending_skb = alloc_skb(ST21NFCA_HCI_LLC_MAX_SIZE * 2, GFP_KERNEL);
|
|
|
|
if (phy->pending_skb == NULL)
|
|
|
|
return -ENOMEM;
|
2014-03-25 12:51:47 +07:00
|
|
|
|
2014-04-01 05:34:06 +07:00
|
|
|
phy->current_read_len = 0;
|
|
|
|
phy->crc_trials = 0;
|
2014-04-25 04:19:34 +07:00
|
|
|
mutex_init(&phy->phy_lock);
|
2014-03-25 12:51:47 +07:00
|
|
|
i2c_set_clientdata(client, phy);
|
|
|
|
|
2017-06-19 17:08:48 +07:00
|
|
|
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);
|
2014-04-01 05:34:06 +07:00
|
|
|
}
|
|
|
|
|
2017-03-07 17:25:46 +07:00
|
|
|
phy->se_status.is_ese_present =
|
|
|
|
device_property_read_bool(&client->dev, "ese-present");
|
|
|
|
phy->se_status.is_uicc_present =
|
|
|
|
device_property_read_bool(&client->dev, "uicc-present");
|
|
|
|
|
2014-04-01 05:34:07 +07:00
|
|
|
r = st21nfca_hci_platform_init(phy);
|
|
|
|
if (r < 0) {
|
|
|
|
nfc_err(&client->dev, "Unable to reboot st21nfca\n");
|
2014-12-03 03:27:55 +07:00
|
|
|
return r;
|
2014-04-01 05:34:07 +07:00
|
|
|
}
|
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
|
|
|
|
st21nfca_hci_irq_thread_fn,
|
2017-03-07 17:25:44 +07:00
|
|
|
IRQF_ONESHOT,
|
2014-03-25 12:51:47 +07:00
|
|
|
ST21NFCA_HCI_DRIVER_NAME, phy);
|
|
|
|
if (r < 0) {
|
|
|
|
nfc_err(&client->dev, "Unable to register IRQ handler\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-04-01 05:34:05 +07:00
|
|
|
return st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
|
NFC: st21nfca: Adding support for secure element
st21nfca has 1 physical SWP line and can support up to 2 secure elements
(UICC & eSE) thanks to an external switch managed with a gpio.
The platform integrator needs to specify thanks to 2 initialization
properties, uicc-present and ese-present, if it is suppose to have uicc
and/or ese. Of course if the platform does not have an external switch,
only one kind of secure element can be supported. Those parameters are
under platform integrator responsibilities.
During initialization, the white_list will be set according to those
parameters.
The discovery_se function will assume a secure element is physically
present according to uicc-present and ese-present values and will add it
to the secure element list. On ese activation, the atr is retrieved to
calculate a command exchange timeout based on the first atr(TB) value.
The se_io will allow to transfer data over SWP. 2 kind of events may appear
after a data is sent over:
- ST21NFCA_EVT_TRANSMIT_DATA when receiving an apdu answer
- ST21NFCA_EVT_WTX_REQUEST when the secure element needs more time than
expected to compute a command. If this timeout expired, a first recovery
tentative consist to send a simple software reset proprietary command.
If this tentative still fail, a second recovery tentative consist to send
a hardware reset proprietary command.
This function is only relevant for eSE like secure element.
This patch also change the way a pipe is referenced. There can be
different pipe connected to the same gate with different host destination
(ex: CONNECTIVITY). In order to keep host information every pipe are
reference with a tuple (gate, host). In order to reduce changes, we are
keeping unchanged the way a gate is addressed on the Terminal Host.
However, this is working because we consider the apdu reader gate is only
present on the eSE slot also the connectivity gate cannot give a reliable
value; it will give the latest stored pipe value.
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-01-27 07:18:19 +07:00
|
|
|
ST21NFCA_FRAME_HEADROOM,
|
|
|
|
ST21NFCA_FRAME_TAILROOM,
|
|
|
|
ST21NFCA_HCI_LLC_MAX_PAYLOAD,
|
|
|
|
&phy->hdev,
|
|
|
|
&phy->se_status);
|
2014-03-25 12:51:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int st21nfca_hci_i2c_remove(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
st21nfca_hci_remove(phy->hdev);
|
|
|
|
|
|
|
|
if (phy->powered)
|
|
|
|
st21nfca_hci_i2c_disable(phy);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-22 00:04:00 +07:00
|
|
|
static const struct i2c_device_id st21nfca_hci_i2c_id_table[] = {
|
2015-12-24 05:45:06 +07:00
|
|
|
{ST21NFCA_HCI_DRIVER_NAME, 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, st21nfca_hci_i2c_id_table);
|
|
|
|
|
nfc: st21nfca: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2100 is used for st21nfca
It has been tested with the following acpi node on Minnowboard Max:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2100") // _HID: Hardware ID
Name (_CID, "SMO2100") // _CID: Compatible ID
Name (_DDN, "SMO NFC") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Name (_DSD, Package (0x02)
{
/* Device Properties for _DSD */
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package (0x02)
{
Package (0x02) { "uicc-present", 1 },
Package (0x02) { "ese-present", 1 }
}
})
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x0001, ControllerInitiated, 400000,
AddressingMode7Bit, "\\_SB.I2C7",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.I2C7.NFC1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-12-24 05:45:11 +07:00
|
|
|
static const struct acpi_device_id st21nfca_hci_i2c_acpi_match[] = {
|
|
|
|
{"SMO2100", 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, st21nfca_hci_i2c_acpi_match);
|
|
|
|
|
2014-05-14 03:03:39 +07:00
|
|
|
static const struct of_device_id of_st21nfca_i2c_match[] = {
|
2014-12-09 04:08:06 +07:00
|
|
|
{ .compatible = "st,st21nfca-i2c", },
|
2014-05-14 03:03:39 +07:00
|
|
|
{ .compatible = "st,st21nfca_i2c", },
|
|
|
|
{}
|
|
|
|
};
|
2014-11-13 06:30:22 +07:00
|
|
|
MODULE_DEVICE_TABLE(of, of_st21nfca_i2c_match);
|
2014-05-14 03:03:39 +07:00
|
|
|
|
2014-03-25 12:51:47 +07:00
|
|
|
static struct i2c_driver st21nfca_hci_i2c_driver = {
|
|
|
|
.driver = {
|
2014-04-01 05:34:06 +07:00
|
|
|
.name = ST21NFCA_HCI_I2C_DRIVER_NAME,
|
2014-05-14 03:03:39 +07:00
|
|
|
.of_match_table = of_match_ptr(of_st21nfca_i2c_match),
|
nfc: st21nfca: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2100 is used for st21nfca
It has been tested with the following acpi node on Minnowboard Max:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2100") // _HID: Hardware ID
Name (_CID, "SMO2100") // _CID: Compatible ID
Name (_DDN, "SMO NFC") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Name (_DSD, Package (0x02)
{
/* Device Properties for _DSD */
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package (0x02)
{
Package (0x02) { "uicc-present", 1 },
Package (0x02) { "ese-present", 1 }
}
})
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x0001, ControllerInitiated, 400000,
AddressingMode7Bit, "\\_SB.I2C7",
0x00, ResourceConsumer, ,)
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0001
}
GpioIo (Exclusive, PullDefault, 0x0000, 0x0000, IoRestrictionOutputOnly,
"\\_SB.GPO2", 0x00, ResourceConsumer, ,)
{ // Pin list
0x0002,
}
})
Return (SBUF) /* \_SB_.I2C7.NFC1._CRS.SBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
Return (0x0F)
}
}
Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
2015-12-24 05:45:11 +07:00
|
|
|
.acpi_match_table = ACPI_PTR(st21nfca_hci_i2c_acpi_match),
|
2014-04-01 05:34:06 +07:00
|
|
|
},
|
2014-03-25 12:51:47 +07:00
|
|
|
.probe = st21nfca_hci_i2c_probe,
|
|
|
|
.id_table = st21nfca_hci_i2c_id_table,
|
|
|
|
.remove = st21nfca_hci_i2c_remove,
|
|
|
|
};
|
|
|
|
module_i2c_driver(st21nfca_hci_i2c_driver);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|