Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'soundwire-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire into char-misc-next

Vinod writes:

soundwire updates for 5.9-rc1

This contains few core changes and bunch of Intel driver updates:

- Adds definitions for 1.2 spec
- Sanyog left as a MAINTAINER and Bard took his place while Sanyog
is a reviewer now.
- Intel: Lots of updates to stream/dai handling, wake support and link
synchronization.

* tag 'soundwire-5.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul/soundwire: (31 commits)
Soundwire: intel_init: save Slave(s) _ADR info in sdw_intel_ctx
soundwire: intel: add wake interrupt support
soundwire: intel/cadence: merge Soundwire interrupt handlers/threads
soundwire: intel_init: use EXPORT_SYMBOL_NS
soundwire: intel_init: add implementation of sdw_intel_enable_irq()
soundwire: intel: introduce helper for link synchronization
soundwire: intel: introduce a helper to arm link synchronization
soundwire: intel: revisit SHIM programming sequences.
soundwire: intel: reuse code for wait loops to set/clear bits
soundwire: fix the kernel-doc comment
soundwire: sdw.h: fix indentation
soundwire: sdw.h: fix PRBS/Static_1 swapped definitions
soundwire: intel: don't free dma_data in DAI shutdown
soundwire: cadence: allocate/free dma_data in set_sdw_stream
soundwire: intel: remove stream allocation/free
soundwire: stream: add helper to startup/shutdown streams
soundwire: intel: implement get_sdw_stream() operations
MAINTAINERS: change SoundWire maintainer
soundwire: bus: initialize bus clock base and scale registers
soundwire: extend SDW_SLAVE_ENTRY
...

