···117117118118What: /sys/bus/pci/devices/.../vpd119119Date: February 2008120120-Contact: Ben Hutchings <bhutchings@solarflare.com>120120+Contact: Ben Hutchings <bwh@kernel.org>121121Description:122122 A file named vpd in a device directory will be a123123 binary file containing the Vital Product Data for the
···6262- interrupt-controller : tell that the PMC is an interrupt controller.6363- #interrupt-cells : must be set to 1. The first cell encodes the interrupt id,6464 and reflect the bit position in the PMC_ER/DR/SR registers.6565- You can use the dt macros defined in dt-bindings/clk/at91.h.6565+ You can use the dt macros defined in dt-bindings/clock/at91.h.6666 0 (AT91_PMC_MOSCS) -> main oscillator ready6767 1 (AT91_PMC_LOCKA) -> PLL A ready6868 2 (AT91_PMC_LOCKB) -> PLL B ready
···22182218 noreplace-smp [X86-32,SMP] Don't replace SMP instructions22192219 with UP alternatives2220222022212221- nordrand [X86] Disable the direct use of the RDRAND22222222- instruction even if it is supported by the22232223- processor. RDRAND is still available to user22242224- space applications.22212221+ nordrand [X86] Disable kernel use of the RDRAND and22222222+ RDSEED instructions even if they are supported22232223+ by the processor. RDRAND and RDSEED are still22242224+ available to user space applications.2225222522262226 noresume [SWSUSP] Disables resume and restores original swap22272227 space.
+18-6
MAINTAINERS
···18931893S: Supported18941894F: drivers/net/ethernet/broadcom/bnx2x/1895189518961896-BROADCOM BCM281XX/BCM11XXX ARM ARCHITECTURE18961896+BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITECTURE18971897M: Christian Daudt <bcm@fixthebug.org>18981898M: Matt Porter <mporter@linaro.org>18991899L: bcm-kernel-feedback-list@broadcom.com19001900-T: git git://git.github.com/broadcom/bcm1135119001900+T: git git://github.com/broadcom/mach-bcm19011901S: Maintained19021902F: arch/arm/mach-bcm/19031903F: arch/arm/boot/dts/bcm113*19041904+F: arch/arm/boot/dts/bcm216*19041905F: arch/arm/boot/dts/bcm281*19051906F: arch/arm/configs/bcm_defconfig19061907F: drivers/mmc/host/sdhci_bcm_kona.c···48134812S: Maintained48144813T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core48154814F: kernel/irq/48154815+48164816+IRQCHIP DRIVERS48174817+M: Thomas Gleixner <tglx@linutronix.de>48184818+M: Jason Cooper <jason@lakedaemon.net>48194819+L: linux-kernel@vger.kernel.org48204820+S: Maintained48214821+T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq/core48224822+T: git git://git.infradead.org/users/jcooper/linux.git irqchip/core48164823F: drivers/irqchip/4817482448184825IRQ DOMAINS (IRQ NUMBER MAPPING LIBRARY)···54935484F: drivers/hwmon/ltc4261.c5494548554955486LTP (Linux Test Project)54965496-M: Shubham Goyal <shubham@linux.vnet.ibm.com>54975487M: Mike Frysinger <vapier@gentoo.org>54985488M: Cyril Hrubis <chrubis@suse.cz>54995499-M: Caspar Zhang <caspar@casparzhang.com>55005489M: Wanlong Gao <gaowanlong@cn.fujitsu.com>54905490+M: Jan Stancek <jstancek@redhat.com>54915491+M: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>54925492+M: Alexey Kodanev <alexey.kodanev@oracle.com>55015493L: ltp-list@lists.sourceforge.net (subscribers-only)55025502-W: http://ltp.sourceforge.net/54945494+W: http://linux-test-project.github.io/55035495T: git git://github.com/linux-test-project/ltp.git55045504-T: git git://ltp.git.sourceforge.net/gitroot/ltp/ltp-dev55055496S: Maintained5506549755075498M32R ARCHITECTURE···9111910291129103TURBOCHANNEL SUBSYSTEM91139104M: "Maciej W. Rozycki" <macro@linux-mips.org>91059105+M: Ralf Baechle <ralf@linux-mips.org>91069106+L: linux-mips@linux-mips.org91079107+Q: http://patchwork.linux-mips.org/project/linux-mips/list/91149108S: Maintained91159109F: drivers/tc/91169110F: include/linux/tc.h
···6262 };6363};64646565+&iva {6666+ status = "disabled";6767+};6868+6969+&mailbox {7070+ status = "disabled";7171+};7272+7373+&mmu_isp {7474+ status = "disabled";7575+};7676+7777+&smartreflex_mpu_iva {7878+ status = "disabled";7979+};8080+6581/include/ "am35xx-clocks.dtsi"6682/include/ "omap36xx-am35xx-omap3430es2plus-clocks.dtsi"
···1423142314241424#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DMADEVICES)1425142514261426-static int edma_of_read_u32_to_s16_array(const struct device_node *np,14271427- const char *propname, s16 *out_values,14281428- size_t sz)14261426+static int edma_xbar_event_map(struct device *dev, struct device_node *node,14271427+ struct edma_soc_info *pdata, size_t sz)14291428{14301430- int ret;14311431-14321432- ret = of_property_read_u16_array(np, propname, out_values, sz);14331433- if (ret)14341434- return ret;14351435-14361436- /* Terminate it */14371437- *out_values++ = -1;14381438- *out_values++ = -1;14391439-14401440- return 0;14411441-}14421442-14431443-static int edma_xbar_event_map(struct device *dev,14441444- struct device_node *node,14451445- struct edma_soc_info *pdata, int len)14461446-{14471447- int ret, i;14291429+ const char pname[] = "ti,edma-xbar-event-map";14481430 struct resource res;14491431 void __iomem *xbar;14501450- const s16 (*xbar_chans)[2];14321432+ s16 (*xbar_chans)[2];14331433+ size_t nelm = sz / sizeof(s16);14511434 u32 shift, offset, mux;14351435+ int ret, i;1452143614531453- xbar_chans = devm_kzalloc(dev,14541454- len/sizeof(s16) + 2*sizeof(s16),14551455- GFP_KERNEL);14371437+ xbar_chans = devm_kzalloc(dev, (nelm + 2) * sizeof(s16), GFP_KERNEL);14561438 if (!xbar_chans)14571439 return -ENOMEM;1458144014591441 ret = of_address_to_resource(node, 1, &res);14601442 if (ret)14611461- return -EIO;14431443+ return -ENOMEM;1462144414631445 xbar = devm_ioremap(dev, res.start, resource_size(&res));14641446 if (!xbar)14651447 return -ENOMEM;1466144814671467- ret = edma_of_read_u32_to_s16_array(node,14681468- "ti,edma-xbar-event-map",14691469- (s16 *)xbar_chans,14701470- len/sizeof(u32));14491449+ ret = of_property_read_u16_array(node, pname, (u16 *)xbar_chans, nelm);14711450 if (ret)14721451 return -EIO;1473145214741474- for (i = 0; xbar_chans[i][0] != -1; i++) {14531453+ /* Invalidate last entry for the other user of this mess */14541454+ nelm >>= 1;14551455+ xbar_chans[nelm][0] = xbar_chans[nelm][1] = -1;14561456+14571457+ for (i = 0; i < nelm; i++) {14751458 shift = (xbar_chans[i][1] & 0x03) << 3;14761459 offset = xbar_chans[i][1] & 0xfffffffc;14771460 mux = readl(xbar + offset);···14631480 writel(mux, (xbar + offset));14641481 }1465148214661466- pdata->xbar_chans = xbar_chans;14671467-14831483+ pdata->xbar_chans = (const s16 (*)[2]) xbar_chans;14681484 return 0;14691485}14701486
+1-1
arch/arm/configs/sunxi_defconfig
···3737# CONFIG_NET_VENDOR_NATSEMI is not set3838# CONFIG_NET_VENDOR_SEEQ is not set3939# CONFIG_NET_VENDOR_SMSC is not set4040-# CONFIG_NET_VENDOR_STMICRO is not set4040+CONFIG_STMMAC_ETH=y4141# CONFIG_NET_VENDOR_WIZNET is not set4242# CONFIG_WLAN is not set4343CONFIG_SERIAL_8250=y
···11/*22 * Secondary CPU startup routine source file.33 *44- * Copyright (C) 2009 Texas Instruments, Inc.44+ * Copyright (C) 2009-2014 Texas Instruments, Inc.55 *66 * Author:77 * Santosh Shilimkar <santosh.shilimkar@ti.com>···2828 * code. This routine also provides a holding flag into which2929 * secondary core is held until we're ready for it to initialise.3030 * The primary core will update this flag using a hardware3131-+ * register AuxCoreBoot0.3131+ * register AuxCoreBoot0.3232 */3333ENTRY(omap5_secondary_startup)3434+.arm3535+THUMB( adr r9, BSYM(wait) ) @ CPU may be entered in ARM mode.3636+THUMB( bx r9 ) @ If this is a Thumb-2 kernel,3737+THUMB( .thumb ) @ switch to Thumb now.3438wait: ldr r2, =AUX_CORE_BOOT0_PA @ read from AuxCoreBoot03539 ldr r0, [r2]3640 mov r0, r0, lsr #5
···9797 if (irqd_is_per_cpu(d) || !cpumask_test_cpu(smp_processor_id(), affinity))9898 return false;9999100100- if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) {101101- affinity = cpu_online_mask;100100+ if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids)102101 ret = true;103103- }104102103103+ /*104104+ * when using forced irq_set_affinity we must ensure that the cpu105105+ * being offlined is not present in the affinity mask, it may be106106+ * selected as the target CPU otherwise107107+ */108108+ affinity = cpu_online_mask;105109 c = irq_data_get_irq_chip(d);106110 if (!c->irq_set_affinity)107111 pr_debug("IRQ%u: unable to set affinity\n", d->irq);
···1111121213131414-#define NR_syscalls 314 /* length of syscall table */1414+#define NR_syscalls 315 /* length of syscall table */15151616/*1717 * The following defines stop scripts/checksyscalls.sh from complaining about
···2222/* Add an extra page of padding at the top of the stack for the guard page. */2323#define STACK_TOP (TASK_SIZE - PAGE_SIZE)2424#define STACK_TOP_MAX STACK_TOP2525+/* Maximum virtual space for stack */2626+#define STACK_SIZE_MAX (CONFIG_MAX_STACK_SIZE_MB*1024*1024)25272628/* This decides where the kernel will search for a free chunk of vm2729 * space during mmap's.
···11-/*22- * O32 interface for the 64 (or N32) ABI.33- *44- * Copyright (C) 2002 Maciej W. Rozycki55- *66- * This program is free software; you can redistribute it and/or77- * modify it under the terms of the GNU General Public License88- * as published by the Free Software Foundation; either version99- * 2 of the License, or (at your option) any later version.1010- */1111-1212-#include <asm/asm.h>1313-#include <asm/regdef.h>1414-1515-/* Maximum number of arguments supported. Must be even! */1616-#define O32_ARGC 321717-/* Number of static registers we save. */1818-#define O32_STATC 111919-/* Frame size for both of the above. */2020-#define O32_FRAMESZ (4 * O32_ARGC + SZREG * O32_STATC)2121-2222- .text2323-2424-/*2525- * O32 function call dispatcher, for interfacing 32-bit ROM routines.2626- *2727- * The standard 64 (N32) calling sequence is supported, with a02828- * holding a function pointer, a1-a7 -- its first seven arguments2929- * and the stack -- remaining ones (up to O32_ARGC, including a1-a7).3030- * Static registers, gp and fp are preserved, v0 holds a result.3131- * This code relies on the called o32 function for sp and ra3232- * restoration and thus both this dispatcher and the current stack3333- * have to be placed in a KSEGx (or KUSEG) address space. Any3434- * pointers passed have to point to addresses within one of these3535- * spaces as well.3636- */3737-NESTED(call_o32, O32_FRAMESZ, ra)3838- REG_SUBU sp,O32_FRAMESZ3939-4040- REG_S ra,O32_FRAMESZ-1*SZREG(sp)4141- REG_S fp,O32_FRAMESZ-2*SZREG(sp)4242- REG_S gp,O32_FRAMESZ-3*SZREG(sp)4343- REG_S s7,O32_FRAMESZ-4*SZREG(sp)4444- REG_S s6,O32_FRAMESZ-5*SZREG(sp)4545- REG_S s5,O32_FRAMESZ-6*SZREG(sp)4646- REG_S s4,O32_FRAMESZ-7*SZREG(sp)4747- REG_S s3,O32_FRAMESZ-8*SZREG(sp)4848- REG_S s2,O32_FRAMESZ-9*SZREG(sp)4949- REG_S s1,O32_FRAMESZ-10*SZREG(sp)5050- REG_S s0,O32_FRAMESZ-11*SZREG(sp)5151-5252- move jp,a05353-5454- sll a0,a1,zero5555- sll a1,a2,zero5656- sll a2,a3,zero5757- sll a3,a4,zero5858- sw a5,0x10(sp)5959- sw a6,0x14(sp)6060- sw a7,0x18(sp)6161-6262- PTR_LA t0,O32_FRAMESZ(sp)6363- PTR_LA t1,0x1c(sp)6464- li t2,O32_ARGC-76565-1:6666- lw t3,(t0)6767- REG_ADDU t0,SZREG6868- sw t3,(t1)6969- REG_SUBU t2,17070- REG_ADDU t1,47171- bnez t2,1b7272-7373- jalr jp7474-7575- REG_L s0,O32_FRAMESZ-11*SZREG(sp)7676- REG_L s1,O32_FRAMESZ-10*SZREG(sp)7777- REG_L s2,O32_FRAMESZ-9*SZREG(sp)7878- REG_L s3,O32_FRAMESZ-8*SZREG(sp)7979- REG_L s4,O32_FRAMESZ-7*SZREG(sp)8080- REG_L s5,O32_FRAMESZ-6*SZREG(sp)8181- REG_L s6,O32_FRAMESZ-5*SZREG(sp)8282- REG_L s7,O32_FRAMESZ-4*SZREG(sp)8383- REG_L gp,O32_FRAMESZ-3*SZREG(sp)8484- REG_L fp,O32_FRAMESZ-2*SZREG(sp)8585- REG_L ra,O32_FRAMESZ-1*SZREG(sp)8686-8787- REG_ADDU sp,O32_FRAMESZ8888- jr ra8989-END(call_o32)
+35-22
arch/mips/fw/lib/call_o32.S
···11/*22 * O32 interface for the 64 (or N32) ABI.33 *44- * Copyright (C) 2002 Maciej W. Rozycki44+ * Copyright (C) 2002, 2014 Maciej W. Rozycki55 *66 * This program is free software; you can redistribute it and/or77 * modify it under the terms of the GNU General Public License···1212#include <asm/asm.h>1313#include <asm/regdef.h>14141515+/* O32 register size. */1616+#define O32_SZREG 41517/* Maximum number of arguments supported. Must be even! */1618#define O32_ARGC 321717-/* Number of static registers we save. */1919+/* Number of static registers we save. */1820#define O32_STATC 111919-/* Frame size for static register */2020-#define O32_FRAMESZ (SZREG * O32_STATC)2121-/* Frame size on new stack */2222-#define O32_FRAMESZ_NEW (SZREG + 4 * O32_ARGC)2121+/* Argument area frame size. */2222+#define O32_ARGSZ (O32_SZREG * O32_ARGC)2323+/* Static register save area frame size. */2424+#define O32_STATSZ (SZREG * O32_STATC)2525+/* Stack pointer register save area frame size. */2626+#define O32_SPSZ SZREG2727+/* Combined area frame size. */2828+#define O32_FRAMESZ (O32_ARGSZ + O32_SPSZ + O32_STATSZ)2929+/* Switched stack frame size. */3030+#define O32_NFRAMESZ (O32_ARGSZ + O32_SPSZ)23312432 .text25332634/*2735 * O32 function call dispatcher, for interfacing 32-bit ROM routines.2836 *2929- * The standard 64 (N32) calling sequence is supported, with a03030- * holding a function pointer, a1 a new stack pointer, a2-a7 -- its3131- * first six arguments and the stack -- remaining ones (up to O32_ARGC,3232- * including a2-a7). Static registers, gp and fp are preserved, v0 holds3333- * a result. This code relies on the called o32 function for sp and ra3434- * restoration and this dispatcher has to be placed in a KSEGx (or KUSEG)3535- * address space. Any pointers passed have to point to addresses within3636- * one of these spaces as well.3737+ * The standard 64 (N32) calling sequence is supported, with a0 holding3838+ * a function pointer, a1 a pointer to the new stack to call the3939+ * function with or 0 if no stack switching is requested, a2-a7 -- the4040+ * function call's first six arguments, and the stack -- the remaining4141+ * arguments (up to O32_ARGC, including a2-a7). Static registers, gp4242+ * and fp are preserved, v0 holds the result. This code relies on the4343+ * called o32 function for sp and ra restoration and this dispatcher has4444+ * to be placed in a KSEGx (or KUSEG) address space. Any pointers4545+ * passed have to point to addresses within one of these spaces as well.3746 */3847NESTED(call_o32, O32_FRAMESZ, ra)3948 REG_SUBU sp,O32_FRAMESZ···6051 REG_S s0,O32_FRAMESZ-11*SZREG(sp)61526253 move jp,a06363- REG_SUBU s0,a1,O32_FRAMESZ_NEW6464- REG_S sp,O32_FRAMESZ_NEW-1*SZREG(s0)5454+5555+ move fp,sp5656+ beqz a1,0f5757+ REG_SUBU fp,a1,O32_NFRAMESZ5858+0:5959+ REG_S sp,O32_NFRAMESZ-1*SZREG(fp)65606661 sll a0,a2,zero6762 sll a1,a3,zero6863 sll a2,a4,zero6964 sll a3,a5,zero7070- sw a6,0x10(s0)7171- sw a7,0x14(s0)6565+ sw a6,4*O32_SZREG(fp)6666+ sw a7,5*O32_SZREG(fp)72677368 PTR_LA t0,O32_FRAMESZ(sp)7474- PTR_LA t1,0x18(s0)6969+ PTR_LA t1,6*O32_SZREG(fp)7570 li t2,O32_ARGC-676711:7772 lw t3,(t0)7873 REG_ADDU t0,SZREG7974 sw t3,(t1)8075 REG_SUBU t2,18181- REG_ADDU t1,47676+ REG_ADDU t1,O32_SZREG8277 bnez t2,1b83788484- move sp,s07979+ move sp,fp85808681 jalr jp87828888- REG_L sp,O32_FRAMESZ_NEW-1*SZREG(sp)8383+ REG_L sp,O32_NFRAMESZ-1*SZREG(sp)89849085 REG_L s0,O32_FRAMESZ-11*SZREG(sp)9186 REG_L s1,O32_FRAMESZ-10*SZREG(sp)
+2-1
arch/mips/fw/sni/sniprom.c
···40404141#ifdef CONFIG_64BIT42424343-static u8 o32_stk[16384];4343+/* O32 stack has to be 8-byte aligned. */4444+static u64 o32_stk[4096];4445#define O32_STK &o32_stk[sizeof(o32_stk)]45464647#define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
···11-/*22- * Copyright (C) 2004 by Basler Vision Technologies AG33- * Author: Thomas Koeller <thomas.koeller@baslerweb.com>44- *55- * This program is free software; you can redistribute it and/or modify66- * it under the terms of the GNU General Public License as published by77- * the Free Software Foundation; either version 2 of the License, or88- * (at your option) any later version.99- *1010- * This program is distributed in the hope that it will be useful,1111- * but WITHOUT ANY WARRANTY; without even the implied warranty of1212- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1313- * GNU General Public License for more details.1414- *1515- * You should have received a copy of the GNU General Public License1616- * along with this program; if not, write to the Free Software1717- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA1818- */1919-2020-#if !defined(_ASM_RM9K_OCD_H)2121-#define _ASM_RM9K_OCD_H2222-2323-#include <linux/types.h>2424-#include <linux/spinlock.h>2525-#include <asm/io.h>2626-2727-extern volatile void __iomem * const ocd_base;2828-extern volatile void __iomem * const titan_base;2929-3030-#define ocd_addr(__x__) (ocd_base + (__x__))3131-#define titan_addr(__x__) (titan_base + (__x__))3232-#define scram_addr(__x__) (scram_base + (__x__))3333-3434-/* OCD register access */3535-#define ocd_readl(__offs__) __raw_readl(ocd_addr(__offs__))3636-#define ocd_readw(__offs__) __raw_readw(ocd_addr(__offs__))3737-#define ocd_readb(__offs__) __raw_readb(ocd_addr(__offs__))3838-#define ocd_writel(__val__, __offs__) \3939- __raw_writel((__val__), ocd_addr(__offs__))4040-#define ocd_writew(__val__, __offs__) \4141- __raw_writew((__val__), ocd_addr(__offs__))4242-#define ocd_writeb(__val__, __offs__) \4343- __raw_writeb((__val__), ocd_addr(__offs__))4444-4545-/* TITAN register access - 32 bit-wide only */4646-#define titan_readl(__offs__) __raw_readl(titan_addr(__offs__))4747-#define titan_writel(__val__, __offs__) \4848- __raw_writel((__val__), titan_addr(__offs__))4949-5050-/* Protect access to shared TITAN registers */5151-extern spinlock_t titan_lock;5252-extern int titan_irqflags;5353-#define lock_titan_regs() spin_lock_irqsave(&titan_lock, titan_irqflags)5454-#define unlock_titan_regs() spin_unlock_irqrestore(&titan_lock, titan_irqflags)5555-5656-#endif /* !defined(_ASM_RM9K_OCD_H) */
+2
arch/mips/include/asm/syscall.h
···133133#ifdef CONFIG_64BIT134134 if (!test_thread_flag(TIF_32BIT_REGS))135135 arch |= __AUDIT_ARCH_64BIT;136136+ if (test_thread_flag(TIF_32BIT_ADDR))137137+ arch |= __AUDIT_ARCH_CONVENTION_MIPS64_N32;136138#endif137139#if defined(__LITTLE_ENDIAN)138140 arch |= __AUDIT_ARCH_LE;
+199-199
arch/mips/include/uapi/asm/inst.h
···484484 * Damn ... bitfields depend from byteorder :-(485485 */486486#ifdef __MIPSEB__487487-#define BITFIELD_FIELD(field, more) \487487+#define __BITFIELD_FIELD(field, more) \488488 field; \489489 more490490491491#elif defined(__MIPSEL__)492492493493-#define BITFIELD_FIELD(field, more) \493493+#define __BITFIELD_FIELD(field, more) \494494 more \495495 field;496496···499499#endif500500501501struct j_format {502502- BITFIELD_FIELD(unsigned int opcode : 6, /* Jump format */503503- BITFIELD_FIELD(unsigned int target : 26,502502+ __BITFIELD_FIELD(unsigned int opcode : 6, /* Jump format */503503+ __BITFIELD_FIELD(unsigned int target : 26,504504 ;))505505};506506507507struct i_format { /* signed immediate format */508508- BITFIELD_FIELD(unsigned int opcode : 6,509509- BITFIELD_FIELD(unsigned int rs : 5,510510- BITFIELD_FIELD(unsigned int rt : 5,511511- BITFIELD_FIELD(signed int simmediate : 16,508508+ __BITFIELD_FIELD(unsigned int opcode : 6,509509+ __BITFIELD_FIELD(unsigned int rs : 5,510510+ __BITFIELD_FIELD(unsigned int rt : 5,511511+ __BITFIELD_FIELD(signed int simmediate : 16,512512 ;))))513513};514514515515struct u_format { /* unsigned immediate format */516516- BITFIELD_FIELD(unsigned int opcode : 6,517517- BITFIELD_FIELD(unsigned int rs : 5,518518- BITFIELD_FIELD(unsigned int rt : 5,519519- BITFIELD_FIELD(unsigned int uimmediate : 16,516516+ __BITFIELD_FIELD(unsigned int opcode : 6,517517+ __BITFIELD_FIELD(unsigned int rs : 5,518518+ __BITFIELD_FIELD(unsigned int rt : 5,519519+ __BITFIELD_FIELD(unsigned int uimmediate : 16,520520 ;))))521521};522522523523struct c_format { /* Cache (>= R6000) format */524524- BITFIELD_FIELD(unsigned int opcode : 6,525525- BITFIELD_FIELD(unsigned int rs : 5,526526- BITFIELD_FIELD(unsigned int c_op : 3,527527- BITFIELD_FIELD(unsigned int cache : 2,528528- BITFIELD_FIELD(unsigned int simmediate : 16,524524+ __BITFIELD_FIELD(unsigned int opcode : 6,525525+ __BITFIELD_FIELD(unsigned int rs : 5,526526+ __BITFIELD_FIELD(unsigned int c_op : 3,527527+ __BITFIELD_FIELD(unsigned int cache : 2,528528+ __BITFIELD_FIELD(unsigned int simmediate : 16,529529 ;)))))530530};531531532532struct r_format { /* Register format */533533- BITFIELD_FIELD(unsigned int opcode : 6,534534- BITFIELD_FIELD(unsigned int rs : 5,535535- BITFIELD_FIELD(unsigned int rt : 5,536536- BITFIELD_FIELD(unsigned int rd : 5,537537- BITFIELD_FIELD(unsigned int re : 5,538538- BITFIELD_FIELD(unsigned int func : 6,533533+ __BITFIELD_FIELD(unsigned int opcode : 6,534534+ __BITFIELD_FIELD(unsigned int rs : 5,535535+ __BITFIELD_FIELD(unsigned int rt : 5,536536+ __BITFIELD_FIELD(unsigned int rd : 5,537537+ __BITFIELD_FIELD(unsigned int re : 5,538538+ __BITFIELD_FIELD(unsigned int func : 6,539539 ;))))))540540};541541542542struct p_format { /* Performance counter format (R10000) */543543- BITFIELD_FIELD(unsigned int opcode : 6,544544- BITFIELD_FIELD(unsigned int rs : 5,545545- BITFIELD_FIELD(unsigned int rt : 5,546546- BITFIELD_FIELD(unsigned int rd : 5,547547- BITFIELD_FIELD(unsigned int re : 5,548548- BITFIELD_FIELD(unsigned int func : 6,543543+ __BITFIELD_FIELD(unsigned int opcode : 6,544544+ __BITFIELD_FIELD(unsigned int rs : 5,545545+ __BITFIELD_FIELD(unsigned int rt : 5,546546+ __BITFIELD_FIELD(unsigned int rd : 5,547547+ __BITFIELD_FIELD(unsigned int re : 5,548548+ __BITFIELD_FIELD(unsigned int func : 6,549549 ;))))))550550};551551552552struct f_format { /* FPU register format */553553- BITFIELD_FIELD(unsigned int opcode : 6,554554- BITFIELD_FIELD(unsigned int : 1,555555- BITFIELD_FIELD(unsigned int fmt : 4,556556- BITFIELD_FIELD(unsigned int rt : 5,557557- BITFIELD_FIELD(unsigned int rd : 5,558558- BITFIELD_FIELD(unsigned int re : 5,559559- BITFIELD_FIELD(unsigned int func : 6,553553+ __BITFIELD_FIELD(unsigned int opcode : 6,554554+ __BITFIELD_FIELD(unsigned int : 1,555555+ __BITFIELD_FIELD(unsigned int fmt : 4,556556+ __BITFIELD_FIELD(unsigned int rt : 5,557557+ __BITFIELD_FIELD(unsigned int rd : 5,558558+ __BITFIELD_FIELD(unsigned int re : 5,559559+ __BITFIELD_FIELD(unsigned int func : 6,560560 ;)))))))561561};562562563563struct ma_format { /* FPU multiply and add format (MIPS IV) */564564- BITFIELD_FIELD(unsigned int opcode : 6,565565- BITFIELD_FIELD(unsigned int fr : 5,566566- BITFIELD_FIELD(unsigned int ft : 5,567567- BITFIELD_FIELD(unsigned int fs : 5,568568- BITFIELD_FIELD(unsigned int fd : 5,569569- BITFIELD_FIELD(unsigned int func : 4,570570- BITFIELD_FIELD(unsigned int fmt : 2,564564+ __BITFIELD_FIELD(unsigned int opcode : 6,565565+ __BITFIELD_FIELD(unsigned int fr : 5,566566+ __BITFIELD_FIELD(unsigned int ft : 5,567567+ __BITFIELD_FIELD(unsigned int fs : 5,568568+ __BITFIELD_FIELD(unsigned int fd : 5,569569+ __BITFIELD_FIELD(unsigned int func : 4,570570+ __BITFIELD_FIELD(unsigned int fmt : 2,571571 ;)))))))572572};573573574574struct b_format { /* BREAK and SYSCALL */575575- BITFIELD_FIELD(unsigned int opcode : 6,576576- BITFIELD_FIELD(unsigned int code : 20,577577- BITFIELD_FIELD(unsigned int func : 6,575575+ __BITFIELD_FIELD(unsigned int opcode : 6,576576+ __BITFIELD_FIELD(unsigned int code : 20,577577+ __BITFIELD_FIELD(unsigned int func : 6,578578 ;)))579579};580580581581struct ps_format { /* MIPS-3D / paired single format */582582- BITFIELD_FIELD(unsigned int opcode : 6,583583- BITFIELD_FIELD(unsigned int rs : 5,584584- BITFIELD_FIELD(unsigned int ft : 5,585585- BITFIELD_FIELD(unsigned int fs : 5,586586- BITFIELD_FIELD(unsigned int fd : 5,587587- BITFIELD_FIELD(unsigned int func : 6,582582+ __BITFIELD_FIELD(unsigned int opcode : 6,583583+ __BITFIELD_FIELD(unsigned int rs : 5,584584+ __BITFIELD_FIELD(unsigned int ft : 5,585585+ __BITFIELD_FIELD(unsigned int fs : 5,586586+ __BITFIELD_FIELD(unsigned int fd : 5,587587+ __BITFIELD_FIELD(unsigned int func : 6,588588 ;))))))589589};590590591591struct v_format { /* MDMX vector format */592592- BITFIELD_FIELD(unsigned int opcode : 6,593593- BITFIELD_FIELD(unsigned int sel : 4,594594- BITFIELD_FIELD(unsigned int fmt : 1,595595- BITFIELD_FIELD(unsigned int vt : 5,596596- BITFIELD_FIELD(unsigned int vs : 5,597597- BITFIELD_FIELD(unsigned int vd : 5,598598- BITFIELD_FIELD(unsigned int func : 6,592592+ __BITFIELD_FIELD(unsigned int opcode : 6,593593+ __BITFIELD_FIELD(unsigned int sel : 4,594594+ __BITFIELD_FIELD(unsigned int fmt : 1,595595+ __BITFIELD_FIELD(unsigned int vt : 5,596596+ __BITFIELD_FIELD(unsigned int vs : 5,597597+ __BITFIELD_FIELD(unsigned int vd : 5,598598+ __BITFIELD_FIELD(unsigned int func : 6,599599 ;)))))))600600};601601602602struct spec3_format { /* SPEC3 */603603- BITFIELD_FIELD(unsigned int opcode:6,604604- BITFIELD_FIELD(unsigned int rs:5,605605- BITFIELD_FIELD(unsigned int rt:5,606606- BITFIELD_FIELD(signed int simmediate:9,607607- BITFIELD_FIELD(unsigned int func:7,603603+ __BITFIELD_FIELD(unsigned int opcode:6,604604+ __BITFIELD_FIELD(unsigned int rs:5,605605+ __BITFIELD_FIELD(unsigned int rt:5,606606+ __BITFIELD_FIELD(signed int simmediate:9,607607+ __BITFIELD_FIELD(unsigned int func:7,608608 ;)))))609609};610610···616616 * if it is MIPS32 instruction re-encoded for use in the microMIPS ASE.617617 */618618struct fb_format { /* FPU branch format (MIPS32) */619619- BITFIELD_FIELD(unsigned int opcode : 6,620620- BITFIELD_FIELD(unsigned int bc : 5,621621- BITFIELD_FIELD(unsigned int cc : 3,622622- BITFIELD_FIELD(unsigned int flag : 2,623623- BITFIELD_FIELD(signed int simmediate : 16,619619+ __BITFIELD_FIELD(unsigned int opcode : 6,620620+ __BITFIELD_FIELD(unsigned int bc : 5,621621+ __BITFIELD_FIELD(unsigned int cc : 3,622622+ __BITFIELD_FIELD(unsigned int flag : 2,623623+ __BITFIELD_FIELD(signed int simmediate : 16,624624 ;)))))625625};626626627627struct fp0_format { /* FPU multiply and add format (MIPS32) */628628- BITFIELD_FIELD(unsigned int opcode : 6,629629- BITFIELD_FIELD(unsigned int fmt : 5,630630- BITFIELD_FIELD(unsigned int ft : 5,631631- BITFIELD_FIELD(unsigned int fs : 5,632632- BITFIELD_FIELD(unsigned int fd : 5,633633- BITFIELD_FIELD(unsigned int func : 6,628628+ __BITFIELD_FIELD(unsigned int opcode : 6,629629+ __BITFIELD_FIELD(unsigned int fmt : 5,630630+ __BITFIELD_FIELD(unsigned int ft : 5,631631+ __BITFIELD_FIELD(unsigned int fs : 5,632632+ __BITFIELD_FIELD(unsigned int fd : 5,633633+ __BITFIELD_FIELD(unsigned int func : 6,634634 ;))))))635635};636636637637struct mm_fp0_format { /* FPU multipy and add format (microMIPS) */638638- BITFIELD_FIELD(unsigned int opcode : 6,639639- BITFIELD_FIELD(unsigned int ft : 5,640640- BITFIELD_FIELD(unsigned int fs : 5,641641- BITFIELD_FIELD(unsigned int fd : 5,642642- BITFIELD_FIELD(unsigned int fmt : 3,643643- BITFIELD_FIELD(unsigned int op : 2,644644- BITFIELD_FIELD(unsigned int func : 6,638638+ __BITFIELD_FIELD(unsigned int opcode : 6,639639+ __BITFIELD_FIELD(unsigned int ft : 5,640640+ __BITFIELD_FIELD(unsigned int fs : 5,641641+ __BITFIELD_FIELD(unsigned int fd : 5,642642+ __BITFIELD_FIELD(unsigned int fmt : 3,643643+ __BITFIELD_FIELD(unsigned int op : 2,644644+ __BITFIELD_FIELD(unsigned int func : 6,645645 ;)))))))646646};647647648648struct fp1_format { /* FPU mfc1 and cfc1 format (MIPS32) */649649- BITFIELD_FIELD(unsigned int opcode : 6,650650- BITFIELD_FIELD(unsigned int op : 5,651651- BITFIELD_FIELD(unsigned int rt : 5,652652- BITFIELD_FIELD(unsigned int fs : 5,653653- BITFIELD_FIELD(unsigned int fd : 5,654654- BITFIELD_FIELD(unsigned int func : 6,649649+ __BITFIELD_FIELD(unsigned int opcode : 6,650650+ __BITFIELD_FIELD(unsigned int op : 5,651651+ __BITFIELD_FIELD(unsigned int rt : 5,652652+ __BITFIELD_FIELD(unsigned int fs : 5,653653+ __BITFIELD_FIELD(unsigned int fd : 5,654654+ __BITFIELD_FIELD(unsigned int func : 6,655655 ;))))))656656};657657658658struct mm_fp1_format { /* FPU mfc1 and cfc1 format (microMIPS) */659659- BITFIELD_FIELD(unsigned int opcode : 6,660660- BITFIELD_FIELD(unsigned int rt : 5,661661- BITFIELD_FIELD(unsigned int fs : 5,662662- BITFIELD_FIELD(unsigned int fmt : 2,663663- BITFIELD_FIELD(unsigned int op : 8,664664- BITFIELD_FIELD(unsigned int func : 6,659659+ __BITFIELD_FIELD(unsigned int opcode : 6,660660+ __BITFIELD_FIELD(unsigned int rt : 5,661661+ __BITFIELD_FIELD(unsigned int fs : 5,662662+ __BITFIELD_FIELD(unsigned int fmt : 2,663663+ __BITFIELD_FIELD(unsigned int op : 8,664664+ __BITFIELD_FIELD(unsigned int func : 6,665665 ;))))))666666};667667668668struct mm_fp2_format { /* FPU movt and movf format (microMIPS) */669669- BITFIELD_FIELD(unsigned int opcode : 6,670670- BITFIELD_FIELD(unsigned int fd : 5,671671- BITFIELD_FIELD(unsigned int fs : 5,672672- BITFIELD_FIELD(unsigned int cc : 3,673673- BITFIELD_FIELD(unsigned int zero : 2,674674- BITFIELD_FIELD(unsigned int fmt : 2,675675- BITFIELD_FIELD(unsigned int op : 3,676676- BITFIELD_FIELD(unsigned int func : 6,669669+ __BITFIELD_FIELD(unsigned int opcode : 6,670670+ __BITFIELD_FIELD(unsigned int fd : 5,671671+ __BITFIELD_FIELD(unsigned int fs : 5,672672+ __BITFIELD_FIELD(unsigned int cc : 3,673673+ __BITFIELD_FIELD(unsigned int zero : 2,674674+ __BITFIELD_FIELD(unsigned int fmt : 2,675675+ __BITFIELD_FIELD(unsigned int op : 3,676676+ __BITFIELD_FIELD(unsigned int func : 6,677677 ;))))))))678678};679679680680struct mm_fp3_format { /* FPU abs and neg format (microMIPS) */681681- BITFIELD_FIELD(unsigned int opcode : 6,682682- BITFIELD_FIELD(unsigned int rt : 5,683683- BITFIELD_FIELD(unsigned int fs : 5,684684- BITFIELD_FIELD(unsigned int fmt : 3,685685- BITFIELD_FIELD(unsigned int op : 7,686686- BITFIELD_FIELD(unsigned int func : 6,681681+ __BITFIELD_FIELD(unsigned int opcode : 6,682682+ __BITFIELD_FIELD(unsigned int rt : 5,683683+ __BITFIELD_FIELD(unsigned int fs : 5,684684+ __BITFIELD_FIELD(unsigned int fmt : 3,685685+ __BITFIELD_FIELD(unsigned int op : 7,686686+ __BITFIELD_FIELD(unsigned int func : 6,687687 ;))))))688688};689689690690struct mm_fp4_format { /* FPU c.cond format (microMIPS) */691691- BITFIELD_FIELD(unsigned int opcode : 6,692692- BITFIELD_FIELD(unsigned int rt : 5,693693- BITFIELD_FIELD(unsigned int fs : 5,694694- BITFIELD_FIELD(unsigned int cc : 3,695695- BITFIELD_FIELD(unsigned int fmt : 3,696696- BITFIELD_FIELD(unsigned int cond : 4,697697- BITFIELD_FIELD(unsigned int func : 6,691691+ __BITFIELD_FIELD(unsigned int opcode : 6,692692+ __BITFIELD_FIELD(unsigned int rt : 5,693693+ __BITFIELD_FIELD(unsigned int fs : 5,694694+ __BITFIELD_FIELD(unsigned int cc : 3,695695+ __BITFIELD_FIELD(unsigned int fmt : 3,696696+ __BITFIELD_FIELD(unsigned int cond : 4,697697+ __BITFIELD_FIELD(unsigned int func : 6,698698 ;)))))))699699};700700701701struct mm_fp5_format { /* FPU lwxc1 and swxc1 format (microMIPS) */702702- BITFIELD_FIELD(unsigned int opcode : 6,703703- BITFIELD_FIELD(unsigned int index : 5,704704- BITFIELD_FIELD(unsigned int base : 5,705705- BITFIELD_FIELD(unsigned int fd : 5,706706- BITFIELD_FIELD(unsigned int op : 5,707707- BITFIELD_FIELD(unsigned int func : 6,702702+ __BITFIELD_FIELD(unsigned int opcode : 6,703703+ __BITFIELD_FIELD(unsigned int index : 5,704704+ __BITFIELD_FIELD(unsigned int base : 5,705705+ __BITFIELD_FIELD(unsigned int fd : 5,706706+ __BITFIELD_FIELD(unsigned int op : 5,707707+ __BITFIELD_FIELD(unsigned int func : 6,708708 ;))))))709709};710710711711struct fp6_format { /* FPU madd and msub format (MIPS IV) */712712- BITFIELD_FIELD(unsigned int opcode : 6,713713- BITFIELD_FIELD(unsigned int fr : 5,714714- BITFIELD_FIELD(unsigned int ft : 5,715715- BITFIELD_FIELD(unsigned int fs : 5,716716- BITFIELD_FIELD(unsigned int fd : 5,717717- BITFIELD_FIELD(unsigned int func : 6,712712+ __BITFIELD_FIELD(unsigned int opcode : 6,713713+ __BITFIELD_FIELD(unsigned int fr : 5,714714+ __BITFIELD_FIELD(unsigned int ft : 5,715715+ __BITFIELD_FIELD(unsigned int fs : 5,716716+ __BITFIELD_FIELD(unsigned int fd : 5,717717+ __BITFIELD_FIELD(unsigned int func : 6,718718 ;))))))719719};720720721721struct mm_fp6_format { /* FPU madd and msub format (microMIPS) */722722- BITFIELD_FIELD(unsigned int opcode : 6,723723- BITFIELD_FIELD(unsigned int ft : 5,724724- BITFIELD_FIELD(unsigned int fs : 5,725725- BITFIELD_FIELD(unsigned int fd : 5,726726- BITFIELD_FIELD(unsigned int fr : 5,727727- BITFIELD_FIELD(unsigned int func : 6,722722+ __BITFIELD_FIELD(unsigned int opcode : 6,723723+ __BITFIELD_FIELD(unsigned int ft : 5,724724+ __BITFIELD_FIELD(unsigned int fs : 5,725725+ __BITFIELD_FIELD(unsigned int fd : 5,726726+ __BITFIELD_FIELD(unsigned int fr : 5,727727+ __BITFIELD_FIELD(unsigned int func : 6,728728 ;))))))729729};730730731731struct mm_i_format { /* Immediate format (microMIPS) */732732- BITFIELD_FIELD(unsigned int opcode : 6,733733- BITFIELD_FIELD(unsigned int rt : 5,734734- BITFIELD_FIELD(unsigned int rs : 5,735735- BITFIELD_FIELD(signed int simmediate : 16,732732+ __BITFIELD_FIELD(unsigned int opcode : 6,733733+ __BITFIELD_FIELD(unsigned int rt : 5,734734+ __BITFIELD_FIELD(unsigned int rs : 5,735735+ __BITFIELD_FIELD(signed int simmediate : 16,736736 ;))))737737};738738739739struct mm_m_format { /* Multi-word load/store format (microMIPS) */740740- BITFIELD_FIELD(unsigned int opcode : 6,741741- BITFIELD_FIELD(unsigned int rd : 5,742742- BITFIELD_FIELD(unsigned int base : 5,743743- BITFIELD_FIELD(unsigned int func : 4,744744- BITFIELD_FIELD(signed int simmediate : 12,740740+ __BITFIELD_FIELD(unsigned int opcode : 6,741741+ __BITFIELD_FIELD(unsigned int rd : 5,742742+ __BITFIELD_FIELD(unsigned int base : 5,743743+ __BITFIELD_FIELD(unsigned int func : 4,744744+ __BITFIELD_FIELD(signed int simmediate : 12,745745 ;)))))746746};747747748748struct mm_x_format { /* Scaled indexed load format (microMIPS) */749749- BITFIELD_FIELD(unsigned int opcode : 6,750750- BITFIELD_FIELD(unsigned int index : 5,751751- BITFIELD_FIELD(unsigned int base : 5,752752- BITFIELD_FIELD(unsigned int rd : 5,753753- BITFIELD_FIELD(unsigned int func : 11,749749+ __BITFIELD_FIELD(unsigned int opcode : 6,750750+ __BITFIELD_FIELD(unsigned int index : 5,751751+ __BITFIELD_FIELD(unsigned int base : 5,752752+ __BITFIELD_FIELD(unsigned int rd : 5,753753+ __BITFIELD_FIELD(unsigned int func : 11,754754 ;)))))755755};756756···758758 * microMIPS instruction formats (16-bit length)759759 */760760struct mm_b0_format { /* Unconditional branch format (microMIPS) */761761- BITFIELD_FIELD(unsigned int opcode : 6,762762- BITFIELD_FIELD(signed int simmediate : 10,763763- BITFIELD_FIELD(unsigned int : 16, /* Ignored */761761+ __BITFIELD_FIELD(unsigned int opcode : 6,762762+ __BITFIELD_FIELD(signed int simmediate : 10,763763+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */764764 ;)))765765};766766767767struct mm_b1_format { /* Conditional branch format (microMIPS) */768768- BITFIELD_FIELD(unsigned int opcode : 6,769769- BITFIELD_FIELD(unsigned int rs : 3,770770- BITFIELD_FIELD(signed int simmediate : 7,771771- BITFIELD_FIELD(unsigned int : 16, /* Ignored */768768+ __BITFIELD_FIELD(unsigned int opcode : 6,769769+ __BITFIELD_FIELD(unsigned int rs : 3,770770+ __BITFIELD_FIELD(signed int simmediate : 7,771771+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */772772 ;))))773773};774774775775struct mm16_m_format { /* Multi-word load/store format */776776- BITFIELD_FIELD(unsigned int opcode : 6,777777- BITFIELD_FIELD(unsigned int func : 4,778778- BITFIELD_FIELD(unsigned int rlist : 2,779779- BITFIELD_FIELD(unsigned int imm : 4,780780- BITFIELD_FIELD(unsigned int : 16, /* Ignored */776776+ __BITFIELD_FIELD(unsigned int opcode : 6,777777+ __BITFIELD_FIELD(unsigned int func : 4,778778+ __BITFIELD_FIELD(unsigned int rlist : 2,779779+ __BITFIELD_FIELD(unsigned int imm : 4,780780+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */781781 ;)))))782782};783783784784struct mm16_rb_format { /* Signed immediate format */785785- BITFIELD_FIELD(unsigned int opcode : 6,786786- BITFIELD_FIELD(unsigned int rt : 3,787787- BITFIELD_FIELD(unsigned int base : 3,788788- BITFIELD_FIELD(signed int simmediate : 4,789789- BITFIELD_FIELD(unsigned int : 16, /* Ignored */785785+ __BITFIELD_FIELD(unsigned int opcode : 6,786786+ __BITFIELD_FIELD(unsigned int rt : 3,787787+ __BITFIELD_FIELD(unsigned int base : 3,788788+ __BITFIELD_FIELD(signed int simmediate : 4,789789+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */790790 ;)))))791791};792792793793struct mm16_r3_format { /* Load from global pointer format */794794- BITFIELD_FIELD(unsigned int opcode : 6,795795- BITFIELD_FIELD(unsigned int rt : 3,796796- BITFIELD_FIELD(signed int simmediate : 7,797797- BITFIELD_FIELD(unsigned int : 16, /* Ignored */794794+ __BITFIELD_FIELD(unsigned int opcode : 6,795795+ __BITFIELD_FIELD(unsigned int rt : 3,796796+ __BITFIELD_FIELD(signed int simmediate : 7,797797+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */798798 ;))))799799};800800801801struct mm16_r5_format { /* Load/store from stack pointer format */802802- BITFIELD_FIELD(unsigned int opcode : 6,803803- BITFIELD_FIELD(unsigned int rt : 5,804804- BITFIELD_FIELD(signed int simmediate : 5,805805- BITFIELD_FIELD(unsigned int : 16, /* Ignored */802802+ __BITFIELD_FIELD(unsigned int opcode : 6,803803+ __BITFIELD_FIELD(unsigned int rt : 5,804804+ __BITFIELD_FIELD(signed int simmediate : 5,805805+ __BITFIELD_FIELD(unsigned int : 16, /* Ignored */806806 ;))))807807};808808···810810 * MIPS16e instruction formats (16-bit length)811811 */812812struct m16e_rr {813813- BITFIELD_FIELD(unsigned int opcode : 5,814814- BITFIELD_FIELD(unsigned int rx : 3,815815- BITFIELD_FIELD(unsigned int nd : 1,816816- BITFIELD_FIELD(unsigned int l : 1,817817- BITFIELD_FIELD(unsigned int ra : 1,818818- BITFIELD_FIELD(unsigned int func : 5,813813+ __BITFIELD_FIELD(unsigned int opcode : 5,814814+ __BITFIELD_FIELD(unsigned int rx : 3,815815+ __BITFIELD_FIELD(unsigned int nd : 1,816816+ __BITFIELD_FIELD(unsigned int l : 1,817817+ __BITFIELD_FIELD(unsigned int ra : 1,818818+ __BITFIELD_FIELD(unsigned int func : 5,819819 ;))))))820820};821821822822struct m16e_jal {823823- BITFIELD_FIELD(unsigned int opcode : 5,824824- BITFIELD_FIELD(unsigned int x : 1,825825- BITFIELD_FIELD(unsigned int imm20_16 : 5,826826- BITFIELD_FIELD(signed int imm25_21 : 5,823823+ __BITFIELD_FIELD(unsigned int opcode : 5,824824+ __BITFIELD_FIELD(unsigned int x : 1,825825+ __BITFIELD_FIELD(unsigned int imm20_16 : 5,826826+ __BITFIELD_FIELD(signed int imm25_21 : 5,827827 ;))))828828};829829830830struct m16e_i64 {831831- BITFIELD_FIELD(unsigned int opcode : 5,832832- BITFIELD_FIELD(unsigned int func : 3,833833- BITFIELD_FIELD(unsigned int imm : 8,831831+ __BITFIELD_FIELD(unsigned int opcode : 5,832832+ __BITFIELD_FIELD(unsigned int func : 3,833833+ __BITFIELD_FIELD(unsigned int imm : 8,834834 ;)))835835};836836837837struct m16e_ri64 {838838- BITFIELD_FIELD(unsigned int opcode : 5,839839- BITFIELD_FIELD(unsigned int func : 3,840840- BITFIELD_FIELD(unsigned int ry : 3,841841- BITFIELD_FIELD(unsigned int imm : 5,838838+ __BITFIELD_FIELD(unsigned int opcode : 5,839839+ __BITFIELD_FIELD(unsigned int func : 3,840840+ __BITFIELD_FIELD(unsigned int ry : 3,841841+ __BITFIELD_FIELD(unsigned int imm : 5,842842 ;))))843843};844844845845struct m16e_ri {846846- BITFIELD_FIELD(unsigned int opcode : 5,847847- BITFIELD_FIELD(unsigned int rx : 3,848848- BITFIELD_FIELD(unsigned int imm : 8,846846+ __BITFIELD_FIELD(unsigned int opcode : 5,847847+ __BITFIELD_FIELD(unsigned int rx : 3,848848+ __BITFIELD_FIELD(unsigned int imm : 8,849849 ;)))850850};851851852852struct m16e_rri {853853- BITFIELD_FIELD(unsigned int opcode : 5,854854- BITFIELD_FIELD(unsigned int rx : 3,855855- BITFIELD_FIELD(unsigned int ry : 3,856856- BITFIELD_FIELD(unsigned int imm : 5,853853+ __BITFIELD_FIELD(unsigned int opcode : 5,854854+ __BITFIELD_FIELD(unsigned int rx : 3,855855+ __BITFIELD_FIELD(unsigned int ry : 3,856856+ __BITFIELD_FIELD(unsigned int imm : 5,857857 ;))))858858};859859860860struct m16e_i8 {861861- BITFIELD_FIELD(unsigned int opcode : 5,862862- BITFIELD_FIELD(unsigned int func : 3,863863- BITFIELD_FIELD(unsigned int imm : 8,861861+ __BITFIELD_FIELD(unsigned int opcode : 5,862862+ __BITFIELD_FIELD(unsigned int func : 3,863863+ __BITFIELD_FIELD(unsigned int imm : 8,864864 ;)))865865};866866
+6-3
arch/mips/include/uapi/asm/unistd.h
···371371#define __NR_finit_module (__NR_Linux + 348)372372#define __NR_sched_setattr (__NR_Linux + 349)373373#define __NR_sched_getattr (__NR_Linux + 350)374374+#define __NR_renameat2 (__NR_Linux + 351)374375375376/*376377 * Offset of the last Linux o32 flavoured syscall377378 */378378-#define __NR_Linux_syscalls 350379379+#define __NR_Linux_syscalls 351379380380381#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */381382···700699#define __NR_getdents64 (__NR_Linux + 308)701700#define __NR_sched_setattr (__NR_Linux + 309)702701#define __NR_sched_getattr (__NR_Linux + 310)702702+#define __NR_renameat2 (__NR_Linux + 311)703703704704/*705705 * Offset of the last Linux 64-bit flavoured syscall706706 */707707-#define __NR_Linux_syscalls 310707707+#define __NR_Linux_syscalls 311708708709709#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */710710···10331031#define __NR_finit_module (__NR_Linux + 312)10341032#define __NR_sched_setattr (__NR_Linux + 313)10351033#define __NR_sched_getattr (__NR_Linux + 314)10341034+#define __NR_renameat2 (__NR_Linux + 315)1036103510371036/*10381037 * Offset of the last N32 flavoured syscall10391038 */10401040-#define __NR_Linux_syscalls 31410391039+#define __NR_Linux_syscalls 3151041104010421041#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */10431042
···91919292int clk_set_rate(struct clk *clk, unsigned long rate)9393{9494+ unsigned int rate_khz = rate / 1000;9495 int ret = 0;9596 int regval;9697 int i;···112111 if (loongson2_clockmod_table[i].frequency ==113112 CPUFREQ_ENTRY_INVALID)114113 continue;115115- if (rate == loongson2_clockmod_table[i].frequency)114114+ if (rate_khz == loongson2_clockmod_table[i].frequency)116115 break;117116 }118118- if (rate != loongson2_clockmod_table[i].frequency)117117+ if (rate_khz != loongson2_clockmod_table[i].frequency)119118 return -ENOTSUPP;120119121120 clk->rate = rate;
+3-1
arch/mips/mm/tlb-funcs.S
···16161717#define FASTPATH_SIZE 12818181919+EXPORT(tlbmiss_handler_setup_pgd_start)1920LEAF(tlbmiss_handler_setup_pgd)2020- .space 16 * 42121+1: j 1b /* Dummy, will be replaced. */2222+ .space 642123END(tlbmiss_handler_setup_pgd)2224EXPORT(tlbmiss_handler_setup_pgd_end)2325
···2525#include <linux/interrupt.h>2626#include <linux/console.h>2727#include <linux/bug.h>2828+#include <linux/ratelimit.h>28292930#include <asm/assembly.h>3031#include <asm/uaccess.h>···4241#include <asm/cacheflush.h>43424443#include "../math-emu/math-emu.h" /* for handle_fpe() */4545-4646-#define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */4747- /* dumped to the console via printk) */48444945#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)5046DEFINE_SPINLOCK(pa_dbit_lock);···158160 }159161}160162163163+static DEFINE_RATELIMIT_STATE(_hppa_rs,164164+ DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST);165165+166166+#define parisc_printk_ratelimited(critical, regs, fmt, ...) { \167167+ if ((critical || show_unhandled_signals) && __ratelimit(&_hppa_rs)) { \168168+ printk(fmt, ##__VA_ARGS__); \169169+ show_regs(regs); \170170+ } \171171+}172172+173173+161174static void do_show_stack(struct unwind_frame_info *info)162175{163176 int i = 1;···238229 if (err == 0)239230 return; /* STFU */240231241241- printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",232232+ parisc_printk_ratelimited(1, regs,233233+ KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",242234 current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);243243-#ifdef PRINT_USER_FAULTS244244- /* XXX for debugging only */245245- show_regs(regs);246246-#endif235235+247236 return;248237 }249238···328321 (tt == BUG_TRAP_TYPE_NONE) ? 9 : 0);329322 }330323331331-#ifdef PRINT_USER_FAULTS332332- if (unlikely(iir != GDB_BREAK_INSN)) {333333- printk(KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",324324+ if (unlikely(iir != GDB_BREAK_INSN))325325+ parisc_printk_ratelimited(0, regs,326326+ KERN_DEBUG "break %d,%d: pid=%d command='%s'\n",334327 iir & 31, (iir>>13) & ((1<<13)-1),335328 task_pid_nr(current), current->comm);336336- show_regs(regs);337337- }338338-#endif339329340330 /* send standard GDB signal */341331 handle_gdb_break(regs, TRAP_BRKPT);···762758763759 default:764760 if (user_mode(regs)) {765765-#ifdef PRINT_USER_FAULTS766766- printk(KERN_DEBUG "\nhandle_interruption() pid=%d command='%s'\n",767767- task_pid_nr(current), current->comm);768768- show_regs(regs);769769-#endif761761+ parisc_printk_ratelimited(0, regs, KERN_DEBUG762762+ "handle_interruption() pid=%d command='%s'\n",763763+ task_pid_nr(current), current->comm);770764 /* SIGBUS, for lack of a better one. */771765 si.si_signo = SIGBUS;772766 si.si_code = BUS_OBJERR;···781779782780 if (user_mode(regs)) {783781 if ((fault_space >> SPACEID_SHIFT) != (regs->sr[7] >> SPACEID_SHIFT)) {784784-#ifdef PRINT_USER_FAULTS785785- if (fault_space == 0)786786- printk(KERN_DEBUG "User Fault on Kernel Space ");787787- else788788- printk(KERN_DEBUG "User Fault (long pointer) (fault %d) ",789789- code);790790- printk(KERN_CONT "pid=%d command='%s'\n",791791- task_pid_nr(current), current->comm);792792- show_regs(regs);793793-#endif782782+ parisc_printk_ratelimited(0, regs, KERN_DEBUG783783+ "User fault %d on space 0x%08lx, pid=%d command='%s'\n",784784+ code, fault_space,785785+ task_pid_nr(current), current->comm);794786 si.si_signo = SIGSEGV;795787 si.si_errno = 0;796788 si.si_code = SEGV_MAPERR;
+30-14
arch/parisc/mm/fault.c
···1919#include <asm/uaccess.h>2020#include <asm/traps.h>21212222-#define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */2323- /* dumped to the console via printk) */2424-2525-2622/* Various important other fields */2723#define bit22set(x) (x & 0x00000200)2824#define bits23_25set(x) (x & 0x000001c0)···293330343135DEFINE_PER_CPU(struct exception_data, exception_data);3636+3737+int show_unhandled_signals = 1;32383339/*3440 * parisc_acctyp(unsigned int inst) --···171173 return 0;172174}173175176176+/*177177+ * Print out info about fatal segfaults, if the show_unhandled_signals178178+ * sysctl is set:179179+ */180180+static inline void181181+show_signal_msg(struct pt_regs *regs, unsigned long code,182182+ unsigned long address, struct task_struct *tsk,183183+ struct vm_area_struct *vma)184184+{185185+ if (!unhandled_signal(tsk, SIGSEGV))186186+ return;187187+188188+ if (!printk_ratelimit())189189+ return;190190+191191+ pr_warn("\n");192192+ pr_warn("do_page_fault() command='%s' type=%lu address=0x%08lx",193193+ tsk->comm, code, address);194194+ print_vma_addr(KERN_CONT " in ", regs->iaoq[0]);195195+ if (vma)196196+ pr_warn(" vm_start = 0x%08lx, vm_end = 0x%08lx\n",197197+ vma->vm_start, vma->vm_end);198198+199199+ show_regs(regs);200200+}201201+174202void do_page_fault(struct pt_regs *regs, unsigned long code,175203 unsigned long address)176204{···294270 if (user_mode(regs)) {295271 struct siginfo si;296272297297-#ifdef PRINT_USER_FAULTS298298- printk(KERN_DEBUG "\n");299299- printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",300300- task_pid_nr(tsk), tsk->comm, code, address);301301- if (vma) {302302- printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",303303- vma->vm_start, vma->vm_end);304304- }305305- show_regs(regs);306306-#endif273273+ show_signal_msg(regs, code, address, tsk, vma);274274+307275 switch (code) {308276 case 15: /* Data TLB miss fault/Data page fault */309277 /* send SIGSEGV when outside of vma */
-3
arch/powerpc/kernel/time.c
···813813static int decrementer_set_next_event(unsigned long evt,814814 struct clock_event_device *dev)815815{816816- /* Don't adjust the decrementer if some irq work is pending */817817- if (test_irq_work_pending())818818- return 0;819816 __get_cpu_var(decrementers_next_tb) = get_tb_or_rtc() + evt;820817 set_dec(evt);821818
+2-1
arch/powerpc/platforms/powernv/eeh-ioda.c
···549549 ret = ioda_eeh_phb_reset(hose, option);550550 } else {551551 bus = eeh_pe_bus_get(pe);552552- if (pci_is_root_bus(bus))552552+ if (pci_is_root_bus(bus) ||553553+ pci_is_root_bus(bus->parent))553554 ret = ioda_eeh_root_reset(hose, option);554555 else555556 ret = ioda_eeh_bridge_reset(hose, bus->self, option);
+3
arch/s390/crypto/aes_s390.c
···820820 else821821 memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE);822822 spin_unlock(&ctrblk_lock);823823+ } else {824824+ if (!nbytes)825825+ memcpy(walk->iv, ctrptr, AES_BLOCK_SIZE);823826 }824827 /*825828 * final block may be < AES_BLOCK_SIZE, copy only nbytes
+3
arch/s390/crypto/des_s390.c
···429429 else430430 memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE);431431 spin_unlock(&ctrblk_lock);432432+ } else {433433+ if (!nbytes)434434+ memcpy(walk->iv, ctrptr, DES_BLOCK_SIZE);432435 }433436 /* final block may be < DES_BLOCK_SIZE, copy only nbytes */434437 if (nbytes) {
+1
arch/x86/include/asm/hugetlb.h
···5252static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,5353 unsigned long addr, pte_t *ptep)5454{5555+ ptep_clear_flush(vma, addr, ptep);5556}56575758static inline int huge_pte_none(pte_t pte)
+1
arch/x86/kernel/cpu/rdrand.c
···2727static int __init x86_rdrand_setup(char *s)2828{2929 setup_clear_cpu_cap(X86_FEATURE_RDRAND);3030+ setup_clear_cpu_cap(X86_FEATURE_RDSEED);3031 return 1;3132}3233__setup("nordrand", x86_rdrand_setup);
+3-1
arch/x86/kernel/ldt.c
···2020#include <asm/mmu_context.h>2121#include <asm/syscalls.h>22222323+int sysctl_ldt16 = 0;2424+2325#ifdef CONFIG_SMP2426static void flush_ldt(void *current_mm)2527{···236234 * IRET leaking the high bits of the kernel stack address.237235 */238236#ifdef CONFIG_X86_64239239- if (!ldt_info.seg_32bit) {237237+ if (!ldt_info.seg_32bit && !sysctl_ldt16) {240238 error = -EINVAL;241239 goto out_unlock;242240 }
···451451 struct blkcg_gq *blkg;452452 int i;453453454454- mutex_lock(&blkcg_pol_mutex);454454+ /*455455+ * XXX: We invoke cgroup_add/rm_cftypes() under blkcg_pol_mutex456456+ * which ends up putting cgroup's internal cgroup_tree_mutex under457457+ * it; however, cgroup_tree_mutex is nested above cgroup file458458+ * active protection and grabbing blkcg_pol_mutex from a cgroup459459+ * file operation creates a possible circular dependency. cgroup460460+ * internal locking is planned to go through further simplification461461+ * and this issue should go away soon. For now, let's trylock462462+ * blkcg_pol_mutex and restart the write on failure.463463+ *464464+ * http://lkml.kernel.org/g/5363C04B.4010400@oracle.com465465+ */466466+ if (!mutex_trylock(&blkcg_pol_mutex))467467+ return restart_syscall();455468 spin_lock_irq(&blkcg->lock);456469457470 /*
···4747 depends on SUSPEND || HIBERNATION4848 default y49495050+config ACPI_PROCFS_POWER5151+ bool "Deprecated power /proc/acpi directories"5252+ depends on PROC_FS5353+ help5454+ For backwards compatibility, this option allows5555+ deprecated power /proc/acpi/ directories to exist, even when5656+ they have been replaced by functions in /sys.5757+ The deprecated directories (and their replacements) include:5858+ /proc/acpi/battery/* (/sys/class/power_supply/*)5959+ /proc/acpi/ac_adapter/* (sys/class/power_supply/*)6060+ This option has no effect on /proc/acpi/ directories6161+ and functions, which do not yet exist in /sys6262+ This option, together with the proc directories, will be6363+ deleted in the future.6464+6565+ Say N to delete power /proc/acpi/ directories that have moved to /sys/6666+5067config ACPI_EC_DEBUGFS5168 tristate "EC read/write access through /sys/kernel/debug/ec"5269 default n
···405405 goto err;406406407407 pr->dev = dev;408408- dev->offline = pr->flags.need_hotplug_init;409408410409 /* Trigger the processor driver's .probe() if present. */411410 if (device_attach(dev) >= 0)
+2-2
drivers/acpi/acpica/acglobal.h
···141141 * address. Although ACPICA adheres to the ACPI specification which142142 * requires the use of the corresponding 64-bit address if it is non-zero,143143 * some machines have been found to have a corrupted non-zero 64-bit144144- * address. Default is FALSE, do not favor the 32-bit addresses.144144+ * address. Default is TRUE, favor the 32-bit addresses.145145 */146146-ACPI_INIT_GLOBAL(u8, acpi_gbl_use32_bit_fadt_addresses, FALSE);146146+ACPI_INIT_GLOBAL(u8, acpi_gbl_use32_bit_fadt_addresses, TRUE);147147148148/*149149 * Optionally truncate I/O addresses to 16 bits. Provides compatibility
+5-2
drivers/acpi/acpica/tbutils.c
···461461 u32 table_count;462462 struct acpi_table_header *table;463463 acpi_physical_address address;464464+ acpi_physical_address rsdt_address;464465 u32 length;465466 u8 *table_entry;466467 acpi_status status;···489488 * as per the ACPI specification.490489 */491490 address = (acpi_physical_address) rsdp->xsdt_physical_address;491491+ rsdt_address =492492+ (acpi_physical_address) rsdp->rsdt_physical_address;492493 table_entry_size = ACPI_XSDT_ENTRY_SIZE;493494 } else {494495 /* Root table is an RSDT (32-bit physical addresses) */495496496497 address = (acpi_physical_address) rsdp->rsdt_physical_address;498498+ rsdt_address = address;497499 table_entry_size = ACPI_RSDT_ENTRY_SIZE;498500 }499501···519515520516 /* Fall back to the RSDT */521517522522- address =523523- (acpi_physical_address) rsdp->rsdt_physical_address;518518+ address = rsdt_address;524519 table_entry_size = ACPI_RSDT_ENTRY_SIZE;525520 }526521 }
···314314 DMI_MATCH(DMI_PRODUCT_VERSION, "2349D15"),315315 },316316 },317317+ {318318+ .callback = dmi_disable_osi_win8,319319+ .ident = "Dell Inspiron 7737",320320+ .matches = {321321+ DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),322322+ DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7737"),323323+ },324324+ },317325318326 /*319327 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.···380372 .matches = {381373 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),382374 DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T500"),375375+ },376376+ },377377+ /*378378+ * Without this this EEEpc exports a non working WMI interface, with379379+ * this it exports a working "good old" eeepc_laptop interface, fixing380380+ * both brightness control, and rfkill not working.381381+ */382382+ {383383+ .callback = dmi_enable_osi_linux,384384+ .ident = "Asus EEE PC 1015PX",385385+ .matches = {386386+ DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),387387+ DMI_MATCH(DMI_PRODUCT_NAME, "1015PX"),383388 },384389 },385390 {}
+105
drivers/acpi/cm_sbs.c
···11+/*22+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~33+ *44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License as published by66+ * the Free Software Foundation; either version 2 of the License, or (at77+ * your option) any later version.88+ *99+ * This program is distributed in the hope that it will be useful, but1010+ * WITHOUT ANY WARRANTY; without even the implied warranty of1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU1212+ * General Public License for more details.1313+ *1414+ * You should have received a copy of the GNU General Public License along1515+ * with this program; if not, write to the Free Software Foundation, Inc.,1616+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.1717+ *1818+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~1919+ */2020+2121+#include <linux/kernel.h>2222+#include <linux/module.h>2323+#include <linux/init.h>2424+#include <linux/acpi.h>2525+#include <linux/types.h>2626+#include <linux/proc_fs.h>2727+#include <linux/seq_file.h>2828+#include <acpi/acpi_bus.h>2929+#include <acpi/acpi_drivers.h>3030+3131+#define PREFIX "ACPI: "3232+3333+ACPI_MODULE_NAME("cm_sbs");3434+#define ACPI_AC_CLASS "ac_adapter"3535+#define ACPI_BATTERY_CLASS "battery"3636+#define _COMPONENT ACPI_SBS_COMPONENT3737+static struct proc_dir_entry *acpi_ac_dir;3838+static struct proc_dir_entry *acpi_battery_dir;3939+4040+static DEFINE_MUTEX(cm_sbs_mutex);4141+4242+static int lock_ac_dir_cnt;4343+static int lock_battery_dir_cnt;4444+4545+struct proc_dir_entry *acpi_lock_ac_dir(void)4646+{4747+ mutex_lock(&cm_sbs_mutex);4848+ if (!acpi_ac_dir)4949+ acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);5050+ if (acpi_ac_dir) {5151+ lock_ac_dir_cnt++;5252+ } else {5353+ printk(KERN_ERR PREFIX5454+ "Cannot create %s\n", ACPI_AC_CLASS);5555+ }5656+ mutex_unlock(&cm_sbs_mutex);5757+ return acpi_ac_dir;5858+}5959+EXPORT_SYMBOL(acpi_lock_ac_dir);6060+6161+void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)6262+{6363+ mutex_lock(&cm_sbs_mutex);6464+ if (acpi_ac_dir_param)6565+ lock_ac_dir_cnt--;6666+ if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {6767+ remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);6868+ acpi_ac_dir = NULL;6969+ }7070+ mutex_unlock(&cm_sbs_mutex);7171+}7272+EXPORT_SYMBOL(acpi_unlock_ac_dir);7373+7474+struct proc_dir_entry *acpi_lock_battery_dir(void)7575+{7676+ mutex_lock(&cm_sbs_mutex);7777+ if (!acpi_battery_dir) {7878+ acpi_battery_dir =7979+ proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);8080+ }8181+ if (acpi_battery_dir) {8282+ lock_battery_dir_cnt++;8383+ } else {8484+ printk(KERN_ERR PREFIX8585+ "Cannot create %s\n", ACPI_BATTERY_CLASS);8686+ }8787+ mutex_unlock(&cm_sbs_mutex);8888+ return acpi_battery_dir;8989+}9090+EXPORT_SYMBOL(acpi_lock_battery_dir);9191+9292+void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)9393+{9494+ mutex_lock(&cm_sbs_mutex);9595+ if (acpi_battery_dir_param)9696+ lock_battery_dir_cnt--;9797+ if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param9898+ && acpi_battery_dir) {9999+ remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);100100+ acpi_battery_dir = NULL;101101+ }102102+ mutex_unlock(&cm_sbs_mutex);103103+ return;104104+}105105+EXPORT_SYMBOL(acpi_unlock_battery_dir);
···815815816816config PATA_AT91817817 tristate "PATA support for AT91SAM9260"818818- depends on ARM && ARCH_AT91818818+ depends on ARM && SOC_AT91SAM9819819 help820820 This option enables support for IDE devices on the Atmel AT91SAM9260 SoC.821821
+15
drivers/ata/ahci.c
···11151115 return pdev->bus->number == (val >> 8) && pdev->devfn == (val & 0xff);11161116}1117111711181118+static bool ahci_broken_devslp(struct pci_dev *pdev)11191119+{11201120+ /* device with broken DEVSLP but still showing SDS capability */11211121+ static const struct pci_device_id ids[] = {11221122+ { PCI_VDEVICE(INTEL, 0x0f23)}, /* Valleyview SoC */11231123+ {}11241124+ };11251125+11261126+ return pci_match_id(ids, pdev);11271127+}11281128+11181129#ifdef CONFIG_ATA_ACPI11191130static void ahci_gtf_filter_workaround(struct ata_host *host)11201131{···13741363 hpriv->flags &= ~AHCI_HFLAG_32BIT_ONLY;1375136413761365 hpriv->mmio = pcim_iomap_table(pdev)[ahci_pci_bar];13661366+13671367+ /* must set flag prior to save config in order to take effect */13681368+ if (ahci_broken_devslp(pdev))13691369+ hpriv->flags |= AHCI_HFLAG_NO_DEVSLP;1377137013781371 /* save initial config */13791372 ahci_pci_save_initial_config(pdev, hpriv);
···2929#include "ahci.h"30303131enum {3232- PORT_PHY_CTL = 0x178, /* Port0 PHY Control */3333- PORT_PHY_CTL_PDDQ_LOC = 0x100000, /* PORT_PHY_CTL bits */3434- HOST_TIMER1MS = 0xe0, /* Timer 1-ms */3232+ /* Timer 1-ms Register */3333+ IMX_TIMER1MS = 0x00e0,3434+ /* Port0 PHY Control Register */3535+ IMX_P0PHYCR = 0x0178,3636+ IMX_P0PHYCR_TEST_PDDQ = 1 << 20,3737+ IMX_P0PHYCR_CR_READ = 1 << 19,3838+ IMX_P0PHYCR_CR_WRITE = 1 << 18,3939+ IMX_P0PHYCR_CR_CAP_DATA = 1 << 17,4040+ IMX_P0PHYCR_CR_CAP_ADDR = 1 << 16,4141+ /* Port0 PHY Status Register */4242+ IMX_P0PHYSR = 0x017c,4343+ IMX_P0PHYSR_CR_ACK = 1 << 18,4444+ IMX_P0PHYSR_CR_DATA_OUT = 0xffff << 0,4545+ /* Lane0 Output Status Register */4646+ IMX_LANE0_OUT_STAT = 0x2003,4747+ IMX_LANE0_OUT_STAT_RX_PLL_STATE = 1 << 1,4848+ /* Clock Reset Register */4949+ IMX_CLOCK_RESET = 0x7f3f,5050+ IMX_CLOCK_RESET_RESET = 1 << 0,3551};36523753enum ahci_imx_type {···70547155static void ahci_imx_host_stop(struct ata_host *host);72565757+static int imx_phy_crbit_assert(void __iomem *mmio, u32 bit, bool assert)5858+{5959+ int timeout = 10;6060+ u32 crval;6161+ u32 srval;6262+6363+ /* Assert or deassert the bit */6464+ crval = readl(mmio + IMX_P0PHYCR);6565+ if (assert)6666+ crval |= bit;6767+ else6868+ crval &= ~bit;6969+ writel(crval, mmio + IMX_P0PHYCR);7070+7171+ /* Wait for the cr_ack signal */7272+ do {7373+ srval = readl(mmio + IMX_P0PHYSR);7474+ if ((assert ? srval : ~srval) & IMX_P0PHYSR_CR_ACK)7575+ break;7676+ usleep_range(100, 200);7777+ } while (--timeout);7878+7979+ return timeout ? 0 : -ETIMEDOUT;8080+}8181+8282+static int imx_phy_reg_addressing(u16 addr, void __iomem *mmio)8383+{8484+ u32 crval = addr;8585+ int ret;8686+8787+ /* Supply the address on cr_data_in */8888+ writel(crval, mmio + IMX_P0PHYCR);8989+9090+ /* Assert the cr_cap_addr signal */9191+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_CAP_ADDR, true);9292+ if (ret)9393+ return ret;9494+9595+ /* Deassert cr_cap_addr */9696+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_CAP_ADDR, false);9797+ if (ret)9898+ return ret;9999+100100+ return 0;101101+}102102+103103+static int imx_phy_reg_write(u16 val, void __iomem *mmio)104104+{105105+ u32 crval = val;106106+ int ret;107107+108108+ /* Supply the data on cr_data_in */109109+ writel(crval, mmio + IMX_P0PHYCR);110110+111111+ /* Assert the cr_cap_data signal */112112+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_CAP_DATA, true);113113+ if (ret)114114+ return ret;115115+116116+ /* Deassert cr_cap_data */117117+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_CAP_DATA, false);118118+ if (ret)119119+ return ret;120120+121121+ if (val & IMX_CLOCK_RESET_RESET) {122122+ /*123123+ * In case we're resetting the phy, it's unable to acknowledge,124124+ * so we return immediately here.125125+ */126126+ crval |= IMX_P0PHYCR_CR_WRITE;127127+ writel(crval, mmio + IMX_P0PHYCR);128128+ goto out;129129+ }130130+131131+ /* Assert the cr_write signal */132132+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_WRITE, true);133133+ if (ret)134134+ return ret;135135+136136+ /* Deassert cr_write */137137+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_WRITE, false);138138+ if (ret)139139+ return ret;140140+141141+out:142142+ return 0;143143+}144144+145145+static int imx_phy_reg_read(u16 *val, void __iomem *mmio)146146+{147147+ int ret;148148+149149+ /* Assert the cr_read signal */150150+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_READ, true);151151+ if (ret)152152+ return ret;153153+154154+ /* Capture the data from cr_data_out[] */155155+ *val = readl(mmio + IMX_P0PHYSR) & IMX_P0PHYSR_CR_DATA_OUT;156156+157157+ /* Deassert cr_read */158158+ ret = imx_phy_crbit_assert(mmio, IMX_P0PHYCR_CR_READ, false);159159+ if (ret)160160+ return ret;161161+162162+ return 0;163163+}164164+165165+static int imx_sata_phy_reset(struct ahci_host_priv *hpriv)166166+{167167+ void __iomem *mmio = hpriv->mmio;168168+ int timeout = 10;169169+ u16 val;170170+ int ret;171171+172172+ /* Reset SATA PHY by setting RESET bit of PHY register CLOCK_RESET */173173+ ret = imx_phy_reg_addressing(IMX_CLOCK_RESET, mmio);174174+ if (ret)175175+ return ret;176176+ ret = imx_phy_reg_write(IMX_CLOCK_RESET_RESET, mmio);177177+ if (ret)178178+ return ret;179179+180180+ /* Wait for PHY RX_PLL to be stable */181181+ do {182182+ usleep_range(100, 200);183183+ ret = imx_phy_reg_addressing(IMX_LANE0_OUT_STAT, mmio);184184+ if (ret)185185+ return ret;186186+ ret = imx_phy_reg_read(&val, mmio);187187+ if (ret)188188+ return ret;189189+ if (val & IMX_LANE0_OUT_STAT_RX_PLL_STATE)190190+ break;191191+ } while (--timeout);192192+193193+ return timeout ? 0 : -ETIMEDOUT;194194+}195195+73196static int imx_sata_enable(struct ahci_host_priv *hpriv)74197{75198 struct imx_ahci_priv *imxpriv = hpriv->plat_data;199199+ struct device *dev = &imxpriv->ahci_pdev->dev;76200 int ret;7720178202 if (imxpriv->no_device)···257101 regmap_update_bits(imxpriv->gpr, IOMUXC_GPR13,258102 IMX6Q_GPR13_SATA_MPLL_CLK_EN,259103 IMX6Q_GPR13_SATA_MPLL_CLK_EN);104104+105105+ usleep_range(100, 200);106106+107107+ ret = imx_sata_phy_reset(hpriv);108108+ if (ret) {109109+ dev_err(dev, "failed to reset phy: %d\n", ret);110110+ goto disable_regulator;111111+ }260112 }261113262114 usleep_range(1000, 2000);···320156 * without full reset once the pddq mode is enabled making it321157 * impossible to use as part of libata LPM.322158 */323323- reg_val = readl(mmio + PORT_PHY_CTL);324324- writel(reg_val | PORT_PHY_CTL_PDDQ_LOC, mmio + PORT_PHY_CTL);159159+ reg_val = readl(mmio + IMX_P0PHYCR);160160+ writel(reg_val | IMX_P0PHYCR_TEST_PDDQ, mmio + IMX_P0PHYCR);325161 imx_sata_disable(hpriv);326162 imxpriv->no_device = true;327163}···381217 if (!imxpriv)382218 return -ENOMEM;383219220220+ imxpriv->ahci_pdev = pdev;384221 imxpriv->no_device = false;385222 imxpriv->first_time = true;386223 imxpriv->type = (enum ahci_imx_type)of_id->data;···413248414249 /*415250 * Configure the HWINIT bits of the HOST_CAP and HOST_PORTS_IMPL,416416- * and IP vendor specific register HOST_TIMER1MS.251251+ * and IP vendor specific register IMX_TIMER1MS.417252 * Configure CAP_SSS (support stagered spin up).418253 * Implement the port0.419254 * Get the ahb clock rate, and configure the TIMER1MS register.···430265 }431266432267 reg_val = clk_get_rate(imxpriv->ahb_clk) / 1000;433433- writel(reg_val, hpriv->mmio + HOST_TIMER1MS);268268+ writel(reg_val, hpriv->mmio + IMX_TIMER1MS);434269435270 ret = ahci_platform_init_host(pdev, hpriv, &ahci_imx_port_info, 0, 0);436271 if (ret)
+7
drivers/ata/libahci.c
···452452 cap &= ~HOST_CAP_SNTF;453453 }454454455455+ if ((cap2 & HOST_CAP2_SDS) && (hpriv->flags & AHCI_HFLAG_NO_DEVSLP)) {456456+ dev_info(dev,457457+ "controller can't do DEVSLP, turning off\n");458458+ cap2 &= ~HOST_CAP2_SDS;459459+ cap2 &= ~HOST_CAP2_SADM;460460+ }461461+455462 if (!(cap & HOST_CAP_FBS) && (hpriv->flags & AHCI_HFLAG_YES_FBS)) {456463 dev_info(dev, "controller can do FBS, turning on CAP_FBS\n");457464 cap |= HOST_CAP_FBS;
+9
drivers/ata/libata-core.c
···63146314static void ata_port_detach(struct ata_port *ap)63156315{63166316 unsigned long flags;63176317+ struct ata_link *link;63186318+ struct ata_device *dev;6317631963186320 if (!ap->ops->error_handler)63196321 goto skip_eh;···63356333 cancel_delayed_work_sync(&ap->hotplug_task);6336633463376335 skip_eh:63366336+ /* clean up zpodd on port removal */63376337+ ata_for_each_link(link, ap, HOST_FIRST) {63386338+ ata_for_each_dev(dev, link, ALL) {63396339+ if (zpodd_dev_enabled(dev))63406340+ zpodd_exit(dev);63416341+ }63426342+ }63386343 if (ap->pmp_link) {63396344 int i;63406345 for (i = 0; i < SATA_PMP_MAX_PORTS; i++)
+16-6
drivers/bus/mvebu-mbus.c
···5656#include <linux/of.h>5757#include <linux/of_address.h>5858#include <linux/debugfs.h>5959+#include <linux/log2.h>59606061/*6162 * DDR target is the same on all platforms.···223222 */224223 if ((u64)base < wend && end > wbase)225224 return 0;226226-227227- /*228228- * Check if target/attribute conflicts229229- */230230- if (target == wtarget && attr == wattr)231231- return 0;232225 }233226234227 return 1;···260265 void __iomem *addr = mbus->mbuswins_base +261266 mbus->soc->win_cfg_offset(win);262267 u32 ctrl, remap_addr;268268+269269+ if (!is_power_of_2(size)) {270270+ WARN(true, "Invalid MBus window size: 0x%zx\n", size);271271+ return -EINVAL;272272+ }273273+274274+ if ((base & (phys_addr_t)(size - 1)) != 0) {275275+ WARN(true, "Invalid MBus base/size: %pa len 0x%zx\n", &base,276276+ size);277277+ return -EINVAL;278278+ }263279264280 ctrl = ((size - 1) & WIN_CTRL_SIZE_MASK) |265281 (attr << WIN_CTRL_ATTR_SHIFT) |···418412 seq_printf(seq, "[%02d] %016llx - %016llx : %04x:%04x",419413 win, (unsigned long long)wbase,420414 (unsigned long long)(wbase + wsize), wtarget, wattr);415415+416416+ if (!is_power_of_2(wsize) ||417417+ ((wbase & (u64)(wsize - 1)) != 0))418418+ seq_puts(seq, " (Invalid base/size!!)");421419422420 if (win < mbus->soc->num_remappable_wins) {423421 seq_printf(seq, " (remap %016llx)\n",
···144144 return true;145145}146146147147+static int _round_up_table(const struct clk_div_table *table, int div)148148+{149149+ const struct clk_div_table *clkt;150150+ int up = _get_table_maxdiv(table);151151+152152+ for (clkt = table; clkt->div; clkt++) {153153+ if (clkt->div == div)154154+ return clkt->div;155155+ else if (clkt->div < div)156156+ continue;157157+158158+ if ((clkt->div - div) < (up - div))159159+ up = clkt->div;160160+ }161161+162162+ return up;163163+}164164+165165+static int _div_round_up(struct clk_divider *divider,166166+ unsigned long parent_rate, unsigned long rate)167167+{168168+ int div = DIV_ROUND_UP(parent_rate, rate);169169+170170+ if (divider->flags & CLK_DIVIDER_POWER_OF_TWO)171171+ div = __roundup_pow_of_two(div);172172+ if (divider->table)173173+ div = _round_up_table(divider->table, div);174174+175175+ return div;176176+}177177+147178static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,148179 unsigned long *best_parent_rate)149180{···190159191160 if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {192161 parent_rate = *best_parent_rate;193193- bestdiv = DIV_ROUND_UP(parent_rate, rate);162162+ bestdiv = _div_round_up(divider, parent_rate, rate);194163 bestdiv = bestdiv == 0 ? 1 : bestdiv;195164 bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;196165 return bestdiv;···250219 u32 val;251220252221 div = DIV_ROUND_UP(parent_rate, rate);222222+223223+ if (!_is_valid_div(divider, div))224224+ return -EINVAL;225225+253226 value = _get_val(divider, div);254227255228 if (value > div_mask(divider))
+32-42
drivers/clk/clk.c
···19841984}19851985EXPORT_SYMBOL_GPL(__clk_register);1986198619871987-static int _clk_register(struct device *dev, struct clk_hw *hw, struct clk *clk)19871987+/**19881988+ * clk_register - allocate a new clock, register it and return an opaque cookie19891989+ * @dev: device that is registering this clock19901990+ * @hw: link to hardware-specific clock data19911991+ *19921992+ * clk_register is the primary interface for populating the clock tree with new19931993+ * clock nodes. It returns a pointer to the newly allocated struct clk which19941994+ * cannot be dereferenced by driver code but may be used in conjuction with the19951995+ * rest of the clock API. In the event of an error clk_register will return an19961996+ * error code; drivers must test for an error code after calling clk_register.19971997+ */19981998+struct clk *clk_register(struct device *dev, struct clk_hw *hw)19881999{19892000 int i, ret;20012001+ struct clk *clk;20022002+20032003+ clk = kzalloc(sizeof(*clk), GFP_KERNEL);20042004+ if (!clk) {20052005+ pr_err("%s: could not allocate clk\n", __func__);20062006+ ret = -ENOMEM;20072007+ goto fail_out;20082008+ }1990200919912010 clk->name = kstrdup(hw->init->name, GFP_KERNEL);19922011 if (!clk->name) {···2045202620462027 ret = __clk_init(dev, clk);20472028 if (!ret)20482048- return 0;20292029+ return clk;2049203020502031fail_parent_names_copy:20512032 while (--i >= 0)···20542035fail_parent_names:20552036 kfree(clk->name);20562037fail_name:20572057- return ret;20582058-}20592059-20602060-/**20612061- * clk_register - allocate a new clock, register it and return an opaque cookie20622062- * @dev: device that is registering this clock20632063- * @hw: link to hardware-specific clock data20642064- *20652065- * clk_register is the primary interface for populating the clock tree with new20662066- * clock nodes. It returns a pointer to the newly allocated struct clk which20672067- * cannot be dereferenced by driver code but may be used in conjuction with the20682068- * rest of the clock API. In the event of an error clk_register will return an20692069- * error code; drivers must test for an error code after calling clk_register.20702070- */20712071-struct clk *clk_register(struct device *dev, struct clk_hw *hw)20722072-{20732073- int ret;20742074- struct clk *clk;20752075-20762076- clk = kzalloc(sizeof(*clk), GFP_KERNEL);20772077- if (!clk) {20782078- pr_err("%s: could not allocate clk\n", __func__);20792079- ret = -ENOMEM;20802080- goto fail_out;20812081- }20822082-20832083- ret = _clk_register(dev, hw, clk);20842084- if (!ret)20852085- return clk;20862086-20872038 kfree(clk);20882039fail_out:20892040 return ERR_PTR(ret);···2140215121412152 if (!hlist_empty(&clk->children)) {21422153 struct clk *child;21542154+ struct hlist_node *t;2143215521442156 /* Reparent all children to the orphan list. */21452145- hlist_for_each_entry(child, &clk->children, child_node)21572157+ hlist_for_each_entry_safe(child, t, &clk->children, child_node)21462158 clk_set_parent(child, NULL);21472159 }21482160···2163217321642174static void devm_clk_release(struct device *dev, void *res)21652175{21662166- clk_unregister(res);21762176+ clk_unregister(*(struct clk **)res);21672177}2168217821692179/**···21782188struct clk *devm_clk_register(struct device *dev, struct clk_hw *hw)21792189{21802190 struct clk *clk;21812181- int ret;21912191+ struct clk **clkp;2182219221832183- clk = devres_alloc(devm_clk_release, sizeof(*clk), GFP_KERNEL);21842184- if (!clk)21932193+ clkp = devres_alloc(devm_clk_release, sizeof(*clkp), GFP_KERNEL);21942194+ if (!clkp)21852195 return ERR_PTR(-ENOMEM);2186219621872187- ret = _clk_register(dev, hw, clk);21882188- if (!ret) {21892189- devres_add(dev, clk);21972197+ clk = clk_register(dev, hw);21982198+ if (!IS_ERR(clk)) {21992199+ *clkp = clk;22002200+ devres_add(dev, clkp);21902201 } else {21912191- devres_free(clk);21922192- clk = ERR_PTR(ret);22022202+ devres_free(clkp);21932203 }2194220421952205 return clk;
+7-2
drivers/clk/shmobile/clk-mstp.c
···156156static void __init cpg_mstp_clocks_init(struct device_node *np)157157{158158 struct mstp_clock_group *group;159159+ const char *idxname;159160 struct clk **clks;160161 unsigned int i;161162···185184 for (i = 0; i < MSTP_MAX_CLOCKS; ++i)186185 clks[i] = ERR_PTR(-ENOENT);187186187187+ if (of_find_property(np, "clock-indices", &i))188188+ idxname = "clock-indices";189189+ else190190+ idxname = "renesas,clock-indices";191191+188192 for (i = 0; i < MSTP_MAX_CLOCKS; ++i) {189193 const char *parent_name;190194 const char *name;···203197 continue;204198205199 parent_name = of_clk_get_parent_name(np, i);206206- ret = of_property_read_u32_index(np, "renesas,clock-indices", i,207207- &clkidx);200200+ ret = of_property_read_u32_index(np, idxname, i, &clkidx);208201 if (parent_name == NULL || ret < 0)209202 break;210203
···894894 dev_err(&spi->dev, "invalid spi-present-mask\n");895895 return -ENODEV;896896 }897897-898898- for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++)897897+ for (addr = 0; addr < ARRAY_SIZE(pdata->chip); addr++) {898898+ if ((spi_present_mask & (1 << addr)))899899+ chips++;899900 pullups[addr] = 0;901901+ }900902 } else {901903 type = spi_get_device_id(spi)->driver_data;902904 pdata = dev_get_platdata(&spi->dev);···921919 pullups[addr] = pdata->chip[addr].pullups;922920 }923921924924- if (!chips)925925- return -ENODEV;926926-927922 base = pdata->base;928923 }924924+925925+ if (!chips)926926+ return -ENODEV;929927930928 data = kzalloc(sizeof(*data) + chips * sizeof(struct mcp23s08),931929 GFP_KERNEL);
+38-14
drivers/gpu/drm/i915/intel_bios.c
···560560561561 dev_priv->vbt.edp_pps = *edp_pps;562562563563- dev_priv->vbt.edp_rate = edp_link_params->rate ? DP_LINK_BW_2_7 :564564- DP_LINK_BW_1_62;563563+ switch (edp_link_params->rate) {564564+ case EDP_RATE_1_62:565565+ dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;566566+ break;567567+ case EDP_RATE_2_7:568568+ dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;569569+ break;570570+ default:571571+ DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",572572+ edp_link_params->rate);573573+ break;574574+ }575575+565576 switch (edp_link_params->lanes) {566566- case 0:577577+ case EDP_LANE_1:567578 dev_priv->vbt.edp_lanes = 1;568579 break;569569- case 1:580580+ case EDP_LANE_2:570581 dev_priv->vbt.edp_lanes = 2;571582 break;572572- case 3:573573- default:583583+ case EDP_LANE_4:574584 dev_priv->vbt.edp_lanes = 4;575585 break;586586+ default:587587+ DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",588588+ edp_link_params->lanes);589589+ break;576590 }591591+577592 switch (edp_link_params->preemphasis) {578578- case 0:593593+ case EDP_PREEMPHASIS_NONE:579594 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;580595 break;581581- case 1:596596+ case EDP_PREEMPHASIS_3_5dB:582597 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;583598 break;584584- case 2:599599+ case EDP_PREEMPHASIS_6dB:585600 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;586601 break;587587- case 3:602602+ case EDP_PREEMPHASIS_9_5dB:588603 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;589604 break;605605+ default:606606+ DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",607607+ edp_link_params->preemphasis);608608+ break;590609 }610610+591611 switch (edp_link_params->vswing) {592592- case 0:612612+ case EDP_VSWING_0_4V:593613 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;594614 break;595595- case 1:615615+ case EDP_VSWING_0_6V:596616 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;597617 break;598598- case 2:618618+ case EDP_VSWING_0_8V:599619 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;600620 break;601601- case 3:621621+ case EDP_VSWING_1_2V:602622 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;623623+ break;624624+ default:625625+ DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",626626+ edp_link_params->vswing);603627 break;604628 }605629}
+46-9
drivers/gpu/drm/i915/intel_dp.c
···121121 return max_link_bw;122122}123123124124+static u8 intel_dp_max_lane_count(struct intel_dp *intel_dp)125125+{126126+ struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);127127+ struct drm_device *dev = intel_dig_port->base.base.dev;128128+ u8 source_max, sink_max;129129+130130+ source_max = 4;131131+ if (HAS_DDI(dev) && intel_dig_port->port == PORT_A &&132132+ (intel_dig_port->saved_port_bits & DDI_A_4_LANES) == 0)133133+ source_max = 2;134134+135135+ sink_max = drm_dp_max_lane_count(intel_dp->dpcd);136136+137137+ return min(source_max, sink_max);138138+}139139+124140/*125141 * The units on the numbers in the next two are... bizarre. Examples will126142 * make it clearer; this one parallels an example in the eDP spec.···187171 }188172189173 max_link_clock = drm_dp_bw_code_to_link_rate(intel_dp_max_link_bw(intel_dp));190190- max_lanes = drm_dp_max_lane_count(intel_dp->dpcd);174174+ max_lanes = intel_dp_max_lane_count(intel_dp);191175192176 max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);193177 mode_rate = intel_dp_link_required(target_clock, 18);···767751 struct intel_crtc *intel_crtc = encoder->new_crtc;768752 struct intel_connector *intel_connector = intel_dp->attached_connector;769753 int lane_count, clock;770770- int max_lane_count = drm_dp_max_lane_count(intel_dp->dpcd);754754+ int min_lane_count = 1;755755+ int max_lane_count = intel_dp_max_lane_count(intel_dp);771756 /* Conveniently, the link BW constants become indices with a shift...*/757757+ int min_clock = 0;772758 int max_clock = intel_dp_max_link_bw(intel_dp) >> 3;773759 int bpp, mode_rate;774760 static int bws[] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7, DP_LINK_BW_5_4 };···803785 /* Walk through all bpp values. Luckily they're all nicely spaced with 2804786 * bpc in between. */805787 bpp = pipe_config->pipe_bpp;806806- if (is_edp(intel_dp) && dev_priv->vbt.edp_bpp &&807807- dev_priv->vbt.edp_bpp < bpp) {808808- DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",809809- dev_priv->vbt.edp_bpp);810810- bpp = dev_priv->vbt.edp_bpp;788788+ if (is_edp(intel_dp)) {789789+ if (dev_priv->vbt.edp_bpp && dev_priv->vbt.edp_bpp < bpp) {790790+ DRM_DEBUG_KMS("clamping bpp for eDP panel to BIOS-provided %i\n",791791+ dev_priv->vbt.edp_bpp);792792+ bpp = dev_priv->vbt.edp_bpp;793793+ }794794+795795+ if (IS_BROADWELL(dev)) {796796+ /* Yes, it's an ugly hack. */797797+ min_lane_count = max_lane_count;798798+ DRM_DEBUG_KMS("forcing lane count to max (%u) on BDW\n",799799+ min_lane_count);800800+ } else if (dev_priv->vbt.edp_lanes) {801801+ min_lane_count = min(dev_priv->vbt.edp_lanes,802802+ max_lane_count);803803+ DRM_DEBUG_KMS("using min %u lanes per VBT\n",804804+ min_lane_count);805805+ }806806+807807+ if (dev_priv->vbt.edp_rate) {808808+ min_clock = min(dev_priv->vbt.edp_rate >> 3, max_clock);809809+ DRM_DEBUG_KMS("using min %02x link bw per VBT\n",810810+ bws[min_clock]);811811+ }811812 }812813813814 for (; bpp >= 6*3; bpp -= 2*3) {814815 mode_rate = intel_dp_link_required(adjusted_mode->crtc_clock,815816 bpp);816817817817- for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {818818- for (clock = 0; clock <= max_clock; clock++) {818818+ for (lane_count = min_lane_count; lane_count <= max_lane_count; lane_count <<= 1) {819819+ for (clock = min_clock; clock <= max_clock; clock++) {819820 link_clock = drm_dp_bw_code_to_link_rate(bws[clock]);820821 link_avail = intel_dp_max_data_rate(link_clock,821822 lane_count);
+9
drivers/gpu/drm/i915/intel_fbdev.c
···387387 height);388388 }389389390390+ /* No preferred mode marked by the EDID? Are there any modes? */391391+ if (!modes[i] && !list_empty(&connector->modes)) {392392+ DRM_DEBUG_KMS("using first mode listed on connector %s\n",393393+ drm_get_connector_name(connector));394394+ modes[i] = list_first_entry(&connector->modes,395395+ struct drm_display_mode,396396+ head);397397+ }398398+390399 /* last resort: use current mode */391400 if (!modes[i]) {392401 /*
+4-4
drivers/gpu/drm/i915/intel_panel.c
···492492 enum pipe pipe = intel_get_pipe_from_connector(connector);493493 u32 freq;494494 unsigned long flags;495495+ u64 n;495496496497 if (!panel->backlight.present || pipe == INVALID_PIPE)497498 return;···503502504503 /* scale to hardware max, but be careful to not overflow */505504 freq = panel->backlight.max;506506- if (freq < max)507507- level = level * freq / max;508508- else509509- level = freq / max * level;505505+ n = (u64)level * freq;506506+ do_div(n, max);507507+ level = n;510508511509 panel->backlight.level = level;512510 if (panel->backlight.device)
···99999910001000 dev->virtbase = devm_ioremap(&adev->dev, adev->res.start,10011001 resource_size(&adev->res));10021002- if (IS_ERR(dev->virtbase)) {10021002+ if (!dev->virtbase) {10031003 ret = -ENOMEM;10041004 goto err_no_mem;10051005 }
+1-1
drivers/i2c/busses/i2c-qup.c
···479479 int ret, idx;480480481481 ret = pm_runtime_get_sync(qup->dev);482482- if (ret)482482+ if (ret < 0)483483 goto out;484484485485 writel(1, qup->base + QUP_SW_RESET);
+8-1
drivers/i2c/busses/i2c-rcar.c
···561561562562 ret = -EINVAL;563563 for (i = 0; i < num; i++) {564564+ /* This HW can't send STOP after address phase */565565+ if (msgs[i].len == 0) {566566+ ret = -EOPNOTSUPP;567567+ break;568568+ }569569+564570 /*-------------- spin lock -----------------*/565571 spin_lock_irqsave(&priv->lock, flags);566572···631625632626static u32 rcar_i2c_func(struct i2c_adapter *adap)633627{634634- return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;628628+ /* This HW can't do SMBUS_QUICK and NOSTART */629629+ return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);635630}636631637632static const struct i2c_algorithm rcar_i2c_algo = {
···788788 * per device. But we can enable the exclusion range per789789 * device. This is done here790790 */791791- set_dev_entry_bit(m->devid, DEV_ENTRY_EX);791791+ set_dev_entry_bit(devid, DEV_ENTRY_EX);792792 iommu->exclusion_start = m->range_start;793793 iommu->exclusion_length = m->range_length;794794 }
···1919#include <linux/crypto.h>2020#include <linux/workqueue.h>2121#include <linux/backing-dev.h>2222-#include <linux/percpu.h>2322#include <linux/atomic.h>2423#include <linux/scatterlist.h>2524#include <asm/page.h>···4243 struct bvec_iter iter_out;4344 sector_t cc_sector;4445 atomic_t cc_pending;4646+ struct ablkcipher_request *req;4547};46484749/*···111111enum flags { DM_CRYPT_SUSPENDED, DM_CRYPT_KEY_VALID };112112113113/*114114- * Duplicated per-CPU state for cipher.115115- */116116-struct crypt_cpu {117117- struct ablkcipher_request *req;118118-};119119-120120-/*121121- * The fields in here must be read only after initialization,122122- * changing state should be in crypt_cpu.114114+ * The fields in here must be read only after initialization.123115 */124116struct crypt_config {125117 struct dm_dev *dev;···141149 } iv_gen_private;142150 sector_t iv_offset;143151 unsigned int iv_size;144144-145145- /*146146- * Duplicated per cpu state. Access through147147- * per_cpu_ptr() only.148148- */149149- struct crypt_cpu __percpu *cpu;150152151153 /* ESSIV: struct crypto_cipher *essiv_tfm */152154 void *iv_private;···177191static void clone_init(struct dm_crypt_io *, struct bio *);178192static void kcryptd_queue_crypt(struct dm_crypt_io *io);179193static u8 *iv_of_dmreq(struct crypt_config *cc, struct dm_crypt_request *dmreq);180180-181181-static struct crypt_cpu *this_crypt_config(struct crypt_config *cc)182182-{183183- return this_cpu_ptr(cc->cpu);184184-}185194186195/*187196 * Use this to access cipher attributes that are the same for each CPU.···884903static void crypt_alloc_req(struct crypt_config *cc,885904 struct convert_context *ctx)886905{887887- struct crypt_cpu *this_cc = this_crypt_config(cc);888906 unsigned key_index = ctx->cc_sector & (cc->tfms_count - 1);889907890890- if (!this_cc->req)891891- this_cc->req = mempool_alloc(cc->req_pool, GFP_NOIO);908908+ if (!ctx->req)909909+ ctx->req = mempool_alloc(cc->req_pool, GFP_NOIO);892910893893- ablkcipher_request_set_tfm(this_cc->req, cc->tfms[key_index]);894894- ablkcipher_request_set_callback(this_cc->req,911911+ ablkcipher_request_set_tfm(ctx->req, cc->tfms[key_index]);912912+ ablkcipher_request_set_callback(ctx->req,895913 CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,896896- kcryptd_async_done, dmreq_of_req(cc, this_cc->req));914914+ kcryptd_async_done, dmreq_of_req(cc, ctx->req));897915}898916899917/*···901921static int crypt_convert(struct crypt_config *cc,902922 struct convert_context *ctx)903923{904904- struct crypt_cpu *this_cc = this_crypt_config(cc);905924 int r;906925907926 atomic_set(&ctx->cc_pending, 1);···911932912933 atomic_inc(&ctx->cc_pending);913934914914- r = crypt_convert_block(cc, ctx, this_cc->req);935935+ r = crypt_convert_block(cc, ctx, ctx->req);915936916937 switch (r) {917938 /* async */···920941 reinit_completion(&ctx->restart);921942 /* fall through*/922943 case -EINPROGRESS:923923- this_cc->req = NULL;944944+ ctx->req = NULL;924945 ctx->cc_sector++;925946 continue;926947···10191040 io->sector = sector;10201041 io->error = 0;10211042 io->base_io = NULL;10431043+ io->ctx.req = NULL;10221044 atomic_set(&io->io_pending, 0);1023104510241046 return io;···10451065 if (!atomic_dec_and_test(&io->io_pending))10461066 return;1047106710681068+ if (io->ctx.req)10691069+ mempool_free(io->ctx.req, cc->req_pool);10481070 mempool_free(io, cc->io_pool);1049107110501072 if (likely(!base_io))···14741492static void crypt_dtr(struct dm_target *ti)14751493{14761494 struct crypt_config *cc = ti->private;14771477- struct crypt_cpu *cpu_cc;14781478- int cpu;1479149514801496 ti->private = NULL;14811497···14841504 destroy_workqueue(cc->io_queue);14851505 if (cc->crypt_queue)14861506 destroy_workqueue(cc->crypt_queue);14871487-14881488- if (cc->cpu)14891489- for_each_possible_cpu(cpu) {14901490- cpu_cc = per_cpu_ptr(cc->cpu, cpu);14911491- if (cpu_cc->req)14921492- mempool_free(cpu_cc->req, cc->req_pool);14931493- }1494150714951508 crypt_free_tfms(cc);14961509···1502152915031530 if (cc->dev)15041531 dm_put_device(ti, cc->dev);15051505-15061506- if (cc->cpu)15071507- free_percpu(cc->cpu);1508153215091533 kzfree(cc->cipher);15101534 kzfree(cc->cipher_string);···1557158715581588 if (tmp)15591589 DMWARN("Ignoring unexpected additional cipher options");15601560-15611561- cc->cpu = __alloc_percpu(sizeof(*(cc->cpu)),15621562- __alignof__(struct crypt_cpu));15631563- if (!cc->cpu) {15641564- ti->error = "Cannot allocate per cpu state";15651565- goto bad_mem;15661566- }1567159015681591 /*15691592 * For compatibility with the original dm-crypt mapping format, if
+1-1
drivers/md/dm-mpath.c
···15661566 }15671567 if (m->pg_init_required)15681568 __pg_init_all_paths(m);15691569- spin_unlock_irqrestore(&m->lock, flags);15701569 dm_table_run_md_queue_async(m->ti->table);15701570+ spin_unlock_irqrestore(&m->lock, flags);15711571 }1572157215731573 return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg);
+22-1
drivers/md/dm-thin.c
···2727#define MAPPING_POOL_SIZE 10242828#define PRISON_CELLS 10242929#define COMMIT_PERIOD HZ3030+#define NO_SPACE_TIMEOUT (HZ * 60)30313132DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(snapshot_copy_throttle,3233 "A percentage of time allocated for copy on write");···176175 struct workqueue_struct *wq;177176 struct work_struct worker;178177 struct delayed_work waker;178178+ struct delayed_work no_space_timeout;179179180180 unsigned long last_commit_jiffies;181181 unsigned ref_count;···937935{938936 int r;939937940940- if (get_pool_mode(pool) != PM_WRITE)938938+ if (get_pool_mode(pool) >= PM_READ_ONLY)941939 return -EINVAL;942940943941 r = dm_pool_commit_metadata(pool->pmd);···15921590 queue_delayed_work(pool->wq, &pool->waker, COMMIT_PERIOD);15931591}1594159215931593+/*15941594+ * We're holding onto IO to allow userland time to react. After the15951595+ * timeout either the pool will have been resized (and thus back in15961596+ * PM_WRITE mode), or we degrade to PM_READ_ONLY and start erroring IO.15971597+ */15981598+static void do_no_space_timeout(struct work_struct *ws)15991599+{16001600+ struct pool *pool = container_of(to_delayed_work(ws), struct pool,16011601+ no_space_timeout);16021602+16031603+ if (get_pool_mode(pool) == PM_OUT_OF_DATA_SPACE && !pool->pf.error_if_no_space)16041604+ set_pool_mode(pool, PM_READ_ONLY);16051605+}16061606+15951607/*----------------------------------------------------------------*/1596160815971609struct noflush_work {···17311715 pool->process_discard = process_discard;17321716 pool->process_prepared_mapping = process_prepared_mapping;17331717 pool->process_prepared_discard = process_prepared_discard_passdown;17181718+17191719+ if (!pool->pf.error_if_no_space)17201720+ queue_delayed_work(pool->wq, &pool->no_space_timeout, NO_SPACE_TIMEOUT);17341721 break;1735172217361723 case PM_WRITE:···2119210021202101 INIT_WORK(&pool->worker, do_worker);21212102 INIT_DELAYED_WORK(&pool->waker, do_waker);21032103+ INIT_DELAYED_WORK(&pool->no_space_timeout, do_no_space_timeout);21222104 spin_lock_init(&pool->lock);21232105 bio_list_init(&pool->deferred_flush_bios);21242106 INIT_LIST_HEAD(&pool->prepared_mappings);···26822662 struct pool *pool = pt->pool;2683266326842664 cancel_delayed_work(&pool->waker);26652665+ cancel_delayed_work(&pool->no_space_timeout);26852666 flush_workqueue(pool->wq);26862667 (void) commit(pool);26872668}
+2-1
drivers/md/md.c
···85168516 if (mddev_trylock(mddev)) {85178517 if (mddev->pers)85188518 __md_stop_writes(mddev);85198519- mddev->safemode = 2;85198519+ if (mddev->persistent)85208520+ mddev->safemode = 2;85208521 mddev_unlock(mddev);85218522 }85228523 need_delay = 1;
+7-6
drivers/md/raid10.c
···11721172 int max_sectors;11731173 int sectors;1174117411751175+ /*11761176+ * Register the new request and wait if the reconstruction11771177+ * thread has put up a bar for new requests.11781178+ * Continue immediately if no resync is active currently.11791179+ */11801180+ wait_barrier(conf);11811181+11751182 sectors = bio_sectors(bio);11761183 while (test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&11771184 bio->bi_iter.bi_sector < conf->reshape_progress &&···1559155215601553 md_write_start(mddev, bio);1561155415621562- /*15631563- * Register the new request and wait if the reconstruction15641564- * thread has put up a bar for new requests.15651565- * Continue immediately if no resync is active currently.15661566- */15671567- wait_barrier(conf);1568155515691556 do {15701557
+1-1
drivers/media/i2c/ov7670.c
···11091109 * windows that fall outside that.11101110 */11111111 for (i = 0; i < n_win_sizes; i++) {11121112- struct ov7670_win_size *win = &info->devtype->win_sizes[index];11121112+ struct ov7670_win_size *win = &info->devtype->win_sizes[i];11131113 if (info->min_width && win->width < info->min_width)11141114 continue;11151115 if (info->min_height && win->height < info->min_height)
+1-1
drivers/media/i2c/s5c73m3/s5c73m3-core.c
···16161616 if (ret < 0)16171617 return -EINVAL;1618161816191619- node_ep = v4l2_of_get_next_endpoint(node, NULL);16191619+ node_ep = of_graph_get_next_endpoint(node, NULL);16201620 if (!node_ep) {16211621 dev_warn(dev, "no endpoint defined for node: %s\n",16221622 node->full_name);
···178178179179static int __get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)180180{181181+ if (get_user(kp->type, &up->type))182182+ return -EFAULT;183183+181184 switch (kp->type) {182185 case V4L2_BUF_TYPE_VIDEO_CAPTURE:183186 case V4L2_BUF_TYPE_VIDEO_OUTPUT:···207204208205static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)209206{210210- if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||211211- get_user(kp->type, &up->type))212212- return -EFAULT;207207+ if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)))208208+ return -EFAULT;213209 return __get_v4l2_format32(kp, up);214210}215211216212static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)217213{218214 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||219219- copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt)))220220- return -EFAULT;215215+ copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format)))216216+ return -EFAULT;221217 return __get_v4l2_format32(&kp->format, &up->format);222218}223219
+13-2
drivers/memory/mvebu-devbus.c
···108108 node->full_name);109109 return err;110110 }111111- /* Convert bit width to byte width */112112- r.bus_width /= 8;111111+112112+ /*113113+ * The bus width is encoded into the register as 0 for 8 bits,114114+ * and 1 for 16 bits, so we do the necessary conversion here.115115+ */116116+ if (r.bus_width == 8)117117+ r.bus_width = 0;118118+ else if (r.bus_width == 16)119119+ r.bus_width = 1;120120+ else {121121+ dev_err(devbus->dev, "invalid bus width %d\n", r.bus_width);122122+ return -EINVAL;123123+ }113124114125 err = get_timing_param_ps(devbus, node, "devbus,badr-skew-ps",115126 &r.badr_skew);
+4
drivers/of/base.c
···18311831 if (!found)18321832 return -ENODEV;1833183318341834+ /* At early boot, bail out and defer setup to of_init() */18351835+ if (!of_kset)18361836+ return found ? 0 : -ENODEV;18371837+18341838 /* Update the sysfs attribute */18351839 sysfs_remove_bin_file(&np->kobj, &oldprop->attr);18361840 __of_add_property_sysfs(np, newprop);
+76-16
drivers/pci/host/pci-mvebu.c
···293293 return PCIBIOS_SUCCESSFUL;294294}295295296296+/*297297+ * Remove windows, starting from the largest ones to the smallest298298+ * ones.299299+ */300300+static void mvebu_pcie_del_windows(struct mvebu_pcie_port *port,301301+ phys_addr_t base, size_t size)302302+{303303+ while (size) {304304+ size_t sz = 1 << (fls(size) - 1);305305+306306+ mvebu_mbus_del_window(base, sz);307307+ base += sz;308308+ size -= sz;309309+ }310310+}311311+312312+/*313313+ * MBus windows can only have a power of two size, but PCI BARs do not314314+ * have this constraint. Therefore, we have to split the PCI BAR into315315+ * areas each having a power of two size. We start from the largest316316+ * one (i.e highest order bit set in the size).317317+ */318318+static void mvebu_pcie_add_windows(struct mvebu_pcie_port *port,319319+ unsigned int target, unsigned int attribute,320320+ phys_addr_t base, size_t size,321321+ phys_addr_t remap)322322+{323323+ size_t size_mapped = 0;324324+325325+ while (size) {326326+ size_t sz = 1 << (fls(size) - 1);327327+ int ret;328328+329329+ ret = mvebu_mbus_add_window_remap_by_id(target, attribute, base,330330+ sz, remap);331331+ if (ret) {332332+ dev_err(&port->pcie->pdev->dev,333333+ "Could not create MBus window at 0x%x, size 0x%x: %d\n",334334+ base, sz, ret);335335+ mvebu_pcie_del_windows(port, base - size_mapped,336336+ size_mapped);337337+ return;338338+ }339339+340340+ size -= sz;341341+ size_mapped += sz;342342+ base += sz;343343+ if (remap != MVEBU_MBUS_NO_REMAP)344344+ remap += sz;345345+ }346346+}347347+296348static void mvebu_pcie_handle_iobase_change(struct mvebu_pcie_port *port)297349{298350 phys_addr_t iobase;···356304357305 /* If a window was configured, remove it */358306 if (port->iowin_base) {359359- mvebu_mbus_del_window(port->iowin_base,360360- port->iowin_size);307307+ mvebu_pcie_del_windows(port, port->iowin_base,308308+ port->iowin_size);361309 port->iowin_base = 0;362310 port->iowin_size = 0;363311 }···383331 port->iowin_base = port->pcie->io.start + iobase;384332 port->iowin_size = ((0xFFF | ((port->bridge.iolimit & 0xF0) << 8) |385333 (port->bridge.iolimitupper << 16)) -386386- iobase);334334+ iobase) + 1;387335388388- mvebu_mbus_add_window_remap_by_id(port->io_target, port->io_attr,389389- port->iowin_base, port->iowin_size,390390- iobase);336336+ mvebu_pcie_add_windows(port, port->io_target, port->io_attr,337337+ port->iowin_base, port->iowin_size,338338+ iobase);391339}392340393341static void mvebu_pcie_handle_membase_change(struct mvebu_pcie_port *port)···398346399347 /* If a window was configured, remove it */400348 if (port->memwin_base) {401401- mvebu_mbus_del_window(port->memwin_base,402402- port->memwin_size);349349+ mvebu_pcie_del_windows(port, port->memwin_base,350350+ port->memwin_size);403351 port->memwin_base = 0;404352 port->memwin_size = 0;405353 }···416364 port->memwin_base = ((port->bridge.membase & 0xFFF0) << 16);417365 port->memwin_size =418366 (((port->bridge.memlimit & 0xFFF0) << 16) | 0xFFFFF) -419419- port->memwin_base;367367+ port->memwin_base + 1;420368421421- mvebu_mbus_add_window_by_id(port->mem_target, port->mem_attr,422422- port->memwin_base, port->memwin_size);369369+ mvebu_pcie_add_windows(port, port->mem_target, port->mem_attr,370370+ port->memwin_base, port->memwin_size,371371+ MVEBU_MBUS_NO_REMAP);423372}424373425374/*···796743797744 /*798745 * On the PCI-to-PCI bridge side, the I/O windows must have at799799- * least a 64 KB size and be aligned on their size, and the800800- * memory windows must have at least a 1 MB size and be801801- * aligned on their size746746+ * least a 64 KB size and the memory windows must have at747747+ * least a 1 MB size. Moreover, MBus windows need to have a748748+ * base address aligned on their size, and their size must be749749+ * a power of two. This means that if the BAR doesn't have a750750+ * power of two size, several MBus windows will actually be751751+ * created. We need to ensure that the biggest MBus window752752+ * (which will be the first one) is aligned on its size, which753753+ * explains the rounddown_pow_of_two() being done here.802754 */803755 if (res->flags & IORESOURCE_IO)804804- return round_up(start, max_t(resource_size_t, SZ_64K, size));756756+ return round_up(start, max_t(resource_size_t, SZ_64K,757757+ rounddown_pow_of_two(size)));805758 else if (res->flags & IORESOURCE_MEM)806806- return round_up(start, max_t(resource_size_t, SZ_1M, size));759759+ return round_up(start, max_t(resource_size_t, SZ_1M,760760+ rounddown_pow_of_two(size)));807761 else808762 return start;809763}
+2-2
drivers/pci/hotplug/shpchp_ctrl.c
···282282 return WRONG_BUS_FREQUENCY;283283 }284284285285- bsp = ctrl->pci_dev->bus->cur_bus_speed;286286- msp = ctrl->pci_dev->bus->max_bus_speed;285285+ bsp = ctrl->pci_dev->subordinate->cur_bus_speed;286286+ msp = ctrl->pci_dev->subordinate->max_bus_speed;287287288288 /* Check if there are other slots or devices on the same bus */289289 if (!list_empty(&ctrl->pci_dev->subordinate->devices))
+3-2
drivers/pci/pci.c
···30673067 if (!pci_is_pcie(dev))30683068 return 1;3069306930703070- return pci_wait_for_pending(dev, PCI_EXP_DEVSTA, PCI_EXP_DEVSTA_TRPND);30703070+ return pci_wait_for_pending(dev, pci_pcie_cap(dev) + PCI_EXP_DEVSTA,30713071+ PCI_EXP_DEVSTA_TRPND);30713072}30723073EXPORT_SYMBOL(pci_wait_for_pending_transaction);30733074···31103109 return 0;3111311031123111 /* Wait for Transaction Pending bit clean */31133113- if (pci_wait_for_pending(dev, PCI_AF_STATUS, PCI_AF_STATUS_TP))31123112+ if (pci_wait_for_pending(dev, pos + PCI_AF_STATUS, PCI_AF_STATUS_TP))31143113 goto clear;3115311431163115 dev_err(&dev->dev, "transaction is not cleared; "
+3
drivers/rtc/rtc-hym8563.c
···569569 if (IS_ERR(hym8563->rtc))570570 return PTR_ERR(hym8563->rtc);571571572572+ /* the hym8563 alarm only supports a minute accuracy */573573+ hym8563->rtc->uie_unsupported = 1;574574+572575#ifdef CONFIG_COMMON_CLK573576 hym8563_clkout_register_clk(hym8563);574577#endif
+8-6
drivers/sh/Makefile
···11#22# Makefile for the SuperH specific drivers.33#44-obj-y := intc/44+obj-$(CONFIG_SUPERH) += intc/55+obj-$(CONFIG_ARCH_SHMOBILE_LEGACY) += intc/66+ifneq ($(CONFIG_COMMON_CLK),y)77+obj-$(CONFIG_HAVE_CLK) += clk/88+endif99+obj-$(CONFIG_MAPLE) += maple/1010+obj-$(CONFIG_SUPERHYWAY) += superhyway/51166-obj-$(CONFIG_HAVE_CLK) += clk/77-obj-$(CONFIG_MAPLE) += maple/88-obj-$(CONFIG_SUPERHYWAY) += superhyway/99-1010-obj-y += pm_runtime.o1212+obj-y += pm_runtime.o
···2929 struct sg_table *sgt;3030 void *buf, *pbuf;31313232- /*3333- * Some DMA controllers have problems transferring buffers that are3434- * not multiple of 4 bytes. So we truncate the transfer so that it3535- * is suitable for such controllers, and handle the trailing bytes3636- * manually after the DMA completes.3737- *3838- * REVISIT: It would be better if this information could be3939- * retrieved directly from the DMA device in a similar way than4040- * ->copy_align etc. is done.4141- */4242- len = ALIGN(drv_data->len, 4);4343-4432 if (dir == DMA_TO_DEVICE) {4533 dmadev = drv_data->tx_chan->device->dev;4634 sgt = &drv_data->tx_sgt;···132144 if (!error) {133145 pxa2xx_spi_unmap_dma_buffers(drv_data);134146135135- /* Handle the last bytes of unaligned transfer */136147 drv_data->tx += drv_data->tx_map_len;137137- drv_data->write(drv_data);138138-139148 drv_data->rx += drv_data->rx_map_len;140140- drv_data->read(drv_data);141149142150 msg->actual_length += drv_data->len;143151 msg->state = pxa2xx_spi_next_transfer(drv_data);
+1-1
drivers/spi/spi-qup.c
···734734 int ret;735735736736 ret = pm_runtime_get_sync(&pdev->dev);737737- if (ret)737737+ if (ret < 0)738738 return ret;739739740740 ret = spi_qup_set_state(controller, QUP_STATE_RESET);
+77-47
drivers/spi/spi.c
···580580 spi->master->set_cs(spi, !enable);581581}582582583583+#ifdef CONFIG_HAS_DMA583584static int spi_map_buf(struct spi_master *master, struct device *dev,584585 struct sg_table *sgt, void *buf, size_t len,585586 enum dma_data_direction dir)···638637 }639638}640639641641-static int spi_map_msg(struct spi_master *master, struct spi_message *msg)640640+static int __spi_map_msg(struct spi_master *master, struct spi_message *msg)642641{643642 struct device *tx_dev, *rx_dev;644643 struct spi_transfer *xfer;645645- void *tmp;646646- unsigned int max_tx, max_rx;647644 int ret;648648-649649- if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) {650650- max_tx = 0;651651- max_rx = 0;652652-653653- list_for_each_entry(xfer, &msg->transfers, transfer_list) {654654- if ((master->flags & SPI_MASTER_MUST_TX) &&655655- !xfer->tx_buf)656656- max_tx = max(xfer->len, max_tx);657657- if ((master->flags & SPI_MASTER_MUST_RX) &&658658- !xfer->rx_buf)659659- max_rx = max(xfer->len, max_rx);660660- }661661-662662- if (max_tx) {663663- tmp = krealloc(master->dummy_tx, max_tx,664664- GFP_KERNEL | GFP_DMA);665665- if (!tmp)666666- return -ENOMEM;667667- master->dummy_tx = tmp;668668- memset(tmp, 0, max_tx);669669- }670670-671671- if (max_rx) {672672- tmp = krealloc(master->dummy_rx, max_rx,673673- GFP_KERNEL | GFP_DMA);674674- if (!tmp)675675- return -ENOMEM;676676- master->dummy_rx = tmp;677677- }678678-679679- if (max_tx || max_rx) {680680- list_for_each_entry(xfer, &msg->transfers,681681- transfer_list) {682682- if (!xfer->tx_buf)683683- xfer->tx_buf = master->dummy_tx;684684- if (!xfer->rx_buf)685685- xfer->rx_buf = master->dummy_rx;686686- }687687- }688688- }689645690646 if (!master->can_dma)691647 return 0;···699741 }700742701743 return 0;744744+}745745+#else /* !CONFIG_HAS_DMA */746746+static inline int __spi_map_msg(struct spi_master *master,747747+ struct spi_message *msg)748748+{749749+ return 0;750750+}751751+752752+static inline int spi_unmap_msg(struct spi_master *master,753753+ struct spi_message *msg)754754+{755755+ return 0;756756+}757757+#endif /* !CONFIG_HAS_DMA */758758+759759+static int spi_map_msg(struct spi_master *master, struct spi_message *msg)760760+{761761+ struct spi_transfer *xfer;762762+ void *tmp;763763+ unsigned int max_tx, max_rx;764764+765765+ if (master->flags & (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX)) {766766+ max_tx = 0;767767+ max_rx = 0;768768+769769+ list_for_each_entry(xfer, &msg->transfers, transfer_list) {770770+ if ((master->flags & SPI_MASTER_MUST_TX) &&771771+ !xfer->tx_buf)772772+ max_tx = max(xfer->len, max_tx);773773+ if ((master->flags & SPI_MASTER_MUST_RX) &&774774+ !xfer->rx_buf)775775+ max_rx = max(xfer->len, max_rx);776776+ }777777+778778+ if (max_tx) {779779+ tmp = krealloc(master->dummy_tx, max_tx,780780+ GFP_KERNEL | GFP_DMA);781781+ if (!tmp)782782+ return -ENOMEM;783783+ master->dummy_tx = tmp;784784+ memset(tmp, 0, max_tx);785785+ }786786+787787+ if (max_rx) {788788+ tmp = krealloc(master->dummy_rx, max_rx,789789+ GFP_KERNEL | GFP_DMA);790790+ if (!tmp)791791+ return -ENOMEM;792792+ master->dummy_rx = tmp;793793+ }794794+795795+ if (max_tx || max_rx) {796796+ list_for_each_entry(xfer, &msg->transfers,797797+ transfer_list) {798798+ if (!xfer->tx_buf)799799+ xfer->tx_buf = master->dummy_tx;800800+ if (!xfer->rx_buf)801801+ xfer->rx_buf = master->dummy_rx;802802+ }803803+ }804804+ }805805+806806+ return __spi_map_msg(master, msg);702807}703808704809/*···11721151{11731152 int ret;1174115311751175- master->queued = true;11761154 master->transfer = spi_queued_transfer;11771155 if (!master->transfer_one_message)11781156 master->transfer_one_message = spi_transfer_one_message;···11821162 dev_err(&master->dev, "problem initializing queue\n");11831163 goto err_init_queue;11841164 }11651165+ master->queued = true;11851166 ret = spi_start_queue(master);11861167 if (ret) {11871168 dev_err(&master->dev, "problem starting queue\n");···11921171 return 0;1193117211941173err_start_queue:11951195-err_init_queue:11961174 spi_destroy_queue(master);11751175+err_init_queue:11971176 return ret;11981177}11991178···17771756 */17781757int spi_setup(struct spi_device *spi)17791758{17801780- unsigned bad_bits;17591759+ unsigned bad_bits, ugly_bits;17811760 int status = 0;1782176117831762 /* check mode to prevent that DUAL and QUAD set at the same time···17971776 * that aren't supported with their current master17981777 */17991778 bad_bits = spi->mode & ~spi->master->mode_bits;17791779+ ugly_bits = bad_bits &17801780+ (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD);17811781+ if (ugly_bits) {17821782+ dev_warn(&spi->dev,17831783+ "setup: ignoring unsupported mode bits %x\n",17841784+ ugly_bits);17851785+ spi->mode &= ~ugly_bits;17861786+ bad_bits &= ~ugly_bits;17871787+ }18001788 if (bad_bits) {18011789 dev_err(&spi->dev, "setup: unsupported mode bits %x\n",18021790 bad_bits);
+6-1
drivers/staging/imx-drm/imx-drm-core.c
···517517 of_node_put(port);518518 if (port == imx_crtc->port) {519519 ret = of_graph_parse_endpoint(ep, &endpoint);520520- return ret ? ret : endpoint.id;520520+ return ret ? ret : endpoint.port;521521 }522522 } while (ep);523523···673673 for_each_child_of_node(port, ep) {674674 remote = of_graph_get_remote_port_parent(ep);675675 if (!remote || !of_device_is_available(remote)) {676676+ of_node_put(remote);677677+ continue;678678+ } else if (!of_device_is_available(remote->parent)) {679679+ dev_warn(&pdev->dev, "parent device of %s is not available\n",680680+ remote->full_name);676681 of_node_put(remote);677682 continue;678683 }
···798798 pr_err("emulate_write_cache not supported for pSCSI\n");799799 return -EINVAL;800800 }801801- if (dev->transport->get_write_cache) {802802- pr_warn("emulate_write_cache cannot be changed when underlying"803803- " HW reports WriteCacheEnabled, ignoring request\n");804804- return 0;801801+ if (flag &&802802+ dev->transport->get_write_cache) {803803+ pr_err("emulate_write_cache not supported for this device\n");804804+ return -EINVAL;805805 }806806807807 dev->dev_attrib.emulate_write_cache = flag;···936936 return 0;937937 }938938 if (!dev->transport->init_prot || !dev->transport->free_prot) {939939+ /* 0 is only allowed value for non-supporting backends */940940+ if (flag == 0)941941+ return 0;942942+939943 pr_err("DIF protection not supported by backend: %s\n",940944 dev->transport->name);941945 return -ENOSYS;
+1-1
drivers/target/target_core_transport.c
···11131113 init_completion(&cmd->cmd_wait_comp);11141114 init_completion(&cmd->task_stop_comp);11151115 spin_lock_init(&cmd->t_state_lock);11161116+ kref_init(&cmd->cmd_kref);11161117 cmd->transport_state = CMD_T_DEV_ACTIVE;1117111811181119 cmd->se_tfo = tfo;···23582357 unsigned long flags;23592358 int ret = 0;2360235923612361- kref_init(&se_cmd->cmd_kref);23622360 /*23632361 * Add a second kref if the fabric caller is expecting to handle23642362 * fabric acknowledgement that requires two target_put_sess_cmd()
+4-4
drivers/target/tcm_fc/tfc_cmd.c
···9090{9191 struct fc_frame *fp;9292 struct fc_lport *lport;9393- struct se_session *se_sess;9393+ struct ft_sess *sess;94949595 if (!cmd)9696 return;9797- se_sess = cmd->sess->se_sess;9797+ sess = cmd->sess;9898 fp = cmd->req_frame;9999 lport = fr_dev(fp);100100 if (fr_seq(fp))101101 lport->tt.seq_release(fr_seq(fp));102102 fc_frame_free(fp);103103- percpu_ida_free(&se_sess->sess_tag_pool, cmd->se_cmd.map_tag);104104- ft_sess_put(cmd->sess); /* undo get from lookup at recv */103103+ percpu_ida_free(&sess->se_sess->sess_tag_pool, cmd->se_cmd.map_tag);104104+ ft_sess_put(sess); /* undo get from lookup at recv */105105}106106107107void ft_release_cmd(struct se_cmd *se_cmd)
···657657 unsigned long rlim_stack;658658659659#ifdef CONFIG_STACK_GROWSUP660660- /* Limit stack size to 1GB */660660+ /* Limit stack size */661661 stack_base = rlimit_max(RLIMIT_STACK);662662- if (stack_base > (1 << 30))663663- stack_base = 1 << 30;662662+ if (stack_base > STACK_SIZE_MAX)663663+ stack_base = STACK_SIZE_MAX;664664665665 /* Make sure we didn't let the argument array grow too large. */666666 if (vma->vm_end - vma->vm_start > stack_base)
+10-7
fs/kernfs/file.c
···610610static int kernfs_fop_open(struct inode *inode, struct file *file)611611{612612 struct kernfs_node *kn = file->f_path.dentry->d_fsdata;613613+ struct kernfs_root *root = kernfs_root(kn);613614 const struct kernfs_ops *ops;614615 struct kernfs_open_file *of;615616 bool has_read, has_write, has_mmap;···625624 has_write = ops->write || ops->mmap;626625 has_mmap = ops->mmap;627626628628- /* check perms and supported operations */629629- if ((file->f_mode & FMODE_WRITE) &&630630- (!(inode->i_mode & S_IWUGO) || !has_write))631631- goto err_out;627627+ /* see the flag definition for details */628628+ if (root->flags & KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK) {629629+ if ((file->f_mode & FMODE_WRITE) &&630630+ (!(inode->i_mode & S_IWUGO) || !has_write))631631+ goto err_out;632632633633- if ((file->f_mode & FMODE_READ) &&634634- (!(inode->i_mode & S_IRUGO) || !has_read))635635- goto err_out;633633+ if ((file->f_mode & FMODE_READ) &&634634+ (!(inode->i_mode & S_IRUGO) || !has_read))635635+ goto err_out;636636+ }636637637638 /* allocate a kernfs_open_file for the file */638639 error = -ENOMEM;
+24-12
fs/locks.c
···389389 fl->fl_ops = NULL;390390 fl->fl_lmops = NULL;391391392392- /* Ensure that fl->fl_filp has compatible f_mode */393393- switch (l->l_type) {394394- case F_RDLCK:395395- if (!(filp->f_mode & FMODE_READ))396396- return -EBADF;397397- break;398398- case F_WRLCK:399399- if (!(filp->f_mode & FMODE_WRITE))400400- return -EBADF;401401- break;402402- }403403-404392 return assign_type(fl, l->l_type);405393}406394···20222034 return error;20232035}2024203620372037+/* Ensure that fl->fl_filp has compatible f_mode for F_SETLK calls */20382038+static int20392039+check_fmode_for_setlk(struct file_lock *fl)20402040+{20412041+ switch (fl->fl_type) {20422042+ case F_RDLCK:20432043+ if (!(fl->fl_file->f_mode & FMODE_READ))20442044+ return -EBADF;20452045+ break;20462046+ case F_WRLCK:20472047+ if (!(fl->fl_file->f_mode & FMODE_WRITE))20482048+ return -EBADF;20492049+ }20502050+ return 0;20512051+}20522052+20252053/* Apply the lock described by l to an open file descriptor.20262054 * This implements both the F_SETLK and F_SETLKW commands of fcntl().20272055 */···2072206820732069again:20742070 error = flock_to_posix_lock(filp, file_lock, &flock);20712071+ if (error)20722072+ goto out;20732073+20742074+ error = check_fmode_for_setlk(file_lock);20752075 if (error)20762076 goto out;20772077···2211220322122204again:22132205 error = flock64_to_posix_lock(filp, file_lock, &flock);22062206+ if (error)22072207+ goto out;22082208+22092209+ error = check_fmode_for_setlk(file_lock);22142210 if (error)22152211 goto out;22162212
+9-8
fs/nfsd/nfs4acl.c
···402402 * by uid/gid. */403403 int i, j;404404405405- if (pacl->a_count <= 4)406406- return; /* no users or groups */405405+ /* no users or groups */406406+ if (!pacl || pacl->a_count <= 4)407407+ return;408408+407409 i = 1;408410 while (pacl->a_entries[i].e_tag == ACL_USER)409411 i++;···532530533531 /*534532 * ACLs with no ACEs are treated differently in the inheritable535535- * and effective cases: when there are no inheritable ACEs, we536536- * set a zero-length default posix acl:533533+ * and effective cases: when there are no inheritable ACEs,534534+ * calls ->set_acl with a NULL ACL structure.537535 */538538- if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT)) {539539- pacl = posix_acl_alloc(0, GFP_KERNEL);540540- return pacl ? pacl : ERR_PTR(-ENOMEM);541541- }536536+ if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT))537537+ return NULL;538538+542539 /*543540 * When there are no effective ACEs, the following will end544541 * up setting a 3-element effective posix ACL with all
···473473};474474475475extern struct cgroup_root cgrp_dfl_root;476476+extern struct css_set init_css_set;476477477478static inline bool cgroup_on_dfl(const struct cgroup *cgrp)478479{···699698 int subsys_id)700699{701700 return task_css_check(task, subsys_id, false);701701+}702702+703703+/**704704+ * task_css_is_root - test whether a task belongs to the root css705705+ * @task: the target task706706+ * @subsys_id: the target subsystem ID707707+ *708708+ * Test whether @task belongs to the root css on the specified subsystem.709709+ * May be invoked in any context.710710+ */711711+static inline bool task_css_is_root(struct task_struct *task, int subsys_id)712712+{713713+ return task_css_check(task, subsys_id, true) ==714714+ init_css_set.subsys[subsys_id];702715}703716704717static inline struct cgroup *task_cgroup(struct task_struct *task,
···272272 return -EINVAL;273273}274274275275+static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)276276+{277277+ return 0;278278+}279279+275280static inline int irq_can_set_affinity(unsigned int irq)276281{277282 return 0;
+18-1
include/linux/kernfs.h
···50505151/* @flags for kernfs_create_root() */5252enum kernfs_root_flag {5353- KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001,5353+ /*5454+ * kernfs_nodes are created in the deactivated state and invisible.5555+ * They require explicit kernfs_activate() to become visible. This5656+ * can be used to make related nodes become visible atomically5757+ * after all nodes are created successfully.5858+ */5959+ KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001,6060+6161+ /*6262+ * For regular flies, if the opener has CAP_DAC_OVERRIDE, open(2)6363+ * succeeds regardless of the RW permissions. sysfs had an extra6464+ * layer of enforcement where open(2) fails with -EACCES regardless6565+ * of CAP_DAC_OVERRIDE if the permission doesn't have the6666+ * respective read or write access at all (none of S_IRUGO or6767+ * S_IWUGO) or the respective operation isn't implemented. The6868+ * following flag enables that behavior.6969+ */7070+ KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002,5471};55725673/* type-specific structures for kernfs_node union members */
···9494 SNDRV_HWDEP_IFACE_HDA, /* HD-audio */9595 SNDRV_HWDEP_IFACE_USB_STREAM, /* direct access to usb stream */9696 SNDRV_HWDEP_IFACE_FW_DICE, /* TC DICE FireWire device */9797+ SNDRV_HWDEP_IFACE_FW_FIREWORKS, /* Echo Audio Fireworks based device */9898+ SNDRV_HWDEP_IFACE_FW_BEBOB, /* BridgeCo BeBoB based device */979998100 /* Don't forget to change the following: */9999- SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_DICE101101+ SNDRV_HWDEP_IFACE_LAST = SNDRV_HWDEP_IFACE_FW_BEBOB100102};101103102104struct snd_hwdep_info {
+22-1
include/uapi/sound/firewire.h
···22#define _UAPI_SOUND_FIREWIRE_H_INCLUDED3344#include <linux/ioctl.h>55+#include <linux/types.h>5667/* events can be read() from the hwdep device */7889#define SNDRV_FIREWIRE_EVENT_LOCK_STATUS 0x000010cc910#define SNDRV_FIREWIRE_EVENT_DICE_NOTIFICATION 0xd1ce004e1111+#define SNDRV_FIREWIRE_EVENT_EFW_RESPONSE 0x4e61747510121113struct snd_firewire_event_common {1214 unsigned int type; /* SNDRV_FIREWIRE_EVENT_xxx */···2422 unsigned int notification; /* DICE-specific bits */2523};26242525+#define SND_EFW_TRANSACTION_USER_SEQNUM_MAX ((__u32)((__u16)~0) - 1)2626+/* each field should be in big endian */2727+struct snd_efw_transaction {2828+ __be32 length;2929+ __be32 version;3030+ __be32 seqnum;3131+ __be32 category;3232+ __be32 command;3333+ __be32 status;3434+ __be32 params[0];3535+};3636+struct snd_firewire_event_efw_response {3737+ unsigned int type;3838+ __be32 response[0]; /* some responses */3939+};4040+2741union snd_firewire_event {2842 struct snd_firewire_event_common common;2943 struct snd_firewire_event_lock_status lock_status;3044 struct snd_firewire_event_dice_notification dice_notification;4545+ struct snd_firewire_event_efw_response efw_response;3146};32473348···5334#define SNDRV_FIREWIRE_IOCTL_UNLOCK _IO('H', 0xfa)54355536#define SNDRV_FIREWIRE_TYPE_DICE 15656-/* Fireworks, AV/C, RME, MOTU, ... */3737+#define SNDRV_FIREWIRE_TYPE_FIREWORKS 23838+#define SNDRV_FIREWIRE_TYPE_BEBOB 33939+/* AV/C, RME, MOTU, ... */57405841struct snd_firewire_get_info {5942 unsigned int type; /* SNDRV_FIREWIRE_TYPE_xxx */
+5-5
kernel/cgroup.c
···348348 * reference-counted, to improve performance when child cgroups349349 * haven't been created.350350 */351351-static struct css_set init_css_set = {351351+struct css_set init_css_set = {352352 .refcount = ATOMIC_INIT(1),353353 .cgrp_links = LIST_HEAD_INIT(init_css_set.cgrp_links),354354 .tasks = LIST_HEAD_INIT(init_css_set.tasks),···14951495 */14961496 if (!use_task_css_set_links)14971497 cgroup_enable_task_cg_lists();14981498-retry:14981498+14991499 mutex_lock(&cgroup_tree_mutex);15001500 mutex_lock(&cgroup_mutex);15011501···15031503 ret = parse_cgroupfs_options(data, &opts);15041504 if (ret)15051505 goto out_unlock;15061506-15061506+retry:15071507 /* look for a matching existing root */15081508 if (!opts.subsys_mask && !opts.none && !opts.name) {15091509 cgrp_dfl_root_visible = true;···15621562 if (!atomic_inc_not_zero(&root->cgrp.refcnt)) {15631563 mutex_unlock(&cgroup_mutex);15641564 mutex_unlock(&cgroup_tree_mutex);15651565- kfree(opts.release_agent);15661566- kfree(opts.name);15671565 msleep(10);15661566+ mutex_lock(&cgroup_tree_mutex);15671567+ mutex_lock(&cgroup_mutex);15681568 goto retry;15691569 }15701570
+49-67
kernel/cgroup_freezer.c
···2121#include <linux/uaccess.h>2222#include <linux/freezer.h>2323#include <linux/seq_file.h>2424+#include <linux/mutex.h>24252526/*2627 * A cgroup is freezing if any FREEZING flags are set. FREEZING_SELF is···4342struct freezer {4443 struct cgroup_subsys_state css;4544 unsigned int state;4646- spinlock_t lock;4745};4646+4747+static DEFINE_MUTEX(freezer_mutex);48484949static inline struct freezer *css_freezer(struct cgroup_subsys_state *css)5050{···9593 if (!freezer)9694 return ERR_PTR(-ENOMEM);97959898- spin_lock_init(&freezer->lock);9996 return &freezer->css;10097}10198···111110 struct freezer *freezer = css_freezer(css);112111 struct freezer *parent = parent_freezer(freezer);113112114114- /*115115- * The following double locking and freezing state inheritance116116- * guarantee that @cgroup can never escape ancestors' freezing117117- * states. See css_for_each_descendant_pre() for details.118118- */119119- if (parent)120120- spin_lock_irq(&parent->lock);121121- spin_lock_nested(&freezer->lock, SINGLE_DEPTH_NESTING);113113+ mutex_lock(&freezer_mutex);122114123115 freezer->state |= CGROUP_FREEZER_ONLINE;124116···120126 atomic_inc(&system_freezing_cnt);121127 }122128123123- spin_unlock(&freezer->lock);124124- if (parent)125125- spin_unlock_irq(&parent->lock);126126-129129+ mutex_unlock(&freezer_mutex);127130 return 0;128131}129132···135144{136145 struct freezer *freezer = css_freezer(css);137146138138- spin_lock_irq(&freezer->lock);147147+ mutex_lock(&freezer_mutex);139148140149 if (freezer->state & CGROUP_FREEZING)141150 atomic_dec(&system_freezing_cnt);142151143152 freezer->state = 0;144153145145- spin_unlock_irq(&freezer->lock);154154+ mutex_unlock(&freezer_mutex);146155}147156148157static void freezer_css_free(struct cgroup_subsys_state *css)···166175 struct task_struct *task;167176 bool clear_frozen = false;168177169169- spin_lock_irq(&freezer->lock);178178+ mutex_lock(&freezer_mutex);170179171180 /*172181 * Make the new tasks conform to the current state of @new_css.···188197 }189198 }190199191191- spin_unlock_irq(&freezer->lock);192192-193193- /*194194- * Propagate FROZEN clearing upwards. We may race with195195- * update_if_frozen(), but as long as both work bottom-up, either196196- * update_if_frozen() sees child's FROZEN cleared or we clear the197197- * parent's FROZEN later. No parent w/ !FROZEN children can be198198- * left FROZEN.199199- */200200+ /* propagate FROZEN clearing upwards */200201 while (clear_frozen && (freezer = parent_freezer(freezer))) {201201- spin_lock_irq(&freezer->lock);202202 freezer->state &= ~CGROUP_FROZEN;203203 clear_frozen = freezer->state & CGROUP_FREEZING;204204- spin_unlock_irq(&freezer->lock);205204 }205205+206206+ mutex_unlock(&freezer_mutex);206207}207208208209/**···211228{212229 struct freezer *freezer;213230214214- rcu_read_lock();215215- freezer = task_freezer(task);216216-217231 /*218232 * The root cgroup is non-freezable, so we can skip locking the219233 * freezer. This is safe regardless of race with task migration.···218238 * to do. If we lost and root is the new cgroup, noop is still the219239 * right thing to do.220240 */221221- if (!parent_freezer(freezer))222222- goto out;241241+ if (task_css_is_root(task, freezer_cgrp_id))242242+ return;223243224224- /*225225- * Grab @freezer->lock and freeze @task after verifying @task still226226- * belongs to @freezer and it's freezing. The former is for the227227- * case where we have raced against task migration and lost and228228- * @task is already in a different cgroup which may not be frozen.229229- * This isn't strictly necessary as freeze_task() is allowed to be230230- * called spuriously but let's do it anyway for, if nothing else,231231- * documentation.232232- */233233- spin_lock_irq(&freezer->lock);234234- if (freezer == task_freezer(task) && (freezer->state & CGROUP_FREEZING))244244+ mutex_lock(&freezer_mutex);245245+ rcu_read_lock();246246+247247+ freezer = task_freezer(task);248248+ if (freezer->state & CGROUP_FREEZING)235249 freeze_task(task);236236- spin_unlock_irq(&freezer->lock);237237-out:250250+238251 rcu_read_unlock();252252+ mutex_unlock(&freezer_mutex);239253}240254241255/**···255281 struct css_task_iter it;256282 struct task_struct *task;257283258258- WARN_ON_ONCE(!rcu_read_lock_held());259259-260260- spin_lock_irq(&freezer->lock);284284+ lockdep_assert_held(&freezer_mutex);261285262286 if (!(freezer->state & CGROUP_FREEZING) ||263287 (freezer->state & CGROUP_FROZEN))264264- goto out_unlock;288288+ return;265289266290 /* are all (live) children frozen? */291291+ rcu_read_lock();267292 css_for_each_child(pos, css) {268293 struct freezer *child = css_freezer(pos);269294270295 if ((child->state & CGROUP_FREEZER_ONLINE) &&271271- !(child->state & CGROUP_FROZEN))272272- goto out_unlock;296296+ !(child->state & CGROUP_FROZEN)) {297297+ rcu_read_unlock();298298+ return;299299+ }273300 }301301+ rcu_read_unlock();274302275303 /* are all tasks frozen? */276304 css_task_iter_start(css, &it);···293317 freezer->state |= CGROUP_FROZEN;294318out_iter_end:295319 css_task_iter_end(&it);296296-out_unlock:297297- spin_unlock_irq(&freezer->lock);298320}299321300322static int freezer_read(struct seq_file *m, void *v)301323{302324 struct cgroup_subsys_state *css = seq_css(m), *pos;303325326326+ mutex_lock(&freezer_mutex);304327 rcu_read_lock();305328306329 /* update states bottom-up */307307- css_for_each_descendant_post(pos, css)330330+ css_for_each_descendant_post(pos, css) {331331+ if (!css_tryget(pos))332332+ continue;333333+ rcu_read_unlock();334334+308335 update_if_frozen(pos);309336337337+ rcu_read_lock();338338+ css_put(pos);339339+ }340340+310341 rcu_read_unlock();342342+ mutex_unlock(&freezer_mutex);311343312344 seq_puts(m, freezer_state_strs(css_freezer(css)->state));313345 seq_putc(m, '\n');···357373 unsigned int state)358374{359375 /* also synchronizes against task migration, see freezer_attach() */360360- lockdep_assert_held(&freezer->lock);376376+ lockdep_assert_held(&freezer_mutex);361377362378 if (!(freezer->state & CGROUP_FREEZER_ONLINE))363379 return;···398414 * descendant will try to inherit its parent's FREEZING state as399415 * CGROUP_FREEZING_PARENT.400416 */417417+ mutex_lock(&freezer_mutex);401418 rcu_read_lock();402419 css_for_each_descendant_pre(pos, &freezer->css) {403420 struct freezer *pos_f = css_freezer(pos);404421 struct freezer *parent = parent_freezer(pos_f);405422406406- spin_lock_irq(&pos_f->lock);423423+ if (!css_tryget(pos))424424+ continue;425425+ rcu_read_unlock();407426408408- if (pos_f == freezer) {427427+ if (pos_f == freezer)409428 freezer_apply_state(pos_f, freeze,410429 CGROUP_FREEZING_SELF);411411- } else {412412- /*413413- * Our update to @parent->state is already visible414414- * which is all we need. No need to lock @parent.415415- * For more info on synchronization, see416416- * freezer_post_create().417417- */430430+ else418431 freezer_apply_state(pos_f,419432 parent->state & CGROUP_FREEZING,420433 CGROUP_FREEZING_PARENT);421421- }422434423423- spin_unlock_irq(&pos_f->lock);435435+ rcu_read_lock();436436+ css_put(pos);424437 }425438 rcu_read_unlock();439439+ mutex_unlock(&freezer_mutex);426440}427441428442static int freezer_write(struct cgroup_subsys_state *css, struct cftype *cft,
+4-4
kernel/hrtimer.c
···990990 /* Remove an active timer from the queue: */991991 ret = remove_hrtimer(timer, base);992992993993- /* Switch the timer base, if necessary: */994994- new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);995995-996993 if (mode & HRTIMER_MODE_REL) {997997- tim = ktime_add_safe(tim, new_base->get_time());994994+ tim = ktime_add_safe(tim, base->get_time());998995 /*999996 * CONFIG_TIME_LOW_RES is a temporary way for architectures1000997 * to signal that they simply return xtime in···10051008 }1006100910071010 hrtimer_set_expires_range_ns(timer, tim, delta_ns);10111011+10121012+ /* Switch the timer base, if necessary: */10131013+ new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);1008101410091015 timer_stats_hrtimer_set_start_info(timer);10101016
+30-6
kernel/workqueue.c
···1916191619171917 /* mayday mayday mayday */19181918 if (list_empty(&pwq->mayday_node)) {19191919+ /*19201920+ * If @pwq is for an unbound wq, its base ref may be put at19211921+ * any time due to an attribute change. Pin @pwq until the19221922+ * rescuer is done with it.19231923+ */19241924+ get_pwq(pwq);19191925 list_add_tail(&pwq->mayday_node, &wq->maydays);19201926 wake_up_process(wq->rescuer->task);19211927 }···24042398 struct worker *rescuer = __rescuer;24052399 struct workqueue_struct *wq = rescuer->rescue_wq;24062400 struct list_head *scheduled = &rescuer->scheduled;24012401+ bool should_stop;2407240224082403 set_user_nice(current, RESCUER_NICE_LEVEL);24092404···24162409repeat:24172410 set_current_state(TASK_INTERRUPTIBLE);2418241124192419- if (kthread_should_stop()) {24202420- __set_current_state(TASK_RUNNING);24212421- rescuer->task->flags &= ~PF_WQ_WORKER;24222422- return 0;24232423- }24122412+ /*24132413+ * By the time the rescuer is requested to stop, the workqueue24142414+ * shouldn't have any work pending, but @wq->maydays may still have24152415+ * pwq(s) queued. This can happen by non-rescuer workers consuming24162416+ * all the work items before the rescuer got to them. Go through24172417+ * @wq->maydays processing before acting on should_stop so that the24182418+ * list is always empty on exit.24192419+ */24202420+ should_stop = kthread_should_stop();2424242124252422 /* see whether any pwq is asking for help */24262423 spin_lock_irq(&wq_mayday_lock);···24562445 process_scheduled_works(rescuer);2457244624582447 /*24482448+ * Put the reference grabbed by send_mayday(). @pool won't24492449+ * go away while we're holding its lock.24502450+ */24512451+ put_pwq(pwq);24522452+24532453+ /*24592454 * Leave this pool. If keep_working() is %true, notify a24602455 * regular worker; otherwise, we end up with 0 concurrency24612456 * and stalling the execution.···24752458 }2476245924772460 spin_unlock_irq(&wq_mayday_lock);24612461+24622462+ if (should_stop) {24632463+ __set_current_state(TASK_RUNNING);24642464+ rescuer->task->flags &= ~PF_WQ_WORKER;24652465+ return 0;24662466+ }2478246724792468 /* rescuers should never participate in concurrency management */24802469 WARN_ON_ONCE(!(rescuer->flags & WORKER_NOT_RUNNING));···41234100 if (!pwq) {41244101 pr_warning("workqueue: allocation failed while updating NUMA affinity of \"%s\"\n",41254102 wq->name);41264126- goto out_unlock;41034103+ mutex_lock(&wq->mutex);41044104+ goto use_dfl_pwq;41274105 }4128410641294107 /*
+15
mm/Kconfig
···581581582582config GENERIC_EARLY_IOREMAP583583 bool584584+585585+config MAX_STACK_SIZE_MB586586+ int "Maximum user stack size for 32-bit processes (MB)"587587+ default 80588588+ range 8 256 if METAG589589+ range 8 2048590590+ depends on STACK_GROWSUP && (!64BIT || COMPAT)591591+ help592592+ This is the maximum stack size in Megabytes in the VM layout of 32-bit593593+ user processes when the stack grows upwards (currently only on parisc594594+ and metag arch). The stack will be located at the highest memory595595+ address minus the given value, unless the RLIMIT_STACK hard limit is596596+ changed to a smaller value in which case that is used.597597+598598+ A sane initial value is 80 MB.
···306306}307307308308/**309309- * may_access - verifies if a new exception is part of what is allowed310310- * by a dev cgroup based on the default policy +311311- * exceptions. This is used to make sure a child cgroup312312- * won't have more privileges than its parent or to313313- * verify if a certain access is allowed.314314- * @dev_cgroup: dev cgroup to be tested against315315- * @refex: new exception316316- * @behavior: behavior of the exception309309+ * match_exception - iterates the exception list trying to find a complete match310310+ * @exceptions: list of exceptions311311+ * @type: device type (DEV_BLOCK or DEV_CHAR)312312+ * @major: device file major number, ~0 to match all313313+ * @minor: device file minor number, ~0 to match all314314+ * @access: permission mask (ACC_READ, ACC_WRITE, ACC_MKNOD)315315+ *316316+ * It is considered a complete match if an exception is found that will317317+ * contain the entire range of provided parameters.318318+ *319319+ * Return: true in case it matches an exception completely317320 */318318-static bool may_access(struct dev_cgroup *dev_cgroup,319319- struct dev_exception_item *refex,320320- enum devcg_behavior behavior)321321+static bool match_exception(struct list_head *exceptions, short type,322322+ u32 major, u32 minor, short access)321323{322324 struct dev_exception_item *ex;325325+326326+ list_for_each_entry_rcu(ex, exceptions, list) {327327+ if ((type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))328328+ continue;329329+ if ((type & DEV_CHAR) && !(ex->type & DEV_CHAR))330330+ continue;331331+ if (ex->major != ~0 && ex->major != major)332332+ continue;333333+ if (ex->minor != ~0 && ex->minor != minor)334334+ continue;335335+ /* provided access cannot have more than the exception rule */336336+ if (access & (~ex->access))337337+ continue;338338+ return true;339339+ }340340+ return false;341341+}342342+343343+/**344344+ * match_exception_partial - iterates the exception list trying to find a partial match345345+ * @exceptions: list of exceptions346346+ * @type: device type (DEV_BLOCK or DEV_CHAR)347347+ * @major: device file major number, ~0 to match all348348+ * @minor: device file minor number, ~0 to match all349349+ * @access: permission mask (ACC_READ, ACC_WRITE, ACC_MKNOD)350350+ *351351+ * It is considered a partial match if an exception's range is found to352352+ * contain *any* of the devices specified by provided parameters. This is353353+ * used to make sure no extra access is being granted that is forbidden by354354+ * any of the exception list.355355+ *356356+ * Return: true in case the provided range mat matches an exception completely357357+ */358358+static bool match_exception_partial(struct list_head *exceptions, short type,359359+ u32 major, u32 minor, short access)360360+{361361+ struct dev_exception_item *ex;362362+363363+ list_for_each_entry_rcu(ex, exceptions, list) {364364+ if ((type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))365365+ continue;366366+ if ((type & DEV_CHAR) && !(ex->type & DEV_CHAR))367367+ continue;368368+ /*369369+ * We must be sure that both the exception and the provided370370+ * range aren't masking all devices371371+ */372372+ if (ex->major != ~0 && major != ~0 && ex->major != major)373373+ continue;374374+ if (ex->minor != ~0 && minor != ~0 && ex->minor != minor)375375+ continue;376376+ /*377377+ * In order to make sure the provided range isn't matching378378+ * an exception, all its access bits shouldn't match the379379+ * exception's access bits380380+ */381381+ if (!(access & ex->access))382382+ continue;383383+ return true;384384+ }385385+ return false;386386+}387387+388388+/**389389+ * verify_new_ex - verifies if a new exception is allowed by parent cgroup's permissions390390+ * @dev_cgroup: dev cgroup to be tested against391391+ * @refex: new exception392392+ * @behavior: behavior of the exception's dev_cgroup393393+ *394394+ * This is used to make sure a child cgroup won't have more privileges395395+ * than its parent396396+ */397397+static bool verify_new_ex(struct dev_cgroup *dev_cgroup,398398+ struct dev_exception_item *refex,399399+ enum devcg_behavior behavior)400400+{323401 bool match = false;324402325403 rcu_lockdep_assert(rcu_read_lock_held() ||326404 lockdep_is_held(&devcgroup_mutex),327327- "device_cgroup::may_access() called without proper synchronization");328328-329329- list_for_each_entry_rcu(ex, &dev_cgroup->exceptions, list) {330330- if ((refex->type & DEV_BLOCK) && !(ex->type & DEV_BLOCK))331331- continue;332332- if ((refex->type & DEV_CHAR) && !(ex->type & DEV_CHAR))333333- continue;334334- if (ex->major != ~0 && ex->major != refex->major)335335- continue;336336- if (ex->minor != ~0 && ex->minor != refex->minor)337337- continue;338338- if (refex->access & (~ex->access))339339- continue;340340- match = true;341341- break;342342- }405405+ "device_cgroup:verify_new_ex called without proper synchronization");343406344407 if (dev_cgroup->behavior == DEVCG_DEFAULT_ALLOW) {345408 if (behavior == DEVCG_DEFAULT_ALLOW) {346346- /* the exception will deny access to certain devices */409409+ /*410410+ * new exception in the child doesn't matter, only411411+ * adding extra restrictions412412+ */ 347413 return true;348414 } else {349349- /* the exception will allow access to certain devices */415415+ /*416416+ * new exception in the child will add more devices417417+ * that can be acessed, so it can't match any of418418+ * parent's exceptions, even slightly419419+ */ 420420+ match = match_exception_partial(&dev_cgroup->exceptions,421421+ refex->type,422422+ refex->major,423423+ refex->minor,424424+ refex->access);425425+350426 if (match)351351- /*352352- * a new exception allowing access shouldn't353353- * match an parent's exception354354- */355427 return false;356428 return true;357429 }358430 } else {359359- /* only behavior == DEVCG_DEFAULT_DENY allowed here */431431+ /*432432+ * Only behavior == DEVCG_DEFAULT_DENY allowed here, therefore433433+ * the new exception will add access to more devices and must434434+ * be contained completely in an parent's exception to be435435+ * allowed436436+ */437437+ match = match_exception(&dev_cgroup->exceptions, refex->type,438438+ refex->major, refex->minor,439439+ refex->access);440440+360441 if (match)361442 /* parent has an exception that matches the proposed */362443 return true;···459378460379 if (!parent)461380 return 1;462462- return may_access(parent, ex, childcg->behavior);381381+ return verify_new_ex(parent, ex, childcg->behavior);382382+}383383+384384+/**385385+ * parent_allows_removal - verify if it's ok to remove an exception386386+ * @childcg: child cgroup from where the exception will be removed387387+ * @ex: exception being removed388388+ *389389+ * When removing an exception in cgroups with default ALLOW policy, it must390390+ * be checked if removing it will give the child cgroup more access than the391391+ * parent.392392+ *393393+ * Return: true if it's ok to remove exception, false otherwise394394+ */395395+static bool parent_allows_removal(struct dev_cgroup *childcg,396396+ struct dev_exception_item *ex)397397+{398398+ struct dev_cgroup *parent = css_to_devcgroup(css_parent(&childcg->css));399399+400400+ if (!parent)401401+ return true;402402+403403+ /* It's always allowed to remove access to devices */404404+ if (childcg->behavior == DEVCG_DEFAULT_DENY)405405+ return true;406406+407407+ /*408408+ * Make sure you're not removing part or a whole exception existing in409409+ * the parent cgroup410410+ */411411+ return !match_exception_partial(&parent->exceptions, ex->type,412412+ ex->major, ex->minor, ex->access);463413}464414465415/**···728616729617 switch (filetype) {730618 case DEVCG_ALLOW:731731- if (!parent_has_perm(devcgroup, &ex))732732- return -EPERM;733619 /*734620 * If the default policy is to allow by default, try to remove735621 * an matching exception instead. And be silent about it: we736622 * don't want to break compatibility737623 */738624 if (devcgroup->behavior == DEVCG_DEFAULT_ALLOW) {625625+ /* Check if the parent allows removing it first */626626+ if (!parent_allows_removal(devcgroup, &ex))627627+ return -EPERM;739628 dev_exception_rm(devcgroup, &ex);740740- return 0;629629+ break;741630 }631631+632632+ if (!parent_has_perm(devcgroup, &ex))633633+ return -EPERM;742634 rc = dev_exception_add(devcgroup, &ex);743635 break;744636 case DEVCG_DENY:···820704 short access)821705{822706 struct dev_cgroup *dev_cgroup;823823- struct dev_exception_item ex;824824- int rc;825825-826826- memset(&ex, 0, sizeof(ex));827827- ex.type = type;828828- ex.major = major;829829- ex.minor = minor;830830- ex.access = access;707707+ bool rc;831708832709 rcu_read_lock();833710 dev_cgroup = task_devcgroup(current);834834- rc = may_access(dev_cgroup, &ex, dev_cgroup->behavior);711711+ if (dev_cgroup->behavior == DEVCG_DEFAULT_ALLOW)712712+ /* Can't match any of the exceptions, even partially */713713+ rc = !match_exception_partial(&dev_cgroup->exceptions,714714+ type, major, minor, access);715715+ else716716+ /* Need to match completely one exception to be allowed */717717+ rc = match_exception(&dev_cgroup->exceptions, type, major,718718+ minor, access);835719 rcu_read_unlock();836720837721 if (!rc)
+59
sound/firewire/Kconfig
···6161 To compile this driver as a module, choose M here: the module6262 will be called snd-scs1x.63636464+config SND_FIREWORKS6565+ tristate "Echo Fireworks board module support"6666+ select SND_FIREWIRE_LIB6767+ select SND_RAWMIDI6868+ select SND_PCM6969+ select SND_HWDEP7070+ help7171+ Say Y here to include support for FireWire devices based7272+ on Echo Digital Audio Fireworks board:7373+ * Mackie Onyx 400F/1200F7474+ * Echo AudioFire12/8(until 2009 July)7575+ * Echo AudioFire2/4/Pre8/8(since 2009 July)7676+ * Echo Fireworks 8/HDMI7777+ * Gibson Robot Interface Pack/GoldTop7878+7979+ To compile this driver as a module, choose M here: the module8080+ will be called snd-fireworks.8181+8282+config SND_BEBOB8383+ tristate "BridgeCo DM1000/DM1100/DM1500 with BeBoB firmware"8484+ select SND_FIREWIRE_LIB8585+ select SND_RAWMIDI8686+ select SND_PCM8787+ select SND_HWDEP8888+ help8989+ Say Y here to include support for FireWire devices based9090+ on BridgeCo DM1000/DM1100/DM1500 with BeBoB firmware:9191+ * Edirol FA-66/FA-1019292+ * PreSonus FIREBOX/FIREPOD/FP10/Inspire13949393+ * BridgeCo RDAudio1/Audio59494+ * Mackie Onyx 1220/1620/1640 (Firewire I/O Card)9595+ * Mackie d.2 (Firewire Option)9696+ * Stanton FinalScratch 2 (ScratchAmp)9797+ * Tascam IF-FW/DM9898+ * Behringer XENIX UFX 1204/16049999+ * Behringer Digital Mixer X32 series (X-UF Card)100100+ * Apogee Rosetta 200/400 (X-FireWire card)101101+ * Apogee DA/AD/DD-16X (X-FireWire card)102102+ * Apogee Ensemble103103+ * ESI Quotafire610104104+ * AcousticReality eARMasterOne105105+ * CME MatrixKFW106106+ * Phonic Helix Board 12 MkII/18 MkII/24 MkII107107+ * Phonic Helix Board 12 Universal/18 Universal/24 Universal108108+ * Lynx Aurora 8/16 (LT-FW)109109+ * ICON FireXon110110+ * PrismSound Orpheus/ADA-8XR111111+ * TerraTec PHASE 24 FW/PHASE X24 FW/PHASE 88 Rack FW112112+ * Terratec EWS MIC2/EWS MIC4113113+ * Terratec Aureon 7.1 Firewire114114+ * Yamaha GO44/GO46115115+ * Focusrite Saffire/Saffire LE/SaffirePro10 IO/SaffirePro26 IO116116+ * M-Audio Firewire410/AudioPhile/Solo117117+ * M-Audio Ozonic/NRV10/ProfireLightBridge118118+ * M-Audio Firewire 1814/ProjectMix IO119119+120120+ To compile this driver as a module, choose M here: the module121121+ will be called snd-bebob.122122+64123endif # SND_FIREWIRE
···1111#include <linux/firewire.h>1212#include <linux/module.h>1313#include <linux/slab.h>1414+#include <linux/sched.h>1415#include <sound/pcm.h>1616+#include <sound/pcm_params.h>1717+#include <sound/rawmidi.h>1518#include "amdtp.h"16191720#define TICKS_PER_CYCLE 3072···23202421#define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 µs */25222323+/* isochronous header parameters */2424+#define ISO_DATA_LENGTH_SHIFT 162625#define TAG_CIP 127262727+/* common isochronous packet header parameters */2828#define CIP_EOH (1u << 31)2929+#define CIP_EOH_MASK 0x800000002930#define CIP_FMT_AM (0x10 << 24)3030-#define AMDTP_FDF_AM824 (0 << 19)3131-#define AMDTP_FDF_SFC_SHIFT 163131+#define CIP_FMT_MASK 0x3f0000003232+#define CIP_SYT_MASK 0x0000ffff3333+#define CIP_SYT_NO_INFO 0xffff3434+#define CIP_FDF_MASK 0x00ff00003535+#define CIP_FDF_SFC_SHIFT 163636+3737+/*3838+ * Audio and Music transfer protocol specific parameters3939+ * only "Clock-based rate control mode" is supported4040+ */4141+#define AMDTP_FDF_AM824 (0 << (CIP_FDF_SFC_SHIFT + 3))4242+#define AMDTP_FDF_NO_DATA 0xff4343+#define AMDTP_DBS_MASK 0x00ff00004444+#define AMDTP_DBS_SHIFT 164545+#define AMDTP_DBC_MASK 0x000000ff32463347/* TODO: make these configurable */3448#define INTERRUPT_INTERVAL 163549#define QUEUE_LENGTH 4836505151+#define IN_PACKET_HEADER_SIZE 45252+#define OUT_PACKET_HEADER_SIZE 05353+3754static void pcm_period_tasklet(unsigned long data);38553956/**4040- * amdtp_out_stream_init - initialize an AMDTP output stream structure4141- * @s: the AMDTP output stream to initialize5757+ * amdtp_stream_init - initialize an AMDTP stream structure5858+ * @s: the AMDTP stream to initialize4259 * @unit: the target of the stream6060+ * @dir: the direction of stream4361 * @flags: the packet transmission method to use4462 */4545-int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,4646- enum cip_out_flags flags)6363+int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,6464+ enum amdtp_stream_direction dir, enum cip_flags flags)4765{4866 s->unit = fw_unit_get(unit);6767+ s->direction = dir;4968 s->flags = flags;5069 s->context = ERR_PTR(-1);5170 mutex_init(&s->mutex);5271 tasklet_init(&s->period_tasklet, pcm_period_tasklet, (unsigned long)s);5372 s->packet_index = 0;54737474+ init_waitqueue_head(&s->callback_wait);7575+ s->callbacked = false;7676+ s->sync_slave = NULL;7777+7878+ s->rx_blocks_for_midi = UINT_MAX;7979+5580 return 0;5681}5757-EXPORT_SYMBOL(amdtp_out_stream_init);8282+EXPORT_SYMBOL(amdtp_stream_init);58835984/**6060- * amdtp_out_stream_destroy - free stream resources6161- * @s: the AMDTP output stream to destroy8585+ * amdtp_stream_destroy - free stream resources8686+ * @s: the AMDTP stream to destroy6287 */6363-void amdtp_out_stream_destroy(struct amdtp_out_stream *s)8888+void amdtp_stream_destroy(struct amdtp_stream *s)6489{6565- WARN_ON(amdtp_out_stream_running(s));9090+ WARN_ON(amdtp_stream_running(s));6691 mutex_destroy(&s->mutex);6792 fw_unit_put(s->unit);6893}6969-EXPORT_SYMBOL(amdtp_out_stream_destroy);9494+EXPORT_SYMBOL(amdtp_stream_destroy);70957196const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT] = {7297 [CIP_SFC_32000] = 8,···10776};10877EXPORT_SYMBOL(amdtp_syt_intervals);109787979+const unsigned int amdtp_rate_table[CIP_SFC_COUNT] = {8080+ [CIP_SFC_32000] = 32000,8181+ [CIP_SFC_44100] = 44100,8282+ [CIP_SFC_48000] = 48000,8383+ [CIP_SFC_88200] = 88200,8484+ [CIP_SFC_96000] = 96000,8585+ [CIP_SFC_176400] = 176400,8686+ [CIP_SFC_192000] = 192000,8787+};8888+EXPORT_SYMBOL(amdtp_rate_table);8989+11090/**111111- * amdtp_out_stream_set_parameters - set stream parameters112112- * @s: the AMDTP output stream to configure9191+ * amdtp_stream_add_pcm_hw_constraints - add hw constraints for PCM substream9292+ * @s: the AMDTP stream, which must be initialized.9393+ * @runtime: the PCM substream runtime9494+ */9595+int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,9696+ struct snd_pcm_runtime *runtime)9797+{9898+ int err;9999+100100+ /* AM824 in IEC 61883-6 can deliver 24bit data */101101+ err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);102102+ if (err < 0)103103+ goto end;104104+105105+ /*106106+ * Currently firewire-lib processes 16 packets in one software107107+ * interrupt callback. This equals to 2msec but actually the108108+ * interval of the interrupts has a jitter.109109+ * Additionally, even if adding a constraint to fit period size to110110+ * 2msec, actual calculated frames per period doesn't equal to 2msec,111111+ * depending on sampling rate.112112+ * Anyway, the interval to call snd_pcm_period_elapsed() cannot 2msec.113113+ * Here let us use 5msec for safe period interrupt.114114+ */115115+ err = snd_pcm_hw_constraint_minmax(runtime,116116+ SNDRV_PCM_HW_PARAM_PERIOD_TIME,117117+ 5000, UINT_MAX);118118+ if (err < 0)119119+ goto end;120120+121121+ /* Non-Blocking stream has no more constraints */122122+ if (!(s->flags & CIP_BLOCKING))123123+ goto end;124124+125125+ /*126126+ * One AMDTP packet can include some frames. In blocking mode, the127127+ * number equals to SYT_INTERVAL. So the number is 8, 16 or 32,128128+ * depending on its sampling rate. For accurate period interrupt, it's129129+ * preferrable to aligh period/buffer sizes to current SYT_INTERVAL.130130+ *131131+ * TODO: These constraints can be improved with propper rules.132132+ * Currently apply LCM of SYT_INTEVALs.133133+ */134134+ err = snd_pcm_hw_constraint_step(runtime, 0,135135+ SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);136136+ if (err < 0)137137+ goto end;138138+ err = snd_pcm_hw_constraint_step(runtime, 0,139139+ SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);140140+end:141141+ return err;142142+}143143+EXPORT_SYMBOL(amdtp_stream_add_pcm_hw_constraints);144144+145145+/**146146+ * amdtp_stream_set_parameters - set stream parameters147147+ * @s: the AMDTP stream to configure113148 * @rate: the sample rate114149 * @pcm_channels: the number of PCM samples in each data block, to be encoded115150 * as AM824 multi-bit linear audio···18487 * The parameters must be set before the stream is started, and must not be18588 * changed while the stream is running.18689 */187187-void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,188188- unsigned int rate,189189- unsigned int pcm_channels,190190- unsigned int midi_ports)9090+void amdtp_stream_set_parameters(struct amdtp_stream *s,9191+ unsigned int rate,9292+ unsigned int pcm_channels,9393+ unsigned int midi_ports)19194{192192- static const unsigned int rates[] = {193193- [CIP_SFC_32000] = 32000,194194- [CIP_SFC_44100] = 44100,195195- [CIP_SFC_48000] = 48000,196196- [CIP_SFC_88200] = 88200,197197- [CIP_SFC_96000] = 96000,198198- [CIP_SFC_176400] = 176400,199199- [CIP_SFC_192000] = 192000,200200- };201201- unsigned int sfc;9595+ unsigned int i, sfc, midi_channels;20296203203- if (WARN_ON(amdtp_out_stream_running(s)))9797+ midi_channels = DIV_ROUND_UP(midi_ports, 8);9898+9999+ if (WARN_ON(amdtp_stream_running(s)) |100100+ WARN_ON(pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM) |101101+ WARN_ON(midi_channels > AMDTP_MAX_CHANNELS_FOR_MIDI))204102 return;205103206206- for (sfc = 0; sfc < CIP_SFC_COUNT; ++sfc)207207- if (rates[sfc] == rate)104104+ for (sfc = 0; sfc < ARRAY_SIZE(amdtp_rate_table); ++sfc)105105+ if (amdtp_rate_table[sfc] == rate)208106 goto sfc_found;209107 WARN_ON(1);210108 return;211109212110sfc_found:213213- s->dual_wire = (s->flags & CIP_HI_DUALWIRE) && sfc > CIP_SFC_96000;214214- if (s->dual_wire) {215215- sfc -= 2;216216- rate /= 2;217217- pcm_channels *= 2;218218- }219219- s->sfc = sfc;220220- s->data_block_quadlets = pcm_channels + DIV_ROUND_UP(midi_ports, 8);221111 s->pcm_channels = pcm_channels;112112+ s->sfc = sfc;113113+ s->data_block_quadlets = s->pcm_channels + midi_channels;222114 s->midi_ports = midi_ports;223115224116 s->syt_interval = amdtp_syt_intervals[sfc];···217131 if (s->flags & CIP_BLOCKING)218132 /* additional buffering needed to adjust for no-data packets */219133 s->transfer_delay += TICKS_PER_SECOND * s->syt_interval / rate;134134+135135+ /* init the position map for PCM and MIDI channels */136136+ for (i = 0; i < pcm_channels; i++)137137+ s->pcm_positions[i] = i;138138+ s->midi_position = s->pcm_channels;220139}221221-EXPORT_SYMBOL(amdtp_out_stream_set_parameters);140140+EXPORT_SYMBOL(amdtp_stream_set_parameters);222141223142/**224224- * amdtp_out_stream_get_max_payload - get the stream's packet size225225- * @s: the AMDTP output stream143143+ * amdtp_stream_get_max_payload - get the stream's packet size144144+ * @s: the AMDTP stream226145 *227146 * This function must not be called before the stream has been configured228228- * with amdtp_out_stream_set_parameters().147147+ * with amdtp_stream_set_parameters().229148 */230230-unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s)149149+unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s)231150{232151 return 8 + s->syt_interval * s->data_block_quadlets * 4;233152}234234-EXPORT_SYMBOL(amdtp_out_stream_get_max_payload);153153+EXPORT_SYMBOL(amdtp_stream_get_max_payload);235154236236-static void amdtp_write_s16(struct amdtp_out_stream *s,155155+static void amdtp_write_s16(struct amdtp_stream *s,237156 struct snd_pcm_substream *pcm,238157 __be32 *buffer, unsigned int frames);239239-static void amdtp_write_s32(struct amdtp_out_stream *s,158158+static void amdtp_write_s32(struct amdtp_stream *s,240159 struct snd_pcm_substream *pcm,241160 __be32 *buffer, unsigned int frames);242242-static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,243243- struct snd_pcm_substream *pcm,244244- __be32 *buffer, unsigned int frames);245245-static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,246246- struct snd_pcm_substream *pcm,247247- __be32 *buffer, unsigned int frames);161161+static void amdtp_read_s32(struct amdtp_stream *s,162162+ struct snd_pcm_substream *pcm,163163+ __be32 *buffer, unsigned int frames);248164249165/**250250- * amdtp_out_stream_set_pcm_format - set the PCM format251251- * @s: the AMDTP output stream to configure166166+ * amdtp_stream_set_pcm_format - set the PCM format167167+ * @s: the AMDTP stream to configure252168 * @format: the format of the ALSA PCM device253169 *254170 * The sample format must be set after the other paramters (rate/PCM channels/255171 * MIDI) and before the stream is started, and must not be changed while the256172 * stream is running.257173 */258258-void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,259259- snd_pcm_format_t format)174174+void amdtp_stream_set_pcm_format(struct amdtp_stream *s,175175+ snd_pcm_format_t format)260176{261261- if (WARN_ON(amdtp_out_stream_running(s)))177177+ if (WARN_ON(amdtp_stream_pcm_running(s)))262178 return;263179264180 switch (format) {···268180 WARN_ON(1);269181 /* fall through */270182 case SNDRV_PCM_FORMAT_S16:271271- if (s->dual_wire)272272- s->transfer_samples = amdtp_write_s16_dualwire;273273- else183183+ if (s->direction == AMDTP_OUT_STREAM) {274184 s->transfer_samples = amdtp_write_s16;275275- break;185185+ break;186186+ }187187+ WARN_ON(1);188188+ /* fall through */276189 case SNDRV_PCM_FORMAT_S32:277277- if (s->dual_wire)278278- s->transfer_samples = amdtp_write_s32_dualwire;279279- else190190+ if (s->direction == AMDTP_OUT_STREAM)280191 s->transfer_samples = amdtp_write_s32;192192+ else193193+ s->transfer_samples = amdtp_read_s32;281194 break;282195 }283196}284284-EXPORT_SYMBOL(amdtp_out_stream_set_pcm_format);197197+EXPORT_SYMBOL(amdtp_stream_set_pcm_format);285198286199/**287287- * amdtp_out_stream_pcm_prepare - prepare PCM device for running288288- * @s: the AMDTP output stream200200+ * amdtp_stream_pcm_prepare - prepare PCM device for running201201+ * @s: the AMDTP stream289202 *290203 * This function should be called from the PCM device's .prepare callback.291204 */292292-void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)205205+void amdtp_stream_pcm_prepare(struct amdtp_stream *s)293206{294207 tasklet_kill(&s->period_tasklet);295208 s->pcm_buffer_pointer = 0;296209 s->pcm_period_pointer = 0;297210 s->pointer_flush = true;298211}299299-EXPORT_SYMBOL(amdtp_out_stream_pcm_prepare);212212+EXPORT_SYMBOL(amdtp_stream_pcm_prepare);300213301301-static unsigned int calculate_data_blocks(struct amdtp_out_stream *s)214214+static unsigned int calculate_data_blocks(struct amdtp_stream *s)302215{303216 unsigned int phase, data_blocks;304217305305- if (!cip_sfc_is_base_44100(s->sfc)) {218218+ if (s->flags & CIP_BLOCKING)219219+ data_blocks = s->syt_interval;220220+ else if (!cip_sfc_is_base_44100(s->sfc)) {306221 /* Sample_rate / 8000 is an integer, and precomputed. */307222 data_blocks = s->data_block_state;308223 } else {···334243 return data_blocks;335244}336245337337-static unsigned int calculate_syt(struct amdtp_out_stream *s,246246+static unsigned int calculate_syt(struct amdtp_stream *s,338247 unsigned int cycle)339248{340249 unsigned int syt_offset, phase, index, syt;···371280 syt = (cycle + syt_offset / TICKS_PER_CYCLE) << 12;372281 syt += syt_offset % TICKS_PER_CYCLE;373282374374- return syt & 0xffff;283283+ return syt & CIP_SYT_MASK;375284 } else {376376- return 0xffff; /* no info */285285+ return CIP_SYT_NO_INFO;377286 }378287}379288380380-static void amdtp_write_s32(struct amdtp_out_stream *s,289289+static void amdtp_write_s32(struct amdtp_stream *s,381290 struct snd_pcm_substream *pcm,382291 __be32 *buffer, unsigned int frames)383292{384293 struct snd_pcm_runtime *runtime = pcm->runtime;385385- unsigned int channels, remaining_frames, frame_step, i, c;294294+ unsigned int channels, remaining_frames, i, c;386295 const u32 *src;387296388297 channels = s->pcm_channels;389298 src = (void *)runtime->dma_area +390299 frames_to_bytes(runtime, s->pcm_buffer_pointer);391300 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;392392- frame_step = s->data_block_quadlets - channels;393301394302 for (i = 0; i < frames; ++i) {395303 for (c = 0; c < channels; ++c) {396396- *buffer = cpu_to_be32((*src >> 8) | 0x40000000);304304+ buffer[s->pcm_positions[c]] =305305+ cpu_to_be32((*src >> 8) | 0x40000000);397306 src++;398398- buffer++;399307 }400400- buffer += frame_step;308308+ buffer += s->data_block_quadlets;401309 if (--remaining_frames == 0)402310 src = (void *)runtime->dma_area;403311 }404312}405313406406-static void amdtp_write_s16(struct amdtp_out_stream *s,314314+static void amdtp_write_s16(struct amdtp_stream *s,407315 struct snd_pcm_substream *pcm,408316 __be32 *buffer, unsigned int frames)409317{410318 struct snd_pcm_runtime *runtime = pcm->runtime;411411- unsigned int channels, remaining_frames, frame_step, i, c;319319+ unsigned int channels, remaining_frames, i, c;412320 const u16 *src;413321414322 channels = s->pcm_channels;415323 src = (void *)runtime->dma_area +416324 frames_to_bytes(runtime, s->pcm_buffer_pointer);417325 remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;418418- frame_step = s->data_block_quadlets - channels;419326420327 for (i = 0; i < frames; ++i) {421328 for (c = 0; c < channels; ++c) {422422- *buffer = cpu_to_be32((*src << 8) | 0x40000000);329329+ buffer[s->pcm_positions[c]] =330330+ cpu_to_be32((*src << 8) | 0x40000000);423331 src++;424424- buffer++;425332 }426426- buffer += frame_step;333333+ buffer += s->data_block_quadlets;427334 if (--remaining_frames == 0)428335 src = (void *)runtime->dma_area;429336 }430337}431338432432-static void amdtp_write_s32_dualwire(struct amdtp_out_stream *s,433433- struct snd_pcm_substream *pcm,434434- __be32 *buffer, unsigned int frames)339339+static void amdtp_read_s32(struct amdtp_stream *s,340340+ struct snd_pcm_substream *pcm,341341+ __be32 *buffer, unsigned int frames)435342{436343 struct snd_pcm_runtime *runtime = pcm->runtime;437437- unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;438438- const u32 *src;344344+ unsigned int channels, remaining_frames, i, c;345345+ u32 *dst;439346440347 channels = s->pcm_channels;441441- src = (void *)runtime->dma_area +442442- s->pcm_buffer_pointer * (runtime->frame_bits / 8);443443- frame_adjust_1 = channels - 1;444444- frame_adjust_2 = 1 - (s->data_block_quadlets - channels);348348+ dst = (void *)runtime->dma_area +349349+ frames_to_bytes(runtime, s->pcm_buffer_pointer);350350+ remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer;445351446446- channels /= 2;447352 for (i = 0; i < frames; ++i) {448353 for (c = 0; c < channels; ++c) {449449- *buffer = cpu_to_be32((*src >> 8) | 0x40000000);450450- src++;451451- buffer += 2;354354+ *dst = be32_to_cpu(buffer[s->pcm_positions[c]]) << 8;355355+ dst++;452356 }453453- buffer -= frame_adjust_1;454454- for (c = 0; c < channels; ++c) {455455- *buffer = cpu_to_be32((*src >> 8) | 0x40000000);456456- src++;457457- buffer += 2;458458- }459459- buffer -= frame_adjust_2;357357+ buffer += s->data_block_quadlets;358358+ if (--remaining_frames == 0)359359+ dst = (void *)runtime->dma_area;460360 }461361}462362463463-static void amdtp_write_s16_dualwire(struct amdtp_out_stream *s,464464- struct snd_pcm_substream *pcm,465465- __be32 *buffer, unsigned int frames)466466-{467467- struct snd_pcm_runtime *runtime = pcm->runtime;468468- unsigned int channels, frame_adjust_1, frame_adjust_2, i, c;469469- const u16 *src;470470-471471- channels = s->pcm_channels;472472- src = (void *)runtime->dma_area +473473- s->pcm_buffer_pointer * (runtime->frame_bits / 8);474474- frame_adjust_1 = channels - 1;475475- frame_adjust_2 = 1 - (s->data_block_quadlets - channels);476476-477477- channels /= 2;478478- for (i = 0; i < frames; ++i) {479479- for (c = 0; c < channels; ++c) {480480- *buffer = cpu_to_be32((*src << 8) | 0x40000000);481481- src++;482482- buffer += 2;483483- }484484- buffer -= frame_adjust_1;485485- for (c = 0; c < channels; ++c) {486486- *buffer = cpu_to_be32((*src << 8) | 0x40000000);487487- src++;488488- buffer += 2;489489- }490490- buffer -= frame_adjust_2;491491- }492492-}493493-494494-static void amdtp_fill_pcm_silence(struct amdtp_out_stream *s,363363+static void amdtp_fill_pcm_silence(struct amdtp_stream *s,495364 __be32 *buffer, unsigned int frames)496365{497366 unsigned int i, c;498367499368 for (i = 0; i < frames; ++i) {500369 for (c = 0; c < s->pcm_channels; ++c)501501- buffer[c] = cpu_to_be32(0x40000000);370370+ buffer[s->pcm_positions[c]] = cpu_to_be32(0x40000000);502371 buffer += s->data_block_quadlets;503372 }504373}505374506506-static void amdtp_fill_midi(struct amdtp_out_stream *s,375375+static void amdtp_fill_midi(struct amdtp_stream *s,507376 __be32 *buffer, unsigned int frames)508377{509509- unsigned int i;378378+ unsigned int f, port;379379+ u8 *b;510380511511- for (i = 0; i < frames; ++i)512512- buffer[s->pcm_channels + i * s->data_block_quadlets] =513513- cpu_to_be32(0x80000000);381381+ for (f = 0; f < frames; f++) {382382+ buffer[s->midi_position] = 0;383383+ b = (u8 *)&buffer[s->midi_position];384384+385385+ port = (s->data_block_counter + f) % 8;386386+ if ((f >= s->rx_blocks_for_midi) ||387387+ (s->midi[port] == NULL) ||388388+ (snd_rawmidi_transmit(s->midi[port], b + 1, 1) <= 0))389389+ b[0] = 0x80;390390+ else391391+ b[0] = 0x81;392392+393393+ buffer += s->data_block_quadlets;394394+ }514395}515396516516-static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)397397+static void amdtp_pull_midi(struct amdtp_stream *s,398398+ __be32 *buffer, unsigned int frames)399399+{400400+ unsigned int f, port;401401+ int len;402402+ u8 *b;403403+404404+ for (f = 0; f < frames; f++) {405405+ port = (s->data_block_counter + f) % 8;406406+ b = (u8 *)&buffer[s->midi_position];407407+408408+ len = b[0] - 0x80;409409+ if ((1 <= len) && (len <= 3) && (s->midi[port]))410410+ snd_rawmidi_receive(s->midi[port], b + 1, len);411411+412412+ buffer += s->data_block_quadlets;413413+ }414414+}415415+416416+static void update_pcm_pointers(struct amdtp_stream *s,417417+ struct snd_pcm_substream *pcm,418418+ unsigned int frames)419419+{ unsigned int ptr;420420+421421+ ptr = s->pcm_buffer_pointer + frames;422422+ if (ptr >= pcm->runtime->buffer_size)423423+ ptr -= pcm->runtime->buffer_size;424424+ ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;425425+426426+ s->pcm_period_pointer += frames;427427+ if (s->pcm_period_pointer >= pcm->runtime->period_size) {428428+ s->pcm_period_pointer -= pcm->runtime->period_size;429429+ s->pointer_flush = false;430430+ tasklet_hi_schedule(&s->period_tasklet);431431+ }432432+}433433+434434+static void pcm_period_tasklet(unsigned long data)435435+{436436+ struct amdtp_stream *s = (void *)data;437437+ struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);438438+439439+ if (pcm)440440+ snd_pcm_period_elapsed(pcm);441441+}442442+443443+static int queue_packet(struct amdtp_stream *s,444444+ unsigned int header_length,445445+ unsigned int payload_length, bool skip)446446+{447447+ struct fw_iso_packet p = {0};448448+ int err = 0;449449+450450+ if (IS_ERR(s->context))451451+ goto end;452452+453453+ p.interrupt = IS_ALIGNED(s->packet_index + 1, INTERRUPT_INTERVAL);454454+ p.tag = TAG_CIP;455455+ p.header_length = header_length;456456+ p.payload_length = (!skip) ? payload_length : 0;457457+ p.skip = skip;458458+ err = fw_iso_context_queue(s->context, &p, &s->buffer.iso_buffer,459459+ s->buffer.packets[s->packet_index].offset);460460+ if (err < 0) {461461+ dev_err(&s->unit->device, "queueing error: %d\n", err);462462+ goto end;463463+ }464464+465465+ if (++s->packet_index >= QUEUE_LENGTH)466466+ s->packet_index = 0;467467+end:468468+ return err;469469+}470470+471471+static inline int queue_out_packet(struct amdtp_stream *s,472472+ unsigned int payload_length, bool skip)473473+{474474+ return queue_packet(s, OUT_PACKET_HEADER_SIZE,475475+ payload_length, skip);476476+}477477+478478+static inline int queue_in_packet(struct amdtp_stream *s)479479+{480480+ return queue_packet(s, IN_PACKET_HEADER_SIZE,481481+ amdtp_stream_get_max_payload(s), false);482482+}483483+484484+static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)517485{518486 __be32 *buffer;519519- unsigned int index, data_blocks, syt, ptr;487487+ unsigned int data_blocks, payload_length;520488 struct snd_pcm_substream *pcm;521521- struct fw_iso_packet packet;522522- int err;523489524490 if (s->packet_index < 0)525491 return;526526- index = s->packet_index;527492528493 /* this module generate empty packet for 'no data' */529529- syt = calculate_syt(s, cycle);530530- if (!(s->flags & CIP_BLOCKING))494494+ if (!(s->flags & CIP_BLOCKING) || (syt != CIP_SYT_NO_INFO))531495 data_blocks = calculate_data_blocks(s);532532- else if (syt != 0xffff)533533- data_blocks = s->syt_interval;534496 else535497 data_blocks = 0;536498537537- buffer = s->buffer.packets[index].buffer;499499+ buffer = s->buffer.packets[s->packet_index].buffer;538500 buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |539539- (s->data_block_quadlets << 16) |501501+ (s->data_block_quadlets << AMDTP_DBS_SHIFT) |540502 s->data_block_counter);541503 buffer[1] = cpu_to_be32(CIP_EOH | CIP_FMT_AM | AMDTP_FDF_AM824 |542542- (s->sfc << AMDTP_FDF_SFC_SHIFT) | syt);504504+ (s->sfc << CIP_FDF_SFC_SHIFT) | syt);543505 buffer += 2;544506545507 pcm = ACCESS_ONCE(s->pcm);···605461606462 s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff;607463608608- packet.payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;609609- packet.interrupt = IS_ALIGNED(index + 1, INTERRUPT_INTERVAL);610610- packet.skip = 0;611611- packet.tag = TAG_CIP;612612- packet.sy = 0;613613- packet.header_length = 0;614614-615615- err = fw_iso_context_queue(s->context, &packet, &s->buffer.iso_buffer,616616- s->buffer.packets[index].offset);617617- if (err < 0) {618618- dev_err(&s->unit->device, "queueing error: %d\n", err);464464+ payload_length = 8 + data_blocks * 4 * s->data_block_quadlets;465465+ if (queue_out_packet(s, payload_length, false) < 0) {619466 s->packet_index = -1;620620- amdtp_out_stream_pcm_abort(s);467467+ amdtp_stream_pcm_abort(s);621468 return;622469 }623470624624- if (++index >= QUEUE_LENGTH)625625- index = 0;626626- s->packet_index = index;627627-628628- if (pcm) {629629- if (s->dual_wire)630630- data_blocks *= 2;631631-632632- ptr = s->pcm_buffer_pointer + data_blocks;633633- if (ptr >= pcm->runtime->buffer_size)634634- ptr -= pcm->runtime->buffer_size;635635- ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;636636-637637- s->pcm_period_pointer += data_blocks;638638- if (s->pcm_period_pointer >= pcm->runtime->period_size) {639639- s->pcm_period_pointer -= pcm->runtime->period_size;640640- s->pointer_flush = false;641641- tasklet_hi_schedule(&s->period_tasklet);642642- }643643- }471471+ if (pcm)472472+ update_pcm_pointers(s, pcm, data_blocks);644473}645474646646-static void pcm_period_tasklet(unsigned long data)475475+static void handle_in_packet(struct amdtp_stream *s,476476+ unsigned int payload_quadlets,477477+ __be32 *buffer)647478{648648- struct amdtp_out_stream *s = (void *)data;649649- struct snd_pcm_substream *pcm = ACCESS_ONCE(s->pcm);479479+ u32 cip_header[2];480480+ unsigned int data_blocks, data_block_quadlets, data_block_counter,481481+ dbc_interval;482482+ struct snd_pcm_substream *pcm = NULL;483483+ bool lost;484484+485485+ cip_header[0] = be32_to_cpu(buffer[0]);486486+ cip_header[1] = be32_to_cpu(buffer[1]);487487+488488+ /*489489+ * This module supports 'Two-quadlet CIP header with SYT field'.490490+ * For convenience, also check FMT field is AM824 or not.491491+ */492492+ if (((cip_header[0] & CIP_EOH_MASK) == CIP_EOH) ||493493+ ((cip_header[1] & CIP_EOH_MASK) != CIP_EOH) ||494494+ ((cip_header[1] & CIP_FMT_MASK) != CIP_FMT_AM)) {495495+ dev_info_ratelimited(&s->unit->device,496496+ "Invalid CIP header for AMDTP: %08X:%08X\n",497497+ cip_header[0], cip_header[1]);498498+ goto end;499499+ }500500+501501+ /* Calculate data blocks */502502+ if (payload_quadlets < 3 ||503503+ ((cip_header[1] & CIP_FDF_MASK) ==504504+ (AMDTP_FDF_NO_DATA << CIP_FDF_SFC_SHIFT))) {505505+ data_blocks = 0;506506+ } else {507507+ data_block_quadlets =508508+ (cip_header[0] & AMDTP_DBS_MASK) >> AMDTP_DBS_SHIFT;509509+ /* avoid division by zero */510510+ if (data_block_quadlets == 0) {511511+ dev_info_ratelimited(&s->unit->device,512512+ "Detect invalid value in dbs field: %08X\n",513513+ cip_header[0]);514514+ goto err;515515+ }516516+ if (s->flags & CIP_WRONG_DBS)517517+ data_block_quadlets = s->data_block_quadlets;518518+519519+ data_blocks = (payload_quadlets - 2) / data_block_quadlets;520520+ }521521+522522+ /* Check data block counter continuity */523523+ data_block_counter = cip_header[0] & AMDTP_DBC_MASK;524524+ if (data_blocks == 0 && (s->flags & CIP_EMPTY_HAS_WRONG_DBC) &&525525+ s->data_block_counter != UINT_MAX)526526+ data_block_counter = s->data_block_counter;527527+528528+ if (((s->flags & CIP_SKIP_DBC_ZERO_CHECK) && data_block_counter == 0) ||529529+ (s->data_block_counter == UINT_MAX)) {530530+ lost = false;531531+ } else if (!(s->flags & CIP_DBC_IS_END_EVENT)) {532532+ lost = data_block_counter != s->data_block_counter;533533+ } else {534534+ if ((data_blocks > 0) && (s->tx_dbc_interval > 0))535535+ dbc_interval = s->tx_dbc_interval;536536+ else537537+ dbc_interval = data_blocks;538538+539539+ lost = data_block_counter !=540540+ ((s->data_block_counter + dbc_interval) & 0xff);541541+ }542542+543543+ if (lost) {544544+ dev_info(&s->unit->device,545545+ "Detect discontinuity of CIP: %02X %02X\n",546546+ s->data_block_counter, data_block_counter);547547+ goto err;548548+ }549549+550550+ if (data_blocks > 0) {551551+ buffer += 2;552552+553553+ pcm = ACCESS_ONCE(s->pcm);554554+ if (pcm)555555+ s->transfer_samples(s, pcm, buffer, data_blocks);556556+557557+ if (s->midi_ports)558558+ amdtp_pull_midi(s, buffer, data_blocks);559559+ }560560+561561+ if (s->flags & CIP_DBC_IS_END_EVENT)562562+ s->data_block_counter = data_block_counter;563563+ else564564+ s->data_block_counter =565565+ (data_block_counter + data_blocks) & 0xff;566566+end:567567+ if (queue_in_packet(s) < 0)568568+ goto err;650569651570 if (pcm)652652- snd_pcm_period_elapsed(pcm);571571+ update_pcm_pointers(s, pcm, data_blocks);572572+573573+ return;574574+err:575575+ s->packet_index = -1;576576+ amdtp_stream_pcm_abort(s);653577}654578655655-static void out_packet_callback(struct fw_iso_context *context, u32 cycle,656656- size_t header_length, void *header, void *data)579579+static void out_stream_callback(struct fw_iso_context *context, u32 cycle,580580+ size_t header_length, void *header,581581+ void *private_data)657582{658658- struct amdtp_out_stream *s = data;659659- unsigned int i, packets = header_length / 4;583583+ struct amdtp_stream *s = private_data;584584+ unsigned int i, syt, packets = header_length / 4;660585661586 /*662587 * Compute the cycle of the last queued packet.···734521 */735522 cycle += QUEUE_LENGTH - packets;736523737737- for (i = 0; i < packets; ++i)738738- queue_out_packet(s, ++cycle);524524+ for (i = 0; i < packets; ++i) {525525+ syt = calculate_syt(s, ++cycle);526526+ handle_out_packet(s, syt);527527+ }739528 fw_iso_context_queue_flush(s->context);740529}741530742742-static int queue_initial_skip_packets(struct amdtp_out_stream *s)531531+static void in_stream_callback(struct fw_iso_context *context, u32 cycle,532532+ size_t header_length, void *header,533533+ void *private_data)743534{744744- struct fw_iso_packet skip_packet = {745745- .skip = 1,746746- };747747- unsigned int i;748748- int err;535535+ struct amdtp_stream *s = private_data;536536+ unsigned int p, syt, packets, payload_quadlets;537537+ __be32 *buffer, *headers = header;749538750750- for (i = 0; i < QUEUE_LENGTH; ++i) {751751- skip_packet.interrupt = IS_ALIGNED(s->packet_index + 1,752752- INTERRUPT_INTERVAL);753753- err = fw_iso_context_queue(s->context, &skip_packet, NULL, 0);754754- if (err < 0)755755- return err;756756- if (++s->packet_index >= QUEUE_LENGTH)757757- s->packet_index = 0;539539+ /* The number of packets in buffer */540540+ packets = header_length / IN_PACKET_HEADER_SIZE;541541+542542+ for (p = 0; p < packets; p++) {543543+ if (s->packet_index < 0)544544+ break;545545+546546+ buffer = s->buffer.packets[s->packet_index].buffer;547547+548548+ /* Process sync slave stream */549549+ if (s->sync_slave && s->sync_slave->callbacked) {550550+ syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK;551551+ handle_out_packet(s->sync_slave, syt);552552+ }553553+554554+ /* The number of quadlets in this packet */555555+ payload_quadlets =556556+ (be32_to_cpu(headers[p]) >> ISO_DATA_LENGTH_SHIFT) / 4;557557+ handle_in_packet(s, payload_quadlets, buffer);758558 }759559760760- return 0;560560+ /* Queueing error or detecting discontinuity */561561+ if (s->packet_index < 0) {562562+ /* Abort sync slave. */563563+ if (s->sync_slave) {564564+ s->sync_slave->packet_index = -1;565565+ amdtp_stream_pcm_abort(s->sync_slave);566566+ }567567+ return;568568+ }569569+570570+ /* when sync to device, flush the packets for slave stream */571571+ if (s->sync_slave && s->sync_slave->callbacked)572572+ fw_iso_context_queue_flush(s->sync_slave->context);573573+574574+ fw_iso_context_queue_flush(s->context);575575+}576576+577577+/* processing is done by master callback */578578+static void slave_stream_callback(struct fw_iso_context *context, u32 cycle,579579+ size_t header_length, void *header,580580+ void *private_data)581581+{582582+ return;583583+}584584+585585+/* this is executed one time */586586+static void amdtp_stream_first_callback(struct fw_iso_context *context,587587+ u32 cycle, size_t header_length,588588+ void *header, void *private_data)589589+{590590+ struct amdtp_stream *s = private_data;591591+592592+ /*593593+ * For in-stream, first packet has come.594594+ * For out-stream, prepared to transmit first packet595595+ */596596+ s->callbacked = true;597597+ wake_up(&s->callback_wait);598598+599599+ if (s->direction == AMDTP_IN_STREAM)600600+ context->callback.sc = in_stream_callback;601601+ else if ((s->flags & CIP_BLOCKING) && (s->flags & CIP_SYNC_TO_DEVICE))602602+ context->callback.sc = slave_stream_callback;603603+ else604604+ context->callback.sc = out_stream_callback;605605+606606+ context->callback.sc(context, cycle, header_length, header, s);761607}762608763609/**764764- * amdtp_out_stream_start - start sending packets765765- * @s: the AMDTP output stream to start610610+ * amdtp_stream_start - start transferring packets611611+ * @s: the AMDTP stream to start766612 * @channel: the isochronous channel on the bus767613 * @speed: firewire speed code768614 *769615 * The stream cannot be started until it has been configured with770770- * amdtp_out_stream_set_parameters() and amdtp_out_stream_set_pcm_format(),771771- * and it must be started before any PCM or MIDI device can be started.616616+ * amdtp_stream_set_parameters() and it must be started before any PCM or MIDI617617+ * device can be started.772618 */773773-int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed)619619+int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed)774620{775621 static const struct {776622 unsigned int data_block;···843571 [CIP_SFC_88200] = { 0, 67 },844572 [CIP_SFC_176400] = { 0, 67 },845573 };846846- int err;574574+ unsigned int header_size;575575+ enum dma_data_direction dir;576576+ int type, tag, err;847577848578 mutex_lock(&s->mutex);849579850850- if (WARN_ON(amdtp_out_stream_running(s) ||851851- (!s->pcm_channels && !s->midi_ports))) {580580+ if (WARN_ON(amdtp_stream_running(s) ||581581+ (s->data_block_quadlets < 1))) {852582 err = -EBADFD;853583 goto err_unlock;854584 }855585586586+ if (s->direction == AMDTP_IN_STREAM &&587587+ s->flags & CIP_SKIP_INIT_DBC_CHECK)588588+ s->data_block_counter = UINT_MAX;589589+ else590590+ s->data_block_counter = 0;856591 s->data_block_state = initial_state[s->sfc].data_block;857592 s->syt_offset_state = initial_state[s->sfc].syt_offset;858593 s->last_syt_offset = TICKS_PER_CYCLE;859594595595+ /* initialize packet buffer */596596+ if (s->direction == AMDTP_IN_STREAM) {597597+ dir = DMA_FROM_DEVICE;598598+ type = FW_ISO_CONTEXT_RECEIVE;599599+ header_size = IN_PACKET_HEADER_SIZE;600600+ } else {601601+ dir = DMA_TO_DEVICE;602602+ type = FW_ISO_CONTEXT_TRANSMIT;603603+ header_size = OUT_PACKET_HEADER_SIZE;604604+ }860605 err = iso_packets_buffer_init(&s->buffer, s->unit, QUEUE_LENGTH,861861- amdtp_out_stream_get_max_payload(s),862862- DMA_TO_DEVICE);606606+ amdtp_stream_get_max_payload(s), dir);863607 if (err < 0)864608 goto err_unlock;865609866610 s->context = fw_iso_context_create(fw_parent_device(s->unit)->card,867867- FW_ISO_CONTEXT_TRANSMIT,868868- channel, speed, 0,869869- out_packet_callback, s);611611+ type, channel, speed, header_size,612612+ amdtp_stream_first_callback, s);870613 if (IS_ERR(s->context)) {871614 err = PTR_ERR(s->context);872615 if (err == -EBUSY)873616 dev_err(&s->unit->device,874874- "no free output stream on this controller\n");617617+ "no free stream on this controller\n");875618 goto err_buffer;876619 }877620878878- amdtp_out_stream_update(s);621621+ amdtp_stream_update(s);879622880623 s->packet_index = 0;881881- s->data_block_counter = 0;882882- err = queue_initial_skip_packets(s);883883- if (err < 0)884884- goto err_context;624624+ do {625625+ if (s->direction == AMDTP_IN_STREAM)626626+ err = queue_in_packet(s);627627+ else628628+ err = queue_out_packet(s, 0, true);629629+ if (err < 0)630630+ goto err_context;631631+ } while (s->packet_index > 0);885632886886- err = fw_iso_context_start(s->context, -1, 0, 0);633633+ /* NOTE: TAG1 matches CIP. This just affects in stream. */634634+ tag = FW_ISO_CONTEXT_MATCH_TAG1;635635+ if (s->flags & CIP_EMPTY_WITH_TAG0)636636+ tag |= FW_ISO_CONTEXT_MATCH_TAG0;637637+638638+ s->callbacked = false;639639+ err = fw_iso_context_start(s->context, -1, 0, tag);887640 if (err < 0)888641 goto err_context;889642···926629927630 return err;928631}929929-EXPORT_SYMBOL(amdtp_out_stream_start);632632+EXPORT_SYMBOL(amdtp_stream_start);930633931634/**932932- * amdtp_out_stream_pcm_pointer - get the PCM buffer position933933- * @s: the AMDTP output stream that transports the PCM data635635+ * amdtp_stream_pcm_pointer - get the PCM buffer position636636+ * @s: the AMDTP stream that transports the PCM data934637 *935638 * Returns the current buffer position, in frames.936639 */937937-unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s)640640+unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s)938641{939642 /* this optimization is allowed to be racy */940940- if (s->pointer_flush)643643+ if (s->pointer_flush && amdtp_stream_running(s))941644 fw_iso_context_flush_completions(s->context);942645 else943646 s->pointer_flush = true;944647945648 return ACCESS_ONCE(s->pcm_buffer_pointer);946649}947947-EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);650650+EXPORT_SYMBOL(amdtp_stream_pcm_pointer);948651949652/**950950- * amdtp_out_stream_update - update the stream after a bus reset951951- * @s: the AMDTP output stream653653+ * amdtp_stream_update - update the stream after a bus reset654654+ * @s: the AMDTP stream952655 */953953-void amdtp_out_stream_update(struct amdtp_out_stream *s)656656+void amdtp_stream_update(struct amdtp_stream *s)954657{955658 ACCESS_ONCE(s->source_node_id_field) =956659 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;957660}958958-EXPORT_SYMBOL(amdtp_out_stream_update);661661+EXPORT_SYMBOL(amdtp_stream_update);959662960663/**961961- * amdtp_out_stream_stop - stop sending packets962962- * @s: the AMDTP output stream to stop664664+ * amdtp_stream_stop - stop sending packets665665+ * @s: the AMDTP stream to stop963666 *964667 * All PCM and MIDI devices of the stream must be stopped before the stream965668 * itself can be stopped.966669 */967967-void amdtp_out_stream_stop(struct amdtp_out_stream *s)670670+void amdtp_stream_stop(struct amdtp_stream *s)968671{969672 mutex_lock(&s->mutex);970673971971- if (!amdtp_out_stream_running(s)) {674674+ if (!amdtp_stream_running(s)) {972675 mutex_unlock(&s->mutex);973676 return;974677 }···979682 s->context = ERR_PTR(-1);980683 iso_packets_buffer_destroy(&s->buffer, s->unit);981684685685+ s->callbacked = false;686686+982687 mutex_unlock(&s->mutex);983688}984984-EXPORT_SYMBOL(amdtp_out_stream_stop);689689+EXPORT_SYMBOL(amdtp_stream_stop);985690986691/**987987- * amdtp_out_stream_pcm_abort - abort the running PCM device692692+ * amdtp_stream_pcm_abort - abort the running PCM device988693 * @s: the AMDTP stream about to be stopped989694 *990695 * If the isochronous stream needs to be stopped asynchronously, call this991696 * function first to stop the PCM device.992697 */993993-void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s)698698+void amdtp_stream_pcm_abort(struct amdtp_stream *s)994699{995700 struct snd_pcm_substream *pcm;996701···1004705 snd_pcm_stream_unlock_irq(pcm);1005706 }1006707}10071007-EXPORT_SYMBOL(amdtp_out_stream_pcm_abort);708708+EXPORT_SYMBOL(amdtp_stream_pcm_abort);
+163-37
sound/firewire/amdtp.h
···88#include "packets-buffer.h"991010/**1111- * enum cip_out_flags - describes details of the streaming protocol1111+ * enum cip_flags - describes details of the streaming protocol1212 * @CIP_NONBLOCKING: In non-blocking mode, each packet contains1313 * sample_rate/8000 samples, with rounding up or down to adjust1414 * for clock skew and left-over fractional samples. This should···1616 * @CIP_BLOCKING: In blocking mode, each packet contains either zero or1717 * SYT_INTERVAL samples, with these two types alternating so that1818 * the overall sample rate comes out right.1919- * @CIP_HI_DUALWIRE: At rates above 96 kHz, pretend that the stream runs2020- * at half the actual sample rate with twice the number of channels;2121- * two samples of a channel are stored consecutively in the packet.2222- * Requires blocking mode and SYT_INTERVAL-aligned PCM buffer size.1919+ * @CIP_SYNC_TO_DEVICE: In sync to device mode, time stamp in out packets is2020+ * generated by in packets. Defaultly this driver generates timestamp.2121+ * @CIP_EMPTY_WITH_TAG0: Only for in-stream. Empty in-packets have TAG0.2222+ * @CIP_DBC_IS_END_EVENT: Only for in-stream. The value of dbc in an in-packet2323+ * corresponds to the end of event in the packet. Out of IEC 61883.2424+ * @CIP_WRONG_DBS: Only for in-stream. The value of dbs is wrong in in-packets.2525+ * The value of data_block_quadlets is used instead of reported value.2626+ * @SKIP_DBC_ZERO_CHECK: Only for in-stream. Packets with zero in dbc is2727+ * skipped for detecting discontinuity.2828+ * @CIP_SKIP_INIT_DBC_CHECK: Only for in-stream. The value of dbc in first2929+ * packet is not continuous from an initial value.3030+ * @CIP_EMPTY_HAS_WRONG_DBC: Only for in-stream. The value of dbc in empty3131+ * packet is wrong but the others are correct.2332 */2424-enum cip_out_flags {2525- CIP_NONBLOCKING = 0x00,2626- CIP_BLOCKING = 0x01,2727- CIP_HI_DUALWIRE = 0x02,3333+enum cip_flags {3434+ CIP_NONBLOCKING = 0x00,3535+ CIP_BLOCKING = 0x01,3636+ CIP_SYNC_TO_DEVICE = 0x02,3737+ CIP_EMPTY_WITH_TAG0 = 0x04,3838+ CIP_DBC_IS_END_EVENT = 0x08,3939+ CIP_WRONG_DBS = 0x10,4040+ CIP_SKIP_DBC_ZERO_CHECK = 0x20,4141+ CIP_SKIP_INIT_DBC_CHECK = 0x40,4242+ CIP_EMPTY_HAS_WRONG_DBC = 0x80,2843};29443045/**···5641 CIP_SFC_COUNT5742};58434444+#define AMDTP_IN_PCM_FORMAT_BITS SNDRV_PCM_FMTBIT_S324545+5946#define AMDTP_OUT_PCM_FORMAT_BITS (SNDRV_PCM_FMTBIT_S16 | \6047 SNDRV_PCM_FMTBIT_S32)4848+4949+5050+/*5151+ * This module supports maximum 64 PCM channels for one PCM stream5252+ * This is for our convenience.5353+ */5454+#define AMDTP_MAX_CHANNELS_FOR_PCM 645555+5656+/*5757+ * AMDTP packet can include channels for MIDI conformant data.5858+ * Each MIDI conformant data channel includes 8 MPX-MIDI data stream.5959+ * Each MPX-MIDI data stream includes one data stream from/to MIDI ports.6060+ *6161+ * This module supports maximum 1 MIDI conformant data channels.6262+ * Then this AMDTP packets can transfer maximum 8 MIDI data streams.6363+ */6464+#define AMDTP_MAX_CHANNELS_FOR_MIDI 161656266struct fw_unit;6367struct fw_iso_context;6468struct snd_pcm_substream;6969+struct snd_pcm_runtime;7070+struct snd_rawmidi_substream;65716666-struct amdtp_out_stream {7272+enum amdtp_stream_direction {7373+ AMDTP_OUT_STREAM = 0,7474+ AMDTP_IN_STREAM7575+};7676+7777+struct amdtp_stream {6778 struct fw_unit *unit;6868- enum cip_out_flags flags;7979+ enum cip_flags flags;8080+ enum amdtp_stream_direction direction;6981 struct fw_iso_context *context;7082 struct mutex mutex;71837284 enum cip_sfc sfc;7373- bool dual_wire;7485 unsigned int data_block_quadlets;7586 unsigned int pcm_channels;7687 unsigned int midi_ports;7777- void (*transfer_samples)(struct amdtp_out_stream *s,8888+ void (*transfer_samples)(struct amdtp_stream *s,7889 struct snd_pcm_substream *pcm,7990 __be32 *buffer, unsigned int frames);9191+ u8 pcm_positions[AMDTP_MAX_CHANNELS_FOR_PCM];9292+ u8 midi_position;80938194 unsigned int syt_interval;8295 unsigned int transfer_delay;···12582 unsigned int pcm_buffer_pointer;12683 unsigned int pcm_period_pointer;12784 bool pointer_flush;8585+8686+ struct snd_rawmidi_substream *midi[AMDTP_MAX_CHANNELS_FOR_MIDI * 8];8787+8888+ /* quirk: fixed interval of dbc between previos/current packets. */8989+ unsigned int tx_dbc_interval;9090+9191+ /* quirk: the first count of data blocks in an rx packet for MIDI */9292+ unsigned int rx_blocks_for_midi;9393+9494+ bool callbacked;9595+ wait_queue_head_t callback_wait;9696+ struct amdtp_stream *sync_slave;12897};12998130130-int amdtp_out_stream_init(struct amdtp_out_stream *s, struct fw_unit *unit,131131- enum cip_out_flags flags);132132-void amdtp_out_stream_destroy(struct amdtp_out_stream *s);9999+int amdtp_stream_init(struct amdtp_stream *s, struct fw_unit *unit,100100+ enum amdtp_stream_direction dir,101101+ enum cip_flags flags);102102+void amdtp_stream_destroy(struct amdtp_stream *s);133103134134-void amdtp_out_stream_set_parameters(struct amdtp_out_stream *s,135135- unsigned int rate,136136- unsigned int pcm_channels,137137- unsigned int midi_ports);138138-unsigned int amdtp_out_stream_get_max_payload(struct amdtp_out_stream *s);104104+void amdtp_stream_set_parameters(struct amdtp_stream *s,105105+ unsigned int rate,106106+ unsigned int pcm_channels,107107+ unsigned int midi_ports);108108+unsigned int amdtp_stream_get_max_payload(struct amdtp_stream *s);139109140140-int amdtp_out_stream_start(struct amdtp_out_stream *s, int channel, int speed);141141-void amdtp_out_stream_update(struct amdtp_out_stream *s);142142-void amdtp_out_stream_stop(struct amdtp_out_stream *s);110110+int amdtp_stream_start(struct amdtp_stream *s, int channel, int speed);111111+void amdtp_stream_update(struct amdtp_stream *s);112112+void amdtp_stream_stop(struct amdtp_stream *s);143113144144-void amdtp_out_stream_set_pcm_format(struct amdtp_out_stream *s,145145- snd_pcm_format_t format);146146-void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s);147147-unsigned long amdtp_out_stream_pcm_pointer(struct amdtp_out_stream *s);148148-void amdtp_out_stream_pcm_abort(struct amdtp_out_stream *s);114114+int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,115115+ struct snd_pcm_runtime *runtime);116116+void amdtp_stream_set_pcm_format(struct amdtp_stream *s,117117+ snd_pcm_format_t format);118118+void amdtp_stream_pcm_prepare(struct amdtp_stream *s);119119+unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);120120+void amdtp_stream_pcm_abort(struct amdtp_stream *s);149121150122extern const unsigned int amdtp_syt_intervals[CIP_SFC_COUNT];123123+extern const unsigned int amdtp_rate_table[CIP_SFC_COUNT];151124152152-static inline bool amdtp_out_stream_running(struct amdtp_out_stream *s)125125+/**126126+ * amdtp_stream_running - check stream is running or not127127+ * @s: the AMDTP stream128128+ *129129+ * If this function returns true, the stream is running.130130+ */131131+static inline bool amdtp_stream_running(struct amdtp_stream *s)153132{154133 return !IS_ERR(s->context);155134}156135157136/**158158- * amdtp_out_streaming_error - check for streaming error159159- * @s: the AMDTP output stream137137+ * amdtp_streaming_error - check for streaming error138138+ * @s: the AMDTP stream160139 *161140 * If this function returns true, the stream's packet queue has stopped due to162141 * an asynchronous error.163142 */164164-static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)143143+static inline bool amdtp_streaming_error(struct amdtp_stream *s)165144{166145 return s->packet_index < 0;167146}168147169148/**170170- * amdtp_out_stream_pcm_trigger - start/stop playback from a PCM device171171- * @s: the AMDTP output stream149149+ * amdtp_stream_pcm_running - check PCM substream is running or not150150+ * @s: the AMDTP stream151151+ *152152+ * If this function returns true, PCM substream in the AMDTP stream is running.153153+ */154154+static inline bool amdtp_stream_pcm_running(struct amdtp_stream *s)155155+{156156+ return !!s->pcm;157157+}158158+159159+/**160160+ * amdtp_stream_pcm_trigger - start/stop playback from a PCM device161161+ * @s: the AMDTP stream172162 * @pcm: the PCM device to be started, or %NULL to stop the current device173163 *174164 * Call this function on a running isochronous stream to enable the actual175165 * transmission of PCM data. This function should be called from the PCM176166 * device's .trigger callback.177167 */178178-static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,179179- struct snd_pcm_substream *pcm)168168+static inline void amdtp_stream_pcm_trigger(struct amdtp_stream *s,169169+ struct snd_pcm_substream *pcm)180170{181171 ACCESS_ONCE(s->pcm) = pcm;172172+}173173+174174+/**175175+ * amdtp_stream_midi_trigger - start/stop playback/capture with a MIDI device176176+ * @s: the AMDTP stream177177+ * @port: index of MIDI port178178+ * @midi: the MIDI device to be started, or %NULL to stop the current device179179+ *180180+ * Call this function on a running isochronous stream to enable the actual181181+ * transmission of MIDI data. This function should be called from the MIDI182182+ * device's .trigger callback.183183+ */184184+static inline void amdtp_stream_midi_trigger(struct amdtp_stream *s,185185+ unsigned int port,186186+ struct snd_rawmidi_substream *midi)187187+{188188+ if (port < s->midi_ports)189189+ ACCESS_ONCE(s->midi[port]) = midi;182190}183191184192static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)185193{186194 return sfc & 1;195195+}196196+197197+static inline void amdtp_stream_set_sync(enum cip_flags sync_mode,198198+ struct amdtp_stream *master,199199+ struct amdtp_stream *slave)200200+{201201+ if (sync_mode == CIP_SYNC_TO_DEVICE) {202202+ master->flags |= CIP_SYNC_TO_DEVICE;203203+ slave->flags |= CIP_SYNC_TO_DEVICE;204204+ master->sync_slave = slave;205205+ } else {206206+ master->flags &= ~CIP_SYNC_TO_DEVICE;207207+ slave->flags &= ~CIP_SYNC_TO_DEVICE;208208+ master->sync_slave = NULL;209209+ }210210+211211+ slave->sync_slave = NULL;212212+}213213+214214+/**215215+ * amdtp_stream_wait_callback - sleep till callbacked or timeout216216+ * @s: the AMDTP stream217217+ * @timeout: msec till timeout218218+ *219219+ * If this function return false, the AMDTP stream should be stopped.220220+ */221221+static inline bool amdtp_stream_wait_callback(struct amdtp_stream *s,222222+ unsigned int timeout)223223+{224224+ return wait_event_timeout(s->callback_wait,225225+ s->callbacked == true,226226+ msecs_to_jiffies(timeout)) > 0;187227}188228189229#endif
···11+/*22+ * bebob.h - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#ifndef SOUND_BEBOB_H_INCLUDED1010+#define SOUND_BEBOB_H_INCLUDED1111+1212+#include <linux/compat.h>1313+#include <linux/device.h>1414+#include <linux/firewire.h>1515+#include <linux/firewire-constants.h>1616+#include <linux/module.h>1717+#include <linux/mod_devicetable.h>1818+#include <linux/delay.h>1919+#include <linux/slab.h>2020+2121+#include <sound/core.h>2222+#include <sound/initval.h>2323+#include <sound/info.h>2424+#include <sound/rawmidi.h>2525+#include <sound/pcm.h>2626+#include <sound/pcm_params.h>2727+#include <sound/firewire.h>2828+#include <sound/hwdep.h>2929+3030+#include "../lib.h"3131+#include "../fcp.h"3232+#include "../packets-buffer.h"3333+#include "../iso-resources.h"3434+#include "../amdtp.h"3535+#include "../cmp.h"3636+3737+/* basic register addresses on DM1000/DM1100/DM1500 */3838+#define BEBOB_ADDR_REG_INFO 0xffffc8020000ULL3939+#define BEBOB_ADDR_REG_REQ 0xffffc8021000ULL4040+4141+struct snd_bebob;4242+4343+#define SND_BEBOB_STRM_FMT_ENTRIES 74444+struct snd_bebob_stream_formation {4545+ unsigned int pcm;4646+ unsigned int midi;4747+};4848+/* this is a lookup table for index of stream formations */4949+extern const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES];5050+5151+/* device specific operations */5252+#define SND_BEBOB_CLOCK_INTERNAL "Internal"5353+struct snd_bebob_clock_spec {5454+ unsigned int num;5555+ char *const *labels;5656+ int (*get)(struct snd_bebob *bebob, unsigned int *id);5757+};5858+struct snd_bebob_rate_spec {5959+ int (*get)(struct snd_bebob *bebob, unsigned int *rate);6060+ int (*set)(struct snd_bebob *bebob, unsigned int rate);6161+};6262+struct snd_bebob_meter_spec {6363+ unsigned int num;6464+ char *const *labels;6565+ int (*get)(struct snd_bebob *bebob, u32 *target, unsigned int size);6666+};6767+struct snd_bebob_spec {6868+ struct snd_bebob_clock_spec *clock;6969+ struct snd_bebob_rate_spec *rate;7070+ struct snd_bebob_meter_spec *meter;7171+};7272+7373+struct snd_bebob {7474+ struct snd_card *card;7575+ struct fw_unit *unit;7676+ int card_index;7777+7878+ struct mutex mutex;7979+ spinlock_t lock;8080+8181+ const struct snd_bebob_spec *spec;8282+8383+ unsigned int midi_input_ports;8484+ unsigned int midi_output_ports;8585+8686+ /* for bus reset quirk */8787+ struct completion bus_reset;8888+ bool connected;8989+9090+ struct amdtp_stream *master;9191+ struct amdtp_stream tx_stream;9292+ struct amdtp_stream rx_stream;9393+ struct cmp_connection out_conn;9494+ struct cmp_connection in_conn;9595+ atomic_t capture_substreams;9696+ atomic_t playback_substreams;9797+9898+ struct snd_bebob_stream_formation9999+ tx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];100100+ struct snd_bebob_stream_formation101101+ rx_stream_formations[SND_BEBOB_STRM_FMT_ENTRIES];102102+103103+ int sync_input_plug;104104+105105+ /* for uapi */106106+ int dev_lock_count;107107+ bool dev_lock_changed;108108+ wait_queue_head_t hwdep_wait;109109+110110+ /* for M-Audio special devices */111111+ void *maudio_special_quirk;112112+ bool deferred_registration;113113+};114114+115115+static inline int116116+snd_bebob_read_block(struct fw_unit *unit, u64 addr, void *buf, int size)117117+{118118+ return snd_fw_transaction(unit, TCODE_READ_BLOCK_REQUEST,119119+ BEBOB_ADDR_REG_INFO + addr,120120+ buf, size, 0);121121+}122122+123123+static inline int124124+snd_bebob_read_quad(struct fw_unit *unit, u64 addr, u32 *buf)125125+{126126+ return snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,127127+ BEBOB_ADDR_REG_INFO + addr,128128+ (void *)buf, sizeof(u32), 0);129129+}130130+131131+/* AV/C Audio Subunit Specification 1.0 (Oct 2000, 1394TA) */132132+int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,133133+ unsigned int fb_id, unsigned int num);134134+int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,135135+ unsigned int fb_id, unsigned int *num);136136+137137+/*138138+ * AVC command extensions, AV/C Unit and Subunit, Revision 17139139+ * (Nov 2003, BridgeCo)140140+ */141141+#define AVC_BRIDGECO_ADDR_BYTES 6142142+enum avc_bridgeco_plug_dir {143143+ AVC_BRIDGECO_PLUG_DIR_IN = 0x00,144144+ AVC_BRIDGECO_PLUG_DIR_OUT = 0x01145145+};146146+enum avc_bridgeco_plug_mode {147147+ AVC_BRIDGECO_PLUG_MODE_UNIT = 0x00,148148+ AVC_BRIDGECO_PLUG_MODE_SUBUNIT = 0x01,149149+ AVC_BRIDGECO_PLUG_MODE_FUNCTION_BLOCK = 0x02150150+};151151+enum avc_bridgeco_plug_unit {152152+ AVC_BRIDGECO_PLUG_UNIT_ISOC = 0x00,153153+ AVC_BRIDGECO_PLUG_UNIT_EXT = 0x01,154154+ AVC_BRIDGECO_PLUG_UNIT_ASYNC = 0x02155155+};156156+enum avc_bridgeco_plug_type {157157+ AVC_BRIDGECO_PLUG_TYPE_ISOC = 0x00,158158+ AVC_BRIDGECO_PLUG_TYPE_ASYNC = 0x01,159159+ AVC_BRIDGECO_PLUG_TYPE_MIDI = 0x02,160160+ AVC_BRIDGECO_PLUG_TYPE_SYNC = 0x03,161161+ AVC_BRIDGECO_PLUG_TYPE_ANA = 0x04,162162+ AVC_BRIDGECO_PLUG_TYPE_DIG = 0x05163163+};164164+static inline void165165+avc_bridgeco_fill_unit_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],166166+ enum avc_bridgeco_plug_dir dir,167167+ enum avc_bridgeco_plug_unit unit,168168+ unsigned int pid)169169+{170170+ buf[0] = 0xff; /* Unit */171171+ buf[1] = dir;172172+ buf[2] = AVC_BRIDGECO_PLUG_MODE_UNIT;173173+ buf[3] = unit;174174+ buf[4] = 0xff & pid;175175+ buf[5] = 0xff; /* reserved */176176+}177177+static inline void178178+avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],179179+ enum avc_bridgeco_plug_dir dir,180180+ unsigned int pid)181181+{182182+ buf[0] = 0x60; /* Music subunit */183183+ buf[1] = dir;184184+ buf[2] = AVC_BRIDGECO_PLUG_MODE_SUBUNIT;185185+ buf[3] = 0xff & pid;186186+ buf[4] = 0xff; /* reserved */187187+ buf[5] = 0xff; /* reserved */188188+}189189+int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,190190+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],191191+ u8 *buf, unsigned int len);192192+int avc_bridgeco_get_plug_type(struct fw_unit *unit,193193+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],194194+ enum avc_bridgeco_plug_type *type);195195+int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,196196+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],197197+ unsigned int id, u8 *type);198198+int avc_bridgeco_get_plug_input(struct fw_unit *unit,199199+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],200200+ u8 input[7]);201201+int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,202202+ u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,203203+ unsigned int *len, unsigned int eid);204204+205205+/* for AMDTP streaming */206206+int snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *rate);207207+int snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate);208208+int snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob,209209+ bool *internal);210210+int snd_bebob_stream_discover(struct snd_bebob *bebob);211211+int snd_bebob_stream_map(struct snd_bebob *bebob,212212+ struct amdtp_stream *stream);213213+int snd_bebob_stream_init_duplex(struct snd_bebob *bebob);214214+int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate);215215+void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob);216216+void snd_bebob_stream_update_duplex(struct snd_bebob *bebob);217217+void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob);218218+219219+void snd_bebob_stream_lock_changed(struct snd_bebob *bebob);220220+int snd_bebob_stream_lock_try(struct snd_bebob *bebob);221221+void snd_bebob_stream_lock_release(struct snd_bebob *bebob);222222+223223+void snd_bebob_proc_init(struct snd_bebob *bebob);224224+225225+int snd_bebob_create_midi_devices(struct snd_bebob *bebob);226226+227227+int snd_bebob_create_pcm_devices(struct snd_bebob *bebob);228228+229229+int snd_bebob_create_hwdep_device(struct snd_bebob *bebob);230230+231231+/* model specific operations */232232+extern struct snd_bebob_spec phase88_rack_spec;233233+extern struct snd_bebob_spec phase24_series_spec;234234+extern struct snd_bebob_spec yamaha_go_spec;235235+extern struct snd_bebob_spec saffirepro_26_spec;236236+extern struct snd_bebob_spec saffirepro_10_spec;237237+extern struct snd_bebob_spec saffire_le_spec;238238+extern struct snd_bebob_spec saffire_spec;239239+extern struct snd_bebob_spec maudio_fw410_spec;240240+extern struct snd_bebob_spec maudio_audiophile_spec;241241+extern struct snd_bebob_spec maudio_solo_spec;242242+extern struct snd_bebob_spec maudio_ozonic_spec;243243+extern struct snd_bebob_spec maudio_nrv10_spec;244244+extern struct snd_bebob_spec maudio_special_spec;245245+int snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814);246246+int snd_bebob_maudio_load_firmware(struct fw_unit *unit);247247+248248+#define SND_BEBOB_DEV_ENTRY(vendor, model, data) \249249+{ \250250+ .match_flags = IEEE1394_MATCH_VENDOR_ID | \251251+ IEEE1394_MATCH_MODEL_ID, \252252+ .vendor_id = vendor, \253253+ .model_id = model, \254254+ .driver_data = (kernel_ulong_t)data \255255+}256256+257257+#endif
+282
sound/firewire/bebob/bebob_command.c
···11+/*22+ * bebob_command.c - driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+int avc_audio_set_selector(struct fw_unit *unit, unsigned int subunit_id,1212+ unsigned int fb_id, unsigned int num)1313+{1414+ u8 *buf;1515+ int err;1616+1717+ buf = kzalloc(12, GFP_KERNEL);1818+ if (buf == NULL)1919+ return -ENOMEM;2020+2121+ buf[0] = 0x00; /* AV/C CONTROL */2222+ buf[1] = 0x08 | (0x07 & subunit_id); /* AUDIO SUBUNIT ID */2323+ buf[2] = 0xb8; /* FUNCTION BLOCK */2424+ buf[3] = 0x80; /* type is 'selector'*/2525+ buf[4] = 0xff & fb_id; /* function block id */2626+ buf[5] = 0x10; /* control attribute is CURRENT */2727+ buf[6] = 0x02; /* selector length is 2 */2828+ buf[7] = 0xff & num; /* input function block plug number */2929+ buf[8] = 0x01; /* control selector is SELECTOR_CONTROL */3030+3131+ err = fcp_avc_transaction(unit, buf, 12, buf, 12,3232+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |3333+ BIT(6) | BIT(7) | BIT(8));3434+ if (err > 0 && err < 9)3535+ err = -EIO;3636+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */3737+ err = -ENOSYS;3838+ else if (buf[0] == 0x0a) /* REJECTED */3939+ err = -EINVAL;4040+ else if (err > 0)4141+ err = 0;4242+4343+ kfree(buf);4444+ return err;4545+}4646+4747+int avc_audio_get_selector(struct fw_unit *unit, unsigned int subunit_id,4848+ unsigned int fb_id, unsigned int *num)4949+{5050+ u8 *buf;5151+ int err;5252+5353+ buf = kzalloc(12, GFP_KERNEL);5454+ if (buf == NULL)5555+ return -ENOMEM;5656+5757+ buf[0] = 0x01; /* AV/C STATUS */5858+ buf[1] = 0x08 | (0x07 & subunit_id); /* AUDIO SUBUNIT ID */5959+ buf[2] = 0xb8; /* FUNCTION BLOCK */6060+ buf[3] = 0x80; /* type is 'selector'*/6161+ buf[4] = 0xff & fb_id; /* function block id */6262+ buf[5] = 0x10; /* control attribute is CURRENT */6363+ buf[6] = 0x02; /* selector length is 2 */6464+ buf[7] = 0xff; /* input function block plug number */6565+ buf[8] = 0x01; /* control selector is SELECTOR_CONTROL */6666+6767+ err = fcp_avc_transaction(unit, buf, 12, buf, 12,6868+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |6969+ BIT(6) | BIT(8));7070+ if (err > 0 && err < 9)7171+ err = -EIO;7272+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */7373+ err = -ENOSYS;7474+ else if (buf[0] == 0x0a) /* REJECTED */7575+ err = -EINVAL;7676+ else if (buf[0] == 0x0b) /* IN TRANSITION */7777+ err = -EAGAIN;7878+ if (err < 0)7979+ goto end;8080+8181+ *num = buf[7];8282+ err = 0;8383+end:8484+ kfree(buf);8585+ return err;8686+}8787+8888+static inline void8989+avc_bridgeco_fill_extension_addr(u8 *buf, u8 *addr)9090+{9191+ buf[1] = addr[0];9292+ memcpy(buf + 4, addr + 1, 5);9393+}9494+9595+static inline void9696+avc_bridgeco_fill_plug_info_extension_command(u8 *buf, u8 *addr,9797+ unsigned int itype)9898+{9999+ buf[0] = 0x01; /* AV/C STATUS */100100+ buf[2] = 0x02; /* AV/C GENERAL PLUG INFO */101101+ buf[3] = 0xc0; /* BridgeCo extension */102102+ avc_bridgeco_fill_extension_addr(buf, addr);103103+ buf[9] = itype; /* info type */104104+}105105+106106+int avc_bridgeco_get_plug_type(struct fw_unit *unit,107107+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],108108+ enum avc_bridgeco_plug_type *type)109109+{110110+ u8 *buf;111111+ int err;112112+113113+ buf = kzalloc(12, GFP_KERNEL);114114+ if (buf == NULL)115115+ return -ENOMEM;116116+117117+ /* Info type is 'plug type'. */118118+ avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x00);119119+120120+ err = fcp_avc_transaction(unit, buf, 12, buf, 12,121121+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |122122+ BIT(6) | BIT(7) | BIT(9));123123+ if ((err >= 0) && (err < 8))124124+ err = -EIO;125125+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */126126+ err = -ENOSYS;127127+ else if (buf[0] == 0x0a) /* REJECTED */128128+ err = -EINVAL;129129+ else if (buf[0] == 0x0b) /* IN TRANSITION */130130+ err = -EAGAIN;131131+ if (err < 0)132132+ goto end;133133+134134+ *type = buf[10];135135+ err = 0;136136+end:137137+ kfree(buf);138138+ return err;139139+}140140+141141+int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,142142+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],143143+ u8 *buf, unsigned int len)144144+{145145+ int err;146146+147147+ /* Info type is 'channel position'. */148148+ avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x03);149149+150150+ err = fcp_avc_transaction(unit, buf, 12, buf, 256,151151+ BIT(1) | BIT(2) | BIT(3) | BIT(4) |152152+ BIT(5) | BIT(6) | BIT(7) | BIT(9));153153+ if ((err >= 0) && (err < 8))154154+ err = -EIO;155155+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */156156+ err = -ENOSYS;157157+ else if (buf[0] == 0x0a) /* REJECTED */158158+ err = -EINVAL;159159+ else if (buf[0] == 0x0b) /* IN TRANSITION */160160+ err = -EAGAIN;161161+ if (err < 0)162162+ goto end;163163+164164+ /* Pick up specific data. */165165+ memmove(buf, buf + 10, err - 10);166166+ err = 0;167167+end:168168+ return err;169169+}170170+171171+int avc_bridgeco_get_plug_section_type(struct fw_unit *unit,172172+ u8 addr[AVC_BRIDGECO_ADDR_BYTES],173173+ unsigned int id, u8 *type)174174+{175175+ u8 *buf;176176+ int err;177177+178178+ /* section info includes charactors but this module don't need it */179179+ buf = kzalloc(12, GFP_KERNEL);180180+ if (buf == NULL)181181+ return -ENOMEM;182182+183183+ /* Info type is 'section info'. */184184+ avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x07);185185+ buf[10] = 0xff & ++id; /* section id */186186+187187+ err = fcp_avc_transaction(unit, buf, 12, buf, 12,188188+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |189189+ BIT(6) | BIT(7) | BIT(9) | BIT(10));190190+ if ((err >= 0) && (err < 8))191191+ err = -EIO;192192+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */193193+ err = -ENOSYS;194194+ else if (buf[0] == 0x0a) /* REJECTED */195195+ err = -EINVAL;196196+ else if (buf[0] == 0x0b) /* IN TRANSITION */197197+ err = -EAGAIN;198198+ if (err < 0)199199+ goto end;200200+201201+ *type = buf[11];202202+ err = 0;203203+end:204204+ kfree(buf);205205+ return err;206206+}207207+208208+int avc_bridgeco_get_plug_input(struct fw_unit *unit,209209+ u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 input[7])210210+{211211+ int err;212212+ u8 *buf;213213+214214+ buf = kzalloc(18, GFP_KERNEL);215215+ if (buf == NULL)216216+ return -ENOMEM;217217+218218+ /* Info type is 'plug input'. */219219+ avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x05);220220+221221+ err = fcp_avc_transaction(unit, buf, 16, buf, 16,222222+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |223223+ BIT(6) | BIT(7));224224+ if ((err >= 0) && (err < 8))225225+ err = -EIO;226226+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */227227+ err = -ENOSYS;228228+ else if (buf[0] == 0x0a) /* REJECTED */229229+ err = -EINVAL;230230+ else if (buf[0] == 0x0b) /* IN TRANSITION */231231+ err = -EAGAIN;232232+ if (err < 0)233233+ goto end;234234+235235+ memcpy(input, buf + 10, 5);236236+ err = 0;237237+end:238238+ kfree(buf);239239+ return err;240240+}241241+242242+int avc_bridgeco_get_plug_strm_fmt(struct fw_unit *unit,243243+ u8 addr[AVC_BRIDGECO_ADDR_BYTES], u8 *buf,244244+ unsigned int *len, unsigned int eid)245245+{246246+ int err;247247+248248+ /* check given buffer */249249+ if ((buf == NULL) || (*len < 12)) {250250+ err = -EINVAL;251251+ goto end;252252+ }253253+254254+ buf[0] = 0x01; /* AV/C STATUS */255255+ buf[2] = 0x2f; /* AV/C STREAM FORMAT SUPPORT */256256+ buf[3] = 0xc1; /* Bridgeco extension - List Request */257257+ avc_bridgeco_fill_extension_addr(buf, addr);258258+ buf[10] = 0xff & eid; /* Entry ID */259259+260260+ err = fcp_avc_transaction(unit, buf, 12, buf, *len,261261+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) |262262+ BIT(6) | BIT(7) | BIT(10));263263+ if ((err >= 0) && (err < 12))264264+ err = -EIO;265265+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */266266+ err = -ENOSYS;267267+ else if (buf[0] == 0x0a) /* REJECTED */268268+ err = -EINVAL;269269+ else if (buf[0] == 0x0b) /* IN TRANSITION */270270+ err = -EAGAIN;271271+ else if (buf[10] != eid)272272+ err = -EIO;273273+ if (err < 0)274274+ goto end;275275+276276+ /* Pick up 'stream format info'. */277277+ memmove(buf, buf + 11, err - 11);278278+ *len = err - 11;279279+ err = 0;280280+end:281281+ return err;282282+}
+279
sound/firewire/bebob/bebob_focusrite.c
···11+/*22+ * bebob_focusrite.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+#define ANA_IN "Analog In"1212+#define DIG_IN "Digital In"1313+#define ANA_OUT "Analog Out"1414+#define DIG_OUT "Digital Out"1515+#define STM_IN "Stream In"1616+1717+#define SAFFIRE_ADDRESS_BASE 0x000100000000ULL1818+1919+#define SAFFIRE_OFFSET_CLOCK_SOURCE 0x00f82020+#define SAFFIREPRO_OFFSET_CLOCK_SOURCE 0x01742121+2222+/* whether sync to external device or not */2323+#define SAFFIRE_OFFSET_CLOCK_SYNC_EXT 0x013c2424+#define SAFFIRE_LE_OFFSET_CLOCK_SYNC_EXT 0x04322525+#define SAFFIREPRO_OFFSET_CLOCK_SYNC_EXT 0x01642626+2727+#define SAFFIRE_CLOCK_SOURCE_INTERNAL 02828+#define SAFFIRE_CLOCK_SOURCE_SPDIF 12929+3030+/* '1' is absent, why... */3131+#define SAFFIREPRO_CLOCK_SOURCE_INTERNAL 03232+#define SAFFIREPRO_CLOCK_SOURCE_SPDIF 23333+#define SAFFIREPRO_CLOCK_SOURCE_ADAT1 33434+#define SAFFIREPRO_CLOCK_SOURCE_ADAT2 43535+#define SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK 53636+3737+/* S/PDIF, ADAT1, ADAT2 is enabled or not. three quadlets */3838+#define SAFFIREPRO_ENABLE_DIG_IFACES 0x01a43939+4040+/* saffirepro has its own parameter for sampling frequency */4141+#define SAFFIREPRO_RATE_NOREBOOT 0x01cc4242+/* index is the value for this register */4343+static const unsigned int rates[] = {4444+ [0] = 0,4545+ [1] = 44100,4646+ [2] = 48000,4747+ [3] = 88200,4848+ [4] = 96000,4949+ [5] = 176400,5050+ [6] = 1920005151+};5252+5353+/* saffire(no label)/saffire LE has metering */5454+#define SAFFIRE_OFFSET_METER 0x01005555+#define SAFFIRE_LE_OFFSET_METER 0x01685656+5757+static inline int5858+saffire_read_block(struct snd_bebob *bebob, u64 offset,5959+ u32 *buf, unsigned int size)6060+{6161+ unsigned int i;6262+ int err;6363+ __be32 *tmp = (__be32 *)buf;6464+6565+ err = snd_fw_transaction(bebob->unit, TCODE_READ_BLOCK_REQUEST,6666+ SAFFIRE_ADDRESS_BASE + offset,6767+ tmp, size, 0);6868+ if (err < 0)6969+ goto end;7070+7171+ for (i = 0; i < size / sizeof(u32); i++)7272+ buf[i] = be32_to_cpu(tmp[i]);7373+end:7474+ return err;7575+}7676+7777+static inline int7878+saffire_read_quad(struct snd_bebob *bebob, u64 offset, u32 *value)7979+{8080+ int err;8181+ __be32 tmp;8282+8383+ err = snd_fw_transaction(bebob->unit, TCODE_READ_QUADLET_REQUEST,8484+ SAFFIRE_ADDRESS_BASE + offset,8585+ &tmp, sizeof(__be32), 0);8686+ if (err < 0)8787+ goto end;8888+8989+ *value = be32_to_cpu(tmp);9090+end:9191+ return err;9292+}9393+9494+static inline int9595+saffire_write_quad(struct snd_bebob *bebob, u64 offset, u32 value)9696+{9797+ __be32 data = cpu_to_be32(value);9898+9999+ return snd_fw_transaction(bebob->unit, TCODE_WRITE_QUADLET_REQUEST,100100+ SAFFIRE_ADDRESS_BASE + offset,101101+ &data, sizeof(__be32), 0);102102+}103103+104104+static char *const saffirepro_26_clk_src_labels[] = {105105+ SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "ADAT1", "ADAT2", "Word Clock"106106+};107107+108108+static char *const saffirepro_10_clk_src_labels[] = {109109+ SND_BEBOB_CLOCK_INTERNAL, "S/PDIF", "Word Clock"110110+};111111+static int112112+saffirepro_both_clk_freq_get(struct snd_bebob *bebob, unsigned int *rate)113113+{114114+ u32 id;115115+ int err;116116+117117+ err = saffire_read_quad(bebob, SAFFIREPRO_RATE_NOREBOOT, &id);118118+ if (err < 0)119119+ goto end;120120+ if (id >= ARRAY_SIZE(rates))121121+ err = -EIO;122122+ else123123+ *rate = rates[id];124124+end:125125+ return err;126126+}127127+static int128128+saffirepro_both_clk_freq_set(struct snd_bebob *bebob, unsigned int rate)129129+{130130+ u32 id;131131+132132+ for (id = 0; id < ARRAY_SIZE(rates); id++) {133133+ if (rates[id] == rate)134134+ break;135135+ }136136+ if (id == ARRAY_SIZE(rates))137137+ return -EINVAL;138138+139139+ return saffire_write_quad(bebob, SAFFIREPRO_RATE_NOREBOOT, id);140140+}141141+static int142142+saffirepro_both_clk_src_get(struct snd_bebob *bebob, unsigned int *id)143143+{144144+ int err;145145+ u32 value;146146+147147+ err = saffire_read_quad(bebob, SAFFIREPRO_OFFSET_CLOCK_SOURCE, &value);148148+ if (err < 0)149149+ goto end;150150+151151+ if (bebob->spec->clock->labels == saffirepro_10_clk_src_labels) {152152+ if (value == SAFFIREPRO_CLOCK_SOURCE_WORDCLOCK)153153+ *id = 2;154154+ else if (value == SAFFIREPRO_CLOCK_SOURCE_SPDIF)155155+ *id = 1;156156+ } else if (value > 1) {157157+ *id = value - 1;158158+ }159159+end:160160+ return err;161161+}162162+163163+struct snd_bebob_spec saffire_le_spec;164164+static char *const saffire_both_clk_src_labels[] = {165165+ SND_BEBOB_CLOCK_INTERNAL, "S/PDIF"166166+};167167+static int168168+saffire_both_clk_src_get(struct snd_bebob *bebob, unsigned int *id)169169+{170170+ int err;171171+ u32 value;172172+173173+ err = saffire_read_quad(bebob, SAFFIRE_OFFSET_CLOCK_SOURCE, &value);174174+ if (err >= 0)175175+ *id = 0xff & value;176176+177177+ return err;178178+};179179+static char *const saffire_le_meter_labels[] = {180180+ ANA_IN, ANA_IN, DIG_IN,181181+ ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,182182+ STM_IN, STM_IN183183+};184184+static char *const saffire_meter_labels[] = {185185+ ANA_IN, ANA_IN,186186+ STM_IN, STM_IN, STM_IN, STM_IN, STM_IN,187187+};188188+static int189189+saffire_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)190190+{191191+ struct snd_bebob_meter_spec *spec = bebob->spec->meter;192192+ unsigned int channels;193193+ u64 offset;194194+ int err;195195+196196+ if (spec->labels == saffire_le_meter_labels)197197+ offset = SAFFIRE_LE_OFFSET_METER;198198+ else199199+ offset = SAFFIRE_OFFSET_METER;200200+201201+ channels = spec->num * 2;202202+ if (size < channels * sizeof(u32))203203+ return -EIO;204204+205205+ err = saffire_read_block(bebob, offset, buf, size);206206+ if (err >= 0 && spec->labels == saffire_le_meter_labels) {207207+ swap(buf[1], buf[3]);208208+ swap(buf[2], buf[3]);209209+ swap(buf[3], buf[4]);210210+211211+ swap(buf[7], buf[10]);212212+ swap(buf[8], buf[10]);213213+ swap(buf[9], buf[11]);214214+ swap(buf[11], buf[12]);215215+216216+ swap(buf[15], buf[16]);217217+ }218218+219219+ return err;220220+}221221+222222+static struct snd_bebob_rate_spec saffirepro_both_rate_spec = {223223+ .get = &saffirepro_both_clk_freq_get,224224+ .set = &saffirepro_both_clk_freq_set,225225+};226226+/* Saffire Pro 26 I/O */227227+static struct snd_bebob_clock_spec saffirepro_26_clk_spec = {228228+ .num = ARRAY_SIZE(saffirepro_26_clk_src_labels),229229+ .labels = saffirepro_26_clk_src_labels,230230+ .get = &saffirepro_both_clk_src_get,231231+};232232+struct snd_bebob_spec saffirepro_26_spec = {233233+ .clock = &saffirepro_26_clk_spec,234234+ .rate = &saffirepro_both_rate_spec,235235+ .meter = NULL236236+};237237+/* Saffire Pro 10 I/O */238238+static struct snd_bebob_clock_spec saffirepro_10_clk_spec = {239239+ .num = ARRAY_SIZE(saffirepro_10_clk_src_labels),240240+ .labels = saffirepro_10_clk_src_labels,241241+ .get = &saffirepro_both_clk_src_get,242242+};243243+struct snd_bebob_spec saffirepro_10_spec = {244244+ .clock = &saffirepro_10_clk_spec,245245+ .rate = &saffirepro_both_rate_spec,246246+ .meter = NULL247247+};248248+249249+static struct snd_bebob_rate_spec saffire_both_rate_spec = {250250+ .get = &snd_bebob_stream_get_rate,251251+ .set = &snd_bebob_stream_set_rate,252252+};253253+static struct snd_bebob_clock_spec saffire_both_clk_spec = {254254+ .num = ARRAY_SIZE(saffire_both_clk_src_labels),255255+ .labels = saffire_both_clk_src_labels,256256+ .get = &saffire_both_clk_src_get,257257+};258258+/* Saffire LE */259259+static struct snd_bebob_meter_spec saffire_le_meter_spec = {260260+ .num = ARRAY_SIZE(saffire_le_meter_labels),261261+ .labels = saffire_le_meter_labels,262262+ .get = &saffire_meter_get,263263+};264264+struct snd_bebob_spec saffire_le_spec = {265265+ .clock = &saffire_both_clk_spec,266266+ .rate = &saffire_both_rate_spec,267267+ .meter = &saffire_le_meter_spec268268+};269269+/* Saffire */270270+static struct snd_bebob_meter_spec saffire_meter_spec = {271271+ .num = ARRAY_SIZE(saffire_meter_labels),272272+ .labels = saffire_meter_labels,273273+ .get = &saffire_meter_get,274274+};275275+struct snd_bebob_spec saffire_spec = {276276+ .clock = &saffire_both_clk_spec,277277+ .rate = &saffire_both_rate_spec,278278+ .meter = &saffire_meter_spec279279+};
+199
sound/firewire/bebob/bebob_hwdep.c
···11+/*22+ * bebob_hwdep.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+/*1010+ * This codes give three functionality.1111+ *1212+ * 1.get firewire node infomation1313+ * 2.get notification about starting/stopping stream1414+ * 3.lock/unlock stream1515+ */1616+1717+#include "bebob.h"1818+1919+static long2020+hwdep_read(struct snd_hwdep *hwdep, char __user *buf, long count,2121+ loff_t *offset)2222+{2323+ struct snd_bebob *bebob = hwdep->private_data;2424+ DEFINE_WAIT(wait);2525+ union snd_firewire_event event;2626+2727+ spin_lock_irq(&bebob->lock);2828+2929+ while (!bebob->dev_lock_changed) {3030+ prepare_to_wait(&bebob->hwdep_wait, &wait, TASK_INTERRUPTIBLE);3131+ spin_unlock_irq(&bebob->lock);3232+ schedule();3333+ finish_wait(&bebob->hwdep_wait, &wait);3434+ if (signal_pending(current))3535+ return -ERESTARTSYS;3636+ spin_lock_irq(&bebob->lock);3737+ }3838+3939+ memset(&event, 0, sizeof(event));4040+ if (bebob->dev_lock_changed) {4141+ event.lock_status.type = SNDRV_FIREWIRE_EVENT_LOCK_STATUS;4242+ event.lock_status.status = (bebob->dev_lock_count > 0);4343+ bebob->dev_lock_changed = false;4444+4545+ count = min_t(long, count, sizeof(event.lock_status));4646+ }4747+4848+ spin_unlock_irq(&bebob->lock);4949+5050+ if (copy_to_user(buf, &event, count))5151+ return -EFAULT;5252+5353+ return count;5454+}5555+5656+static unsigned int5757+hwdep_poll(struct snd_hwdep *hwdep, struct file *file, poll_table *wait)5858+{5959+ struct snd_bebob *bebob = hwdep->private_data;6060+ unsigned int events;6161+6262+ poll_wait(file, &bebob->hwdep_wait, wait);6363+6464+ spin_lock_irq(&bebob->lock);6565+ if (bebob->dev_lock_changed)6666+ events = POLLIN | POLLRDNORM;6767+ else6868+ events = 0;6969+ spin_unlock_irq(&bebob->lock);7070+7171+ return events;7272+}7373+7474+static int7575+hwdep_get_info(struct snd_bebob *bebob, void __user *arg)7676+{7777+ struct fw_device *dev = fw_parent_device(bebob->unit);7878+ struct snd_firewire_get_info info;7979+8080+ memset(&info, 0, sizeof(info));8181+ info.type = SNDRV_FIREWIRE_TYPE_BEBOB;8282+ info.card = dev->card->index;8383+ *(__be32 *)&info.guid[0] = cpu_to_be32(dev->config_rom[3]);8484+ *(__be32 *)&info.guid[4] = cpu_to_be32(dev->config_rom[4]);8585+ strlcpy(info.device_name, dev_name(&dev->device),8686+ sizeof(info.device_name));8787+8888+ if (copy_to_user(arg, &info, sizeof(info)))8989+ return -EFAULT;9090+9191+ return 0;9292+}9393+9494+static int9595+hwdep_lock(struct snd_bebob *bebob)9696+{9797+ int err;9898+9999+ spin_lock_irq(&bebob->lock);100100+101101+ if (bebob->dev_lock_count == 0) {102102+ bebob->dev_lock_count = -1;103103+ err = 0;104104+ } else {105105+ err = -EBUSY;106106+ }107107+108108+ spin_unlock_irq(&bebob->lock);109109+110110+ return err;111111+}112112+113113+static int114114+hwdep_unlock(struct snd_bebob *bebob)115115+{116116+ int err;117117+118118+ spin_lock_irq(&bebob->lock);119119+120120+ if (bebob->dev_lock_count == -1) {121121+ bebob->dev_lock_count = 0;122122+ err = 0;123123+ } else {124124+ err = -EBADFD;125125+ }126126+127127+ spin_unlock_irq(&bebob->lock);128128+129129+ return err;130130+}131131+132132+static int133133+hwdep_release(struct snd_hwdep *hwdep, struct file *file)134134+{135135+ struct snd_bebob *bebob = hwdep->private_data;136136+137137+ spin_lock_irq(&bebob->lock);138138+ if (bebob->dev_lock_count == -1)139139+ bebob->dev_lock_count = 0;140140+ spin_unlock_irq(&bebob->lock);141141+142142+ return 0;143143+}144144+145145+static int146146+hwdep_ioctl(struct snd_hwdep *hwdep, struct file *file,147147+ unsigned int cmd, unsigned long arg)148148+{149149+ struct snd_bebob *bebob = hwdep->private_data;150150+151151+ switch (cmd) {152152+ case SNDRV_FIREWIRE_IOCTL_GET_INFO:153153+ return hwdep_get_info(bebob, (void __user *)arg);154154+ case SNDRV_FIREWIRE_IOCTL_LOCK:155155+ return hwdep_lock(bebob);156156+ case SNDRV_FIREWIRE_IOCTL_UNLOCK:157157+ return hwdep_unlock(bebob);158158+ default:159159+ return -ENOIOCTLCMD;160160+ }161161+}162162+163163+#ifdef CONFIG_COMPAT164164+static int165165+hwdep_compat_ioctl(struct snd_hwdep *hwdep, struct file *file,166166+ unsigned int cmd, unsigned long arg)167167+{168168+ return hwdep_ioctl(hwdep, file, cmd,169169+ (unsigned long)compat_ptr(arg));170170+}171171+#else172172+#define hwdep_compat_ioctl NULL173173+#endif174174+175175+static const struct snd_hwdep_ops hwdep_ops = {176176+ .read = hwdep_read,177177+ .release = hwdep_release,178178+ .poll = hwdep_poll,179179+ .ioctl = hwdep_ioctl,180180+ .ioctl_compat = hwdep_compat_ioctl,181181+};182182+183183+int snd_bebob_create_hwdep_device(struct snd_bebob *bebob)184184+{185185+ struct snd_hwdep *hwdep;186186+ int err;187187+188188+ err = snd_hwdep_new(bebob->card, "BeBoB", 0, &hwdep);189189+ if (err < 0)190190+ goto end;191191+ strcpy(hwdep->name, "BeBoB");192192+ hwdep->iface = SNDRV_HWDEP_IFACE_FW_BEBOB;193193+ hwdep->ops = hwdep_ops;194194+ hwdep->private_data = bebob;195195+ hwdep->exclusive = true;196196+end:197197+ return err;198198+}199199+
+792
sound/firewire/bebob/bebob_maudio.c
···11+/*22+ * bebob_maudio.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+#include <sound/control.h>1111+1212+/*1313+ * Just powering on, Firewire 410/Audiophile/1814 and ProjectMix I/O wait to1414+ * download firmware blob. To enable these devices, drivers should upload1515+ * firmware blob and send a command to initialize configuration to factory1616+ * settings when completing uploading. Then these devices generate bus reset1717+ * and are recognized as new devices with the firmware.1818+ *1919+ * But with firmware version 5058 or later, the firmware is stored to flash2020+ * memory in the device and drivers can tell bootloader to load the firmware2121+ * by sending a cue. This cue must be sent one time.2222+ *2323+ * For streaming, both of output and input streams are needed for Firewire 4102424+ * and Ozonic. The single stream is OK for the other devices even if the clock2525+ * source is not SYT-Match (I note no devices use SYT-Match).2626+ *2727+ * Without streaming, the devices except for Firewire Audiophile can mix any2828+ * input and output. For this reason, Audiophile cannot be used as standalone2929+ * mixer.3030+ *3131+ * Firewire 1814 and ProjectMix I/O uses special firmware. It will be freezed3232+ * when receiving any commands which the firmware can't understand. These3333+ * devices utilize completely different system to control. It is some3434+ * write-transaction directly into a certain address. All of addresses for mixer3535+ * functionality is between 0xffc700700000 to 0xffc70070009c.3636+ */3737+3838+/* Offset from information register */3939+#define INFO_OFFSET_SW_DATE 0x204040+4141+/* Bootloader Protocol Version 1 */4242+#define MAUDIO_BOOTLOADER_CUE1 0x000000014343+/*4444+ * Initializing configuration to factory settings (= 0x1101), (swapped in line),4545+ * Command code is zero (= 0x00),4646+ * the number of operands is zero (= 0x00)(at least significant byte)4747+ */4848+#define MAUDIO_BOOTLOADER_CUE2 0x011100004949+/* padding */5050+#define MAUDIO_BOOTLOADER_CUE3 0x000000005151+5252+#define MAUDIO_SPECIFIC_ADDRESS 0xffc700000000ULL5353+5454+#define METER_OFFSET 0x006000005555+5656+/* some device has sync info after metering data */5757+#define METER_SIZE_SPECIAL 84 /* with sync info */5858+#define METER_SIZE_FW410 76 /* with sync info */5959+#define METER_SIZE_AUDIOPHILE 60 /* with sync info */6060+#define METER_SIZE_SOLO 52 /* with sync info */6161+#define METER_SIZE_OZONIC 486262+#define METER_SIZE_NRV10 806363+6464+/* labels for metering */6565+#define ANA_IN "Analog In"6666+#define ANA_OUT "Analog Out"6767+#define DIG_IN "Digital In"6868+#define SPDIF_IN "S/PDIF In"6969+#define ADAT_IN "ADAT In"7070+#define DIG_OUT "Digital Out"7171+#define SPDIF_OUT "S/PDIF Out"7272+#define ADAT_OUT "ADAT Out"7373+#define STRM_IN "Stream In"7474+#define AUX_OUT "Aux Out"7575+#define HP_OUT "HP Out"7676+/* for NRV */7777+#define UNKNOWN_METER "Unknown"7878+7979+struct special_params {8080+ bool is1814;8181+ unsigned int clk_src;8282+ unsigned int dig_in_fmt;8383+ unsigned int dig_out_fmt;8484+ unsigned int clk_lock;8585+ struct snd_ctl_elem_id *ctl_id_sync;8686+};8787+8888+/*8989+ * For some M-Audio devices, this module just send cue to load firmware. After9090+ * loading, the device generates bus reset and newly detected.9191+ *9292+ * If we make any transactions to load firmware, the operation may failed.9393+ */9494+int snd_bebob_maudio_load_firmware(struct fw_unit *unit)9595+{9696+ struct fw_device *device = fw_parent_device(unit);9797+ int err, rcode;9898+ u64 date;9999+ __be32 cues[3] = {100100+ MAUDIO_BOOTLOADER_CUE1,101101+ MAUDIO_BOOTLOADER_CUE2,102102+ MAUDIO_BOOTLOADER_CUE3103103+ };104104+105105+ /* check date of software used to build */106106+ err = snd_bebob_read_block(unit, INFO_OFFSET_SW_DATE,107107+ &date, sizeof(u64));108108+ if (err < 0)109109+ goto end;110110+ /*111111+ * firmware version 5058 or later has date later than "20070401", but112112+ * 'date' is not null-terminated.113113+ */114114+ if (date < 0x3230303730343031LL) {115115+ dev_err(&unit->device,116116+ "Use firmware version 5058 or later\n");117117+ err = -ENOSYS;118118+ goto end;119119+ }120120+121121+ rcode = fw_run_transaction(device->card, TCODE_WRITE_BLOCK_REQUEST,122122+ device->node_id, device->generation,123123+ device->max_speed, BEBOB_ADDR_REG_REQ,124124+ cues, sizeof(cues));125125+ if (rcode != RCODE_COMPLETE) {126126+ dev_err(&unit->device,127127+ "Failed to send a cue to load firmware\n");128128+ err = -EIO;129129+ }130130+end:131131+ return err;132132+}133133+134134+static inline int135135+get_meter(struct snd_bebob *bebob, void *buf, unsigned int size)136136+{137137+ return snd_fw_transaction(bebob->unit, TCODE_READ_BLOCK_REQUEST,138138+ MAUDIO_SPECIFIC_ADDRESS + METER_OFFSET,139139+ buf, size, 0);140140+}141141+142142+static int143143+check_clk_sync(struct snd_bebob *bebob, unsigned int size, bool *sync)144144+{145145+ int err;146146+ u8 *buf;147147+148148+ buf = kmalloc(size, GFP_KERNEL);149149+ if (buf == NULL)150150+ return -ENOMEM;151151+152152+ err = get_meter(bebob, buf, size);153153+ if (err < 0)154154+ goto end;155155+156156+ /* if synced, this value is the same as SFC of FDF in CIP header */157157+ *sync = (buf[size - 2] != 0xff);158158+end:159159+ kfree(buf);160160+ return err;161161+}162162+163163+/*164164+ * dig_fmt: 0x00:S/PDIF, 0x01:ADAT165165+ * clk_lock: 0x00:unlock, 0x01:lock166166+ */167167+static int168168+avc_maudio_set_special_clk(struct snd_bebob *bebob, unsigned int clk_src,169169+ unsigned int dig_in_fmt, unsigned int dig_out_fmt,170170+ unsigned int clk_lock)171171+{172172+ struct special_params *params = bebob->maudio_special_quirk;173173+ int err;174174+ u8 *buf;175175+176176+ if (amdtp_stream_running(&bebob->rx_stream) ||177177+ amdtp_stream_running(&bebob->tx_stream))178178+ return -EBUSY;179179+180180+ buf = kmalloc(12, GFP_KERNEL);181181+ if (buf == NULL)182182+ return -ENOMEM;183183+184184+ buf[0] = 0x00; /* CONTROL */185185+ buf[1] = 0xff; /* UNIT */186186+ buf[2] = 0x00; /* vendor dependent */187187+ buf[3] = 0x04; /* company ID high */188188+ buf[4] = 0x00; /* company ID middle */189189+ buf[5] = 0x04; /* company ID low */190190+ buf[6] = 0xff & clk_src; /* clock source */191191+ buf[7] = 0xff & dig_in_fmt; /* input digital format */192192+ buf[8] = 0xff & dig_out_fmt; /* output digital format */193193+ buf[9] = 0xff & clk_lock; /* lock these settings */194194+ buf[10] = 0x00; /* padding */195195+ buf[11] = 0x00; /* padding */196196+197197+ err = fcp_avc_transaction(bebob->unit, buf, 12, buf, 12,198198+ BIT(1) | BIT(2) | BIT(3) | BIT(4) |199199+ BIT(5) | BIT(6) | BIT(7) | BIT(8) |200200+ BIT(9));201201+ if ((err > 0) && (err < 10))202202+ err = -EIO;203203+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */204204+ err = -ENOSYS;205205+ else if (buf[0] == 0x0a) /* REJECTED */206206+ err = -EINVAL;207207+ if (err < 0)208208+ goto end;209209+210210+ params->clk_src = buf[6];211211+ params->dig_in_fmt = buf[7];212212+ params->dig_out_fmt = buf[8];213213+ params->clk_lock = buf[9];214214+215215+ if (params->ctl_id_sync)216216+ snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,217217+ params->ctl_id_sync);218218+219219+ err = 0;220220+end:221221+ kfree(buf);222222+ return err;223223+}224224+static void225225+special_stream_formation_set(struct snd_bebob *bebob)226226+{227227+ static const unsigned int ch_table[2][2][3] = {228228+ /* AMDTP_OUT_STREAM */229229+ { { 6, 6, 4 }, /* SPDIF */230230+ { 12, 8, 4 } }, /* ADAT */231231+ /* AMDTP_IN_STREAM */232232+ { { 10, 10, 2 }, /* SPDIF */233233+ { 16, 12, 2 } } /* ADAT */234234+ };235235+ struct special_params *params = bebob->maudio_special_quirk;236236+ unsigned int i, max;237237+238238+ max = SND_BEBOB_STRM_FMT_ENTRIES - 1;239239+ if (!params->is1814)240240+ max -= 2;241241+242242+ for (i = 0; i < max; i++) {243243+ bebob->tx_stream_formations[i + 1].pcm =244244+ ch_table[AMDTP_IN_STREAM][params->dig_in_fmt][i / 2];245245+ bebob->tx_stream_formations[i + 1].midi = 1;246246+247247+ bebob->rx_stream_formations[i + 1].pcm =248248+ ch_table[AMDTP_OUT_STREAM][params->dig_out_fmt][i / 2];249249+ bebob->rx_stream_formations[i + 1].midi = 1;250250+ }251251+}252252+253253+static int add_special_controls(struct snd_bebob *bebob);254254+int255255+snd_bebob_maudio_special_discover(struct snd_bebob *bebob, bool is1814)256256+{257257+ struct special_params *params;258258+ int err;259259+260260+ params = kzalloc(sizeof(struct special_params), GFP_KERNEL);261261+ if (params == NULL)262262+ return -ENOMEM;263263+264264+ mutex_lock(&bebob->mutex);265265+266266+ bebob->maudio_special_quirk = (void *)params;267267+ params->is1814 = is1814;268268+269269+ /* initialize these parameters because driver is not allowed to ask */270270+ bebob->rx_stream.context = ERR_PTR(-1);271271+ bebob->tx_stream.context = ERR_PTR(-1);272272+ err = avc_maudio_set_special_clk(bebob, 0x03, 0x00, 0x00, 0x00);273273+ if (err < 0) {274274+ dev_err(&bebob->unit->device,275275+ "fail to initialize clock params: %d\n", err);276276+ goto end;277277+ }278278+279279+ err = add_special_controls(bebob);280280+ if (err < 0)281281+ goto end;282282+283283+ special_stream_formation_set(bebob);284284+285285+ if (params->is1814) {286286+ bebob->midi_input_ports = 1;287287+ bebob->midi_output_ports = 1;288288+ } else {289289+ bebob->midi_input_ports = 2;290290+ bebob->midi_output_ports = 2;291291+ }292292+end:293293+ if (err < 0) {294294+ kfree(params);295295+ bebob->maudio_special_quirk = NULL;296296+ }297297+ mutex_unlock(&bebob->mutex);298298+ return err;299299+}300300+301301+/* Input plug shows actual rate. Output plug is needless for this purpose. */302302+static int special_get_rate(struct snd_bebob *bebob, unsigned int *rate)303303+{304304+ int err, trials;305305+306306+ trials = 0;307307+ do {308308+ err = avc_general_get_sig_fmt(bebob->unit, rate,309309+ AVC_GENERAL_PLUG_DIR_IN, 0);310310+ } while (err == -EAGAIN && ++trials < 3);311311+312312+ return err;313313+}314314+static int special_set_rate(struct snd_bebob *bebob, unsigned int rate)315315+{316316+ struct special_params *params = bebob->maudio_special_quirk;317317+ int err;318318+319319+ err = avc_general_set_sig_fmt(bebob->unit, rate,320320+ AVC_GENERAL_PLUG_DIR_OUT, 0);321321+ if (err < 0)322322+ goto end;323323+324324+ /*325325+ * Just after changing sampling rate for output, a followed command326326+ * for input is easy to fail. This is a workaround fot this issue.327327+ */328328+ msleep(100);329329+330330+ err = avc_general_set_sig_fmt(bebob->unit, rate,331331+ AVC_GENERAL_PLUG_DIR_IN, 0);332332+ if (err < 0)333333+ goto end;334334+335335+ if (params->ctl_id_sync)336336+ snd_ctl_notify(bebob->card, SNDRV_CTL_EVENT_MASK_VALUE,337337+ params->ctl_id_sync);338338+end:339339+ return err;340340+}341341+342342+/* Clock source control for special firmware */343343+static char *const special_clk_labels[] = {344344+ SND_BEBOB_CLOCK_INTERNAL " with Digital Mute", "Digital",345345+ "Word Clock", SND_BEBOB_CLOCK_INTERNAL};346346+static int special_clk_get(struct snd_bebob *bebob, unsigned int *id)347347+{348348+ struct special_params *params = bebob->maudio_special_quirk;349349+ *id = params->clk_src;350350+ return 0;351351+}352352+static int special_clk_ctl_info(struct snd_kcontrol *kctl,353353+ struct snd_ctl_elem_info *einf)354354+{355355+ einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;356356+ einf->count = 1;357357+ einf->value.enumerated.items = ARRAY_SIZE(special_clk_labels);358358+359359+ if (einf->value.enumerated.item >= einf->value.enumerated.items)360360+ einf->value.enumerated.item = einf->value.enumerated.items - 1;361361+362362+ strcpy(einf->value.enumerated.name,363363+ special_clk_labels[einf->value.enumerated.item]);364364+365365+ return 0;366366+}367367+static int special_clk_ctl_get(struct snd_kcontrol *kctl,368368+ struct snd_ctl_elem_value *uval)369369+{370370+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);371371+ struct special_params *params = bebob->maudio_special_quirk;372372+ uval->value.enumerated.item[0] = params->clk_src;373373+ return 0;374374+}375375+static int special_clk_ctl_put(struct snd_kcontrol *kctl,376376+ struct snd_ctl_elem_value *uval)377377+{378378+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);379379+ struct special_params *params = bebob->maudio_special_quirk;380380+ int err, id;381381+382382+ mutex_lock(&bebob->mutex);383383+384384+ id = uval->value.enumerated.item[0];385385+ if (id >= ARRAY_SIZE(special_clk_labels))386386+ return 0;387387+388388+ err = avc_maudio_set_special_clk(bebob, id,389389+ params->dig_in_fmt,390390+ params->dig_out_fmt,391391+ params->clk_lock);392392+ mutex_unlock(&bebob->mutex);393393+394394+ return err >= 0;395395+}396396+static struct snd_kcontrol_new special_clk_ctl = {397397+ .name = "Clock Source",398398+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,399399+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,400400+ .info = special_clk_ctl_info,401401+ .get = special_clk_ctl_get,402402+ .put = special_clk_ctl_put403403+};404404+405405+/* Clock synchronization control for special firmware */406406+static int special_sync_ctl_info(struct snd_kcontrol *kctl,407407+ struct snd_ctl_elem_info *einf)408408+{409409+ einf->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;410410+ einf->count = 1;411411+ einf->value.integer.min = 0;412412+ einf->value.integer.max = 1;413413+414414+ return 0;415415+}416416+static int special_sync_ctl_get(struct snd_kcontrol *kctl,417417+ struct snd_ctl_elem_value *uval)418418+{419419+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);420420+ int err;421421+ bool synced = 0;422422+423423+ err = check_clk_sync(bebob, METER_SIZE_SPECIAL, &synced);424424+ if (err >= 0)425425+ uval->value.integer.value[0] = synced;426426+427427+ return 0;428428+}429429+static struct snd_kcontrol_new special_sync_ctl = {430430+ .name = "Sync Status",431431+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,432432+ .access = SNDRV_CTL_ELEM_ACCESS_READ,433433+ .info = special_sync_ctl_info,434434+ .get = special_sync_ctl_get,435435+};436436+437437+/* Digital interface control for special firmware */438438+static char *const special_dig_iface_labels[] = {439439+ "S/PDIF Optical", "S/PDIF Coaxial", "ADAT Optical"440440+};441441+static int special_dig_in_iface_ctl_info(struct snd_kcontrol *kctl,442442+ struct snd_ctl_elem_info *einf)443443+{444444+ einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;445445+ einf->count = 1;446446+ einf->value.enumerated.items = ARRAY_SIZE(special_dig_iface_labels);447447+448448+ if (einf->value.enumerated.item >= einf->value.enumerated.items)449449+ einf->value.enumerated.item = einf->value.enumerated.items - 1;450450+451451+ strcpy(einf->value.enumerated.name,452452+ special_dig_iface_labels[einf->value.enumerated.item]);453453+454454+ return 0;455455+}456456+static int special_dig_in_iface_ctl_get(struct snd_kcontrol *kctl,457457+ struct snd_ctl_elem_value *uval)458458+{459459+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);460460+ struct special_params *params = bebob->maudio_special_quirk;461461+ unsigned int dig_in_iface;462462+ int err, val;463463+464464+ mutex_lock(&bebob->mutex);465465+466466+ err = avc_audio_get_selector(bebob->unit, 0x00, 0x04,467467+ &dig_in_iface);468468+ if (err < 0) {469469+ dev_err(&bebob->unit->device,470470+ "fail to get digital input interface: %d\n", err);471471+ goto end;472472+ }473473+474474+ /* encoded id for user value */475475+ val = (params->dig_in_fmt << 1) | (dig_in_iface & 0x01);476476+477477+ /* for ADAT Optical */478478+ if (val > 2)479479+ val = 2;480480+481481+ uval->value.enumerated.item[0] = val;482482+end:483483+ mutex_unlock(&bebob->mutex);484484+ return err;485485+}486486+static int special_dig_in_iface_ctl_set(struct snd_kcontrol *kctl,487487+ struct snd_ctl_elem_value *uval)488488+{489489+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);490490+ struct special_params *params = bebob->maudio_special_quirk;491491+ unsigned int id, dig_in_fmt, dig_in_iface;492492+ int err;493493+494494+ mutex_lock(&bebob->mutex);495495+496496+ id = uval->value.enumerated.item[0];497497+498498+ /* decode user value */499499+ dig_in_fmt = (id >> 1) & 0x01;500500+ dig_in_iface = id & 0x01;501501+502502+ err = avc_maudio_set_special_clk(bebob,503503+ params->clk_src,504504+ dig_in_fmt,505505+ params->dig_out_fmt,506506+ params->clk_lock);507507+ if ((err < 0) || (params->dig_in_fmt > 0)) /* ADAT */508508+ goto end;509509+510510+ err = avc_audio_set_selector(bebob->unit, 0x00, 0x04, dig_in_iface);511511+ if (err < 0)512512+ dev_err(&bebob->unit->device,513513+ "fail to set digital input interface: %d\n", err);514514+end:515515+ special_stream_formation_set(bebob);516516+ mutex_unlock(&bebob->mutex);517517+ return err;518518+}519519+static struct snd_kcontrol_new special_dig_in_iface_ctl = {520520+ .name = "Digital Input Interface",521521+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,522522+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,523523+ .info = special_dig_in_iface_ctl_info,524524+ .get = special_dig_in_iface_ctl_get,525525+ .put = special_dig_in_iface_ctl_set526526+};527527+528528+static int special_dig_out_iface_ctl_info(struct snd_kcontrol *kctl,529529+ struct snd_ctl_elem_info *einf)530530+{531531+ einf->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;532532+ einf->count = 1;533533+ einf->value.enumerated.items = ARRAY_SIZE(special_dig_iface_labels) - 1;534534+535535+ if (einf->value.enumerated.item >= einf->value.enumerated.items)536536+ einf->value.enumerated.item = einf->value.enumerated.items - 1;537537+538538+ strcpy(einf->value.enumerated.name,539539+ special_dig_iface_labels[einf->value.enumerated.item + 1]);540540+541541+ return 0;542542+}543543+static int special_dig_out_iface_ctl_get(struct snd_kcontrol *kctl,544544+ struct snd_ctl_elem_value *uval)545545+{546546+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);547547+ struct special_params *params = bebob->maudio_special_quirk;548548+ mutex_lock(&bebob->mutex);549549+ uval->value.enumerated.item[0] = params->dig_out_fmt;550550+ mutex_unlock(&bebob->mutex);551551+ return 0;552552+}553553+static int special_dig_out_iface_ctl_set(struct snd_kcontrol *kctl,554554+ struct snd_ctl_elem_value *uval)555555+{556556+ struct snd_bebob *bebob = snd_kcontrol_chip(kctl);557557+ struct special_params *params = bebob->maudio_special_quirk;558558+ unsigned int id;559559+ int err;560560+561561+ mutex_lock(&bebob->mutex);562562+563563+ id = uval->value.enumerated.item[0];564564+565565+ err = avc_maudio_set_special_clk(bebob,566566+ params->clk_src,567567+ params->dig_in_fmt,568568+ id, params->clk_lock);569569+ if (err >= 0)570570+ special_stream_formation_set(bebob);571571+572572+ mutex_unlock(&bebob->mutex);573573+ return err;574574+}575575+static struct snd_kcontrol_new special_dig_out_iface_ctl = {576576+ .name = "Digital Output Interface",577577+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,578578+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,579579+ .info = special_dig_out_iface_ctl_info,580580+ .get = special_dig_out_iface_ctl_get,581581+ .put = special_dig_out_iface_ctl_set582582+};583583+584584+static int add_special_controls(struct snd_bebob *bebob)585585+{586586+ struct snd_kcontrol *kctl;587587+ struct special_params *params = bebob->maudio_special_quirk;588588+ int err;589589+590590+ kctl = snd_ctl_new1(&special_clk_ctl, bebob);591591+ err = snd_ctl_add(bebob->card, kctl);592592+ if (err < 0)593593+ goto end;594594+595595+ kctl = snd_ctl_new1(&special_sync_ctl, bebob);596596+ err = snd_ctl_add(bebob->card, kctl);597597+ if (err < 0)598598+ goto end;599599+ params->ctl_id_sync = &kctl->id;600600+601601+ kctl = snd_ctl_new1(&special_dig_in_iface_ctl, bebob);602602+ err = snd_ctl_add(bebob->card, kctl);603603+ if (err < 0)604604+ goto end;605605+606606+ kctl = snd_ctl_new1(&special_dig_out_iface_ctl, bebob);607607+ err = snd_ctl_add(bebob->card, kctl);608608+end:609609+ return err;610610+}611611+612612+/* Hardware metering for special firmware */613613+static char *const special_meter_labels[] = {614614+ ANA_IN, ANA_IN, ANA_IN, ANA_IN,615615+ SPDIF_IN,616616+ ADAT_IN, ADAT_IN, ADAT_IN, ADAT_IN,617617+ ANA_OUT, ANA_OUT,618618+ SPDIF_OUT,619619+ ADAT_OUT, ADAT_OUT, ADAT_OUT, ADAT_OUT,620620+ HP_OUT, HP_OUT,621621+ AUX_OUT622622+};623623+static int624624+special_meter_get(struct snd_bebob *bebob, u32 *target, unsigned int size)625625+{626626+ u16 *buf;627627+ unsigned int i, c, channels;628628+ int err;629629+630630+ channels = ARRAY_SIZE(special_meter_labels) * 2;631631+ if (size < channels * sizeof(u32))632632+ return -EINVAL;633633+634634+ /* omit last 4 bytes because it's clock info. */635635+ buf = kmalloc(METER_SIZE_SPECIAL - 4, GFP_KERNEL);636636+ if (buf == NULL)637637+ return -ENOMEM;638638+639639+ err = get_meter(bebob, (void *)buf, METER_SIZE_SPECIAL - 4);640640+ if (err < 0)641641+ goto end;642642+643643+ /* Its format is u16 and some channels are unknown. */644644+ i = 0;645645+ for (c = 2; c < channels + 2; c++)646646+ target[i++] = be16_to_cpu(buf[c]) << 16;647647+end:648648+ kfree(buf);649649+ return err;650650+}651651+652652+/* last 4 bytes are omitted because it's clock info. */653653+static char *const fw410_meter_labels[] = {654654+ ANA_IN, DIG_IN,655655+ ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT, DIG_OUT,656656+ HP_OUT657657+};658658+static char *const audiophile_meter_labels[] = {659659+ ANA_IN, DIG_IN,660660+ ANA_OUT, ANA_OUT, DIG_OUT,661661+ HP_OUT, AUX_OUT,662662+};663663+static char *const solo_meter_labels[] = {664664+ ANA_IN, DIG_IN,665665+ STRM_IN, STRM_IN,666666+ ANA_OUT, DIG_OUT667667+};668668+669669+/* no clock info */670670+static char *const ozonic_meter_labels[] = {671671+ ANA_IN, ANA_IN,672672+ STRM_IN, STRM_IN,673673+ ANA_OUT, ANA_OUT674674+};675675+/* TODO: need testers. these positions are based on authour's assumption */676676+static char *const nrv10_meter_labels[] = {677677+ ANA_IN, ANA_IN, ANA_IN, ANA_IN,678678+ DIG_IN,679679+ ANA_OUT, ANA_OUT, ANA_OUT, ANA_OUT,680680+ DIG_IN681681+};682682+static int683683+normal_meter_get(struct snd_bebob *bebob, u32 *buf, unsigned int size)684684+{685685+ struct snd_bebob_meter_spec *spec = bebob->spec->meter;686686+ unsigned int c, channels;687687+ int err;688688+689689+ channels = spec->num * 2;690690+ if (size < channels * sizeof(u32))691691+ return -EINVAL;692692+693693+ err = get_meter(bebob, (void *)buf, size);694694+ if (err < 0)695695+ goto end;696696+697697+ for (c = 0; c < channels; c++)698698+ be32_to_cpus(&buf[c]);699699+700700+ /* swap stream channels because inverted */701701+ if (spec->labels == solo_meter_labels) {702702+ swap(buf[4], buf[6]);703703+ swap(buf[5], buf[7]);704704+ }705705+end:706706+ return err;707707+}708708+709709+/* for special customized devices */710710+static struct snd_bebob_rate_spec special_rate_spec = {711711+ .get = &special_get_rate,712712+ .set = &special_set_rate,713713+};714714+static struct snd_bebob_clock_spec special_clk_spec = {715715+ .num = ARRAY_SIZE(special_clk_labels),716716+ .labels = special_clk_labels,717717+ .get = &special_clk_get,718718+};719719+static struct snd_bebob_meter_spec special_meter_spec = {720720+ .num = ARRAY_SIZE(special_meter_labels),721721+ .labels = special_meter_labels,722722+ .get = &special_meter_get723723+};724724+struct snd_bebob_spec maudio_special_spec = {725725+ .clock = &special_clk_spec,726726+ .rate = &special_rate_spec,727727+ .meter = &special_meter_spec728728+};729729+730730+/* Firewire 410 specification */731731+static struct snd_bebob_rate_spec usual_rate_spec = {732732+ .get = &snd_bebob_stream_get_rate,733733+ .set = &snd_bebob_stream_set_rate,734734+};735735+static struct snd_bebob_meter_spec fw410_meter_spec = {736736+ .num = ARRAY_SIZE(fw410_meter_labels),737737+ .labels = fw410_meter_labels,738738+ .get = &normal_meter_get739739+};740740+struct snd_bebob_spec maudio_fw410_spec = {741741+ .clock = NULL,742742+ .rate = &usual_rate_spec,743743+ .meter = &fw410_meter_spec744744+};745745+746746+/* Firewire Audiophile specification */747747+static struct snd_bebob_meter_spec audiophile_meter_spec = {748748+ .num = ARRAY_SIZE(audiophile_meter_labels),749749+ .labels = audiophile_meter_labels,750750+ .get = &normal_meter_get751751+};752752+struct snd_bebob_spec maudio_audiophile_spec = {753753+ .clock = NULL,754754+ .rate = &usual_rate_spec,755755+ .meter = &audiophile_meter_spec756756+};757757+758758+/* Firewire Solo specification */759759+static struct snd_bebob_meter_spec solo_meter_spec = {760760+ .num = ARRAY_SIZE(solo_meter_labels),761761+ .labels = solo_meter_labels,762762+ .get = &normal_meter_get763763+};764764+struct snd_bebob_spec maudio_solo_spec = {765765+ .clock = NULL,766766+ .rate = &usual_rate_spec,767767+ .meter = &solo_meter_spec768768+};769769+770770+/* Ozonic specification */771771+static struct snd_bebob_meter_spec ozonic_meter_spec = {772772+ .num = ARRAY_SIZE(ozonic_meter_labels),773773+ .labels = ozonic_meter_labels,774774+ .get = &normal_meter_get775775+};776776+struct snd_bebob_spec maudio_ozonic_spec = {777777+ .clock = NULL,778778+ .rate = &usual_rate_spec,779779+ .meter = &ozonic_meter_spec780780+};781781+782782+/* NRV10 specification */783783+static struct snd_bebob_meter_spec nrv10_meter_spec = {784784+ .num = ARRAY_SIZE(nrv10_meter_labels),785785+ .labels = nrv10_meter_labels,786786+ .get = &normal_meter_get787787+};788788+struct snd_bebob_spec maudio_nrv10_spec = {789789+ .clock = NULL,790790+ .rate = &usual_rate_spec,791791+ .meter = &nrv10_meter_spec792792+};
+168
sound/firewire/bebob/bebob_midi.c
···11+/*22+ * bebob_midi.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "bebob.h"1010+1111+static int midi_capture_open(struct snd_rawmidi_substream *substream)1212+{1313+ struct snd_bebob *bebob = substream->rmidi->private_data;1414+ int err;1515+1616+ err = snd_bebob_stream_lock_try(bebob);1717+ if (err < 0)1818+ goto end;1919+2020+ atomic_inc(&bebob->capture_substreams);2121+ err = snd_bebob_stream_start_duplex(bebob, 0);2222+ if (err < 0)2323+ snd_bebob_stream_lock_release(bebob);2424+end:2525+ return err;2626+}2727+2828+static int midi_playback_open(struct snd_rawmidi_substream *substream)2929+{3030+ struct snd_bebob *bebob = substream->rmidi->private_data;3131+ int err;3232+3333+ err = snd_bebob_stream_lock_try(bebob);3434+ if (err < 0)3535+ goto end;3636+3737+ atomic_inc(&bebob->playback_substreams);3838+ err = snd_bebob_stream_start_duplex(bebob, 0);3939+ if (err < 0)4040+ snd_bebob_stream_lock_release(bebob);4141+end:4242+ return err;4343+}4444+4545+static int midi_capture_close(struct snd_rawmidi_substream *substream)4646+{4747+ struct snd_bebob *bebob = substream->rmidi->private_data;4848+4949+ atomic_dec(&bebob->capture_substreams);5050+ snd_bebob_stream_stop_duplex(bebob);5151+5252+ snd_bebob_stream_lock_release(bebob);5353+ return 0;5454+}5555+5656+static int midi_playback_close(struct snd_rawmidi_substream *substream)5757+{5858+ struct snd_bebob *bebob = substream->rmidi->private_data;5959+6060+ atomic_dec(&bebob->playback_substreams);6161+ snd_bebob_stream_stop_duplex(bebob);6262+6363+ snd_bebob_stream_lock_release(bebob);6464+ return 0;6565+}6666+6767+static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)6868+{6969+ struct snd_bebob *bebob = substrm->rmidi->private_data;7070+ unsigned long flags;7171+7272+ spin_lock_irqsave(&bebob->lock, flags);7373+7474+ if (up)7575+ amdtp_stream_midi_trigger(&bebob->tx_stream,7676+ substrm->number, substrm);7777+ else7878+ amdtp_stream_midi_trigger(&bebob->tx_stream,7979+ substrm->number, NULL);8080+8181+ spin_unlock_irqrestore(&bebob->lock, flags);8282+}8383+8484+static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)8585+{8686+ struct snd_bebob *bebob = substrm->rmidi->private_data;8787+ unsigned long flags;8888+8989+ spin_lock_irqsave(&bebob->lock, flags);9090+9191+ if (up)9292+ amdtp_stream_midi_trigger(&bebob->rx_stream,9393+ substrm->number, substrm);9494+ else9595+ amdtp_stream_midi_trigger(&bebob->rx_stream,9696+ substrm->number, NULL);9797+9898+ spin_unlock_irqrestore(&bebob->lock, flags);9999+}100100+101101+static struct snd_rawmidi_ops midi_capture_ops = {102102+ .open = midi_capture_open,103103+ .close = midi_capture_close,104104+ .trigger = midi_capture_trigger,105105+};106106+107107+static struct snd_rawmidi_ops midi_playback_ops = {108108+ .open = midi_playback_open,109109+ .close = midi_playback_close,110110+ .trigger = midi_playback_trigger,111111+};112112+113113+static void set_midi_substream_names(struct snd_bebob *bebob,114114+ struct snd_rawmidi_str *str)115115+{116116+ struct snd_rawmidi_substream *subs;117117+118118+ list_for_each_entry(subs, &str->substreams, list) {119119+ snprintf(subs->name, sizeof(subs->name),120120+ "%s MIDI %d",121121+ bebob->card->shortname, subs->number + 1);122122+ }123123+}124124+125125+int snd_bebob_create_midi_devices(struct snd_bebob *bebob)126126+{127127+ struct snd_rawmidi *rmidi;128128+ struct snd_rawmidi_str *str;129129+ int err;130130+131131+ /* create midi ports */132132+ err = snd_rawmidi_new(bebob->card, bebob->card->driver, 0,133133+ bebob->midi_output_ports, bebob->midi_input_ports,134134+ &rmidi);135135+ if (err < 0)136136+ return err;137137+138138+ snprintf(rmidi->name, sizeof(rmidi->name),139139+ "%s MIDI", bebob->card->shortname);140140+ rmidi->private_data = bebob;141141+142142+ if (bebob->midi_input_ports > 0) {143143+ rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;144144+145145+ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,146146+ &midi_capture_ops);147147+148148+ str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];149149+150150+ set_midi_substream_names(bebob, str);151151+ }152152+153153+ if (bebob->midi_output_ports > 0) {154154+ rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;155155+156156+ snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,157157+ &midi_playback_ops);158158+159159+ str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];160160+161161+ set_midi_substream_names(bebob, str);162162+ }163163+164164+ if ((bebob->midi_output_ports > 0) && (bebob->midi_input_ports > 0))165165+ rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;166166+167167+ return 0;168168+}
+378
sound/firewire/bebob/bebob_pcm.c
···11+/*22+ * bebob_pcm.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+static int1212+hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)1313+{1414+ struct snd_bebob_stream_formation *formations = rule->private;1515+ struct snd_interval *r =1616+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);1717+ const struct snd_interval *c =1818+ hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS);1919+ struct snd_interval t = {2020+ .min = UINT_MAX, .max = 0, .integer = 12121+ };2222+ unsigned int i;2323+2424+ for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {2525+ /* entry is invalid */2626+ if (formations[i].pcm == 0)2727+ continue;2828+2929+ if (!snd_interval_test(c, formations[i].pcm))3030+ continue;3131+3232+ t.min = min(t.min, snd_bebob_rate_table[i]);3333+ t.max = max(t.max, snd_bebob_rate_table[i]);3434+3535+ }3636+ return snd_interval_refine(r, &t);3737+}3838+3939+static int4040+hw_rule_channels(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule)4141+{4242+ struct snd_bebob_stream_formation *formations = rule->private;4343+ struct snd_interval *c =4444+ hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);4545+ const struct snd_interval *r =4646+ hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE);4747+ struct snd_interval t = {4848+ .min = UINT_MAX, .max = 0, .integer = 14949+ };5050+5151+ unsigned int i;5252+5353+ for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {5454+ /* entry is invalid */5555+ if (formations[i].pcm == 0)5656+ continue;5757+5858+ if (!snd_interval_test(r, snd_bebob_rate_table[i]))5959+ continue;6060+6161+ t.min = min(t.min, formations[i].pcm);6262+ t.max = max(t.max, formations[i].pcm);6363+ }6464+6565+ return snd_interval_refine(c, &t);6666+}6767+6868+static void6969+limit_channels_and_rates(struct snd_pcm_hardware *hw,7070+ struct snd_bebob_stream_formation *formations)7171+{7272+ unsigned int i;7373+7474+ hw->channels_min = UINT_MAX;7575+ hw->channels_max = 0;7676+7777+ hw->rate_min = UINT_MAX;7878+ hw->rate_max = 0;7979+ hw->rates = 0;8080+8181+ for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {8282+ /* entry has no PCM channels */8383+ if (formations[i].pcm == 0)8484+ continue;8585+8686+ hw->channels_min = min(hw->channels_min, formations[i].pcm);8787+ hw->channels_max = max(hw->channels_max, formations[i].pcm);8888+8989+ hw->rate_min = min(hw->rate_min, snd_bebob_rate_table[i]);9090+ hw->rate_max = max(hw->rate_max, snd_bebob_rate_table[i]);9191+ hw->rates |= snd_pcm_rate_to_rate_bit(snd_bebob_rate_table[i]);9292+ }9393+}9494+9595+static void9696+limit_period_and_buffer(struct snd_pcm_hardware *hw)9797+{9898+ hw->periods_min = 2; /* SNDRV_PCM_INFO_BATCH */9999+ hw->periods_max = UINT_MAX;100100+101101+ hw->period_bytes_min = 4 * hw->channels_max; /* bytes for a frame */102102+103103+ /* Just to prevent from allocating much pages. */104104+ hw->period_bytes_max = hw->period_bytes_min * 2048;105105+ hw->buffer_bytes_max = hw->period_bytes_max * hw->periods_min;106106+}107107+108108+static int109109+pcm_init_hw_params(struct snd_bebob *bebob,110110+ struct snd_pcm_substream *substream)111111+{112112+ struct snd_pcm_runtime *runtime = substream->runtime;113113+ struct amdtp_stream *s;114114+ struct snd_bebob_stream_formation *formations;115115+ int err;116116+117117+ runtime->hw.info = SNDRV_PCM_INFO_BATCH |118118+ SNDRV_PCM_INFO_BLOCK_TRANSFER |119119+ SNDRV_PCM_INFO_INTERLEAVED |120120+ SNDRV_PCM_INFO_JOINT_DUPLEX |121121+ SNDRV_PCM_INFO_MMAP |122122+ SNDRV_PCM_INFO_MMAP_VALID;123123+124124+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {125125+ runtime->hw.formats = AMDTP_IN_PCM_FORMAT_BITS;126126+ s = &bebob->tx_stream;127127+ formations = bebob->tx_stream_formations;128128+ } else {129129+ runtime->hw.formats = AMDTP_OUT_PCM_FORMAT_BITS;130130+ s = &bebob->rx_stream;131131+ formations = bebob->rx_stream_formations;132132+ }133133+134134+ limit_channels_and_rates(&runtime->hw, formations);135135+ limit_period_and_buffer(&runtime->hw);136136+137137+ err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,138138+ hw_rule_channels, formations,139139+ SNDRV_PCM_HW_PARAM_RATE, -1);140140+ if (err < 0)141141+ goto end;142142+143143+ err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,144144+ hw_rule_rate, formations,145145+ SNDRV_PCM_HW_PARAM_CHANNELS, -1);146146+ if (err < 0)147147+ goto end;148148+149149+ err = amdtp_stream_add_pcm_hw_constraints(s, runtime);150150+end:151151+ return err;152152+}153153+154154+static int155155+pcm_open(struct snd_pcm_substream *substream)156156+{157157+ struct snd_bebob *bebob = substream->private_data;158158+ struct snd_bebob_rate_spec *spec = bebob->spec->rate;159159+ unsigned int sampling_rate;160160+ bool internal;161161+ int err;162162+163163+ err = snd_bebob_stream_lock_try(bebob);164164+ if (err < 0)165165+ goto end;166166+167167+ err = pcm_init_hw_params(bebob, substream);168168+ if (err < 0)169169+ goto err_locked;170170+171171+ err = snd_bebob_stream_check_internal_clock(bebob, &internal);172172+ if (err < 0)173173+ goto err_locked;174174+175175+ /*176176+ * When source of clock is internal or any PCM stream are running,177177+ * the available sampling rate is limited at current sampling rate.178178+ */179179+ if (!internal ||180180+ amdtp_stream_pcm_running(&bebob->tx_stream) ||181181+ amdtp_stream_pcm_running(&bebob->rx_stream)) {182182+ err = spec->get(bebob, &sampling_rate);183183+ if (err < 0) {184184+ dev_err(&bebob->unit->device,185185+ "fail to get sampling rate: %d\n", err);186186+ goto err_locked;187187+ }188188+189189+ substream->runtime->hw.rate_min = sampling_rate;190190+ substream->runtime->hw.rate_max = sampling_rate;191191+ }192192+193193+ snd_pcm_set_sync(substream);194194+end:195195+ return err;196196+err_locked:197197+ snd_bebob_stream_lock_release(bebob);198198+ return err;199199+}200200+201201+static int202202+pcm_close(struct snd_pcm_substream *substream)203203+{204204+ struct snd_bebob *bebob = substream->private_data;205205+ snd_bebob_stream_lock_release(bebob);206206+ return 0;207207+}208208+209209+static int210210+pcm_capture_hw_params(struct snd_pcm_substream *substream,211211+ struct snd_pcm_hw_params *hw_params)212212+{213213+ struct snd_bebob *bebob = substream->private_data;214214+215215+ if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)216216+ atomic_inc(&bebob->capture_substreams);217217+ amdtp_stream_set_pcm_format(&bebob->tx_stream,218218+ params_format(hw_params));219219+ return snd_pcm_lib_alloc_vmalloc_buffer(substream,220220+ params_buffer_bytes(hw_params));221221+}222222+static int223223+pcm_playback_hw_params(struct snd_pcm_substream *substream,224224+ struct snd_pcm_hw_params *hw_params)225225+{226226+ struct snd_bebob *bebob = substream->private_data;227227+228228+ if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)229229+ atomic_inc(&bebob->playback_substreams);230230+ amdtp_stream_set_pcm_format(&bebob->rx_stream,231231+ params_format(hw_params));232232+ return snd_pcm_lib_alloc_vmalloc_buffer(substream,233233+ params_buffer_bytes(hw_params));234234+}235235+236236+static int237237+pcm_capture_hw_free(struct snd_pcm_substream *substream)238238+{239239+ struct snd_bebob *bebob = substream->private_data;240240+241241+ if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)242242+ atomic_dec(&bebob->capture_substreams);243243+244244+ snd_bebob_stream_stop_duplex(bebob);245245+246246+ return snd_pcm_lib_free_vmalloc_buffer(substream);247247+}248248+static int249249+pcm_playback_hw_free(struct snd_pcm_substream *substream)250250+{251251+ struct snd_bebob *bebob = substream->private_data;252252+253253+ if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN)254254+ atomic_dec(&bebob->playback_substreams);255255+256256+ snd_bebob_stream_stop_duplex(bebob);257257+258258+ return snd_pcm_lib_free_vmalloc_buffer(substream);259259+}260260+261261+static int262262+pcm_capture_prepare(struct snd_pcm_substream *substream)263263+{264264+ struct snd_bebob *bebob = substream->private_data;265265+ struct snd_pcm_runtime *runtime = substream->runtime;266266+ int err;267267+268268+ err = snd_bebob_stream_start_duplex(bebob, runtime->rate);269269+ if (err >= 0)270270+ amdtp_stream_pcm_prepare(&bebob->tx_stream);271271+272272+ return err;273273+}274274+static int275275+pcm_playback_prepare(struct snd_pcm_substream *substream)276276+{277277+ struct snd_bebob *bebob = substream->private_data;278278+ struct snd_pcm_runtime *runtime = substream->runtime;279279+ int err;280280+281281+ err = snd_bebob_stream_start_duplex(bebob, runtime->rate);282282+ if (err >= 0)283283+ amdtp_stream_pcm_prepare(&bebob->rx_stream);284284+285285+ return err;286286+}287287+288288+static int289289+pcm_capture_trigger(struct snd_pcm_substream *substream, int cmd)290290+{291291+ struct snd_bebob *bebob = substream->private_data;292292+293293+ switch (cmd) {294294+ case SNDRV_PCM_TRIGGER_START:295295+ amdtp_stream_pcm_trigger(&bebob->tx_stream, substream);296296+ break;297297+ case SNDRV_PCM_TRIGGER_STOP:298298+ amdtp_stream_pcm_trigger(&bebob->tx_stream, NULL);299299+ break;300300+ default:301301+ return -EINVAL;302302+ }303303+304304+ return 0;305305+}306306+static int307307+pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd)308308+{309309+ struct snd_bebob *bebob = substream->private_data;310310+311311+ switch (cmd) {312312+ case SNDRV_PCM_TRIGGER_START:313313+ amdtp_stream_pcm_trigger(&bebob->rx_stream, substream);314314+ break;315315+ case SNDRV_PCM_TRIGGER_STOP:316316+ amdtp_stream_pcm_trigger(&bebob->rx_stream, NULL);317317+ break;318318+ default:319319+ return -EINVAL;320320+ }321321+322322+ return 0;323323+}324324+325325+static snd_pcm_uframes_t326326+pcm_capture_pointer(struct snd_pcm_substream *sbstrm)327327+{328328+ struct snd_bebob *bebob = sbstrm->private_data;329329+ return amdtp_stream_pcm_pointer(&bebob->tx_stream);330330+}331331+static snd_pcm_uframes_t332332+pcm_playback_pointer(struct snd_pcm_substream *sbstrm)333333+{334334+ struct snd_bebob *bebob = sbstrm->private_data;335335+ return amdtp_stream_pcm_pointer(&bebob->rx_stream);336336+}337337+338338+static const struct snd_pcm_ops pcm_capture_ops = {339339+ .open = pcm_open,340340+ .close = pcm_close,341341+ .ioctl = snd_pcm_lib_ioctl,342342+ .hw_params = pcm_capture_hw_params,343343+ .hw_free = pcm_capture_hw_free,344344+ .prepare = pcm_capture_prepare,345345+ .trigger = pcm_capture_trigger,346346+ .pointer = pcm_capture_pointer,347347+ .page = snd_pcm_lib_get_vmalloc_page,348348+};349349+static const struct snd_pcm_ops pcm_playback_ops = {350350+ .open = pcm_open,351351+ .close = pcm_close,352352+ .ioctl = snd_pcm_lib_ioctl,353353+ .hw_params = pcm_playback_hw_params,354354+ .hw_free = pcm_playback_hw_free,355355+ .prepare = pcm_playback_prepare,356356+ .trigger = pcm_playback_trigger,357357+ .pointer = pcm_playback_pointer,358358+ .page = snd_pcm_lib_get_vmalloc_page,359359+ .mmap = snd_pcm_lib_mmap_vmalloc,360360+};361361+362362+int snd_bebob_create_pcm_devices(struct snd_bebob *bebob)363363+{364364+ struct snd_pcm *pcm;365365+ int err;366366+367367+ err = snd_pcm_new(bebob->card, bebob->card->driver, 0, 1, 1, &pcm);368368+ if (err < 0)369369+ goto end;370370+371371+ pcm->private_data = bebob;372372+ snprintf(pcm->name, sizeof(pcm->name),373373+ "%s PCM", bebob->card->shortname);374374+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &pcm_playback_ops);375375+ snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_capture_ops);376376+end:377377+ return err;378378+}
+196
sound/firewire/bebob/bebob_proc.c
···11+/*22+ * bebob_proc.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+/* contents of information register */1212+struct hw_info {1313+ u64 manufacturer;1414+ u32 protocol_ver;1515+ u32 bld_ver;1616+ u32 guid[2];1717+ u32 model_id;1818+ u32 model_rev;1919+ u64 fw_date;2020+ u64 fw_time;2121+ u32 fw_id;2222+ u32 fw_ver;2323+ u32 base_addr;2424+ u32 max_size;2525+ u64 bld_date;2626+ u64 bld_time;2727+/* may not used in product2828+ u64 dbg_date;2929+ u64 dbg_time;3030+ u32 dbg_id;3131+ u32 dbg_version;3232+*/3333+} __packed;3434+3535+static void3636+proc_read_hw_info(struct snd_info_entry *entry,3737+ struct snd_info_buffer *buffer)3838+{3939+ struct snd_bebob *bebob = entry->private_data;4040+ struct hw_info *info;4141+4242+ info = kzalloc(sizeof(struct hw_info), GFP_KERNEL);4343+ if (info == NULL)4444+ return;4545+4646+ if (snd_bebob_read_block(bebob->unit, 0,4747+ info, sizeof(struct hw_info)) < 0)4848+ goto end;4949+5050+ snd_iprintf(buffer, "Manufacturer:\t%.8s\n",5151+ (char *)&info->manufacturer);5252+ snd_iprintf(buffer, "Protocol Ver:\t%d\n", info->protocol_ver);5353+ snd_iprintf(buffer, "Build Ver:\t%d\n", info->bld_ver);5454+ snd_iprintf(buffer, "GUID:\t\t0x%.8X%.8X\n",5555+ info->guid[0], info->guid[1]);5656+ snd_iprintf(buffer, "Model ID:\t0x%02X\n", info->model_id);5757+ snd_iprintf(buffer, "Model Rev:\t%d\n", info->model_rev);5858+ snd_iprintf(buffer, "Firmware Date:\t%.8s\n", (char *)&info->fw_date);5959+ snd_iprintf(buffer, "Firmware Time:\t%.8s\n", (char *)&info->fw_time);6060+ snd_iprintf(buffer, "Firmware ID:\t0x%X\n", info->fw_id);6161+ snd_iprintf(buffer, "Firmware Ver:\t%d\n", info->fw_ver);6262+ snd_iprintf(buffer, "Base Addr:\t0x%X\n", info->base_addr);6363+ snd_iprintf(buffer, "Max Size:\t%d\n", info->max_size);6464+ snd_iprintf(buffer, "Loader Date:\t%.8s\n", (char *)&info->bld_date);6565+ snd_iprintf(buffer, "Loader Time:\t%.8s\n", (char *)&info->bld_time);6666+6767+end:6868+ kfree(info);6969+}7070+7171+static void7272+proc_read_meters(struct snd_info_entry *entry,7373+ struct snd_info_buffer *buffer)7474+{7575+ struct snd_bebob *bebob = entry->private_data;7676+ struct snd_bebob_meter_spec *spec = bebob->spec->meter;7777+ u32 *buf;7878+ unsigned int i, c, channels, size;7979+8080+ if (spec == NULL)8181+ return;8282+8383+ channels = spec->num * 2;8484+ size = channels * sizeof(u32);8585+ buf = kmalloc(size, GFP_KERNEL);8686+ if (buf == NULL)8787+ return;8888+8989+ if (spec->get(bebob, buf, size) < 0)9090+ goto end;9191+9292+ for (i = 0, c = 1; i < channels; i++) {9393+ snd_iprintf(buffer, "%s %d:\t%d\n",9494+ spec->labels[i / 2], c++, buf[i]);9595+ if ((i + 1 < channels - 1) &&9696+ (strcmp(spec->labels[i / 2],9797+ spec->labels[(i + 1) / 2]) != 0))9898+ c = 1;9999+ }100100+end:101101+ kfree(buf);102102+}103103+104104+static void105105+proc_read_formation(struct snd_info_entry *entry,106106+ struct snd_info_buffer *buffer)107107+{108108+ struct snd_bebob *bebob = entry->private_data;109109+ struct snd_bebob_stream_formation *formation;110110+ unsigned int i;111111+112112+ snd_iprintf(buffer, "Output Stream from device:\n");113113+ snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");114114+ formation = bebob->tx_stream_formations;115115+ for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {116116+ snd_iprintf(buffer,117117+ "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],118118+ formation[i].pcm, formation[i].midi);119119+ }120120+121121+ snd_iprintf(buffer, "Input Stream to device:\n");122122+ snd_iprintf(buffer, "\tRate\tPCM\tMIDI\n");123123+ formation = bebob->rx_stream_formations;124124+ for (i = 0; i < SND_BEBOB_STRM_FMT_ENTRIES; i++) {125125+ snd_iprintf(buffer,126126+ "\t%d\t%d\t%d\n", snd_bebob_rate_table[i],127127+ formation[i].pcm, formation[i].midi);128128+ }129129+}130130+131131+static void132132+proc_read_clock(struct snd_info_entry *entry,133133+ struct snd_info_buffer *buffer)134134+{135135+ struct snd_bebob *bebob = entry->private_data;136136+ struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;137137+ struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;138138+ unsigned int rate, id;139139+ bool internal;140140+141141+ if (rate_spec->get(bebob, &rate) >= 0)142142+ snd_iprintf(buffer, "Sampling rate: %d\n", rate);143143+144144+ if (clk_spec) {145145+ if (clk_spec->get(bebob, &id) >= 0)146146+ snd_iprintf(buffer, "Clock Source: %s\n",147147+ clk_spec->labels[id]);148148+ } else {149149+ if (snd_bebob_stream_check_internal_clock(bebob,150150+ &internal) >= 0)151151+ snd_iprintf(buffer, "Clock Source: %s (MSU-dest: %d)\n",152152+ (internal) ? "Internal" : "External",153153+ bebob->sync_input_plug);154154+ }155155+}156156+157157+static void158158+add_node(struct snd_bebob *bebob, struct snd_info_entry *root, const char *name,159159+ void (*op)(struct snd_info_entry *e, struct snd_info_buffer *b))160160+{161161+ struct snd_info_entry *entry;162162+163163+ entry = snd_info_create_card_entry(bebob->card, name, root);164164+ if (entry == NULL)165165+ return;166166+167167+ snd_info_set_text_ops(entry, bebob, op);168168+ if (snd_info_register(entry) < 0)169169+ snd_info_free_entry(entry);170170+}171171+172172+void snd_bebob_proc_init(struct snd_bebob *bebob)173173+{174174+ struct snd_info_entry *root;175175+176176+ /*177177+ * All nodes are automatically removed at snd_card_disconnect(),178178+ * by following to link list.179179+ */180180+ root = snd_info_create_card_entry(bebob->card, "firewire",181181+ bebob->card->proc_root);182182+ if (root == NULL)183183+ return;184184+ root->mode = S_IFDIR | S_IRUGO | S_IXUGO;185185+ if (snd_info_register(root) < 0) {186186+ snd_info_free_entry(root);187187+ return;188188+ }189189+190190+ add_node(bebob, root, "clock", proc_read_clock);191191+ add_node(bebob, root, "firmware", proc_read_hw_info);192192+ add_node(bebob, root, "formation", proc_read_formation);193193+194194+ if (bebob->spec->meter != NULL)195195+ add_node(bebob, root, "meter", proc_read_meters);196196+}
+1021
sound/firewire/bebob/bebob_stream.c
···11+/*22+ * bebob_stream.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+#define CALLBACK_TIMEOUT 10001212+#define FW_ISO_RESOURCE_DELAY 10001313+1414+/*1515+ * NOTE;1616+ * For BeBoB streams, Both of input and output CMP connection are important.1717+ *1818+ * For most devices, each CMP connection starts to transmit/receive a1919+ * corresponding stream. But for a few devices, both of CMP connection needs2020+ * to start transmitting stream. An example is 'M-Audio Firewire 410'.2121+ */2222+2323+/* 128 is an arbitrary length but it seems to be enough */2424+#define FORMAT_MAXIMUM_LENGTH 1282525+2626+const unsigned int snd_bebob_rate_table[SND_BEBOB_STRM_FMT_ENTRIES] = {2727+ [0] = 32000,2828+ [1] = 44100,2929+ [2] = 48000,3030+ [3] = 88200,3131+ [4] = 96000,3232+ [5] = 176400,3333+ [6] = 192000,3434+};3535+3636+/*3737+ * See: Table 51: Extended Stream Format Info ‘Sampling Frequency’3838+ * in Additional AVC commands (Nov 2003, BridgeCo)3939+ */4040+static const unsigned int bridgeco_freq_table[] = {4141+ [0] = 0x02,4242+ [1] = 0x03,4343+ [2] = 0x04,4444+ [3] = 0x0a,4545+ [4] = 0x05,4646+ [5] = 0x06,4747+ [6] = 0x07,4848+};4949+5050+static unsigned int5151+get_formation_index(unsigned int rate)5252+{5353+ unsigned int i;5454+5555+ for (i = 0; i < ARRAY_SIZE(snd_bebob_rate_table); i++) {5656+ if (snd_bebob_rate_table[i] == rate)5757+ return i;5858+ }5959+ return -EINVAL;6060+}6161+6262+int6363+snd_bebob_stream_get_rate(struct snd_bebob *bebob, unsigned int *curr_rate)6464+{6565+ unsigned int tx_rate, rx_rate, trials;6666+ int err;6767+6868+ trials = 0;6969+ do {7070+ err = avc_general_get_sig_fmt(bebob->unit, &tx_rate,7171+ AVC_GENERAL_PLUG_DIR_OUT, 0);7272+ } while (err == -EAGAIN && ++trials < 3);7373+ if (err < 0)7474+ goto end;7575+7676+ trials = 0;7777+ do {7878+ err = avc_general_get_sig_fmt(bebob->unit, &rx_rate,7979+ AVC_GENERAL_PLUG_DIR_IN, 0);8080+ } while (err == -EAGAIN && ++trials < 3);8181+ if (err < 0)8282+ goto end;8383+8484+ *curr_rate = rx_rate;8585+ if (rx_rate == tx_rate)8686+ goto end;8787+8888+ /* synchronize receive stream rate to transmit stream rate */8989+ err = avc_general_set_sig_fmt(bebob->unit, rx_rate,9090+ AVC_GENERAL_PLUG_DIR_IN, 0);9191+end:9292+ return err;9393+}9494+9595+int9696+snd_bebob_stream_set_rate(struct snd_bebob *bebob, unsigned int rate)9797+{9898+ int err;9999+100100+ err = avc_general_set_sig_fmt(bebob->unit, rate,101101+ AVC_GENERAL_PLUG_DIR_OUT, 0);102102+ if (err < 0)103103+ goto end;104104+105105+ err = avc_general_set_sig_fmt(bebob->unit, rate,106106+ AVC_GENERAL_PLUG_DIR_IN, 0);107107+ if (err < 0)108108+ goto end;109109+110110+ /*111111+ * Some devices need a bit time for transition.112112+ * 300msec is got by some experiments.113113+ */114114+ msleep(300);115115+end:116116+ return err;117117+}118118+119119+int120120+snd_bebob_stream_check_internal_clock(struct snd_bebob *bebob, bool *internal)121121+{122122+ struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;123123+ u8 addr[AVC_BRIDGECO_ADDR_BYTES], input[7];124124+ unsigned int id;125125+ int err = 0;126126+127127+ *internal = false;128128+129129+ /* 1.The device has its own operation to switch source of clock */130130+ if (clk_spec) {131131+ err = clk_spec->get(bebob, &id);132132+ if (err < 0)133133+ dev_err(&bebob->unit->device,134134+ "fail to get clock source: %d\n", err);135135+ else if (strncmp(clk_spec->labels[id], SND_BEBOB_CLOCK_INTERNAL,136136+ strlen(SND_BEBOB_CLOCK_INTERNAL)) == 0)137137+ *internal = true;138138+ goto end;139139+ }140140+141141+ /*142142+ * 2.The device don't support to switch source of clock then assumed143143+ * to use internal clock always144144+ */145145+ if (bebob->sync_input_plug < 0) {146146+ *internal = true;147147+ goto end;148148+ }149149+150150+ /*151151+ * 3.The device supports to switch source of clock by an usual way.152152+ * Let's check input for 'Music Sub Unit Sync Input' plug.153153+ */154154+ avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,155155+ bebob->sync_input_plug);156156+ err = avc_bridgeco_get_plug_input(bebob->unit, addr, input);157157+ if (err < 0) {158158+ dev_err(&bebob->unit->device,159159+ "fail to get an input for MSU in plug %d: %d\n",160160+ bebob->sync_input_plug, err);161161+ goto end;162162+ }163163+164164+ /*165165+ * If there are no input plugs, all of fields are 0xff.166166+ * Here check the first field. This field is used for direction.167167+ */168168+ if (input[0] == 0xff) {169169+ *internal = true;170170+ goto end;171171+ }172172+173173+ /*174174+ * If source of clock is internal CSR, Music Sub Unit Sync Input is175175+ * a destination of Music Sub Unit Sync Output.176176+ */177177+ *internal = ((input[0] == AVC_BRIDGECO_PLUG_DIR_OUT) &&178178+ (input[1] == AVC_BRIDGECO_PLUG_MODE_SUBUNIT) &&179179+ (input[2] == 0x0c) &&180180+ (input[3] == 0x00));181181+end:182182+ return err;183183+}184184+185185+static unsigned int186186+map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)187187+{188188+ unsigned int sec, sections, ch, channels;189189+ unsigned int pcm, midi, location;190190+ unsigned int stm_pos, sec_loc, pos;191191+ u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;192192+ enum avc_bridgeco_plug_dir dir;193193+ int err;194194+195195+ /*196196+ * The length of return value of this command cannot be expected. Here197197+ * use the maximum length of FCP.198198+ */199199+ buf = kzalloc(256, GFP_KERNEL);200200+ if (buf == NULL)201201+ return -ENOMEM;202202+203203+ if (s == &bebob->tx_stream)204204+ dir = AVC_BRIDGECO_PLUG_DIR_OUT;205205+ else206206+ dir = AVC_BRIDGECO_PLUG_DIR_IN;207207+208208+ avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);209209+ err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);210210+ if (err < 0) {211211+ dev_err(&bebob->unit->device,212212+ "fail to get channel position for isoc %s plug 0: %d\n",213213+ (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" : "out",214214+ err);215215+ goto end;216216+ }217217+ pos = 0;218218+219219+ /* positions in I/O buffer */220220+ pcm = 0;221221+ midi = 0;222222+223223+ /* the number of sections in AMDTP packet */224224+ sections = buf[pos++];225225+226226+ for (sec = 0; sec < sections; sec++) {227227+ /* type of this section */228228+ avc_bridgeco_fill_unit_addr(addr, dir,229229+ AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);230230+ err = avc_bridgeco_get_plug_section_type(bebob->unit, addr,231231+ sec, &type);232232+ if (err < 0) {233233+ dev_err(&bebob->unit->device,234234+ "fail to get section type for isoc %s plug 0: %d\n",235235+ (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :236236+ "out",237237+ err);238238+ goto end;239239+ }240240+ /* NoType */241241+ if (type == 0xff) {242242+ err = -ENOSYS;243243+ goto end;244244+ }245245+246246+ /* the number of channels in this section */247247+ channels = buf[pos++];248248+249249+ for (ch = 0; ch < channels; ch++) {250250+ /* position of this channel in AMDTP packet */251251+ stm_pos = buf[pos++] - 1;252252+ /* location of this channel in this section */253253+ sec_loc = buf[pos++] - 1;254254+255255+ /*256256+ * Basically the number of location is within the257257+ * number of channels in this section. But some models258258+ * of M-Audio don't follow this. Its location for MIDI259259+ * is the position of MIDI channels in AMDTP packet.260260+ */261261+ if (sec_loc >= channels)262262+ sec_loc = ch;263263+264264+ switch (type) {265265+ /* for MIDI conformant data channel */266266+ case 0x0a:267267+ /* AMDTP_MAX_CHANNELS_FOR_MIDI is 1. */268268+ if ((midi > 0) && (stm_pos != midi)) {269269+ err = -ENOSYS;270270+ goto end;271271+ }272272+ s->midi_position = stm_pos;273273+ midi = stm_pos;274274+ break;275275+ /* for PCM data channel */276276+ case 0x01: /* Headphone */277277+ case 0x02: /* Microphone */278278+ case 0x03: /* Line */279279+ case 0x04: /* SPDIF */280280+ case 0x05: /* ADAT */281281+ case 0x06: /* TDIF */282282+ case 0x07: /* MADI */283283+ /* for undefined/changeable signal */284284+ case 0x08: /* Analog */285285+ case 0x09: /* Digital */286286+ default:287287+ location = pcm + sec_loc;288288+ if (location >= AMDTP_MAX_CHANNELS_FOR_PCM) {289289+ err = -ENOSYS;290290+ goto end;291291+ }292292+ s->pcm_positions[location] = stm_pos;293293+ break;294294+ }295295+ }296296+297297+ if (type != 0x0a)298298+ pcm += channels;299299+ else300300+ midi += channels;301301+ }302302+end:303303+ kfree(buf);304304+ return err;305305+}306306+307307+static int308308+init_both_connections(struct snd_bebob *bebob)309309+{310310+ int err;311311+312312+ err = cmp_connection_init(&bebob->in_conn,313313+ bebob->unit, CMP_INPUT, 0);314314+ if (err < 0)315315+ goto end;316316+317317+ err = cmp_connection_init(&bebob->out_conn,318318+ bebob->unit, CMP_OUTPUT, 0);319319+ if (err < 0)320320+ cmp_connection_destroy(&bebob->in_conn);321321+end:322322+ return err;323323+}324324+325325+static int326326+check_connection_used_by_others(struct snd_bebob *bebob, struct amdtp_stream *s)327327+{328328+ struct cmp_connection *conn;329329+ bool used;330330+ int err;331331+332332+ if (s == &bebob->tx_stream)333333+ conn = &bebob->out_conn;334334+ else335335+ conn = &bebob->in_conn;336336+337337+ err = cmp_connection_check_used(conn, &used);338338+ if ((err >= 0) && used && !amdtp_stream_running(s)) {339339+ dev_err(&bebob->unit->device,340340+ "Connection established by others: %cPCR[%d]\n",341341+ (conn->direction == CMP_OUTPUT) ? 'o' : 'i',342342+ conn->pcr_index);343343+ err = -EBUSY;344344+ }345345+346346+ return err;347347+}348348+349349+static int350350+make_both_connections(struct snd_bebob *bebob, unsigned int rate)351351+{352352+ int index, pcm_channels, midi_channels, err = 0;353353+354354+ if (bebob->connected)355355+ goto end;356356+357357+ /* confirm params for both streams */358358+ index = get_formation_index(rate);359359+ pcm_channels = bebob->tx_stream_formations[index].pcm;360360+ midi_channels = bebob->tx_stream_formations[index].midi;361361+ amdtp_stream_set_parameters(&bebob->tx_stream,362362+ rate, pcm_channels, midi_channels * 8);363363+ pcm_channels = bebob->rx_stream_formations[index].pcm;364364+ midi_channels = bebob->rx_stream_formations[index].midi;365365+ amdtp_stream_set_parameters(&bebob->rx_stream,366366+ rate, pcm_channels, midi_channels * 8);367367+368368+ /* establish connections for both streams */369369+ err = cmp_connection_establish(&bebob->out_conn,370370+ amdtp_stream_get_max_payload(&bebob->tx_stream));371371+ if (err < 0)372372+ goto end;373373+ err = cmp_connection_establish(&bebob->in_conn,374374+ amdtp_stream_get_max_payload(&bebob->rx_stream));375375+ if (err < 0) {376376+ cmp_connection_break(&bebob->out_conn);377377+ goto end;378378+ }379379+380380+ bebob->connected = true;381381+end:382382+ return err;383383+}384384+385385+static void386386+break_both_connections(struct snd_bebob *bebob)387387+{388388+ cmp_connection_break(&bebob->in_conn);389389+ cmp_connection_break(&bebob->out_conn);390390+391391+ bebob->connected = false;392392+393393+ /* These models seems to be in transition state for a longer time. */394394+ if (bebob->maudio_special_quirk != NULL)395395+ msleep(200);396396+}397397+398398+static void399399+destroy_both_connections(struct snd_bebob *bebob)400400+{401401+ break_both_connections(bebob);402402+403403+ cmp_connection_destroy(&bebob->in_conn);404404+ cmp_connection_destroy(&bebob->out_conn);405405+}406406+407407+static int408408+get_sync_mode(struct snd_bebob *bebob, enum cip_flags *sync_mode)409409+{410410+ /* currently this module doesn't support SYT-Match mode */411411+ *sync_mode = CIP_SYNC_TO_DEVICE;412412+ return 0;413413+}414414+415415+static int416416+start_stream(struct snd_bebob *bebob, struct amdtp_stream *stream,417417+ unsigned int rate)418418+{419419+ struct cmp_connection *conn;420420+ int err = 0;421421+422422+ if (stream == &bebob->rx_stream)423423+ conn = &bebob->in_conn;424424+ else425425+ conn = &bebob->out_conn;426426+427427+ /* channel mapping */428428+ if (bebob->maudio_special_quirk == NULL) {429429+ err = map_data_channels(bebob, stream);430430+ if (err < 0)431431+ goto end;432432+ }433433+434434+ /* start amdtp stream */435435+ err = amdtp_stream_start(stream,436436+ conn->resources.channel,437437+ conn->speed);438438+end:439439+ return err;440440+}441441+442442+int snd_bebob_stream_init_duplex(struct snd_bebob *bebob)443443+{444444+ int err;445445+446446+ err = init_both_connections(bebob);447447+ if (err < 0)448448+ goto end;449449+450450+ err = amdtp_stream_init(&bebob->tx_stream, bebob->unit,451451+ AMDTP_IN_STREAM, CIP_BLOCKING);452452+ if (err < 0) {453453+ amdtp_stream_destroy(&bebob->tx_stream);454454+ destroy_both_connections(bebob);455455+ goto end;456456+ }457457+ /* See comments in next function */458458+ init_completion(&bebob->bus_reset);459459+ bebob->tx_stream.flags |= CIP_SKIP_INIT_DBC_CHECK;460460+ /*461461+ * At high sampling rate, M-Audio special firmware transmits empty462462+ * packet with the value of dbc incremented by 8 but the others are463463+ * valid to IEC 61883-1.464464+ */465465+ if (bebob->maudio_special_quirk)466466+ bebob->tx_stream.flags |= CIP_EMPTY_HAS_WRONG_DBC;467467+468468+ err = amdtp_stream_init(&bebob->rx_stream, bebob->unit,469469+ AMDTP_OUT_STREAM, CIP_BLOCKING);470470+ if (err < 0) {471471+ amdtp_stream_destroy(&bebob->tx_stream);472472+ amdtp_stream_destroy(&bebob->rx_stream);473473+ destroy_both_connections(bebob);474474+ }475475+ /*476476+ * The firmware for these devices ignore MIDI messages in more than477477+ * first 8 data blocks of an received AMDTP packet.478478+ */479479+ if (bebob->spec == &maudio_fw410_spec ||480480+ bebob->spec == &maudio_special_spec)481481+ bebob->rx_stream.rx_blocks_for_midi = 8;482482+end:483483+ return err;484484+}485485+486486+int snd_bebob_stream_start_duplex(struct snd_bebob *bebob, unsigned int rate)487487+{488488+ struct snd_bebob_rate_spec *rate_spec = bebob->spec->rate;489489+ struct amdtp_stream *master, *slave;490490+ atomic_t *slave_substreams;491491+ enum cip_flags sync_mode;492492+ unsigned int curr_rate;493493+ bool updated = false;494494+ int err = 0;495495+496496+ /*497497+ * Normal BeBoB firmware has a quirk at bus reset to transmits packets498498+ * with discontinuous value in dbc field.499499+ *500500+ * This 'struct completion' is used to call .update() at first to update501501+ * connections/streams. Next following codes handle streaming error.502502+ */503503+ if (amdtp_streaming_error(&bebob->tx_stream)) {504504+ if (completion_done(&bebob->bus_reset))505505+ reinit_completion(&bebob->bus_reset);506506+507507+ updated = (wait_for_completion_interruptible_timeout(508508+ &bebob->bus_reset,509509+ msecs_to_jiffies(FW_ISO_RESOURCE_DELAY)) > 0);510510+ }511511+512512+ mutex_lock(&bebob->mutex);513513+514514+ /* Need no substreams */515515+ if (atomic_read(&bebob->playback_substreams) == 0 &&516516+ atomic_read(&bebob->capture_substreams) == 0)517517+ goto end;518518+519519+ err = get_sync_mode(bebob, &sync_mode);520520+ if (err < 0)521521+ goto end;522522+ if (sync_mode == CIP_SYNC_TO_DEVICE) {523523+ master = &bebob->tx_stream;524524+ slave = &bebob->rx_stream;525525+ slave_substreams = &bebob->playback_substreams;526526+ } else {527527+ master = &bebob->rx_stream;528528+ slave = &bebob->tx_stream;529529+ slave_substreams = &bebob->capture_substreams;530530+ }531531+532532+ /*533533+ * Considering JACK/FFADO streaming:534534+ * TODO: This can be removed hwdep functionality becomes popular.535535+ */536536+ err = check_connection_used_by_others(bebob, master);537537+ if (err < 0)538538+ goto end;539539+540540+ /*541541+ * packet queueing error or detecting discontinuity542542+ *543543+ * At bus reset, connections should not be broken here. So streams need544544+ * to be re-started. This is a reason to use SKIP_INIT_DBC_CHECK flag.545545+ */546546+ if (amdtp_streaming_error(master))547547+ amdtp_stream_stop(master);548548+ if (amdtp_streaming_error(slave))549549+ amdtp_stream_stop(slave);550550+ if (!updated &&551551+ !amdtp_stream_running(master) && !amdtp_stream_running(slave))552552+ break_both_connections(bebob);553553+554554+ /* stop streams if rate is different */555555+ err = rate_spec->get(bebob, &curr_rate);556556+ if (err < 0) {557557+ dev_err(&bebob->unit->device,558558+ "fail to get sampling rate: %d\n", err);559559+ goto end;560560+ }561561+ if (rate == 0)562562+ rate = curr_rate;563563+ if (rate != curr_rate) {564564+ amdtp_stream_stop(master);565565+ amdtp_stream_stop(slave);566566+ break_both_connections(bebob);567567+ }568568+569569+ /* master should be always running */570570+ if (!amdtp_stream_running(master)) {571571+ amdtp_stream_set_sync(sync_mode, master, slave);572572+ bebob->master = master;573573+574574+ /*575575+ * NOTE:576576+ * If establishing connections at first, Yamaha GO46577577+ * (and maybe Terratec X24) don't generate sound.578578+ *579579+ * For firmware customized by M-Audio, refer to next NOTE.580580+ */581581+ if (bebob->maudio_special_quirk == NULL) {582582+ err = rate_spec->set(bebob, rate);583583+ if (err < 0) {584584+ dev_err(&bebob->unit->device,585585+ "fail to set sampling rate: %d\n",586586+ err);587587+ goto end;588588+ }589589+ }590590+591591+ err = make_both_connections(bebob, rate);592592+ if (err < 0)593593+ goto end;594594+595595+ err = start_stream(bebob, master, rate);596596+ if (err < 0) {597597+ dev_err(&bebob->unit->device,598598+ "fail to run AMDTP master stream:%d\n", err);599599+ break_both_connections(bebob);600600+ goto end;601601+ }602602+603603+ /*604604+ * NOTE:605605+ * The firmware customized by M-Audio uses these commands to606606+ * start transmitting stream. This is not usual way.607607+ */608608+ if (bebob->maudio_special_quirk != NULL) {609609+ err = rate_spec->set(bebob, rate);610610+ if (err < 0) {611611+ dev_err(&bebob->unit->device,612612+ "fail to ensure sampling rate: %d\n",613613+ err);614614+ amdtp_stream_stop(master);615615+ break_both_connections(bebob);616616+ goto end;617617+ }618618+ }619619+620620+ /* wait first callback */621621+ if (!amdtp_stream_wait_callback(master, CALLBACK_TIMEOUT)) {622622+ amdtp_stream_stop(master);623623+ break_both_connections(bebob);624624+ err = -ETIMEDOUT;625625+ goto end;626626+ }627627+ }628628+629629+ /* start slave if needed */630630+ if (atomic_read(slave_substreams) > 0 && !amdtp_stream_running(slave)) {631631+ err = start_stream(bebob, slave, rate);632632+ if (err < 0) {633633+ dev_err(&bebob->unit->device,634634+ "fail to run AMDTP slave stream:%d\n", err);635635+ amdtp_stream_stop(master);636636+ break_both_connections(bebob);637637+ goto end;638638+ }639639+640640+ /* wait first callback */641641+ if (!amdtp_stream_wait_callback(slave, CALLBACK_TIMEOUT)) {642642+ amdtp_stream_stop(slave);643643+ amdtp_stream_stop(master);644644+ break_both_connections(bebob);645645+ err = -ETIMEDOUT;646646+ }647647+ }648648+end:649649+ mutex_unlock(&bebob->mutex);650650+ return err;651651+}652652+653653+void snd_bebob_stream_stop_duplex(struct snd_bebob *bebob)654654+{655655+ struct amdtp_stream *master, *slave;656656+ atomic_t *master_substreams, *slave_substreams;657657+658658+ mutex_lock(&bebob->mutex);659659+660660+ if (bebob->master == &bebob->rx_stream) {661661+ slave = &bebob->tx_stream;662662+ master = &bebob->rx_stream;663663+ slave_substreams = &bebob->capture_substreams;664664+ master_substreams = &bebob->playback_substreams;665665+ } else {666666+ slave = &bebob->rx_stream;667667+ master = &bebob->tx_stream;668668+ slave_substreams = &bebob->playback_substreams;669669+ master_substreams = &bebob->capture_substreams;670670+ }671671+672672+ if (atomic_read(slave_substreams) == 0) {673673+ amdtp_stream_pcm_abort(slave);674674+ amdtp_stream_stop(slave);675675+676676+ if (atomic_read(master_substreams) == 0) {677677+ amdtp_stream_pcm_abort(master);678678+ amdtp_stream_stop(master);679679+ break_both_connections(bebob);680680+ }681681+ }682682+683683+ mutex_unlock(&bebob->mutex);684684+}685685+686686+void snd_bebob_stream_update_duplex(struct snd_bebob *bebob)687687+{688688+ /* vs. XRUN recovery due to discontinuity at bus reset */689689+ mutex_lock(&bebob->mutex);690690+691691+ if ((cmp_connection_update(&bebob->in_conn) < 0) ||692692+ (cmp_connection_update(&bebob->out_conn) < 0)) {693693+ amdtp_stream_pcm_abort(&bebob->rx_stream);694694+ amdtp_stream_pcm_abort(&bebob->tx_stream);695695+ amdtp_stream_stop(&bebob->rx_stream);696696+ amdtp_stream_stop(&bebob->tx_stream);697697+ break_both_connections(bebob);698698+ } else {699699+ amdtp_stream_update(&bebob->rx_stream);700700+ amdtp_stream_update(&bebob->tx_stream);701701+ }702702+703703+ /* wake up stream_start_duplex() */704704+ if (!completion_done(&bebob->bus_reset))705705+ complete_all(&bebob->bus_reset);706706+707707+ mutex_unlock(&bebob->mutex);708708+}709709+710710+void snd_bebob_stream_destroy_duplex(struct snd_bebob *bebob)711711+{712712+ mutex_lock(&bebob->mutex);713713+714714+ amdtp_stream_pcm_abort(&bebob->rx_stream);715715+ amdtp_stream_pcm_abort(&bebob->tx_stream);716716+717717+ amdtp_stream_stop(&bebob->rx_stream);718718+ amdtp_stream_stop(&bebob->tx_stream);719719+720720+ amdtp_stream_destroy(&bebob->rx_stream);721721+ amdtp_stream_destroy(&bebob->tx_stream);722722+723723+ destroy_both_connections(bebob);724724+725725+ mutex_unlock(&bebob->mutex);726726+}727727+728728+/*729729+ * See: Table 50: Extended Stream Format Info Format Hierarchy Level 2’730730+ * in Additional AVC commands (Nov 2003, BridgeCo)731731+ * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005732732+ */733733+static int734734+parse_stream_formation(u8 *buf, unsigned int len,735735+ struct snd_bebob_stream_formation *formation)736736+{737737+ unsigned int i, e, channels, format;738738+739739+ /*740740+ * this module can support a hierarchy combination that:741741+ * Root: Audio and Music (0x90)742742+ * Level 1: AM824 Compound (0x40)743743+ */744744+ if ((buf[0] != 0x90) || (buf[1] != 0x40))745745+ return -ENOSYS;746746+747747+ /* check sampling rate */748748+ for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {749749+ if (buf[2] == bridgeco_freq_table[i])750750+ break;751751+ }752752+ if (i == sizeof(bridgeco_freq_table))753753+ return -ENOSYS;754754+755755+ /* Avoid double count by different entries for the same rate. */756756+ memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));757757+758758+ for (e = 0; e < buf[4]; e++) {759759+ channels = buf[5 + e * 2];760760+ format = buf[6 + e * 2];761761+762762+ switch (format) {763763+ /* IEC 60958 Conformant, currently handled as MBLA */764764+ case 0x00:765765+ /* Multi bit linear audio */766766+ case 0x06: /* Raw */767767+ formation[i].pcm += channels;768768+ break;769769+ /* MIDI Conformant */770770+ case 0x0d:771771+ formation[i].midi += channels;772772+ break;773773+ /* IEC 61937-3 to 7 */774774+ case 0x01:775775+ case 0x02:776776+ case 0x03:777777+ case 0x04:778778+ case 0x05:779779+ /* Multi bit linear audio */780780+ case 0x07: /* DVD-Audio */781781+ case 0x0c: /* High Precision */782782+ /* One Bit Audio */783783+ case 0x08: /* (Plain) Raw */784784+ case 0x09: /* (Plain) SACD */785785+ case 0x0a: /* (Encoded) Raw */786786+ case 0x0b: /* (Encoded) SACD */787787+ /* Synchronization Stream (Stereo Raw audio) */788788+ case 0x40:789789+ /* Don't care */790790+ case 0xff:791791+ default:792792+ return -ENOSYS; /* not supported */793793+ }794794+ }795795+796796+ if (formation[i].pcm > AMDTP_MAX_CHANNELS_FOR_PCM ||797797+ formation[i].midi > AMDTP_MAX_CHANNELS_FOR_MIDI)798798+ return -ENOSYS;799799+800800+ return 0;801801+}802802+803803+static int804804+fill_stream_formations(struct snd_bebob *bebob, enum avc_bridgeco_plug_dir dir,805805+ unsigned short pid)806806+{807807+ u8 *buf;808808+ struct snd_bebob_stream_formation *formations;809809+ unsigned int len, eid;810810+ u8 addr[AVC_BRIDGECO_ADDR_BYTES];811811+ int err;812812+813813+ buf = kmalloc(FORMAT_MAXIMUM_LENGTH, GFP_KERNEL);814814+ if (buf == NULL)815815+ return -ENOMEM;816816+817817+ if (dir == AVC_BRIDGECO_PLUG_DIR_IN)818818+ formations = bebob->rx_stream_formations;819819+ else820820+ formations = bebob->tx_stream_formations;821821+822822+ for (eid = 0; eid < SND_BEBOB_STRM_FMT_ENTRIES; eid++) {823823+ len = FORMAT_MAXIMUM_LENGTH;824824+ avc_bridgeco_fill_unit_addr(addr, dir,825825+ AVC_BRIDGECO_PLUG_UNIT_ISOC, pid);826826+ err = avc_bridgeco_get_plug_strm_fmt(bebob->unit, addr, buf,827827+ &len, eid);828828+ /* No entries remained. */829829+ if (err == -EINVAL && eid > 0) {830830+ err = 0;831831+ break;832832+ } else if (err < 0) {833833+ dev_err(&bebob->unit->device,834834+ "fail to get stream format %d for isoc %s plug %d:%d\n",835835+ eid,836836+ (dir == AVC_BRIDGECO_PLUG_DIR_IN) ? "in" :837837+ "out",838838+ pid, err);839839+ break;840840+ }841841+842842+ err = parse_stream_formation(buf, len, formations);843843+ if (err < 0)844844+ break;845845+ }846846+847847+ kfree(buf);848848+ return err;849849+}850850+851851+static int852852+seek_msu_sync_input_plug(struct snd_bebob *bebob)853853+{854854+ u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];855855+ unsigned int i;856856+ enum avc_bridgeco_plug_type type;857857+ int err;858858+859859+ /* Get the number of Music Sub Unit for both direction. */860860+ err = avc_general_get_plug_info(bebob->unit, 0x0c, 0x00, 0x00, plugs);861861+ if (err < 0) {862862+ dev_err(&bebob->unit->device,863863+ "fail to get info for MSU in/out plugs: %d\n",864864+ err);865865+ goto end;866866+ }867867+868868+ /* seek destination plugs for 'MSU sync input' */869869+ bebob->sync_input_plug = -1;870870+ for (i = 0; i < plugs[0]; i++) {871871+ avc_bridgeco_fill_msu_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN, i);872872+ err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);873873+ if (err < 0) {874874+ dev_err(&bebob->unit->device,875875+ "fail to get type for MSU in plug %d: %d\n",876876+ i, err);877877+ goto end;878878+ }879879+880880+ if (type == AVC_BRIDGECO_PLUG_TYPE_SYNC) {881881+ bebob->sync_input_plug = i;882882+ break;883883+ }884884+ }885885+end:886886+ return err;887887+}888888+889889+int snd_bebob_stream_discover(struct snd_bebob *bebob)890890+{891891+ struct snd_bebob_clock_spec *clk_spec = bebob->spec->clock;892892+ u8 plugs[AVC_PLUG_INFO_BUF_BYTES], addr[AVC_BRIDGECO_ADDR_BYTES];893893+ enum avc_bridgeco_plug_type type;894894+ unsigned int i;895895+ int err;896896+897897+ /* the number of plugs for isoc in/out, ext in/out */898898+ err = avc_general_get_plug_info(bebob->unit, 0x1f, 0x07, 0x00, plugs);899899+ if (err < 0) {900900+ dev_err(&bebob->unit->device,901901+ "fail to get info for isoc/external in/out plugs: %d\n",902902+ err);903903+ goto end;904904+ }905905+906906+ /*907907+ * This module supports at least one isoc input plug and one isoc908908+ * output plug.909909+ */910910+ if ((plugs[0] == 0) || (plugs[1] == 0)) {911911+ err = -ENOSYS;912912+ goto end;913913+ }914914+915915+ avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,916916+ AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);917917+ err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);918918+ if (err < 0) {919919+ dev_err(&bebob->unit->device,920920+ "fail to get type for isoc in plug 0: %d\n", err);921921+ goto end;922922+ } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {923923+ err = -ENOSYS;924924+ goto end;925925+ }926926+ err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_IN, 0);927927+ if (err < 0)928928+ goto end;929929+930930+ avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,931931+ AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);932932+ err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);933933+ if (err < 0) {934934+ dev_err(&bebob->unit->device,935935+ "fail to get type for isoc out plug 0: %d\n", err);936936+ goto end;937937+ } else if (type != AVC_BRIDGECO_PLUG_TYPE_ISOC) {938938+ err = -ENOSYS;939939+ goto end;940940+ }941941+ err = fill_stream_formations(bebob, AVC_BRIDGECO_PLUG_DIR_OUT, 0);942942+ if (err < 0)943943+ goto end;944944+945945+ /* count external input plugs for MIDI */946946+ bebob->midi_input_ports = 0;947947+ for (i = 0; i < plugs[2]; i++) {948948+ avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_IN,949949+ AVC_BRIDGECO_PLUG_UNIT_EXT, i);950950+ err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);951951+ if (err < 0) {952952+ dev_err(&bebob->unit->device,953953+ "fail to get type for external in plug %d: %d\n",954954+ i, err);955955+ goto end;956956+ } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {957957+ bebob->midi_input_ports++;958958+ }959959+ }960960+961961+ /* count external output plugs for MIDI */962962+ bebob->midi_output_ports = 0;963963+ for (i = 0; i < plugs[3]; i++) {964964+ avc_bridgeco_fill_unit_addr(addr, AVC_BRIDGECO_PLUG_DIR_OUT,965965+ AVC_BRIDGECO_PLUG_UNIT_EXT, i);966966+ err = avc_bridgeco_get_plug_type(bebob->unit, addr, &type);967967+ if (err < 0) {968968+ dev_err(&bebob->unit->device,969969+ "fail to get type for external out plug %d: %d\n",970970+ i, err);971971+ goto end;972972+ } else if (type == AVC_BRIDGECO_PLUG_TYPE_MIDI) {973973+ bebob->midi_output_ports++;974974+ }975975+ }976976+977977+ /* for check source of clock later */978978+ if (!clk_spec)979979+ err = seek_msu_sync_input_plug(bebob);980980+end:981981+ return err;982982+}983983+984984+void snd_bebob_stream_lock_changed(struct snd_bebob *bebob)985985+{986986+ bebob->dev_lock_changed = true;987987+ wake_up(&bebob->hwdep_wait);988988+}989989+990990+int snd_bebob_stream_lock_try(struct snd_bebob *bebob)991991+{992992+ int err;993993+994994+ spin_lock_irq(&bebob->lock);995995+996996+ /* user land lock this */997997+ if (bebob->dev_lock_count < 0) {998998+ err = -EBUSY;999999+ goto end;10001000+ }10011001+10021002+ /* this is the first time */10031003+ if (bebob->dev_lock_count++ == 0)10041004+ snd_bebob_stream_lock_changed(bebob);10051005+ err = 0;10061006+end:10071007+ spin_unlock_irq(&bebob->lock);10081008+ return err;10091009+}10101010+10111011+void snd_bebob_stream_lock_release(struct snd_bebob *bebob)10121012+{10131013+ spin_lock_irq(&bebob->lock);10141014+10151015+ if (WARN_ON(bebob->dev_lock_count <= 0))10161016+ goto end;10171017+ if (--bebob->dev_lock_count == 0)10181018+ snd_bebob_stream_lock_changed(bebob);10191019+end:10201020+ spin_unlock_irq(&bebob->lock);10211021+}
+68
sound/firewire/bebob/bebob_terratec.c
···11+/*22+ * bebob_terratec.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+static char *const phase88_rack_clk_src_labels[] = {1212+ SND_BEBOB_CLOCK_INTERNAL, "Digital In", "Word Clock"1313+};1414+static int1515+phase88_rack_clk_src_get(struct snd_bebob *bebob, unsigned int *id)1616+{1717+ unsigned int enable_ext, enable_word;1818+ int err;1919+2020+ err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_ext);2121+ if (err < 0)2222+ goto end;2323+ err = avc_audio_get_selector(bebob->unit, 0, 0, &enable_word);2424+ if (err < 0)2525+ goto end;2626+2727+ *id = (enable_ext & 0x01) | ((enable_word & 0x01) << 1);2828+end:2929+ return err;3030+}3131+3232+static char *const phase24_series_clk_src_labels[] = {3333+ SND_BEBOB_CLOCK_INTERNAL, "Digital In"3434+};3535+static int3636+phase24_series_clk_src_get(struct snd_bebob *bebob, unsigned int *id)3737+{3838+ return avc_audio_get_selector(bebob->unit, 0, 4, id);3939+}4040+4141+static struct snd_bebob_rate_spec phase_series_rate_spec = {4242+ .get = &snd_bebob_stream_get_rate,4343+ .set = &snd_bebob_stream_set_rate,4444+};4545+4646+/* PHASE 88 Rack FW */4747+static struct snd_bebob_clock_spec phase88_rack_clk = {4848+ .num = ARRAY_SIZE(phase88_rack_clk_src_labels),4949+ .labels = phase88_rack_clk_src_labels,5050+ .get = &phase88_rack_clk_src_get,5151+};5252+struct snd_bebob_spec phase88_rack_spec = {5353+ .clock = &phase88_rack_clk,5454+ .rate = &phase_series_rate_spec,5555+ .meter = NULL5656+};5757+5858+/* 'PHASE 24 FW' and 'PHASE X24 FW' */5959+static struct snd_bebob_clock_spec phase24_series_clk = {6060+ .num = ARRAY_SIZE(phase24_series_clk_src_labels),6161+ .labels = phase24_series_clk_src_labels,6262+ .get = &phase24_series_clk_src_get,6363+};6464+struct snd_bebob_spec phase24_series_spec = {6565+ .clock = &phase24_series_clk,6666+ .rate = &phase_series_rate_spec,6767+ .meter = NULL6868+};
+50
sound/firewire/bebob/bebob_yamaha.c
···11+/*22+ * bebob_yamaha.c - a part of driver for BeBoB based devices33+ *44+ * Copyright (c) 2013-2014 Takashi Sakamoto55+ *66+ * Licensed under the terms of the GNU General Public License, version 2.77+ */88+99+#include "./bebob.h"1010+1111+/*1212+ * NOTE:1313+ * Yamaha GO44 is not designed to be used as stand-alone mixer. So any streams1414+ * must be accompanied. If changing the state, a LED on the device starts to1515+ * blink and its sync status is false. In this state, the device sounds nothing1616+ * even if streaming. To start streaming at the current sampling rate is only1717+ * way to revocer this state. GO46 is better for stand-alone mixer.1818+ *1919+ * Both of them have a capability to change its sampling rate up to 192.0kHz.2020+ * At 192.0kHz, the device reports 4 PCM-in, 1 MIDI-in, 6 PCM-out, 1 MIDI-out.2121+ * But Yamaha's driver reduce 2 PCM-in, 1 MIDI-in, 2 PCM-out, 1 MIDI-out to use2222+ * 'Extended Stream Format Information Command - Single Request' in 'Additional2323+ * AVC commands' defined by BridgeCo.2424+ * This ALSA driver don't do this because a bit tiresome. Then isochronous2525+ * streaming with many asynchronous transactions brings sounds with noises.2626+ * Unfortunately current 'ffado-mixer' generated many asynchronous transaction2727+ * to observe device's state, mainly check cmp connection and signal format. I2828+ * reccomend users to close ffado-mixer at 192.0kHz if mixer is needless.2929+ */3030+3131+static char *const clk_src_labels[] = {SND_BEBOB_CLOCK_INTERNAL, "SPDIF"};3232+static int3333+clk_src_get(struct snd_bebob *bebob, unsigned int *id)3434+{3535+ return avc_audio_get_selector(bebob->unit, 0, 4, id);3636+}3737+static struct snd_bebob_clock_spec clock_spec = {3838+ .num = ARRAY_SIZE(clk_src_labels),3939+ .labels = clk_src_labels,4040+ .get = &clk_src_get,4141+};4242+static struct snd_bebob_rate_spec rate_spec = {4343+ .get = &snd_bebob_stream_get_rate,4444+ .set = &snd_bebob_stream_set_rate,4545+};4646+struct snd_bebob_spec yamaha_go_spec = {4747+ .clock = &clock_spec,4848+ .rate = &rate_spec,4949+ .meter = NULL5050+};
+153-50
sound/firewire/cmp.c
···1414#include "iso-resources.h"1515#include "cmp.h"16161717-#define IMPR_SPEED_MASK 0xc00000001818-#define IMPR_SPEED_SHIFT 301919-#define IMPR_XSPEED_MASK 0x000000602020-#define IMPR_XSPEED_SHIFT 52121-#define IMPR_PLUGS_MASK 0x0000001f1717+/* MPR common fields */1818+#define MPR_SPEED_MASK 0xc00000001919+#define MPR_SPEED_SHIFT 302020+#define MPR_XSPEED_MASK 0x000000602121+#define MPR_XSPEED_SHIFT 52222+#define MPR_PLUGS_MASK 0x0000001f22232323-#define IPCR_ONLINE 0x800000002424-#define IPCR_BCAST_CONN 0x400000002525-#define IPCR_P2P_CONN_MASK 0x3f0000002626-#define IPCR_P2P_CONN_SHIFT 242727-#define IPCR_CHANNEL_MASK 0x003f00002828-#define IPCR_CHANNEL_SHIFT 162424+/* PCR common fields */2525+#define PCR_ONLINE 0x800000002626+#define PCR_BCAST_CONN 0x400000002727+#define PCR_P2P_CONN_MASK 0x3f0000002828+#define PCR_P2P_CONN_SHIFT 242929+#define PCR_CHANNEL_MASK 0x003f00003030+#define PCR_CHANNEL_SHIFT 163131+3232+/* oPCR specific fields */3333+#define OPCR_XSPEED_MASK 0x00C000003434+#define OPCR_XSPEED_SHIFT 223535+#define OPCR_SPEED_MASK 0x0000C0003636+#define OPCR_SPEED_SHIFT 143737+#define OPCR_OVERHEAD_ID_MASK 0x00003C003838+#define OPCR_OVERHEAD_ID_SHIFT 1029393040enum bus_reset_handling {3141 ABORT_ON_BUS_RESET,···49395040 va_start(va, fmt);5141 dev_err(&c->resources.unit->device, "%cPCR%u: %pV",5252- 'i', c->pcr_index, &(struct va_format){ fmt, &va });4242+ (c->direction == CMP_INPUT) ? 'i' : 'o',4343+ c->pcr_index, &(struct va_format){ fmt, &va });5344 va_end(va);4545+}4646+4747+static u64 mpr_address(struct cmp_connection *c)4848+{4949+ if (c->direction == CMP_INPUT)5050+ return CSR_REGISTER_BASE + CSR_IMPR;5151+ else5252+ return CSR_REGISTER_BASE + CSR_OMPR;5353+}5454+5555+static u64 pcr_address(struct cmp_connection *c)5656+{5757+ if (c->direction == CMP_INPUT)5858+ return CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index);5959+ else6060+ return CSR_REGISTER_BASE + CSR_OPCR(c->pcr_index);5461}55625663static int pcr_modify(struct cmp_connection *c,···85588659 err = snd_fw_transaction(8760 c->resources.unit, TCODE_LOCK_COMPARE_SWAP,8888- CSR_REGISTER_BASE + CSR_IPCR(c->pcr_index),8989- buffer, 8,6161+ pcr_address(c), buffer, 8,9062 FW_FIXED_GENERATION | c->resources.generation);91639264 if (err < 0) {···11488 * cmp_connection_init - initializes a connection manager11589 * @c: the connection manager to initialize11690 * @unit: a unit of the target device117117- * @ipcr_index: the index of the iPCR on the target device9191+ * @pcr_index: the index of the iPCR/oPCR on the target device11892 */11993int cmp_connection_init(struct cmp_connection *c,12094 struct fw_unit *unit,121121- unsigned int ipcr_index)9595+ enum cmp_direction direction,9696+ unsigned int pcr_index)12297{123123- __be32 impr_be;124124- u32 impr;9898+ __be32 mpr_be;9999+ u32 mpr;125100 int err;126101102102+ c->direction = direction;127103 err = snd_fw_transaction(unit, TCODE_READ_QUADLET_REQUEST,128128- CSR_REGISTER_BASE + CSR_IMPR,129129- &impr_be, 4, 0);104104+ mpr_address(c), &mpr_be, 4, 0);130105 if (err < 0)131106 return err;132132- impr = be32_to_cpu(impr_be);107107+ mpr = be32_to_cpu(mpr_be);133108134134- if (ipcr_index >= (impr & IMPR_PLUGS_MASK))109109+ if (pcr_index >= (mpr & MPR_PLUGS_MASK))135110 return -EINVAL;136111137112 err = fw_iso_resources_init(&c->resources, unit);···142115 c->connected = false;143116 mutex_init(&c->mutex);144117 c->last_pcr_value = cpu_to_be32(0x80000000);145145- c->pcr_index = ipcr_index;146146- c->max_speed = (impr & IMPR_SPEED_MASK) >> IMPR_SPEED_SHIFT;118118+ c->pcr_index = pcr_index;119119+ c->max_speed = (mpr & MPR_SPEED_MASK) >> MPR_SPEED_SHIFT;147120 if (c->max_speed == SCODE_BETA)148148- c->max_speed += (impr & IMPR_XSPEED_MASK) >> IMPR_XSPEED_SHIFT;121121+ c->max_speed += (mpr & MPR_XSPEED_MASK) >> MPR_XSPEED_SHIFT;149122150123 return 0;151124}152125EXPORT_SYMBOL(cmp_connection_init);126126+127127+/**128128+ * cmp_connection_check_used - check connection is already esablished or not129129+ * @c: the connection manager to be checked130130+ */131131+int cmp_connection_check_used(struct cmp_connection *c, bool *used)132132+{133133+ __be32 pcr;134134+ int err;135135+136136+ err = snd_fw_transaction(137137+ c->resources.unit, TCODE_READ_QUADLET_REQUEST,138138+ pcr_address(c), &pcr, 4, 0);139139+ if (err >= 0)140140+ *used = !!(pcr & cpu_to_be32(PCR_BCAST_CONN |141141+ PCR_P2P_CONN_MASK));142142+143143+ return err;144144+}145145+EXPORT_SYMBOL(cmp_connection_check_used);153146154147/**155148 * cmp_connection_destroy - free connection manager resources···186139187140static __be32 ipcr_set_modify(struct cmp_connection *c, __be32 ipcr)188141{189189- ipcr &= ~cpu_to_be32(IPCR_BCAST_CONN |190190- IPCR_P2P_CONN_MASK |191191- IPCR_CHANNEL_MASK);192192- ipcr |= cpu_to_be32(1 << IPCR_P2P_CONN_SHIFT);193193- ipcr |= cpu_to_be32(c->resources.channel << IPCR_CHANNEL_SHIFT);142142+ ipcr &= ~cpu_to_be32(PCR_BCAST_CONN |143143+ PCR_P2P_CONN_MASK |144144+ PCR_CHANNEL_MASK);145145+ ipcr |= cpu_to_be32(1 << PCR_P2P_CONN_SHIFT);146146+ ipcr |= cpu_to_be32(c->resources.channel << PCR_CHANNEL_SHIFT);194147195148 return ipcr;196149}197150198198-static int ipcr_set_check(struct cmp_connection *c, __be32 ipcr)151151+static int get_overhead_id(struct cmp_connection *c)199152{200200- if (ipcr & cpu_to_be32(IPCR_BCAST_CONN |201201- IPCR_P2P_CONN_MASK)) {153153+ int id;154154+155155+ /*156156+ * apply "oPCR overhead ID encoding"157157+ * the encoding table can convert up to 512.158158+ * here the value over 512 is converted as the same way as 512.159159+ */160160+ for (id = 1; id < 16; id++) {161161+ if (c->resources.bandwidth_overhead < (id << 5))162162+ break;163163+ }164164+ if (id == 16)165165+ id = 0;166166+167167+ return id;168168+}169169+170170+static __be32 opcr_set_modify(struct cmp_connection *c, __be32 opcr)171171+{172172+ unsigned int spd, xspd;173173+174174+ /* generate speed and extended speed field value */175175+ if (c->speed > SCODE_400) {176176+ spd = SCODE_800;177177+ xspd = c->speed - SCODE_800;178178+ } else {179179+ spd = c->speed;180180+ xspd = 0;181181+ }182182+183183+ opcr &= ~cpu_to_be32(PCR_BCAST_CONN |184184+ PCR_P2P_CONN_MASK |185185+ OPCR_XSPEED_MASK |186186+ PCR_CHANNEL_MASK |187187+ OPCR_SPEED_MASK |188188+ OPCR_OVERHEAD_ID_MASK);189189+ opcr |= cpu_to_be32(1 << PCR_P2P_CONN_SHIFT);190190+ opcr |= cpu_to_be32(xspd << OPCR_XSPEED_SHIFT);191191+ opcr |= cpu_to_be32(c->resources.channel << PCR_CHANNEL_SHIFT);192192+ opcr |= cpu_to_be32(spd << OPCR_SPEED_SHIFT);193193+ opcr |= cpu_to_be32(get_overhead_id(c) << OPCR_OVERHEAD_ID_SHIFT);194194+195195+ return opcr;196196+}197197+198198+static int pcr_set_check(struct cmp_connection *c, __be32 pcr)199199+{200200+ if (pcr & cpu_to_be32(PCR_BCAST_CONN |201201+ PCR_P2P_CONN_MASK)) {202202 cmp_error(c, "plug is already in use\n");203203 return -EBUSY;204204 }205205- if (!(ipcr & cpu_to_be32(IPCR_ONLINE))) {205205+ if (!(pcr & cpu_to_be32(PCR_ONLINE))) {206206 cmp_error(c, "plug is not on-line\n");207207 return -ECONNREFUSED;208208 }···264170 *265171 * This function establishes a point-to-point connection from the local266172 * computer to the target by allocating isochronous resources (channel and267267- * bandwidth) and setting the target's input plug control register. When this268268- * function succeeds, the caller is responsible for starting transmitting269269- * packets.173173+ * bandwidth) and setting the target's input/output plug control register.174174+ * When this function succeeds, the caller is responsible for starting175175+ * transmitting packets.270176 */271177int cmp_connection_establish(struct cmp_connection *c,272178 unsigned int max_payload_bytes)···287193 if (err < 0)288194 goto err_mutex;289195290290- err = pcr_modify(c, ipcr_set_modify, ipcr_set_check,291291- ABORT_ON_BUS_RESET);196196+ if (c->direction == CMP_OUTPUT)197197+ err = pcr_modify(c, opcr_set_modify, pcr_set_check,198198+ ABORT_ON_BUS_RESET);199199+ else200200+ err = pcr_modify(c, ipcr_set_modify, pcr_set_check,201201+ ABORT_ON_BUS_RESET);202202+292203 if (err == -EAGAIN) {293204 fw_iso_resources_free(&c->resources);294205 goto retry_after_bus_reset;···320221 * cmp_connection_update - update the connection after a bus reset321222 * @c: the connection manager322223 *323323- * This function must be called from the driver's .update handler to reestablish324324- * any connection that might have been active.224224+ * This function must be called from the driver's .update handler to225225+ * reestablish any connection that might have been active.325226 *326227 * Returns zero on success, or a negative error code. On an error, the327228 * connection is broken and the caller must stop transmitting iso packets.···341242 if (err < 0)342243 goto err_unconnect;343244344344- err = pcr_modify(c, ipcr_set_modify, ipcr_set_check,345345- SUCCEED_ON_BUS_RESET);245245+ if (c->direction == CMP_OUTPUT)246246+ err = pcr_modify(c, opcr_set_modify, pcr_set_check,247247+ SUCCEED_ON_BUS_RESET);248248+ else249249+ err = pcr_modify(c, ipcr_set_modify, pcr_set_check,250250+ SUCCEED_ON_BUS_RESET);251251+346252 if (err < 0)347253 goto err_resources;348254···365261}366262EXPORT_SYMBOL(cmp_connection_update);367263368368-369369-static __be32 ipcr_break_modify(struct cmp_connection *c, __be32 ipcr)264264+static __be32 pcr_break_modify(struct cmp_connection *c, __be32 pcr)370265{371371- return ipcr & ~cpu_to_be32(IPCR_BCAST_CONN | IPCR_P2P_CONN_MASK);266266+ return pcr & ~cpu_to_be32(PCR_BCAST_CONN | PCR_P2P_CONN_MASK);372267}373268374269/**375270 * cmp_connection_break - break the connection to the target376271 * @c: the connection manager377272 *378378- * This function deactives the connection in the target's input plug control379379- * register, and frees the isochronous resources of the connection. Before380380- * calling this function, the caller should cease transmitting packets.273273+ * This function deactives the connection in the target's input/output plug274274+ * control register, and frees the isochronous resources of the connection.275275+ * Before calling this function, the caller should cease transmitting packets.381276 */382277void cmp_connection_break(struct cmp_connection *c)383278{···389286 return;390287 }391288392392- err = pcr_modify(c, ipcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);289289+ err = pcr_modify(c, pcr_break_modify, NULL, SUCCEED_ON_BUS_RESET);393290 if (err < 0)394291 cmp_error(c, "plug is still connected\n");395292
+11-3
sound/firewire/cmp.h
···7788struct fw_unit;991010+enum cmp_direction {1111+ CMP_INPUT = 0,1212+ CMP_OUTPUT,1313+};1414+1015/**1116 * struct cmp_connection - manages an isochronous connection to a device1217 * @speed: the connection's actual speed1318 *1414- * This structure manages (using CMP) an isochronous stream from the local1515- * computer to a device's input plug (iPCR).1919+ * This structure manages (using CMP) an isochronous stream between the local2020+ * computer and a device's input plug (iPCR) and output plug (oPCR).1621 *1722 * There is no corresponding oPCR created on the local computer, so it is not1823 * possible to overlay connections on top of this one.···3126 __be32 last_pcr_value;3227 unsigned int pcr_index;3328 unsigned int max_speed;2929+ enum cmp_direction direction;3430};35313632int cmp_connection_init(struct cmp_connection *connection,3733 struct fw_unit *unit,3838- unsigned int ipcr_index);3434+ enum cmp_direction direction,3535+ unsigned int pcr_index);3636+int cmp_connection_check_used(struct cmp_connection *connection, bool *used);3937void cmp_connection_destroy(struct cmp_connection *connection);40384139int cmp_connection_establish(struct cmp_connection *connection,
+47-41
sound/firewire/dice.c
···5151 wait_queue_head_t hwdep_wait;5252 u32 notification_bits;5353 struct fw_iso_resources resources;5454- struct amdtp_out_stream stream;5454+ struct amdtp_stream stream;5555};56565757MODULE_DESCRIPTION("DICE driver");···420420 if (err < 0)421421 goto err_lock;422422423423- err = snd_pcm_hw_constraint_step(runtime, 0,424424- SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 32);425425- if (err < 0)426426- goto err_lock;427427- err = snd_pcm_hw_constraint_step(runtime, 0,428428- SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 32);429429- if (err < 0)430430- goto err_lock;431431-432432- err = snd_pcm_hw_constraint_minmax(runtime,433433- SNDRV_PCM_HW_PARAM_PERIOD_TIME,434434- 5000, UINT_MAX);435435- if (err < 0)436436- goto err_lock;437437-438438- err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);423423+ err = amdtp_stream_add_pcm_hw_constraints(&dice->stream, runtime);439424 if (err < 0)440425 goto err_lock;441426···445460{446461 int err;447462448448- if (amdtp_out_stream_running(&dice->stream))463463+ if (amdtp_stream_running(&dice->stream))449464 return 0;450465451451- err = amdtp_out_stream_start(&dice->stream, dice->resources.channel,452452- fw_parent_device(dice->unit)->max_speed);466466+ err = amdtp_stream_start(&dice->stream, dice->resources.channel,467467+ fw_parent_device(dice->unit)->max_speed);453468 if (err < 0)454469 return err;455470456471 err = dice_enable_set(dice);457472 if (err < 0) {458458- amdtp_out_stream_stop(&dice->stream);473473+ amdtp_stream_stop(&dice->stream);459474 return err;460475 }461476···469484470485 if (!dice->resources.allocated) {471486 err = fw_iso_resources_allocate(&dice->resources,472472- amdtp_out_stream_get_max_payload(&dice->stream),487487+ amdtp_stream_get_max_payload(&dice->stream),473488 fw_parent_device(dice->unit)->max_speed);474489 if (err < 0)475490 goto error;···501516502517static void dice_stream_stop_packets(struct dice *dice)503518{504504- if (amdtp_out_stream_running(&dice->stream)) {519519+ if (amdtp_stream_running(&dice->stream)) {505520 dice_enable_clear(dice);506506- amdtp_out_stream_stop(&dice->stream);521521+ amdtp_stream_stop(&dice->stream);507522 }508523}509524···548563 struct snd_pcm_hw_params *hw_params)549564{550565 struct dice *dice = substream->private_data;551551- unsigned int rate_index, mode;566566+ unsigned int rate_index, mode, rate, channels, i;552567 int err;553568554569 mutex_lock(&dice->mutex);···560575 if (err < 0)561576 return err;562577563563- rate_index = rate_to_index(params_rate(hw_params));578578+ rate = params_rate(hw_params);579579+ rate_index = rate_to_index(rate);564580 err = dice_change_rate(dice, rate_index << CLOCK_RATE_SHIFT);565581 if (err < 0)566582 return err;567583584584+ /*585585+ * At rates above 96 kHz, pretend that the stream runs at half the586586+ * actual sample rate with twice the number of channels; two samples587587+ * of a channel are stored consecutively in the packet. Requires588588+ * blocking mode and PCM buffer size should be aligned to SYT_INTERVAL.589589+ */590590+ channels = params_channels(hw_params);591591+ if (rate_index > 4) {592592+ if (channels > AMDTP_MAX_CHANNELS_FOR_PCM / 2) {593593+ err = -ENOSYS;594594+ return err;595595+ }596596+597597+ for (i = 0; i < channels; i++) {598598+ dice->stream.pcm_positions[i * 2] = i;599599+ dice->stream.pcm_positions[i * 2 + 1] = i + channels;600600+ }601601+602602+ rate /= 2;603603+ channels *= 2;604604+ }605605+568606 mode = rate_index_to_mode(rate_index);569569- amdtp_out_stream_set_parameters(&dice->stream,570570- params_rate(hw_params),571571- params_channels(hw_params),572572- dice->rx_midi_ports[mode]);573573- amdtp_out_stream_set_pcm_format(&dice->stream,574574- params_format(hw_params));607607+ amdtp_stream_set_parameters(&dice->stream, rate, channels,608608+ dice->rx_midi_ports[mode]);609609+ amdtp_stream_set_pcm_format(&dice->stream,610610+ params_format(hw_params));575611576612 return 0;577613}···615609616610 mutex_lock(&dice->mutex);617611618618- if (amdtp_out_streaming_error(&dice->stream))612612+ if (amdtp_streaming_error(&dice->stream))619613 dice_stream_stop_packets(dice);620614621615 err = dice_stream_start(dice);···626620627621 mutex_unlock(&dice->mutex);628622629629- amdtp_out_stream_pcm_prepare(&dice->stream);623623+ amdtp_stream_pcm_prepare(&dice->stream);630624631625 return 0;632626}···646640 default:647641 return -EINVAL;648642 }649649- amdtp_out_stream_pcm_trigger(&dice->stream, pcm);643643+ amdtp_stream_pcm_trigger(&dice->stream, pcm);650644651645 return 0;652646}···655649{656650 struct dice *dice = substream->private_data;657651658658- return amdtp_out_stream_pcm_pointer(&dice->stream);652652+ return amdtp_stream_pcm_pointer(&dice->stream);659653}660654661655static int dice_create_pcm(struct dice *dice)···11101104{11111105 struct dice *dice = card->private_data;1112110611131113- amdtp_out_stream_destroy(&dice->stream);11071107+ amdtp_stream_destroy(&dice->stream);11141108 fw_core_remove_address_handler(&dice->notification_handler);11151109 mutex_destroy(&dice->mutex);11161110}···13661360 goto err_owner;13671361 dice->resources.channels_mask = 0x00000000ffffffffuLL;1368136213691369- err = amdtp_out_stream_init(&dice->stream, unit,13701370- CIP_BLOCKING | CIP_HI_DUALWIRE);13631363+ err = amdtp_stream_init(&dice->stream, unit, AMDTP_OUT_STREAM,13641364+ CIP_BLOCKING);13711365 if (err < 0)13721366 goto err_resources;13731367···14231417{14241418 struct dice *dice = dev_get_drvdata(&unit->device);1425141914261426- amdtp_out_stream_pcm_abort(&dice->stream);14201420+ amdtp_stream_pcm_abort(&dice->stream);1427142114281422 snd_card_disconnect(dice->card);14291423···14491443 * to stop so that the application can restart them in an orderly14501444 * manner.14511445 */14521452- amdtp_out_stream_pcm_abort(&dice->stream);14461446+ amdtp_stream_pcm_abort(&dice->stream);1453144714541448 mutex_lock(&dice->mutex);14551449
+182-7
sound/firewire/fcp.c
···1010#include <linux/firewire-constants.h>1111#include <linux/list.h>1212#include <linux/module.h>1313+#include <linux/slab.h>1314#include <linux/sched.h>1415#include <linux/spinlock.h>1516#include <linux/wait.h>1617#include <linux/delay.h>1718#include "fcp.h"1819#include "lib.h"2020+#include "amdtp.h"19212022#define CTS_AVC 0x0021232224#define ERROR_RETRIES 32325#define ERROR_DELAY_MS 52426#define FCP_TIMEOUT_MS 1252727+2828+int avc_general_set_sig_fmt(struct fw_unit *unit, unsigned int rate,2929+ enum avc_general_plug_dir dir,3030+ unsigned short pid)3131+{3232+ unsigned int sfc;3333+ u8 *buf;3434+ bool flag;3535+ int err;3636+3737+ flag = false;3838+ for (sfc = 0; sfc < CIP_SFC_COUNT; sfc++) {3939+ if (amdtp_rate_table[sfc] == rate) {4040+ flag = true;4141+ break;4242+ }4343+ }4444+ if (!flag)4545+ return -EINVAL;4646+4747+ buf = kzalloc(8, GFP_KERNEL);4848+ if (buf == NULL)4949+ return -ENOMEM;5050+5151+ buf[0] = 0x00; /* AV/C CONTROL */5252+ buf[1] = 0xff; /* UNIT */5353+ if (dir == AVC_GENERAL_PLUG_DIR_IN)5454+ buf[2] = 0x19; /* INPUT PLUG SIGNAL FORMAT */5555+ else5656+ buf[2] = 0x18; /* OUTPUT PLUG SIGNAL FORMAT */5757+ buf[3] = 0xff & pid; /* plug id */5858+ buf[4] = 0x90; /* EOH_1, Form_1, FMT. AM824 */5959+ buf[5] = 0x07 & sfc; /* FDF-hi. AM824, frequency */6060+ buf[6] = 0xff; /* FDF-mid. AM824, SYT hi (not used)*/6161+ buf[7] = 0xff; /* FDF-low. AM824, SYT lo (not used) */6262+6363+ /* do transaction and check buf[1-5] are the same against command */6464+ err = fcp_avc_transaction(unit, buf, 8, buf, 8,6565+ BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5));6666+ if (err >= 0 && err < 8)6767+ err = -EIO;6868+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */6969+ err = -ENOSYS;7070+ else if (buf[0] == 0x0a) /* REJECTED */7171+ err = -EINVAL;7272+ if (err < 0)7373+ goto end;7474+7575+ err = 0;7676+end:7777+ kfree(buf);7878+ return err;7979+}8080+EXPORT_SYMBOL(avc_general_set_sig_fmt);8181+8282+int avc_general_get_sig_fmt(struct fw_unit *unit, unsigned int *rate,8383+ enum avc_general_plug_dir dir,8484+ unsigned short pid)8585+{8686+ unsigned int sfc;8787+ u8 *buf;8888+ int err;8989+9090+ buf = kzalloc(8, GFP_KERNEL);9191+ if (buf == NULL)9292+ return -ENOMEM;9393+9494+ buf[0] = 0x01; /* AV/C STATUS */9595+ buf[1] = 0xff; /* Unit */9696+ if (dir == AVC_GENERAL_PLUG_DIR_IN)9797+ buf[2] = 0x19; /* INPUT PLUG SIGNAL FORMAT */9898+ else9999+ buf[2] = 0x18; /* OUTPUT PLUG SIGNAL FORMAT */100100+ buf[3] = 0xff & pid; /* plug id */101101+ buf[4] = 0x90; /* EOH_1, Form_1, FMT. AM824 */102102+ buf[5] = 0xff; /* FDF-hi. AM824, frequency */103103+ buf[6] = 0xff; /* FDF-mid. AM824, SYT hi (not used) */104104+ buf[7] = 0xff; /* FDF-low. AM824, SYT lo (not used) */105105+106106+ /* do transaction and check buf[1-4] are the same against command */107107+ err = fcp_avc_transaction(unit, buf, 8, buf, 8,108108+ BIT(1) | BIT(2) | BIT(3) | BIT(4));109109+ if (err >= 0 && err < 8)110110+ err = -EIO;111111+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */112112+ err = -ENOSYS;113113+ else if (buf[0] == 0x0a) /* REJECTED */114114+ err = -EINVAL;115115+ else if (buf[0] == 0x0b) /* IN TRANSITION */116116+ err = -EAGAIN;117117+ if (err < 0)118118+ goto end;119119+120120+ /* check sfc field and pick up rate */121121+ sfc = 0x07 & buf[5];122122+ if (sfc >= CIP_SFC_COUNT) {123123+ err = -EAGAIN; /* also in transition */124124+ goto end;125125+ }126126+127127+ *rate = amdtp_rate_table[sfc];128128+ err = 0;129129+end:130130+ kfree(buf);131131+ return err;132132+}133133+EXPORT_SYMBOL(avc_general_get_sig_fmt);134134+135135+int avc_general_get_plug_info(struct fw_unit *unit, unsigned int subunit_type,136136+ unsigned int subunit_id, unsigned int subfunction,137137+ u8 info[AVC_PLUG_INFO_BUF_BYTES])138138+{139139+ u8 *buf;140140+ int err;141141+142142+ /* extended subunit in spec.4.2 is not supported */143143+ if ((subunit_type == 0x1E) || (subunit_id == 5))144144+ return -EINVAL;145145+146146+ buf = kzalloc(8, GFP_KERNEL);147147+ if (buf == NULL)148148+ return -ENOMEM;149149+150150+ buf[0] = 0x01; /* AV/C STATUS */151151+ /* UNIT or Subunit, Functionblock */152152+ buf[1] = ((subunit_type & 0x1f) << 3) | (subunit_id & 0x7);153153+ buf[2] = 0x02; /* PLUG INFO */154154+ buf[3] = 0xff & subfunction;155155+156156+ err = fcp_avc_transaction(unit, buf, 8, buf, 8, BIT(1) | BIT(2));157157+ if (err >= 0 && err < 8)158158+ err = -EIO;159159+ else if (buf[0] == 0x08) /* NOT IMPLEMENTED */160160+ err = -ENOSYS;161161+ else if (buf[0] == 0x0a) /* REJECTED */162162+ err = -EINVAL;163163+ else if (buf[0] == 0x0b) /* IN TRANSITION */164164+ err = -EAGAIN;165165+ if (err < 0)166166+ goto end;167167+168168+ info[0] = buf[4];169169+ info[1] = buf[5];170170+ info[2] = buf[6];171171+ info[3] = buf[7];172172+173173+ err = 0;174174+end:175175+ kfree(buf);176176+ return err;177177+}178178+EXPORT_SYMBOL(avc_general_get_plug_info);2517926180static DEFINE_SPINLOCK(transactions_lock);27181static LIST_HEAD(transactions);···18430 STATE_PENDING,18531 STATE_BUS_RESET,18632 STATE_COMPLETE,3333+ STATE_DEFERRED,18734};1883518936struct fcp_transaction {···19540 unsigned int response_match_bytes;19641 enum fcp_state state;19742 wait_queue_head_t wait;4343+ bool deferrable;19844};1994520046/**···23781 t.state = STATE_PENDING;23882 init_waitqueue_head(&t.wait);239838484+ if (*(const u8 *)command == 0x00 || *(const u8 *)command == 0x03)8585+ t.deferrable = true;8686+24087 spin_lock_irq(&transactions_lock);24188 list_add_tail(&t.list, &transactions);24289 spin_unlock_irq(&transactions_lock);···25293 (void *)command, command_size, 0);25394 if (ret < 0)25495 break;255255-9696+deferred:25697 wait_event_timeout(t.wait, t.state != STATE_PENDING,25798 msecs_to_jiffies(FCP_TIMEOUT_MS));25899259259- if (t.state == STATE_COMPLETE) {100100+ if (t.state == STATE_DEFERRED) {101101+ /*102102+ * 'AV/C General Specification' define no time limit103103+ * on command completion once an INTERIM response has104104+ * been sent. but we promise to finish this function105105+ * for a caller. Here we use FCP_TIMEOUT_MS for next106106+ * interval. This is not in the specification.107107+ */108108+ t.state = STATE_PENDING;109109+ goto deferred;110110+ } else if (t.state == STATE_COMPLETE) {260111 ret = t.response_size;261112 break;262113 } else if (t.state == STATE_BUS_RESET) {···301132 spin_lock_irq(&transactions_lock);302133 list_for_each_entry(t, &transactions, list) {303134 if (t->unit == unit &&304304- t->state == STATE_PENDING) {135135+ (t->state == STATE_PENDING ||136136+ t->state == STATE_DEFERRED)) {305137 t->state = STATE_BUS_RESET;306138 wake_up(&t->wait);307139 }···356186357187 if (t->state == STATE_PENDING &&358188 is_matching_response(t, data, length)) {359359- t->state = STATE_COMPLETE;360360- t->response_size = min((unsigned int)length,361361- t->response_size);362362- memcpy(t->response_buffer, data, t->response_size);189189+ if (t->deferrable && *(const u8 *)data == 0x0f) {190190+ t->state = STATE_DEFERRED;191191+ } else {192192+ t->state = STATE_COMPLETE;193193+ t->response_size = min_t(unsigned int, length,194194+ t->response_size);195195+ memcpy(t->response_buffer, data,196196+ t->response_size);197197+ }363198 wake_up(&t->wait);364199 }365200 }
+21
sound/firewire/fcp.h
···11#ifndef SOUND_FIREWIRE_FCP_H_INCLUDED22#define SOUND_FIREWIRE_FCP_H_INCLUDED3344+#define AVC_PLUG_INFO_BUF_BYTES 455+46struct fw_unit;77+88+/*99+ * AV/C Digital Interface Command Set General Specification 4.21010+ * (Sep 2004, 1394TA)1111+ */1212+enum avc_general_plug_dir {1313+ AVC_GENERAL_PLUG_DIR_IN = 0,1414+ AVC_GENERAL_PLUG_DIR_OUT = 1,1515+ AVC_GENERAL_PLUG_DIR_COUNT1616+};1717+int avc_general_set_sig_fmt(struct fw_unit *unit, unsigned int rate,1818+ enum avc_general_plug_dir dir,1919+ unsigned short plug);2020+int avc_general_get_sig_fmt(struct fw_unit *unit, unsigned int *rate,2121+ enum avc_general_plug_dir dir,2222+ unsigned short plug);2323+int avc_general_get_plug_info(struct fw_unit *unit, unsigned int subunit_type,2424+ unsigned int subunit_id, unsigned int subfunction,2525+ u8 info[AVC_PLUG_INFO_BUF_BYTES]);526627int fcp_avc_transaction(struct fw_unit *unit,728 const void *command, unsigned int command_size,
···13671367 /* initialize streams */13681368 azx_init_stream(chip);1369136913701370+ /* workaround for Broadwell HDMI: the first stream is broken,13711371+ * so mask it by keeping it as if opened13721372+ */13731373+ if (pci->vendor == 0x8086 && pci->device == 0x160c)13741374+ chip->azx_dev[0].opened = 1;13751375+13701376 /* initialize chip */13711377 azx_init_pci(chip);13721378 azx_init_chip(chip, (probe_only[dev] & 2) == 0);