sh_mobile_sdhi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * SuperH Mobile SDHI
  3. *
  4. * Copyright (C) 2009 Magnus Damm
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Based on "Compaq ASIC3 support":
  11. *
  12. * Copyright 2001 Compaq Computer Corporation.
  13. * Copyright 2004-2005 Phil Blundell
  14. * Copyright 2007-2008 OpenedHand Ltd.
  15. *
  16. * Authors: Phil Blundell <pb@handhelds.org>,
  17. * Samuel Ortiz <sameo@openedhand.com>
  18. *
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/clk.h>
  22. #include <linux/slab.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/mmc/host.h>
  25. #include <linux/mfd/core.h>
  26. #include <linux/mfd/tmio.h>
  27. #include <linux/mfd/sh_mobile_sdhi.h>
  28. struct sh_mobile_sdhi {
  29. struct clk *clk;
  30. struct tmio_mmc_data mmc_data;
  31. struct mfd_cell cell_mmc;
  32. };
  33. static struct resource sh_mobile_sdhi_resources[] = {
  34. {
  35. .start = 0x000,
  36. .end = 0x1ff,
  37. .flags = IORESOURCE_MEM,
  38. },
  39. {
  40. .start = 0,
  41. .end = 0,
  42. .flags = IORESOURCE_IRQ,
  43. },
  44. };
  45. static struct mfd_cell sh_mobile_sdhi_cell = {
  46. .name = "tmio-mmc",
  47. .num_resources = ARRAY_SIZE(sh_mobile_sdhi_resources),
  48. .resources = sh_mobile_sdhi_resources,
  49. };
  50. static void sh_mobile_sdhi_set_pwr(struct platform_device *tmio, int state)
  51. {
  52. struct platform_device *pdev = to_platform_device(tmio->dev.parent);
  53. struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
  54. if (p && p->set_pwr)
  55. p->set_pwr(pdev, state);
  56. }
  57. static int __init sh_mobile_sdhi_probe(struct platform_device *pdev)
  58. {
  59. struct sh_mobile_sdhi *priv;
  60. struct resource *mem;
  61. char clk_name[8];
  62. int ret, irq;
  63. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  64. if (!mem)
  65. dev_err(&pdev->dev, "missing MEM resource\n");
  66. irq = platform_get_irq(pdev, 0);
  67. if (irq < 0)
  68. dev_err(&pdev->dev, "missing IRQ resource\n");
  69. if (!mem || (irq < 0))
  70. return -EINVAL;
  71. priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
  72. if (priv == NULL) {
  73. dev_err(&pdev->dev, "kzalloc failed\n");
  74. return -ENOMEM;
  75. }
  76. snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
  77. priv->clk = clk_get(&pdev->dev, clk_name);
  78. if (IS_ERR(priv->clk)) {
  79. dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
  80. ret = PTR_ERR(priv->clk);
  81. kfree(priv);
  82. return ret;
  83. }
  84. clk_enable(priv->clk);
  85. priv->mmc_data.hclk = clk_get_rate(priv->clk);
  86. priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr;
  87. priv->mmc_data.capabilities = MMC_CAP_MMC_HIGHSPEED;
  88. memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc));
  89. priv->cell_mmc.driver_data = &priv->mmc_data;
  90. priv->cell_mmc.platform_data = &priv->cell_mmc;
  91. priv->cell_mmc.data_size = sizeof(priv->cell_mmc);
  92. platform_set_drvdata(pdev, priv);
  93. ret = mfd_add_devices(&pdev->dev, pdev->id,
  94. &priv->cell_mmc, 1, mem, irq);
  95. if (ret) {
  96. clk_disable(priv->clk);
  97. clk_put(priv->clk);
  98. kfree(priv);
  99. }
  100. return ret;
  101. }
  102. static int sh_mobile_sdhi_remove(struct platform_device *pdev)
  103. {
  104. struct sh_mobile_sdhi *priv = platform_get_drvdata(pdev);
  105. mfd_remove_devices(&pdev->dev);
  106. clk_disable(priv->clk);
  107. clk_put(priv->clk);
  108. kfree(priv);
  109. return 0;
  110. }
  111. static struct platform_driver sh_mobile_sdhi_driver = {
  112. .driver = {
  113. .name = "sh_mobile_sdhi",
  114. .owner = THIS_MODULE,
  115. },
  116. .probe = sh_mobile_sdhi_probe,
  117. .remove = __devexit_p(sh_mobile_sdhi_remove),
  118. };
  119. static int __init sh_mobile_sdhi_init(void)
  120. {
  121. return platform_driver_register(&sh_mobile_sdhi_driver);
  122. }
  123. static void __exit sh_mobile_sdhi_exit(void)
  124. {
  125. platform_driver_unregister(&sh_mobile_sdhi_driver);
  126. }
  127. module_init(sh_mobile_sdhi_init);
  128. module_exit(sh_mobile_sdhi_exit);
  129. MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
  130. MODULE_AUTHOR("Magnus Damm");
  131. MODULE_LICENSE("GPL v2");