2014-05-26 03:35:38 +07:00
|
|
|
/*
|
2015-06-10 03:26:05 +07:00
|
|
|
* I2C Link Layer for ST NCI NFC controller familly based Driver
|
|
|
|
* Copyright (C) 2014-2015 STMicroelectronics SAS. All rights reserved.
|
2014-05-26 03:35:38 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/gpio.h>
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
#include <linux/gpio/consumer.h>
|
2014-05-26 03:35:38 +07:00
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_gpio.h>
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
#include <linux/acpi.h>
|
2014-05-26 03:35:38 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/nfc.h>
|
2015-08-15 03:33:30 +07:00
|
|
|
#include <linux/platform_data/st-nci.h>
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-10-26 04:54:17 +07:00
|
|
|
#include "st-nci.h"
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-08-15 03:33:31 +07:00
|
|
|
#define DRIVER_DESC "NCI NFC driver for ST_NCI"
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
/* ndlc header */
|
2015-10-26 04:54:44 +07:00
|
|
|
#define ST_NCI_FRAME_HEADROOM 1
|
2015-08-15 03:33:31 +07:00
|
|
|
#define ST_NCI_FRAME_TAILROOM 0
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
#define ST_NCI_I2C_MIN_SIZE 4 /* PCB(1) + NCI Packet header(3) */
|
|
|
|
#define ST_NCI_I2C_MAX_SIZE 250 /* req 4.2.1 */
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
#define ST_NCI_I2C_DRIVER_NAME "st_nci_i2c"
|
2014-05-26 03:35:38 +07:00
|
|
|
|
nfc: st-nci: i2c: Change ST_NCI_GPIO_NAME_RESET to match DT
Since
commit 10cf4899f8af ("gpiolib: tighten up ACPI legacy gpio lookups")
If _DSD properties are available in an ACPI node, we are not
allowed to fallback to _CRS data to retrieve gpio properties.
This was causing us to fail if uicc-present and/or ese-present
are defined.
To be consistent with devicetree change ST_NCI_GPIO_NAME_RESET
content to reset so that acpi_find_gpio in drivers/gpio/gpiolib.c
will look for reset-gpios. In the mean time the ACPI table needs
to be fixed as follow:
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _CID: Compatible ID
Name (_DDN, "SMO NFC") // _DDN: DOS Device Name
Name (_UID, One) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (SBUF, ResourceTemplate ()
{
I2cSerialBus (0x0008, 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,
}
})
Name (_DSD, Package (0x02)
{
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") /* Device Properties for _DSD */,
Package (0x03)
{
Package (0x02) { "uicc-present", 1 },
Package (0x02) { "ese-present", 1 },
Package (0x02) { "reset-gpios", Package(0x04) { ^NFC1, 1, 0, 0} },
}
})
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>
2016-04-30 14:12:35 +07:00
|
|
|
#define ST_NCI_GPIO_NAME_RESET "reset"
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy {
|
2014-05-26 03:35:38 +07:00
|
|
|
struct i2c_client *i2c_dev;
|
|
|
|
struct llt_ndlc *ndlc;
|
|
|
|
|
2015-10-26 04:54:48 +07:00
|
|
|
bool irq_active;
|
|
|
|
|
2014-05-26 03:35:38 +07:00
|
|
|
unsigned int gpio_reset;
|
|
|
|
unsigned int irq_polarity;
|
2015-10-26 04:54:39 +07:00
|
|
|
|
|
|
|
struct st_nci_se_status se_status;
|
2014-05-26 03:35:38 +07:00
|
|
|
};
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_enable(void *phy_id)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = phy_id;
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
gpio_set_value(phy->gpio_reset, 0);
|
|
|
|
usleep_range(10000, 15000);
|
|
|
|
gpio_set_value(phy->gpio_reset, 1);
|
|
|
|
usleep_range(80000, 85000);
|
|
|
|
|
2015-10-26 04:54:48 +07:00
|
|
|
if (phy->ndlc->powered == 0 && phy->irq_active == 0) {
|
2015-06-06 18:16:51 +07:00
|
|
|
enable_irq(phy->i2c_dev->irq);
|
2015-10-26 04:54:48 +07:00
|
|
|
phy->irq_active = true;
|
|
|
|
}
|
2015-06-06 18:16:51 +07:00
|
|
|
|
2014-05-26 03:35:38 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static void st_nci_i2c_disable(void *phy_id)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = phy_id;
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-06-06 18:16:51 +07:00
|
|
|
disable_irq_nosync(phy->i2c_dev->irq);
|
2015-10-26 04:54:48 +07:00
|
|
|
phy->irq_active = false;
|
2014-05-26 03:35:38 +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
|
|
|
|
*/
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_write(void *phy_id, struct sk_buff *skb)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
|
|
|
int r = -1;
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = phy_id;
|
2014-05-26 03:35:38 +07:00
|
|
|
struct i2c_client *client = phy->i2c_dev;
|
|
|
|
|
2014-09-13 15:28:47 +07:00
|
|
|
if (phy->ndlc->hard_fault != 0)
|
|
|
|
return phy->ndlc->hard_fault;
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
r = i2c_master_send(client, skb->data, skb->len);
|
2015-03-31 13:02:15 +07:00
|
|
|
if (r < 0) { /* Retry, chip was in standby */
|
2014-05-26 03:35:38 +07:00
|
|
|
usleep_range(1000, 4000);
|
|
|
|
r = i2c_master_send(client, skb->data, skb->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r >= 0) {
|
|
|
|
if (r != skb->len)
|
|
|
|
r = -EREMOTEIO;
|
|
|
|
else
|
|
|
|
r = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads an ndlc frame and returns it in a newly allocated sk_buff.
|
|
|
|
* returns:
|
2015-08-15 03:33:32 +07:00
|
|
|
* 0 : if received frame is complete
|
2014-05-26 03:35:38 +07:00
|
|
|
* -EREMOTEIO : i2c read error (fatal)
|
|
|
|
* -EBADMSG : frame was incorrect and discarded
|
2015-08-15 03:33:32 +07:00
|
|
|
* -ENOMEM : cannot allocate skb, frame dropped
|
2014-05-26 03:35:38 +07:00
|
|
|
*/
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_read(struct st_nci_i2c_phy *phy,
|
2014-05-26 03:35:38 +07:00
|
|
|
struct sk_buff **skb)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
u8 len;
|
2015-06-10 03:26:05 +07:00
|
|
|
u8 buf[ST_NCI_I2C_MAX_SIZE];
|
2014-05-26 03:35:38 +07:00
|
|
|
struct i2c_client *client = phy->i2c_dev;
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE);
|
2015-03-31 13:02:15 +07:00
|
|
|
if (r < 0) { /* Retry, chip was in standby */
|
2014-05-26 03:35:38 +07:00
|
|
|
usleep_range(1000, 4000);
|
2015-06-10 03:26:05 +07:00
|
|
|
r = i2c_master_recv(client, buf, ST_NCI_I2C_MIN_SIZE);
|
2014-09-04 04:30:26 +07:00
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
if (r != ST_NCI_I2C_MIN_SIZE)
|
2014-05-26 03:35:38 +07:00
|
|
|
return -EREMOTEIO;
|
|
|
|
|
|
|
|
len = be16_to_cpu(*(__be16 *) (buf + 2));
|
2015-06-10 03:26:05 +07:00
|
|
|
if (len > ST_NCI_I2C_MAX_SIZE) {
|
2014-05-26 03:35:38 +07:00
|
|
|
nfc_err(&client->dev, "invalid frame len\n");
|
|
|
|
return -EBADMSG;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
*skb = alloc_skb(ST_NCI_I2C_MIN_SIZE + len, GFP_KERNEL);
|
2014-05-26 03:35:38 +07:00
|
|
|
if (*skb == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
skb_reserve(*skb, ST_NCI_I2C_MIN_SIZE);
|
|
|
|
skb_put(*skb, ST_NCI_I2C_MIN_SIZE);
|
|
|
|
memcpy((*skb)->data, buf, ST_NCI_I2C_MIN_SIZE);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = i2c_master_recv(client, buf, len);
|
|
|
|
if (r != len) {
|
|
|
|
kfree_skb(*skb);
|
|
|
|
return -EREMOTEIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
skb_put(*skb, len);
|
2015-06-10 03:26:05 +07:00
|
|
|
memcpy((*skb)->data + ST_NCI_I2C_MIN_SIZE, buf, len);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads an ndlc frame from the chip.
|
|
|
|
*
|
2015-08-15 03:33:31 +07:00
|
|
|
* On ST_NCI, IRQ goes in idle state when read starts.
|
2014-05-26 03:35:38 +07:00
|
|
|
*/
|
2015-06-10 03:26:05 +07:00
|
|
|
static irqreturn_t st_nci_irq_thread_fn(int irq, void *phy_id)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = phy_id;
|
2014-05-26 03:35:38 +07:00
|
|
|
struct i2c_client *client;
|
|
|
|
struct sk_buff *skb = NULL;
|
|
|
|
int r;
|
|
|
|
|
2015-01-26 05:33:29 +07:00
|
|
|
if (!phy || !phy->ndlc || irq != phy->i2c_dev->irq) {
|
2014-05-26 03:35:38 +07:00
|
|
|
WARN_ON_ONCE(1);
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
client = phy->i2c_dev;
|
|
|
|
dev_dbg(&client->dev, "IRQ\n");
|
|
|
|
|
2014-09-13 15:28:47 +07:00
|
|
|
if (phy->ndlc->hard_fault)
|
2014-05-26 03:35:38 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
2015-06-06 18:16:50 +07:00
|
|
|
if (!phy->ndlc->powered) {
|
2015-06-10 03:26:05 +07:00
|
|
|
st_nci_i2c_disable(phy);
|
2014-05-26 03:35:38 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
r = st_nci_i2c_read(phy, &skb);
|
2014-09-13 15:28:47 +07:00
|
|
|
if (r == -EREMOTEIO || r == -ENOMEM || r == -EBADMSG)
|
2014-05-26 03:35:38 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
|
|
|
ndlc_recv(phy->ndlc, skb);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nfc_phy_ops i2c_phy_ops = {
|
2015-06-10 03:26:05 +07:00
|
|
|
.write = st_nci_i2c_write,
|
|
|
|
.enable = st_nci_i2c_enable,
|
|
|
|
.disable = st_nci_i2c_disable,
|
2014-05-26 03:35:38 +07:00
|
|
|
};
|
|
|
|
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
static int st_nci_i2c_acpi_request_resources(struct i2c_client *client)
|
|
|
|
{
|
|
|
|
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
|
|
|
|
struct gpio_desc *gpiod_reset;
|
2016-04-30 14:12:45 +07:00
|
|
|
struct device *dev = &client->dev;
|
2016-04-30 14:12:39 +07:00
|
|
|
u8 tmp;
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
|
|
|
|
/* Get RESET GPIO from ACPI */
|
|
|
|
gpiod_reset = devm_gpiod_get_index(dev, ST_NCI_GPIO_NAME_RESET, 1,
|
|
|
|
GPIOD_OUT_HIGH);
|
|
|
|
if (IS_ERR(gpiod_reset)) {
|
|
|
|
nfc_err(dev, "Unable to get RESET GPIO\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
phy->gpio_reset = desc_to_gpio(gpiod_reset);
|
|
|
|
|
|
|
|
phy->irq_polarity = irq_get_trigger_type(client->irq);
|
|
|
|
|
2016-04-30 14:12:39 +07:00
|
|
|
phy->se_status.is_ese_present = false;
|
|
|
|
phy->se_status.is_uicc_present = false;
|
|
|
|
|
|
|
|
if (device_property_present(dev, "ese-present")) {
|
|
|
|
device_property_read_u8(dev, "ese-present", &tmp);
|
|
|
|
phy->se_status.is_ese_present = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device_property_present(dev, "uicc-present")) {
|
|
|
|
device_property_read_u8(dev, "uicc-present", &tmp);
|
|
|
|
phy->se_status.is_uicc_present = tmp;
|
|
|
|
}
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_of_request_resources(struct i2c_client *client)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
|
2014-05-26 03:35:38 +07:00
|
|
|
struct device_node *pp;
|
|
|
|
int gpio;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
pp = client->dev.of_node;
|
|
|
|
if (!pp)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Get GPIO from device tree */
|
|
|
|
gpio = of_get_named_gpio(pp, "reset-gpios", 0);
|
|
|
|
if (gpio < 0) {
|
|
|
|
nfc_err(&client->dev,
|
|
|
|
"Failed to retrieve reset-gpios from device tree\n");
|
|
|
|
return gpio;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPIO request and configuration */
|
2014-07-28 23:11:33 +07:00
|
|
|
r = devm_gpio_request_one(&client->dev, gpio,
|
2015-12-24 05:45:07 +07:00
|
|
|
GPIOF_OUT_INIT_HIGH, ST_NCI_GPIO_NAME_RESET);
|
2014-05-26 03:35:38 +07:00
|
|
|
if (r) {
|
|
|
|
nfc_err(&client->dev, "Failed to request reset pin\n");
|
2014-12-03 03:27:56 +07:00
|
|
|
return r;
|
2014-05-26 03:35:38 +07:00
|
|
|
}
|
|
|
|
phy->gpio_reset = gpio;
|
|
|
|
|
2014-11-13 06:30:26 +07:00
|
|
|
phy->irq_polarity = irq_get_trigger_type(client->irq);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-10-26 04:54:39 +07:00
|
|
|
phy->se_status.is_ese_present =
|
|
|
|
of_property_read_bool(pp, "ese-present");
|
|
|
|
phy->se_status.is_uicc_present =
|
|
|
|
of_property_read_bool(pp, "uicc-present");
|
|
|
|
|
2014-05-26 03:35:38 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_request_resources(struct i2c_client *client)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_nfc_platform_data *pdata;
|
|
|
|
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
|
2014-05-26 03:35:38 +07:00
|
|
|
int r;
|
|
|
|
|
|
|
|
pdata = client->dev.platform_data;
|
|
|
|
if (pdata == NULL) {
|
|
|
|
nfc_err(&client->dev, "No platform data\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store for later use */
|
|
|
|
phy->gpio_reset = pdata->gpio_reset;
|
|
|
|
phy->irq_polarity = pdata->irq_polarity;
|
|
|
|
|
2014-07-28 23:11:33 +07:00
|
|
|
r = devm_gpio_request_one(&client->dev,
|
2015-12-24 05:45:07 +07:00
|
|
|
phy->gpio_reset, GPIOF_OUT_INIT_HIGH,
|
|
|
|
ST_NCI_GPIO_NAME_RESET);
|
2014-05-26 03:35:38 +07:00
|
|
|
if (r) {
|
|
|
|
pr_err("%s : reset gpio_request failed\n", __FILE__);
|
2014-12-03 03:27:56 +07:00
|
|
|
return r;
|
2014-05-26 03:35:38 +07:00
|
|
|
}
|
|
|
|
|
2015-10-26 04:54:39 +07:00
|
|
|
phy->se_status.is_ese_present = pdata->is_ese_present;
|
|
|
|
phy->se_status.is_uicc_present = pdata->is_uicc_present;
|
|
|
|
|
2014-05-26 03:35:38 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_probe(struct i2c_client *client,
|
2014-05-26 03:35:38 +07:00
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy;
|
|
|
|
struct st_nci_nfc_platform_data *pdata;
|
2014-05-26 03:35:38 +07:00
|
|
|
int r;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
phy = devm_kzalloc(&client->dev, sizeof(struct st_nci_i2c_phy),
|
2014-05-26 03:35:38 +07:00
|
|
|
GFP_KERNEL);
|
2015-04-07 14:17:00 +07:00
|
|
|
if (!phy)
|
2014-05-26 03:35:38 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
phy->i2c_dev = client;
|
|
|
|
|
|
|
|
i2c_set_clientdata(client, phy);
|
|
|
|
|
|
|
|
pdata = client->dev.platform_data;
|
|
|
|
if (!pdata && client->dev.of_node) {
|
2015-06-10 03:26:05 +07:00
|
|
|
r = st_nci_i2c_of_request_resources(client);
|
2014-05-26 03:35:38 +07:00
|
|
|
if (r) {
|
|
|
|
nfc_err(&client->dev, "No platform data\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
} else if (pdata) {
|
2015-06-10 03:26:05 +07:00
|
|
|
r = st_nci_i2c_request_resources(client);
|
2014-05-26 03:35:38 +07:00
|
|
|
if (r) {
|
|
|
|
nfc_err(&client->dev,
|
|
|
|
"Cannot get platform resources\n");
|
|
|
|
return r;
|
|
|
|
}
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
} else if (ACPI_HANDLE(&client->dev)) {
|
|
|
|
r = st_nci_i2c_acpi_request_resources(client);
|
|
|
|
if (r) {
|
|
|
|
nfc_err(&client->dev, "Cannot get ACPI data\n");
|
|
|
|
return r;
|
|
|
|
}
|
2014-05-26 03:35:38 +07:00
|
|
|
} else {
|
|
|
|
nfc_err(&client->dev,
|
2015-08-15 03:33:31 +07:00
|
|
|
"st_nci platform resources not available\n");
|
2014-05-26 03:35:38 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2015-01-26 05:33:29 +07:00
|
|
|
r = ndlc_probe(phy, &i2c_phy_ops, &client->dev,
|
2015-08-15 03:33:31 +07:00
|
|
|
ST_NCI_FRAME_HEADROOM, ST_NCI_FRAME_TAILROOM,
|
2015-10-26 04:54:39 +07:00
|
|
|
&phy->ndlc, &phy->se_status);
|
2015-01-26 05:33:29 +07:00
|
|
|
if (r < 0) {
|
|
|
|
nfc_err(&client->dev, "Unable to register ndlc layer\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-10-26 04:54:48 +07:00
|
|
|
phy->irq_active = true;
|
2014-05-26 03:35:38 +07:00
|
|
|
r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
|
2015-06-10 03:26:05 +07:00
|
|
|
st_nci_irq_thread_fn,
|
2014-05-26 03:35:38 +07:00
|
|
|
phy->irq_polarity | IRQF_ONESHOT,
|
2015-06-10 03:26:05 +07:00
|
|
|
ST_NCI_DRIVER_NAME, phy);
|
2015-01-26 05:33:29 +07:00
|
|
|
if (r < 0)
|
2014-05-26 03:35:38 +07:00
|
|
|
nfc_err(&client->dev, "Unable to register IRQ handler\n");
|
|
|
|
|
2015-01-26 05:33:29 +07:00
|
|
|
return r;
|
2014-05-26 03:35:38 +07:00
|
|
|
}
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static int st_nci_i2c_remove(struct i2c_client *client)
|
2014-05-26 03:35:38 +07:00
|
|
|
{
|
2015-06-10 03:26:05 +07:00
|
|
|
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
dev_dbg(&client->dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
ndlc_remove(phy->ndlc);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-24 05:45:05 +07:00
|
|
|
static struct i2c_device_id st_nci_i2c_id_table[] = {
|
|
|
|
{ST_NCI_DRIVER_NAME, 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, st_nci_i2c_id_table);
|
|
|
|
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
static const struct acpi_device_id st_nci_i2c_acpi_match[] = {
|
|
|
|
{"SMO2101"},
|
|
|
|
{"SMO2102"},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, st_nci_i2c_acpi_match);
|
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static const struct of_device_id of_st_nci_i2c_match[] = {
|
2014-12-09 04:08:07 +07:00
|
|
|
{ .compatible = "st,st21nfcb-i2c", },
|
2014-05-26 03:35:38 +07:00
|
|
|
{ .compatible = "st,st21nfcb_i2c", },
|
2015-06-10 03:26:05 +07:00
|
|
|
{ .compatible = "st,st21nfcc-i2c", },
|
2014-05-26 03:35:38 +07:00
|
|
|
{}
|
|
|
|
};
|
2015-06-10 03:26:05 +07:00
|
|
|
MODULE_DEVICE_TABLE(of, of_st_nci_i2c_match);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
2015-06-10 03:26:05 +07:00
|
|
|
static struct i2c_driver st_nci_i2c_driver = {
|
2014-05-26 03:35:38 +07:00
|
|
|
.driver = {
|
2015-06-10 03:26:05 +07:00
|
|
|
.name = ST_NCI_I2C_DRIVER_NAME,
|
|
|
|
.of_match_table = of_match_ptr(of_st_nci_i2c_match),
|
nfc: st-nci: Add support for acpi probing for i2c device.
Add support for acpi probing.
SMO2101 is used for st21nfcb
SMO2102 is used for st21nfcc
It has been tested with the following acpi node on Minnowboard:
Note: Remove uicc-present or ese-present Package if one them is not
supported.
Device (NFC1)
{
Name (_ADR, Zero) // _ADR: Address
Name (_HID, "SMO2101") // _HID: Hardware ID
Name (_CID, "SMO2101") // _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 (0x0008, 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:09 +07:00
|
|
|
.acpi_match_table = ACPI_PTR(st_nci_i2c_acpi_match),
|
2014-05-26 03:35:38 +07:00
|
|
|
},
|
2015-06-10 03:26:05 +07:00
|
|
|
.probe = st_nci_i2c_probe,
|
|
|
|
.id_table = st_nci_i2c_id_table,
|
|
|
|
.remove = st_nci_i2c_remove,
|
2014-05-26 03:35:38 +07:00
|
|
|
};
|
2015-06-10 03:26:05 +07:00
|
|
|
module_i2c_driver(st_nci_i2c_driver);
|
2014-05-26 03:35:38 +07:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|