xref: /linux/drivers/mmc/host/sdhci-pltfm.h (revision d005d94359a8df84ea6e5ac137393707f9e87e81)
1515033f9SAnton Vorontsov /*
2515033f9SAnton Vorontsov  * Copyright 2010 MontaVista Software, LLC.
3515033f9SAnton Vorontsov  *
4515033f9SAnton Vorontsov  * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
5515033f9SAnton Vorontsov  *
6515033f9SAnton Vorontsov  * This program is free software; you can redistribute it and/or modify
7515033f9SAnton Vorontsov  * it under the terms of the GNU General Public License version 2 as
8515033f9SAnton Vorontsov  * published by the Free Software Foundation.
9515033f9SAnton Vorontsov  */
10515033f9SAnton Vorontsov 
11515033f9SAnton Vorontsov #ifndef _DRIVERS_MMC_SDHCI_PLTFM_H
12515033f9SAnton Vorontsov #define _DRIVERS_MMC_SDHCI_PLTFM_H
13515033f9SAnton Vorontsov 
144b711cb1SWolfram Sang #include <linux/clk.h>
1585d6509dSShawn Guo #include <linux/platform_device.h>
16f0de8369SShawn Guo #include "sdhci.h"
1720b1597bSAnton Vorontsov 
1894cc6a86SShawn Guo struct sdhci_pltfm_data {
1994cc6a86SShawn Guo 	struct sdhci_ops *ops;
2094cc6a86SShawn Guo 	unsigned int quirks;
2194cc6a86SShawn Guo };
2294cc6a86SShawn Guo 
234b711cb1SWolfram Sang struct sdhci_pltfm_host {
244b711cb1SWolfram Sang 	struct clk *clk;
25e149860dSRichard Zhu 	void *priv; /* to handle quirks across io-accessor calls */
26e307148fSShawn Guo 
27e307148fSShawn Guo 	/* migrate from sdhci_of_host */
28e307148fSShawn Guo 	unsigned int clock;
29e307148fSShawn Guo 	u16 xfer_mode_shadow;
304b711cb1SWolfram Sang };
314b711cb1SWolfram Sang 
3238576af1SShawn Guo #ifdef CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER
33f0de8369SShawn Guo /*
34f0de8369SShawn Guo  * These accessors are designed for big endian hosts doing I/O to
35f0de8369SShawn Guo  * little endian controllers incorporating a 32-bit hardware byte swapper.
36f0de8369SShawn Guo  */
37f0de8369SShawn Guo static inline u32 sdhci_be32bs_readl(struct sdhci_host *host, int reg)
38f0de8369SShawn Guo {
39f0de8369SShawn Guo 	return in_be32(host->ioaddr + reg);
40f0de8369SShawn Guo }
41f0de8369SShawn Guo 
42f0de8369SShawn Guo static inline u16 sdhci_be32bs_readw(struct sdhci_host *host, int reg)
43f0de8369SShawn Guo {
44f0de8369SShawn Guo 	return in_be16(host->ioaddr + (reg ^ 0x2));
45f0de8369SShawn Guo }
46f0de8369SShawn Guo 
47f0de8369SShawn Guo static inline u8 sdhci_be32bs_readb(struct sdhci_host *host, int reg)
48f0de8369SShawn Guo {
49f0de8369SShawn Guo 	return in_8(host->ioaddr + (reg ^ 0x3));
50f0de8369SShawn Guo }
51f0de8369SShawn Guo 
52f0de8369SShawn Guo static inline void sdhci_be32bs_writel(struct sdhci_host *host,
53f0de8369SShawn Guo 				       u32 val, int reg)
54f0de8369SShawn Guo {
55f0de8369SShawn Guo 	out_be32(host->ioaddr + reg, val);
56f0de8369SShawn Guo }
57f0de8369SShawn Guo 
58f0de8369SShawn Guo static inline void sdhci_be32bs_writew(struct sdhci_host *host,
59f0de8369SShawn Guo 				       u16 val, int reg)
60f0de8369SShawn Guo {
61f0de8369SShawn Guo 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
62f0de8369SShawn Guo 	int base = reg & ~0x3;
63f0de8369SShawn Guo 	int shift = (reg & 0x2) * 8;
64f0de8369SShawn Guo 
65f0de8369SShawn Guo 	switch (reg) {
66f0de8369SShawn Guo 	case SDHCI_TRANSFER_MODE:
67f0de8369SShawn Guo 		/*
68f0de8369SShawn Guo 		 * Postpone this write, we must do it together with a
69f0de8369SShawn Guo 		 * command write that is down below.
70f0de8369SShawn Guo 		 */
71f0de8369SShawn Guo 		pltfm_host->xfer_mode_shadow = val;
72f0de8369SShawn Guo 		return;
73f0de8369SShawn Guo 	case SDHCI_COMMAND:
74f0de8369SShawn Guo 		sdhci_be32bs_writel(host,
75f0de8369SShawn Guo 				    val << 16 | pltfm_host->xfer_mode_shadow,
76f0de8369SShawn Guo 				    SDHCI_TRANSFER_MODE);
77f0de8369SShawn Guo 		return;
78f0de8369SShawn Guo 	}
79f0de8369SShawn Guo 	clrsetbits_be32(host->ioaddr + base, 0xffff << shift, val << shift);
80f0de8369SShawn Guo }
81f0de8369SShawn Guo 
82f0de8369SShawn Guo static inline void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg)
83f0de8369SShawn Guo {
84f0de8369SShawn Guo 	int base = reg & ~0x3;
85f0de8369SShawn Guo 	int shift = (reg & 0x3) * 8;
86f0de8369SShawn Guo 
87f0de8369SShawn Guo 	clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);
88f0de8369SShawn Guo }
89f0de8369SShawn Guo #endif /* CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER */
9038576af1SShawn Guo 
9138576af1SShawn Guo extern void sdhci_get_of_property(struct platform_device *pdev);
9238576af1SShawn Guo 
9385d6509dSShawn Guo extern struct sdhci_host *sdhci_pltfm_init(struct platform_device *pdev,
9485d6509dSShawn Guo 					   struct sdhci_pltfm_data *pdata);
9585d6509dSShawn Guo extern void sdhci_pltfm_free(struct platform_device *pdev);
9685d6509dSShawn Guo 
9785d6509dSShawn Guo extern int sdhci_pltfm_register(struct platform_device *pdev,
9885d6509dSShawn Guo 				struct sdhci_pltfm_data *pdata);
9985d6509dSShawn Guo extern int sdhci_pltfm_unregister(struct platform_device *pdev);
10085d6509dSShawn Guo 
101*d005d943SLars-Peter Clausen extern unsigned int sdhci_pltfm_clk_get_max_clock(struct sdhci_host *host);
102*d005d943SLars-Peter Clausen 
10385d6509dSShawn Guo #ifdef CONFIG_PM
10429495aa0SManuel Lauss extern const struct dev_pm_ops sdhci_pltfm_pmops;
10529495aa0SManuel Lauss #define SDHCI_PLTFM_PMOPS (&sdhci_pltfm_pmops)
10629495aa0SManuel Lauss #else
10729495aa0SManuel Lauss #define SDHCI_PLTFM_PMOPS NULL
10885d6509dSShawn Guo #endif
10920b1597bSAnton Vorontsov 
110515033f9SAnton Vorontsov #endif /* _DRIVERS_MMC_SDHCI_PLTFM_H */
111