+1141 -307
+10 -1
Documentation/driver-api/soundwire/stream.rst
··· 293 293 294 294 int sdw_alloc_stream(char * stream_name); 295 295 296 + The SoundWire core provides a sdw_startup_stream() helper function, 297 + typically called during a dailink .startup() callback, which performs 298 + stream allocation and sets the stream pointer for all DAIs 299 + connected to a stream. 296 300 297 301 SDW_STREAM_CONFIGURED 298 302 ~~~~~~~~~~~~~~~~~~~~~ ··· 513 509 514 510 void sdw_release_stream(struct sdw_stream_runtime * stream); 515 511 516 - Not Supported 512 + The SoundWire core provides a sdw_shutdown_stream() helper function, 513 + typically called during a dailink .shutdown() callback, which clears 514 + the stream pointer for all DAIS connected to a stream and releases the 515 + memory allocated for the stream. 516 + 517 + Not Supported 517 518 ============= 518 519 519 520 1. A single port with multiple channels supported cannot be used between two
+2 -1
MAINTAINERS
··· 16014 16014 16015 16015 SOUNDWIRE SUBSYSTEM 16016 16016 M: Vinod Koul <vkoul@kernel.org> 16017 - M: Sanyog Kale <sanyog.r.kale@intel.com> 16017 + M: Bard Liao <yung-chuan.liao@linux.intel.com> 16018 16018 R: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> 16019 + R: Sanyog Kale <sanyog.r.kale@intel.com> 16019 16020 L: alsa-devel@alsa-project.org (moderated for non-subscribers) 16020 16021 S: Supported 16021 16022 F: Documentation/driver-api/soundwire/
+5 -5
drivers/soundwire/Makefile
··· 4 4 # 5 5 6 6 #Bus Objs 7 - soundwire-bus-objs := bus_type.o bus.o master.o slave.o mipi_disco.o stream.o \ 7 + soundwire-bus-y := bus_type.o bus.o master.o slave.o mipi_disco.o stream.o \ 8 8 sysfs_slave.o sysfs_slave_dpn.o 9 9 obj-$(CONFIG_SOUNDWIRE) += soundwire-bus.o 10 10 11 11 ifdef CONFIG_DEBUG_FS 12 - soundwire-bus-objs += debugfs.o 12 + soundwire-bus-y += debugfs.o 13 13 endif 14 14 15 15 #Cadence Objs 16 - soundwire-cadence-objs := cadence_master.o 16 + soundwire-cadence-y := cadence_master.o 17 17 obj-$(CONFIG_SOUNDWIRE_CADENCE) += soundwire-cadence.o 18 18 19 19 #Intel driver 20 - soundwire-intel-objs := intel.o intel_init.o 20 + soundwire-intel-y := intel.o intel_init.o 21 21 obj-$(CONFIG_SOUNDWIRE_INTEL) += soundwire-intel.o 22 22 23 23 #Qualcomm driver 24 - soundwire-qcom-objs := qcom.o 24 + soundwire-qcom-y := qcom.o 25 25 obj-$(CONFIG_SOUNDWIRE_QCOM) += soundwire-qcom.o
+124 -6
drivers/soundwire/bus.c
··· 863 863 if (!slave->dev_num) 864 864 continue; 865 865 866 - /* Identify if Slave(s) are available on Bus */ 867 - is_slave = true; 868 - 869 866 if (slave->status != SDW_SLAVE_ATTACHED && 870 867 slave->status != SDW_SLAVE_ALERT) 871 868 continue; 869 + 870 + /* Identify if Slave(s) are available on Bus */ 871 + is_slave = true; 872 872 873 873 slave_mode = sdw_get_clk_stop_mode(slave); 874 874 slave->curr_clk_stop_mode = slave_mode; ··· 899 899 if (ret < 0) 900 900 return ret; 901 901 } 902 + 903 + /* Don't need to inform slaves if there is no slave attached */ 904 + if (!is_slave) 905 + return ret; 902 906 903 907 /* Inform slaves that prep is done */ 904 908 list_for_each_entry(slave, &bus->slaves, node) { ··· 989 985 if (!slave->dev_num) 990 986 continue; 991 987 992 - /* Identify if Slave(s) are available on Bus */ 993 - is_slave = true; 994 - 995 988 if (slave->status != SDW_SLAVE_ATTACHED && 996 989 slave->status != SDW_SLAVE_ALERT) 997 990 continue; 991 + 992 + /* Identify if Slave(s) are available on Bus */ 993 + is_slave = true; 998 994 999 995 mode = slave->curr_clk_stop_mode; 1000 996 ··· 1019 1015 1020 1016 if (is_slave && !simple_clk_stop) 1021 1017 sdw_bus_wait_for_clk_prep_deprep(bus, SDW_BROADCAST_DEV_NUM); 1018 + 1019 + /* 1020 + * Don't need to call slave callback function if there is no slave 1021 + * attached 1022 + */ 1023 + if (!is_slave) 1024 + return 0; 1022 1025 1023 1026 list_for_each_entry(slave, &bus->slaves, node) { 1024 1027 if (!slave->dev_num) ··· 1070 1059 return ret; 1071 1060 } 1072 1061 1062 + static int sdw_slave_set_frequency(struct sdw_slave *slave) 1063 + { 1064 + u32 mclk_freq = slave->bus->prop.mclk_freq; 1065 + u32 curr_freq = slave->bus->params.curr_dr_freq >> 1; 1066 + unsigned int scale; 1067 + u8 scale_index; 1068 + u8 base; 1069 + int ret; 1070 + 1071 + /* 1072 + * frequency base and scale registers are required for SDCA 1073 + * devices. They may also be used for 1.2+/non-SDCA devices, 1074 + * but we will need a DisCo property to cover this case 1075 + */ 1076 + if (!slave->id.class_id) 1077 + return 0; 1078 + 1079 + if (!mclk_freq) { 1080 + dev_err(&slave->dev, 1081 + "no bus MCLK, cannot set SDW_SCP_BUS_CLOCK_BASE\n"); 1082 + return -EINVAL; 1083 + } 1084 + 1085 + /* 1086 + * map base frequency using Table 89 of SoundWire 1.2 spec. 1087 + * The order of the tests just follows the specification, this 1088 + * is not a selection between possible values or a search for 1089 + * the best value but just a mapping. Only one case per platform 1090 + * is relevant. 1091 + * Some BIOS have inconsistent values for mclk_freq but a 1092 + * correct root so we force the mclk_freq to avoid variations. 1093 + */ 1094 + if (!(19200000 % mclk_freq)) { 1095 + mclk_freq = 19200000; 1096 + base = SDW_SCP_BASE_CLOCK_19200000_HZ; 1097 + } else if (!(24000000 % mclk_freq)) { 1098 + mclk_freq = 24000000; 1099 + base = SDW_SCP_BASE_CLOCK_24000000_HZ; 1100 + } else if (!(24576000 % mclk_freq)) { 1101 + mclk_freq = 24576000; 1102 + base = SDW_SCP_BASE_CLOCK_24576000_HZ; 1103 + } else if (!(22579200 % mclk_freq)) { 1104 + mclk_freq = 22579200; 1105 + base = SDW_SCP_BASE_CLOCK_22579200_HZ; 1106 + } else if (!(32000000 % mclk_freq)) { 1107 + mclk_freq = 32000000; 1108 + base = SDW_SCP_BASE_CLOCK_32000000_HZ; 1109 + } else { 1110 + dev_err(&slave->dev, 1111 + "Unsupported clock base, mclk %d\n", 1112 + mclk_freq); 1113 + return -EINVAL; 1114 + } 1115 + 1116 + if (mclk_freq % curr_freq) { 1117 + dev_err(&slave->dev, 1118 + "mclk %d is not multiple of bus curr_freq %d\n", 1119 + mclk_freq, curr_freq); 1120 + return -EINVAL; 1121 + } 1122 + 1123 + scale = mclk_freq / curr_freq; 1124 + 1125 + /* 1126 + * map scale to Table 90 of SoundWire 1.2 spec - and check 1127 + * that the scale is a power of two and maximum 64 1128 + */ 1129 + scale_index = ilog2(scale); 1130 + 1131 + if (BIT(scale_index) != scale || scale_index > 6) { 1132 + dev_err(&slave->dev, 1133 + "No match found for scale %d, bus mclk %d curr_freq %d\n", 1134 + scale, mclk_freq, curr_freq); 1135 + return -EINVAL; 1136 + } 1137 + scale_index++; 1138 + 1139 + ret = sdw_write(slave, SDW_SCP_BUS_CLOCK_BASE, base); 1140 + if (ret < 0) { 1141 + dev_err(&slave->dev, 1142 + "SDW_SCP_BUS_CLOCK_BASE write failed:%d\n", ret); 1143 + return ret; 1144 + } 1145 + 1146 + /* initialize scale for both banks */ 1147 + ret = sdw_write(slave, SDW_SCP_BUSCLOCK_SCALE_B0, scale_index); 1148 + if (ret < 0) { 1149 + dev_err(&slave->dev, 1150 + "SDW_SCP_BUSCLOCK_SCALE_B0 write failed:%d\n", ret); 1151 + return ret; 1152 + } 1153 + ret = sdw_write(slave, SDW_SCP_BUSCLOCK_SCALE_B1, scale_index); 1154 + if (ret < 0) 1155 + dev_err(&slave->dev, 1156 + "SDW_SCP_BUSCLOCK_SCALE_B1 write failed:%d\n", ret); 1157 + 1158 + dev_dbg(&slave->dev, 1159 + "Configured bus base %d, scale %d, mclk %d, curr_freq %d\n", 1160 + base, scale_index, mclk_freq, curr_freq); 1161 + 1162 + return ret; 1163 + } 1164 + 1073 1165 static int sdw_initialize_slave(struct sdw_slave *slave) 1074 1166 { 1075 1167 struct sdw_slave_prop *prop = &slave->prop; 1076 1168 int ret; 1077 1169 u8 val; 1170 + 1171 + ret = sdw_slave_set_frequency(slave); 1172 + if (ret < 0) 1173 + return ret; 1078 1174 1079 1175 /* 1080 1176 * Set bus clash, parity and SCP implementation
+11 -8
drivers/soundwire/bus_type.c
··· 20 20 static const struct sdw_device_id * 21 21 sdw_get_device_id(struct sdw_slave *slave, struct sdw_driver *drv) 22 22 { 23 - const struct sdw_device_id *id = drv->id_table; 23 + const struct sdw_device_id *id; 24 24 25 - while (id && id->mfg_id) { 25 + for (id = drv->id_table; id && id->mfg_id; id++) 26 26 if (slave->id.mfg_id == id->mfg_id && 27 - slave->id.part_id == id->part_id) 27 + slave->id.part_id == id->part_id && 28 + (!id->sdw_version || 29 + slave->id.sdw_version == id->sdw_version) && 30 + (!id->class_id || 31 + slave->id.class_id == id->class_id)) 28 32 return id; 29 - id++; 30 - } 31 33 32 34 return NULL; 33 35 } ··· 51 49 52 50 int sdw_slave_modalias(const struct sdw_slave *slave, char *buf, size_t size) 53 51 { 54 - /* modalias is sdw:m<mfg_id>p<part_id> */ 52 + /* modalias is sdw:m<mfg_id>p<part_id>v<version>c<class_id> */ 55 53 56 - return snprintf(buf, size, "sdw:m%04Xp%04X\n", 57 - slave->id.mfg_id, slave->id.part_id); 54 + return snprintf(buf, size, "sdw:m%04Xp%04Xv%02Xc%02X\n", 55 + slave->id.mfg_id, slave->id.part_id, 56 + slave->id.sdw_version, slave->id.class_id); 58 57 } 59 58 60 59 int sdw_slave_uevent(struct device *dev, struct kobj_uevent_env *env)
+48 -22
drivers/soundwire/cadence_master.c
··· 17 17 #include <linux/soundwire/sdw.h> 18 18 #include <sound/pcm_params.h> 19 19 #include <sound/soc.h> 20 + #include <linux/workqueue.h> 20 21 #include "bus.h" 21 22 #include "cadence_master.h" 22 23 ··· 791 790 CDNS_MCP_INT_SLAVE_MASK, 0); 792 791 793 792 int_status &= ~CDNS_MCP_INT_SLAVE_MASK; 794 - ret = IRQ_WAKE_THREAD; 793 + schedule_work(&cdns->work); 795 794 } 796 795 797 796 cdns_writel(cdns, CDNS_MCP_INTSTAT, int_status); ··· 800 799 EXPORT_SYMBOL(sdw_cdns_irq); 801 800 802 801 /** 803 - * sdw_cdns_thread() - Cadence irq thread handler 804 - * @irq: irq number 805 - * @dev_id: irq context 802 + * To update slave status in a work since we will need to handle 803 + * other interrupts eg. CDNS_MCP_INT_RX_WL during the update slave 804 + * process. 805 + * @work: cdns worker thread 806 806 */ 807 - irqreturn_t sdw_cdns_thread(int irq, void *dev_id) 807 + static void cdns_update_slave_status_work(struct work_struct *work) 808 808 { 809 - struct sdw_cdns *cdns = dev_id; 809 + struct sdw_cdns *cdns = 810 + container_of(work, struct sdw_cdns, work); 810 811 u32 slave0, slave1; 811 812 812 813 dev_dbg_ratelimited(cdns->dev, "Slave status change\n"); ··· 825 822 cdns_updatel(cdns, CDNS_MCP_INTMASK, 826 823 CDNS_MCP_INT_SLAVE_MASK, CDNS_MCP_INT_SLAVE_MASK); 827 824 828 - return IRQ_HANDLED; 829 825 } 830 - EXPORT_SYMBOL(sdw_cdns_thread); 831 826 832 827 /* 833 828 * init routines ··· 1428 1427 init_completion(&cdns->tx_complete); 1429 1428 cdns->bus.port_ops = &cdns_port_ops; 1430 1429 1430 + INIT_WORK(&cdns->work, cdns_update_slave_status_work); 1431 1431 return 0; 1432 1432 } 1433 1433 EXPORT_SYMBOL(sdw_cdns_probe); ··· 1439 1437 struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); 1440 1438 struct sdw_cdns_dma_data *dma; 1441 1439 1442 - dma = kzalloc(sizeof(*dma), GFP_KERNEL); 1443 - if (!dma) 1444 - return -ENOMEM; 1440 + if (stream) { 1441 + /* first paranoia check */ 1442 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) 1443 + dma = dai->playback_dma_data; 1444 + else 1445 + dma = dai->capture_dma_data; 1445 1446 1446 - if (pcm) 1447 - dma->stream_type = SDW_STREAM_PCM; 1448 - else 1449 - dma->stream_type = SDW_STREAM_PDM; 1447 + if (dma) { 1448 + dev_err(dai->dev, 1449 + "dma_data already allocated for dai %s\n", 1450 + dai->name); 1451 + return -EINVAL; 1452 + } 1450 1453 1451 - dma->bus = &cdns->bus; 1452 - dma->link_id = cdns->instance; 1454 + /* allocate and set dma info */ 1455 + dma = kzalloc(sizeof(*dma), GFP_KERNEL); 1456 + if (!dma) 1457 + return -ENOMEM; 1453 1458 1454 - dma->stream = stream; 1459 + if (pcm) 1460 + dma->stream_type = SDW_STREAM_PCM; 1461 + else 1462 + dma->stream_type = SDW_STREAM_PDM; 1455 1463 1456 - if (direction == SNDRV_PCM_STREAM_PLAYBACK) 1457 - dai->playback_dma_data = dma; 1458 - else 1459 - dai->capture_dma_data = dma; 1464 + dma->bus = &cdns->bus; 1465 + dma->link_id = cdns->instance; 1460 1466 1467 + dma->stream = stream; 1468 + 1469 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) 1470 + dai->playback_dma_data = dma; 1471 + else 1472 + dai->capture_dma_data = dma; 1473 + } else { 1474 + /* for NULL stream we release allocated dma_data */ 1475 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) { 1476 + kfree(dai->playback_dma_data); 1477 + dai->playback_dma_data = NULL; 1478 + } else { 1479 + kfree(dai->capture_dma_data); 1480 + dai->capture_dma_data = NULL; 1481 + } 1482 + } 1461 1483 return 0; 1462 1484 } 1463 1485 EXPORT_SYMBOL(cdns_set_sdw_stream);
+4
drivers/soundwire/cadence_master.h
··· 129 129 130 130 bool link_up; 131 131 unsigned int msg_count; 132 + 133 + struct work_struct work; 134 + 135 + struct list_head list; 132 136 }; 133 137 134 138 #define bus_to_cdns(_bus) container_of(_bus, struct sdw_cdns, bus)
+370 -189
drivers/soundwire/intel.c
··· 13 13 #include <linux/io.h> 14 14 #include <linux/platform_device.h> 15 15 #include <sound/pcm_params.h> 16 + #include <linux/pm_runtime.h> 16 17 #include <sound/soc.h> 17 18 #include <linux/soundwire/sdw_registers.h> 18 19 #include <linux/soundwire/sdw.h> ··· 47 46 #define SDW_SHIM_LCTL_SPA BIT(0) 48 47 #define SDW_SHIM_LCTL_CPA BIT(8) 49 48 50 - #define SDW_SHIM_SYNC_SYNCPRD_VAL 0x176F 49 + #define SDW_SHIM_SYNC_SYNCPRD_VAL_24 (24000 / SDW_CADENCE_GSYNC_KHZ - 1) 50 + #define SDW_SHIM_SYNC_SYNCPRD_VAL_38_4 (38400 / SDW_CADENCE_GSYNC_KHZ - 1) 51 51 #define SDW_SHIM_SYNC_SYNCPRD GENMASK(14, 0) 52 52 #define SDW_SHIM_SYNC_SYNCCPU BIT(15) 53 53 #define SDW_SHIM_SYNC_CMDSYNC_MASK GENMASK(19, 16) ··· 94 92 #define SDW_ALH_STRMZCFG_DMAT GENMASK(7, 0) 95 93 #define SDW_ALH_STRMZCFG_CHN GENMASK(19, 16) 96 94 97 - #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 98 - 99 95 enum intel_pdi_type { 100 96 INTEL_PDI_IN = 0, 101 97 INTEL_PDI_OUT = 1, 102 98 INTEL_PDI_BD = 2, 103 - }; 104 - 105 - struct sdw_intel { 106 - struct sdw_cdns cdns; 107 - int instance; 108 - struct sdw_intel_link_res *link_res; 109 - #ifdef CONFIG_DEBUG_FS 110 - struct dentry *debugfs; 111 - #endif 112 99 }; 113 100 114 101 #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns) ··· 125 134 writew(value, base + offset); 126 135 } 127 136 128 - static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask) 137 + static int intel_wait_bit(void __iomem *base, int offset, u32 mask, u32 target) 129 138 { 130 139 int timeout = 10; 131 140 u32 reg_read; 132 141 133 - writel(value, base + offset); 134 142 do { 135 143 reg_read = readl(base + offset); 136 - if (!(reg_read & mask)) 144 + if ((reg_read & mask) == target) 137 145 return 0; 138 146 139 147 timeout--; 140 - udelay(50); 148 + usleep_range(50, 100); 141 149 } while (timeout != 0); 142 150 143 151 return -EAGAIN; 144 152 } 145 153 154 + static int intel_clear_bit(void __iomem *base, int offset, u32 value, u32 mask) 155 + { 156 + writel(value, base + offset); 157 + return intel_wait_bit(base, offset, mask, 0); 158 + } 159 + 146 160 static int intel_set_bit(void __iomem *base, int offset, u32 value, u32 mask) 147 161 { 148 - int timeout = 10; 149 - u32 reg_read; 150 - 151 162 writel(value, base + offset); 152 - do { 153 - reg_read = readl(base + offset); 154 - if (reg_read & mask) 155 - return 0; 156 - 157 - timeout--; 158 - udelay(50); 159 - } while (timeout != 0); 160 - 161 - return -EAGAIN; 163 + return intel_wait_bit(base, offset, mask, mask); 162 164 } 163 165 164 166 /* ··· 274 290 { 275 291 unsigned int link_id = sdw->instance; 276 292 void __iomem *shim = sdw->link_res->shim; 293 + u32 *shim_mask = sdw->link_res->shim_mask; 294 + struct sdw_bus *bus = &sdw->cdns.bus; 295 + struct sdw_master_prop *prop = &bus->prop; 277 296 int spa_mask, cpa_mask; 278 - int link_control, ret; 297 + int link_control; 298 + int ret = 0; 299 + u32 syncprd; 300 + u32 sync_reg; 301 + 302 + mutex_lock(sdw->link_res->shim_lock); 303 + 304 + /* 305 + * The hardware relies on an internal counter, typically 4kHz, 306 + * to generate the SoundWire SSP - which defines a 'safe' 307 + * synchronization point between commands and audio transport 308 + * and allows for multi link synchronization. The SYNCPRD value 309 + * is only dependent on the oscillator clock provided to 310 + * the IP, so adjust based on _DSD properties reported in DSDT 311 + * tables. The values reported are based on either 24MHz 312 + * (CNL/CML) or 38.4 MHz (ICL/TGL+). 313 + */ 314 + if (prop->mclk_freq % 6000000) 315 + syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_38_4; 316 + else 317 + syncprd = SDW_SHIM_SYNC_SYNCPRD_VAL_24; 318 + 319 + if (!*shim_mask) { 320 + /* we first need to program the SyncPRD/CPU registers */ 321 + dev_dbg(sdw->cdns.dev, 322 + "%s: first link up, programming SYNCPRD\n", __func__); 323 + 324 + /* set SyncPRD period */ 325 + sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 326 + sync_reg |= (syncprd << 327 + SDW_REG_SHIFT(SDW_SHIM_SYNC_SYNCPRD)); 328 + 329 + /* Set SyncCPU bit */ 330 + sync_reg |= SDW_SHIM_SYNC_SYNCCPU; 331 + intel_writel(shim, SDW_SHIM_SYNC, sync_reg); 332 + } 279 333 280 334 /* Link power up sequence */ 281 335 link_control = intel_readl(shim, SDW_SHIM_LCTL); ··· 322 300 link_control |= spa_mask; 323 301 324 302 ret = intel_set_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); 325 - if (ret < 0) 326 - return ret; 303 + if (ret < 0) { 304 + dev_err(sdw->cdns.dev, "Failed to power up link: %d\n", ret); 305 + goto out; 306 + } 307 + 308 + if (!*shim_mask) { 309 + /* SyncCPU will change once link is active */ 310 + ret = intel_wait_bit(shim, SDW_SHIM_SYNC, 311 + SDW_SHIM_SYNC_SYNCCPU, 0); 312 + if (ret < 0) { 313 + dev_err(sdw->cdns.dev, 314 + "Failed to set SHIM_SYNC: %d\n", ret); 315 + goto out; 316 + } 317 + } 318 + 319 + *shim_mask |= BIT(link_id); 327 320 328 321 sdw->cdns.link_up = true; 329 - return 0; 322 + out: 323 + mutex_unlock(sdw->link_res->shim_lock); 324 + 325 + return ret; 330 326 } 331 327 332 - static int intel_shim_init(struct sdw_intel *sdw) 328 + /* this needs to be called with shim_lock */ 329 + static void intel_shim_glue_to_master_ip(struct sdw_intel *sdw) 333 330 { 334 331 void __iomem *shim = sdw->link_res->shim; 335 332 unsigned int link_id = sdw->instance; 336 - int sync_reg, ret; 337 - u16 ioctl = 0, act = 0; 338 - 339 - /* Initialize Shim */ 340 - ioctl |= SDW_SHIM_IOCTL_BKE; 341 - intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 342 - 343 - ioctl |= SDW_SHIM_IOCTL_WPDD; 344 - intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 345 - 346 - ioctl |= SDW_SHIM_IOCTL_DO; 347 - intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 348 - 349 - ioctl |= SDW_SHIM_IOCTL_DOE; 350 - intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 333 + u16 ioctl; 351 334 352 335 /* Switch to MIP from Glue logic */ 353 336 ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); 354 337 355 338 ioctl &= ~(SDW_SHIM_IOCTL_DOE); 356 339 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 340 + usleep_range(10, 15); 357 341 358 342 ioctl &= ~(SDW_SHIM_IOCTL_DO); 359 343 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 344 + usleep_range(10, 15); 360 345 361 346 ioctl |= (SDW_SHIM_IOCTL_MIF); 362 347 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 348 + usleep_range(10, 15); 363 349 364 350 ioctl &= ~(SDW_SHIM_IOCTL_BKE); 365 351 ioctl &= ~(SDW_SHIM_IOCTL_COE); 366 - 367 352 intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 353 + usleep_range(10, 15); 354 + 355 + /* at this point Master IP has full control of the I/Os */ 356 + } 357 + 358 + /* this needs to be called with shim_lock */ 359 + static void intel_shim_master_ip_to_glue(struct sdw_intel *sdw) 360 + { 361 + unsigned int link_id = sdw->instance; 362 + void __iomem *shim = sdw->link_res->shim; 363 + u16 ioctl; 364 + 365 + /* Glue logic */ 366 + ioctl = intel_readw(shim, SDW_SHIM_IOCTL(link_id)); 367 + ioctl |= SDW_SHIM_IOCTL_BKE; 368 + ioctl |= SDW_SHIM_IOCTL_COE; 369 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 370 + usleep_range(10, 15); 371 + 372 + ioctl &= ~(SDW_SHIM_IOCTL_MIF); 373 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 374 + usleep_range(10, 15); 375 + 376 + /* at this point Integration Glue has full control of the I/Os */ 377 + } 378 + 379 + static int intel_shim_init(struct sdw_intel *sdw, bool clock_stop) 380 + { 381 + void __iomem *shim = sdw->link_res->shim; 382 + unsigned int link_id = sdw->instance; 383 + int ret = 0; 384 + u16 ioctl = 0, act = 0; 385 + 386 + mutex_lock(sdw->link_res->shim_lock); 387 + 388 + /* Initialize Shim */ 389 + ioctl |= SDW_SHIM_IOCTL_BKE; 390 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 391 + usleep_range(10, 15); 392 + 393 + ioctl |= SDW_SHIM_IOCTL_WPDD; 394 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 395 + usleep_range(10, 15); 396 + 397 + ioctl |= SDW_SHIM_IOCTL_DO; 398 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 399 + usleep_range(10, 15); 400 + 401 + ioctl |= SDW_SHIM_IOCTL_DOE; 402 + intel_writew(shim, SDW_SHIM_IOCTL(link_id), ioctl); 403 + usleep_range(10, 15); 404 + 405 + intel_shim_glue_to_master_ip(sdw); 368 406 369 407 act |= 0x1 << SDW_REG_SHIFT(SDW_SHIM_CTMCTL_DOAIS); 370 408 act |= SDW_SHIM_CTMCTL_DACTQE; 371 409 act |= SDW_SHIM_CTMCTL_DODS; 372 410 intel_writew(shim, SDW_SHIM_CTMCTL(link_id), act); 411 + usleep_range(10, 15); 373 412 374 - /* Now set SyncPRD period */ 375 - sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 376 - sync_reg |= (SDW_SHIM_SYNC_SYNCPRD_VAL << 377 - SDW_REG_SHIFT(SDW_SHIM_SYNC_SYNCPRD)); 413 + mutex_unlock(sdw->link_res->shim_lock); 378 414 379 - /* Set SyncCPU bit */ 380 - sync_reg |= SDW_SHIM_SYNC_SYNCCPU; 381 - ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg, 382 - SDW_SHIM_SYNC_SYNCCPU); 415 + return ret; 416 + } 417 + 418 + static void intel_shim_wake(struct sdw_intel *sdw, bool wake_enable) 419 + { 420 + void __iomem *shim = sdw->link_res->shim; 421 + unsigned int link_id = sdw->instance; 422 + u16 wake_en, wake_sts; 423 + 424 + mutex_lock(sdw->link_res->shim_lock); 425 + wake_en = intel_readw(shim, SDW_SHIM_WAKEEN); 426 + 427 + if (wake_enable) { 428 + /* Enable the wakeup */ 429 + wake_en |= (SDW_SHIM_WAKEEN_ENABLE << link_id); 430 + intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); 431 + } else { 432 + /* Disable the wake up interrupt */ 433 + wake_en &= ~(SDW_SHIM_WAKEEN_ENABLE << link_id); 434 + intel_writew(shim, SDW_SHIM_WAKEEN, wake_en); 435 + 436 + /* Clear wake status */ 437 + wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS); 438 + wake_sts |= (SDW_SHIM_WAKEEN_ENABLE << link_id); 439 + intel_writew(shim, SDW_SHIM_WAKESTS_STATUS, wake_sts); 440 + } 441 + mutex_unlock(sdw->link_res->shim_lock); 442 + } 443 + 444 + static int __maybe_unused intel_link_power_down(struct sdw_intel *sdw) 445 + { 446 + int link_control, spa_mask, cpa_mask; 447 + unsigned int link_id = sdw->instance; 448 + void __iomem *shim = sdw->link_res->shim; 449 + u32 *shim_mask = sdw->link_res->shim_mask; 450 + int ret = 0; 451 + 452 + mutex_lock(sdw->link_res->shim_lock); 453 + 454 + intel_shim_master_ip_to_glue(sdw); 455 + 456 + /* Link power down sequence */ 457 + link_control = intel_readl(shim, SDW_SHIM_LCTL); 458 + spa_mask = ~(SDW_SHIM_LCTL_SPA << link_id); 459 + cpa_mask = (SDW_SHIM_LCTL_CPA << link_id); 460 + link_control &= spa_mask; 461 + 462 + ret = intel_clear_bit(shim, SDW_SHIM_LCTL, link_control, cpa_mask); 463 + 464 + if (!(*shim_mask & BIT(link_id))) 465 + dev_err(sdw->cdns.dev, 466 + "%s: Unbalanced power-up/down calls\n", __func__); 467 + 468 + *shim_mask &= ~BIT(link_id); 469 + 470 + mutex_unlock(sdw->link_res->shim_lock); 471 + 383 472 if (ret < 0) 384 - dev_err(sdw->cdns.dev, "Failed to set sync period: %d\n", ret); 473 + return ret; 474 + 475 + sdw->cdns.link_up = false; 476 + return 0; 477 + } 478 + 479 + static void intel_shim_sync_arm(struct sdw_intel *sdw) 480 + { 481 + void __iomem *shim = sdw->link_res->shim; 482 + u32 sync_reg; 483 + 484 + mutex_lock(sdw->link_res->shim_lock); 485 + 486 + /* update SYNC register */ 487 + sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 488 + sync_reg |= (SDW_SHIM_SYNC_CMDSYNC << sdw->instance); 489 + intel_writel(shim, SDW_SHIM_SYNC, sync_reg); 490 + 491 + mutex_unlock(sdw->link_res->shim_lock); 492 + } 493 + 494 + static int intel_shim_sync_go_unlocked(struct sdw_intel *sdw) 495 + { 496 + void __iomem *shim = sdw->link_res->shim; 497 + u32 sync_reg; 498 + int ret; 499 + 500 + /* Read SYNC register */ 501 + sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 502 + 503 + /* 504 + * Set SyncGO bit to synchronously trigger a bank switch for 505 + * all the masters. A write to SYNCGO bit clears CMDSYNC bit for all 506 + * the Masters. 507 + */ 508 + sync_reg |= SDW_SHIM_SYNC_SYNCGO; 509 + 510 + ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg, 511 + SDW_SHIM_SYNC_SYNCGO); 512 + 513 + if (ret < 0) 514 + dev_err(sdw->cdns.dev, "SyncGO clear failed: %d\n", ret); 385 515 386 516 return ret; 387 517 } ··· 751 577 { 752 578 struct sdw_cdns *cdns = bus_to_cdns(bus); 753 579 struct sdw_intel *sdw = cdns_to_intel(cdns); 754 - void __iomem *shim = sdw->link_res->shim; 755 - int sync_reg; 756 580 757 581 /* Write to register only for multi-link */ 758 582 if (!bus->multi_link) 759 583 return 0; 760 584 761 - /* Read SYNC register */ 762 - sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 763 - sync_reg |= SDW_SHIM_SYNC_CMDSYNC << sdw->instance; 764 - intel_writel(shim, SDW_SHIM_SYNC, sync_reg); 585 + intel_shim_sync_arm(sdw); 765 586 766 587 return 0; 767 588 } ··· 772 603 if (!bus->multi_link) 773 604 return 0; 774 605 606 + mutex_lock(sdw->link_res->shim_lock); 607 + 775 608 /* Read SYNC register */ 776 609 sync_reg = intel_readl(shim, SDW_SHIM_SYNC); 777 610 ··· 785 614 * 786 615 * So, set the SYNCGO bit only if CMDSYNC bit is set for any Master. 787 616 */ 788 - if (!(sync_reg & SDW_SHIM_SYNC_CMDSYNC_MASK)) 789 - return 0; 617 + if (!(sync_reg & SDW_SHIM_SYNC_CMDSYNC_MASK)) { 618 + ret = 0; 619 + goto unlock; 620 + } 790 621 791 - /* 792 - * Set SyncGO bit to synchronously trigger a bank switch for 793 - * all the masters. A write to SYNCGO bit clears CMDSYNC bit for all 794 - * the Masters. 795 - */ 796 - sync_reg |= SDW_SHIM_SYNC_SYNCGO; 622 + ret = intel_shim_sync_go_unlocked(sdw); 623 + unlock: 624 + mutex_unlock(sdw->link_res->shim_lock); 797 625 798 - ret = intel_clear_bit(shim, SDW_SHIM_SYNC, sync_reg, 799 - SDW_SHIM_SYNC_SYNCGO); 800 626 if (ret < 0) 801 627 dev_err(sdw->cdns.dev, "Post bank switch failed: %d\n", ret); 802 628 ··· 804 636 * DAI routines 805 637 */ 806 638 807 - static int sdw_stream_setup(struct snd_pcm_substream *substream, 808 - struct snd_soc_dai *dai) 809 - { 810 - struct snd_soc_pcm_runtime *rtd = substream->private_data; 811 - struct sdw_stream_runtime *sdw_stream = NULL; 812 - char *name; 813 - int i, ret; 814 - 815 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 816 - name = kasprintf(GFP_KERNEL, "%s-Playback", dai->name); 817 - else 818 - name = kasprintf(GFP_KERNEL, "%s-Capture", dai->name); 819 - 820 - if (!name) 821 - return -ENOMEM; 822 - 823 - sdw_stream = sdw_alloc_stream(name); 824 - if (!sdw_stream) { 825 - dev_err(dai->dev, "alloc stream failed for DAI %s", dai->name); 826 - ret = -ENOMEM; 827 - goto error; 828 - } 829 - 830 - /* Set stream pointer on CPU DAI */ 831 - ret = snd_soc_dai_set_sdw_stream(dai, sdw_stream, substream->stream); 832 - if (ret < 0) { 833 - dev_err(dai->dev, "failed to set stream pointer on cpu dai %s", 834 - dai->name); 835 - goto release_stream; 836 - } 837 - 838 - /* Set stream pointer on all CODEC DAIs */ 839 - for (i = 0; i < rtd->num_codecs; i++) { 840 - ret = snd_soc_dai_set_sdw_stream(asoc_rtd_to_codec(rtd, i), sdw_stream, 841 - substream->stream); 842 - if (ret < 0) { 843 - dev_err(dai->dev, "failed to set stream pointer on codec dai %s", 844 - asoc_rtd_to_codec(rtd, i)->name); 845 - goto release_stream; 846 - } 847 - } 848 - 849 - return 0; 850 - 851 - release_stream: 852 - sdw_release_stream(sdw_stream); 853 - error: 854 - kfree(name); 855 - return ret; 856 - } 857 - 858 639 static int intel_startup(struct snd_pcm_substream *substream, 859 640 struct snd_soc_dai *dai) 860 641 { ··· 811 694 * TODO: add pm_runtime support here, the startup callback 812 695 * will make sure the IP is 'active' 813 696 */ 814 - 815 - return sdw_stream_setup(substream, dai); 697 + return 0; 816 698 } 817 699 818 700 static int intel_hw_params(struct snd_pcm_substream *substream, ··· 979 863 return ret; 980 864 } 981 865 982 - kfree(dma->stream->name); 983 - sdw_release_stream(dma->stream); 984 - 985 866 return 0; 986 867 } 987 868 988 869 static void intel_shutdown(struct snd_pcm_substream *substream, 989 870 struct snd_soc_dai *dai) 990 871 { 991 - struct sdw_cdns_dma_data *dma; 992 872 993 - dma = snd_soc_dai_get_dma_data(dai, substream); 994 - if (!dma) 995 - return; 996 - 997 - snd_soc_dai_set_dma_data(dai, substream, NULL); 998 - kfree(dma); 999 873 } 1000 874 1001 875 static int intel_pcm_set_sdw_stream(struct snd_soc_dai *dai, ··· 1000 894 return cdns_set_sdw_stream(dai, stream, false, direction); 1001 895 } 1002 896 897 + static void *intel_get_sdw_stream(struct snd_soc_dai *dai, 898 + int direction) 899 + { 900 + struct sdw_cdns_dma_data *dma; 901 + 902 + if (direction == SNDRV_PCM_STREAM_PLAYBACK) 903 + dma = dai->playback_dma_data; 904 + else 905 + dma = dai->capture_dma_data; 906 + 907 + if (!dma) 908 + return NULL; 909 + 910 + return dma->stream; 911 + } 912 + 1003 913 static const struct snd_soc_dai_ops intel_pcm_dai_ops = { 1004 914 .startup = intel_startup, 1005 915 .hw_params = intel_hw_params, ··· 1024 902 .hw_free = intel_hw_free, 1025 903 .shutdown = intel_shutdown, 1026 904 .set_sdw_stream = intel_pcm_set_sdw_stream, 905 + .get_sdw_stream = intel_get_sdw_stream, 1027 906 }; 1028 907 1029 908 static const struct snd_soc_dai_ops intel_pdm_dai_ops = { ··· 1035 912 .hw_free = intel_hw_free, 1036 913 .shutdown = intel_shutdown, 1037 914 .set_sdw_stream = intel_pdm_set_sdw_stream, 915 + .get_sdw_stream = intel_get_sdw_stream, 1038 916 }; 1039 917 1040 918 static const struct snd_soc_component_driver dai_component = { ··· 1198 1074 1199 1075 static int intel_init(struct sdw_intel *sdw) 1200 1076 { 1077 + bool clock_stop; 1078 + 1201 1079 /* Initialize shim and controller */ 1202 1080 intel_link_power_up(sdw); 1203 - intel_shim_init(sdw); 1081 + 1082 + clock_stop = sdw_cdns_is_clock_stop(&sdw->cdns); 1083 + 1084 + intel_shim_init(sdw, clock_stop); 1085 + 1086 + if (clock_stop) 1087 + return 0; 1204 1088 1205 1089 return sdw_cdns_init(&sdw->cdns); 1206 1090 } ··· 1216 1084 /* 1217 1085 * probe and init 1218 1086 */ 1219 - static int intel_probe(struct platform_device *pdev) 1087 + static int intel_master_probe(struct platform_device *pdev) 1220 1088 { 1221 - struct sdw_cdns_stream_config config; 1089 + struct device *dev = &pdev->dev; 1222 1090 struct sdw_intel *sdw; 1091 + struct sdw_cdns *cdns; 1092 + struct sdw_bus *bus; 1223 1093 int ret; 1224 1094 1225 - sdw = devm_kzalloc(&pdev->dev, sizeof(*sdw), GFP_KERNEL); 1095 + sdw = devm_kzalloc(dev, sizeof(*sdw), GFP_KERNEL); 1226 1096 if (!sdw) 1227 1097 return -ENOMEM; 1228 1098 1229 - sdw->instance = pdev->id; 1230 - sdw->link_res = dev_get_platdata(&pdev->dev); 1231 - sdw->cdns.dev = &pdev->dev; 1232 - sdw->cdns.registers = sdw->link_res->registers; 1233 - sdw->cdns.instance = sdw->instance; 1234 - sdw->cdns.msg_count = 0; 1235 - sdw->cdns.bus.link_id = pdev->id; 1099 + cdns = &sdw->cdns; 1100 + bus = &cdns->bus; 1236 1101 1237 - sdw_cdns_probe(&sdw->cdns); 1102 + sdw->instance = pdev->id; 1103 + sdw->link_res = dev_get_platdata(dev); 1104 + cdns->dev = dev; 1105 + cdns->registers = sdw->link_res->registers; 1106 + cdns->instance = sdw->instance; 1107 + cdns->msg_count = 0; 1108 + 1109 + bus->link_id = pdev->id; 1110 + 1111 + sdw_cdns_probe(cdns); 1238 1112 1239 1113 /* Set property read ops */ 1240 1114 sdw_intel_ops.read_prop = intel_prop_read; 1241 - sdw->cdns.bus.ops = &sdw_intel_ops; 1115 + bus->ops = &sdw_intel_ops; 1242 1116 1243 - platform_set_drvdata(pdev, sdw); 1117 + /* set driver data, accessed by snd_soc_dai_get_drvdata() */ 1118 + dev_set_drvdata(dev, cdns); 1244 1119 1245 - ret = sdw_bus_master_add(&sdw->cdns.bus, &pdev->dev, pdev->dev.fwnode); 1120 + ret = sdw_bus_master_add(bus, dev, dev->fwnode); 1246 1121 if (ret) { 1247 - dev_err(&pdev->dev, "sdw_bus_master_add fail: %d\n", ret); 1122 + dev_err(dev, "sdw_bus_master_add fail: %d\n", ret); 1248 1123 return ret; 1249 1124 } 1250 1125 1251 - if (sdw->cdns.bus.prop.hw_disabled) { 1252 - dev_info(&pdev->dev, "SoundWire master %d is disabled, ignoring\n", 1253 - sdw->cdns.bus.link_id); 1126 + if (bus->prop.hw_disabled) 1127 + dev_info(dev, 1128 + "SoundWire master %d is disabled, will be ignored\n", 1129 + bus->link_id); 1130 + 1131 + return 0; 1132 + } 1133 + 1134 + int intel_master_startup(struct platform_device *pdev) 1135 + { 1136 + struct sdw_cdns_stream_config config; 1137 + struct device *dev = &pdev->dev; 1138 + struct sdw_cdns *cdns = dev_get_drvdata(dev); 1139 + struct sdw_intel *sdw = cdns_to_intel(cdns); 1140 + struct sdw_bus *bus = &cdns->bus; 1141 + int ret; 1142 + 1143 + if (bus->prop.hw_disabled) { 1144 + dev_info(dev, 1145 + "SoundWire master %d is disabled, ignoring\n", 1146 + sdw->instance); 1254 1147 return 0; 1255 1148 } 1256 1149 ··· 1286 1129 1287 1130 /* Read the PDI config and initialize cadence PDI */ 1288 1131 intel_pdi_init(sdw, &config); 1289 - ret = sdw_cdns_pdi_init(&sdw->cdns, config); 1132 + ret = sdw_cdns_pdi_init(cdns, config); 1290 1133 if (ret) 1291 1134 goto err_init; 1292 1135 1293 1136 intel_pdi_ch_update(sdw); 1294 1137 1295 - /* Acquire IRQ */ 1296 - ret = request_threaded_irq(sdw->link_res->irq, 1297 - sdw_cdns_irq, sdw_cdns_thread, 1298 - IRQF_SHARED, KBUILD_MODNAME, &sdw->cdns); 1138 + ret = sdw_cdns_enable_interrupt(cdns, true); 1299 1139 if (ret < 0) { 1300 - dev_err(sdw->cdns.dev, "unable to grab IRQ %d, disabling device\n", 1301 - sdw->link_res->irq); 1140 + dev_err(dev, "cannot enable interrupts\n"); 1302 1141 goto err_init; 1303 1142 } 1304 1143 1305 - ret = sdw_cdns_enable_interrupt(&sdw->cdns, true); 1144 + ret = sdw_cdns_exit_reset(cdns); 1306 1145 if (ret < 0) { 1307 - dev_err(sdw->cdns.dev, "cannot enable interrupts\n"); 1308 - goto err_init; 1309 - } 1310 - 1311 - ret = sdw_cdns_exit_reset(&sdw->cdns); 1312 - if (ret < 0) { 1313 - dev_err(sdw->cdns.dev, "unable to exit bus reset sequence\n"); 1146 + dev_err(dev, "unable to exit bus reset sequence\n"); 1314 1147 goto err_interrupt; 1315 1148 } 1316 1149 1317 1150 /* Register DAIs */ 1318 1151 ret = intel_register_dai(sdw); 1319 1152 if (ret) { 1320 - dev_err(sdw->cdns.dev, "DAI registration failed: %d\n", ret); 1321 - snd_soc_unregister_component(sdw->cdns.dev); 1153 + dev_err(dev, "DAI registration failed: %d\n", ret); 1154 + snd_soc_unregister_component(dev); 1322 1155 goto err_interrupt; 1323 1156 } 1324 1157 ··· 1317 1170 return 0; 1318 1171 1319 1172 err_interrupt: 1320 - sdw_cdns_enable_interrupt(&sdw->cdns, false); 1321 - free_irq(sdw->link_res->irq, sdw); 1173 + sdw_cdns_enable_interrupt(cdns, false); 1322 1174 err_init: 1323 - sdw_bus_master_delete(&sdw->cdns.bus); 1324 1175 return ret; 1325 1176 } 1326 1177 1327 - static int intel_remove(struct platform_device *pdev) 1178 + static int intel_master_remove(struct platform_device *pdev) 1328 1179 { 1180 + struct device *dev = &pdev->dev; 1181 + struct sdw_cdns *cdns = dev_get_drvdata(dev); 1182 + struct sdw_intel *sdw = cdns_to_intel(cdns); 1183 + struct sdw_bus *bus = &cdns->bus; 1184 + 1185 + if (!bus->prop.hw_disabled) { 1186 + intel_debugfs_exit(sdw); 1187 + sdw_cdns_enable_interrupt(cdns, false); 1188 + snd_soc_unregister_component(dev); 1189 + } 1190 + sdw_bus_master_delete(bus); 1191 + 1192 + return 0; 1193 + } 1194 + 1195 + int intel_master_process_wakeen_event(struct platform_device *pdev) 1196 + { 1197 + struct device *dev = &pdev->dev; 1329 1198 struct sdw_intel *sdw; 1199 + struct sdw_bus *bus; 1200 + void __iomem *shim; 1201 + u16 wake_sts; 1330 1202 1331 1203 sdw = platform_get_drvdata(pdev); 1204 + bus = &sdw->cdns.bus; 1332 1205 1333 - if (!sdw->cdns.bus.prop.hw_disabled) { 1334 - intel_debugfs_exit(sdw); 1335 - sdw_cdns_enable_interrupt(&sdw->cdns, false); 1336 - free_irq(sdw->link_res->irq, sdw); 1337 - snd_soc_unregister_component(sdw->cdns.dev); 1206 + if (bus->prop.hw_disabled) { 1207 + dev_dbg(dev, "SoundWire master %d is disabled, ignoring\n", bus->link_id); 1208 + return 0; 1338 1209 } 1339 - sdw_bus_master_delete(&sdw->cdns.bus); 1210 + 1211 + shim = sdw->link_res->shim; 1212 + wake_sts = intel_readw(shim, SDW_SHIM_WAKESTS); 1213 + 1214 + if (!(wake_sts & BIT(sdw->instance))) 1215 + return 0; 1216 + 1217 + /* disable WAKEEN interrupt ASAP to prevent interrupt flood */ 1218 + intel_shim_wake(sdw, false); 1219 + 1220 + /* 1221 + * resume the Master, which will generate a bus reset and result in 1222 + * Slaves re-attaching and be re-enumerated. The SoundWire physical 1223 + * device which generated the wake will trigger an interrupt, which 1224 + * will in turn cause the corresponding Linux Slave device to be 1225 + * resumed and the Slave codec driver to check the status. 1226 + */ 1227 + pm_request_resume(dev); 1340 1228 1341 1229 return 0; 1342 1230 } 1343 1231 1344 1232 static struct platform_driver sdw_intel_drv = { 1345 - .probe = intel_probe, 1346 - .remove = intel_remove, 1233 + .probe = intel_master_probe, 1234 + .remove = intel_master_remove, 1347 1235 .driver = { 1348 - .name = "int-sdw", 1349 - 1236 + .name = "intel-sdw", 1350 1237 }, 1351 1238 }; 1352 1239 1353 1240 module_platform_driver(sdw_intel_drv); 1354 1241 1355 1242 MODULE_LICENSE("Dual BSD/GPL"); 1356 - MODULE_ALIAS("platform:int-sdw"); 1243 + MODULE_ALIAS("platform:intel-sdw"); 1357 1244 MODULE_DESCRIPTION("Intel Soundwire Master Driver");
+22
drivers/soundwire/intel.h
··· 15 15 * @irq: Interrupt line 16 16 * @ops: Shim callback ops 17 17 * @dev: device implementing hw_params and free callbacks 18 + * @shim_lock: mutex to handle access to shared SHIM registers 19 + * @shim_mask: global pointer to check SHIM register initialization 20 + * @cdns: Cadence master descriptor 21 + * @list: used to walk-through all masters exposed by the same controller 18 22 */ 19 23 struct sdw_intel_link_res { 20 24 struct platform_device *pdev; ··· 29 25 int irq; 30 26 const struct sdw_intel_ops *ops; 31 27 struct device *dev; 28 + struct mutex *shim_lock; /* protect shared registers */ 29 + u32 *shim_mask; 30 + struct sdw_cdns *cdns; 31 + struct list_head list; 32 32 }; 33 + 34 + struct sdw_intel { 35 + struct sdw_cdns cdns; 36 + int instance; 37 + struct sdw_intel_link_res *link_res; 38 + #ifdef CONFIG_DEBUG_FS 39 + struct dentry *debugfs; 40 + #endif 41 + }; 42 + 43 + #define SDW_INTEL_QUIRK_MASK_BUS_DISABLE BIT(1) 44 + 45 + int intel_master_startup(struct platform_device *pdev); 46 + int intel_master_process_wakeen_event(struct platform_device *pdev); 33 47 34 48 #endif /* __SDW_INTEL_LOCAL_H */
+299 -57
drivers/soundwire/intel_init.c
··· 9 9 10 10 #include <linux/acpi.h> 11 11 #include <linux/export.h> 12 + #include <linux/interrupt.h> 12 13 #include <linux/io.h> 13 14 #include <linux/module.h> 14 15 #include <linux/platform_device.h> 15 16 #include <linux/soundwire/sdw_intel.h> 17 + #include "cadence_master.h" 16 18 #include "intel.h" 17 19 18 20 #define SDW_LINK_TYPE 4 /* from Intel ACPI documentation */ ··· 25 23 #define SDW_LINK_BASE 0x30000 26 24 #define SDW_LINK_SIZE 0x10000 27 25 28 - static int link_mask; 29 - module_param_named(sdw_link_mask, link_mask, int, 0444); 26 + static int ctrl_link_mask; 27 + module_param_named(sdw_link_mask, ctrl_link_mask, int, 0444); 30 28 MODULE_PARM_DESC(sdw_link_mask, "Intel link mask (one bit per link)"); 31 29 32 - static int sdw_intel_cleanup_pdev(struct sdw_intel_ctx *ctx) 30 + static bool is_link_enabled(struct fwnode_handle *fw_node, int i) 31 + { 32 + struct fwnode_handle *link; 33 + char name[32]; 34 + u32 quirk_mask = 0; 35 + 36 + /* Find master handle */ 37 + snprintf(name, sizeof(name), 38 + "mipi-sdw-link-%d-subproperties", i); 39 + 40 + link = fwnode_get_named_child_node(fw_node, name); 41 + if (!link) 42 + return false; 43 + 44 + fwnode_property_read_u32(link, 45 + "intel-quirk-mask", 46 + &quirk_mask); 47 + 48 + if (quirk_mask & SDW_INTEL_QUIRK_MASK_BUS_DISABLE) 49 + return false; 50 + 51 + return true; 52 + } 53 + 54 + static int sdw_intel_cleanup(struct sdw_intel_ctx *ctx) 33 55 { 34 56 struct sdw_intel_link_res *link = ctx->links; 57 + u32 link_mask; 35 58 int i; 36 59 37 60 if (!link) 38 61 return 0; 39 62 40 - for (i = 0; i < ctx->count; i++) { 63 + link_mask = ctx->link_mask; 64 + 65 + for (i = 0; i < ctx->count; i++, link++) { 66 + if (!(link_mask & BIT(i))) 67 + continue; 68 + 41 69 if (link->pdev) 42 70 platform_device_unregister(link->pdev); 43 - link++; 44 71 } 45 - 46 - kfree(ctx->links); 47 - ctx->links = NULL; 48 72 49 73 return 0; 50 74 } 51 75 52 - static struct sdw_intel_ctx 53 - *sdw_intel_add_controller(struct sdw_intel_res *res) 76 + static int 77 + sdw_intel_scan_controller(struct sdw_intel_acpi_info *info) 54 78 { 55 - struct platform_device_info pdevinfo; 56 - struct platform_device *pdev; 57 - struct sdw_intel_link_res *link; 58 - struct sdw_intel_ctx *ctx; 59 79 struct acpi_device *adev; 60 80 int ret, i; 61 81 u8 count; 62 - u32 caps; 63 82 64 - if (acpi_bus_get_device(res->handle, &adev)) 65 - return NULL; 83 + if (acpi_bus_get_device(info->handle, &adev)) 84 + return -EINVAL; 66 85 67 86 /* Found controller, find links supported */ 68 87 count = 0; 69 88 ret = fwnode_property_read_u8_array(acpi_fwnode_handle(adev), 70 89 "mipi-sdw-master-count", &count, 1); 71 90 72 - /* Don't fail on error, continue and use hw value */ 91 + /* 92 + * In theory we could check the number of links supported in 93 + * hardware, but in that step we cannot assume SoundWire IP is 94 + * powered. 95 + * 96 + * In addition, if the BIOS doesn't even provide this 97 + * 'master-count' property then all the inits based on link 98 + * masks will fail as well. 99 + * 100 + * We will check the hardware capabilities in the startup() step 101 + */ 102 + 73 103 if (ret) { 74 104 dev_err(&adev->dev, 75 105 "Failed to read mipi-sdw-master-count: %d\n", ret); 76 - count = SDW_MAX_LINKS; 106 + return -EINVAL; 77 107 } 78 - 79 - /* Check SNDWLCAP.LCOUNT */ 80 - caps = ioread32(res->mmio_base + SDW_SHIM_BASE + SDW_SHIM_LCAP); 81 - caps &= GENMASK(2, 0); 82 - 83 - /* Check HW supported vs property value and use min of two */ 84 - count = min_t(u8, caps, count); 85 108 86 109 /* Check count is within bounds */ 87 110 if (count > SDW_MAX_LINKS) { 88 111 dev_err(&adev->dev, "Link count %d exceeds max %d\n", 89 112 count, SDW_MAX_LINKS); 90 - return NULL; 113 + return -EINVAL; 91 114 } 92 115 93 116 if (!count) { 94 117 dev_warn(&adev->dev, "No SoundWire links detected\n"); 95 - return NULL; 118 + return -EINVAL; 119 + } 120 + dev_dbg(&adev->dev, "ACPI reports %d SDW Link devices\n", count); 121 + 122 + info->count = count; 123 + info->link_mask = 0; 124 + 125 + for (i = 0; i < count; i++) { 126 + if (ctrl_link_mask && !(ctrl_link_mask & BIT(i))) { 127 + dev_dbg(&adev->dev, 128 + "Link %d masked, will not be enabled\n", i); 129 + continue; 130 + } 131 + 132 + if (!is_link_enabled(acpi_fwnode_handle(adev), i)) { 133 + dev_dbg(&adev->dev, 134 + "Link %d not selected in firmware\n", i); 135 + continue; 136 + } 137 + 138 + info->link_mask |= BIT(i); 96 139 } 97 140 141 + return 0; 142 + } 143 + 144 + #define HDA_DSP_REG_ADSPIC2 (0x10) 145 + #define HDA_DSP_REG_ADSPIS2 (0x14) 146 + #define HDA_DSP_REG_ADSPIC2_SNDW BIT(5) 147 + 148 + /** 149 + * sdw_intel_enable_irq() - enable/disable Intel SoundWire IRQ 150 + * @mmio_base: The mmio base of the control register 151 + * @enable: true if enable 152 + */ 153 + void sdw_intel_enable_irq(void __iomem *mmio_base, bool enable) 154 + { 155 + u32 val; 156 + 157 + val = readl(mmio_base + HDA_DSP_REG_ADSPIC2); 158 + 159 + if (enable) 160 + val |= HDA_DSP_REG_ADSPIC2_SNDW; 161 + else 162 + val &= ~HDA_DSP_REG_ADSPIC2_SNDW; 163 + 164 + writel(val, mmio_base + HDA_DSP_REG_ADSPIC2); 165 + } 166 + EXPORT_SYMBOL_NS(sdw_intel_enable_irq, SOUNDWIRE_INTEL_INIT); 167 + 168 + irqreturn_t sdw_intel_thread(int irq, void *dev_id) 169 + { 170 + struct sdw_intel_ctx *ctx = dev_id; 171 + struct sdw_intel_link_res *link; 172 + 173 + list_for_each_entry(link, &ctx->link_list, list) 174 + sdw_cdns_irq(irq, link->cdns); 175 + 176 + sdw_intel_enable_irq(ctx->mmio_base, true); 177 + return IRQ_HANDLED; 178 + } 179 + EXPORT_SYMBOL_NS(sdw_intel_thread, SOUNDWIRE_INTEL_INIT); 180 + 181 + static struct sdw_intel_ctx 182 + *sdw_intel_probe_controller(struct sdw_intel_res *res) 183 + { 184 + struct platform_device_info pdevinfo; 185 + struct platform_device *pdev; 186 + struct sdw_intel_link_res *link; 187 + struct sdw_intel_ctx *ctx; 188 + struct acpi_device *adev; 189 + struct sdw_slave *slave; 190 + struct list_head *node; 191 + struct sdw_bus *bus; 192 + u32 link_mask; 193 + int num_slaves = 0; 194 + int count; 195 + int i; 196 + 197 + if (!res) 198 + return NULL; 199 + 200 + if (acpi_bus_get_device(res->handle, &adev)) 201 + return NULL; 202 + 203 + if (!res->count) 204 + return NULL; 205 + 206 + count = res->count; 98 207 dev_dbg(&adev->dev, "Creating %d SDW Link devices\n", count); 99 208 100 - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); 209 + ctx = devm_kzalloc(&adev->dev, sizeof(*ctx), GFP_KERNEL); 101 210 if (!ctx) 102 211 return NULL; 103 212 104 213 ctx->count = count; 105 - ctx->links = kcalloc(ctx->count, sizeof(*ctx->links), GFP_KERNEL); 214 + ctx->links = devm_kcalloc(&adev->dev, ctx->count, 215 + sizeof(*ctx->links), GFP_KERNEL); 106 216 if (!ctx->links) 107 - goto link_err; 217 + return NULL; 218 + 219 + ctx->count = count; 220 + ctx->mmio_base = res->mmio_base; 221 + ctx->link_mask = res->link_mask; 222 + ctx->handle = res->handle; 223 + mutex_init(&ctx->shim_lock); 108 224 109 225 link = ctx->links; 226 + link_mask = ctx->link_mask; 227 + 228 + INIT_LIST_HEAD(&ctx->link_list); 110 229 111 230 /* Create SDW Master devices */ 112 - for (i = 0; i < count; i++) { 113 - if (link_mask && !(link_mask & BIT(i))) { 231 + for (i = 0; i < count; i++, link++) { 232 + if (!(link_mask & BIT(i))) { 114 233 dev_dbg(&adev->dev, 115 234 "Link %d masked, will not be enabled\n", i); 116 - link++; 117 235 continue; 118 236 } 119 237 238 + link->mmio_base = res->mmio_base; 120 239 link->registers = res->mmio_base + SDW_LINK_BASE 121 - + (SDW_LINK_SIZE * i); 240 + + (SDW_LINK_SIZE * i); 122 241 link->shim = res->mmio_base + SDW_SHIM_BASE; 123 242 link->alh = res->mmio_base + SDW_ALH_BASE; 124 243 125 244 link->ops = res->ops; 126 245 link->dev = res->dev; 127 246 247 + link->shim_lock = &ctx->shim_lock; 248 + link->shim_mask = &ctx->shim_mask; 249 + 128 250 memset(&pdevinfo, 0, sizeof(pdevinfo)); 129 251 130 252 pdevinfo.parent = res->parent; 131 - pdevinfo.name = "int-sdw"; 253 + pdevinfo.name = "intel-sdw"; 132 254 pdevinfo.id = i; 133 255 pdevinfo.fwnode = acpi_fwnode_handle(adev); 256 + pdevinfo.data = link; 257 + pdevinfo.size_data = sizeof(*link); 134 258 135 259 pdev = platform_device_register_full(&pdevinfo); 136 260 if (IS_ERR(pdev)) { 137 261 dev_err(&adev->dev, 138 262 "platform device creation failed: %ld\n", 139 263 PTR_ERR(pdev)); 140 - goto pdev_err; 264 + goto err; 141 265 } 142 - 143 266 link->pdev = pdev; 144 - link++; 267 + link->cdns = platform_get_drvdata(pdev); 268 + 269 + list_add_tail(&link->list, &ctx->link_list); 270 + bus = &link->cdns->bus; 271 + /* Calculate number of slaves */ 272 + list_for_each(node, &bus->slaves) 273 + num_slaves++; 274 + } 275 + 276 + ctx->ids = devm_kcalloc(&adev->dev, num_slaves, 277 + sizeof(*ctx->ids), GFP_KERNEL); 278 + if (!ctx->ids) 279 + goto err; 280 + 281 + ctx->num_slaves = num_slaves; 282 + i = 0; 283 + list_for_each_entry(link, &ctx->link_list, list) { 284 + bus = &link->cdns->bus; 285 + list_for_each_entry(slave, &bus->slaves, node) { 286 + ctx->ids[i].id = slave->id; 287 + ctx->ids[i].link_id = bus->link_id; 288 + i++; 289 + } 145 290 } 146 291 147 292 return ctx; 148 293 149 - pdev_err: 150 - sdw_intel_cleanup_pdev(ctx); 151 - link_err: 152 - kfree(ctx); 294 + err: 295 + ctx->count = i; 296 + sdw_intel_cleanup(ctx); 153 297 return NULL; 298 + } 299 + 300 + static int 301 + sdw_intel_startup_controller(struct sdw_intel_ctx *ctx) 302 + { 303 + struct acpi_device *adev; 304 + struct sdw_intel_link_res *link; 305 + u32 caps; 306 + u32 link_mask; 307 + int i; 308 + 309 + if (acpi_bus_get_device(ctx->handle, &adev)) 310 + return -EINVAL; 311 + 312 + /* Check SNDWLCAP.LCOUNT */ 313 + caps = ioread32(ctx->mmio_base + SDW_SHIM_BASE + SDW_SHIM_LCAP); 314 + caps &= GENMASK(2, 0); 315 + 316 + /* Check HW supported vs property value */ 317 + if (caps < ctx->count) { 318 + dev_err(&adev->dev, 319 + "BIOS master count is larger than hardware capabilities\n"); 320 + return -EINVAL; 321 + } 322 + 323 + if (!ctx->links) 324 + return -EINVAL; 325 + 326 + link = ctx->links; 327 + link_mask = ctx->link_mask; 328 + 329 + /* Startup SDW Master devices */ 330 + for (i = 0; i < ctx->count; i++, link++) { 331 + if (!(link_mask & BIT(i))) 332 + continue; 333 + 334 + intel_master_startup(link->pdev); 335 + } 336 + 337 + return 0; 154 338 } 155 339 156 340 static acpi_status sdw_intel_acpi_cb(acpi_handle handle, u32 level, 157 341 void *cdata, void **return_value) 158 342 { 159 - struct sdw_intel_res *res = cdata; 343 + struct sdw_intel_acpi_info *info = cdata; 160 344 struct acpi_device *adev; 161 345 acpi_status status; 162 346 u64 adr; ··· 356 168 return AE_NOT_FOUND; 357 169 } 358 170 359 - res->handle = handle; 171 + info->handle = handle; 360 172 361 173 /* 362 174 * On some Intel platforms, multiple children of the HDAS ··· 373 185 } 374 186 375 187 /** 376 - * sdw_intel_init() - SoundWire Intel init routine 188 + * sdw_intel_acpi_scan() - SoundWire Intel init routine 377 189 * @parent_handle: ACPI parent handle 378 - * @res: resource data 190 + * @info: description of what firmware/DSDT tables expose 379 191 * 380 - * This scans the namespace and creates SoundWire link controller devices 381 - * based on the info queried. 192 + * This scans the namespace and queries firmware to figure out which 193 + * links to enable. A follow-up use of sdw_intel_probe() and 194 + * sdw_intel_startup() is required for creation of devices and bus 195 + * startup 382 196 */ 383 - void *sdw_intel_init(acpi_handle *parent_handle, struct sdw_intel_res *res) 197 + int sdw_intel_acpi_scan(acpi_handle *parent_handle, 198 + struct sdw_intel_acpi_info *info) 384 199 { 385 200 acpi_status status; 386 201 387 202 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, 388 203 parent_handle, 1, 389 204 sdw_intel_acpi_cb, 390 - NULL, res, NULL); 205 + NULL, info, NULL); 391 206 if (ACPI_FAILURE(status)) 392 - return NULL; 207 + return -ENODEV; 393 208 394 - return sdw_intel_add_controller(res); 209 + return sdw_intel_scan_controller(info); 395 210 } 211 + EXPORT_SYMBOL_NS(sdw_intel_acpi_scan, SOUNDWIRE_INTEL_INIT); 396 212 397 213 /** 214 + * sdw_intel_probe() - SoundWire Intel probe routine 215 + * @res: resource data 216 + * 217 + * This registers a platform device for each Master handled by the controller, 218 + * and SoundWire Master and Slave devices will be created by the platform 219 + * device probe. All the information necessary is stored in the context, and 220 + * the res argument pointer can be freed after this step. 221 + * This function will be called after sdw_intel_acpi_scan() by SOF probe. 222 + */ 223 + struct sdw_intel_ctx 224 + *sdw_intel_probe(struct sdw_intel_res *res) 225 + { 226 + return sdw_intel_probe_controller(res); 227 + } 228 + EXPORT_SYMBOL_NS(sdw_intel_probe, SOUNDWIRE_INTEL_INIT); 229 + 230 + /** 231 + * sdw_intel_startup() - SoundWire Intel startup 232 + * @ctx: SoundWire context allocated in the probe 233 + * 234 + * Startup Intel SoundWire controller. This function will be called after 235 + * Intel Audio DSP is powered up. 236 + */ 237 + int sdw_intel_startup(struct sdw_intel_ctx *ctx) 238 + { 239 + return sdw_intel_startup_controller(ctx); 240 + } 241 + EXPORT_SYMBOL_NS(sdw_intel_startup, SOUNDWIRE_INTEL_INIT); 242 + /** 398 243 * sdw_intel_exit() - SoundWire Intel exit 399 - * @arg: callback context 244 + * @ctx: SoundWire context allocated in the probe 400 245 * 401 246 * Delete the controller instances created and cleanup 402 247 */ 403 248 void sdw_intel_exit(struct sdw_intel_ctx *ctx) 404 249 { 405 - sdw_intel_cleanup_pdev(ctx); 406 - kfree(ctx); 250 + sdw_intel_cleanup(ctx); 407 251 } 408 - EXPORT_SYMBOL(sdw_intel_exit); 252 + EXPORT_SYMBOL_NS(sdw_intel_exit, SOUNDWIRE_INTEL_INIT); 253 + 254 + void sdw_intel_process_wakeen_event(struct sdw_intel_ctx *ctx) 255 + { 256 + struct sdw_intel_link_res *link; 257 + u32 link_mask; 258 + int i; 259 + 260 + if (!ctx->links) 261 + return; 262 + 263 + link = ctx->links; 264 + link_mask = ctx->link_mask; 265 + 266 + /* Startup SDW Master devices */ 267 + for (i = 0; i < ctx->count; i++, link++) { 268 + if (!(link_mask & BIT(i))) 269 + continue; 270 + 271 + intel_master_process_wakeen_event(link->pdev); 272 + } 273 + } 274 + EXPORT_SYMBOL_NS(sdw_intel_process_wakeen_event, SOUNDWIRE_INTEL_INIT); 409 275 410 276 MODULE_LICENSE("Dual BSD/GPL"); 411 277 MODULE_DESCRIPTION("Intel Soundwire Init Library");
+2 -2
drivers/soundwire/qcom.c
··· 406 406 return ctrl->reg_write(ctrl, reg, val); 407 407 } 408 408 409 - static struct sdw_master_port_ops qcom_swrm_port_ops = { 409 + static const struct sdw_master_port_ops qcom_swrm_port_ops = { 410 410 .dpn_set_port_params = qcom_swrm_port_params, 411 411 .dpn_set_port_transport_params = qcom_swrm_transport_params, 412 412 .dpn_port_enable_ch = qcom_swrm_port_enable, 413 413 }; 414 414 415 - static struct sdw_master_ops qcom_swrm_ops = { 415 + static const struct sdw_master_ops qcom_swrm_ops = { 416 416 .xfer_msg = qcom_swrm_xfer_msg, 417 417 .pre_bank_switch = qcom_swrm_pre_bank_switch, 418 418 };
+98
drivers/soundwire/stream.c
··· 13 13 #include <linux/slab.h> 14 14 #include <linux/soundwire/sdw_registers.h> 15 15 #include <linux/soundwire/sdw.h> 16 + #include <sound/soc.h> 16 17 #include "bus.h" 17 18 18 19 /* ··· 1827 1826 return ret; 1828 1827 } 1829 1828 EXPORT_SYMBOL(sdw_deprepare_stream); 1829 + 1830 + static int set_stream(struct snd_pcm_substream *substream, 1831 + struct sdw_stream_runtime *sdw_stream) 1832 + { 1833 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 1834 + struct snd_soc_dai *dai; 1835 + int ret = 0; 1836 + int i; 1837 + 1838 + /* Set stream pointer on all DAIs */ 1839 + for_each_rtd_dais(rtd, i, dai) { 1840 + ret = snd_soc_dai_set_sdw_stream(dai, sdw_stream, substream->stream); 1841 + if (ret < 0) { 1842 + dev_err(rtd->dev, "failed to set stream pointer on dai %s", dai->name); 1843 + break; 1844 + } 1845 + } 1846 + 1847 + return ret; 1848 + } 1849 + 1850 + /** 1851 + * sdw_startup_stream() - Startup SoundWire stream 1852 + * 1853 + * @sdw_substream: Soundwire stream 1854 + * 1855 + * Documentation/driver-api/soundwire/stream.rst explains this API in detail 1856 + */ 1857 + int sdw_startup_stream(void *sdw_substream) 1858 + { 1859 + struct snd_pcm_substream *substream = sdw_substream; 1860 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 1861 + struct sdw_stream_runtime *sdw_stream; 1862 + char *name; 1863 + int ret; 1864 + 1865 + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1866 + name = kasprintf(GFP_KERNEL, "%s-Playback", substream->name); 1867 + else 1868 + name = kasprintf(GFP_KERNEL, "%s-Capture", substream->name); 1869 + 1870 + if (!name) 1871 + return -ENOMEM; 1872 + 1873 + sdw_stream = sdw_alloc_stream(name); 1874 + if (!sdw_stream) { 1875 + dev_err(rtd->dev, "alloc stream failed for substream DAI %s", substream->name); 1876 + ret = -ENOMEM; 1877 + goto error; 1878 + } 1879 + 1880 + ret = set_stream(substream, sdw_stream); 1881 + if (ret < 0) 1882 + goto release_stream; 1883 + return 0; 1884 + 1885 + release_stream: 1886 + sdw_release_stream(sdw_stream); 1887 + set_stream(substream, NULL); 1888 + error: 1889 + kfree(name); 1890 + return ret; 1891 + } 1892 + EXPORT_SYMBOL(sdw_startup_stream); 1893 + 1894 + /** 1895 + * sdw_shutdown_stream() - Shutdown SoundWire stream 1896 + * 1897 + * @sdw_substream: Soundwire stream 1898 + * 1899 + * Documentation/driver-api/soundwire/stream.rst explains this API in detail 1900 + */ 1901 + void sdw_shutdown_stream(void *sdw_substream) 1902 + { 1903 + struct snd_pcm_substream *substream = sdw_substream; 1904 + struct snd_soc_pcm_runtime *rtd = substream->private_data; 1905 + struct sdw_stream_runtime *sdw_stream; 1906 + struct snd_soc_dai *dai; 1907 + 1908 + /* Find stream from first CPU DAI */ 1909 + dai = asoc_rtd_to_cpu(rtd, 0); 1910 + 1911 + sdw_stream = snd_soc_dai_get_sdw_stream(dai, substream->stream); 1912 + 1913 + if (!sdw_stream) { 1914 + dev_err(rtd->dev, "no stream found for DAI %s", dai->name); 1915 + return; 1916 + } 1917 + 1918 + /* release memory */ 1919 + kfree(sdw_stream->name); 1920 + sdw_release_stream(sdw_stream); 1921 + 1922 + /* clear DAI data */ 1923 + set_stream(substream, NULL); 1924 + } 1925 + EXPORT_SYMBOL(sdw_shutdown_stream);
+2
include/linux/mod_devicetable.h
··· 251 251 struct sdw_device_id { 252 252 __u16 mfg_id; 253 253 __u16 part_id; 254 + __u8 sdw_version; 255 + __u8 class_id; 254 256 kernel_ulong_t driver_data; 255 257 }; 256 258
+19 -14
include/linux/soundwire/sdw.h
··· 88 88 * @SDW_CLK_POST_DEPREPARE: post clock stop de-prepare 89 89 */ 90 90 enum sdw_clk_stop_type { 91 - SDW_CLK_PRE_PREPARE = 0, 92 - SDW_CLK_POST_PREPARE, 93 - SDW_CLK_PRE_DEPREPARE, 94 - SDW_CLK_POST_DEPREPARE, 91 + SDW_CLK_PRE_PREPARE = 0, 92 + SDW_CLK_POST_PREPARE, 93 + SDW_CLK_PRE_DEPREPARE, 94 + SDW_CLK_POST_DEPREPARE, 95 95 }; 96 96 97 97 /** ··· 152 152 * 153 153 * @SDW_PORT_DATA_MODE_NORMAL: Normal data mode where audio data is received 154 154 * and transmitted. 155 + * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce 156 + * a pseudo random data pattern that is transferred 157 + * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of 158 + * logic 0. The encoding will result in no signal transitions 155 159 * @SDW_PORT_DATA_MODE_STATIC_1: Simple test mode which uses static value of 156 160 * logic 1. The encoding will result in signal transitions at every bitslot 157 161 * owned by this Port 158 - * @SDW_PORT_DATA_MODE_STATIC_0: Simple test mode which uses static value of 159 - * logic 0. The encoding will result in no signal transitions 160 - * @SDW_PORT_DATA_MODE_PRBS: Test mode which uses a PRBS generator to produce 161 - * a pseudo random data pattern that is transferred 162 162 */ 163 163 enum sdw_port_data_mode { 164 164 SDW_PORT_DATA_MODE_NORMAL = 0, 165 - SDW_PORT_DATA_MODE_STATIC_1 = 1, 165 + SDW_PORT_DATA_MODE_PRBS = 1, 166 166 SDW_PORT_DATA_MODE_STATIC_0 = 2, 167 - SDW_PORT_DATA_MODE_PRBS = 3, 167 + SDW_PORT_DATA_MODE_STATIC_1 = 3, 168 168 }; 169 169 170 170 /* ··· 426 426 * struct sdw_slave_id - Slave ID 427 427 * @mfg_id: MIPI Manufacturer ID 428 428 * @part_id: Device Part ID 429 - * @class_id: MIPI Class ID, unused now. 430 - * Currently a placeholder in MIPI SoundWire Spec 429 + * @class_id: MIPI Class ID (defined starting with SoundWire 1.2 spec) 431 430 * @unique_id: Device unique ID 432 431 * @sdw_version: SDW version implemented 433 432 * ··· 658 659 struct device_driver driver; 659 660 }; 660 661 661 - #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \ 662 - { .mfg_id = (_mfg_id), .part_id = (_part_id), \ 662 + #define SDW_SLAVE_ENTRY_EXT(_mfg_id, _part_id, _version, _c_id, _drv_data) \ 663 + { .mfg_id = (_mfg_id), .part_id = (_part_id), \ 664 + .sdw_version = (_version), .class_id = (_c_id), \ 663 665 .driver_data = (unsigned long)(_drv_data) } 666 + 667 + #define SDW_SLAVE_ENTRY(_mfg_id, _part_id, _drv_data) \ 668 + SDW_SLAVE_ENTRY_EXT((_mfg_id), (_part_id), 0, 0, (_drv_data)) 664 669 665 670 int sdw_handle_slave_status(struct sdw_bus *bus, 666 671 enum sdw_slave_status status[]); ··· 955 952 struct sdw_stream_runtime *stream); 956 953 int sdw_stream_remove_slave(struct sdw_slave *slave, 957 954 struct sdw_stream_runtime *stream); 955 + int sdw_startup_stream(void *sdw_substream); 958 956 int sdw_prepare_stream(struct sdw_stream_runtime *stream); 959 957 int sdw_enable_stream(struct sdw_stream_runtime *stream); 960 958 int sdw_disable_stream(struct sdw_stream_runtime *stream); 961 959 int sdw_deprepare_stream(struct sdw_stream_runtime *stream); 960 + void sdw_shutdown_stream(void *sdw_substream); 962 961 int sdw_bus_prep_clk_stop(struct sdw_bus *bus); 963 962 int sdw_bus_clk_stop(struct sdw_bus *bus); 964 963 int sdw_bus_exit_clk_stop(struct sdw_bus *bus);
+2
include/linux/soundwire/sdw_intel.h
··· 115 115 * links 116 116 * @link_list: list to handle interrupts across all links 117 117 * @shim_lock: mutex to handle concurrent rmw access to shared SHIM registers. 118 + * @shim_mask: flags to track initialization of SHIM shared registers 118 119 */ 119 120 struct sdw_intel_ctx { 120 121 int count; ··· 127 126 struct sdw_intel_slave_id *ids; 128 127 struct list_head link_list; 129 128 struct mutex shim_lock; /* lock for access to shared SHIM registers */ 129 + u32 shim_mask; 130 130 }; 131 131 132 132 /**
+116 -1
include/linux/soundwire/sdw_registers.h
··· 12 12 #define SDW_REG_SHIFT(n) (ffs(n) - 1) 13 13 14 14 /* 15 - * SDW registers as defined by MIPI 1.1 Spec 15 + * SDW registers as defined by MIPI 1.2 Spec 16 16 */ 17 17 #define SDW_REGADDR GENMASK(14, 0) 18 18 #define SDW_SCP_ADDRPAGE2_MASK GENMASK(22, 15) ··· 43 43 #define SDW_DP0_INT_TEST_FAIL BIT(0) 44 44 #define SDW_DP0_INT_PORT_READY BIT(1) 45 45 #define SDW_DP0_INT_BRA_FAILURE BIT(2) 46 + #define SDW_DP0_SDCA_CASCADE BIT(3) 47 + /* BIT(4) not allocated in SoundWire specification 1.2 */ 46 48 #define SDW_DP0_INT_IMPDEF1 BIT(5) 47 49 #define SDW_DP0_INT_IMPDEF2 BIT(6) 48 50 #define SDW_DP0_INT_IMPDEF3 BIT(7) ··· 108 106 #define SDW_SCP_ADDRPAGE2 0x49 109 107 #define SDW_SCP_KEEPEREN 0x4A 110 108 #define SDW_SCP_BANKDELAY 0x4B 109 + #define SDW_SCP_COMMIT 0x4C 110 + 111 + #define SDW_SCP_BUS_CLOCK_BASE 0x4D 112 + #define SDW_SCP_BASE_CLOCK_FREQ GENMASK(2, 0) 113 + #define SDW_SCP_BASE_CLOCK_UNKNOWN 0x0 114 + #define SDW_SCP_BASE_CLOCK_19200000_HZ 0x1 115 + #define SDW_SCP_BASE_CLOCK_24000000_HZ 0x2 116 + #define SDW_SCP_BASE_CLOCK_24576000_HZ 0x3 117 + #define SDW_SCP_BASE_CLOCK_22579200_HZ 0x4 118 + #define SDW_SCP_BASE_CLOCK_32000000_HZ 0x5 119 + #define SDW_SCP_BASE_CLOCK_RESERVED 0x6 120 + #define SDW_SCP_BASE_CLOCK_IMP_DEF 0x7 121 + 122 + /* 0x4E is not allocated in SoundWire specification 1.2 */ 111 123 #define SDW_SCP_TESTMODE 0x4F 112 124 #define SDW_SCP_DEVID_0 0x50 113 125 #define SDW_SCP_DEVID_1 0x51 ··· 130 114 #define SDW_SCP_DEVID_4 0x54 131 115 #define SDW_SCP_DEVID_5 0x55 132 116 117 + /* Both INT and STATUS register are same */ 118 + #define SDW_SCP_SDCA_INT1 0x58 119 + #define SDW_SCP_SDCA_INT_SDCA_0 BIT(0) 120 + #define SDW_SCP_SDCA_INT_SDCA_1 BIT(1) 121 + #define SDW_SCP_SDCA_INT_SDCA_2 BIT(2) 122 + #define SDW_SCP_SDCA_INT_SDCA_3 BIT(3) 123 + #define SDW_SCP_SDCA_INT_SDCA_4 BIT(4) 124 + #define SDW_SCP_SDCA_INT_SDCA_5 BIT(5) 125 + #define SDW_SCP_SDCA_INT_SDCA_6 BIT(6) 126 + #define SDW_SCP_SDCA_INT_SDCA_7 BIT(7) 127 + 128 + #define SDW_SCP_SDCA_INT2 0x59 129 + #define SDW_SCP_SDCA_INT_SDCA_8 BIT(0) 130 + #define SDW_SCP_SDCA_INT_SDCA_9 BIT(1) 131 + #define SDW_SCP_SDCA_INT_SDCA_10 BIT(2) 132 + #define SDW_SCP_SDCA_INT_SDCA_11 BIT(3) 133 + #define SDW_SCP_SDCA_INT_SDCA_12 BIT(4) 134 + #define SDW_SCP_SDCA_INT_SDCA_13 BIT(5) 135 + #define SDW_SCP_SDCA_INT_SDCA_14 BIT(6) 136 + #define SDW_SCP_SDCA_INT_SDCA_15 BIT(7) 137 + 138 + #define SDW_SCP_SDCA_INT3 0x5A 139 + #define SDW_SCP_SDCA_INT_SDCA_16 BIT(0) 140 + #define SDW_SCP_SDCA_INT_SDCA_17 BIT(1) 141 + #define SDW_SCP_SDCA_INT_SDCA_18 BIT(2) 142 + #define SDW_SCP_SDCA_INT_SDCA_19 BIT(3) 143 + #define SDW_SCP_SDCA_INT_SDCA_20 BIT(4) 144 + #define SDW_SCP_SDCA_INT_SDCA_21 BIT(5) 145 + #define SDW_SCP_SDCA_INT_SDCA_22 BIT(6) 146 + #define SDW_SCP_SDCA_INT_SDCA_23 BIT(7) 147 + 148 + #define SDW_SCP_SDCA_INT4 0x5B 149 + #define SDW_SCP_SDCA_INT_SDCA_24 BIT(0) 150 + #define SDW_SCP_SDCA_INT_SDCA_25 BIT(1) 151 + #define SDW_SCP_SDCA_INT_SDCA_26 BIT(2) 152 + #define SDW_SCP_SDCA_INT_SDCA_27 BIT(3) 153 + #define SDW_SCP_SDCA_INT_SDCA_28 BIT(4) 154 + #define SDW_SCP_SDCA_INT_SDCA_29 BIT(5) 155 + #define SDW_SCP_SDCA_INT_SDCA_30 BIT(6) 156 + /* BIT(7) not allocated in SoundWire 1.2 specification */ 157 + 158 + #define SDW_SCP_SDCA_INTMASK1 0x5C 159 + #define SDW_SCP_SDCA_INTMASK_SDCA_0 BIT(0) 160 + #define SDW_SCP_SDCA_INTMASK_SDCA_1 BIT(1) 161 + #define SDW_SCP_SDCA_INTMASK_SDCA_2 BIT(2) 162 + #define SDW_SCP_SDCA_INTMASK_SDCA_3 BIT(3) 163 + #define SDW_SCP_SDCA_INTMASK_SDCA_4 BIT(4) 164 + #define SDW_SCP_SDCA_INTMASK_SDCA_5 BIT(5) 165 + #define SDW_SCP_SDCA_INTMASK_SDCA_6 BIT(6) 166 + #define SDW_SCP_SDCA_INTMASK_SDCA_7 BIT(7) 167 + 168 + #define SDW_SCP_SDCA_INTMASK2 0x5D 169 + #define SDW_SCP_SDCA_INTMASK_SDCA_8 BIT(0) 170 + #define SDW_SCP_SDCA_INTMASK_SDCA_9 BIT(1) 171 + #define SDW_SCP_SDCA_INTMASK_SDCA_10 BIT(2) 172 + #define SDW_SCP_SDCA_INTMASK_SDCA_11 BIT(3) 173 + #define SDW_SCP_SDCA_INTMASK_SDCA_12 BIT(4) 174 + #define SDW_SCP_SDCA_INTMASK_SDCA_13 BIT(5) 175 + #define SDW_SCP_SDCA_INTMASK_SDCA_14 BIT(6) 176 + #define SDW_SCP_SDCA_INTMASK_SDCA_15 BIT(7) 177 + 178 + #define SDW_SCP_SDCA_INTMASK3 0x5E 179 + #define SDW_SCP_SDCA_INTMASK_SDCA_16 BIT(0) 180 + #define SDW_SCP_SDCA_INTMASK_SDCA_17 BIT(1) 181 + #define SDW_SCP_SDCA_INTMASK_SDCA_18 BIT(2) 182 + #define SDW_SCP_SDCA_INTMASK_SDCA_19 BIT(3) 183 + #define SDW_SCP_SDCA_INTMASK_SDCA_20 BIT(4) 184 + #define SDW_SCP_SDCA_INTMASK_SDCA_21 BIT(5) 185 + #define SDW_SCP_SDCA_INTMASK_SDCA_22 BIT(6) 186 + #define SDW_SCP_SDCA_INTMASK_SDCA_23 BIT(7) 187 + 188 + #define SDW_SCP_SDCA_INTMASK4 0x5F 189 + #define SDW_SCP_SDCA_INTMASK_SDCA_24 BIT(0) 190 + #define SDW_SCP_SDCA_INTMASK_SDCA_25 BIT(1) 191 + #define SDW_SCP_SDCA_INTMASK_SDCA_26 BIT(2) 192 + #define SDW_SCP_SDCA_INTMASK_SDCA_27 BIT(3) 193 + #define SDW_SCP_SDCA_INTMASK_SDCA_28 BIT(4) 194 + #define SDW_SCP_SDCA_INTMASK_SDCA_29 BIT(5) 195 + #define SDW_SCP_SDCA_INTMASK_SDCA_30 BIT(6) 196 + /* BIT(7) not allocated in SoundWire 1.2 specification */ 197 + 133 198 /* Banked Registers */ 134 199 #define SDW_SCP_FRAMECTRL_B0 0x60 135 200 #define SDW_SCP_FRAMECTRL_B1 (0x60 + SDW_BANK1_OFFSET) 136 201 #define SDW_SCP_NEXTFRAME_B0 0x61 137 202 #define SDW_SCP_NEXTFRAME_B1 (0x61 + SDW_BANK1_OFFSET) 203 + 204 + #define SDW_SCP_BUSCLOCK_SCALE_B0 0x62 205 + #define SDW_SCP_BUSCLOCK_SCALE_B1 (0x62 + SDW_BANK1_OFFSET) 206 + #define SDW_SCP_CLOCK_SCALE GENMASK(3, 0) 207 + 208 + /* PHY registers - CTRL and STAT are the same address */ 209 + #define SDW_SCP_PHY_OUT_CTRL_0 0x80 210 + #define SDW_SCP_PHY_OUT_CTRL_1 0x81 211 + #define SDW_SCP_PHY_OUT_CTRL_2 0x82 212 + #define SDW_SCP_PHY_OUT_CTRL_3 0x83 213 + #define SDW_SCP_PHY_OUT_CTRL_4 0x84 214 + #define SDW_SCP_PHY_OUT_CTRL_5 0x85 215 + #define SDW_SCP_PHY_OUT_CTRL_6 0x86 216 + #define SDW_SCP_PHY_OUT_CTRL_7 0x87 217 + 218 + #define SDW_SCP_CAP_LOAD_CTRL GENMASK(2, 0) 219 + #define SDW_SCP_DRIVE_STRENGTH_CTRL GENMASK(5, 3) 220 + #define SDW_SCP_SLEW_TIME_CTRL GENMASK(7, 6) 138 221 139 222 /* Both INT and STATUS register is same */ 140 223 #define SDW_DPN_INT(n) (0x0 + SDW_DPN_SIZE * (n))
+2
scripts/mod/devicetable-offsets.c
··· 216 216 DEVID(sdw_device_id); 217 217 DEVID_FIELD(sdw_device_id, mfg_id); 218 218 DEVID_FIELD(sdw_device_id, part_id); 219 + DEVID_FIELD(sdw_device_id, sdw_version); 220 + DEVID_FIELD(sdw_device_id, class_id); 219 221 220 222 DEVID(fsl_mc_device_id); 221 223 DEVID_FIELD(fsl_mc_device_id, vendor);
+5 -1
scripts/mod/file2alias.c
··· 1258 1258 return 1; 1259 1259 } 1260 1260 1261 - /* Looks like: sdw:mNpN */ 1261 + /* Looks like: sdw:mNpNvNcN */ 1262 1262 static int do_sdw_entry(const char *filename, void *symval, char *alias) 1263 1263 { 1264 1264 DEF_FIELD(symval, sdw_device_id, mfg_id); 1265 1265 DEF_FIELD(symval, sdw_device_id, part_id); 1266 + DEF_FIELD(symval, sdw_device_id, sdw_version); 1267 + DEF_FIELD(symval, sdw_device_id, class_id); 1266 1268 1267 1269 strcpy(alias, "sdw:"); 1268 1270 ADD(alias, "m", mfg_id != 0, mfg_id); 1269 1271 ADD(alias, "p", part_id != 0, part_id); 1272 + ADD(alias, "v", sdw_version != 0, sdw_version); 1273 + ADD(alias, "c", class_id != 0, class_id); 1270 1274 1271 1275 add_wildcard(alias); 1272 1276 return 1;