Skip to content

Commit

Permalink
NFC: st-nci: Get rid of code duplication in ->probe()
Browse files Browse the repository at this point in the history
Since OF and ACPI case almost the same get rid of code duplication
by moving gpiod_get() calls directly to ->probe().

Signed-off-by: Andy Shevchenko <[email protected]>
Signed-off-by: Samuel Ortiz <[email protected]>
  • Loading branch information
andy-shev authored and Samuel Ortiz committed Jun 22, 2017
1 parent 85d23e7 commit c745120
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 103 deletions.
61 changes: 9 additions & 52 deletions drivers/nfc/st-nci/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,41 +210,6 @@ static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = {
{},
};

static int st_nci_i2c_acpi_request_resources(struct i2c_client *client)
{
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
struct device *dev = &client->dev;
int r;

r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios);
if (r)
return r;

/* Get RESET GPIO from ACPI */
phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(dev, "Unable to get RESET GPIO\n");
return -ENODEV;
}

return 0;
}

static int st_nci_i2c_of_request_resources(struct i2c_client *client)
{
struct st_nci_i2c_phy *phy = i2c_get_clientdata(client);
struct device *dev = &client->dev;

/* Get GPIO from device tree */
phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(dev, "Unable to get RESET GPIO\n");
return PTR_ERR(phy->gpiod_reset);
}

return 0;
}

static int st_nci_i2c_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
Expand All @@ -260,30 +225,22 @@ static int st_nci_i2c_probe(struct i2c_client *client,
return -ENODEV;
}

phy = devm_kzalloc(&client->dev, sizeof(struct st_nci_i2c_phy),
GFP_KERNEL);
phy = devm_kzalloc(dev, sizeof(struct st_nci_i2c_phy), GFP_KERNEL);
if (!phy)
return -ENOMEM;

phy->i2c_dev = client;

i2c_set_clientdata(client, phy);

if (client->dev.of_node) {
r = st_nci_i2c_of_request_resources(client);
if (r) {
nfc_err(&client->dev, "No platform data\n");
return r;
}
} 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;
}
} else {
nfc_err(&client->dev,
"st_nci platform resources not available\n");
r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios);
if (r)
dev_dbg(dev, "Unable to add GPIO mapping table\n");

/* Get RESET GPIO */
phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(dev, "Unable to get RESET GPIO\n");
return -ENODEV;
}

Expand Down
60 changes: 9 additions & 51 deletions drivers/nfc/st-nci/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,41 +225,6 @@ static const struct acpi_gpio_mapping acpi_st_nci_gpios[] = {
{},
};

static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev)
{
struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev);
struct device *dev = &spi_dev->dev;
int r;

r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios);
if (r)
return r;

/* Get RESET GPIO from ACPI */
phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(dev, "Unable to get RESET GPIO\n");
return PTR_ERR(phy->gpiod_reset);
}

return 0;
}

static int st_nci_spi_of_request_resources(struct spi_device *spi)
{
struct st_nci_spi_phy *phy = spi_get_drvdata(spi);
struct device *dev = &spi->dev;

/* Get GPIO from device tree */
phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(dev, "Unable to get RESET GPIO\n");
return PTR_ERR(phy->gpiod_reset);
}

return 0;
}

static int st_nci_spi_probe(struct spi_device *dev)
{
struct st_nci_spi_phy *phy;
Expand All @@ -284,22 +249,15 @@ static int st_nci_spi_probe(struct spi_device *dev)

spi_set_drvdata(dev, phy);

if (dev->dev.of_node) {
r = st_nci_spi_of_request_resources(dev);
if (r) {
nfc_err(&dev->dev, "No platform data\n");
return r;
}
} else if (ACPI_HANDLE(&dev->dev)) {
r = st_nci_spi_acpi_request_resources(dev);
if (r) {
nfc_err(&dev->dev, "Cannot get ACPI data\n");
return r;
}
} else {
nfc_err(&dev->dev,
"st_nci platform resources not available\n");
return -ENODEV;
r = devm_acpi_dev_add_driver_gpios(&dev->dev, acpi_st_nci_gpios);
if (r)
dev_dbg(&dev->dev, "Unable to add GPIO mapping table\n");

/* Get RESET GPIO */
phy->gpiod_reset = devm_gpiod_get(&dev->dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(phy->gpiod_reset)) {
nfc_err(&dev->dev, "Unable to get RESET GPIO\n");
return PTR_ERR(phy->gpiod_reset);
}

phy->se_status.is_ese_present =
Expand Down

0 comments on commit c745120

Please sign in to comment.