anatop-mfd.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Anatop MFD driver
  3. *
  4. * Copyright (C) 2012 Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>
  5. * Copyright (C) 2012 Linaro
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2 of the License, or
  23. * (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License along
  31. * with this program; if not, write to the Free Software Foundation, Inc.,
  32. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  33. *
  34. */
  35. #include <linux/io.h>
  36. #include <linux/module.h>
  37. #include <linux/platform_device.h>
  38. #include <linux/of.h>
  39. #include <linux/of_platform.h>
  40. #include <linux/of_address.h>
  41. #include <linux/mfd/anatop.h>
  42. u32 anatop_read_reg(struct anatop *adata, u32 addr)
  43. {
  44. return readl(adata->ioreg + addr);
  45. }
  46. EXPORT_SYMBOL_GPL(anatop_read_reg);
  47. void anatop_write_reg(struct anatop *adata, u32 addr, u32 data, u32 mask)
  48. {
  49. u32 val;
  50. data &= mask;
  51. spin_lock(&adata->reglock);
  52. val = readl(adata->ioreg + addr);
  53. val &= ~mask;
  54. val |= data;
  55. writel(val, adata->ioreg + addr);
  56. spin_unlock(&adata->reglock);
  57. }
  58. EXPORT_SYMBOL_GPL(anatop_write_reg);
  59. static const struct of_device_id of_anatop_match[] = {
  60. { .compatible = "fsl,imx6q-anatop", },
  61. { },
  62. };
  63. static int __devinit of_anatop_probe(struct platform_device *pdev)
  64. {
  65. struct device *dev = &pdev->dev;
  66. struct device_node *np = dev->of_node;
  67. void *ioreg;
  68. struct anatop *drvdata;
  69. ioreg = of_iomap(np, 0);
  70. if (!ioreg)
  71. return -EADDRNOTAVAIL;
  72. drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
  73. if (!drvdata)
  74. return -ENOMEM;
  75. drvdata->ioreg = ioreg;
  76. spin_lock_init(&drvdata->reglock);
  77. platform_set_drvdata(pdev, drvdata);
  78. of_platform_populate(np, of_anatop_match, NULL, dev);
  79. return 0;
  80. }
  81. static int __devexit of_anatop_remove(struct platform_device *pdev)
  82. {
  83. struct anatop *drvdata;
  84. drvdata = platform_get_drvdata(pdev);
  85. iounmap(drvdata->ioreg);
  86. return 0;
  87. }
  88. static struct platform_driver anatop_of_driver = {
  89. .driver = {
  90. .name = "anatop-mfd",
  91. .owner = THIS_MODULE,
  92. .of_match_table = of_anatop_match,
  93. },
  94. .probe = of_anatop_probe,
  95. .remove = of_anatop_remove,
  96. };
  97. static int __init anatop_init(void)
  98. {
  99. return platform_driver_register(&anatop_of_driver);
  100. }
  101. postcore_initcall(anatop_init);
  102. static void __exit anatop_exit(void)
  103. {
  104. platform_driver_unregister(&anatop_of_driver);
  105. }
  106. module_exit(anatop_exit);
  107. MODULE_AUTHOR("Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org>");
  108. MODULE_DESCRIPTION("ANATOP MFD driver");
  109. MODULE_LICENSE("GPL v2");