sh_mobile_sdhi.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/platform_device.h>
  23. #include <linux/mmc/host.h>
  24. #include <linux/mfd/core.h>
  25. #include <linux/mfd/tmio.h>
  26. #include <linux/mfd/sh_mobile_sdhi.h>
  27. struct sh_mobile_sdhi {
  28. struct clk *clk;
  29. struct tmio_mmc_data mmc_data;
  30. struct mfd_cell cell_mmc;
  31. };
  32. static struct resource sh_mobile_sdhi_resources[] = {
  33. {
  34. .start = 0x000,
  35. .end = 0x1ff,
  36. .flags = IORESOURCE_MEM,
  37. },
  38. {
  39. .start = 0,
  40. .end = 0,
  41. .flags = IORESOURCE_IRQ,
  42. },
  43. };
  44. static struct mfd_cell sh_mobile_sdhi_cell = {
  45. .name = "tmio-mmc",
  46. .num_resources = ARRAY_SIZE(sh_mobile_sdhi_resources),
  47. .resources = sh_mobile_sdhi_resources,
  48. };
  49. static void sh_mobile_sdhi_set_pwr(struct platform_device *tmio, int state)
  50. {
  51. struct platform_device *pdev = to_platform_device(tmio->dev.parent);
  52. struct sh_mobile_sdhi_info *p = pdev->dev.platform_data;
  53. if (p && p->set_pwr)
  54. p->set_pwr(pdev, state);
  55. }
  56. static int __init sh_mobile_sdhi_probe(struct platform_device *pdev)
  57. {
  58. struct sh_mobile_sdhi *priv;
  59. struct resource *mem;
  60. char clk_name[8];
  61. int ret, irq;
  62. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  63. if (!mem)
  64. dev_err(&pdev->dev, "missing MEM resource\n");
  65. irq = platform_get_irq(pdev, 0);
  66. if (irq < 0)
  67. dev_err(&pdev->dev, "missing IRQ resource\n");
  68. if (!mem || (irq < 0))
  69. return -EINVAL;
  70. priv = kzalloc(sizeof(struct sh_mobile_sdhi), GFP_KERNEL);
  71. if (priv == NULL) {
  72. dev_err(&pdev->dev, "kzalloc failed\n");
  73. return -ENOMEM;
  74. }
  75. snprintf(clk_name, sizeof(clk_name), "sdhi%d", pdev->id);
  76. priv->clk = clk_get(&pdev->dev, clk_name);
  77. if (IS_ERR(priv->clk)) {
  78. dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
  79. ret = PTR_ERR(priv->clk);
  80. kfree(priv);
  81. return ret;
  82. }
  83. clk_enable(priv->clk);
  84. priv->mmc_data.hclk = clk_get_rate(priv->clk);
  85. priv->mmc_data.set_pwr = sh_mobile_sdhi_set_pwr;
  86. priv->mmc_data.capabilities = MMC_CAP_MMC_HIGHSPEED;
  87. memcpy(&priv->cell_mmc, &sh_mobile_sdhi_cell, sizeof(priv->cell_mmc));
  88. priv->cell_mmc.driver_data = &priv->mmc_data;
  89. priv->cell_mmc.platform_data = &priv->cell_mmc;
  90. priv->cell_mmc.data_size = sizeof(priv->cell_mmc);
  91. platform_set_drvdata(pdev, priv);
  92. ret = mfd_add_devices(&pdev->dev, pdev->id,
  93. &priv->cell_mmc, 1, mem, irq);
  94. if (ret) {
  95. clk_disable(priv->clk);
  96. clk_put(priv->clk);
  97. kfree(priv);
  98. }
  99. return ret;
  100. }
  101. static int sh_mobile_sdhi_remove(struct platform_device *pdev)
  102. {
  103. struct sh_mobile_sdhi *priv = platform_get_drvdata(pdev);
  104. mfd_remove_devices(&pdev->dev);
  105. clk_disable(priv->clk);
  106. clk_put(priv->clk);
  107. kfree(priv);
  108. return 0;
  109. }
  110. static struct platform_driver sh_mobile_sdhi_driver = {
  111. .driver = {
  112. .name = "sh_mobile_sdhi",
  113. .owner = THIS_MODULE,
  114. },
  115. .probe = sh_mobile_sdhi_probe,
  116. .remove = __devexit_p(sh_mobile_sdhi_remove),
  117. };
  118. static int __init sh_mobile_sdhi_init(void)
  119. {
  120. return platform_driver_register(&sh_mobile_sdhi_driver);
  121. }
  122. static void __exit sh_mobile_sdhi_exit(void)
  123. {
  124. platform_driver_unregister(&sh_mobile_sdhi_driver);
  125. }
  126. module_init(sh_mobile_sdhi_init);
  127. module_exit(sh_mobile_sdhi_exit);
  128. MODULE_DESCRIPTION("SuperH Mobile SDHI driver");
  129. MODULE_AUTHOR("Magnus Damm");
  130. MODULE_LICENSE("GPL v2");