android_kernel_xiaomi_sm7250/sound/usb/pcm.c
UtsavBalar1231 7f11ea40c4 Merge tag 'ASB-2021-04-05_4.19-stable' of https://github.com/aosp-mirror/kernel_common into android12-base
https://source.android.com/security/bulletin/2021-04-01
CVE-2020-15436
CVE-2020-29368
CVE-2020-25705

* tag 'ASB-2021-04-05_4.19-stable' of https://github.com/aosp-mirror/kernel_common:
  ANDROID: Add OWNERS files referring to the respective android-mainline OWNERS
  BACKPORT: drm/virtio: Use vmalloc for command buffer allocations.
  UPSTREAM: drm/virtio: Rewrite virtio_gpu_queue_ctrl_buffer using fenced version.
  ANDROID: Make vsock virtio packet buff size configurable
  ANDROID: fix up ext4 build from 4.19.183
  ANDROID: refresh ABI XML to new version
  ANDROID: refresh ABI XML
  Linux 4.19.183
  cifs: Fix preauth hash corruption
  x86/apic/of: Fix CPU devicetree-node lookups
  genirq: Disable interrupts for force threaded handlers
  ext4: fix potential error in ext4_do_update_inode
  ext4: do not try to set xattr into ea_inode if value is empty
  ext4: find old entry again if failed to rename whiteout
  x86: Introduce TS_COMPAT_RESTART to fix get_nr_restart_syscall()
  x86: Move TS_COMPAT back to asm/thread_info.h
  kernel, fs: Introduce and use set_restart_fn() and arch_set_restart_data()
  x86/ioapic: Ignore IRQ2 again
  perf/x86/intel: Fix a crash caused by zero PEBS status
  PCI: rpadlpar: Fix potential drc_name corruption in store functions
  iio: hid-sensor-temperature: Fix issues of timestamp channel
  iio: hid-sensor-prox: Fix scale not correct issue
  iio: hid-sensor-humidity: Fix alignment issue of timestamp channel
  iio: gyro: mpu3050: Fix error handling in mpu3050_trigger_handler
  iio: adis16400: Fix an error code in adis16400_initial_setup()
  iio:adc:qcom-spmi-vadc: add default scale to LR_MUX2_BAT_ID channel
  iio:adc:stm32-adc: Add HAS_IOMEM dependency
  usb: gadget: configfs: Fix KASAN use-after-free
  USB: replace hardcode maximum usb string length by definition
  usbip: Fix incorrect double assignment to udc->ud.tcp_rx
  usb-storage: Add quirk to defeat Kindle's automatic unload
  powerpc: Force inlining of cpu_has_feature() to avoid build failure
  nvme-rdma: fix possible hang when failing to set io queues
  scsi: lpfc: Fix some error codes in debugfs
  net/qrtr: fix __netdev_alloc_skb call
  sunrpc: fix refcount leak for rpc auth modules
  svcrdma: disable timeouts on rdma backchannel
  NFSD: Repair misuse of sv_lock in 5.10.16-rt30.
  nvmet: don't check iosqes,iocqes for discovery controllers
  ASoC: fsl_ssi: Fix TDM slot setup for I2S mode
  btrfs: fix slab cache flags for free space tree bitmap
  btrfs: fix race when cloning extent buffer during rewind of an old root
  tools build: Check if gettid() is available before providing helper
  tools build feature: Check if eventfd() is available
  tools build feature: Check if get_current_dir_name() is available
  perf tools: Use %define api.pure full instead of %pure-parser
  lkdtm: don't move ctors to .rodata
  vmlinux.lds.h: Create section for protection against instrumentation
  Revert "PM: runtime: Update device status before letting suppliers suspend"
  ALSA: hda: generic: Fix the micmute led init state
  ASoC: ak5558: Add MODULE_DEVICE_TABLE
  ASoC: ak4458: Add MODULE_DEVICE_TABLE
  ANDROID: clang: update to 12.0.4
  Linux 4.19.182
  net: dsa: b53: Support setting learning on port
  net: dsa: tag_mtk: fix 802.1ad VLAN egress
  bpf: Add sanity check for upper ptr_limit
  bpf: Simplify alu_limit masking for pointer arithmetic
  bpf: Fix off-by-one for area size in creating mask to left
  bpf: Prohibit alu ops for pointer types not defining ptr_limit
  KVM: arm64: nvhe: Save the SPE context early
  ext4: check journal inode extents more carefully
  Revert "net: Introduce parse_protocol header_ops callback"
  Revert "net: check if protocol extracted by virtio_net_hdr_set_proto is correct"
  Linux 4.19.181
  xen/events: avoid handling the same event on two cpus at the same time
  xen/events: don't unmask an event channel when an eoi is pending
  xen/events: reset affinity of 2-level event when tearing it down
  KVM: arm64: Fix exclusive limit for IPA size
  hwmon: (lm90) Fix max6658 sporadic wrong temperature reading
  x86/unwind/orc: Disable KASAN checking in the ORC unwinder, part 2
  binfmt_misc: fix possible deadlock in bm_register_write
  powerpc/64s: Fix instruction encoding for lis in ppc_function_entry()
  include/linux/sched/mm.h: use rcu_dereference in in_vfork()
  stop_machine: mark helpers __always_inline
  hrtimer: Update softirq_expires_next correctly after __hrtimer_get_next_event()
  configfs: fix a use-after-free in __configfs_open_file
  block: rsxx: fix error return code of rsxx_pci_probe()
  NFSv4.2: fix return value of _nfs4_get_security_label()
  sh_eth: fix TRSCER mask for R7S72100
  staging: comedi: pcl818: Fix endian problem for AI command data
  staging: comedi: pcl711: Fix endian problem for AI command data
  staging: comedi: me4000: Fix endian problem for AI command data
  staging: comedi: dmm32at: Fix endian problem for AI command data
  staging: comedi: das800: Fix endian problem for AI command data
  staging: comedi: das6402: Fix endian problem for AI command data
  staging: comedi: adv_pci1710: Fix endian problem for AI command data
  staging: comedi: addi_apci_1500: Fix endian problem for command sample
  staging: comedi: addi_apci_1032: Fix endian problem for COS sample
  staging: rtl8192e: Fix possible buffer overflow in _rtl92e_wx_set_scan
  staging: rtl8712: Fix possible buffer overflow in r8712_sitesurvey_cmd
  staging: ks7010: prevent buffer overflow in ks_wlan_set_scan()
  staging: rtl8188eu: fix potential memory corruption in rtw_check_beacon_data()
  staging: rtl8712: unterminated string leads to read overflow
  staging: rtl8188eu: prevent ->ssid overflow in rtw_wx_set_scan()
  staging: rtl8192u: fix ->ssid overflow in r8192_wx_set_scan()
  usbip: fix vudc usbip_sockfd_store races leading to gpf
  usbip: fix vhci_hcd attach_store() races leading to gpf
  usbip: fix stub_dev usbip_sockfd_store() races leading to gpf
  usbip: fix vudc to check for stream socket
  usbip: fix vhci_hcd to check for stream socket
  usbip: fix stub_dev to check for stream socket
  USB: serial: cp210x: add some more GE USB IDs
  USB: serial: cp210x: add ID for Acuity Brands nLight Air Adapter
  USB: serial: ch341: add new Product ID
  USB: serial: io_edgeport: fix memory leak in edge_startup
  usb: xhci: Fix ASMedia ASM1042A and ASM3242 DMA addressing
  xhci: Improve detection of device initiated wake signal.
  usb: renesas_usbhs: Clear PIPECFG for re-enabling pipe with other EPNUM
  USB: usblp: fix a hang in poll() if disconnected
  usb: dwc3: qcom: Honor wakeup enabled/disabled state
  usb: gadget: f_uac1: stop playback on function disable
  usb: gadget: f_uac2: always increase endpoint max_packet_size by one audio slot
  USB: gadget: u_ether: Fix a configfs return code
  Goodix Fingerprint device is not a modem
  mmc: cqhci: Fix random crash when remove mmc module/card
  mmc: core: Fix partition switch time for eMMC
  s390/dasd: fix hanging IO request during DASD driver unbind
  s390/dasd: fix hanging DASD driver unbind
  Revert 95ebabde382c ("capabilities: Don't allow writing ambiguous v3 file capabilities")
  ALSA: usb-audio: Apply the control quirk to Plantronics headsets
  ALSA: usb-audio: Fix "cannot get freq eq" errors on Dell AE515 sound bar
  ALSA: hda: Avoid spurious unsol event handling during S3/S4
  ALSA: hda: Drop the BATCH workaround for AMD controllers
  ALSA: hda/hdmi: Cancel pending works before suspend
  ALSA: usb: Add Plantronics C320-M USB ctrl msg delay quirk
  scsi: target: core: Prevent underflow for service actions
  scsi: target: core: Add cmd length set before cmd complete
  scsi: libiscsi: Fix iscsi_prep_scsi_cmd_pdu() error handling
  s390/smp: __smp_rescan_cpus() - move cpumask away from stack
  i40e: Fix memory leak in i40e_probe
  PCI: Fix pci_register_io_range() memory leak
  PCI: mediatek: Add missing of_node_put() to fix reference leak
  PCI: xgene-msi: Fix race in installing chained irq handler
  sparc64: Use arch_validate_flags() to validate ADI flag
  sparc32: Limit memblock allocation to low memory
  powerpc/perf: Record counter overflow always if SAMPLE_IP is unset
  powerpc: improve handling of unrecoverable system reset
  powerpc/pci: Add ppc_md.discover_phbs()
  mmc: mediatek: fix race condition between msdc_request_timeout and irq
  mmc: mxs-mmc: Fix a resource leak in an error handling path in 'mxs_mmc_probe()'
  udf: fix silent AED tagLocation corruption
  i2c: rcar: optimize cacheline to minimize HW race condition
  net: phy: fix save wrong speed and duplex problem if autoneg is on
  media: v4l: vsp1: Fix bru null pointer access
  media: v4l: vsp1: Fix uif null pointer access
  media: usbtv: Fix deadlock on suspend
  sh_eth: fix TRSCER mask for R7S9210
  s390/cio: return -EFAULT if copy_to_user() fails
  drm: meson_drv add shutdown function
  drm/compat: Clear bounce structures
  s390/cio: return -EFAULT if copy_to_user() fails again
  perf traceevent: Ensure read cmdlines are null terminated.
  selftests: forwarding: Fix race condition in mirror installation
  net: stmmac: fix watchdog timeout during suspend/resume stress test
  net: stmmac: stop each tx channel independently
  net: qrtr: fix error return code of qrtr_sendmsg()
  net: davicom: Fix regulator not turned off on driver removal
  net: davicom: Fix regulator not turned off on failed probe
  net: lapbether: Remove netif_start_queue / netif_stop_queue
  cipso,calipso: resolve a number of problems with the DOI refcounts
  net: usb: qmi_wwan: allow qmimux add/del with master up
  net: sched: avoid duplicates in classes dump
  net: stmmac: fix incorrect DMA channel intr enable setting of EQoS v4.10
  net/mlx4_en: update moderation when config reset
  net: avoid infinite loop in mpls_gso_segment when mpls_hlen == 0
  net: check if protocol extracted by virtio_net_hdr_set_proto is correct
  sh_eth: fix TRSCER mask for SH771x
  Revert "mm, slub: consider rest of partial list if acquire_slab() fails"
  scripts/recordmcount.{c,pl}: support -ffunction-sections .text.* section names
  cifs: return proper error code in statfs(2)
  tcp: add sanity tests to TCP_QUEUE_SEQ
  tcp: annotate tp->write_seq lockless reads
  tcp: annotate tp->copied_seq lockless reads
  mt76: dma: do not report truncated frames to mac80211
  netfilter: x_tables: gpf inside xt_find_revision()
  can: flexcan: enable RX FIFO after FRZ/HALT valid
  can: flexcan: assert FRZ bit in flexcan_chip_freeze()
  can: skb: can_skb_set_owner(): fix ref counting if socket was closed before setting skb ownership
  net: Introduce parse_protocol header_ops callback
  net: Fix gro aggregation for udp encaps with zero csum
  ath9k: fix transmitting to stations in dynamic SMPS mode
  ethernet: alx: fix order of calls on resume
  uapi: nfnetlink_cthelper.h: fix userspace compilation error
  FROMGIT: configfs: fix a use-after-free in __configfs_open_file
  ANDROID: GKI: Enable CONFIG_BT for x86
  Revert "Revert "zram: close udev startup race condition as default groups""
  Revert "block: genhd: add 'groups' argument to device_add_disk"
  Revert "nvme: register ns_id attributes as default sysfs groups"
  Revert "aoe: register default groups with device_add_disk()"
  Revert "zram: register default groups with device_add_disk()"
  Revert "virtio-blk: modernize sysfs attribute creation"
  Linux 4.19.180
  mmc: sdhci-of-dwcmshc: set SDHCI_QUIRK2_PRESET_VALUE_BROKEN
  drm/msm/a5xx: Remove overwriting A5XX_PC_DBG_ECO_CNTL register
  misc: eeprom_93xx46: Add quirk to support Microchip 93LC46B eeprom
  PCI: Add function 1 DMA alias quirk for Marvell 9215 SATA controller
  ASoC: Intel: bytcr_rt5640: Add quirk for ARCHOS Cesium 140
  media: cx23885: add more quirks for reset DMA on some AMD IOMMU
  HID: mf: add support for 0079:1846 Mayflash/Dragonrise USB Gamecube Adapter
  platform/x86: acer-wmi: Add ACER_CAP_KBD_DOCK quirk for the Aspire Switch 10E SW3-016
  platform/x86: acer-wmi: Add support for SW_TABLET_MODE on Switch devices
  platform/x86: acer-wmi: Add ACER_CAP_SET_FUNCTION_MODE capability flag
  platform/x86: acer-wmi: Add new force_caps module parameter
  platform/x86: acer-wmi: Cleanup accelerometer device handling
  platform/x86: acer-wmi: Cleanup ACER_CAP_FOO defines
  mwifiex: pcie: skip cancel_work_sync() on reset failure path
  iommu/amd: Fix sleeping in atomic in increase_address_space()
  dm table: fix zoned iterate_devices based device capability checks
  dm table: fix DAX iterate_devices based device capability checks
  dm table: fix iterate_devices based device capability checks
  net: dsa: add GRO support via gro_cells
  r8169: fix resuming from suspend on RTL8105e if machine runs on battery
  dm verity: fix FEC for RS roots unaligned to block size
  rsxx: Return -EFAULT if copy_to_user() fails
  RDMA/rxe: Fix missing kconfig dependency on CRYPTO
  ALSA: ctxfi: cthw20k2: fix mask on conf to allow 4 bits
  virtio-blk: modernize sysfs attribute creation
  zram: register default groups with device_add_disk()
  aoe: register default groups with device_add_disk()
  nvme: register ns_id attributes as default sysfs groups
  block: genhd: add 'groups' argument to device_add_disk
  Revert "zram: close udev startup race condition as default groups"
  usbip: tools: fix build error for multiple definition
  drm/amdgpu: fix parameter error of RREG32_PCIE() in amdgpu_regs_pcie
  dm bufio: subtract the number of initial sectors in dm_bufio_get_device_size
  PM: runtime: Update device status before letting suppliers suspend
  btrfs: unlock extents in btrfs_zero_range in case of quota reservation errors
  btrfs: free correct amount of space in btrfs_delayed_inode_reserve_metadata
  btrfs: validate qgroup inherit for SNAP_CREATE_V2 ioctl
  btrfs: fix raid6 qstripe kmap
  btrfs: raid56: simplify tracking of Q stripe presence
  ANDROID: GKI: hack up fs/sysfs/file.c to prevent GENKSYMS change
  Revert "arm64: Avoid redundant type conversions in xchg() and cmpxchg()"
  Linux 4.19.179
  ALSA: hda/realtek: Apply dual codec quirks for MSI Godlike X570 board
  ALSA: hda/realtek: Add quirk for Clevo NH55RZQ
  media: v4l: ioctl: Fix memory leak in video_usercopy
  swap: fix swapfile read/write offset
  zsmalloc: account the number of compacted pages correctly
  xen-netback: respect gnttab_map_refs()'s return value
  Xen/gnttab: handle p2m update errors on a per-slot basis
  scsi: iscsi: Verify lengths on passthrough PDUs
  scsi: iscsi: Ensure sysfs attributes are limited to PAGE_SIZE
  sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output
  scsi: iscsi: Restrict sessions and handles to admin capabilities
  ASoC: Intel: bytcr_rt5640: Add quirk for the Acer One S1002 tablet
  ASoC: Intel: bytcr_rt5640: Add quirk for the Voyo Winpad A15 tablet
  ASoC: Intel: bytcr_rt5640: Add quirk for the Estar Beauty HD MID 7316R tablet
  parisc: Bump 64-bit IRQ stack size to 64 KB
  btrfs: fix error handling in commit_fs_roots
  f2fs: fix to set/clear I_LINKABLE under i_lock
  f2fs: handle unallocated section and zone on pinned/atgc
  media: uvcvideo: Allow entities with no pads
  drm/amd/display: Guard against NULL pointer deref when get_i2c_info fails
  PCI: Add a REBAR size quirk for Sapphire RX 5600 XT Pulse
  crypto: tcrypt - avoid signed overflow in byte count
  staging: most: sound: add sanity check for function argument
  Bluetooth: Fix null pointer dereference in amp_read_loc_assoc_final_data
  x86/build: Treat R_386_PLT32 relocation as R_386_PC32
  ath10k: fix wmi mgmt tx queue full due to race condition
  pktgen: fix misuse of BUG_ON() in pktgen_thread_worker()
  Bluetooth: hci_h5: Set HCI_QUIRK_SIMULTANEOUS_DISCOVERY for btrtl
  wlcore: Fix command execute failure 19 for wl12xx
  vt/consolemap: do font sum unsigned
  x86/reboot: Add Zotac ZBOX CI327 nano PCI reboot quirk
  staging: fwserial: Fix error handling in fwserial_create
  rsi: Move card interrupt handling to RX thread
  rsi: Fix TX EAPOL packet handling against iwlwifi AP
  dt-bindings: net: btusb: DT fix s/interrupt-name/interrupt-names/
  net: bridge: use switchdev for port flags set through sysfs too
  mm/hugetlb.c: fix unnecessary address expansion of pmd sharing
  net: fix up truesize of cloned skb in skb_prepare_for_shift()
  smackfs: restrict bytes count in smackfs write functions
  xfs: Fix assert failure in xfs_setattr_size()
  media: mceusb: sanity check for prescaler value
  udlfb: Fix memory leak in dlfb_usb_probe
  JFS: more checks for invalid superblock
  MIPS: VDSO: Use CLANG_FLAGS instead of filtering out '--target='
  arm64: Use correct ll/sc atomic constraints
  arm64: cmpxchg: Use "K" instead of "L" for ll/sc immediate constraint
  arm64: Avoid redundant type conversions in xchg() and cmpxchg()
  arm64 module: set plt* section addresses to 0x0
  virtio/s390: implement virtio-ccw revision 2 correctly
  drm/virtio: use kvmalloc for large allocations
  hugetlb: fix update_and_free_page contig page struct assumption
  net: usb: qmi_wwan: support ZTE P685M modem
  ANDROID: clang: update to 12.0.3
  Revert "block: split .sysfs_lock into two locks"
  Revert "block: fix race between switching elevator and removing queues"
  Revert "block: don't release queue's sysfs lock during switching elevator"
  Revert "dm: fix deadlock when swapping to encrypted device"
  Linux 4.19.178
  ARM: dts: aspeed: Add LCLK to lpc-snoop
  net: qrtr: Fix memory leak in qrtr_tun_open
  dm era: Update in-core bitset after committing the metadata
  net: icmp: pass zeroed opts from icmp{,v6}_ndo_send before sending
  ipv6: silence compilation warning for non-IPV6 builds
  ipv6: icmp6: avoid indirect call for icmpv6_send()
  xfrm: interface: use icmp_ndo_send helper
  sunvnet: use icmp_ndo_send helper
  gtp: use icmp_ndo_send helper
  icmp: allow icmpv6_ndo_send to work with CONFIG_IPV6=n
  icmp: introduce helper for nat'd source address in network device context
  dm era: only resize metadata in preresume
  dm era: Reinitialize bitset cache before digesting a new writeset
  dm era: Use correct value size in equality function of writeset tree
  dm era: Fix bitset memory leaks
  dm era: Verify the data block size hasn't changed
  dm era: Recover committed writeset after crash
  dm: fix deadlock when swapping to encrypted device
  gfs2: Don't skip dlm unlock if glock has an lvb
  sparc32: fix a user-triggerable oops in clear_user()
  f2fs: fix out-of-repair __setattr_copy()
  cpufreq: intel_pstate: Get per-CPU max freq via MSR_HWP_CAPABILITIES if available
  printk: fix deadlock when kernel panic
  gpio: pcf857x: Fix missing first interrupt
  mmc: sdhci-esdhc-imx: fix kernel panic when remove module
  module: Ignore _GLOBAL_OFFSET_TABLE_ when warning for undefined symbols
  arm64: Extend workaround for erratum 1024718 to all versions of Cortex-A55
  libnvdimm/dimm: Avoid race between probe and available_slots_show()
  hugetlb: fix copy_huge_page_from_user contig page struct assumption
  x86: fix seq_file iteration for pat/memtype.c
  seq_file: document how per-entry resources are managed.
  fs/affs: release old buffer head on error path
  mtd: spi-nor: hisi-sfc: Put child node np on error path
  watchdog: mei_wdt: request stop on unregister
  arm64: uprobe: Return EOPNOTSUPP for AARCH32 instruction probing
  floppy: reintroduce O_NDELAY fix
  x86/reboot: Force all cpus to exit VMX root if VMX is supported
  media: ipu3-cio2: Fix mbus_code processing in cio2_subdev_set_fmt()
  staging: rtl8188eu: Add Edimax EW-7811UN V2 to device table
  staging: gdm724x: Fix DMA from stack
  staging/mt7621-dma: mtk-hsdma.c->hsdma-mt7621.c
  dts64: mt7622: fix slow sd card access
  pstore: Fix typo in compression option name
  drivers/misc/vmw_vmci: restrict too big queue size in qp_host_alloc_queue
  misc: rtsx: init of rts522a add OCP power off when no card is present
  seccomp: Add missing return in non-void function
  crypto: sun4i-ss - handle BigEndian for cipher
  crypto: sun4i-ss - checking sg length is not sufficient
  crypto: arm64/sha - add missing module aliases
  btrfs: fix extent buffer leak on failure to copy root
  btrfs: fix reloc root leak with 0 ref reloc roots on recovery
  btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root
  KEYS: trusted: Fix migratable=1 failing
  tpm_tis: Clean up locality release
  tpm_tis: Fix check_locality for correct locality acquisition
  ALSA: hda/realtek: modify EAPD in the ALC886
  USB: serial: mos7720: fix error code in mos7720_write()
  USB: serial: mos7840: fix error code in mos7840_write()
  USB: serial: ftdi_sio: fix FTX sub-integer prescaler
  usb: dwc3: gadget: Fix dep->interval for fullspeed interrupt
  usb: dwc3: gadget: Fix setting of DEPCFG.bInterval_m1
  usb: musb: Fix runtime PM race in musb_queue_resume_work
  USB: serial: option: update interface mapping for ZTE P685M
  Input: i8042 - add ASUS Zenbook Flip to noselftest list
  Input: joydev - prevent potential read overflow in ioctl
  Input: xpad - add support for PowerA Enhanced Wired Controller for Xbox Series X|S
  Input: raydium_ts_i2c - do not send zero length
  HID: wacom: Ignore attempts to overwrite the touch_max value from HID
  ACPI: configfs: add missing check after configfs_register_default_group()
  ACPI: property: Fix fwnode string properties matching
  blk-settings: align max_sectors on "logical_block_size" boundary
  scsi: bnx2fc: Fix Kconfig warning & CNIC build errors
  mm/rmap: fix potential pte_unmap on an not mapped pte
  i2c: brcmstb: Fix brcmstd_send_i2c_cmd condition
  arm64: Add missing ISB after invalidating TLB in __primary_switch
  r8169: fix jumbo packet handling on RTL8168e
  mm/hugetlb: fix potential double free in hugetlb_register_node() error path
  mm/memory.c: fix potential pte_unmap_unlock pte error
  ocfs2: fix a use after free on error
  vxlan: move debug check after netdev unregister
  net/mlx4_core: Add missed mlx4_free_cmd_mailbox()
  i40e: Fix add TC filter for IPv6
  i40e: Fix VFs not created
  i40e: Fix overwriting flow control settings during driver loading
  i40e: Add zero-initialization of AQ command structures
  i40e: Fix flow for IPv6 next header (extension header)
  regmap: sdw: use _no_pm functions in regmap_read/write
  ext4: fix potential htree index checksum corruption
  drm/msm/dsi: Correct io_start for MSM8994 (20nm PHY)
  PCI: Align checking of syscall user config accessors
  VMCI: Use set_page_dirty_lock() when unregistering guest memory
  pwm: rockchip: rockchip_pwm_probe(): Remove superfluous clk_unprepare()
  misc: eeprom_93xx46: Add module alias to avoid breaking support for non device tree users
  misc: eeprom_93xx46: Fix module alias to enable module autoprobe
  sparc64: only select COMPAT_BINFMT_ELF if BINFMT_ELF is set
  Input: elo - fix an error code in elo_connect()
  perf test: Fix unaligned access in sample parsing test
  perf intel-pt: Fix missing CYC processing in PSB
  Input: sur40 - fix an error code in sur40_probe()
  spi: pxa2xx: Fix the controller numbering for Wildcat Point
  clk: qcom: gcc-msm8998: Fix Alpha PLL type for all GPLLs
  powerpc/8xx: Fix software emulation interrupt
  powerpc/pseries/dlpar: handle ibm, configure-connector delay status
  mfd: wm831x-auxadc: Prevent use after free in wm831x_auxadc_read_irq()
  spi: stm32: properly handle 0 byte transfer
  RDMA/rxe: Correct skb on loopback path
  RDMA/rxe: Fix coding error in rxe_recv.c
  perf tools: Fix DSO filtering when not finding a map for a sampled address
  tracepoint: Do not fail unregistering a probe due to memory failure
  amba: Fix resource leak for drivers without .remove
  ARM: 9046/1: decompressor: Do not clear SCTLR.nTLSMD for ARMv7+ cores
  mmc: renesas_sdhi_internal_dmac: Fix DMA buffer alignment from 8 to 128-bytes
  mmc: usdhi6rol0: Fix a resource leak in the error handling path of the probe
  powerpc/47x: Disable 256k page size
  KVM: PPC: Make the VMX instruction emulation routines static
  IB/umad: Return EPOLLERR in case of when device disassociated
  IB/umad: Return EIO in case of when device disassociated
  auxdisplay: ht16k33: Fix refresh rate handling
  isofs: release buffer head before return
  regulator: s5m8767: Drop regulators OF node reference
  spi: atmel: Put allocated master before return
  certs: Fix blacklist flag type confusion
  regulator: axp20x: Fix reference cout leak
  clk: sunxi-ng: h6: Fix clock divider range on some clocks
  RDMA/mlx5: Use the correct obj_id upon DEVX TIR creation
  clocksource/drivers/mxs_timer: Add missing semicolon when DEBUG is defined
  rtc: s5m: select REGMAP_I2C
  power: reset: at91-sama5d2_shdwc: fix wkupdbc mask
  of/fdt: Make sure no-map does not remove already reserved regions
  fdt: Properly handle "no-map" field in the memory region
  mfd: bd9571mwv: Use devm_mfd_add_devices()
  dmaengine: hsu: disable spurious interrupt
  dmaengine: owl-dma: Fix a resource leak in the remove function
  dmaengine: fsldma: Fix a resource leak in an error handling path of the probe function
  dmaengine: fsldma: Fix a resource leak in the remove function
  HID: core: detect and skip invalid inputs to snto32()
  clk: sunxi-ng: h6: Fix CEC clock
  spi: cadence-quadspi: Abort read if dummy cycles required are too many
  quota: Fix memory leak when handling corrupted quota file
  clk: meson: clk-pll: fix initializing the old rate (fallback) for a PLL
  capabilities: Don't allow writing ambiguous v3 file capabilities
  jffs2: fix use after free in jffs2_sum_write_data()
  fs/jfs: fix potential integer overflow on shift of a int
  ima: Free IMA measurement buffer after kexec syscall
  ima: Free IMA measurement buffer on error
  crypto: ecdh_helper - Ensure 'len >= secret.len' in decode_key()
  hwrng: timeriomem - Fix cooldown period calculation
  btrfs: clarify error returns values in __load_free_space_cache
  Drivers: hv: vmbus: Avoid use-after-free in vmbus_onoffer_rescind()
  drm/amdgpu: Prevent shift wrapping in amdgpu_read_mask()
  f2fs: fix to avoid inconsistent quota data
  ASoC: cpcap: fix microphone timeslot mask
  ata: ahci_brcm: Add back regulators management
  crypto: talitos - Work around SEC6 ERRATA (AES-CTR mode data size error)
  media: uvcvideo: Accept invalid bFormatIndex and bFrameIndex values
  media: pxa_camera: declare variable when DEBUG is defined
  media: cx25821: Fix a bug when reallocating some dma memory
  media: qm1d1c0042: fix error return code in qm1d1c0042_init()
  media: lmedm04: Fix misuse of comma
  drm/amd/display: Fix 10/12 bpc setup in DCE output bit depth reduction.
  crypto: bcm - Rename struct device_private to bcm_device_private
  ASoC: cs42l56: fix up error handling in probe
  media: tm6000: Fix memleak in tm6000_start_stream
  media: media/pci: Fix memleak in empress_init
  media: em28xx: Fix use-after-free in em28xx_alloc_urbs
  media: vsp1: Fix an error handling path in the probe function
  media: camss: missing error code in msm_video_register()
  media: i2c: ov5670: Fix PIXEL_RATE minimum value
  MIPS: lantiq: Explicitly compare LTQ_EBU_PCC_ISTAT against 0
  MIPS: c-r4k: Fix section mismatch for loongson2_sc_init
  drm/amdgpu: Fix macro name _AMDGPU_TRACE_H_ in preprocessor if condition
  crypto: sun4i-ss - fix kmap usage
  gma500: clean up error handling in init
  drm/gma500: Fix error return code in psb_driver_load()
  fbdev: aty: SPARC64 requires FB_ATY_CT
  net: mvneta: Remove per-cpu queue mapping for Armada 3700
  net: amd-xgbe: Fix network fluctuations when using 1G BELFUSE SFP
  net: amd-xgbe: Reset link when the link never comes back
  net: amd-xgbe: Fix NETDEV WATCHDOG transmit queue timeout warning
  net: amd-xgbe: Reset the PHY rx data path when mailbox command timeout
  ibmvnic: skip send_request_unmap for timeout reset
  ibmvnic: add memory barrier to protect long term buffer
  b43: N-PHY: Fix the update of coef for the PHY revision >= 3case
  cxgb4/chtls/cxgbit: Keeping the max ofld immediate data size same in cxgb4 and ulds
  tcp: fix SO_RCVLOWAT related hangs under mem pressure
  bpf: Fix bpf_fib_lookup helper MTU check for SKB ctx
  mac80211: fix potential overflow when multiplying to u32 integers
  xen/netback: fix spurious event detection for common event case
  bnxt_en: reverse order of TX disable and carrier off
  ibmvnic: Set to CLOSED state even on error
  ath9k: fix data bus crash when setting nf_override via debugfs
  bpf_lru_list: Read double-checked variable once without lock
  soc: aspeed: snoop: Add clock control logic
  ARM: s3c: fix fiq for clang IAS
  arm64: dts: msm8916: Fix reserved and rfsa nodes unit address
  ARM: dts: armada388-helios4: assign pinctrl to each fan
  ARM: dts: armada388-helios4: assign pinctrl to LEDs
  staging: rtl8723bs: wifi_regd.c: Fix incorrect number of regulatory rules
  usb: dwc2: Make "trimming xfer length" a debug message
  usb: dwc2: Abort transaction after errors with unknown reason
  usb: dwc2: Do not update data length if it is 0 on inbound transfers
  ARM: dts: Configure missing thermal interrupt for 4430
  memory: ti-aemif: Drop child node when jumping out loop
  Bluetooth: Put HCI device if inquiry procedure interrupts
  Bluetooth: drop HCI device reference before return
  usb: gadget: u_audio: Free requests only after callback
  ACPICA: Fix exception code class checks
  cpufreq: brcmstb-avs-cpufreq: Fix resource leaks in ->remove()
  cpufreq: brcmstb-avs-cpufreq: Free resources in error path
  arm64: dts: allwinner: A64: Limit MMC2 bus frequency to 150 MHz
  arm64: dts: allwinner: Drop non-removable from SoPine/LTS SD card
  arm64: dts: allwinner: A64: properly connect USB PHY to port 0
  bpf: Avoid warning when re-casting __bpf_call_base into __bpf_call_base_args
  arm64: dts: exynos: correct PMIC interrupt trigger level on Espresso
  arm64: dts: exynos: correct PMIC interrupt trigger level on TM2
  ARM: dts: exynos: correct PMIC interrupt trigger level on Odroid XU3 family
  ARM: dts: exynos: correct PMIC interrupt trigger level on Arndale Octa
  ARM: dts: exynos: correct PMIC interrupt trigger level on Spring
  ARM: dts: exynos: correct PMIC interrupt trigger level on Rinato
  ARM: dts: exynos: correct PMIC interrupt trigger level on Monk
  ARM: dts: exynos: correct PMIC interrupt trigger level on Artik 5
  Bluetooth: Fix initializing response id after clearing struct
  Bluetooth: btqcomsmd: Fix a resource leak in error handling paths in the probe function
  ath10k: Fix error handling in case of CE pipe init failure
  random: fix the RNDRESEEDCRNG ioctl
  MIPS: vmlinux.lds.S: add missing PAGE_ALIGNED_DATA() section
  ALSA: usb-audio: Fix PCM buffer allocation in non-vmalloc mode
  bfq: Avoid false bfq queue merging
  PCI: qcom: Use PHY_REFCLK_USE_PAD only for ipq8064
  kdb: Make memory allocations more robust
  vmlinux.lds.h: add DWARF v5 sections
  locking/static_key: Fix false positive warnings on concurrent dec/inc
  jump_label/lockdep: Assert we hold the hotplug lock for _cpuslocked() operations
  scripts/recordmcount.pl: support big endian for ARCH sh
  cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath.
  NET: usb: qmi_wwan: Adding support for Cinterion MV31
  block: don't release queue's sysfs lock during switching elevator
  block: fix race between switching elevator and removing queues
  block: split .sysfs_lock into two locks
  block: add helper for checking if queue is registered
  scripts: set proper OpenSSL include dir also for sign-file
  scripts: use pkg-config to locate libcrypto
  arm64: tegra: Add power-domain for Tegra210 HDA
  ntfs: check for valid standard information attribute
  usb: quirks: add quirk to start video capture on ELMO L-12F document camera reliable
  USB: quirks: sort quirk entries
  HID: make arrays usage and value to be the same
  ANDROID: syscalls/x86: use a weak function for IA32 compat syscalls
  ANDROID: Adding kprobes build configs for Cuttlefish

