Skip to content

Commit ad0acfd

Browse files
andy-shevdavem330
authored andcommitted
NFC: nxp-nci: Get rid of code duplication in ->probe()
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]> Tested-by: Sedat Dilek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 099d03f commit ad0acfd

File tree

1 file changed

+15
-53
lines changed

1 file changed

+15
-53
lines changed

drivers/nfc/nxp-nci/i2c.c

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -256,48 +256,10 @@ static const struct acpi_gpio_mapping acpi_nxp_nci_gpios[] = {
256256
{ }
257257
};
258258

259-
static int nxp_nci_i2c_parse_devtree(struct i2c_client *client)
260-
{
261-
struct nxp_nci_i2c_phy *phy = i2c_get_clientdata(client);
262-
263-
phy->gpiod_en = devm_gpiod_get(&client->dev, "enable", GPIOD_OUT_LOW);
264-
if (IS_ERR(phy->gpiod_en)) {
265-
nfc_err(&client->dev, "Failed to get EN gpio\n");
266-
return PTR_ERR(phy->gpiod_en);
267-
}
268-
269-
phy->gpiod_fw = devm_gpiod_get(&client->dev, "firmware", GPIOD_OUT_LOW);
270-
if (IS_ERR(phy->gpiod_fw)) {
271-
nfc_err(&client->dev, "Failed to get FW gpio\n");
272-
return PTR_ERR(phy->gpiod_fw);
273-
}
274-
275-
return 0;
276-
}
277-
278-
static int nxp_nci_i2c_acpi_config(struct nxp_nci_i2c_phy *phy)
279-
{
280-
struct i2c_client *client = phy->i2c_dev;
281-
int r;
282-
283-
r = devm_acpi_dev_add_driver_gpios(&client->dev, acpi_nxp_nci_gpios);
284-
if (r)
285-
return r;
286-
287-
phy->gpiod_en = devm_gpiod_get(&client->dev, "enable", GPIOD_OUT_LOW);
288-
phy->gpiod_fw = devm_gpiod_get(&client->dev, "firmware", GPIOD_OUT_LOW);
289-
290-
if (IS_ERR(phy->gpiod_en) || IS_ERR(phy->gpiod_fw)) {
291-
nfc_err(&client->dev, "No GPIOs\n");
292-
return -EINVAL;
293-
}
294-
295-
return 0;
296-
}
297-
298259
static int nxp_nci_i2c_probe(struct i2c_client *client,
299260
const struct i2c_device_id *id)
300261
{
262+
struct device *dev = &client->dev;
301263
struct nxp_nci_i2c_phy *phy;
302264
int r;
303265

@@ -317,20 +279,20 @@ static int nxp_nci_i2c_probe(struct i2c_client *client,
317279
phy->i2c_dev = client;
318280
i2c_set_clientdata(client, phy);
319281

320-
if (client->dev.of_node) {
321-
r = nxp_nci_i2c_parse_devtree(client);
322-
if (r < 0) {
323-
nfc_err(&client->dev, "Failed to get DT data\n");
324-
goto probe_exit;
325-
}
326-
} else if (ACPI_HANDLE(&client->dev)) {
327-
r = nxp_nci_i2c_acpi_config(phy);
328-
if (r < 0)
329-
goto probe_exit;
330-
} else {
331-
nfc_err(&client->dev, "No platform data\n");
332-
r = -EINVAL;
333-
goto probe_exit;
282+
r = devm_acpi_dev_add_driver_gpios(dev, acpi_nxp_nci_gpios);
283+
if (r)
284+
return r;
285+
286+
phy->gpiod_en = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW);
287+
if (IS_ERR(phy->gpiod_en)) {
288+
nfc_err(dev, "Failed to get EN gpio\n");
289+
return PTR_ERR(phy->gpiod_en);
290+
}
291+
292+
phy->gpiod_fw = devm_gpiod_get(dev, "firmware", GPIOD_OUT_LOW);
293+
if (IS_ERR(phy->gpiod_fw)) {
294+
nfc_err(dev, "Failed to get FW gpio\n");
295+
return PTR_ERR(phy->gpiod_fw);
334296
}
335297

336298
r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops,

0 commit comments

Comments
 (0)