Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NFC: st-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 <andriy.shevchenko@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>

authored by

Andy Shevchenko and committed by
Samuel Ortiz
c745120e 85d23e77

+18 -103
+9 -52
drivers/nfc/st-nci/i2c.c
··· 210 210 {}, 211 211 }; 212 212 213 - static int st_nci_i2c_acpi_request_resources(struct i2c_client *client) 214 - { 215 - struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); 216 - struct device *dev = &client->dev; 217 - int r; 218 - 219 - r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); 220 - if (r) 221 - return r; 222 - 223 - /* Get RESET GPIO from ACPI */ 224 - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 225 - if (IS_ERR(phy->gpiod_reset)) { 226 - nfc_err(dev, "Unable to get RESET GPIO\n"); 227 - return -ENODEV; 228 - } 229 - 230 - return 0; 231 - } 232 - 233 - static int st_nci_i2c_of_request_resources(struct i2c_client *client) 234 - { 235 - struct st_nci_i2c_phy *phy = i2c_get_clientdata(client); 236 - struct device *dev = &client->dev; 237 - 238 - /* Get GPIO from device tree */ 239 - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 240 - if (IS_ERR(phy->gpiod_reset)) { 241 - nfc_err(dev, "Unable to get RESET GPIO\n"); 242 - return PTR_ERR(phy->gpiod_reset); 243 - } 244 - 245 - return 0; 246 - } 247 - 248 213 static int st_nci_i2c_probe(struct i2c_client *client, 249 214 const struct i2c_device_id *id) 250 215 { ··· 225 260 return -ENODEV; 226 261 } 227 262 228 - phy = devm_kzalloc(&client->dev, sizeof(struct st_nci_i2c_phy), 229 - GFP_KERNEL); 263 + phy = devm_kzalloc(dev, sizeof(struct st_nci_i2c_phy), GFP_KERNEL); 230 264 if (!phy) 231 265 return -ENOMEM; 232 266 ··· 233 269 234 270 i2c_set_clientdata(client, phy); 235 271 236 - if (client->dev.of_node) { 237 - r = st_nci_i2c_of_request_resources(client); 238 - if (r) { 239 - nfc_err(&client->dev, "No platform data\n"); 240 - return r; 241 - } 242 - } else if (ACPI_HANDLE(&client->dev)) { 243 - r = st_nci_i2c_acpi_request_resources(client); 244 - if (r) { 245 - nfc_err(&client->dev, "Cannot get ACPI data\n"); 246 - return r; 247 - } 248 - } else { 249 - nfc_err(&client->dev, 250 - "st_nci platform resources not available\n"); 272 + r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); 273 + if (r) 274 + dev_dbg(dev, "Unable to add GPIO mapping table\n"); 275 + 276 + /* Get RESET GPIO */ 277 + phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 278 + if (IS_ERR(phy->gpiod_reset)) { 279 + nfc_err(dev, "Unable to get RESET GPIO\n"); 251 280 return -ENODEV; 252 281 } 253 282
+9 -51
drivers/nfc/st-nci/spi.c
··· 225 225 {}, 226 226 }; 227 227 228 - static int st_nci_spi_acpi_request_resources(struct spi_device *spi_dev) 229 - { 230 - struct st_nci_spi_phy *phy = spi_get_drvdata(spi_dev); 231 - struct device *dev = &spi_dev->dev; 232 - int r; 233 - 234 - r = devm_acpi_dev_add_driver_gpios(dev, acpi_st_nci_gpios); 235 - if (r) 236 - return r; 237 - 238 - /* Get RESET GPIO from ACPI */ 239 - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 240 - if (IS_ERR(phy->gpiod_reset)) { 241 - nfc_err(dev, "Unable to get RESET GPIO\n"); 242 - return PTR_ERR(phy->gpiod_reset); 243 - } 244 - 245 - return 0; 246 - } 247 - 248 - static int st_nci_spi_of_request_resources(struct spi_device *spi) 249 - { 250 - struct st_nci_spi_phy *phy = spi_get_drvdata(spi); 251 - struct device *dev = &spi->dev; 252 - 253 - /* Get GPIO from device tree */ 254 - phy->gpiod_reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); 255 - if (IS_ERR(phy->gpiod_reset)) { 256 - nfc_err(dev, "Unable to get RESET GPIO\n"); 257 - return PTR_ERR(phy->gpiod_reset); 258 - } 259 - 260 - return 0; 261 - } 262 - 263 228 static int st_nci_spi_probe(struct spi_device *dev) 264 229 { 265 230 struct st_nci_spi_phy *phy; ··· 249 284 250 285 spi_set_drvdata(dev, phy); 251 286 252 - if (dev->dev.of_node) { 253 - r = st_nci_spi_of_request_resources(dev); 254 - if (r) { 255 - nfc_err(&dev->dev, "No platform data\n"); 256 - return r; 257 - } 258 - } else if (ACPI_HANDLE(&dev->dev)) { 259 - r = st_nci_spi_acpi_request_resources(dev); 260 - if (r) { 261 - nfc_err(&dev->dev, "Cannot get ACPI data\n"); 262 - return r; 263 - } 264 - } else { 265 - nfc_err(&dev->dev, 266 - "st_nci platform resources not available\n"); 267 - return -ENODEV; 287 + r = devm_acpi_dev_add_driver_gpios(&dev->dev, acpi_st_nci_gpios); 288 + if (r) 289 + dev_dbg(&dev->dev, "Unable to add GPIO mapping table\n"); 290 + 291 + /* Get RESET GPIO */ 292 + phy->gpiod_reset = devm_gpiod_get(&dev->dev, "reset", GPIOD_OUT_HIGH); 293 + if (IS_ERR(phy->gpiod_reset)) { 294 + nfc_err(&dev->dev, "Unable to get RESET GPIO\n"); 295 + return PTR_ERR(phy->gpiod_reset); 268 296 } 269 297 270 298 phy->se_status.is_ese_present =