Change-Id: Ibe55302772a7f7de016842280a9997c992262ea8
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>

Conflicts:
	arch/arm64/kernel/cpufeature.c
	drivers/block/zram/zram_drv.c
	drivers/iio/adc/qcom-spmi-vadc.c
	drivers/md/dm-verity-fec.c
	drivers/usb/gadget/configfs.c
	net/ipv4/tcp_ipv4.c
	net/ipv6/tcp_ipv6.c
	net/qrtr/qrtr.c
2022-02-26 15:09:41 +05:30

2015 lines
55 KiB
C

/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/bitrev.h>
#include <linux/ratelimit.h>
#include <linux/usb.h>
#include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include "usbaudio.h"
#include "card.h"
#include "quirks.h"
#include "debug.h"
#include "endpoint.h"
#include "helper.h"
#include "pcm.h"
#include "clock.h"
#include "power.h"
#define SUBSTREAM_FLAG_DATA_EP_STARTED 0
#define SUBSTREAM_FLAG_SYNC_EP_STARTED 1
#define MAX_SETALT_TIMEOUT_MS 1000
/* return the estimated delay based on USB frame counters */
snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
unsigned int rate)
{
int current_frame_number;
int frame_diff;
int est_delay;
if (!subs->last_delay)
return 0; /* short path */
current_frame_number = usb_get_current_frame_number(subs->dev);
/*
* HCD implementations use different widths, use lower 8 bits.
* The delay will be managed up to 256ms, which is more than
* enough
*/
frame_diff = (current_frame_number - subs->last_frame_number) & 0xff;
/* Approximation based on number of samples per USB frame (ms),
some truncation for 44.1 but the estimate is good enough */
est_delay = frame_diff * rate / 1000;
if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK)
est_delay = subs->last_delay - est_delay;
else
est_delay = subs->last_delay + est_delay;
if (est_delay < 0)
est_delay = 0;
return est_delay;
}
/*
* return the current pcm pointer. just based on the hwptr_done value.
*/
static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
{
struct snd_usb_substream *subs = substream->runtime->private_data;
unsigned int hwptr_done;
if (atomic_read(&subs->stream->chip->shutdown))
return SNDRV_PCM_POS_XRUN;
spin_lock(&subs->lock);
hwptr_done = subs->hwptr_done;
substream->runtime->delay = snd_usb_pcm_delay(subs,
substream->runtime->rate);
spin_unlock(&subs->lock);
return hwptr_done / (substream->runtime->frame_bits >> 3);
}
/*
* find a matching audio format
*/
static struct audioformat *find_format(struct snd_usb_substream *subs)
{
struct audioformat *fp;
struct audioformat *found = NULL;
int cur_attr = 0, attr;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (!(fp->formats & pcm_format_to_bits(subs->pcm_format)))
continue;
if (fp->channels != subs->channels)
continue;
if (subs->cur_rate < fp->rate_min ||
subs->cur_rate > fp->rate_max)
continue;
if (! (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)) {
unsigned int i;
for (i = 0; i < fp->nr_rates; i++)
if (fp->rate_table[i] == subs->cur_rate)
break;
if (i >= fp->nr_rates)
continue;
}
attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
if (! found) {
found = fp;
cur_attr = attr;
continue;
}
/* avoid async out and adaptive in if the other method
* supports the same format.
* this is a workaround for the case like
* M-audio audiophile USB.
*/
if (attr != cur_attr) {
if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE))
continue;
if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
found = fp;
cur_attr = attr;
continue;
}
}
/* find the format with the largest max. packet size */
if (fp->maxpacksize > found->maxpacksize) {
found = fp;
cur_attr = attr;
}
}
return found;
}
/*
* find a matching audio format as well as non-zero service interval
*/
static struct audioformat *find_format_and_si(struct snd_usb_substream *subs,
unsigned int datainterval)
{
unsigned int i;
struct audioformat *fp;
struct audioformat *found = NULL;
int cur_attr = 0, attr;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (datainterval != fp->datainterval)
continue;
if (!(fp->formats & pcm_format_to_bits(subs->pcm_format)))
continue;
if (fp->channels != subs->channels)
continue;
if (subs->cur_rate < fp->rate_min ||
subs->cur_rate > fp->rate_max)
continue;
if (!(fp->rates & SNDRV_PCM_RATE_CONTINUOUS)) {
for (i = 0; i < fp->nr_rates; i++)
if (fp->rate_table[i] == subs->cur_rate)
break;
if (i >= fp->nr_rates)
continue;
}
attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
if (!found) {
found = fp;
cur_attr = attr;
continue;
}
/* avoid async out and adaptive in if the other method
* supports the same format.
* this is a workaround for the case like
* M-audio audiophile USB.
*/
if (attr != cur_attr) {
if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE))
continue;
if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
found = fp;
cur_attr = attr;
continue;
}
}
/* find the format with the largest max. packet size */
if (fp->maxpacksize > found->maxpacksize) {
found = fp;
cur_attr = attr;
}
}
return found;
}
static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts,
struct audioformat *fmt)
{
struct usb_device *dev = chip->dev;
unsigned int ep;
unsigned char data[1];
int err;
if (get_iface_desc(alts)->bNumEndpoints < 1)
return -EINVAL;
ep = get_endpoint(alts, 0)->bEndpointAddress;
data[0] = 1;
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep,
data, sizeof(data));
if (err < 0) {
usb_audio_err(chip, "%d:%d: cannot set enable PITCH\n",
iface, ep);
return err;
}
return 0;
}
static int init_pitch_v2(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts,
struct audioformat *fmt)
{
struct usb_device *dev = chip->dev;
unsigned char data[1];
int err;
data[0] = 1;
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
UAC2_EP_CS_PITCH << 8, 0,
data, sizeof(data));
if (err < 0) {
usb_audio_err(chip, "%d:%d: cannot set enable PITCH (v2)\n",
iface, fmt->altsetting);
return err;
}
return 0;
}
/*
* initialize the pitch control and sample rate
*/
int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
struct usb_host_interface *alts,
struct audioformat *fmt)
{
/* if endpoint doesn't have pitch control, bail out */
if (!(fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL))
return 0;
switch (fmt->protocol) {
case UAC_VERSION_1:
default:
return init_pitch_v1(chip, iface, alts, fmt);
case UAC_VERSION_2:
return init_pitch_v2(chip, iface, alts, fmt);
}
}
static int start_endpoints(struct snd_usb_substream *subs)
{
int err;
if (!subs->data_endpoint)
return -EINVAL;
if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
struct snd_usb_endpoint *ep = subs->data_endpoint;
dev_dbg(&subs->dev->dev, "Starting data EP @%p\n", ep);
ep->data_subs = subs;
err = snd_usb_endpoint_start(ep);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags);
return err;
}
}
if (subs->sync_endpoint &&
!test_and_set_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags)) {
struct snd_usb_endpoint *ep = subs->sync_endpoint;
if (subs->data_endpoint->iface != subs->sync_endpoint->iface ||
subs->data_endpoint->altsetting != subs->sync_endpoint->altsetting) {
err = usb_set_interface(subs->dev,
subs->sync_endpoint->iface,
subs->sync_endpoint->altsetting);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
dev_err(&subs->dev->dev,
"%d:%d: cannot set interface (%d)\n",
subs->sync_endpoint->iface,
subs->sync_endpoint->altsetting, err);
return -EIO;
}
}
dev_dbg(&subs->dev->dev, "Starting sync EP @%p\n", ep);
ep->sync_slave = subs->data_endpoint;
err = snd_usb_endpoint_start(ep);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags);
return err;
}
}
return 0;
}
static void stop_endpoints(struct snd_usb_substream *subs, bool wait)
{
if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags))
snd_usb_endpoint_stop(subs->sync_endpoint);
if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags))
snd_usb_endpoint_stop(subs->data_endpoint);
if (wait) {
snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
}
}
static int search_roland_implicit_fb(struct usb_device *dev, int ifnum,
unsigned int altsetting,
struct usb_host_interface **alts,
unsigned int *ep)
{
struct usb_interface *iface;
struct usb_interface_descriptor *altsd;
struct usb_endpoint_descriptor *epd;
iface = usb_ifnum_to_if(dev, ifnum);
if (!iface || iface->num_altsetting < altsetting + 1)
return -ENOENT;
*alts = &iface->altsetting[altsetting];
altsd = get_iface_desc(*alts);
if (altsd->bAlternateSetting != altsetting ||
altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC ||
(altsd->bInterfaceSubClass != 2 &&
altsd->bInterfaceProtocol != 2 ) ||
altsd->bNumEndpoints < 1)
return -ENOENT;
epd = get_endpoint(*alts, 0);
if (!usb_endpoint_is_isoc_in(epd) ||
(epd->bmAttributes & USB_ENDPOINT_USAGE_MASK) !=
USB_ENDPOINT_USAGE_IMPLICIT_FB)
return -ENOENT;
*ep = epd->bEndpointAddress;
return 0;
}
/* Setup an implicit feedback endpoint from a quirk. Returns 0 if no quirk
* applies. Returns 1 if a quirk was found.
*/
static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
struct usb_device *dev,
struct usb_interface_descriptor *altsd,
unsigned int attr)
{
struct usb_host_interface *alts;
struct usb_interface *iface;
unsigned int ep;
unsigned int ifnum;
/* Implicit feedback sync EPs consumers are always playback EPs */
if (subs->direction != SNDRV_PCM_STREAM_PLAYBACK)
return 0;
switch (subs->stream->chip->usb_id) {
case USB_ID(0x0763, 0x2030): /* M-Audio Fast Track C400 */
case USB_ID(0x0763, 0x2031): /* M-Audio Fast Track C600 */
case USB_ID(0x22f0, 0x0006): /* Allen&Heath Qu-16 */
ep = 0x81;
ifnum = 3;
goto add_sync_ep_from_ifnum;
case USB_ID(0x0763, 0x2080): /* M-Audio FastTrack Ultra */
case USB_ID(0x0763, 0x2081):
ep = 0x81;
ifnum = 2;
goto add_sync_ep_from_ifnum;
case USB_ID(0x2466, 0x8003): /* Fractal Audio Axe-Fx II */
case USB_ID(0x0499, 0x172a): /* Yamaha MODX */
ep = 0x86;
ifnum = 2;
goto add_sync_ep_from_ifnum;
case USB_ID(0x2466, 0x8010): /* Fractal Audio Axe-Fx III */
ep = 0x81;
ifnum = 2;
goto add_sync_ep_from_ifnum;
case USB_ID(0x1686, 0xf029): /* Zoom UAC-2 */
ep = 0x82;
ifnum = 2;
goto add_sync_ep_from_ifnum;
case USB_ID(0x1397, 0x0001): /* Behringer UFX1604 */
case USB_ID(0x1397, 0x0002): /* Behringer UFX1204 */
ep = 0x81;
ifnum = 1;
goto add_sync_ep_from_ifnum;
case USB_ID(0x0582, 0x01d8): /* BOSS Katana */
/* BOSS Katana amplifiers do not need quirks */
return 0;
}
if (attr == USB_ENDPOINT_SYNC_ASYNC &&
altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
altsd->bInterfaceProtocol == 2 &&
altsd->bNumEndpoints == 1 &&
USB_ID_VENDOR(subs->stream->chip->usb_id) == 0x0582 /* Roland */ &&
search_roland_implicit_fb(dev, altsd->bInterfaceNumber + 1,
altsd->bAlternateSetting,
&alts, &ep) >= 0) {
goto add_sync_ep;
}
/* No quirk */
return 0;
add_sync_ep_from_ifnum:
iface = usb_ifnum_to_if(dev, ifnum);
if (!iface || iface->num_altsetting < 2)
return -EINVAL;
alts = &iface->altsetting[1];
add_sync_ep:
subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip,
alts, ep, !subs->direction,
SND_USB_ENDPOINT_TYPE_DATA);
if (!subs->sync_endpoint)
return -EINVAL;
subs->data_endpoint->sync_master = subs->sync_endpoint;
return 1;
}
static int set_sync_endpoint(struct snd_usb_substream *subs,
struct audioformat *fmt,
struct usb_device *dev,
struct usb_host_interface *alts,
struct usb_interface_descriptor *altsd)
{
int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
unsigned int ep, attr;
bool implicit_fb;
int err;
/* we need a sync pipe in async OUT or adaptive IN mode */
/* check the number of EP, since some devices have broken
* descriptors which fool us. if it has only one EP,
* assume it as adaptive-out or sync-in.
*/
attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
if ((is_playback && (attr != USB_ENDPOINT_SYNC_ASYNC)) ||
(!is_playback && (attr != USB_ENDPOINT_SYNC_ADAPTIVE))) {
/*
* In these modes the notion of sync_endpoint is irrelevant.
* Reset pointers to avoid using stale data from previously
* used settings, e.g. when configuration and endpoints were
* changed
*/
subs->sync_endpoint = NULL;
subs->data_endpoint->sync_master = NULL;
}
err = set_sync_ep_implicit_fb_quirk(subs, dev, altsd, attr);
if (err < 0)
return err;
/* endpoint set by quirk */
if (err > 0)
return 0;
if (altsd->bNumEndpoints < 2)
return 0;
if ((is_playback && (attr == USB_ENDPOINT_SYNC_SYNC ||
attr == USB_ENDPOINT_SYNC_ADAPTIVE)) ||
(!is_playback && attr != USB_ENDPOINT_SYNC_ADAPTIVE))
return 0;
/*
* In case of illegal SYNC_NONE for OUT endpoint, we keep going to see
* if we don't find a sync endpoint, as on M-Audio Transit. In case of
* error fall back to SYNC mode and don't create sync endpoint
*/
/* check sync-pipe endpoint */
/* ... and check descriptor size before accessing bSynchAddress
because there is a version of the SB Audigy 2 NX firmware lacking
the audio fields in the endpoint descriptors */
if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC ||
(get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
get_endpoint(alts, 1)->bSynchAddress != 0)) {
dev_err(&dev->dev,
"%d:%d : invalid sync pipe. bmAttributes %02x, bLength %d, bSynchAddress %02x\n",
fmt->iface, fmt->altsetting,
get_endpoint(alts, 1)->bmAttributes,
get_endpoint(alts, 1)->bLength,
get_endpoint(alts, 1)->bSynchAddress);
if (is_playback && attr == USB_ENDPOINT_SYNC_NONE)
return 0;
return -EINVAL;
}
ep = get_endpoint(alts, 1)->bEndpointAddress;
if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
get_endpoint(alts, 0)->bSynchAddress != 0 &&
((is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) ||
(!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) {
dev_err(&dev->dev,
"%d:%d : invalid sync pipe. is_playback %d, ep %02x, bSynchAddress %02x\n",
fmt->iface, fmt->altsetting,
is_playback, ep, get_endpoint(alts, 0)->bSynchAddress);
if (is_playback && attr == USB_ENDPOINT_SYNC_NONE)
return 0;
return -EINVAL;
}
implicit_fb = (get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_USAGE_MASK)
== USB_ENDPOINT_USAGE_IMPLICIT_FB;
subs->sync_endpoint = snd_usb_add_endpoint(subs->stream->chip,
alts, ep, !subs->direction,
implicit_fb ?
SND_USB_ENDPOINT_TYPE_DATA :
SND_USB_ENDPOINT_TYPE_SYNC);
if (!subs->sync_endpoint) {
if (is_playback && attr == USB_ENDPOINT_SYNC_NONE)
return 0;
return -EINVAL;
}
subs->data_endpoint->sync_master = subs->sync_endpoint;
return 0;
}
/*
* find a matching format and set up the interface
*/
static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
{
struct usb_device *dev = subs->dev;
struct usb_host_interface *alts;
struct usb_interface_descriptor *altsd;
struct usb_interface *iface;
int err;
iface = usb_ifnum_to_if(dev, fmt->iface);
if (WARN_ON(!iface))
return -EINVAL;
alts = usb_altnum_to_altsetting(iface, fmt->altsetting);
if (WARN_ON(!alts))
return -EINVAL;
altsd = get_iface_desc(alts);
if (fmt == subs->cur_audiofmt && !subs->need_setup_fmt)
return 0;
/* close the old interface */
if (subs->interface >= 0 && (subs->interface != fmt->iface || subs->need_setup_fmt)) {
if (!subs->stream->chip->keep_iface) {
err = usb_set_interface_timeout(subs->dev,
subs->interface, 0, MAX_SETALT_TIMEOUT_MS);
if (err < 0) {
dev_err(&dev->dev,
"%d:%d: return to setting 0 failed (%d)\n",
fmt->iface, fmt->altsetting, err);
return -EIO;
}
}
subs->interface = -1;
subs->altset_idx = 0;
}
if (subs->need_setup_fmt)
subs->need_setup_fmt = false;
/* set interface */
if (iface->cur_altsetting != alts) {
err = snd_usb_select_mode_quirk(subs, fmt);
if (err < 0)
return -EIO;
err = usb_set_interface_timeout(dev, fmt->iface,
fmt->altsetting, MAX_SETALT_TIMEOUT_MS);
if (err < 0) {
dev_err(&dev->dev,
"%d:%d: usb_set_interface failed (%d)\n",
fmt->iface, fmt->altsetting, err);
return -EIO;
}
dev_dbg(&dev->dev, "setting usb interface %d:%d\n",
fmt->iface, fmt->altsetting);
snd_usb_set_interface_quirk(dev);
}
subs->interface = fmt->iface;
subs->altset_idx = fmt->altset_idx;
subs->data_endpoint = snd_usb_add_endpoint(subs->stream->chip,
alts, fmt->endpoint, subs->direction,
SND_USB_ENDPOINT_TYPE_DATA);
if (!subs->data_endpoint)
return -EINVAL;
err = set_sync_endpoint(subs, fmt, dev, alts, altsd);
if (err < 0)
return err;
err = snd_usb_init_pitch(subs->stream->chip, fmt->iface, alts, fmt);
if (err < 0)
return err;
subs->cur_audiofmt = fmt;
snd_usb_set_format_quirk(subs, fmt);
return 0;
}
static int snd_usb_pcm_change_state(struct snd_usb_substream *subs, int state);
/**
* snd_usb_enable_audio_stream - Enable/disable the specified usb substream.
* @subs: pointer to the usb substream.
* @datainterval: data packet interval.
* @enable: if true, enable the usb substream. Else disable.
*/
int snd_usb_enable_audio_stream(struct snd_usb_substream *subs,
int datainterval, bool enable)
{
struct audioformat *fmt;
struct usb_host_interface *alts;
struct usb_interface *iface;
int ret;
if (!subs || !subs->stream)
return -EINVAL;
if (!enable) {
if (subs->interface >= 0) {
usb_set_interface_timeout(subs->dev, subs->interface, 0,
MAX_SETALT_TIMEOUT_MS);
subs->altset_idx = 0;
subs->interface = -1;
subs->cur_audiofmt = NULL;
}
snd_usb_autosuspend(subs->stream->chip);
return 0;
}
snd_usb_autoresume(subs->stream->chip);
ret = snd_usb_pcm_change_state(subs, UAC3_PD_STATE_D0);
if (ret < 0)
return ret;
if (datainterval != -EINVAL)
fmt = find_format_and_si(subs, datainterval);
else
fmt = find_format(subs);
if (!fmt) {
dev_err(&subs->dev->dev,
"cannot set format: format = %#x, rate = %d, channels = %d\n",
subs->pcm_format, subs->cur_rate, subs->channels);
return -EINVAL;
}
subs->altset_idx = 0;
subs->interface = -1;
if (!subs->stream->chip)
return -EINVAL;
if (atomic_read(&subs->stream->chip->shutdown)) {
ret = -ENODEV;
} else {
ret = set_format(subs, fmt);
if (ret < 0)
return ret;
if (!subs->cur_audiofmt)
return -EINVAL;
iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface);
if (!iface) {
dev_err(&subs->dev->dev, "Could not get iface %d\n",
subs->cur_audiofmt->iface);
return -ENODEV;
}
alts = &iface->altsetting[subs->cur_audiofmt->altset_idx];
ret = snd_usb_init_sample_rate(subs->stream->chip,
subs->cur_audiofmt->iface,
alts,
subs->cur_audiofmt,
subs->cur_rate);
if (ret < 0) {
dev_err(&subs->dev->dev, "failed to set rate %d\n",
subs->cur_rate);
return ret;
}
}
subs->interface = fmt->iface;
subs->altset_idx = fmt->altset_idx;
return 0;
}
EXPORT_SYMBOL_GPL(snd_usb_enable_audio_stream);
/*
* Return the score of matching two audioformats.
* Veto the audioformat if:
* - It has no channels for some reason.
* - Requested PCM format is not supported.
* - Requested sample rate is not supported.
*/
static int match_endpoint_audioformats(struct snd_usb_substream *subs,
struct audioformat *fp,
struct audioformat *match, int rate,
snd_pcm_format_t pcm_format)
{
int i;
int score = 0;
if (fp->channels < 1) {
dev_dbg(&subs->dev->dev,
"%s: (fmt @%p) no channels\n", __func__, fp);
return 0;
}
if (!(fp->formats & pcm_format_to_bits(pcm_format))) {
dev_dbg(&subs->dev->dev,
"%s: (fmt @%p) no match for format %d\n", __func__,
fp, pcm_format);
return 0;
}
for (i = 0; i < fp->nr_rates; i++) {
if (fp->rate_table[i] == rate) {
score++;
break;
}
}
if (!score) {
dev_dbg(&subs->dev->dev,
"%s: (fmt @%p) no match for rate %d\n", __func__,
fp, rate);
return 0;
}
if (fp->channels == match->channels)
score++;
dev_dbg(&subs->dev->dev,
"%s: (fmt @%p) score %d\n", __func__, fp, score);
return score;
}
/*
* Configure the sync ep using the rate and pcm format of the data ep.
*/
static int configure_sync_endpoint(struct snd_usb_substream *subs)
{
int ret;
struct audioformat *fp;
struct audioformat *sync_fp = NULL;
int cur_score = 0;
int sync_period_bytes = subs->period_bytes;
struct snd_usb_substream *sync_subs =
&subs->stream->substream[subs->direction ^ 1];
if (subs->sync_endpoint->type != SND_USB_ENDPOINT_TYPE_DATA ||
!subs->stream)
return snd_usb_endpoint_set_params(subs->sync_endpoint,
subs->pcm_format,
subs->channels,
subs->period_bytes,
0, 0,
subs->cur_rate,
subs->cur_audiofmt,
NULL);
/* Try to find the best matching audioformat. */
list_for_each_entry(fp, &sync_subs->fmt_list, list) {
int score = match_endpoint_audioformats(subs,
fp, subs->cur_audiofmt,
subs->cur_rate, subs->pcm_format);
if (score > cur_score) {
sync_fp = fp;
cur_score = score;
}
}
if (unlikely(sync_fp == NULL)) {
dev_err(&subs->dev->dev,
"%s: no valid audioformat for sync ep %x found\n",
__func__, sync_subs->ep_num);
return -EINVAL;
}
/*
* Recalculate the period bytes if channel number differ between
* data and sync ep audioformat.
*/
if (sync_fp->channels != subs->channels) {
sync_period_bytes = (subs->period_bytes / subs->channels) *
sync_fp->channels;
dev_dbg(&subs->dev->dev,
"%s: adjusted sync ep period bytes (%d -> %d)\n",
__func__, subs->period_bytes, sync_period_bytes);
}
ret = snd_usb_endpoint_set_params(subs->sync_endpoint,
subs->pcm_format,
sync_fp->channels,
sync_period_bytes,
0, 0,
subs->cur_rate,
sync_fp,
NULL);
return ret;
}
/*
* configure endpoint params
*
* called during initial setup and upon resume
*/
static int configure_endpoint(struct snd_usb_substream *subs)
{
int ret;
/* format changed */
stop_endpoints(subs, true);
ret = snd_usb_endpoint_set_params(subs->data_endpoint,
subs->pcm_format,
subs->channels,
subs->period_bytes,
subs->period_frames,
subs->buffer_periods,
subs->cur_rate,
subs->cur_audiofmt,
subs->sync_endpoint);
if (ret < 0)
return ret;
if (subs->sync_endpoint)
ret = configure_sync_endpoint(subs);
return ret;
}
static int snd_usb_pcm_change_state(struct snd_usb_substream *subs, int state)
{
int ret;
if (!subs->str_pd)
return 0;
ret = snd_usb_power_domain_set(subs->stream->chip, subs->str_pd, state);
if (ret < 0) {
dev_err(&subs->dev->dev,
"Cannot change Power Domain ID: %d to state: %d. Err: %d\n",
subs->str_pd->pd_id, state, ret);
return ret;
}
return 0;
}
int snd_usb_pcm_suspend(struct snd_usb_stream *as)
{
int ret;
ret = snd_usb_pcm_change_state(&as->substream[0], UAC3_PD_STATE_D2);
if (ret < 0)
return ret;
ret = snd_usb_pcm_change_state(&as->substream[1], UAC3_PD_STATE_D2);
if (ret < 0)
return ret;
return 0;
}
int snd_usb_pcm_resume(struct snd_usb_stream *as)
{
int ret;
ret = snd_usb_pcm_change_state(&as->substream[0], UAC3_PD_STATE_D1);
if (ret < 0)
return ret;
ret = snd_usb_pcm_change_state(&as->substream[1], UAC3_PD_STATE_D1);
if (ret < 0)
return ret;
return 0;
}
/*
* hw_params callback
*
* allocate a buffer and set the given audio format.
*
* so far we use a physically linear buffer although packetize transfer
* doesn't need a continuous area.
* if sg buffer is supported on the later version of alsa, we'll follow
* that.
*/
static int snd_usb_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *hw_params)
{
struct snd_usb_substream *subs = substream->runtime->private_data;
struct audioformat *fmt;
int ret;
if (snd_usb_use_vmalloc)
ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
params_buffer_bytes(hw_params));
else
ret = snd_pcm_lib_malloc_pages(substream,
params_buffer_bytes(hw_params));
if (ret < 0)
return ret;
subs->pcm_format = params_format(hw_params);
subs->period_bytes = params_period_bytes(hw_params);
subs->period_frames = params_period_size(hw_params);
subs->buffer_periods = params_periods(hw_params);
subs->channels = params_channels(hw_params);
subs->cur_rate = params_rate(hw_params);
fmt = find_format(subs);
if (!fmt) {
dev_dbg(&subs->dev->dev,
"cannot set format: format = %#x, rate = %d, channels = %d\n",
subs->pcm_format, subs->cur_rate, subs->channels);
return -EINVAL;
}
ret = snd_usb_lock_shutdown(subs->stream->chip);
if (ret < 0)
return ret;
ret = snd_usb_pcm_change_state(subs, UAC3_PD_STATE_D0);
if (ret < 0)
goto unlock;
ret = set_format(subs, fmt);
if (ret < 0)
goto unlock;
subs->interface = fmt->iface;
subs->altset_idx = fmt->altset_idx;
subs->need_setup_ep = true;
unlock:
snd_usb_unlock_shutdown(subs->stream->chip);
return ret;
}
/*
* hw_free callback
*
* reset the audio format and release the buffer
*/
static int snd_usb_hw_free(struct snd_pcm_substream *substream)
{
struct snd_usb_substream *subs = substream->runtime->private_data;
subs->cur_audiofmt = NULL;
subs->cur_rate = 0;
subs->period_bytes = 0;
if (!snd_usb_lock_shutdown(subs->stream->chip)) {
stop_endpoints(subs, true);
snd_usb_endpoint_deactivate(subs->sync_endpoint);
snd_usb_endpoint_deactivate(subs->data_endpoint);
snd_usb_unlock_shutdown(subs->stream->chip);
}
if (snd_usb_use_vmalloc)
return snd_pcm_lib_free_vmalloc_buffer(substream);
else
return snd_pcm_lib_free_pages(substream);
}
/*
* prepare callback
*
* only a few subtle things...
*/
static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_usb_substream *subs = runtime->private_data;
struct usb_host_interface *alts;
struct usb_interface *iface;
int ret;
if (! subs->cur_audiofmt) {
dev_err(&subs->dev->dev, "no format is specified!\n");
return -ENXIO;
}
ret = snd_usb_lock_shutdown(subs->stream->chip);
if (ret < 0)
return ret;
if (snd_BUG_ON(!subs->data_endpoint)) {
ret = -EIO;
goto unlock;
}
snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
ret = snd_usb_pcm_change_state(subs, UAC3_PD_STATE_D0);
if (ret < 0)
goto unlock;
ret = set_format(subs, subs->cur_audiofmt);
if (ret < 0)
goto unlock;
if (subs->need_setup_ep) {
iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface);
alts = &iface->altsetting[subs->cur_audiofmt->altset_idx];
ret = snd_usb_init_sample_rate(subs->stream->chip,
subs->cur_audiofmt->iface,
alts,
subs->cur_audiofmt,
subs->cur_rate);
if (ret < 0)
goto unlock;
ret = configure_endpoint(subs);
if (ret < 0)
goto unlock;
subs->need_setup_ep = false;
}
/* some unit conversions in runtime */
subs->data_endpoint->maxframesize =
bytes_to_frames(runtime, subs->data_endpoint->maxpacksize);
subs->data_endpoint->curframesize =
bytes_to_frames(runtime, subs->data_endpoint->curpacksize);
/* reset the pointer */
subs->hwptr_done = 0;
subs->transfer_done = 0;
subs->last_delay = 0;
subs->last_frame_number = 0;
runtime->delay = 0;
/* for playback, submit the URBs now; otherwise, the first hwptr_done
* updates for all URBs would happen at the same time when starting */
if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK)
ret = start_endpoints(subs);
unlock:
snd_usb_unlock_shutdown(subs->stream->chip);
return ret;
}
static const struct snd_pcm_hardware snd_usb_hardware =
{
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_BATCH |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_PAUSE,
.buffer_bytes_max = 1024 * 1024,
.period_bytes_min = 64,
.period_bytes_max = 512 * 1024,
.periods_min = 2,
.periods_max = 1024,
};
static int hw_check_valid_format(struct snd_usb_substream *subs,
struct snd_pcm_hw_params *params,
struct audioformat *fp)
{
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
struct snd_interval *pt = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
struct snd_mask check_fmts;
unsigned int ptime;
/* check the format */
snd_mask_none(&check_fmts);
check_fmts.bits[0] = (u32)fp->formats;
check_fmts.bits[1] = (u32)(fp->formats >> 32);
snd_mask_intersect(&check_fmts, fmts);
if (snd_mask_empty(&check_fmts)) {
hwc_debug(" > check: no supported format %d\n", fp->format);
return 0;
}
/* check the channels */
if (fp->channels < ct->min || fp->channels > ct->max) {
hwc_debug(" > check: no valid channels %d (%d/%d)\n", fp->channels, ct->min, ct->max);
return 0;
}
/* check the rate is within the range */
if (fp->rate_min > it->max || (fp->rate_min == it->max && it->openmax)) {
hwc_debug(" > check: rate_min %d > max %d\n", fp->rate_min, it->max);
return 0;
}
if (fp->rate_max < it->min || (fp->rate_max == it->min && it->openmin)) {
hwc_debug(" > check: rate_max %d < min %d\n", fp->rate_max, it->min);
return 0;
}
/* check whether the period time is >= the data packet interval */
if (subs->speed != USB_SPEED_FULL) {
ptime = 125 * (1 << fp->datainterval);
if (ptime > pt->max || (ptime == pt->max && pt->openmax)) {
hwc_debug(" > check: ptime %u > max %u\n", ptime, pt->max);
return 0;
}
}
return 1;
}
static int hw_rule_rate(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
unsigned int rmin, rmax;
int changed;
hwc_debug("hw_rule_rate: (%d,%d)\n", it->min, it->max);
changed = 0;
rmin = rmax = 0;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (!hw_check_valid_format(subs, params, fp))
continue;
if (changed++) {
if (rmin > fp->rate_min)
rmin = fp->rate_min;
if (rmax < fp->rate_max)
rmax = fp->rate_max;
} else {
rmin = fp->rate_min;
rmax = fp->rate_max;
}
}
if (!changed) {
hwc_debug(" --> get empty\n");
it->empty = 1;
return -EINVAL;
}
changed = 0;
if (it->min < rmin) {
it->min = rmin;
it->openmin = 0;
changed = 1;
}
if (it->max > rmax) {
it->max = rmax;
it->openmax = 0;
changed = 1;
}
if (snd_interval_checkempty(it)) {
it->empty = 1;
return -EINVAL;
}
hwc_debug(" --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
return changed;
}
static int hw_rule_channels(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
unsigned int rmin, rmax;
int changed;
hwc_debug("hw_rule_channels: (%d,%d)\n", it->min, it->max);
changed = 0;
rmin = rmax = 0;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (!hw_check_valid_format(subs, params, fp))
continue;
if (changed++) {
if (rmin > fp->channels)
rmin = fp->channels;
if (rmax < fp->channels)
rmax = fp->channels;
} else {
rmin = fp->channels;
rmax = fp->channels;
}
}
if (!changed) {
hwc_debug(" --> get empty\n");
it->empty = 1;
return -EINVAL;
}
changed = 0;
if (it->min < rmin) {
it->min = rmin;
it->openmin = 0;
changed = 1;
}
if (it->max > rmax) {
it->max = rmax;
it->openmax = 0;
changed = 1;
}
if (snd_interval_checkempty(it)) {
it->empty = 1;
return -EINVAL;
}
hwc_debug(" --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
return changed;
}
static int hw_rule_format(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
u64 fbits;
u32 oldbits[2];
int changed;
hwc_debug("hw_rule_format: %x:%x\n", fmt->bits[0], fmt->bits[1]);
fbits = 0;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (!hw_check_valid_format(subs, params, fp))
continue;
fbits |= fp->formats;
}
oldbits[0] = fmt->bits[0];
oldbits[1] = fmt->bits[1];
fmt->bits[0] &= (u32)fbits;
fmt->bits[1] &= (u32)(fbits >> 32);
if (!fmt->bits[0] && !fmt->bits[1]) {
hwc_debug(" --> get empty\n");
return -EINVAL;
}
changed = (oldbits[0] != fmt->bits[0] || oldbits[1] != fmt->bits[1]);
hwc_debug(" --> %x:%x (changed = %d)\n", fmt->bits[0], fmt->bits[1], changed);
return changed;
}
static int hw_rule_period_time(struct snd_pcm_hw_params *params,
struct snd_pcm_hw_rule *rule)
{
struct snd_usb_substream *subs = rule->private;
struct audioformat *fp;
struct snd_interval *it;
unsigned char min_datainterval;
unsigned int pmin;
int changed;
it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
hwc_debug("hw_rule_period_time: (%u,%u)\n", it->min, it->max);
min_datainterval = 0xff;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (!hw_check_valid_format(subs, params, fp))
continue;
min_datainterval = min(min_datainterval, fp->datainterval);
}
if (min_datainterval == 0xff) {
hwc_debug(" --> get empty\n");
it->empty = 1;
return -EINVAL;
}
pmin = 125 * (1 << min_datainterval);
changed = 0;
if (it->min < pmin) {
it->min = pmin;
it->openmin = 0;
changed = 1;
}
if (snd_interval_checkempty(it)) {
it->empty = 1;
return -EINVAL;
}
hwc_debug(" --> (%u,%u) (changed = %d)\n", it->min, it->max, changed);
return changed;
}
/*
* If the device supports unusual bit rates, does the request meet these?
*/
static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
struct snd_usb_substream *subs)
{
struct audioformat *fp;
int *rate_list;
int count = 0, needs_knot = 0;
int err;
kfree(subs->rate_list.list);
subs->rate_list.list = NULL;
list_for_each_entry(fp, &subs->fmt_list, list) {
if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
return 0;
count += fp->nr_rates;
if (fp->rates & SNDRV_PCM_RATE_KNOT)
needs_knot = 1;
}
if (!needs_knot)
return 0;
subs->rate_list.list = rate_list =
kmalloc_array(count, sizeof(int), GFP_KERNEL);
if (!subs->rate_list.list)
return -ENOMEM;
subs->rate_list.count = count;
subs->rate_list.mask = 0;
count = 0;
list_for_each_entry(fp, &subs->fmt_list, list) {
int i;
for (i = 0; i < fp->nr_rates; i++)
rate_list[count++] = fp->rate_table[i];
}
err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&subs->rate_list);
if (err < 0)
return err;
return 0;
}
/*
* set up the runtime hardware information.
*/
static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs)
{
struct audioformat *fp;
unsigned int pt, ptmin;
int param_period_time_if_needed;
int err;
runtime->hw.formats = subs->formats;
runtime->hw.rate_min = 0x7fffffff;
runtime->hw.rate_max = 0;
runtime->hw.channels_min = 256;
runtime->hw.channels_max = 0;
runtime->hw.rates = 0;
ptmin = UINT_MAX;
/* check min/max rates and channels */
list_for_each_entry(fp, &subs->fmt_list, list) {
runtime->hw.rates |= fp->rates;
if (runtime->hw.rate_min > fp->rate_min)
runtime->hw.rate_min = fp->rate_min;
if (runtime->hw.rate_max < fp->rate_max)
runtime->hw.rate_max = fp->rate_max;
if (runtime->hw.channels_min > fp->channels)
runtime->hw.channels_min = fp->channels;
if (runtime->hw.channels_max < fp->channels)
runtime->hw.channels_max = fp->channels;
if (fp->fmt_type == UAC_FORMAT_TYPE_II && fp->frame_size > 0) {
/* FIXME: there might be more than one audio formats... */
runtime->hw.period_bytes_min = runtime->hw.period_bytes_max =
fp->frame_size;
}
pt = 125 * (1 << fp->datainterval);
ptmin = min(ptmin, pt);
}
param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME;
if (subs->speed == USB_SPEED_FULL)
/* full speed devices have fixed data packet interval */
ptmin = 1000;
if (ptmin == 1000)
/* if period time doesn't go below 1 ms, no rules needed */
param_period_time_if_needed = -1;
err = snd_pcm_hw_constraint_minmax(runtime,
SNDRV_PCM_HW_PARAM_PERIOD_TIME,
ptmin, UINT_MAX);
if (err < 0)
return err;
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
hw_rule_rate, subs,
SNDRV_PCM_HW_PARAM_FORMAT,
SNDRV_PCM_HW_PARAM_CHANNELS,
param_period_time_if_needed,
-1);
if (err < 0)
return err;
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
hw_rule_channels, subs,
SNDRV_PCM_HW_PARAM_FORMAT,
SNDRV_PCM_HW_PARAM_RATE,
param_period_time_if_needed,
-1);
if (err < 0)
return err;
err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
hw_rule_format, subs,
SNDRV_PCM_HW_PARAM_RATE,
SNDRV_PCM_HW_PARAM_CHANNELS,
param_period_time_if_needed,
-1);
if (err < 0)
return err;
if (param_period_time_if_needed >= 0) {
err = snd_pcm_hw_rule_add(runtime, 0,
SNDRV_PCM_HW_PARAM_PERIOD_TIME,
hw_rule_period_time, subs,
SNDRV_PCM_HW_PARAM_FORMAT,
SNDRV_PCM_HW_PARAM_CHANNELS,
SNDRV_PCM_HW_PARAM_RATE,
-1);
if (err < 0)
return err;
}
err = snd_usb_pcm_check_knot(runtime, subs);
if (err < 0)
return err;
return snd_usb_autoresume(subs->stream->chip);
}
static int snd_usb_pcm_open(struct snd_pcm_substream *substream)
{
int direction = substream->stream;
struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_usb_substream *subs = &as->substream[direction];
subs->interface = -1;
subs->altset_idx = 0;
runtime->hw = snd_usb_hardware;
runtime->private_data = subs;
subs->pcm_substream = substream;
/* runtime PM is also done there */
/* initialize DSD/DOP context */
subs->dsd_dop.byte_idx = 0;
subs->dsd_dop.channel = 0;
subs->dsd_dop.marker = 1;
return setup_hw_info(runtime, subs);
}
static int snd_usb_pcm_close(struct snd_pcm_substream *substream)
{
int direction = substream->stream;
struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
struct snd_usb_substream *subs = &as->substream[direction];
int ret;
stop_endpoints(subs, true);
if (!as->chip->keep_iface &&
subs->interface >= 0 &&
!snd_usb_lock_shutdown(subs->stream->chip)) {
usb_set_interface(subs->dev, subs->interface, 0);
subs->interface = -1;
ret = snd_usb_pcm_change_state(subs, UAC3_PD_STATE_D1);
snd_usb_unlock_shutdown(subs->stream->chip);
if (ret < 0)
return ret;
}
subs->pcm_substream = NULL;
snd_usb_autosuspend(subs->stream->chip);
return 0;
}
/* Since a URB can handle only a single linear buffer, we must use double
* buffering when the data to be transferred overflows the buffer boundary.
* To avoid inconsistencies when updating hwptr_done, we use double buffering
* for all URBs.
*/
static void retire_capture_urb(struct snd_usb_substream *subs,
struct urb *urb)
{
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
unsigned int stride, frames, bytes, oldptr;
int i, period_elapsed = 0;
unsigned long flags;
unsigned char *cp;
int current_frame_number;
/* read frame number here, update pointer in critical section */
current_frame_number = usb_get_current_frame_number(subs->dev);
stride = runtime->frame_bits >> 3;
for (i = 0; i < urb->number_of_packets; i++) {
cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset + subs->pkt_offset_adj;
if (urb->iso_frame_desc[i].status && printk_ratelimit()) {
dev_dbg(&subs->dev->dev, "frame %d active: %d\n",
i, urb->iso_frame_desc[i].status);
// continue;
}
bytes = urb->iso_frame_desc[i].actual_length;
frames = bytes / stride;
if (!subs->txfr_quirk)
bytes = frames * stride;
if (bytes % (runtime->sample_bits >> 3) != 0) {
int oldbytes = bytes;
bytes = frames * stride;
dev_warn_ratelimited(&subs->dev->dev,
"Corrected urb data len. %d->%d\n",
oldbytes, bytes);
}
/* update the current pointer */
spin_lock_irqsave(&subs->lock, flags);
oldptr = subs->hwptr_done;
subs->hwptr_done += bytes;
if (subs->hwptr_done >= runtime->buffer_size * stride)
subs->hwptr_done -= runtime->buffer_size * stride;
frames = (bytes + (oldptr % stride)) / stride;
subs->transfer_done += frames;
if (subs->transfer_done >= runtime->period_size) {
subs->transfer_done -= runtime->period_size;
period_elapsed = 1;
}
/* capture delay is by construction limited to one URB,
* reset delays here
*/
runtime->delay = subs->last_delay = 0;
/* realign last_frame_number */
subs->last_frame_number = current_frame_number;
subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
spin_unlock_irqrestore(&subs->lock, flags);
/* copy a data chunk */
if (oldptr + bytes > runtime->buffer_size * stride) {
unsigned int bytes1 =
runtime->buffer_size * stride - oldptr;
memcpy(runtime->dma_area + oldptr, cp, bytes1);
memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
} else {
memcpy(runtime->dma_area + oldptr, cp, bytes);
}
}
if (period_elapsed)
snd_pcm_period_elapsed(subs->pcm_substream);
}
static inline void fill_playback_urb_dsd_dop(struct snd_usb_substream *subs,
struct urb *urb, unsigned int bytes)
{
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
unsigned int stride = runtime->frame_bits >> 3;
unsigned int dst_idx = 0;
unsigned int src_idx = subs->hwptr_done;
unsigned int wrap = runtime->buffer_size * stride;
u8 *dst = urb->transfer_buffer;
u8 *src = runtime->dma_area;
u8 marker[] = { 0x05, 0xfa };
/*
* The DSP DOP format defines a way to transport DSD samples over
* normal PCM data endpoints. It requires stuffing of marker bytes
* (0x05 and 0xfa, alternating per sample frame), and then expects
* 2 additional bytes of actual payload. The whole frame is stored
* LSB.
*
* Hence, for a stereo transport, the buffer layout looks like this,
* where L refers to left channel samples and R to right.
*
* L1 L2 0x05 R1 R2 0x05 L3 L4 0xfa R3 R4 0xfa
* L5 L6 0x05 R5 R6 0x05 L7 L8 0xfa R7 R8 0xfa
* .....
*
*/
while (bytes--) {
if (++subs->dsd_dop.byte_idx == 3) {
/* frame boundary? */
dst[dst_idx++] = marker[subs->dsd_dop.marker];
src_idx += 2;
subs->dsd_dop.byte_idx = 0;
if (++subs->dsd_dop.channel % runtime->channels == 0) {
/* alternate the marker */
subs->dsd_dop.marker++;
subs->dsd_dop.marker %= ARRAY_SIZE(marker);
subs->dsd_dop.channel = 0;
}
} else {
/* stuff the DSD payload */
int idx = (src_idx + subs->dsd_dop.byte_idx - 1) % wrap;
if (subs->cur_audiofmt->dsd_bitrev)
dst[dst_idx++] = bitrev8(src[idx]);
else
dst[dst_idx++] = src[idx];
subs->hwptr_done++;
}
}
if (subs->hwptr_done >= runtime->buffer_size * stride)
subs->hwptr_done -= runtime->buffer_size * stride;
}
static void copy_to_urb(struct snd_usb_substream *subs, struct urb *urb,
int offset, int stride, unsigned int bytes)
{
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
/* err, the transferred area goes over buffer boundary. */
unsigned int bytes1 =
runtime->buffer_size * stride - subs->hwptr_done;
memcpy(urb->transfer_buffer + offset,
runtime->dma_area + subs->hwptr_done, bytes1);
memcpy(urb->transfer_buffer + offset + bytes1,
runtime->dma_area, bytes - bytes1);
} else {
memcpy(urb->transfer_buffer + offset,
runtime->dma_area + subs->hwptr_done, bytes);
}
subs->hwptr_done += bytes;
if (subs->hwptr_done >= runtime->buffer_size * stride)
subs->hwptr_done -= runtime->buffer_size * stride;
}
static unsigned int copy_to_urb_quirk(struct snd_usb_substream *subs,
struct urb *urb, int stride,
unsigned int bytes)
{
__le32 packet_length;
int i;
/* Put __le32 length descriptor at start of each packet. */
for (i = 0; i < urb->number_of_packets; i++) {
unsigned int length = urb->iso_frame_desc[i].length;
unsigned int offset = urb->iso_frame_desc[i].offset;
packet_length = cpu_to_le32(length);
offset += i * sizeof(packet_length);
urb->iso_frame_desc[i].offset = offset;
urb->iso_frame_desc[i].length += sizeof(packet_length);
memcpy(urb->transfer_buffer + offset,
&packet_length, sizeof(packet_length));
copy_to_urb(subs, urb, offset + sizeof(packet_length),
stride, length);
}
/* Adjust transfer size accordingly. */
bytes += urb->number_of_packets * sizeof(packet_length);
return bytes;
}
static void prepare_playback_urb(struct snd_usb_substream *subs,
struct urb *urb)
{
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
struct snd_usb_endpoint *ep = subs->data_endpoint;
struct snd_urb_ctx *ctx = urb->context;
unsigned int counts, frames, bytes;
int i, stride, period_elapsed = 0;
unsigned long flags;
stride = runtime->frame_bits >> 3;
frames = 0;
urb->number_of_packets = 0;
spin_lock_irqsave(&subs->lock, flags);
subs->frame_limit += ep->max_urb_frames;
for (i = 0; i < ctx->packets; i++) {
if (ctx->packet_size[i])
counts = ctx->packet_size[i];
else
counts = snd_usb_endpoint_next_packet_size(ep);
/* set up descriptor */
urb->iso_frame_desc[i].offset = frames * ep->stride;
urb->iso_frame_desc[i].length = counts * ep->stride;
frames += counts;
urb->number_of_packets++;
subs->transfer_done += counts;
if (subs->transfer_done >= runtime->period_size) {
subs->transfer_done -= runtime->period_size;
subs->frame_limit = 0;
period_elapsed = 1;
if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
if (subs->transfer_done > 0) {
/* FIXME: fill-max mode is not
* supported yet */
frames -= subs->transfer_done;
counts -= subs->transfer_done;
urb->iso_frame_desc[i].length =
counts * ep->stride;
subs->transfer_done = 0;
}
i++;
if (i < ctx->packets) {
/* add a transfer delimiter */
urb->iso_frame_desc[i].offset =
frames * ep->stride;
urb->iso_frame_desc[i].length = 0;
urb->number_of_packets++;
}
break;
}
}
/* finish at the period boundary or after enough frames */
if ((period_elapsed ||
subs->transfer_done >= subs->frame_limit) &&
!snd_usb_endpoint_implicit_feedback_sink(ep))
break;
}
bytes = frames * ep->stride;
if (unlikely(subs->pcm_format == SNDRV_PCM_FORMAT_DSD_U16_LE &&
subs->cur_audiofmt->dsd_dop)) {
fill_playback_urb_dsd_dop(subs, urb, bytes);
} else if (unlikely(subs->pcm_format == SNDRV_PCM_FORMAT_DSD_U8 &&
subs->cur_audiofmt->dsd_bitrev)) {
/* bit-reverse the bytes */
u8 *buf = urb->transfer_buffer;
for (i = 0; i < bytes; i++) {
int idx = (subs->hwptr_done + i)
% (runtime->buffer_size * stride);
buf[i] = bitrev8(runtime->dma_area[idx]);
}
subs->hwptr_done += bytes;
if (subs->hwptr_done >= runtime->buffer_size * stride)
subs->hwptr_done -= runtime->buffer_size * stride;
} else {
/* usual PCM */
if (!subs->tx_length_quirk)
copy_to_urb(subs, urb, 0, stride, bytes);
else
bytes = copy_to_urb_quirk(subs, urb, stride, bytes);
/* bytes is now amount of outgoing data */
}
/* update delay with exact number of samples queued */
runtime->delay = subs->last_delay;
runtime->delay += frames;
subs->last_delay = runtime->delay;
/* realign last_frame_number */
subs->last_frame_number = usb_get_current_frame_number(subs->dev);
subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
if (subs->trigger_tstamp_pending_update) {
/* this is the first actual URB submitted,
* update trigger timestamp to reflect actual start time
*/
snd_pcm_gettime(runtime, &runtime->trigger_tstamp);
subs->trigger_tstamp_pending_update = false;
}
spin_unlock_irqrestore(&subs->lock, flags);
urb->transfer_buffer_length = bytes;
if (period_elapsed)
snd_pcm_period_elapsed(subs->pcm_substream);
}
/*
* process after playback data complete
* - decrease the delay count again
*/
static void retire_playback_urb(struct snd_usb_substream *subs,
struct urb *urb)
{
unsigned long flags;
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
struct snd_usb_endpoint *ep = subs->data_endpoint;
int processed = urb->transfer_buffer_length / ep->stride;
int est_delay;
/* ignore the delay accounting when procssed=0 is given, i.e.
* silent payloads are procssed before handling the actual data
*/
if (!processed)
return;
spin_lock_irqsave(&subs->lock, flags);
if (!subs->last_delay)
goto out; /* short path */
est_delay = snd_usb_pcm_delay(subs, runtime->rate);
/* update delay with exact number of samples played */
if (processed > subs->last_delay)
subs->last_delay = 0;
else
subs->last_delay -= processed;
runtime->delay = subs->last_delay;
/*
* Report when delay estimate is off by more than 2ms.
* The error should be lower than 2ms since the estimate relies
* on two reads of a counter updated every ms.
*/
if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
dev_dbg_ratelimited(&subs->dev->dev,
"delay: estimated %d, actual %d\n",
est_delay, subs->last_delay);
if (!subs->running) {
/* update last_frame_number for delay counting here since
* prepare_playback_urb won't be called during pause
*/
subs->last_frame_number =
usb_get_current_frame_number(subs->dev) & 0xff;
}
out:
spin_unlock_irqrestore(&subs->lock, flags);
}
static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream,
int cmd)
{
struct snd_usb_substream *subs = substream->runtime->private_data;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
subs->trigger_tstamp_pending_update = true;
/* fall through */
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
subs->data_endpoint->prepare_data_urb = prepare_playback_urb;
subs->data_endpoint->retire_data_urb = retire_playback_urb;
subs->running = 1;
return 0;
case SNDRV_PCM_TRIGGER_STOP:
stop_endpoints(subs, false);
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
subs->data_endpoint->prepare_data_urb = NULL;
/* keep retire_data_urb for delay calculation */
subs->data_endpoint->retire_data_urb = retire_playback_urb;
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_SUSPEND:
if (subs->stream->chip->setup_fmt_after_resume_quirk) {
stop_endpoints(subs, true);
subs->need_setup_fmt = true;
return 0;
}
break;
}
return -EINVAL;
}
static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream,
int cmd)
{
int err;
struct snd_usb_substream *subs = substream->runtime->private_data;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
err = start_endpoints(subs);
if (err < 0)
return err;
subs->data_endpoint->retire_data_urb = retire_capture_urb;
subs->running = 1;
return 0;
case SNDRV_PCM_TRIGGER_STOP:
stop_endpoints(subs, false);
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
subs->data_endpoint->retire_data_urb = NULL;
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
subs->data_endpoint->retire_data_urb = retire_capture_urb;
subs->running = 1;
return 0;
case SNDRV_PCM_TRIGGER_SUSPEND:
if (subs->stream->chip->setup_fmt_after_resume_quirk) {
stop_endpoints(subs, true);
subs->need_setup_fmt = true;
return 0;
}
break;
}
return -EINVAL;
}
static const struct snd_pcm_ops snd_usb_playback_ops = {
.open = snd_usb_pcm_open,
.close = snd_usb_pcm_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_usb_hw_params,
.hw_free = snd_usb_hw_free,
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_playback_trigger,
.pointer = snd_usb_pcm_pointer,
.page = snd_pcm_lib_get_vmalloc_page,
};
static const struct snd_pcm_ops snd_usb_capture_ops = {
.open = snd_usb_pcm_open,
.close = snd_usb_pcm_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_usb_hw_params,
.hw_free = snd_usb_hw_free,
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_capture_trigger,
.pointer = snd_usb_pcm_pointer,
.page = snd_pcm_lib_get_vmalloc_page,
};
static const struct snd_pcm_ops snd_usb_playback_dev_ops = {
.open = snd_usb_pcm_open,
.close = snd_usb_pcm_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_usb_hw_params,
.hw_free = snd_usb_hw_free,
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_playback_trigger,
.pointer = snd_usb_pcm_pointer,
.page = snd_pcm_sgbuf_ops_page,
};
static const struct snd_pcm_ops snd_usb_capture_dev_ops = {
.open = snd_usb_pcm_open,
.close = snd_usb_pcm_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_usb_hw_params,
.hw_free = snd_usb_hw_free,
.prepare = snd_usb_pcm_prepare,
.trigger = snd_usb_substream_capture_trigger,
.pointer = snd_usb_pcm_pointer,
.page = snd_pcm_sgbuf_ops_page,
};
void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream)
{
const struct snd_pcm_ops *ops;
if (snd_usb_use_vmalloc)
ops = stream == SNDRV_PCM_STREAM_PLAYBACK ?
&snd_usb_playback_ops : &snd_usb_capture_ops;
else
ops = stream == SNDRV_PCM_STREAM_PLAYBACK ?
&snd_usb_playback_dev_ops : &snd_usb_capture_dev_ops;
snd_pcm_set_ops(pcm, stream, ops);
}
void snd_usb_preallocate_buffer(struct snd_usb_substream *subs)
{
struct snd_pcm *pcm = subs->stream->pcm;
struct snd_pcm_substream *s = pcm->streams[subs->direction].substream;
struct device *dev = subs->dev->bus->sysdev;
if (!snd_usb_use_vmalloc)
snd_pcm_lib_preallocate_pages(s, SNDRV_DMA_TYPE_DEV_SG,
dev, 64*1024, 512*1024);
}