sdw.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
  2. // Copyright(c) 2015-17 Intel Corporation.
  3. #ifndef __SOUNDWIRE_H
  4. #define __SOUNDWIRE_H
  5. struct sdw_bus;
  6. struct sdw_slave;
  7. /* SDW spec defines and enums, as defined by MIPI 1.1. Spec */
  8. /* SDW Broadcast Device Number */
  9. #define SDW_BROADCAST_DEV_NUM 15
  10. /* SDW Enumeration Device Number */
  11. #define SDW_ENUM_DEV_NUM 0
  12. /* SDW Group Device Numbers */
  13. #define SDW_GROUP12_DEV_NUM 12
  14. #define SDW_GROUP13_DEV_NUM 13
  15. /* SDW Master Device Number, not supported yet */
  16. #define SDW_MASTER_DEV_NUM 14
  17. #define SDW_MAX_DEVICES 11
  18. /**
  19. * enum sdw_slave_status - Slave status
  20. * @SDW_SLAVE_UNATTACHED: Slave is not attached with the bus.
  21. * @SDW_SLAVE_ATTACHED: Slave is attached with bus.
  22. * @SDW_SLAVE_ALERT: Some alert condition on the Slave
  23. * @SDW_SLAVE_RESERVED: Reserved for future use
  24. */
  25. enum sdw_slave_status {
  26. SDW_SLAVE_UNATTACHED = 0,
  27. SDW_SLAVE_ATTACHED = 1,
  28. SDW_SLAVE_ALERT = 2,
  29. SDW_SLAVE_RESERVED = 3,
  30. };
  31. /*
  32. * SDW Slave Structures and APIs
  33. */
  34. /**
  35. * struct sdw_slave_id - Slave ID
  36. * @mfg_id: MIPI Manufacturer ID
  37. * @part_id: Device Part ID
  38. * @class_id: MIPI Class ID, unused now.
  39. * Currently a placeholder in MIPI SoundWire Spec
  40. * @unique_id: Device unique ID
  41. * @sdw_version: SDW version implemented
  42. *
  43. * The order of the IDs here does not follow the DisCo spec definitions
  44. */
  45. struct sdw_slave_id {
  46. __u16 mfg_id;
  47. __u16 part_id;
  48. __u8 class_id;
  49. __u8 unique_id:4;
  50. __u8 sdw_version:4;
  51. };
  52. /**
  53. * struct sdw_slave - SoundWire Slave
  54. * @id: MIPI device ID
  55. * @dev: Linux device
  56. * @status: Status reported by the Slave
  57. * @bus: Bus handle
  58. * @node: node for bus list
  59. * @dev_num: Device Number assigned by Bus
  60. */
  61. struct sdw_slave {
  62. struct sdw_slave_id id;
  63. struct device dev;
  64. enum sdw_slave_status status;
  65. struct sdw_bus *bus;
  66. struct list_head node;
  67. u16 dev_num;
  68. };
  69. #define dev_to_sdw_dev(_dev) container_of(_dev, struct sdw_slave, dev)
  70. struct sdw_driver {
  71. const char *name;
  72. int (*probe)(struct sdw_slave *sdw,
  73. const struct sdw_device_id *id);
  74. int (*remove)(struct sdw_slave *sdw);
  75. void (*shutdown)(struct sdw_slave *sdw);
  76. const struct sdw_device_id *id_table;
  77. const struct sdw_slave_ops *ops;
  78. struct device_driver driver;
  79. };
  80. #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \
  81. { .mfg_id = (_mfg_id), .part_id = (_part_id), \
  82. .driver_data = (unsigned long)(_drv_data) }
  83. /*
  84. * SDW master structures and APIs
  85. */
  86. /**
  87. * struct sdw_bus - SoundWire bus
  88. * @dev: Master linux device
  89. * @link_id: Link id number, can be 0 to N, unique for each Master
  90. * @slaves: list of Slaves on this bus
  91. * @assigned: Bitmap for Slave device numbers.
  92. * Bit set implies used number, bit clear implies unused number.
  93. * @bus_lock: bus lock
  94. */
  95. struct sdw_bus {
  96. struct device *dev;
  97. unsigned int link_id;
  98. struct list_head slaves;
  99. DECLARE_BITMAP(assigned, SDW_MAX_DEVICES);
  100. struct mutex bus_lock;
  101. };
  102. int sdw_add_bus_master(struct sdw_bus *bus);
  103. void sdw_delete_bus_master(struct sdw_bus *bus);
  104. #endif /* __SOUNDWIRE_H */