fimc-is-i2c.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Samsung EXYNOS4x12 FIMC-IS (Imaging Subsystem) driver
  3. *
  4. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  5. *
  6. * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/clk.h>
  13. #include <linux/module.h>
  14. #include <linux/i2c.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm_runtime.h>
  17. #include <linux/slab.h>
  18. #include "fimc-is-i2c.h"
  19. struct fimc_is_i2c {
  20. struct i2c_adapter adapter;
  21. struct clk *clock;
  22. };
  23. /*
  24. * An empty algorithm is used as the actual I2C bus controller driver
  25. * is implemented in the FIMC-IS subsystem firmware and the host CPU
  26. * doesn't access the I2C bus controller.
  27. */
  28. static const struct i2c_algorithm fimc_is_i2c_algorithm;
  29. static int fimc_is_i2c_probe(struct platform_device *pdev)
  30. {
  31. struct device_node *node = pdev->dev.of_node;
  32. struct fimc_is_i2c *isp_i2c;
  33. struct i2c_adapter *i2c_adap;
  34. int ret;
  35. isp_i2c = devm_kzalloc(&pdev->dev, sizeof(*isp_i2c), GFP_KERNEL);
  36. if (!isp_i2c)
  37. return -ENOMEM;
  38. isp_i2c->clock = devm_clk_get(&pdev->dev, "i2c_isp");
  39. if (IS_ERR(isp_i2c->clock)) {
  40. dev_err(&pdev->dev, "failed to get the clock\n");
  41. return PTR_ERR(isp_i2c->clock);
  42. }
  43. i2c_adap = &isp_i2c->adapter;
  44. i2c_adap->dev.of_node = node;
  45. i2c_adap->dev.parent = &pdev->dev;
  46. strlcpy(i2c_adap->name, "exynos4x12-isp-i2c", sizeof(i2c_adap->name));
  47. i2c_adap->owner = THIS_MODULE;
  48. i2c_adap->algo = &fimc_is_i2c_algorithm;
  49. i2c_adap->class = I2C_CLASS_SPD;
  50. ret = i2c_add_adapter(i2c_adap);
  51. if (ret < 0) {
  52. dev_err(&pdev->dev, "failed to add I2C bus %s\n",
  53. node->full_name);
  54. return ret;
  55. }
  56. platform_set_drvdata(pdev, isp_i2c);
  57. pm_runtime_enable(&pdev->dev);
  58. pm_runtime_enable(&i2c_adap->dev);
  59. return 0;
  60. }
  61. static int fimc_is_i2c_remove(struct platform_device *pdev)
  62. {
  63. struct fimc_is_i2c *isp_i2c = platform_get_drvdata(pdev);
  64. pm_runtime_disable(&isp_i2c->adapter.dev);
  65. pm_runtime_disable(&pdev->dev);
  66. i2c_del_adapter(&isp_i2c->adapter);
  67. return 0;
  68. }
  69. static int fimc_is_i2c_suspend(struct device *dev)
  70. {
  71. struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
  72. clk_disable_unprepare(isp_i2c->clock);
  73. return 0;
  74. }
  75. static int fimc_is_i2c_resume(struct device *dev)
  76. {
  77. struct fimc_is_i2c *isp_i2c = dev_get_drvdata(dev);
  78. return clk_prepare_enable(isp_i2c->clock);
  79. }
  80. static UNIVERSAL_DEV_PM_OPS(fimc_is_i2c_pm_ops, fimc_is_i2c_suspend,
  81. fimc_is_i2c_resume, NULL);
  82. static const struct of_device_id fimc_is_i2c_of_match[] = {
  83. { .compatible = FIMC_IS_I2C_COMPATIBLE },
  84. { },
  85. };
  86. static struct platform_driver fimc_is_i2c_driver = {
  87. .probe = fimc_is_i2c_probe,
  88. .remove = fimc_is_i2c_remove,
  89. .driver = {
  90. .of_match_table = fimc_is_i2c_of_match,
  91. .name = "fimc-isp-i2c",
  92. .owner = THIS_MODULE,
  93. .pm = &fimc_is_i2c_pm_ops,
  94. }
  95. };
  96. int fimc_is_register_i2c_driver(void)
  97. {
  98. return platform_driver_register(&fimc_is_i2c_driver);
  99. }
  100. void fimc_is_unregister_i2c_driver(void)
  101. {
  102. platform_driver_unregister(&fimc_is_i2c_driver);
  103. }