mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-18 03:06:43 +00:00
NFC: dts: st21nfca: Add device-tree (Open Firmware) support to st21nfca
Add functions to recover hardware resources from the device-tree when not provided by the platform data. Based on pn544 devicetree implementation Signed-off-by: Christophe Ricard <christophe-h.ricard@st.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
0515829642
commit
c44cb2edd0
@ -21,6 +21,8 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/i2c.h>
|
#include <linux/i2c.h>
|
||||||
#include <linux/gpio.h>
|
#include <linux/gpio.h>
|
||||||
|
#include <linux/of_irq.h>
|
||||||
|
#include <linux/of_gpio.h>
|
||||||
#include <linux/miscdevice.h>
|
#include <linux/miscdevice.h>
|
||||||
#include <linux/interrupt.h>
|
#include <linux/interrupt.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
@ -502,11 +504,65 @@ static struct nfc_phy_ops i2c_phy_ops = {
|
|||||||
.disable = st21nfca_hci_i2c_disable,
|
.disable = st21nfca_hci_i2c_disable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef CONFIG_OF
|
||||||
|
static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
|
||||||
|
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, "enable-gpios", 0);
|
||||||
|
if (gpio < 0) {
|
||||||
|
nfc_err(&client->dev, "Failed to retrieve enable-gpios from device tree\n");
|
||||||
|
return gpio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* GPIO request and configuration */
|
||||||
|
r = devm_gpio_request(&client->dev, gpio, "clf_enable");
|
||||||
|
if (r) {
|
||||||
|
nfc_err(&client->dev, "Failed to request enable pin\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = gpio_direction_output(gpio, 1);
|
||||||
|
if (r) {
|
||||||
|
nfc_err(&client->dev, "Failed to set enable pin direction as output\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
phy->gpio_ena = gpio;
|
||||||
|
|
||||||
|
/* IRQ */
|
||||||
|
r = irq_of_parse_and_map(pp, 0);
|
||||||
|
if (r < 0) {
|
||||||
|
nfc_err(&client->dev,
|
||||||
|
"Unable to get irq, error: %d\n", r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
phy->irq_polarity = irq_get_trigger_type(r);
|
||||||
|
client->irq = r;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
|
||||||
|
{
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int st21nfca_hci_i2c_request_resources(struct i2c_client *client)
|
static int st21nfca_hci_i2c_request_resources(struct i2c_client *client)
|
||||||
{
|
{
|
||||||
struct st21nfca_nfc_platform_data *pdata;
|
struct st21nfca_nfc_platform_data *pdata;
|
||||||
struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
|
struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
|
||||||
int r;
|
int r;
|
||||||
|
int irq;
|
||||||
|
|
||||||
pdata = client->dev.platform_data;
|
pdata = client->dev.platform_data;
|
||||||
if (pdata == NULL) {
|
if (pdata == NULL) {
|
||||||
@ -547,6 +603,16 @@ static int st21nfca_hci_i2c_request_resources(struct i2c_client *client)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* IRQ */
|
||||||
|
irq = gpio_to_irq(phy->gpio_irq);
|
||||||
|
if (irq < 0) {
|
||||||
|
nfc_err(&client->dev,
|
||||||
|
"Unable to get irq number for GPIO %d error %d\n",
|
||||||
|
phy->gpio_irq, r);
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
client->irq = irq;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -556,7 +622,6 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
|
|||||||
struct st21nfca_i2c_phy *phy;
|
struct st21nfca_i2c_phy *phy;
|
||||||
struct st21nfca_nfc_platform_data *pdata;
|
struct st21nfca_nfc_platform_data *pdata;
|
||||||
int r;
|
int r;
|
||||||
int irq;
|
|
||||||
|
|
||||||
dev_dbg(&client->dev, "%s\n", __func__);
|
dev_dbg(&client->dev, "%s\n", __func__);
|
||||||
dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
|
dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
|
||||||
@ -585,26 +650,22 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client,
|
|||||||
i2c_set_clientdata(client, phy);
|
i2c_set_clientdata(client, phy);
|
||||||
|
|
||||||
pdata = client->dev.platform_data;
|
pdata = client->dev.platform_data;
|
||||||
if (!pdata) {
|
if (!pdata && client->dev.of_node) {
|
||||||
nfc_err(&client->dev, "No platform data\n");
|
r = st21nfca_hci_i2c_of_request_resources(client);
|
||||||
return -EINVAL;
|
if (r) {
|
||||||
}
|
nfc_err(&client->dev, "No platform data\n");
|
||||||
|
return r;
|
||||||
r = st21nfca_hci_i2c_request_resources(client);
|
}
|
||||||
if (r) {
|
} else if (pdata) {
|
||||||
nfc_err(&client->dev, "Cannot get platform resources\n");
|
r = st21nfca_hci_i2c_request_resources(client);
|
||||||
return r;
|
if (r) {
|
||||||
}
|
nfc_err(&client->dev, "Cannot get platform resources\n");
|
||||||
|
return r;
|
||||||
/* IRQ */
|
}
|
||||||
irq = gpio_to_irq(phy->gpio_irq);
|
} else {
|
||||||
if (irq < 0) {
|
nfc_err(&client->dev, "st21nfca platform resources not available\n");
|
||||||
nfc_err(&client->dev,
|
|
||||||
"Unable to get irq number for GPIO %d error %d\n",
|
|
||||||
phy->gpio_irq, r);
|
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
client->irq = irq;
|
|
||||||
|
|
||||||
r = st21nfca_hci_platform_init(phy);
|
r = st21nfca_hci_platform_init(phy);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@ -640,10 +701,17 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct of_device_id of_st21nfca_i2c_match[] = {
|
||||||
|
{ .compatible = "st,st21nfca_i2c", },
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
static struct i2c_driver st21nfca_hci_i2c_driver = {
|
static struct i2c_driver st21nfca_hci_i2c_driver = {
|
||||||
.driver = {
|
.driver = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.name = ST21NFCA_HCI_I2C_DRIVER_NAME,
|
.name = ST21NFCA_HCI_I2C_DRIVER_NAME,
|
||||||
|
.owner = THIS_MODULE,
|
||||||
|
.of_match_table = of_match_ptr(of_st21nfca_i2c_match),
|
||||||
},
|
},
|
||||||
.probe = st21nfca_hci_i2c_probe,
|
.probe = st21nfca_hci_i2c_probe,
|
||||||
.id_table = st21nfca_hci_i2c_id_table,
|
.id_table = st21nfca_hci_i2c_id_table,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user