sdw_intel.h 5.9 KB
Newer Older
1 2
/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
/* Copyright(c) 2015-17 Intel Corporation. */
3 4 5 6

#ifndef __SDW_INTEL_H
#define __SDW_INTEL_H

7
#include <linux/irqreturn.h>
8
#include <linux/soundwire/sdw.h>
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/**
 * struct sdw_intel_stream_params_data: configuration passed during
 * the @params_stream callback, e.g. for interaction with DSP
 * firmware.
 */
struct sdw_intel_stream_params_data {
	struct snd_pcm_substream *substream;
	struct snd_soc_dai *dai;
	struct snd_pcm_hw_params *hw_params;
	int link_id;
	int alh_stream_id;
};

/**
 * struct sdw_intel_stream_free_data: configuration passed during
 * the @free_stream callback, e.g. for interaction with DSP
 * firmware.
 */
struct sdw_intel_stream_free_data {
	struct snd_pcm_substream *substream;
	struct snd_soc_dai *dai;
	int link_id;
};

V
Vinod Koul 已提交
34 35 36 37 38
/**
 * struct sdw_intel_ops: Intel audio driver callback ops
 *
 */
struct sdw_intel_ops {
39 40 41 42
	int (*params_stream)(struct device *dev,
			     struct sdw_intel_stream_params_data *params_data);
	int (*free_stream)(struct device *dev,
			   struct sdw_intel_stream_free_data *free_data);
V
Vinod Koul 已提交
43 44
};

45
/**
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
 * struct sdw_intel_acpi_info - Soundwire Intel information found in ACPI tables
 * @handle: ACPI controller handle
 * @count: link count found with "sdw-master-count" property
 * @link_mask: bit-wise mask listing links enabled by BIOS menu
 *
 * this structure could be expanded to e.g. provide all the _ADR
 * information in case the link_mask is not sufficient to identify
 * platform capabilities.
 */
struct sdw_intel_acpi_info {
	acpi_handle handle;
	int count;
	u32 link_mask;
};

struct sdw_intel_link_res;

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
/* Intel clock-stop/pm_runtime quirk definitions */

/*
 * Force the clock to remain on during pm_runtime suspend. This might
 * be needed if Slave devices do not have an alternate clock source or
 * if the latency requirements are very strict.
 */
#define SDW_INTEL_CLK_STOP_NOT_ALLOWED		BIT(0)

/*
 * Stop the bus during pm_runtime suspend. If set, a complete bus
 * reset and re-enumeration will be performed when the bus
 * restarts. This mode shall not be used if Slave devices can generate
 * in-band wakes.
 */
#define SDW_INTEL_CLK_STOP_TEARDOWN		BIT(1)

/*
 * Stop the bus during pm_suspend if Slaves are not wake capable
 * (e.g. speaker amplifiers). The clock-stop mode is typically
 * slightly higher power than when the IP is completely powered-off.
 */
#define SDW_INTEL_CLK_STOP_WAKE_CAPABLE_ONLY	BIT(2)

/*
 * Require a bus reset (and complete re-enumeration) when exiting
 * clock stop modes. This may be needed if the controller power was
 * turned off and all context lost. This quirk shall not be used if a
 * Slave device needs to remain enumerated and keep its context,
 * e.g. to provide the reasons for the wake, report acoustic events or
 * pass a history buffer.
 */
#define SDW_INTEL_CLK_STOP_BUS_RESET		BIT(3)

97 98 99 100 101
struct sdw_intel_slave_id {
	int link_id;
	struct sdw_slave_id id;
};

102 103 104 105 106 107 108 109
/**
 * struct sdw_intel_ctx - context allocated by the controller
 * driver probe
 * @count: link count
 * @mmio_base: mmio base of SoundWire registers, only used to check
 * hardware capabilities after all power dependencies are settled.
 * @link_mask: bit-wise mask listing SoundWire links reported by the
 * Controller
110
 * @num_slaves: total number of devices exposed across all enabled links
111 112 113
 * @handle: ACPI parent handle
 * @links: information for each link (controller-specific and kept
 * opaque here)
114 115
 * @ids: array of slave_id, representing Slaves exposed across all enabled
 * links
116
 * @link_list: list to handle interrupts across all links
117
 * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers.
118
 * @shim_mask: flags to track initialization of SHIM shared registers
119 120 121 122 123
 */
struct sdw_intel_ctx {
	int count;
	void __iomem *mmio_base;
	u32 link_mask;
124
	int num_slaves;
125 126
	acpi_handle handle;
	struct sdw_intel_link_res *links;
127
	struct sdw_intel_slave_id *ids;
128
	struct list_head link_list;
129
	struct mutex shim_lock; /* lock for access to shared SHIM registers */
130
	u32 shim_mask;
131 132 133 134 135 136 137
};

/**
 * struct sdw_intel_res - Soundwire Intel global resource structure,
 * typically populated by the DSP driver
 *
 * @count: link count
138 139 140 141
 * @mmio_base: mmio base of SoundWire registers
 * @irq: interrupt number
 * @handle: ACPI parent handle
 * @parent: parent device
V
Vinod Koul 已提交
142
 * @ops: callback ops
143 144 145 146
 * @dev: device implementing hwparams and free callbacks
 * @link_mask: bit-wise mask listing links selected by the DSP driver
 * This mask may be a subset of the one reported by the controller since
 * machine-specific quirks are handled in the DSP driver.
147 148
 * @clock_stop_quirks: mask array of possible behaviors requested by the
 * DSP driver. The quirks are common for all links for now.
149 150
 */
struct sdw_intel_res {
151
	int count;
152 153 154 155
	void __iomem *mmio_base;
	int irq;
	acpi_handle handle;
	struct device *parent;
V
Vinod Koul 已提交
156
	const struct sdw_intel_ops *ops;
157 158
	struct device *dev;
	u32 link_mask;
159
	u32 clock_stop_quirks;
160 161
};

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/*
 * On Intel platforms, the SoundWire IP has dependencies on power
 * rails shared with the DSP, and the initialization steps are split
 * in three. First an ACPI scan to check what the firmware describes
 * in DSDT tables, then an allocation step (with no hardware
 * configuration but with all the relevant devices created) and last
 * the actual hardware configuration. The final stage is a global
 * interrupt enable which is controlled by the DSP driver. Splitting
 * these phases helps simplify the boot flow and make early decisions
 * on e.g. which machine driver to select (I2S mode, HDaudio or
 * SoundWire).
 */
int sdw_intel_acpi_scan(acpi_handle *parent_handle,
			struct sdw_intel_acpi_info *info);

177 178
void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx);

179 180 181 182 183 184 185 186
struct sdw_intel_ctx *
sdw_intel_probe(struct sdw_intel_res *res);

int sdw_intel_startup(struct sdw_intel_ctx *ctx);

void sdw_intel_exit(struct sdw_intel_ctx *ctx);

void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable);
187

188 189
irqreturn_t sdw_intel_thread(int irq, void *dev_id);

190 191
#define SDW_INTEL_QUIRK_MASK_BUS_DISABLE      BIT(1)

192
#endif