aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2011-05-27 11:48:14 -0400
committerChris Ball <cjb@laptop.org>2011-07-20 17:20:47 -0400
commit38576af1f8cad48446df47dcf404b197c9206dba (patch)
tree2e35c4fe4588b95febfb4430bbf784b5634b216d /drivers/mmc
parente307148fd4f971cecfaebb516ee28e164948a24b (diff)
mmc: sdhci: make sdhci-of device drivers self registered
The patch turns the sdhci-of-core common stuff into helper functions added into sdhci-pltfm.c, and makes sdhci-of device drviers self registered using the same pair of .probe and .remove used by sdhci-pltfm device drivers. As a result, sdhci-of-core.c and sdhci-of.h can be eliminated with those common things merged into sdhci-pltfm.c and sdhci-pltfm.h respectively. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Anton Vorontsov <cbouatmailru@gmail.com> Reviewed-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/Kconfig13
-rw-r--r--drivers/mmc/host/Makefile9
-rw-r--r--drivers/mmc/host/sdhci-of-esdhc.c53
-rw-r--r--drivers/mmc/host/sdhci-of-hlwd.c50
-rw-r--r--drivers/mmc/host/sdhci-of.h33
-rw-r--r--drivers/mmc/host/sdhci-pltfm.c111
-rw-r--r--drivers/mmc/host/sdhci-pltfm.h12
7 files changed, 227 insertions, 54 deletions
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index d9ca2623038d..ee4ac77b0eae 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -81,18 +81,9 @@ config MMC_RICOH_MMC
81 81
82 If unsure, say Y. 82 If unsure, say Y.
83 83
84config MMC_SDHCI_OF
85 tristate "SDHCI support on OpenFirmware platforms"
86 depends on MMC_SDHCI && OF
87 help
88 This selects the OF support for Secure Digital Host Controller
89 Interfaces.
90
91 If unsure, say N.
92
93config MMC_SDHCI_OF_ESDHC 84config MMC_SDHCI_OF_ESDHC
94 bool "SDHCI OF support for the Freescale eSDHC controller" 85 bool "SDHCI OF support for the Freescale eSDHC controller"
95 depends on MMC_SDHCI_OF 86 depends on MMC_SDHCI
96 depends on PPC_OF 87 depends on PPC_OF
97 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 88 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
98 help 89 help
@@ -102,7 +93,7 @@ config MMC_SDHCI_OF_ESDHC
102 93
103config MMC_SDHCI_OF_HLWD 94config MMC_SDHCI_OF_HLWD
104 bool "SDHCI OF support for the Nintendo Wii SDHCI controllers" 95 bool "SDHCI OF support for the Nintendo Wii SDHCI controllers"
105 depends on MMC_SDHCI_OF 96 depends on MMC_SDHCI
106 depends on PPC_OF 97 depends on PPC_OF
107 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER 98 select MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
108 help 99 help
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 732ec1e2a3d0..cbd89c310146 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -52,11 +52,10 @@ obj-$(CONFIG_MMC_SDHCI_DOVE) += sdhci-dove.o
52sdhci-dove-objs := sdhci-pltfm.o 52sdhci-dove-objs := sdhci-pltfm.o
53obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o 53obj-$(CONFIG_MMC_SDHCI_TEGRA) += sdhci-tegra.o
54sdhci-tegra-objs := sdhci-pltfm.o 54sdhci-tegra-objs := sdhci-pltfm.o
55 55obj-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o
56obj-$(CONFIG_MMC_SDHCI_OF) += sdhci-of.o 56sdhci-of-esdhc-objs := sdhci-pltfm.o
57sdhci-of-y := sdhci-of-core.o 57obj-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o
58sdhci-of-$(CONFIG_MMC_SDHCI_OF_ESDHC) += sdhci-of-esdhc.o 58sdhci-of-hlwd-objs := sdhci-pltfm.o
59sdhci-of-$(CONFIG_MMC_SDHCI_OF_HLWD) += sdhci-of-hlwd.o
60 59
61ifeq ($(CONFIG_CB710_DEBUG),y) 60ifeq ($(CONFIG_CB710_DEBUG),y)
62 CFLAGS-cb710-mmc += -DDEBUG 61 CFLAGS-cb710-mmc += -DDEBUG
diff --git a/drivers/mmc/host/sdhci-of-esdhc.c b/drivers/mmc/host/sdhci-of-esdhc.c
index 492bcd72180a..2db6a455d839 100644
--- a/drivers/mmc/host/sdhci-of-esdhc.c
+++ b/drivers/mmc/host/sdhci-of-esdhc.c
@@ -16,7 +16,7 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
19#include "sdhci-of.h" 19#include "sdhci-pltfm.h"
20#include "sdhci.h" 20#include "sdhci.h"
21#include "sdhci-esdhc.h" 21#include "sdhci-esdhc.h"
22 22
@@ -85,9 +85,58 @@ static struct sdhci_ops sdhci_esdhc_ops = {
85 .get_min_clock = esdhc_of_get_min_clock, 85 .get_min_clock = esdhc_of_get_min_clock,
86}; 86};
87 87
88struct sdhci_pltfm_data sdhci_esdhc_pdata = { 88static struct sdhci_pltfm_data sdhci_esdhc_pdata = {
89 /* card detection could be handled via GPIO */ 89 /* card detection could be handled via GPIO */
90 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION 90 .quirks = ESDHC_DEFAULT_QUIRKS | SDHCI_QUIRK_BROKEN_CARD_DETECTION
91 | SDHCI_QUIRK_NO_CARD_NO_RESET, 91 | SDHCI_QUIRK_NO_CARD_NO_RESET,
92 .ops = &sdhci_esdhc_ops, 92 .ops = &sdhci_esdhc_ops,
93}; 93};
94
95static int __devinit sdhci_esdhc_probe(struct platform_device *pdev)
96{
97 return sdhci_pltfm_register(pdev, &sdhci_esdhc_pdata);
98}
99
100static int __devexit sdhci_esdhc_remove(struct platform_device *pdev)
101{
102 return sdhci_pltfm_unregister(pdev);
103}
104
105static const struct of_device_id sdhci_esdhc_of_match[] = {
106 { .compatible = "fsl,mpc8379-esdhc" },
107 { .compatible = "fsl,mpc8536-esdhc" },
108 { .compatible = "fsl,esdhc" },
109 { }
110};
111MODULE_DEVICE_TABLE(of, sdhci_esdhc_of_match);
112
113static struct platform_driver sdhci_esdhc_driver = {
114 .driver = {
115 .name = "sdhci-esdhc",
116 .owner = THIS_MODULE,
117 .of_match_table = sdhci_esdhc_of_match,
118 },
119 .probe = sdhci_esdhc_probe,
120 .remove = __devexit_p(sdhci_esdhc_remove),
121#ifdef CONFIG_PM
122 .suspend = sdhci_pltfm_suspend,
123 .resume = sdhci_pltfm_resume,
124#endif
125};
126
127static int __init sdhci_esdhc_init(void)
128{
129 return platform_driver_register(&sdhci_esdhc_driver);
130}
131module_init(sdhci_esdhc_init);
132
133static void __exit sdhci_esdhc_exit(void)
134{
135 platform_driver_unregister(&sdhci_esdhc_driver);
136}
137module_exit(sdhci_esdhc_exit);
138
139MODULE_DESCRIPTION("SDHCI OF driver for Freescale MPC eSDHC");
140MODULE_AUTHOR("Xiaobo Xie <X.Xie@freescale.com>, "
141 "Anton Vorontsov <avorontsov@ru.mvista.com>");
142MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/sdhci-of-hlwd.c b/drivers/mmc/host/sdhci-of-hlwd.c
index 380e896864b5..faedfcec7760 100644
--- a/drivers/mmc/host/sdhci-of-hlwd.c
+++ b/drivers/mmc/host/sdhci-of-hlwd.c
@@ -21,7 +21,7 @@
21 21
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/mmc/host.h> 23#include <linux/mmc/host.h>
24#include "sdhci-of.h" 24#include "sdhci-pltfm.h"
25#include "sdhci.h" 25#include "sdhci.h"
26 26
27/* 27/*
@@ -60,8 +60,54 @@ static struct sdhci_ops sdhci_hlwd_ops = {
60 .write_b = sdhci_hlwd_writeb, 60 .write_b = sdhci_hlwd_writeb,
61}; 61};
62 62
63struct sdhci_pltfm_data sdhci_hlwd_pdata = { 63static struct sdhci_pltfm_data sdhci_hlwd_pdata = {
64 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR | 64 .quirks = SDHCI_QUIRK_32BIT_DMA_ADDR |
65 SDHCI_QUIRK_32BIT_DMA_SIZE, 65 SDHCI_QUIRK_32BIT_DMA_SIZE,
66 .ops = &sdhci_hlwd_ops, 66 .ops = &sdhci_hlwd_ops,
67}; 67};
68
69static int __devinit sdhci_hlwd_probe(struct platform_device *pdev)
70{
71 return sdhci_pltfm_register(pdev, &sdhci_hlwd_pdata);
72}
73
74static int __devexit sdhci_hlwd_remove(struct platform_device *pdev)
75{
76 return sdhci_pltfm_unregister(pdev);
77}
78
79static const struct of_device_id sdhci_hlwd_of_match[] = {
80 { .compatible = "nintendo,hollywood-sdhci" },
81 { }
82};
83MODULE_DEVICE_TABLE(of, sdhci_hlwd_of_match);
84
85static struct platform_driver sdhci_hlwd_driver = {
86 .driver = {
87 .name = "sdhci-hlwd",
88 .owner = THIS_MODULE,
89 .of_match_table = sdhci_hlwd_of_match,
90 },
91 .probe = sdhci_hlwd_probe,
92 .remove = __devexit_p(sdhci_hlwd_remove),
93#ifdef CONFIG_PM
94 .suspend = sdhci_pltfm_suspend,
95 .resume = sdhci_pltfm_resume,
96#endif
97};
98
99static int __init sdhci_hlwd_init(void)
100{
101 return platform_driver_register(&sdhci_hlwd_driver);
102}
103module_init(sdhci_hlwd_init);
104
105static void __exit sdhci_hlwd_exit(void)
106{
107 platform_driver_unregister(&sdhci_hlwd_driver);
108}
109module_exit(sdhci_hlwd_exit);
110
111MODULE_DESCRIPTION("Nintendo Wii SDHCI OF driver");
112MODULE_AUTHOR("The GameCube Linux Team, Albert Herranz");
113MODULE_LICENSE("GPL v2");
diff --git a/drivers/mmc/host/sdhci-of.h b/drivers/mmc/host/sdhci-of.h
deleted file mode 100644
index 5bdb5e7cce61..000000000000
--- a/drivers/mmc/host/sdhci-of.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * OpenFirmware bindings for Secure Digital Host Controller Interface.
3 *
4 * Copyright (c) 2007 Freescale Semiconductor, Inc.
5 * Copyright (c) 2009 MontaVista Software, Inc.
6 *
7 * Authors: Xiaobo Xie <X.Xie@freescale.com>
8 * Anton Vorontsov <avorontsov@ru.mvista.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 */
15
16#ifndef __SDHCI_OF_H
17#define __SDHCI_OF_H
18
19#include <linux/types.h>
20#include "sdhci.h"
21#include "sdhci-pltfm.h"
22
23extern u32 sdhci_be32bs_readl(struct sdhci_host *host, int reg);
24extern u16 sdhci_be32bs_readw(struct sdhci_host *host, int reg);
25extern u8 sdhci_be32bs_readb(struct sdhci_host *host, int reg);
26extern void sdhci_be32bs_writel(struct sdhci_host *host, u32 val, int reg);
27extern void sdhci_be32bs_writew(struct sdhci_host *host, u16 val, int reg);
28extern void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg);
29
30extern struct sdhci_pltfm_data sdhci_esdhc_pdata;
31extern struct sdhci_pltfm_data sdhci_hlwd_pdata;
32
33#endif /* __SDHCI_OF_H */
diff --git a/drivers/mmc/host/sdhci-pltfm.c b/drivers/mmc/host/sdhci-pltfm.c
index 8ccf25666201..041b0e2a898e 100644
--- a/drivers/mmc/host/sdhci-pltfm.c
+++ b/drivers/mmc/host/sdhci-pltfm.c
@@ -2,6 +2,12 @@
2 * sdhci-pltfm.c Support for SDHCI platform devices 2 * sdhci-pltfm.c Support for SDHCI platform devices
3 * Copyright (c) 2009 Intel Corporation 3 * Copyright (c) 2009 Intel Corporation
4 * 4 *
5 * Copyright (c) 2007 Freescale Semiconductor, Inc.
6 * Copyright (c) 2009 MontaVista Software, Inc.
7 *
8 * Authors: Xiaobo Xie <X.Xie@freescale.com>
9 * Anton Vorontsov <avorontsov@ru.mvista.com>
10 *
5 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as 12 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation. 13 * published by the Free Software Foundation.
@@ -23,13 +29,114 @@
23 */ 29 */
24 30
25#include <linux/err.h> 31#include <linux/err.h>
26 32#include <linux/of.h>
33#ifdef CONFIG_PPC
34#include <asm/machdep.h>
35#endif
27#include "sdhci.h" 36#include "sdhci.h"
28#include "sdhci-pltfm.h" 37#include "sdhci-pltfm.h"
29 38
30static struct sdhci_ops sdhci_pltfm_ops = { 39static struct sdhci_ops sdhci_pltfm_ops = {
31}; 40};
32 41
42#ifdef CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
43/*
44 * These accessors are designed for big endian hosts doing I/O to
45 * little endian controllers incorporating a 32-bit hardware byte swapper.
46 */
47u32 sdhci_be32bs_readl(struct sdhci_host *host, int reg)
48{
49 return in_be32(host->ioaddr + reg);
50}
51
52u16 sdhci_be32bs_readw(struct sdhci_host *host, int reg)
53{
54 return in_be16(host->ioaddr + (reg ^ 0x2));
55}
56
57u8 sdhci_be32bs_readb(struct sdhci_host *host, int reg)
58{
59 return in_8(host->ioaddr + (reg ^ 0x3));
60}
61
62void sdhci_be32bs_writel(struct sdhci_host *host, u32 val, int reg)
63{
64 out_be32(host->ioaddr + reg, val);
65}
66
67void sdhci_be32bs_writew(struct sdhci_host *host, u16 val, int reg)
68{
69 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
70 int base = reg & ~0x3;
71 int shift = (reg & 0x2) * 8;
72
73 switch (reg) {
74 case SDHCI_TRANSFER_MODE:
75 /*
76 * Postpone this write, we must do it together with a
77 * command write that is down below.
78 */
79 pltfm_host->xfer_mode_shadow = val;
80 return;
81 case SDHCI_COMMAND:
82 sdhci_be32bs_writel(host,
83 val << 16 | pltfm_host->xfer_mode_shadow,
84 SDHCI_TRANSFER_MODE);
85 return;
86 }
87 clrsetbits_be32(host->ioaddr + base, 0xffff << shift, val << shift);
88}
89
90void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg)
91{
92 int base = reg & ~0x3;
93 int shift = (reg & 0x3) * 8;
94
95 clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
96}
97#endif /* CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER */
98
99#ifdef CONFIG_OF
100static bool sdhci_of_wp_inverted(struct device_node *np)
101{
102 if (of_get_property(np, "sdhci,wp-inverted", NULL))
103 return true;
104
105 /* Old device trees don't have the wp-inverted property. */
106#ifdef CONFIG_PPC
107 return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds);
108#else
109 return false;
110#endif /* CONFIG_PPC */
111}
112
113void sdhci_get_of_property(struct platform_device *pdev)
114{
115 struct device_node *np = pdev->dev.of_node;
116 struct sdhci_host *host = platform_get_drvdata(pdev);
117 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
118 const __be32 *clk;
119 int size;
120
121 if (of_device_is_available(np)) {
122 if (of_get_property(np, "sdhci,auto-cmd12", NULL))
123 host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;
124
125 if (of_get_property(np, "sdhci,1-bit-only", NULL))
126 host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;
127
128 if (sdhci_of_wp_inverted(np))
129 host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT;
130
131 clk = of_get_property(np, "clock-frequency", &size);
132 if (clk && size == sizeof(*clk) && *clk)
133 pltfm_host->clock = be32_to_cpup(clk);
134 }
135}
136#else
137void sdhci_get_of_property(struct platform_device *pdev) {}
138#endif /* CONFIG_OF */
139
33struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev, 140struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
34 struct sdhci_pltfm_data *pdata) 141 struct sdhci_pltfm_data *pdata)
35{ 142{
@@ -117,6 +224,8 @@ int sdhci_pltfm_register(struct platform_device *pdev,
117 if (IS_ERR(host)) 224 if (IS_ERR(host))
118 return PTR_ERR(host); 225 return PTR_ERR(host);
119 226
227 sdhci_get_of_property(pdev);
228
120 ret = sdhci_add_host(host); 229 ret = sdhci_add_host(host);
121 if (ret) 230 if (ret)
122 sdhci_pltfm_free(pdev); 231 sdhci_pltfm_free(pdev);
diff --git a/drivers/mmc/host/sdhci-pltfm.h b/drivers/mmc/host/sdhci-pltfm.h
index 3cac4506f8f9..fe27b83f5bb1 100644
--- a/drivers/mmc/host/sdhci-pltfm.h
+++ b/drivers/mmc/host/sdhci-pltfm.h
@@ -15,6 +15,7 @@
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/mmc/sdhci-pltfm.h> 17#include <linux/mmc/sdhci-pltfm.h>
18#include <linux/mmc/sdhci.h>
18 19
19struct sdhci_pltfm_host { 20struct sdhci_pltfm_host {
20 struct clk *clk; 21 struct clk *clk;
@@ -25,6 +26,17 @@ struct sdhci_pltfm_host {
25 u16 xfer_mode_shadow; 26 u16 xfer_mode_shadow;
26}; 27};
27 28
29#ifdef CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
30extern u32 sdhci_be32bs_readl(struct sdhci_host *host, int reg);
31extern u16 sdhci_be32bs_readw(struct sdhci_host *host, int reg);
32extern u8 sdhci_be32bs_readb(struct sdhci_host *host, int reg);
33extern void sdhci_be32bs_writel(struct sdhci_host *host, u32 val, int reg);
34extern void sdhci_be32bs_writew(struct sdhci_host *host, u16 val, int reg);
35extern void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg);
36#endif
37
38extern void sdhci_get_of_property(struct platform_device *pdev);
39
28extern struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev, 40extern struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
29 struct sdhci_pltfm_data *pdata); 41 struct sdhci_pltfm_data *pdata);
30extern void sdhci_pltfm_free(struct platform_device *pdev); 42extern void sdhci_pltfm_free(struct platform_device *pdev);