treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / mmc / host / of_mmc_spi.c
blob3c4d950a4755353236a4a78b3f906e73d796e0ac
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * OpenFirmware bindings for the MMC-over-SPI driver
5 * Copyright (c) MontaVista Software, Inc. 2008.
7 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/slab.h>
14 #include <linux/irq.h>
15 #include <linux/of.h>
16 #include <linux/of_irq.h>
17 #include <linux/spi/spi.h>
18 #include <linux/spi/mmc_spi.h>
19 #include <linux/mmc/core.h>
20 #include <linux/mmc/host.h>
22 /* For archs that don't support NO_IRQ (such as mips), provide a dummy value */
23 #ifndef NO_IRQ
24 #define NO_IRQ 0
25 #endif
27 MODULE_LICENSE("GPL");
29 struct of_mmc_spi {
30 int detect_irq;
31 struct mmc_spi_platform_data pdata;
34 static struct of_mmc_spi *to_of_mmc_spi(struct device *dev)
36 return container_of(dev->platform_data, struct of_mmc_spi, pdata);
39 static int of_mmc_spi_init(struct device *dev,
40 irqreturn_t (*irqhandler)(int, void *), void *mmc)
42 struct of_mmc_spi *oms = to_of_mmc_spi(dev);
44 return request_threaded_irq(oms->detect_irq, NULL, irqhandler,
45 IRQF_ONESHOT, dev_name(dev), mmc);
48 static void of_mmc_spi_exit(struct device *dev, void *mmc)
50 struct of_mmc_spi *oms = to_of_mmc_spi(dev);
52 free_irq(oms->detect_irq, mmc);
55 struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
57 struct device *dev = &spi->dev;
58 struct device_node *np = dev->of_node;
59 struct of_mmc_spi *oms;
61 if (dev->platform_data || !np)
62 return dev->platform_data;
64 oms = kzalloc(sizeof(*oms), GFP_KERNEL);
65 if (!oms)
66 return NULL;
68 if (mmc_of_parse_voltage(np, &oms->pdata.ocr_mask) <= 0)
69 goto err_ocr;
71 oms->detect_irq = irq_of_parse_and_map(np, 0);
72 if (oms->detect_irq != 0) {
73 oms->pdata.init = of_mmc_spi_init;
74 oms->pdata.exit = of_mmc_spi_exit;
75 } else {
76 oms->pdata.caps |= MMC_CAP_NEEDS_POLL;
79 dev->platform_data = &oms->pdata;
80 return dev->platform_data;
81 err_ocr:
82 kfree(oms);
83 return NULL;
85 EXPORT_SYMBOL(mmc_spi_get_pdata);
87 void mmc_spi_put_pdata(struct spi_device *spi)
89 struct device *dev = &spi->dev;
90 struct device_node *np = dev->of_node;
91 struct of_mmc_spi *oms = to_of_mmc_spi(dev);
93 if (!dev->platform_data || !np)
94 return;
96 kfree(oms);
97 dev->platform_data = NULL;
99 EXPORT_SYMBOL(mmc_spi_put_pdata);