/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ /* * AMD MP2 I2C adapter driver * * Authors: Shyam Sundar S K <[email protected]> * Elie Morisse <[email protected]> */ #ifndef I2C_AMD_PCI_MP2_H #define I2C_AMD_PCI_MP2_H #include <linux/i2c.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #define PCI_DEVICE_ID_AMD_MP2 … struct amd_i2c_common; struct amd_mp2_dev; enum { … }; /* Command register data structures */ #define i2c_none … enum i2c_cmd { … }; enum speed_enum { … }; enum mem_type { … }; /** * union i2c_cmd_base : bit access of C2P commands * @i2c_cmd: bit 0..3 i2c R/W command * @bus_id: bit 4..7 i2c bus index * @slave_addr: bit 8..15 slave address * @length: bit 16..27 read/write length * @i2c_speed: bit 28..30 bus speed * @mem_type: bit 31 0-DRAM; 1-C2P msg o/p */ i2c_cmd_base; enum response_type { … }; enum status_type { … }; /** * union i2c_event : bit access of P2C events * @response: bit 0..1 i2c response type * @status: bit 2..6 status_type * @mem_type: bit 7 0-DRAM; 1-C2P msg o/p * @bus_id: bit 8..11 i2c bus id * @length: bit 12..23 message length * @slave_addr: bit 24-31 slave address */ i2c_event; /** * struct amd_i2c_common - per bus/i2c adapter context, shared * between the pci and the platform driver * @eventval: MP2 event value set by the IRQ handler * @mp2_dev: MP2 pci device this adapter is part of * @msg: i2c message * @cmd_completion: function called by the IRQ handler to signal * the platform driver * @reqcmd: requested i2c command type * @cmd_success: set to true if the MP2 responded to a command with * the expected status and response type * @bus_id: bus index * @i2c_speed: i2c bus speed determined by the slowest slave * @dma_buf: if msg length > 32, holds the DMA buffer virtual address * @dma_addr: if msg length > 32, holds the DMA buffer address */ struct amd_i2c_common { … }; /** * struct amd_mp2_dev - per PCI device context * @pci_dev: PCI driver node * @busses: MP2 devices may have up to two busses, * each bus corresponding to an i2c adapter * @mmio: iommapped registers * @c2p_lock: controls access to the C2P mailbox shared between * the two adapters * @c2p_lock_busid: id of the adapter which locked c2p_lock */ struct amd_mp2_dev { … }; /* PCIe communication driver */ int amd_mp2_rw(struct amd_i2c_common *i2c_common, enum i2c_cmd reqcmd); int amd_mp2_bus_enable_set(struct amd_i2c_common *i2c_common, bool enable); void amd_mp2_process_event(struct amd_i2c_common *i2c_common); void amd_mp2_rw_timeout(struct amd_i2c_common *i2c_common); int amd_mp2_register_cb(struct amd_i2c_common *i2c_common); int amd_mp2_unregister_cb(struct amd_i2c_common *i2c_common); struct amd_mp2_dev *amd_mp2_find_device(void); static inline void amd_mp2_pm_runtime_get(struct amd_mp2_dev *mp2_dev) { … } static inline void amd_mp2_pm_runtime_put(struct amd_mp2_dev *mp2_dev) { … } #endif