sh_mobile_sdhi.c 3.3 KB

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