wcd937x_slave.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/module.h>
  6. #include <linux/slab.h>
  7. #include <linux/platform_device.h>
  8. #include <linux/device.h>
  9. #include <linux/kernel.h>
  10. #include <linux/component.h>
  11. #include <soc/soundwire.h>
  12. struct wcd937x_slave_priv {
  13. struct swr_device *swr_slave;
  14. };
  15. static int wcd937x_slave_bind(struct device *dev,
  16. struct device *master, void *data)
  17. {
  18. int ret = 0;
  19. struct wcd937x_slave_priv *wcd937x_slave = NULL;
  20. uint8_t devnum = 0;
  21. struct swr_device *pdev = to_swr_device(dev);
  22. if (pdev == NULL) {
  23. dev_err(dev, "%s: pdev is NULL\n", __func__);
  24. return -EINVAL;
  25. }
  26. wcd937x_slave = devm_kzalloc(&pdev->dev,
  27. sizeof(struct wcd937x_slave_priv), GFP_KERNEL);
  28. if (!wcd937x_slave)
  29. return -ENOMEM;
  30. swr_set_dev_data(pdev, wcd937x_slave);
  31. wcd937x_slave->swr_slave = pdev;
  32. ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum);
  33. if (ret) {
  34. dev_dbg(&pdev->dev,
  35. "%s get devnum %d for dev addr %lx failed\n",
  36. __func__, devnum, pdev->addr);
  37. swr_remove_device(pdev);
  38. return ret;
  39. }
  40. pdev->dev_num = devnum;
  41. return ret;
  42. }
  43. static void wcd937x_slave_unbind(struct device *dev,
  44. struct device *master, void *data)
  45. {
  46. struct wcd937x_slave_priv *wcd937x_slave = NULL;
  47. struct swr_device *pdev = to_swr_device(dev);
  48. if (pdev == NULL) {
  49. dev_err(dev, "%s: pdev is NULL\n", __func__);
  50. return;
  51. }
  52. wcd937x_slave = swr_get_dev_data(pdev);
  53. if (!wcd937x_slave) {
  54. dev_err(&pdev->dev, "%s: wcd937x_slave is NULL\n", __func__);
  55. return;
  56. }
  57. swr_set_dev_data(pdev, NULL);
  58. }
  59. static const struct swr_device_id wcd937x_swr_id[] = {
  60. {"wcd937x-slave", 0},
  61. {}
  62. };
  63. static const struct of_device_id wcd937x_swr_dt_match[] = {
  64. {
  65. .compatible = "qcom,wcd937x-slave",
  66. },
  67. {}
  68. };
  69. static const struct component_ops wcd937x_slave_comp_ops = {
  70. .bind = wcd937x_slave_bind,
  71. .unbind = wcd937x_slave_unbind,
  72. };
  73. static int wcd937x_swr_up(struct swr_device *pdev)
  74. {
  75. return 0;
  76. }
  77. static int wcd937x_swr_down(struct swr_device *pdev)
  78. {
  79. return 0;
  80. }
  81. static int wcd937x_swr_reset(struct swr_device *pdev)
  82. {
  83. return 0;
  84. }
  85. static int wcd937x_swr_probe(struct swr_device *pdev)
  86. {
  87. return component_add(&pdev->dev, &wcd937x_slave_comp_ops);
  88. }
  89. static int wcd937x_swr_remove(struct swr_device *pdev)
  90. {
  91. component_del(&pdev->dev, &wcd937x_slave_comp_ops);
  92. return 0;
  93. }
  94. static struct swr_driver wcd937x_slave_driver = {
  95. .driver = {
  96. .name = "wcd937x-slave",
  97. .owner = THIS_MODULE,
  98. .of_match_table = wcd937x_swr_dt_match,
  99. },
  100. .probe = wcd937x_swr_probe,
  101. .remove = wcd937x_swr_remove,
  102. .id_table = wcd937x_swr_id,
  103. .device_up = wcd937x_swr_up,
  104. .device_down = wcd937x_swr_down,
  105. .reset_device = wcd937x_swr_reset,
  106. };
  107. static int __init wcd937x_slave_init(void)
  108. {
  109. return swr_driver_register(&wcd937x_slave_driver);
  110. }
  111. static void __exit wcd937x_slave_exit(void)
  112. {
  113. swr_driver_unregister(&wcd937x_slave_driver);
  114. }
  115. module_init(wcd937x_slave_init);
  116. module_exit(wcd937x_slave_exit);
  117. MODULE_DESCRIPTION("WCD937X Swr Slave driver");
  118. MODULE_LICENSE("GPL v2");