wcd937x_slave.c 3.4 KB

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