dw-i3c-master.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (c) 2023 Code Construct
  4. *
  5. * Author: Jeremy Kerr <jk@codeconstruct.com.au>
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/i3c/master.h>
  9. #include <linux/reset.h>
  10. #include <linux/types.h>
  11. #define DW_I3C_MAX_DEVS 32
  12. struct dw_i3c_master_caps {
  13. u8 cmdfifodepth;
  14. u8 datafifodepth;
  15. };
  16. struct dw_i3c_dat_entry {
  17. u8 addr;
  18. bool is_i2c_addr;
  19. struct i3c_dev_desc *ibi_dev;
  20. };
  21. struct dw_i3c_master {
  22. struct i3c_master_controller base;
  23. struct device *dev;
  24. u16 maxdevs;
  25. u16 datstartaddr;
  26. u32 free_pos;
  27. struct {
  28. struct list_head list;
  29. struct dw_i3c_xfer *cur;
  30. spinlock_t lock;
  31. } xferqueue;
  32. struct dw_i3c_master_caps caps;
  33. void __iomem *regs;
  34. struct reset_control *core_rst;
  35. struct clk *core_clk;
  36. struct clk *pclk;
  37. char version[5];
  38. char type[5];
  39. u32 sir_rej_mask;
  40. bool i2c_slv_prsnt;
  41. u32 dev_addr;
  42. u32 i3c_pp_timing;
  43. u32 i3c_od_timing;
  44. u32 ext_lcnt_timing;
  45. u32 bus_free_timing;
  46. u32 i2c_fm_timing;
  47. u32 i2c_fmp_timing;
  48. /*
  49. * Per-device hardware data, used to manage the device address table
  50. * (DAT)
  51. *
  52. * Locking: the devs array may be referenced in IRQ context while
  53. * processing an IBI. However, IBIs (for a specific device, which
  54. * implies a specific DAT entry) can only happen while interrupts are
  55. * requested for that device, which is serialised against other
  56. * insertions/removals from the array by the global i3c infrastructure.
  57. * So, devs_lock protects against concurrent updates to devs->ibi_dev
  58. * between request_ibi/free_ibi and the IBI irq event.
  59. */
  60. struct dw_i3c_dat_entry devs[DW_I3C_MAX_DEVS];
  61. spinlock_t devs_lock;
  62. /* platform-specific data */
  63. const struct dw_i3c_platform_ops *platform_ops;
  64. struct work_struct hj_work;
  65. };
  66. struct dw_i3c_platform_ops {
  67. /*
  68. * Called on early bus init: the i3c has been set up, but before any
  69. * transactions have taken place. Platform implementations may use to
  70. * perform actual device enabling with the i3c core ready.
  71. */
  72. int (*init)(struct dw_i3c_master *i3c);
  73. /*
  74. * Initialise a DAT entry to enable/disable IBIs. Allows the platform
  75. * to perform any device workarounds on the DAT entry before
  76. * inserting into the hardware table.
  77. *
  78. * Called with the DAT lock held; must not sleep.
  79. */
  80. void (*set_dat_ibi)(struct dw_i3c_master *i3c,
  81. struct i3c_dev_desc *dev, bool enable, u32 *reg);
  82. };
  83. extern int dw_i3c_common_probe(struct dw_i3c_master *master,
  84. struct platform_device *pdev);
  85. extern void dw_i3c_common_remove(struct dw_i3c_master *master);