Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) |
| 2 | // Copyright(c) 2015-17 Intel Corporation. |
| 3 | |
| 4 | /* |
| 5 | * SDW Intel Init Routines |
| 6 | * |
| 7 | * Initializes and creates SDW devices based on ACPI and Hardware values |
| 8 | */ |
| 9 | |
| 10 | #include <linux/acpi.h> |
Paul Gortmaker | 4abbd78 | 2019-04-13 11:12:52 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Vinod Koul | 3fc4044 | 2019-10-22 10:03:08 +0530 | [diff] [blame] | 13 | #include <linux/io.h> |
Paul Gortmaker | 4abbd78 | 2019-04-13 11:12:52 -0400 | [diff] [blame] | 14 | #include <linux/module.h> |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 15 | #include <linux/auxiliary_bus.h> |
Pierre-Louis Bossart | ebf878e | 2020-08-17 23:29:12 +0800 | [diff] [blame] | 16 | #include <linux/pm_runtime.h> |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 17 | #include <linux/soundwire/sdw_intel.h> |
Pierre-Louis Bossart | b6109dd | 2020-06-01 02:20:57 +0800 | [diff] [blame] | 18 | #include "cadence_master.h" |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 19 | #include "intel.h" |
| 20 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 21 | static void intel_link_dev_release(struct device *dev) |
| 22 | { |
| 23 | struct auxiliary_device *auxdev = to_auxiliary_dev(dev); |
| 24 | struct sdw_intel_link_dev *ldev = auxiliary_dev_to_sdw_intel_link_dev(auxdev); |
| 25 | |
| 26 | kfree(ldev); |
| 27 | } |
| 28 | |
| 29 | /* alloc, init and add link devices */ |
| 30 | static struct sdw_intel_link_dev *intel_link_dev_register(struct sdw_intel_res *res, |
| 31 | struct sdw_intel_ctx *ctx, |
| 32 | struct fwnode_handle *fwnode, |
| 33 | const char *name, |
| 34 | int link_id) |
| 35 | { |
| 36 | struct sdw_intel_link_dev *ldev; |
| 37 | struct sdw_intel_link_res *link; |
| 38 | struct auxiliary_device *auxdev; |
| 39 | int ret; |
| 40 | |
| 41 | ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); |
| 42 | if (!ldev) |
| 43 | return ERR_PTR(-ENOMEM); |
| 44 | |
| 45 | auxdev = &ldev->auxdev; |
| 46 | auxdev->name = name; |
| 47 | auxdev->dev.parent = res->parent; |
| 48 | auxdev->dev.fwnode = fwnode; |
| 49 | auxdev->dev.release = intel_link_dev_release; |
| 50 | |
| 51 | /* we don't use an IDA since we already have a link ID */ |
| 52 | auxdev->id = link_id; |
| 53 | |
| 54 | /* |
| 55 | * keep a handle on the allocated memory, to be used in all other functions. |
| 56 | * Since the same pattern is used to skip links that are not enabled, there is |
| 57 | * no need to check if ctx->ldev[i] is NULL later on. |
| 58 | */ |
| 59 | ctx->ldev[link_id] = ldev; |
| 60 | |
| 61 | /* Add link information used in the driver probe */ |
| 62 | link = &ldev->link_res; |
| 63 | link->mmio_base = res->mmio_base; |
| 64 | link->registers = res->mmio_base + SDW_LINK_BASE |
| 65 | + (SDW_LINK_SIZE * link_id); |
Bard Liao | 60e9feb | 2021-07-23 19:54:51 +0800 | [diff] [blame] | 66 | link->shim = res->mmio_base + res->shim_base; |
| 67 | link->alh = res->mmio_base + res->alh_base; |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 68 | |
| 69 | link->ops = res->ops; |
| 70 | link->dev = res->dev; |
| 71 | |
| 72 | link->clock_stop_quirks = res->clock_stop_quirks; |
| 73 | link->shim_lock = &ctx->shim_lock; |
| 74 | link->shim_mask = &ctx->shim_mask; |
| 75 | link->link_mask = ctx->link_mask; |
| 76 | |
| 77 | /* now follow the two-step init/add sequence */ |
| 78 | ret = auxiliary_device_init(auxdev); |
| 79 | if (ret < 0) { |
| 80 | dev_err(res->parent, "failed to initialize link dev %s link_id %d\n", |
| 81 | name, link_id); |
| 82 | kfree(ldev); |
| 83 | return ERR_PTR(ret); |
| 84 | } |
| 85 | |
| 86 | ret = auxiliary_device_add(&ldev->auxdev); |
| 87 | if (ret < 0) { |
| 88 | dev_err(res->parent, "failed to add link dev %s link_id %d\n", |
| 89 | ldev->auxdev.name, link_id); |
| 90 | /* ldev will be freed with the put_device() and .release sequence */ |
| 91 | auxiliary_device_uninit(&ldev->auxdev); |
| 92 | return ERR_PTR(ret); |
| 93 | } |
| 94 | |
| 95 | return ldev; |
| 96 | } |
| 97 | |
| 98 | static void intel_link_dev_unregister(struct sdw_intel_link_dev *ldev) |
| 99 | { |
| 100 | auxiliary_device_delete(&ldev->auxdev); |
| 101 | auxiliary_device_uninit(&ldev->auxdev); |
| 102 | } |
| 103 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 104 | static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx) |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 105 | { |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 106 | struct sdw_intel_link_dev *ldev; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 107 | u32 link_mask; |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 108 | int i; |
| 109 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 110 | link_mask = ctx->link_mask; |
| 111 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 112 | for (i = 0; i < ctx->count; i++) { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 113 | if (!(link_mask & BIT(i))) |
| 114 | continue; |
| 115 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 116 | ldev = ctx->ldev[i]; |
Pierre-Louis Bossart | ab996b2 | 2020-08-17 23:29:21 +0800 | [diff] [blame] | 117 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 118 | pm_runtime_disable(&ldev->auxdev.dev); |
| 119 | if (!ldev->link_res.clock_stop_quirks) |
| 120 | pm_runtime_put_noidle(ldev->link_res.dev); |
| 121 | |
| 122 | intel_link_dev_unregister(ldev); |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 123 | } |
| 124 | |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Pierre-Louis Bossart | 12b1614 | 2020-07-16 23:09:43 +0800 | [diff] [blame] | 128 | #define HDA_DSP_REG_ADSPIC2 (0x10) |
| 129 | #define HDA_DSP_REG_ADSPIS2 (0x14) |
| 130 | #define HDA_DSP_REG_ADSPIC2_SNDW BIT(5) |
| 131 | |
| 132 | /** |
| 133 | * sdw_intel_enable_irq() - enable/disable Intel SoundWire IRQ |
| 134 | * @mmio_base: The mmio base of the control register |
| 135 | * @enable: true if enable |
| 136 | */ |
| 137 | void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable) |
| 138 | { |
| 139 | u32 val; |
| 140 | |
| 141 | val = readl(mmio_base + HDA_DSP_REG_ADSPIC2); |
| 142 | |
| 143 | if (enable) |
| 144 | val |= HDA_DSP_REG_ADSPIC2_SNDW; |
| 145 | else |
| 146 | val &= ~HDA_DSP_REG_ADSPIC2_SNDW; |
| 147 | |
| 148 | writel(val, mmio_base + HDA_DSP_REG_ADSPIC2); |
| 149 | } |
Pierre-Louis Bossart | 8459cea | 2020-07-16 23:09:44 +0800 | [diff] [blame] | 150 | EXPORT_SYMBOL_NS(sdw_intel_enable_irq, SOUNDWIRE_INTEL_INIT); |
Pierre-Louis Bossart | 12b1614 | 2020-07-16 23:09:43 +0800 | [diff] [blame] | 151 | |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 152 | irqreturn_t sdw_intel_thread(int irq, void *dev_id) |
| 153 | { |
| 154 | struct sdw_intel_ctx *ctx = dev_id; |
| 155 | struct sdw_intel_link_res *link; |
| 156 | |
| 157 | list_for_each_entry(link, &ctx->link_list, list) |
| 158 | sdw_cdns_irq(irq, link->cdns); |
| 159 | |
| 160 | sdw_intel_enable_irq(ctx->mmio_base, true); |
| 161 | return IRQ_HANDLED; |
| 162 | } |
| 163 | EXPORT_SYMBOL_NS(sdw_intel_thread, SOUNDWIRE_INTEL_INIT); |
| 164 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 165 | static struct sdw_intel_ctx |
| 166 | *sdw_intel_probe_controller(struct sdw_intel_res *res) |
| 167 | { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 168 | struct sdw_intel_link_res *link; |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 169 | struct sdw_intel_link_dev *ldev; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 170 | struct sdw_intel_ctx *ctx; |
| 171 | struct acpi_device *adev; |
Bard Liao | a818440 | 2020-07-16 23:09:47 +0800 | [diff] [blame] | 172 | struct sdw_slave *slave; |
| 173 | struct list_head *node; |
| 174 | struct sdw_bus *bus; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 175 | u32 link_mask; |
Bard Liao | a818440 | 2020-07-16 23:09:47 +0800 | [diff] [blame] | 176 | int num_slaves = 0; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 177 | int count; |
| 178 | int i; |
| 179 | |
| 180 | if (!res) |
| 181 | return NULL; |
| 182 | |
| 183 | if (acpi_bus_get_device(res->handle, &adev)) |
| 184 | return NULL; |
| 185 | |
| 186 | if (!res->count) |
| 187 | return NULL; |
| 188 | |
| 189 | count = res->count; |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 190 | dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count); |
| 191 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 192 | /* |
| 193 | * we need to alloc/free memory manually and can't use devm: |
| 194 | * this routine may be called from a workqueue, and not from |
| 195 | * the parent .probe. |
| 196 | * If devm_ was used, the memory might never be freed on errors. |
| 197 | */ |
| 198 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 199 | if (!ctx) |
| 200 | return NULL; |
| 201 | |
| 202 | ctx->count = count; |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 203 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 204 | /* |
| 205 | * allocate the array of pointers. The link-specific data is allocated |
| 206 | * as part of the first loop below and released with the auxiliary_device_uninit(). |
| 207 | * If some links are disabled, the link pointer will remain NULL. Given that the |
| 208 | * number of links is small, this is simpler than using a list to keep track of links. |
| 209 | */ |
| 210 | ctx->ldev = kcalloc(ctx->count, sizeof(*ctx->ldev), GFP_KERNEL); |
| 211 | if (!ctx->ldev) { |
| 212 | kfree(ctx); |
| 213 | return NULL; |
| 214 | } |
| 215 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 216 | ctx->mmio_base = res->mmio_base; |
Bard Liao | 60e9feb | 2021-07-23 19:54:51 +0800 | [diff] [blame] | 217 | ctx->shim_base = res->shim_base; |
| 218 | ctx->alh_base = res->alh_base; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 219 | ctx->link_mask = res->link_mask; |
| 220 | ctx->handle = res->handle; |
Pierre-Louis Bossart | 4a17c44 | 2020-07-16 23:09:40 +0800 | [diff] [blame] | 221 | mutex_init(&ctx->shim_lock); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 222 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 223 | link_mask = ctx->link_mask; |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 224 | |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 225 | INIT_LIST_HEAD(&ctx->link_list); |
| 226 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 227 | for (i = 0; i < count; i++) { |
| 228 | if (!(link_mask & BIT(i))) |
Pierre-Louis Bossart | 50302fc | 2019-08-05 19:55:20 -0500 | [diff] [blame] | 229 | continue; |
Pierre-Louis Bossart | 50302fc | 2019-08-05 19:55:20 -0500 | [diff] [blame] | 230 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 231 | /* |
| 232 | * init and add a device for each link |
| 233 | * |
| 234 | * The name of the device will be soundwire_intel.link.[i], |
| 235 | * with the "soundwire_intel" module prefix automatically added |
| 236 | * by the auxiliary bus core. |
| 237 | */ |
| 238 | ldev = intel_link_dev_register(res, |
| 239 | ctx, |
| 240 | acpi_fwnode_handle(adev), |
| 241 | "link", |
| 242 | i); |
| 243 | if (IS_ERR(ldev)) |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 244 | goto err; |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 245 | |
| 246 | link = &ldev->link_res; |
| 247 | link->cdns = dev_get_drvdata(&ldev->auxdev.dev); |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 248 | |
Bard Liao | 14968dd | 2021-04-06 09:01:01 +0800 | [diff] [blame] | 249 | if (!link->cdns) { |
| 250 | dev_err(&adev->dev, "failed to get link->cdns\n"); |
| 251 | /* |
| 252 | * 1 will be subtracted from i in the err label, but we need to call |
| 253 | * intel_link_dev_unregister for this ldev, so plus 1 now |
| 254 | */ |
| 255 | i++; |
| 256 | goto err; |
| 257 | } |
Bard Liao | 4a98a6b | 2020-07-16 23:09:45 +0800 | [diff] [blame] | 258 | list_add_tail(&link->list, &ctx->link_list); |
Bard Liao | a818440 | 2020-07-16 23:09:47 +0800 | [diff] [blame] | 259 | bus = &link->cdns->bus; |
| 260 | /* Calculate number of slaves */ |
| 261 | list_for_each(node, &bus->slaves) |
| 262 | num_slaves++; |
| 263 | } |
| 264 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 265 | ctx->ids = kcalloc(num_slaves, sizeof(*ctx->ids), GFP_KERNEL); |
Bard Liao | a818440 | 2020-07-16 23:09:47 +0800 | [diff] [blame] | 266 | if (!ctx->ids) |
| 267 | goto err; |
| 268 | |
| 269 | ctx->num_slaves = num_slaves; |
| 270 | i = 0; |
| 271 | list_for_each_entry(link, &ctx->link_list, list) { |
| 272 | bus = &link->cdns->bus; |
| 273 | list_for_each_entry(slave, &bus->slaves, node) { |
| 274 | ctx->ids[i].id = slave->id; |
| 275 | ctx->ids[i].link_id = bus->link_id; |
| 276 | i++; |
| 277 | } |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return ctx; |
| 281 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 282 | err: |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 283 | while (i--) { |
| 284 | if (!(link_mask & BIT(i))) |
| 285 | continue; |
| 286 | ldev = ctx->ldev[i]; |
| 287 | intel_link_dev_unregister(ldev); |
| 288 | } |
| 289 | kfree(ctx->ldev); |
| 290 | kfree(ctx); |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 291 | return NULL; |
| 292 | } |
| 293 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 294 | static int |
| 295 | sdw_intel_startup_controller(struct sdw_intel_ctx *ctx) |
| 296 | { |
| 297 | struct acpi_device *adev; |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 298 | struct sdw_intel_link_dev *ldev; |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 299 | u32 caps; |
| 300 | u32 link_mask; |
| 301 | int i; |
| 302 | |
| 303 | if (acpi_bus_get_device(ctx->handle, &adev)) |
| 304 | return -EINVAL; |
| 305 | |
| 306 | /* Check SNDWLCAP.LCOUNT */ |
Bard Liao | 60e9feb | 2021-07-23 19:54:51 +0800 | [diff] [blame] | 307 | caps = ioread32(ctx->mmio_base + ctx->shim_base + SDW_SHIM_LCAP); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 308 | caps &= GENMASK(2, 0); |
| 309 | |
| 310 | /* Check HW supported vs property value */ |
| 311 | if (caps < ctx->count) { |
| 312 | dev_err(&adev->dev, |
| 313 | "BIOS master count is larger than hardware capabilities\n"); |
| 314 | return -EINVAL; |
| 315 | } |
| 316 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 317 | if (!ctx->ldev) |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 320 | link_mask = ctx->link_mask; |
| 321 | |
| 322 | /* Startup SDW Master devices */ |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 323 | for (i = 0; i < ctx->count; i++) { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 324 | if (!(link_mask & BIT(i))) |
| 325 | continue; |
| 326 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 327 | ldev = ctx->ldev[i]; |
Pierre-Louis Bossart | ab996b2 | 2020-08-17 23:29:21 +0800 | [diff] [blame] | 328 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 329 | intel_link_startup(&ldev->auxdev); |
| 330 | |
| 331 | if (!ldev->link_res.clock_stop_quirks) { |
Pierre-Louis Bossart | ab996b2 | 2020-08-17 23:29:21 +0800 | [diff] [blame] | 332 | /* |
| 333 | * we need to prevent the parent PCI device |
| 334 | * from entering pm_runtime suspend, so that |
| 335 | * power rails to the SoundWire IP are not |
| 336 | * turned off. |
| 337 | */ |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 338 | pm_runtime_get_noresume(ldev->link_res.dev); |
Pierre-Louis Bossart | ab996b2 | 2020-08-17 23:29:21 +0800 | [diff] [blame] | 339 | } |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 345 | /** |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 346 | * sdw_intel_probe() - SoundWire Intel probe routine |
| 347 | * @res: resource data |
| 348 | * |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 349 | * This registers an auxiliary device for each Master handled by the controller, |
| 350 | * and SoundWire Master and Slave devices will be created by the auxiliary |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 351 | * device probe. All the information necessary is stored in the context, and |
| 352 | * the res argument pointer can be freed after this step. |
| 353 | * This function will be called after sdw_intel_acpi_scan() by SOF probe. |
| 354 | */ |
| 355 | struct sdw_intel_ctx |
| 356 | *sdw_intel_probe(struct sdw_intel_res *res) |
| 357 | { |
| 358 | return sdw_intel_probe_controller(res); |
| 359 | } |
Pierre-Louis Bossart | 8459cea | 2020-07-16 23:09:44 +0800 | [diff] [blame] | 360 | EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 361 | |
| 362 | /** |
| 363 | * sdw_intel_startup() - SoundWire Intel startup |
| 364 | * @ctx: SoundWire context allocated in the probe |
| 365 | * |
| 366 | * Startup Intel SoundWire controller. This function will be called after |
| 367 | * Intel Audio DSP is powered up. |
| 368 | */ |
| 369 | int sdw_intel_startup(struct sdw_intel_ctx *ctx) |
| 370 | { |
| 371 | return sdw_intel_startup_controller(ctx); |
| 372 | } |
Pierre-Louis Bossart | 8459cea | 2020-07-16 23:09:44 +0800 | [diff] [blame] | 373 | EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT); |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 374 | /** |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 375 | * sdw_intel_exit() - SoundWire Intel exit |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 376 | * @ctx: SoundWire context allocated in the probe |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 377 | * |
| 378 | * Delete the controller instances created and cleanup |
| 379 | */ |
Pierre-Louis Bossart | f98f690 | 2019-12-11 19:45:01 -0600 | [diff] [blame] | 380 | void sdw_intel_exit(struct sdw_intel_ctx *ctx) |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 381 | { |
Pierre-Louis Bossart | 6d2c666 | 2020-06-01 02:21:02 +0800 | [diff] [blame] | 382 | sdw_intel_cleanup(ctx); |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 383 | kfree(ctx->ids); |
| 384 | kfree(ctx->ldev); |
| 385 | kfree(ctx); |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 386 | } |
Pierre-Louis Bossart | 8459cea | 2020-07-16 23:09:44 +0800 | [diff] [blame] | 387 | EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT); |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 388 | |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 389 | void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx) |
| 390 | { |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 391 | struct sdw_intel_link_dev *ldev; |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 392 | u32 link_mask; |
| 393 | int i; |
| 394 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 395 | if (!ctx->ldev) |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 396 | return; |
| 397 | |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 398 | link_mask = ctx->link_mask; |
| 399 | |
| 400 | /* Startup SDW Master devices */ |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 401 | for (i = 0; i < ctx->count; i++) { |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 402 | if (!(link_mask & BIT(i))) |
| 403 | continue; |
| 404 | |
Pierre-Louis Bossart | 29a269c | 2021-05-11 13:21:32 +0800 | [diff] [blame] | 405 | ldev = ctx->ldev[i]; |
| 406 | |
| 407 | intel_link_process_wakeen_event(&ldev->auxdev); |
Rander Wang | ab2c913 | 2020-07-16 23:09:46 +0800 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | EXPORT_SYMBOL_NS(sdw_intel_process_wakeen_event, SOUNDWIRE_INTEL_INIT); |
| 411 | |
Vinod Koul | d62a7d4 | 2017-12-14 11:19:44 +0530 | [diff] [blame] | 412 | MODULE_LICENSE("Dual BSD/GPL"); |
| 413 | MODULE_DESCRIPTION("Intel Soundwire Init Library"); |