wcd938x-slave.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0-only
  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 wcd938x_slave_priv {
  13. struct swr_device *swr_slave;
  14. };
  15. static int wcd938x_slave_bind(struct device *dev,
  16. struct device *master, void *data)
  17. {
  18. int ret = 0;
  19. uint8_t devnum = 0;
  20. struct swr_device *pdev = to_swr_device(dev);
  21. ret = swr_get_logical_dev_num(pdev, pdev->addr, &devnum);
  22. if (ret) {
  23. dev_dbg(&pdev->dev,
  24. "%s get devnum %d for dev addr %lx failed\n",
  25. __func__, devnum, pdev->addr);
  26. return ret;
  27. }
  28. pdev->dev_num = devnum;
  29. return ret;
  30. }
  31. static void wcd938x_slave_unbind(struct device *dev,
  32. struct device *master, void *data)
  33. {
  34. struct wcd938x_slave_priv *wcd938x_slave = NULL;
  35. struct swr_device *pdev = to_swr_device(dev);
  36. wcd938x_slave = swr_get_dev_data(pdev);
  37. if (!wcd938x_slave) {
  38. dev_err(&pdev->dev, "%s: wcd938x_slave is NULL\n", __func__);
  39. return;
  40. }
  41. }
  42. static const struct swr_device_id wcd938x_swr_id[] = {
  43. {"wcd938x-slave", 0},
  44. {}
  45. };
  46. static const struct of_device_id wcd938x_swr_dt_match[] = {
  47. {
  48. .compatible = "qcom,wcd938x-slave",
  49. },
  50. {}
  51. };
  52. static const struct component_ops wcd938x_slave_comp_ops = {
  53. .bind = wcd938x_slave_bind,
  54. .unbind = wcd938x_slave_unbind,
  55. };
  56. static int wcd938x_swr_probe(struct swr_device *pdev)
  57. {
  58. struct wcd938x_slave_priv *wcd938x_slave = NULL;
  59. wcd938x_slave = devm_kzalloc(&pdev->dev,
  60. sizeof(struct wcd938x_slave_priv), GFP_KERNEL);
  61. if (!wcd938x_slave)
  62. return -ENOMEM;
  63. swr_set_dev_data(pdev, wcd938x_slave);
  64. wcd938x_slave->swr_slave = pdev;
  65. return component_add(&pdev->dev, &wcd938x_slave_comp_ops);
  66. }
  67. static int wcd938x_swr_remove(struct swr_device *pdev)
  68. {
  69. component_del(&pdev->dev, &wcd938x_slave_comp_ops);
  70. swr_set_dev_data(pdev, NULL);
  71. swr_remove_device(pdev);
  72. return 0;
  73. }
  74. static struct swr_driver wcd938x_slave_driver = {
  75. .driver = {
  76. .name = "wcd938x-slave",
  77. .owner = THIS_MODULE,
  78. .of_match_table = wcd938x_swr_dt_match,
  79. },
  80. .probe = wcd938x_swr_probe,
  81. .remove = wcd938x_swr_remove,
  82. .id_table = wcd938x_swr_id,
  83. };
  84. static int __init wcd938x_slave_init(void)
  85. {
  86. return swr_driver_register(&wcd938x_slave_driver);
  87. }
  88. static void __exit wcd938x_slave_exit(void)
  89. {
  90. swr_driver_unregister(&wcd938x_slave_driver);
  91. }
  92. module_init(wcd938x_slave_init);
  93. module_exit(wcd938x_slave_exit);
  94. MODULE_DESCRIPTION("WCD938X Swr Slave driver");
  95. MODULE_LICENSE("GPL v2");