Path: blob/master/drivers/mmc/host/sdhci-of-core.c
15111 views
/*1* OpenFirmware bindings for Secure Digital Host Controller Interface.2*3* Copyright (c) 2007 Freescale Semiconductor, Inc.4* Copyright (c) 2009 MontaVista Software, Inc.5*6* Authors: Xiaobo Xie <[email protected]>7* Anton Vorontsov <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or (at12* your option) any later version.13*/1415#include <linux/err.h>16#include <linux/module.h>17#include <linux/init.h>18#include <linux/io.h>19#include <linux/interrupt.h>20#include <linux/delay.h>21#include <linux/of.h>22#include <linux/of_platform.h>23#include <linux/of_address.h>24#include <linux/of_irq.h>25#include <linux/mmc/host.h>26#ifdef CONFIG_PPC27#include <asm/machdep.h>28#endif29#include "sdhci-of.h"30#include "sdhci.h"3132#ifdef CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER3334/*35* These accessors are designed for big endian hosts doing I/O to36* little endian controllers incorporating a 32-bit hardware byte swapper.37*/3839u32 sdhci_be32bs_readl(struct sdhci_host *host, int reg)40{41return in_be32(host->ioaddr + reg);42}4344u16 sdhci_be32bs_readw(struct sdhci_host *host, int reg)45{46return in_be16(host->ioaddr + (reg ^ 0x2));47}4849u8 sdhci_be32bs_readb(struct sdhci_host *host, int reg)50{51return in_8(host->ioaddr + (reg ^ 0x3));52}5354void sdhci_be32bs_writel(struct sdhci_host *host, u32 val, int reg)55{56out_be32(host->ioaddr + reg, val);57}5859void sdhci_be32bs_writew(struct sdhci_host *host, u16 val, int reg)60{61struct sdhci_of_host *of_host = sdhci_priv(host);62int base = reg & ~0x3;63int shift = (reg & 0x2) * 8;6465switch (reg) {66case SDHCI_TRANSFER_MODE:67/*68* Postpone this write, we must do it together with a69* command write that is down below.70*/71of_host->xfer_mode_shadow = val;72return;73case SDHCI_COMMAND:74sdhci_be32bs_writel(host, val << 16 | of_host->xfer_mode_shadow,75SDHCI_TRANSFER_MODE);76return;77}78clrsetbits_be32(host->ioaddr + base, 0xffff << shift, val << shift);79}8081void sdhci_be32bs_writeb(struct sdhci_host *host, u8 val, int reg)82{83int base = reg & ~0x3;84int shift = (reg & 0x3) * 8;8586clrsetbits_be32(host->ioaddr + base , 0xff << shift, val << shift);87}88#endif /* CONFIG_MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER */8990#ifdef CONFIG_PM9192static int sdhci_of_suspend(struct platform_device *ofdev, pm_message_t state)93{94struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);9596return mmc_suspend_host(host->mmc);97}9899static int sdhci_of_resume(struct platform_device *ofdev)100{101struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);102103return mmc_resume_host(host->mmc);104}105106#else107108#define sdhci_of_suspend NULL109#define sdhci_of_resume NULL110111#endif112113static bool __devinit sdhci_of_wp_inverted(struct device_node *np)114{115if (of_get_property(np, "sdhci,wp-inverted", NULL))116return true;117118/* Old device trees don't have the wp-inverted property. */119#ifdef CONFIG_PPC120return machine_is(mpc837x_rdb) || machine_is(mpc837x_mds);121#else122return false;123#endif124}125126static const struct of_device_id sdhci_of_match[];127static int __devinit sdhci_of_probe(struct platform_device *ofdev)128{129const struct of_device_id *match;130struct device_node *np = ofdev->dev.of_node;131struct sdhci_of_data *sdhci_of_data;132struct sdhci_host *host;133struct sdhci_of_host *of_host;134const __be32 *clk;135int size;136int ret;137138match = of_match_device(sdhci_of_match, &ofdev->dev);139if (!match)140return -EINVAL;141sdhci_of_data = match->data;142143if (!of_device_is_available(np))144return -ENODEV;145146host = sdhci_alloc_host(&ofdev->dev, sizeof(*of_host));147if (IS_ERR(host))148return -ENOMEM;149150of_host = sdhci_priv(host);151dev_set_drvdata(&ofdev->dev, host);152153host->ioaddr = of_iomap(np, 0);154if (!host->ioaddr) {155ret = -ENOMEM;156goto err_addr_map;157}158159host->irq = irq_of_parse_and_map(np, 0);160if (!host->irq) {161ret = -EINVAL;162goto err_no_irq;163}164165host->hw_name = dev_name(&ofdev->dev);166if (sdhci_of_data) {167host->quirks = sdhci_of_data->quirks;168host->ops = &sdhci_of_data->ops;169}170171if (of_get_property(np, "sdhci,auto-cmd12", NULL))172host->quirks |= SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12;173174175if (of_get_property(np, "sdhci,1-bit-only", NULL))176host->quirks |= SDHCI_QUIRK_FORCE_1_BIT_DATA;177178if (sdhci_of_wp_inverted(np))179host->quirks |= SDHCI_QUIRK_INVERTED_WRITE_PROTECT;180181clk = of_get_property(np, "clock-frequency", &size);182if (clk && size == sizeof(*clk) && *clk)183of_host->clock = be32_to_cpup(clk);184185ret = sdhci_add_host(host);186if (ret)187goto err_add_host;188189return 0;190191err_add_host:192irq_dispose_mapping(host->irq);193err_no_irq:194iounmap(host->ioaddr);195err_addr_map:196sdhci_free_host(host);197return ret;198}199200static int __devexit sdhci_of_remove(struct platform_device *ofdev)201{202struct sdhci_host *host = dev_get_drvdata(&ofdev->dev);203204sdhci_remove_host(host, 0);205sdhci_free_host(host);206irq_dispose_mapping(host->irq);207iounmap(host->ioaddr);208return 0;209}210211static const struct of_device_id sdhci_of_match[] = {212#ifdef CONFIG_MMC_SDHCI_OF_ESDHC213{ .compatible = "fsl,mpc8379-esdhc", .data = &sdhci_esdhc, },214{ .compatible = "fsl,mpc8536-esdhc", .data = &sdhci_esdhc, },215{ .compatible = "fsl,esdhc", .data = &sdhci_esdhc, },216#endif217#ifdef CONFIG_MMC_SDHCI_OF_HLWD218{ .compatible = "nintendo,hollywood-sdhci", .data = &sdhci_hlwd, },219#endif220{ .compatible = "generic-sdhci", },221{},222};223MODULE_DEVICE_TABLE(of, sdhci_of_match);224225static struct platform_driver sdhci_of_driver = {226.driver = {227.name = "sdhci-of",228.owner = THIS_MODULE,229.of_match_table = sdhci_of_match,230},231.probe = sdhci_of_probe,232.remove = __devexit_p(sdhci_of_remove),233.suspend = sdhci_of_suspend,234.resume = sdhci_of_resume,235};236237static int __init sdhci_of_init(void)238{239return platform_driver_register(&sdhci_of_driver);240}241module_init(sdhci_of_init);242243static void __exit sdhci_of_exit(void)244{245platform_driver_unregister(&sdhci_of_driver);246}247module_exit(sdhci_of_exit);248249MODULE_DESCRIPTION("Secure Digital Host Controller Interface OF driver");250MODULE_AUTHOR("Xiaobo Xie <[email protected]>, "251"Anton Vorontsov <[email protected]>");252MODULE_LICENSE("GPL");253254255