.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * sdhci-pltfm.c Support for SDHCI platform devices |
---|
3 | 4 | * Copyright (c) 2009 Intel Corporation |
---|
.. | .. |
---|
7 | 8 | * |
---|
8 | 9 | * Authors: Xiaobo Xie <X.Xie@freescale.com> |
---|
9 | 10 | * Anton Vorontsov <avorontsov@ru.mvista.com> |
---|
10 | | - * |
---|
11 | | - * This program is free software; you can redistribute it and/or modify |
---|
12 | | - * it under the terms of the GNU General Public License version 2 as |
---|
13 | | - * published by the Free Software Foundation. |
---|
14 | | - * |
---|
15 | | - * This program is distributed in the hope that it will be useful, |
---|
16 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | | - * GNU General Public License for more details. |
---|
19 | | - * |
---|
20 | | - * You should have received a copy of the GNU General Public License |
---|
21 | | - * along with this program; if not, write to the Free Software |
---|
22 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
23 | 11 | */ |
---|
24 | 12 | |
---|
25 | 13 | /* Supports: |
---|
.. | .. |
---|
30 | 18 | |
---|
31 | 19 | #include <linux/err.h> |
---|
32 | 20 | #include <linux/module.h> |
---|
| 21 | +#include <linux/property.h> |
---|
33 | 22 | #include <linux/of.h> |
---|
34 | 23 | #ifdef CONFIG_PPC |
---|
35 | 24 | #include <asm/machdep.h> |
---|
.. | .. |
---|
51 | 40 | .set_uhs_signaling = sdhci_set_uhs_signaling, |
---|
52 | 41 | }; |
---|
53 | 42 | |
---|
54 | | -#ifdef CONFIG_OF |
---|
55 | | -static bool sdhci_of_wp_inverted(struct device_node *np) |
---|
| 43 | +static bool sdhci_wp_inverted(struct device *dev) |
---|
56 | 44 | { |
---|
57 | | - if (of_get_property(np, "sdhci,wp-inverted", NULL) || |
---|
58 | | - of_get_property(np, "wp-inverted", NULL)) |
---|
| 45 | + if (device_property_present(dev, "sdhci,wp-inverted") || |
---|
| 46 | + device_property_present(dev, "wp-inverted")) |
---|
59 | 47 | return true; |
---|
60 | 48 | |
---|
61 | 49 | /* Old device trees don't have the wp-inverted property. */ |
---|
.. | .. |
---|
66 | 54 | #endif /* CONFIG_PPC */ |
---|
67 | 55 | } |
---|
68 | 56 | |
---|
69 | | -void sdhci_get_of_property(struct platform_device *pdev) |
---|
| 57 | +#ifdef CONFIG_OF |
---|
| 58 | +static void sdhci_get_compatibility(struct platform_device *pdev) |
---|
70 | 59 | { |
---|
71 | | - struct device_node *np = pdev->dev.of_node; |
---|
72 | 60 | struct sdhci_host *host = platform_get_drvdata(pdev); |
---|
73 | | - struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
---|
74 | | - u32 bus_width; |
---|
| 61 | + struct device_node *np = pdev->dev.of_node; |
---|
75 | 62 | |
---|
76 | | - if (of_get_property(np, "sdhci,auto-cmd12", NULL)) |
---|
77 | | - host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; |
---|
78 | | - |
---|
79 | | - if (of_get_property(np, "sdhci,1-bit-only", NULL) || |
---|
80 | | - (of_property_read_u32(np, "bus-width", &bus_width) == 0 && |
---|
81 | | - bus_width == 1)) |
---|
82 | | - host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; |
---|
83 | | - |
---|
84 | | - if (sdhci_of_wp_inverted(np)) |
---|
85 | | - host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT; |
---|
86 | | - |
---|
87 | | - if (of_get_property(np, "broken-cd", NULL)) |
---|
88 | | - host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
---|
89 | | - |
---|
90 | | - if (of_get_property(np, "no-1-8-v", NULL)) |
---|
91 | | - host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; |
---|
| 63 | + if (!np) |
---|
| 64 | + return; |
---|
92 | 65 | |
---|
93 | 66 | if (of_device_is_compatible(np, "fsl,p2020-rev1-esdhc")) |
---|
94 | 67 | host->quirks |= SDHCI_QUIRK_BROKEN_DMA; |
---|
.. | .. |
---|
98 | 71 | of_device_is_compatible(np, "fsl,t4240-esdhc") || |
---|
99 | 72 | of_device_is_compatible(np, "fsl,mpc8536-esdhc")) |
---|
100 | 73 | host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; |
---|
101 | | - |
---|
102 | | - of_property_read_u32(np, "clock-frequency", &pltfm_host->clock); |
---|
103 | | - |
---|
104 | | - if (of_find_property(np, "keep-power-in-suspend", NULL)) |
---|
105 | | - host->mmc->pm_caps |= MMC_PM_KEEP_POWER; |
---|
106 | | - |
---|
107 | | - if (of_property_read_bool(np, "wakeup-source") || |
---|
108 | | - of_property_read_bool(np, "enable-sdio-wakeup")) /* legacy */ |
---|
109 | | - host->mmc->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; |
---|
110 | 74 | } |
---|
111 | 75 | #else |
---|
112 | | -void sdhci_get_of_property(struct platform_device *pdev) {} |
---|
| 76 | +void sdhci_get_compatibility(struct platform_device *pdev) {} |
---|
113 | 77 | #endif /* CONFIG_OF */ |
---|
114 | | -EXPORT_SYMBOL_GPL(sdhci_get_of_property); |
---|
| 78 | + |
---|
| 79 | +void sdhci_get_property(struct platform_device *pdev) |
---|
| 80 | +{ |
---|
| 81 | + struct device *dev = &pdev->dev; |
---|
| 82 | + struct sdhci_host *host = platform_get_drvdata(pdev); |
---|
| 83 | + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
---|
| 84 | + u32 bus_width; |
---|
| 85 | + |
---|
| 86 | + if (device_property_present(dev, "sdhci,auto-cmd12")) |
---|
| 87 | + host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12; |
---|
| 88 | + |
---|
| 89 | + if (device_property_present(dev, "sdhci,1-bit-only") || |
---|
| 90 | + (device_property_read_u32(dev, "bus-width", &bus_width) == 0 && |
---|
| 91 | + bus_width == 1)) |
---|
| 92 | + host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA; |
---|
| 93 | + |
---|
| 94 | + if (sdhci_wp_inverted(dev)) |
---|
| 95 | + host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT; |
---|
| 96 | + |
---|
| 97 | + if (device_property_present(dev, "broken-cd")) |
---|
| 98 | + host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
---|
| 99 | + |
---|
| 100 | + if (device_property_present(dev, "no-1-8-v")) |
---|
| 101 | + host->quirks2 |= SDHCI_QUIRK2_NO_1_8_V; |
---|
| 102 | + |
---|
| 103 | + sdhci_get_compatibility(pdev); |
---|
| 104 | + |
---|
| 105 | + device_property_read_u32(dev, "clock-frequency", &pltfm_host->clock); |
---|
| 106 | + |
---|
| 107 | + if (device_property_present(dev, "keep-power-in-suspend")) |
---|
| 108 | + host->mmc->pm_caps |= MMC_PM_KEEP_POWER; |
---|
| 109 | + |
---|
| 110 | + if (device_property_read_bool(dev, "wakeup-source") || |
---|
| 111 | + device_property_read_bool(dev, "enable-sdio-wakeup")) /* legacy */ |
---|
| 112 | + host->mmc->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; |
---|
| 113 | +} |
---|
| 114 | +EXPORT_SYMBOL_GPL(sdhci_get_property); |
---|
115 | 115 | |
---|
116 | 116 | struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev, |
---|
117 | 117 | const struct sdhci_pltfm_data *pdata, |
---|
118 | 118 | size_t priv_size) |
---|
119 | 119 | { |
---|
120 | 120 | struct sdhci_host *host; |
---|
121 | | - struct resource *iomem; |
---|
122 | 121 | void __iomem *ioaddr; |
---|
123 | 122 | int irq, ret; |
---|
124 | 123 | |
---|
125 | | - iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
126 | | - ioaddr = devm_ioremap_resource(&pdev->dev, iomem); |
---|
| 124 | + ioaddr = devm_platform_ioremap_resource(pdev, 0); |
---|
127 | 125 | if (IS_ERR(ioaddr)) { |
---|
128 | 126 | ret = PTR_ERR(ioaddr); |
---|
129 | 127 | goto err; |
---|
.. | .. |
---|
131 | 129 | |
---|
132 | 130 | irq = platform_get_irq(pdev, 0); |
---|
133 | 131 | if (irq < 0) { |
---|
134 | | - dev_err(&pdev->dev, "failed to get IRQ number\n"); |
---|
135 | 132 | ret = irq; |
---|
136 | 133 | goto err; |
---|
137 | 134 | } |
---|
.. | .. |
---|
184 | 181 | if (IS_ERR(host)) |
---|
185 | 182 | return PTR_ERR(host); |
---|
186 | 183 | |
---|
187 | | - sdhci_get_of_property(pdev); |
---|
| 184 | + sdhci_get_property(pdev); |
---|
188 | 185 | |
---|
189 | 186 | ret = sdhci_add_host(host); |
---|
190 | 187 | if (ret) |
---|